Skip to content

Commit

Permalink
Merge pull request #2338 from posit-dev/dotnomad/envvar-overlap-err
Browse files Browse the repository at this point in the history
Show error and disable deployment when environment and secrets have duplicates
  • Loading branch information
dotNomad authored Oct 4, 2024
2 parents d88edab + e58aefe commit 79117e1
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,29 @@
/>
</div>

<template v-if="home.duplicatedEnvironmentVariables.length">
<p>
<template v-if="home.duplicatedEnvironmentVariables.length === 1">
A variable was set as both a secret and environment variable. It
must only be set as one or the other.
</template>
<template v-if="home.duplicatedEnvironmentVariables.length > 1">
Variables were set as both secrets and environment variables. They
must only be set as one or the other.
</template>
<a
class="webview-link"
role="button"
@click="
onEditConfiguration(home.selectedConfiguration!.configurationPath)
"
>Edit the Configuration</a
>.
</p>
<p>{{ home.duplicatedEnvironmentVariables.join(", ") }}</p>
<p></p>
</template>

<p v-if="home.config.active.isEntryMissing">
No Config Entry in Deployment record -
{{ home.selectedContentRecord?.saveName }}.
Expand Down
29 changes: 29 additions & 0 deletions extensions/vscode/webviews/homeView/src/stores/home.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,33 @@ export const useHomeStore = defineStore("home", () => {

const secrets = ref(new Map<string, string | undefined>());

const environment = computed((): Map<string, string> => {
const result = new Map<string, string>();
const config = selectedConfiguration.value;

if (config === undefined || isConfigurationError(config)) {
return result;
}

Object.entries(config.configuration.environment || {}).forEach(
([name, value]) => {
result.set(name, value);
},
);

return result;
});

const duplicatedEnvironmentVariables = computed((): string[] => {
const result: string[] = [];
secrets.value.forEach((_, name) => {
if (environment.value.has(name)) {
result.push(name);
}
});
return result;
});

const showDisabledOverlay = ref(false);

const selectedContentRecord = ref<ContentRecord | PreContentRecord>();
Expand Down Expand Up @@ -375,6 +402,8 @@ export const useHomeStore = defineStore("home", () => {
credentials,
sortedCredentials,
secrets,
environment,
duplicatedEnvironmentVariables,
selectedContentRecord,
selectedConfiguration,
serverCredential,
Expand Down

0 comments on commit 79117e1

Please sign in to comment.