-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding Azure REST samples support #178
Conversation
package.json
Outdated
@@ -31,7 +31,8 @@ | |||
"onCommand:vscode-ansible.playbook-in-docker", | |||
"onCommand:vscode-ansible.playbook-in-localansible", | |||
"onCommand:vscode-ansible.ssh", | |||
"onCommand:vscode-ansible.sync-folder-ssh" | |||
"onCommand:vscode-ansible.sync-folder-ssh", | |||
"onCommand:vscode-ansible.rest-api-samples" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggest to rest-module-samples. which is related to ansible
src/playbookManager.ts
Outdated
@@ -5,7 +5,7 @@ import * as vscode from 'vscode'; | |||
export class PlaybookManager { | |||
constructor() { | |||
} | |||
|
|||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove it
src/restSamples.ts
Outdated
} | ||
|
||
public displayMenu() { | ||
this.createRestApiCall(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why need a wrapper of displayMenu()?
src/restSamples.ts
Outdated
// - query list of api groups (compute, etc...) | ||
// - user selects api group | ||
public createRestApiCall() { | ||
let __this = this; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why need private __this?
src/restSamples.ts
Outdated
public selectOperation(path: string) { | ||
|
||
let operations = this.queryAll(path); | ||
let __this = this; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need of private this
src/restSamples.ts
Outdated
|
||
examples.forEach(function(s, i, a) { | ||
items.push({ | ||
'label': apiVersion + ' - Sample: ' + s.split('/').pop(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as we discussed, remove the word 'Sample"here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, sorry, forgot....
src/restSamples.ts
Outdated
pm.insertTask(playbook); | ||
} else { | ||
let playbook = swaggerHandler.generateRestApiTasks(selection['path'], selection['method'], selection['example']); | ||
pm.insertTask(playbook); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move pm.insertTask() out of if/else
src/restSamples.ts
Outdated
}); | ||
} | ||
|
||
public getSpecificationLocation(cb) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggest use async func instead of callback to make coding style consistent
src/restSamples.ts
Outdated
} | ||
|
||
public getSpecificationLocation(cb) { | ||
let config = vscode.workspace.getConfiguration('ansible'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there's utility in utiltities.js: getCodeConfiguration
src/restSamples.ts
Outdated
cb(config.get('AzureRestAPISpecificationPath')); | ||
} else { | ||
|
||
this._outputChannel.append('\nConnecting to Cloud Shell.'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wrong comments
src/restSamples.ts
Outdated
|
||
this._outputChannel.append('\nConnecting to Cloud Shell.'); | ||
this._outputChannel.show(); | ||
const progress = utilities.delayedInterval(() => { this._outputChannel.append('.') }, 500); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
progress should at end of below log message, otherwise you'll ...............Getting Azurexxxxx
src/restSamples.ts
Outdated
for (var path in swagger.paths) { | ||
for (var method in swagger.paths[path]) { | ||
// add only if there are examples | ||
if (swagger.paths[path][method]['x-ms-examples'] != undefined) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
!swagger.paths[path][method]['x-ms-examples'] , to cover both undefined, null and empty check
src/restSamples.ts
Outdated
this.queryDirectory(specLocation + '/specification', false, "", cb); | ||
} | ||
|
||
private queryApiGroup(path, cb) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the 2 function names confusing.. why not use queryDirectory and queryApiGroup?
src/swagger.ts
Outdated
method = method.toLowerCase(); | ||
playbook += //"# https://docs.microsoft.com/en-us/rest/api/" + area + "/" + resource + "/" + internalMethod + '\r'; | ||
"- name: Call REST API - " + this.swagger.paths[path][method]['operationId'] + "\r" + | ||
"\t" + ((method == 'get') ? "azure_rm_resource_facts" : "azure_rm_resource") + ":\r" + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pls replace \t with whitespace array constants
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
playbookManager is replacing tabs with spaces but it doesnt' really matter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tabs /whitespace is matter. :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
of course they matter, and they are replaced later :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a public api. you really want your user do tab replace by themselves?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe they are replaced automatically when inserting sample using code in playbookManager. I could recheck it again...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but anyway, I replaced them with spaces....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
edit.insert(new vscode.Position(0, 0)….. in vscode works in such a way that all inserted tabs are replaced with spaces according to settings appropriate for current editor
src/playbookManager.ts
Outdated
@@ -25,11 +25,11 @@ export class PlaybookManager { | |||
|
|||
public insertTask(task: string) { | |||
let __this = this; | |||
|
|||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pls do code formatting by 'shift+alt+f' to remove those whitesapces.
src/playbookManager.ts
Outdated
if (vscode.window.activeTextEditor.document.getText() == "") { | ||
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
currently, the sample will be only inserted into utiltiled-1 doc, what if user want to insert into existing doc, focus position?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fi existing yaml document is open, new sample will be inserted at the end
src/restSamples.ts
Outdated
let operations = this.queryAll(path); | ||
let items = []; | ||
|
||
for (var key in operations) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
operations null/undefined check?
src/restSamples.ts
Outdated
let home: string = path.join(process.env[(process.platform == 'win32') ? 'USERPROFILE' : 'HOME'], 'azure-rest-api-specs'); | ||
clone("https://github.com/Azure/azure-rest-api-specs.git", home, null, (result) => { | ||
progress.cancel(); | ||
if (result == undefined) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pls use check if (!result) for undefined, null, empty check
src/restSamples.ts
Outdated
private queryDirectory(path: string, files: boolean, ext: string, cb) { | ||
// just use filesystem | ||
try { | ||
let dirEntries = fs.readdirSync(path); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check path exists before read?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's why try is here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perhaps there should be a message and we could clear the configuration if not there?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so you'd like the caller handle when path not exists?
src/swagger.ts
Outdated
method = method.toLowerCase(); | ||
playbook += //"# https://docs.microsoft.com/en-us/rest/api/" + area + "/" + resource + "/" + internalMethod + '\r'; | ||
"- name: Call REST API - " + this.swagger.paths[path][method]['operationId'] + "\r" + | ||
"\t" + ((method == 'get') ? "azure_rm_resource_facts" : "azure_rm_resource") + ":\r" + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tabs /whitespace is matter. :(
src/restSamples.ts
Outdated
let specLocation = await this.getSpecificationLocation(); | ||
__this.queryDirectory(specLocation + '/specification', false, "", function (groups) { | ||
if (groups != null) { | ||
vscode.window.showQuickPick(groups).then(selection => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is async function already, pls use await vscode.window.showQuickPick()
src/restSamples.ts
Outdated
|
||
this._outputChannel.append("Getting Azure REST API specifications."); | ||
let clone = require('git-clone'); | ||
let home: string = path.join(process.env[(process.platform == 'win32') ? 'USERPROFILE' : 'HOME'], 'azure-rest-api-specs'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
under .vscode to make it hide?
src/restSamples.ts
Outdated
this._outputChannel.append("Getting Azure REST API specifications."); | ||
let clone = require('git-clone'); | ||
let home: string = path.join(process.env[(process.platform == 'win32') ? 'USERPROFILE' : 'HOME'], 'azure-rest-api-specs'); | ||
clone("https://github.com/Azure/azure-rest-api-specs.git", home, null, (result) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
async function, pls use await instead of callback
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this library only supports callback
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
then pls remove async on function declaration
src/restSamples.ts
Outdated
let operationId: string = swagger.paths[path][method].operationId; | ||
let description: string = swagger.paths[path][method].description; | ||
|
||
if (!description || description == '') description = "Description not available"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not show this to user, by empty
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just show empty string?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes
src/restSamples.ts
Outdated
private queryDirectory(path: string, files: boolean, ext: string, cb) { | ||
// just use filesystem | ||
try { | ||
let dirEntries = fs.readdirSync(path); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so you'd like the caller handle when path not exists?
src/swagger.ts
Outdated
|
||
method = method.toLowerCase(); | ||
playbook += //"# https://docs.microsoft.com/en-us/rest/api/" + area + "/" + resource + "/" + internalMethod + '\r'; | ||
"- name: Call REST API - " + this.swagger.paths[path][method]['operationId'] + "\r" + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sample for Rest API... ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
with sample link here?
README.md
Outdated
@@ -139,6 +140,24 @@ Enable syntax highlighting by adding `files.associations` in `settings.json`, to | |||
``` | |||
There's notification message at right side of status bar. | |||
|
|||
## Samples for azure_rm_resource (preview) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Preview
README.md
Outdated
@@ -139,6 +140,24 @@ Enable syntax highlighting by adding `files.associations` in `settings.json`, to | |||
``` | |||
There's notification message at right side of status bar. | |||
|
|||
## Samples for azure_rm_resource (preview) | |||
|
|||
This option provides easy an access to the samples available from Azure REST API Specifications. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This option provides sample code snippets for [azure_rm_resource](link here) module, those samples are from Azure Rest API spec.
README.md
Outdated
This option provides easy an access to the samples available from Azure REST API Specifications. | ||
|
||
To use, press **F1** and then select **Ansible: Samples for azure_rm_resource (PREVIEW)** option. | ||
You will be first asked for API group, then required operation. After selecting operation a submenu will be displayed where you can select particular API version and sample. Extension will create appropriate playbook based on **azure_rm_resource** or **azure_rm_resource_facts** module. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
submenu -> pickup list
README.md
Outdated
|
||
Note that all the samples generated by the extension are based on REST API samples from this repository: | ||
|
||
https://github.com/Azure/azure-rest-api-specs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you meet error when using those samples, please file issues at xxxx/issues.
src/restSamples.ts
Outdated
this._outputChannel.append("Getting Azure REST API specifications."); | ||
let clone = require('git-clone'); | ||
let home: string = path.join(process.env[(process.platform == 'win32') ? 'USERPROFILE' : 'HOME'], 'azure-rest-api-specs'); | ||
clone("https://github.com/Azure/azure-rest-api-specs.git", home, null, (result) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
then pls remove async on function declaration
src/restSamples.ts
Outdated
} | ||
} | ||
|
||
private async queryAll(path: string): Promise<{}> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also remove async if there's no async operation in function
src/restSamples.ts
Outdated
return operations; | ||
} | ||
|
||
private async queryApiGroup(path): Promise<string[]> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here
src/restSamples.ts
Outdated
} | ||
} | ||
|
||
private async queryDirectory(path: string, files: boolean, ext: string): Promise<string[]> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no async calls inside
tested vsix on windows and mac..... |
Summary
Issue Type