@@ -28,10 +28,10 @@ export class AzureAksService {
2828 this . _client = new ServiceClient ( endpoint . applicationTokenCredentials , endpoint . subscriptionID , 30 ) ;
2929 }
3030
31- public beginRequest ( uri : string , parameters : { } ) : Promise < webClient . WebResponse > {
31+ public beginRequest ( uri : string , parameters : { } , apiVersion : string , method : string ) : Promise < webClient . WebResponse > {
3232 var webRequest = new webClient . WebRequest ( ) ;
33- webRequest . method = 'GET' ;
34- webRequest . uri = this . _client . getRequestUri ( uri , parameters , null , '2017-08-31' ) ;
33+ webRequest . method = method || 'GET' ;
34+ webRequest . uri = this . _client . getRequestUri ( uri , parameters , null , apiVersion ) ;
3535 return this . _client . beginRequestExpBackoff ( webRequest , 3 ) . then ( ( response ) => {
3636 if ( response . statusCode >= 200 && response . statusCode < 300 ) {
3737 return response ;
@@ -48,10 +48,36 @@ export class AzureAksService {
4848 '{ResourceGroupName}' : resourceGroup ,
4949 '{ClusterName}' : clusterName ,
5050 '{AccessProfileName}' : accessProfileName
51- } ) . then ( ( response ) => {
51+ } , '2017-08-31' , "GET" ) . then ( ( response ) => {
5252 return response . body ;
5353 } , ( reason ) => {
5454 throw Error ( tl . loc ( 'CantDownloadAccessProfile' , clusterName , this . _client . getFormattedError ( reason ) ) ) ;
5555 } ) ;
5656 }
57+
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+ {
62+ '{ResourceGroupName}' : resourceGroup ,
63+ '{ClusterName}' : clusterName ,
64+ '{CredentialAction}' : credentialAction
65+ } , '2024-05-01' , "POST" ) . then ( ( response ) => {
66+ return response . body ;
67+ } , ( reason ) => {
68+ throw Error ( tl . loc ( 'CantDownloadClusterCredentials' , clusterName , this . _client . getFormattedError ( reason ) ) ) ;
69+ } ) ;
70+ }
71+
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+ }
5783}
0 commit comments