Skip to content

Commit

Permalink
fix env group parsing (#4573)
Browse files Browse the repository at this point in the history
  • Loading branch information
Feroze Mohideen authored Apr 23, 2024
1 parent b765d7e commit 9949862
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 19 deletions.
9 changes: 9 additions & 0 deletions dashboard/src/lib/env-groups/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ export const envGroupValidator = z.object({
secret_variables: z.record(z.string()).optional().default({}),
created_at: z.string(),
linked_applications: z.array(z.string()).optional().default([]),
files: z
.array(
z.object({
name: z.string(),
contents: z.string(),
})
)
.optional()
.default([]),
type: z
.string()
.pipe(
Expand Down
25 changes: 13 additions & 12 deletions dashboard/src/main/home/env-dashboard/CreateEnvGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,7 @@ const CreateEnvGroup: React.FC<RouteComponentProps> = ({ history }) => {
reValidateMode: "onSubmit",
defaultValues: {
name: "",
envVariables: [
{
key: "",
value: "",
hidden: false,
locked: false,
deleted: false,
},
],
envVariables: [],
envFiles: [],
},
});
Expand All @@ -66,7 +58,11 @@ const CreateEnvGroup: React.FC<RouteComponentProps> = ({ history }) => {
const validate = async (): Promise<void> => {
const isNameValid = await trigger("name");
const isEnvVariablesValid = await trigger("envVariables");
if (isNameValid && isEnvVariablesValid) {
if (
isNameValid &&
((isEnvVariablesValid && envVariables.length > 0) ||
envFiles.length > 0)
) {
setStep(3);
} else if (isNameValid) {
setStep(2);
Expand All @@ -75,7 +71,7 @@ const CreateEnvGroup: React.FC<RouteComponentProps> = ({ history }) => {
}
};
void validate();
}, [name, envVariables]);
}, [name, envVariables, envFiles]);

const onSubmit = handleSubmit(async (data) => {
setSubmitErrorMessage("");
Expand Down Expand Up @@ -206,7 +202,8 @@ const CreateEnvGroup: React.FC<RouteComponentProps> = ({ history }) => {
<Spacer y={0.5} />
<Text color="helper">
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>
<Spacer y={1} />
<FileArray
Expand Down Expand Up @@ -275,3 +272,7 @@ const DarkMatter = styled.div<{ antiHeight?: string }>`
width: 100%;
margin-top: ${(props) => props.antiHeight || "-5px"};
`;

const Code = styled.span`
font-family: monospace;
`;
7 changes: 6 additions & 1 deletion dashboard/src/main/home/env-dashboard/tabs/EnvVarsTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,8 @@ const EnvVarsTab: React.FC<Props> = ({ envGroup, fetchEnvGroup }) => {
<Spacer y={0.5} />
<Text color="helper">
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>
<Spacer y={1} />
<FileArray
Expand Down Expand Up @@ -275,3 +276,7 @@ const StatusWrapper = styled.div<{
color: ${(props) => (props.success ? "#4797ff" : "#fcba03")};
}
`;

const Code = styled.span`
font-family: monospace;
`;
10 changes: 4 additions & 6 deletions internal/kubernetes/environment_groups/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package environment_groups

import (
"context"
"encoding/base64"
"fmt"
"strconv"
"strings"
Expand Down Expand Up @@ -41,8 +40,8 @@ const (
type EnvGroupFile struct {
// Name is the name of the file
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
Expand Down Expand Up @@ -239,10 +238,9 @@ func listEnvironmentGroups(ctx context.Context, a *kubernetes.Agent, listOpts ..
if ok && isFileSecret == "true" {
var files []EnvGroupFile
for k, v := range secret.Data {
encodedContents := base64.StdEncoding.EncodeToString(v)
files = append(files, EnvGroupFile{
Name: k,
B64Contents: encodedContents,
Name: k,
Contents: string(v),
})
}
envGroupSet[versionedName] = EnvironmentGroup{
Expand Down

0 comments on commit 9949862

Please sign in to comment.