Browse Source

fix env group parsing (#4573)

Feroze Mohideen 2 years ago
parent
commit
9949862e16

+ 9 - 0
dashboard/src/lib/env-groups/types.ts

@@ -33,6 +33,15 @@ export const envGroupValidator = z.object({
   secret_variables: z.record(z.string()).optional().default({}),
   secret_variables: z.record(z.string()).optional().default({}),
   created_at: z.string(),
   created_at: z.string(),
   linked_applications: z.array(z.string()).optional().default([]),
   linked_applications: z.array(z.string()).optional().default([]),
+  files: z
+    .array(
+      z.object({
+        name: z.string(),
+        contents: z.string(),
+      })
+    )
+    .optional()
+    .default([]),
   type: z
   type: z
     .string()
     .string()
     .pipe(
     .pipe(

+ 13 - 12
dashboard/src/main/home/env-dashboard/CreateEnvGroup.tsx

@@ -34,15 +34,7 @@ const CreateEnvGroup: React.FC<RouteComponentProps> = ({ history }) => {
     reValidateMode: "onSubmit",
     reValidateMode: "onSubmit",
     defaultValues: {
     defaultValues: {
       name: "",
       name: "",
-      envVariables: [
-        {
-          key: "",
-          value: "",
-          hidden: false,
-          locked: false,
-          deleted: false,
-        },
-      ],
+      envVariables: [],
       envFiles: [],
       envFiles: [],
     },
     },
   });
   });
@@ -66,7 +58,11 @@ const CreateEnvGroup: React.FC<RouteComponentProps> = ({ history }) => {
     const validate = async (): Promise<void> => {
     const validate = async (): Promise<void> => {
       const isNameValid = await trigger("name");
       const isNameValid = await trigger("name");
       const isEnvVariablesValid = await trigger("envVariables");
       const isEnvVariablesValid = await trigger("envVariables");
-      if (isNameValid && isEnvVariablesValid) {
+      if (
+        isNameValid &&
+        ((isEnvVariablesValid && envVariables.length > 0) ||
+          envFiles.length > 0)
+      ) {
         setStep(3);
         setStep(3);
       } else if (isNameValid) {
       } else if (isNameValid) {
         setStep(2);
         setStep(2);
@@ -75,7 +71,7 @@ const CreateEnvGroup: React.FC<RouteComponentProps> = ({ history }) => {
       }
       }
     };
     };
     void validate();
     void validate();
-  }, [name, envVariables]);
+  }, [name, envVariables, envFiles]);
 
 
   const onSubmit = handleSubmit(async (data) => {
   const onSubmit = handleSubmit(async (data) => {
     setSubmitErrorMessage("");
     setSubmitErrorMessage("");
@@ -206,7 +202,8 @@ const CreateEnvGroup: React.FC<RouteComponentProps> = ({ history }) => {
                     <Spacer y={0.5} />
                     <Spacer y={0.5} />
                     <Text color="helper">
                     <Text color="helper">
                       Files containing sensitive data that will be injected into
                       Files containing sensitive data that will be injected into
-                      your app&apos;s root directory.
+                      your app&apos;s root directory, at the path{" "}
+                      <Code>{`/etc/secrets/${name}`}</Code>.
                     </Text>
                     </Text>
                     <Spacer y={1} />
                     <Spacer y={1} />
                     <FileArray
                     <FileArray
@@ -275,3 +272,7 @@ const DarkMatter = styled.div<{ antiHeight?: string }>`
   width: 100%;
   width: 100%;
   margin-top: ${(props) => props.antiHeight || "-5px"};
   margin-top: ${(props) => props.antiHeight || "-5px"};
 `;
 `;
+
+const Code = styled.span`
+  font-family: monospace;
+`;

+ 6 - 1
dashboard/src/main/home/env-dashboard/tabs/EnvVarsTab.tsx

@@ -215,7 +215,8 @@ const EnvVarsTab: React.FC<Props> = ({ envGroup, fetchEnvGroup }) => {
           <Spacer y={0.5} />
           <Spacer y={0.5} />
           <Text color="helper">
           <Text color="helper">
             Files containing sensitive data that will be injected into your
             Files containing sensitive data that will be injected into your
-            app&apos;s root directory.
+            app&apos;s root directory, at the path{" "}
+            <Code>{`/etc/secrets/${envGroup.name}`}</Code>.
           </Text>
           </Text>
           <Spacer y={1} />
           <Spacer y={1} />
           <FileArray
           <FileArray
@@ -275,3 +276,7 @@ const StatusWrapper = styled.div<{
     color: ${(props) => (props.success ? "#4797ff" : "#fcba03")};
     color: ${(props) => (props.success ? "#4797ff" : "#fcba03")};
   }
   }
 `;
 `;
+
+const Code = styled.span`
+  font-family: monospace;
+`;

+ 4 - 6
internal/kubernetes/environment_groups/list.go

@@ -2,7 +2,6 @@ package environment_groups
 
 
 import (
 import (
 	"context"
 	"context"
-	"encoding/base64"
 	"fmt"
 	"fmt"
 	"strconv"
 	"strconv"
 	"strings"
 	"strings"
@@ -41,8 +40,8 @@ const (
 type EnvGroupFile struct {
 type EnvGroupFile struct {
 	// Name is the name of the file
 	// Name is the name of the file
 	Name string `json:"name"`
 	Name string `json:"name"`
-	// B64Contents is the base64 encoded contents of the file
-	B64Contents string `json:"contents"`
+	// Contents is the contents of the file
+	Contents string `json:"contents"`
 }
 }
 
 
 // EnvironmentGroup represents a ConfigMap in the porter-env-group namespace
 // EnvironmentGroup represents a ConfigMap in the porter-env-group namespace
@@ -239,10 +238,9 @@ func listEnvironmentGroups(ctx context.Context, a *kubernetes.Agent, listOpts ..
 		if ok && isFileSecret == "true" {
 		if ok && isFileSecret == "true" {
 			var files []EnvGroupFile
 			var files []EnvGroupFile
 			for k, v := range secret.Data {
 			for k, v := range secret.Data {
-				encodedContents := base64.StdEncoding.EncodeToString(v)
 				files = append(files, EnvGroupFile{
 				files = append(files, EnvGroupFile{
-					Name:        k,
-					B64Contents: encodedContents,
+					Name:     k,
+					Contents: string(v),
 				})
 				})
 			}
 			}
 			envGroupSet[versionedName] = EnvironmentGroup{
 			envGroupSet[versionedName] = EnvironmentGroup{