-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
71f017b
commit 4b3e056
Showing
6 changed files
with
117 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
src/commands/deployImage/getRegistryCredentialsAndSecrets.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import type { ContainerApp, RegistryCredentials, Secret } from "@azure/arm-appcontainers"; | ||
import { nonNullProp } from "@microsoft/vscode-azext-utils"; | ||
import { listCredentialsFromRegistry } from "./acr/listCredentialsFromRegistry"; | ||
import { IDeployImageContext } from "./IDeployImageContext"; | ||
|
||
export interface IRegistryCredentialsAndSecrets { | ||
registries: RegistryCredentials[] | undefined; | ||
secrets: Secret[] | undefined; | ||
} | ||
|
||
export async function getAcrCredentialsAndSecrets(context: IDeployImageContext, containerAppEnvelope: Required<ContainerApp>): Promise<IRegistryCredentialsAndSecrets> { | ||
const registry = nonNullProp(context, 'registry'); | ||
const { username, password } = await listCredentialsFromRegistry(context, registry); | ||
const passwordName = `${registry.name?.toLocaleLowerCase()}-${password?.name}`; | ||
|
||
// Remove duplicate registries | ||
const registries: RegistryCredentials[] | undefined = containerAppEnvelope.configuration.registries?.filter(r => r.server !== registry.loginServer); | ||
registries?.push( | ||
{ | ||
server: registry.loginServer, | ||
username: username, | ||
passwordSecretRef: passwordName | ||
} | ||
); | ||
|
||
// Remove duplicate secrets | ||
const secrets: Secret[] | undefined = containerAppEnvelope.configuration.secrets?.filter(s => s.name !== passwordName); | ||
secrets?.push({ name: passwordName, value: password.value }); | ||
|
||
return { registries, secrets }; | ||
} | ||
|
||
export function getThirdPartyCredentialsAndSecrets(context: IDeployImageContext, containerAppEnvelope: Required<ContainerApp>): IRegistryCredentialsAndSecrets { | ||
const loginServer: string = getAcaCompliantLoginServer(nonNullProp(context, 'loginServer')); | ||
const passwordSecretRef: string = `${loginServer.replace(/[\.]+/g, '')}-${context.username}`; | ||
|
||
// Remove duplicate registries | ||
const registries: RegistryCredentials[] | undefined = containerAppEnvelope.configuration.registries?.filter(r => r.server !== loginServer); | ||
registries?.push( | ||
{ | ||
server: loginServer, | ||
username: context.username, | ||
passwordSecretRef | ||
} | ||
); | ||
|
||
// Remove duplicate secrets | ||
const secrets: Secret[] | undefined = containerAppEnvelope.configuration.secrets?.filter(s => s.name !== passwordSecretRef); | ||
secrets?.push( | ||
{ | ||
name: passwordSecretRef, | ||
value: context.secret | ||
} | ||
); | ||
|
||
return { registries, secrets }; | ||
} | ||
|
||
// Todo: Revisit and test with different login server formats | ||
// Do we need a fallback for docker hub? 'index.docker.io' | ||
function getAcaCompliantLoginServer(loginServer: string): string { | ||
return loginServer; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters