Skip to content

Commit b016aa7

Browse files
committed
Implement set profile; update docs for release 0.2.0
1 parent cfda6b5 commit b016aa7

File tree

9 files changed

+103
-30
lines changed

9 files changed

+103
-30
lines changed

CHANGELOG.md

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,26 @@
11
# Change Log
2-
All notable changes to the "aws-cli-configure" extension will be documented in this file.
3-
4-
Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file.
2+
All notable changes to the AWS CLI Configure extension will be documented in this file.
53

64
## [Unreleased]
7-
- TBD
5+
- Allow copying profiles with keys (role_arn & source_profile) in addition to those with keys (aws_access_key_id & aws_secret_access_key)
6+
7+
## 0.2.0 - (2018-06-09)
8+
### Added
9+
- Command: Show [named] profile mapped to [default] in 'credentials'
10+
- Command: Set 'credentials' [default] profile to...
11+
- Command: Copy profile name from 'credentials'...
12+
- Status Bar: Activating extension shows which [named] profile is mapped to [default]
13+
- Status Bar: Clicking profile name in status bar executes command: Set 'credentials' [default] profile to...
14+
15+
### Updated
16+
- Rename command to: Open 'credentials' file
17+
- Rename command to: Open 'config' file
18+
- Rename command to: Open 'credentials' & 'config' files
19+
820

9-
## [0.0.1] - 2018-06-08
21+
## 0.0.1 - (2018-06-08)
1022
### Added
11-
- Command: Open `credentials` file
12-
- Command: Open `config` file
13-
- Command: Open `credentials` & `config` files
23+
- Command: Open credentials file
24+
- Command: Open config file
25+
- Command: Open credentials & config files
1426
- Command: Browse online docs

README.md

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,31 @@ The AWS CLI Configure extension allows you to quickly access AWS CLI information
66
## Features
77

88
The extension adds commands for the following:
9-
* Open `credentials` file
10-
* Open `config` file
11-
* Open `credentials` & `config` files
9+
* Open 'credentials' file
10+
* Open 'config' file
11+
* Open 'credentials' & 'config' files
1212
* Browse the online docs
13+
* Show [named] profile mapped to [default] in 'credentials'
14+
* Set 'credentials' [default] profile to...
15+
* Copy profile name from 'credentials'...
1316

14-
For example if there is an image subfolder under your extension project workspace:
17+
### Commands
1518

16-
\!\[feature commands\]\(./images/commands.png)
19+
![Command List](images/commands.png)
1720

21+
### Copy profile name
22+
![Copy Profile](images/copy-profile.png)
23+
Now the name is on the clipboard. Paste away!
1824

25+
### Show named profile mapped to default
26+
![Show Mapped Profile](images/statusbar-mapped-profile.png)
27+
28+
- Saving the 'credentials' file from VSCode or setting the default profile updates the status bar.
29+
- Click the item in the status bar to set the [default] profile to a [named] profile.
30+
31+
32+
### Set default profile
33+
![Set Default Profile](images/set-default-profile.png)
1934

2035
## Known Issues
2136

@@ -24,3 +39,10 @@ No known issues
2439
## Release Notes
2540

2641
See Changelog
42+
43+
## License
44+
This software is released under [MIT License](http://www.opensource.org/licenses/mit-license.php)
45+
© [Mark Tucker (@rmtuckerphx)](https://github.com/rmtuckerphx) & Contributors
46+
47+
## Review
48+
Feedback and contributions welcome. Please leave a [review](https://marketplace.visualstudio.com/items?itemName=mark-tucker.aws-cli-configure#review-details).

extension.js

Lines changed: 47 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const fs = require('fs');
88
const profileHandler = require('aws-profile-handler');
99
const hash = require('object-hash');
1010
const copyPaste = require("copy-paste");
11+
const uniqid = require('uniqid');
1112

1213
const 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

203235
function 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();

images/commands.png

5.81 KB
Loading

images/copy-profile.png

4.87 KB
Loading

images/set-default-profile.png

6.19 KB
Loading
2.27 KB
Loading

package-lock.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "aws-cli-configure",
33
"displayName": "AWS CLI Configure",
44
"description": "Quickly access the AWS CLI config and credentials files",
5-
"version": "0.0.2",
5+
"version": "0.2.0",
66
"publisher": "mark-tucker",
77
"license": "SEE LICENSE IN LICENSE.md",
88
"icon": "images/icon.png",
@@ -69,7 +69,7 @@
6969
{
7070
"command": "aws-cli.copy.profile.credentials",
7171
"title": "AWS CLI: Copy profile name from 'credentials'..."
72-
}
72+
}
7373
]
7474
},
7575
"scripts": {
@@ -87,6 +87,7 @@
8787
"aws-profile-handler": "^2.0.3",
8888
"copy-paste": "^1.3.0",
8989
"object-hash": "^1.3.0",
90-
"opn": "^5.3.0"
90+
"opn": "^5.3.0",
91+
"uniqid": "^5.0.2"
9192
}
9293
}

0 commit comments

Comments
 (0)