fix: postman env variables are to be imported as secrets (#4474)
Co-authored-by: Shoban <mshobanr@ford.com> Co-authored-by: jamesgeorge007 <25279263+jamesgeorge007@users.noreply.github.com>
This commit is contained in:
@@ -36,6 +36,7 @@ import { TeamEnvironment } from "~/helpers/teams/TeamEnvironment"
|
|||||||
import { computed } from "vue"
|
import { computed } from "vue"
|
||||||
import { useReadonlyStream } from "~/composables/stream"
|
import { useReadonlyStream } from "~/composables/stream"
|
||||||
import { initializeDownloadFile } from "~/helpers/import-export/export"
|
import { initializeDownloadFile } from "~/helpers/import-export/export"
|
||||||
|
import { transformEnvironmentVariables } from "~/helpers/import-export/export/environment"
|
||||||
import { environmentsExporter } from "~/helpers/import-export/export/environments"
|
import { environmentsExporter } from "~/helpers/import-export/export/environments"
|
||||||
import { gistExporter } from "~/helpers/import-export/export/gist"
|
import { gistExporter } from "~/helpers/import-export/export/gist"
|
||||||
import { platform } from "~/platform"
|
import { platform } from "~/platform"
|
||||||
@@ -73,10 +74,12 @@ const isTeamEnvironment = computed(() => {
|
|||||||
|
|
||||||
const environmentJson = computed(() => {
|
const environmentJson = computed(() => {
|
||||||
if (isTeamEnvironment.value && props.teamEnvironments) {
|
if (isTeamEnvironment.value && props.teamEnvironments) {
|
||||||
return props.teamEnvironments.map((x) => x.environment)
|
return props.teamEnvironments.map(({ environment }) =>
|
||||||
|
transformEnvironmentVariables(environment)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
return myEnvironments.value
|
return myEnvironments.value.map(transformEnvironmentVariables)
|
||||||
})
|
})
|
||||||
|
|
||||||
const workspaceType = computed(() =>
|
const workspaceType = computed(() =>
|
||||||
|
|||||||
@@ -352,12 +352,15 @@ watch(
|
|||||||
env: {
|
env: {
|
||||||
key: e.key,
|
key: e.key,
|
||||||
value: e.secret
|
value: e.secret
|
||||||
? (secretEnvironmentService.getSecretEnvironmentVariable(
|
? secretEnvironmentService.getSecretEnvironmentVariable(
|
||||||
props.editingEnvironmentIndex === "Global"
|
props.editingEnvironmentIndex === "Global"
|
||||||
? "Global"
|
? "Global"
|
||||||
: workingEnvID.value,
|
: workingEnvID.value,
|
||||||
index
|
index
|
||||||
)?.value ?? "")
|
)?.value ??
|
||||||
|
// @ts-expect-error `value` field can exist for secret environment variables as inferred while importing
|
||||||
|
e.value ??
|
||||||
|
""
|
||||||
: e.value,
|
: e.value,
|
||||||
secret: e.secret,
|
secret: e.secret,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -311,10 +311,13 @@ watch(
|
|||||||
env: {
|
env: {
|
||||||
key: e.key,
|
key: e.key,
|
||||||
value: e.secret
|
value: e.secret
|
||||||
? (secretEnvironmentService.getSecretEnvironmentVariable(
|
? secretEnvironmentService.getSecretEnvironmentVariable(
|
||||||
editingID.value ?? "",
|
editingID.value ?? "",
|
||||||
index
|
index
|
||||||
)?.value ?? "")
|
)?.value ??
|
||||||
|
// @ts-expect-error `value` field can exist for secret environment variables as inferred while importing
|
||||||
|
e.value ??
|
||||||
|
""
|
||||||
: e.value,
|
: e.value,
|
||||||
secret: e.secret,
|
secret: e.secret,
|
||||||
},
|
},
|
||||||
@@ -352,10 +355,6 @@ const removeEnvironmentVariable = (id: number) => {
|
|||||||
const isLoading = ref(false)
|
const isLoading = ref(false)
|
||||||
|
|
||||||
const saveEnvironment = async () => {
|
const saveEnvironment = async () => {
|
||||||
if (isLoading.value) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
isLoading.value = true
|
isLoading.value = true
|
||||||
|
|
||||||
if (!editingName.value) {
|
if (!editingName.value) {
|
||||||
|
|||||||
@@ -19,11 +19,41 @@ const getEnvironmentJSON = (
|
|||||||
? environmentIndex
|
? environmentIndex
|
||||||
: environmentObj.id
|
: environmentObj.id
|
||||||
|
|
||||||
|
// Eliminate `value` field from secret environment variables prior to export
|
||||||
|
const transformedEnvironment = transformEnvironmentVariables(newEnvironment)
|
||||||
|
|
||||||
return environmentId !== null
|
return environmentId !== null
|
||||||
? JSON.stringify(newEnvironment, null, 2)
|
? JSON.stringify(transformedEnvironment, null, 2)
|
||||||
: undefined
|
: undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Apply necessary transformations prior to environment exports
|
||||||
|
export const transformEnvironmentVariables = ({
|
||||||
|
id,
|
||||||
|
v,
|
||||||
|
name,
|
||||||
|
variables,
|
||||||
|
}: Environment) => {
|
||||||
|
return {
|
||||||
|
id,
|
||||||
|
v,
|
||||||
|
name,
|
||||||
|
variables: variables.map((variable) => {
|
||||||
|
const { key, secret } = variable
|
||||||
|
|
||||||
|
// Eliminate `value` field for secret environment variables
|
||||||
|
if (secret) {
|
||||||
|
return {
|
||||||
|
key,
|
||||||
|
secret,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return variable
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export const exportAsJSON = async (
|
export const exportAsJSON = async (
|
||||||
environmentObj: Environment | TeamEnvironment,
|
environmentObj: Environment | TeamEnvironment,
|
||||||
environmentIndex?: number | "Global" | null
|
environmentIndex?: number | "Global" | null
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ const postmanEnvSchema = z.object({
|
|||||||
z.object({
|
z.object({
|
||||||
key: z.string(),
|
key: z.string(),
|
||||||
value: z.string(),
|
value: z.string(),
|
||||||
|
type: z.string(),
|
||||||
})
|
})
|
||||||
),
|
),
|
||||||
})
|
})
|
||||||
@@ -34,6 +35,7 @@ export const postmanEnvImporter = (contents: string[]) => {
|
|||||||
values: entry.values?.map((valueEntry) => ({
|
values: entry.values?.map((valueEntry) => ({
|
||||||
...valueEntry,
|
...valueEntry,
|
||||||
value: String(valueEntry.value),
|
value: String(valueEntry.value),
|
||||||
|
type: String(valueEntry.type),
|
||||||
})),
|
})),
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
@@ -52,7 +54,11 @@ export const postmanEnvImporter = (contents: string[]) => {
|
|||||||
id: uniqueID(),
|
id: uniqueID(),
|
||||||
v: 1,
|
v: 1,
|
||||||
name,
|
name,
|
||||||
variables: values.map((entires) => ({ ...entires, secret: false })),
|
variables: values.map(({ key, value, type }) => ({
|
||||||
|
key,
|
||||||
|
value,
|
||||||
|
secret: type === "secret",
|
||||||
|
})),
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user