Skip to content

Commit e346629

Browse files
authored
Merge pull request #75 from vmware/retain-blueprint-metadata
Keep vRA blueprint metadata like name, id and description in the YAML
2 parents deff5a6 + ad0f693 commit e346629

File tree

8 files changed

+78
-43
lines changed

8 files changed

+78
-43
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
> and [vRealize Automation](https://www.vmware.com/products/vrealize-automation.html) content.
66
77
[![Visual Studio Marketplace Version](https://img.shields.io/visual-studio-marketplace/v/vmware-pscoe.vrealize-developer-tools.svg?label=VS%20Marketplace)](https://marketplace.visualstudio.com/items?itemName=vmware-pscoe.vrealize-developer-tools)
8-
[![Build Status](https://img.shields.io/github/workflow/status/vmware/vrealize-developer-tools/Build/master.svg?logo=github)](https://github.com/vmware/vrealize-developer-tools/actions)
8+
[![Build Status](https://github.com/vmware/vrealize-developer-tools/workflows/Build/badge.svg)](https://github.com/vmware/vrealize-developer-tools/actions)
99
[![Dependencies Status](https://david-dm.org/vmware/vrealize-developer-tools/status.svg)](https://david-dm.org/vmware/vrealize-developer-tools)
1010
[![Coverage Status](https://codecov.io/gh/vmware/vrealize-developer-tools/branch/master/graph/badge.svg)](https://codecov.io/gh/vmware/vrealize-developer-tools/)
1111

common/src/rest/VraNgRestClient.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -204,11 +204,11 @@ export class VraNgRestClient {
204204
return this.unwrapPages(blueprints, "/blueprint/api/blueprints")
205205
}
206206

207-
async createBlueprint(body: { name: string; projectId: string; content: string }): Promise<any> {
207+
async createBlueprint(body: { name: string; projectId: string; content: string, description: string }): Promise<any> {
208208
return this.send("POST", "/blueprint/api/blueprints", { body })
209209
}
210210

211-
async updateBlueprint(id: string, body: { name: string; projectId: string; content: string }): Promise<void> {
211+
async updateBlueprint(id: string, body: { name: string; projectId: string; content: string, description: string }): Promise<void> {
212212
return this.send("PUT", `/blueprint/api/blueprints/${id}`, { body })
213213
}
214214

extension/src/client/command/CreateBlueprint.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,11 @@ export class CreateBlueprint extends BaseVraCommand {
4444
})
4545

4646
if (!newFile) {
47-
return Promise.reject("Save dialog was canceled")
47+
this.logger.warn("Save dialog was canceled")
48+
return
4849
}
4950

50-
await vscode.workspace.fs.writeFile(newFile, Buffer.from(`name: ${blueprintName}\ninputs: {}\nresources:\n`))
51+
await vscode.workspace.fs.writeFile(newFile, Buffer.from(`name: ${blueprintName}\ndescription: ""\ncontent:\n formatVersion: 1\n inputs: {}\n resources:\n`))
5152
await vscode.window.showTextDocument(newFile, { preview: false })
5253

5354
vscode.window

extension/src/client/command/DeployBlueprint.ts

+14-7
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import * as path from "path"
77

88
import { AutoWire, Logger, validate, VraNgRestClient } from "vrealize-common"
99
import * as vscode from "vscode"
10-
import { parse as parseYaml } from "yaml"
10+
import { parse as parseYaml, stringify as stringifyYaml } from "yaml"
1111

1212
import { Commands } from "../constants"
1313
import { ConfigurationManager, EnvironmentManager } from "../system"
@@ -50,9 +50,13 @@ export class DeployBlueprint extends BaseVraCommand {
5050

5151
const restClient = await this.getRestClient()
5252

53-
const blueprintContent = activeTextEditor.document.getText()
54-
const blueprintName = path.basename(activeTextEditor.document.fileName).replace(".yaml", "")
55-
const existingBlueprint = await restClient.getBlueprintByName(blueprintName)
53+
const blueprintYaml = parseYaml(activeTextEditor.document.getText())
54+
const blueprintName = blueprintYaml.name || path.basename(activeTextEditor.document.fileName).replace(".yaml", "")
55+
const blueprintDescription = blueprintYaml.description || ""
56+
const blueprintContent = stringifyYaml(blueprintYaml.content)
57+
const existingBlueprint = blueprintYaml.id
58+
? await restClient.getBlueprintById(blueprintYaml.id)
59+
: await restClient.getBlueprintByName(blueprintName)
5660

5761
if (existingBlueprint) {
5862
const deploymentName = await vscode.window.showInputBox({
@@ -68,6 +72,7 @@ export class DeployBlueprint extends BaseVraCommand {
6872

6973
await restClient.updateBlueprint(existingBlueprint.id, {
7074
name: existingBlueprint.name,
75+
description: blueprintDescription,
7176
projectId: existingBlueprint.projectId,
7277
content: blueprintContent
7378
})
@@ -77,7 +82,7 @@ export class DeployBlueprint extends BaseVraCommand {
7782
restClient,
7883
existingBlueprint.projectId,
7984
deploymentName,
80-
blueprintContent,
85+
stringifyYaml(blueprintYaml.content),
8186
existingBlueprint.id
8287
)
8388
}
@@ -89,11 +94,13 @@ export class DeployBlueprint extends BaseVraCommand {
8994
this.logger.debug("Selected project and deployment name: ", state)
9095

9196
if (!state.projectId) {
92-
return Promise.reject("No project was selected")
97+
this.logger.warn("No project was selected")
98+
return
9399
}
94100

95101
if (!state.deploymentName) {
96-
return Promise.reject("No deployment name was provided")
102+
this.logger.warn("No deployment name was provided")
103+
return
97104
}
98105

99106
return this.doDeploy(context, restClient, state.projectId, state.deploymentName, blueprintContent, undefined)

extension/src/client/command/FetchBlueprint.ts

+18-7
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import * as path from "path"
77

88
import { AutoWire, Logger } from "vrealize-common"
99
import * as vscode from "vscode"
10+
import { parse as parseYaml, Document as YamlDocument } from "yaml"
1011

1112
import { Commands } from "../constants"
1213
import { ConfigurationManager, EnvironmentManager } from "../system"
@@ -45,16 +46,18 @@ export class GetBlueprint extends BaseVraCommand {
4546
)
4647

4748
const selected: BlueprintPickInfo | undefined = await vscode.window.showQuickPick(blueprintsFuture, {
48-
placeHolder: "Pick a blueprint"
49+
placeHolder: "Pick a blueprint",
50+
matchOnDescription: true
4951
})
5052

5153
this.logger.debug("Selected blueprint: ", selected)
5254

5355
if (!selected) {
54-
return Promise.reject("No blueprint selection was made")
56+
this.logger.warn("No blueprint selection was made")
57+
return
5558
}
5659

57-
let blueprintContent: string = ""
60+
const blueprintYaml = new YamlDocument()
5861
await vscode.window.withProgress(
5962
{
6063
location: vscode.ProgressLocation.Notification,
@@ -63,11 +66,18 @@ export class GetBlueprint extends BaseVraCommand {
6366
},
6467
async () => {
6568
const blueprint = await restClient.getBlueprintById(selected.id)
66-
blueprintContent = blueprint.content
69+
70+
blueprintYaml.contents = {
71+
id: blueprint.id,
72+
name: blueprint.name,
73+
description: blueprint.description,
74+
requestScopeOrg: blueprint.requestScopeOrg,
75+
content: parseYaml(blueprint.content)
76+
}
6777
}
6878
)
6979

70-
if (!blueprintContent) {
80+
if (!blueprintYaml.contents) {
7181
return Promise.reject("Could not fetch blueprint or it has empty content")
7282
}
7383

@@ -81,11 +91,12 @@ export class GetBlueprint extends BaseVraCommand {
8191
})
8292

8393
if (!newFile) {
84-
return Promise.reject("Save dialog was canceled")
94+
this.logger.warn("Save dialog was canceled")
95+
return
8596
}
8697

8798
this.logger.debug(`Saving the selected blueprint at ${newFile.toString()}`)
88-
await vscode.workspace.fs.writeFile(newFile, Buffer.from(blueprintContent))
99+
await vscode.workspace.fs.writeFile(newFile, Buffer.from(blueprintYaml.toString()))
89100
await vscode.window.showTextDocument(newFile, { preview: false })
90101
}
91102
}

extension/src/client/command/UploadBlueprint.ts

+16-6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import * as path from "path"
77

88
import { AutoWire, Logger } from "vrealize-common"
99
import * as vscode from "vscode"
10+
import { parse as parseYaml, stringify as stringifyYaml } from "yaml"
1011

1112
import { Commands } from "../constants"
1213
import { ConfigurationManager, EnvironmentManager } from "../system"
@@ -42,17 +43,22 @@ export class UploadBlueprint extends BaseVraCommand {
4243

4344
const restClient = await this.getRestClient()
4445

45-
const blueprintContent = activeTextEditor.document.getText()
46-
const blueprintName = path.basename(activeTextEditor.document.fileName).replace(".yaml", "")
47-
const existingBlueprint = await restClient.getBlueprintByName(blueprintName)
46+
const blueprintYaml = parseYaml(activeTextEditor.document.getText())
47+
const blueprintName = blueprintYaml.name || path.basename(activeTextEditor.document.fileName).replace(".yaml", "")
48+
const blueprintDescription = blueprintYaml.description || ""
49+
const existingBlueprint = blueprintYaml.id
50+
? await restClient.getBlueprintById(blueprintYaml.id)
51+
: await restClient.getBlueprintByName(blueprintName)
4852

4953
if (existingBlueprint) {
5054
await restClient.updateBlueprint(existingBlueprint.id, {
5155
name: existingBlueprint.name,
56+
description: blueprintDescription,
5257
projectId: existingBlueprint.projectId,
53-
content: blueprintContent
58+
content: stringifyYaml(blueprintYaml.content)
5459
})
5560

61+
vscode.window.showInformationMessage(`Blueprint '${blueprintName}' has been updated`)
5662
return
5763
}
5864

@@ -74,13 +80,17 @@ export class UploadBlueprint extends BaseVraCommand {
7480
this.logger.debug("Selected project: ", selectedProject)
7581

7682
if (!selectedProject) {
77-
return Promise.reject("No blueprint selection was made")
83+
this.logger.warn("No project selection was made")
84+
return
7885
}
7986

8087
await restClient.createBlueprint({
8188
name: blueprintName,
89+
description: blueprintDescription,
8290
projectId: selectedProject.id,
83-
content: blueprintContent
91+
content: stringifyYaml(blueprintYaml.content)
8492
})
93+
94+
vscode.window.showInformationMessage(`Blueprint '${blueprintName}' has been created`)
8595
}
8696
}

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,7 @@
551551
"@types/fs-extra": "~5.0.4",
552552
"@types/glob": "7.1.1",
553553
"@types/jest": "^24.9.1",
554+
"@types/jwt-decode": "^2.2.1",
554555
"@types/keytar": "^4.4.2",
555556
"@types/lodash": "^4.14.149",
556557
"@types/micromatch": "^3.1.1",
@@ -580,7 +581,7 @@
580581
"prettier": "^1.19.1",
581582
"ts-jest": "^25.0.0",
582583
"typescript": "~3.7.2",
583-
"vsce": "^1.69.0"
584+
"vsce": "^1.77.0"
584585
},
585586
"dependencies": {
586587
"adm-zip": "^0.4.13",

yarn.lock

+22-17
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,11 @@
676676
resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.3.tgz#bdfd69d61e464dcc81b25159c270d75a73c1a636"
677677
integrity sha512-Il2DtDVRGDcqjDtE+rF8iqg1CArehSK84HZJCT7AMITlyXRBpuPhqGLDQMowraqqu1coEaimg4ZOqggt6L6L+A==
678678

679+
"@types/jwt-decode@^2.2.1":
680+
version "2.2.1"
681+
resolved "https://registry.yarnpkg.com/@types/jwt-decode/-/jwt-decode-2.2.1.tgz#afdf5c527fcfccbd4009b5fd02d1e18241f2d2f2"
682+
integrity sha512-aWw2YTtAdT7CskFyxEX2K21/zSDStuf/ikI3yBqmwpwJF0pS+/IX5DWv+1UFffZIbruP6cnT9/LAJV1gFwAT1A==
683+
679684
"@types/keytar@^4.4.2":
680685
version "4.4.2"
681686
resolved "https://registry.yarnpkg.com/@types/keytar/-/keytar-4.4.2.tgz#49ef917d6cbb4f19241c0ab50cd35097b5729b32"
@@ -1922,11 +1927,6 @@ detect-newline@^3.0.0:
19221927
resolved "https://registry.yarnpkg.com/detect-newline/-/detect-newline-3.1.0.tgz#576f5dfc63ae1a192ff192d8ad3af6308991b651"
19231928
integrity sha1-V29d/GOuGhkv8ZLYrTr2MImRtlE=
19241929

1925-
didyoumean@^1.2.1:
1926-
version "1.2.1"
1927-
resolved "https://registry.yarnpkg.com/didyoumean/-/didyoumean-1.2.1.tgz#e92edfdada6537d484d73c0172fd1eba0c4976ff"
1928-
integrity sha1-6S7f2tplN9SE1zwBcv0eugxJdv8=
1929-
19301930
diff-sequences@^24.9.0:
19311931
version "24.9.0"
19321932
resolved "https://registry.yarnpkg.com/diff-sequences/-/diff-sequences-24.9.0.tgz#5715d6244e2aa65f48bba0bc972db0b0b11e95b5"
@@ -2060,6 +2060,11 @@ entities@^1.1.1, entities@~1.1.1:
20602060
resolved "https://registry.yarnpkg.com/entities/-/entities-1.1.2.tgz#bdfa735299664dfafd34529ed4f8522a275fea56"
20612061
integrity sha512-f2LZMYl1Fzu7YSBKg+RoROelpOaNrcGmE9AZubeDfrCEia483oW4MI4VyFd5VNHIgQ/7qm1I0wUHK1eJnn2y2w==
20622062

2063+
entities@~2.0.0:
2064+
version "2.0.3"
2065+
resolved "https://registry.yarnpkg.com/entities/-/entities-2.0.3.tgz#5c487e5742ab93c15abb5da22759b8590ec03b7f"
2066+
integrity sha512-MyoZ0jgnLvB2X3Lg5HqpFmn1kybDiIfEQmKzTb5apr51Rb+T3KdmMiqa70T+bhGnyv7bQ6WMj2QMHpGMmlrUYQ==
2067+
20632068
error-ex@^1.2.0:
20642069
version "1.3.2"
20652070
resolved "https://registry.yarnpkg.com/error-ex/-/error-ex-1.3.2.tgz#b4ac40648107fdcdcfae242f428bea8a14d4f1bf"
@@ -4357,13 +4362,13 @@ map-visit@^1.0.0:
43574362
dependencies:
43584363
object-visit "^1.0.0"
43594364

4360-
markdown-it@^8.3.1:
4361-
version "8.4.2"
4362-
resolved "https://registry.yarnpkg.com/markdown-it/-/markdown-it-8.4.2.tgz#386f98998dc15a37722aa7722084f4020bdd9b54"
4363-
integrity sha512-GcRz3AWTqSUphY3vsUqQSFMbgR38a4Lh3GWlHRh/7MRwz8mcu9n2IO7HOh+bXHrR9kOPDl5RNCaEsrneb+xhHQ==
4365+
markdown-it@^10.0.0:
4366+
version "10.0.0"
4367+
resolved "https://registry.yarnpkg.com/markdown-it/-/markdown-it-10.0.0.tgz#abfc64f141b1722d663402044e43927f1f50a8dc"
4368+
integrity sha512-YWOP1j7UbDNz+TumYP1kpwnP0aEa711cJjrAQrzd0UXlbJfc5aAq0F/PZHjiioqDC1NKgvIMX+o+9Bk7yuM2dg==
43644369
dependencies:
43654370
argparse "^1.0.7"
4366-
entities "~1.1.1"
4371+
entities "~2.0.0"
43674372
linkify-it "^2.0.0"
43684373
mdurl "^1.0.1"
43694374
uc.micro "^1.0.5"
@@ -6671,20 +6676,20 @@ vinyl@^2.0.0:
66716676
remove-trailing-separator "^1.0.1"
66726677
replace-ext "^1.0.0"
66736678

6674-
vsce@^1.69.0:
6675-
version "1.69.0"
6676-
resolved "https://registry.yarnpkg.com/vsce/-/vsce-1.69.0.tgz#3d862a42103192c1c79724d9fcb384a61e859d25"
6677-
integrity sha512-mRSlfrTb6rw8UVFZpJ3w++s0wd4S/OPjhUgSmspjiuy96HQEqOdpPF6S/ssYs0SqE/hMh6grmAYE0MLUmi1w4Q==
6679+
vsce@^1.77.0:
6680+
version "1.77.0"
6681+
resolved "https://registry.yarnpkg.com/vsce/-/vsce-1.77.0.tgz#21364d3e63095b2f54e0f185445e8ff6ab614602"
6682+
integrity sha512-8vOTCI3jGmOm0JJFu/BMAbqxpaSuka4S3hV9E6K5aWBUsDM1SGFExkIxHblnsI8sls43xP61DHorYT+K0F+GFA==
66786683
dependencies:
66796684
azure-devops-node-api "^7.2.0"
66806685
chalk "^2.4.2"
66816686
cheerio "^1.0.0-rc.1"
66826687
commander "^2.8.1"
66836688
denodeify "^1.2.1"
6684-
didyoumean "^1.2.1"
66856689
glob "^7.0.6"
6686-
lodash "^4.17.10"
6687-
markdown-it "^8.3.1"
6690+
leven "^3.1.0"
6691+
lodash "^4.17.15"
6692+
markdown-it "^10.0.0"
66886693
mime "^1.3.4"
66896694
minimatch "^3.0.3"
66906695
osenv "^0.1.3"

0 commit comments

Comments
 (0)