@@ -8,6 +8,7 @@ const fs = require('fs');
88const profileHandler = require ( 'aws-profile-handler' ) ;
99const hash = require ( 'object-hash' ) ;
1010const copyPaste = require ( "copy-paste" ) ;
11+ const uniqid = require ( 'uniqid' ) ;
1112
1213const DEFAULT_PROFILE = 'default' ;
1314
@@ -57,10 +58,10 @@ function getTooltipMessage() {
5758 message = `No [default] profile in 'credentials'` ;
5859 break ;
5960
60- case 'default' :
61+ case DEFAULT_PROFILE :
6162 message = `No [named] profile mapped to [default] in 'credentials'` ;
6263 break ;
63-
64+
6465 default :
6566 message = `The [${ mappedProfile } ] profile is mapped to [default] in 'credentials'`
6667 break ;
@@ -170,15 +171,47 @@ function getDefaultProfileSetTo() {
170171
171172}
172173
173- async function setDefaultProfileToCredentials ( ) {
174-
174+ async function setDefaultProfileToCredentials ( status ) {
175+
175176 const profiles = getSortedProfilesCredentials ( false ) ;
176177 const newProfile = await vscode . window . showQuickPick ( profiles , { placeHolder : `Select the [named] profile to set as the [default] profile in the 'credentials' file.` } ) ;
177178
178179 if ( newProfile ) {
180+
179181 const message = `[default] profile in 'credentials' file set to: '${ newProfile } '.` ;
180182 console . log ( message ) ;
181- // vscode.window.showInformationMessage(message);
183+
184+ const newProfileData = profileHandler . getProfileCredentials ( newProfile ) ;
185+
186+ const mappedProfile = getDefaultProfileSetTo ( ) ;
187+
188+
189+ if ( mappedProfile === '<none>' ) {
190+ //add new [default] profile using values from mappedProfile
191+ profileHandler . addProfile ( DEFAULT_PROFILE , newProfileData ) ;
192+ }
193+ else {
194+ const defaultProfileData = profileHandler . getProfileCredentials ( DEFAULT_PROFILE ) ;
195+
196+ if ( mappedProfile === DEFAULT_PROFILE ) {
197+ //add new profile zzz-default-?
198+ const generatedName = uniqid ( 'zzz-default-' ) ;
199+
200+ profileHandler . addProfile ( generatedName , defaultProfileData ) ;
201+
202+ const message = `The [default] profile was renamed to ${ generatedName } . Rename or delete this profile.` ;
203+ vscode . window . showInformationMessage ( message ) ;
204+ }
205+
206+ //delete default profile
207+ profileHandler . deleteProfile ( DEFAULT_PROFILE ) ;
208+
209+ //add new [default] profile using values from mappedProfile
210+ profileHandler . addProfile ( DEFAULT_PROFILE , newProfileData ) ;
211+
212+ }
213+
214+ updateStatus ( status ) ;
182215 }
183216
184217}
@@ -190,9 +223,8 @@ async function copyProfileNameCredentials() {
190223
191224 if ( selectedProfile ) {
192225 copyPaste . copy ( selectedProfile , ( ) => {
193- //vscode.window.showInformationMessage(`'${selectedProfile}' copied to clipboard.`);
194226 vscode . window . setStatusBarMessage ( `'${ selectedProfile } ' copied to clipboard.` , 10000 ) ;
195- } ) ;
227+ } ) ;
196228 }
197229
198230}
@@ -202,21 +234,22 @@ async function copyProfileNameCredentials() {
202234
203235function activate ( context ) {
204236
237+ const status = vscode . window . createStatusBarItem ( vscode . StatusBarAlignment . Left ) ;
238+ status . command = 'aws-cli.set-default-profile.credentials' ;
239+ // status.tooltip = `Set [default] profile in 'credentials' to [named] profile`;
240+ status . tooltip = getTooltipMessage ( ) ;
241+ context . subscriptions . push ( status ) ;
242+
243+
205244 context . subscriptions . push ( vscode . commands . registerCommand ( 'aws-cli.open.credentials' , openCredentialsFile ) ) ;
206245 context . subscriptions . push ( vscode . commands . registerCommand ( 'aws-cli.open.config' , openConfigFile ) ) ;
207246 context . subscriptions . push ( vscode . commands . registerCommand ( 'aws-cli.open.both' , openBothFiles ) ) ;
208247 context . subscriptions . push ( vscode . commands . registerCommand ( 'aws-cli.browse.docs' , openOnlineDocs ) ) ;
209248
210249 context . subscriptions . push ( vscode . commands . registerCommand ( 'aws-cli.default.map.credentials' , showDefaultProfileMapCredentials ) ) ;
211- context . subscriptions . push ( vscode . commands . registerCommand ( 'aws-cli.set-default-profile.credentials' , setDefaultProfileToCredentials ) ) ;
250+ context . subscriptions . push ( vscode . commands . registerCommand ( 'aws-cli.set-default-profile.credentials' , setDefaultProfileToCredentials ( status ) ) ) ;
212251 context . subscriptions . push ( vscode . commands . registerCommand ( 'aws-cli.copy.profile.credentials' , copyProfileNameCredentials ) ) ;
213252
214- const status = vscode . window . createStatusBarItem ( vscode . StatusBarAlignment . Left ) ;
215- status . command = 'aws-cli.set-default-profile.credentials' ;
216- // status.tooltip = `Set [default] profile in 'credentials' to [named] profile`;
217- status . tooltip = getTooltipMessage ( ) ;
218-
219- context . subscriptions . push ( status ) ;
220253
221254 context . subscriptions . push ( vscode . workspace . onDidSaveTextDocument ( ( doc ) => {
222255 const credentialsFile = path . join ( os . homedir ( ) , '.aws' , 'credentials' ) . toLowerCase ( ) ;
0 commit comments