@@ -39,7 +39,7 @@ export class AzureAksService {
3939 throw ToError ( response ) ;
4040 }
4141 } ) ;
42- }
42+ }
4343
4444 public getAccessProfile ( resourceGroup : string , clusterName : string , useClusterAdmin ?: boolean ) : Promise < Model . AKSClusterAccessProfile > {
4545 var accessProfileName = ! ! useClusterAdmin ? 'clusterAdmin' : 'clusterUser' ;
@@ -54,30 +54,59 @@ export class AzureAksService {
5454 throw Error ( tl . loc ( 'CantDownloadAccessProfile' , clusterName , this . _client . getFormattedError ( reason ) ) ) ;
5555 } ) ;
5656 }
57+ private createFleetParameters ( resourceGroup : string , name : string ) : { uri : string , parameters : any , apiVersion : string } {
58+ const uri = `//subscriptions/{subscriptionId}/resourceGroups/{ResourceGroupName}/providers/Microsoft.ContainerService/fleets/{FleetName}/listCredentials` ;
59+ const parameters = {
60+ '{ResourceGroupName}' : resourceGroup ,
61+ '{FleetName}' : name ,
62+ } ;
63+ const apiVersion = '2024-04-01' ;
64+ return { uri, parameters, apiVersion } ;
65+ }
5766
58- public getClusterCredentials ( resourceGroup : string , clusterName : string , useClusterAdmin ?: boolean ) : Promise < Model . AKSCredentialResults > {
59- var credentialAction = ! ! useClusterAdmin ? 'listClusterAdminCredential' : 'listClusterUserCredential' ;
60- return this . beginRequest ( `//subscriptions/{subscriptionId}/resourceGroups/{ResourceGroupName}/providers/Microsoft.ContainerService/managedClusters/{ClusterName}/{CredentialAction}` ,
61- {
67+ private createManagedClusterParameters ( resourceGroup : string , name : string , useClusterAdmin ?: boolean ) : { uri : string , parameters : any , apiVersion : string } {
68+ const credentialAction = ! ! useClusterAdmin ? 'listClusterAdminCredential' : 'listClusterUserCredential' ;
69+ const uri = `//subscriptions/{subscriptionId}/resourceGroups/{ResourceGroupName}/providers/Microsoft.ContainerService/managedClusters/{ClusterName}/{CredentialAction}` ;
70+ const parameters = {
6271 '{ResourceGroupName}' : resourceGroup ,
63- '{ClusterName}' : clusterName ,
64- '{CredentialAction}' : credentialAction
65- } , '2024-05-01' , "POST" ) . then ( ( response ) => {
66- return response . body ;
72+ '{ClusterName}' : name ,
73+ '{CredentialAction}' : credentialAction ,
74+ } ;
75+ const apiVersion = '2024-05-01' ;
76+ return { uri, parameters, apiVersion } ;
77+ }
78+
79+ public getCredentials ( resourceGroup : string , name : string , uri : string , parameters : any , apiVersion : string ) : Promise < Model . AKSCredentialResults > {
80+ return this . beginRequest ( uri , parameters , apiVersion , "POST" ) . then ( ( response ) => {
81+ return response . body ;
6782 } , ( reason ) => {
68- throw Error ( tl . loc ( 'CantDownloadClusterCredentials' , clusterName , this . _client . getFormattedError ( reason ) ) ) ;
83+ throw Error ( tl . loc ( 'CantDownloadClusterCredentials' , name , this . _client . getFormattedError ( reason ) ) ) ;
6984 } ) ;
70- }
85+ }
86+
87+ public getClusterCredential ( resourceGroup : string , name : string , useClusterAdmin ?: boolean , credentialName ?: string ) : Promise < Model . AKSCredentialResult > {
88+ const { uri, parameters, apiVersion } = this . createManagedClusterParameters ( resourceGroup , name , useClusterAdmin ) ;
89+ const credentialsPromise = this . getCredentials ( resourceGroup , name , uri , parameters , apiVersion ) ;
90+ return credentialsPromise . then ( ( credentials ) => {
91+ const credential = credentials . kubeconfigs . find ( cred => cred . name === ( credentialName || ( ! ! useClusterAdmin ? 'clusterAdmin' : 'clusterUser' ) ) ) ;
92+ if ( credential === undefined ) {
93+ throw Error ( tl . loc ( 'CantDownloadClusterCredentials' , name , `${ credentialName || 'default' } not found in the list of credentials.` ) ) ;
94+ }
95+ return credential ;
96+ } ) ;
97+ }
98+
99+ public getFleetCredential ( resourceGroup : string , name : string ) : Promise < Model . AKSCredentialResult > {
100+
101+ const { uri, parameters, apiVersion } = this . createFleetParameters ( resourceGroup , name ) ;
102+ const credentialsPromise = this . getCredentials ( resourceGroup , name , uri , parameters , apiVersion ) ;
103+ return credentialsPromise . then ( ( credentials ) => {
104+ const credential = credentials . kubeconfigs [ 0 ] ;
105+ if ( credential === undefined ) {
106+ throw Error ( tl . loc ( 'CantDownloadClusterCredentials' ) ) ;
107+ }
108+ return credential ;
109+ } ) ;
110+ }
71111
72- public getClusterCredential ( resourceGroup : string , clusterName : string , useClusterAdmin ?: boolean , credentialName ?: string ) : Promise < Model . AKSCredentialResult > {
73- var credentialName = ! ! credentialName ? credentialName : ! ! useClusterAdmin ? 'clusterAdmin' : 'clusterUser' ;
74- var clusterCredentials = this . getClusterCredentials ( resourceGroup , clusterName , useClusterAdmin )
75- return clusterCredentials . then ( ( credentials ) => {
76- var credential = credentials . kubeconfigs . find ( credential => credential . name == credentialName )
77- if ( credential === undefined ) {
78- throw Error ( tl . loc ( 'CantDownloadClusterCredentials' , clusterName , `${ credentialName } not found in the list of cluster credentials.` ) ) ;
79- }
80- return credential ;
81- } )
82- }
83112}
0 commit comments