forked from Azure/vscode-aks-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Kaito fed creds and identity changes (Azure#914)
- Loading branch information
1 parent
e728d20
commit 0c016fd
Showing
12 changed files
with
393 additions
and
92 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { | ||
FederatedIdentityCredential, | ||
ManagedServiceIdentityClient, | ||
UserAssignedIdentitiesGetResponse, | ||
} from "@azure/arm-msi"; | ||
import { Errorable, getErrorMessage } from "./errorable"; | ||
|
||
export async function getIdentity( | ||
client: ManagedServiceIdentityClient, | ||
resourceGroupName: string, | ||
resourceName: string, | ||
): Promise<Errorable<UserAssignedIdentitiesGetResponse>> { | ||
try { | ||
const identity = await client.userAssignedIdentities.get(resourceGroupName, resourceName); | ||
if (!identity || !identity.principalId) { | ||
return { succeeded: false, error: "Identity does not have a principalId" }; | ||
} | ||
return { succeeded: true, result: identity }; | ||
} catch (e) { | ||
return { succeeded: false, error: getErrorMessage(e) }; | ||
} | ||
} | ||
|
||
export async function createFederatedCredential( | ||
client: ManagedServiceIdentityClient, | ||
resourceGroupName: string, | ||
resourceName: string, | ||
federatedCredentialName: string, | ||
issuer: string, | ||
subject: string, | ||
audience: string, | ||
): Promise<Errorable<void>> { | ||
try { | ||
const federatedCredential: FederatedIdentityCredential = { | ||
issuer: issuer, | ||
subject: subject, | ||
audiences: [audience], | ||
}; | ||
await client.federatedIdentityCredentials.createOrUpdate( | ||
resourceGroupName, | ||
federatedCredentialName, | ||
resourceName, | ||
federatedCredential, | ||
); | ||
return { succeeded: true, result: undefined }; | ||
} catch (e) { | ||
return { succeeded: false, error: getErrorMessage(e) }; | ||
} | ||
} |
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
Oops, something went wrong.