Skip to content

Commit

Permalink
Merge pull request #75 from vmware/retain-blueprint-metadata
Browse files Browse the repository at this point in the history
Keep vRA blueprint metadata like name, id and description in the YAML
  • Loading branch information
nblagoev authored Jul 22, 2020
2 parents deff5a6 + ad0f693 commit e346629
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 43 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
> and [vRealize Automation](https://www.vmware.com/products/vrealize-automation.html) content.
[![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)
[![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)
[![Build Status](https://github.com/vmware/vrealize-developer-tools/workflows/Build/badge.svg)](https://github.com/vmware/vrealize-developer-tools/actions)
[![Dependencies Status](https://david-dm.org/vmware/vrealize-developer-tools/status.svg)](https://david-dm.org/vmware/vrealize-developer-tools)
[![Coverage Status](https://codecov.io/gh/vmware/vrealize-developer-tools/branch/master/graph/badge.svg)](https://codecov.io/gh/vmware/vrealize-developer-tools/)

Expand Down
4 changes: 2 additions & 2 deletions common/src/rest/VraNgRestClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,11 @@ export class VraNgRestClient {
return this.unwrapPages(blueprints, "/blueprint/api/blueprints")
}

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

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

Expand Down
5 changes: 3 additions & 2 deletions extension/src/client/command/CreateBlueprint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@ export class CreateBlueprint extends BaseVraCommand {
})

if (!newFile) {
return Promise.reject("Save dialog was canceled")
this.logger.warn("Save dialog was canceled")
return
}

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

vscode.window
Expand Down
21 changes: 14 additions & 7 deletions extension/src/client/command/DeployBlueprint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as path from "path"

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

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

const restClient = await this.getRestClient()

const blueprintContent = activeTextEditor.document.getText()
const blueprintName = path.basename(activeTextEditor.document.fileName).replace(".yaml", "")
const existingBlueprint = await restClient.getBlueprintByName(blueprintName)
const blueprintYaml = parseYaml(activeTextEditor.document.getText())
const blueprintName = blueprintYaml.name || path.basename(activeTextEditor.document.fileName).replace(".yaml", "")
const blueprintDescription = blueprintYaml.description || ""
const blueprintContent = stringifyYaml(blueprintYaml.content)
const existingBlueprint = blueprintYaml.id
? await restClient.getBlueprintById(blueprintYaml.id)
: await restClient.getBlueprintByName(blueprintName)

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

await restClient.updateBlueprint(existingBlueprint.id, {
name: existingBlueprint.name,
description: blueprintDescription,
projectId: existingBlueprint.projectId,
content: blueprintContent
})
Expand All @@ -77,7 +82,7 @@ export class DeployBlueprint extends BaseVraCommand {
restClient,
existingBlueprint.projectId,
deploymentName,
blueprintContent,
stringifyYaml(blueprintYaml.content),
existingBlueprint.id
)
}
Expand All @@ -89,11 +94,13 @@ export class DeployBlueprint extends BaseVraCommand {
this.logger.debug("Selected project and deployment name: ", state)

if (!state.projectId) {
return Promise.reject("No project was selected")
this.logger.warn("No project was selected")
return
}

if (!state.deploymentName) {
return Promise.reject("No deployment name was provided")
this.logger.warn("No deployment name was provided")
return
}

return this.doDeploy(context, restClient, state.projectId, state.deploymentName, blueprintContent, undefined)
Expand Down
25 changes: 18 additions & 7 deletions extension/src/client/command/FetchBlueprint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import * as path from "path"

import { AutoWire, Logger } from "vrealize-common"
import * as vscode from "vscode"
import { parse as parseYaml, Document as YamlDocument } from "yaml"

import { Commands } from "../constants"
import { ConfigurationManager, EnvironmentManager } from "../system"
Expand Down Expand Up @@ -45,16 +46,18 @@ export class GetBlueprint extends BaseVraCommand {
)

const selected: BlueprintPickInfo | undefined = await vscode.window.showQuickPick(blueprintsFuture, {
placeHolder: "Pick a blueprint"
placeHolder: "Pick a blueprint",
matchOnDescription: true
})

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

if (!selected) {
return Promise.reject("No blueprint selection was made")
this.logger.warn("No blueprint selection was made")
return
}

let blueprintContent: string = ""
const blueprintYaml = new YamlDocument()
await vscode.window.withProgress(
{
location: vscode.ProgressLocation.Notification,
Expand All @@ -63,11 +66,18 @@ export class GetBlueprint extends BaseVraCommand {
},
async () => {
const blueprint = await restClient.getBlueprintById(selected.id)
blueprintContent = blueprint.content

blueprintYaml.contents = {
id: blueprint.id,
name: blueprint.name,
description: blueprint.description,
requestScopeOrg: blueprint.requestScopeOrg,
content: parseYaml(blueprint.content)
}
}
)

if (!blueprintContent) {
if (!blueprintYaml.contents) {
return Promise.reject("Could not fetch blueprint or it has empty content")
}

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

if (!newFile) {
return Promise.reject("Save dialog was canceled")
this.logger.warn("Save dialog was canceled")
return
}

this.logger.debug(`Saving the selected blueprint at ${newFile.toString()}`)
await vscode.workspace.fs.writeFile(newFile, Buffer.from(blueprintContent))
await vscode.workspace.fs.writeFile(newFile, Buffer.from(blueprintYaml.toString()))
await vscode.window.showTextDocument(newFile, { preview: false })
}
}
22 changes: 16 additions & 6 deletions extension/src/client/command/UploadBlueprint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import * as path from "path"

import { AutoWire, Logger } from "vrealize-common"
import * as vscode from "vscode"
import { parse as parseYaml, stringify as stringifyYaml } from "yaml"

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

const restClient = await this.getRestClient()

const blueprintContent = activeTextEditor.document.getText()
const blueprintName = path.basename(activeTextEditor.document.fileName).replace(".yaml", "")
const existingBlueprint = await restClient.getBlueprintByName(blueprintName)
const blueprintYaml = parseYaml(activeTextEditor.document.getText())
const blueprintName = blueprintYaml.name || path.basename(activeTextEditor.document.fileName).replace(".yaml", "")
const blueprintDescription = blueprintYaml.description || ""
const existingBlueprint = blueprintYaml.id
? await restClient.getBlueprintById(blueprintYaml.id)
: await restClient.getBlueprintByName(blueprintName)

if (existingBlueprint) {
await restClient.updateBlueprint(existingBlueprint.id, {
name: existingBlueprint.name,
description: blueprintDescription,
projectId: existingBlueprint.projectId,
content: blueprintContent
content: stringifyYaml(blueprintYaml.content)
})

vscode.window.showInformationMessage(`Blueprint '${blueprintName}' has been updated`)
return
}

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

if (!selectedProject) {
return Promise.reject("No blueprint selection was made")
this.logger.warn("No project selection was made")
return
}

await restClient.createBlueprint({
name: blueprintName,
description: blueprintDescription,
projectId: selectedProject.id,
content: blueprintContent
content: stringifyYaml(blueprintYaml.content)
})

vscode.window.showInformationMessage(`Blueprint '${blueprintName}' has been created`)
}
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,7 @@
"@types/fs-extra": "~5.0.4",
"@types/glob": "7.1.1",
"@types/jest": "^24.9.1",
"@types/jwt-decode": "^2.2.1",
"@types/keytar": "^4.4.2",
"@types/lodash": "^4.14.149",
"@types/micromatch": "^3.1.1",
Expand Down Expand Up @@ -580,7 +581,7 @@
"prettier": "^1.19.1",
"ts-jest": "^25.0.0",
"typescript": "~3.7.2",
"vsce": "^1.69.0"
"vsce": "^1.77.0"
},
"dependencies": {
"adm-zip": "^0.4.13",
Expand Down
39 changes: 22 additions & 17 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,11 @@
resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.3.tgz#bdfd69d61e464dcc81b25159c270d75a73c1a636"
integrity sha512-Il2DtDVRGDcqjDtE+rF8iqg1CArehSK84HZJCT7AMITlyXRBpuPhqGLDQMowraqqu1coEaimg4ZOqggt6L6L+A==

"@types/jwt-decode@^2.2.1":
version "2.2.1"
resolved "https://registry.yarnpkg.com/@types/jwt-decode/-/jwt-decode-2.2.1.tgz#afdf5c527fcfccbd4009b5fd02d1e18241f2d2f2"
integrity sha512-aWw2YTtAdT7CskFyxEX2K21/zSDStuf/ikI3yBqmwpwJF0pS+/IX5DWv+1UFffZIbruP6cnT9/LAJV1gFwAT1A==

"@types/keytar@^4.4.2":
version "4.4.2"
resolved "https://registry.yarnpkg.com/@types/keytar/-/keytar-4.4.2.tgz#49ef917d6cbb4f19241c0ab50cd35097b5729b32"
Expand Down Expand Up @@ -1922,11 +1927,6 @@ detect-newline@^3.0.0:
resolved "https://registry.yarnpkg.com/detect-newline/-/detect-newline-3.1.0.tgz#576f5dfc63ae1a192ff192d8ad3af6308991b651"
integrity sha1-V29d/GOuGhkv8ZLYrTr2MImRtlE=

didyoumean@^1.2.1:
version "1.2.1"
resolved "https://registry.yarnpkg.com/didyoumean/-/didyoumean-1.2.1.tgz#e92edfdada6537d484d73c0172fd1eba0c4976ff"
integrity sha1-6S7f2tplN9SE1zwBcv0eugxJdv8=

diff-sequences@^24.9.0:
version "24.9.0"
resolved "https://registry.yarnpkg.com/diff-sequences/-/diff-sequences-24.9.0.tgz#5715d6244e2aa65f48bba0bc972db0b0b11e95b5"
Expand Down Expand Up @@ -2060,6 +2060,11 @@ entities@^1.1.1, entities@~1.1.1:
resolved "https://registry.yarnpkg.com/entities/-/entities-1.1.2.tgz#bdfa735299664dfafd34529ed4f8522a275fea56"
integrity sha512-f2LZMYl1Fzu7YSBKg+RoROelpOaNrcGmE9AZubeDfrCEia483oW4MI4VyFd5VNHIgQ/7qm1I0wUHK1eJnn2y2w==

entities@~2.0.0:
version "2.0.3"
resolved "https://registry.yarnpkg.com/entities/-/entities-2.0.3.tgz#5c487e5742ab93c15abb5da22759b8590ec03b7f"
integrity sha512-MyoZ0jgnLvB2X3Lg5HqpFmn1kybDiIfEQmKzTb5apr51Rb+T3KdmMiqa70T+bhGnyv7bQ6WMj2QMHpGMmlrUYQ==

error-ex@^1.2.0:
version "1.3.2"
resolved "https://registry.yarnpkg.com/error-ex/-/error-ex-1.3.2.tgz#b4ac40648107fdcdcfae242f428bea8a14d4f1bf"
Expand Down Expand Up @@ -4357,13 +4362,13 @@ map-visit@^1.0.0:
dependencies:
object-visit "^1.0.0"

markdown-it@^8.3.1:
version "8.4.2"
resolved "https://registry.yarnpkg.com/markdown-it/-/markdown-it-8.4.2.tgz#386f98998dc15a37722aa7722084f4020bdd9b54"
integrity sha512-GcRz3AWTqSUphY3vsUqQSFMbgR38a4Lh3GWlHRh/7MRwz8mcu9n2IO7HOh+bXHrR9kOPDl5RNCaEsrneb+xhHQ==
markdown-it@^10.0.0:
version "10.0.0"
resolved "https://registry.yarnpkg.com/markdown-it/-/markdown-it-10.0.0.tgz#abfc64f141b1722d663402044e43927f1f50a8dc"
integrity sha512-YWOP1j7UbDNz+TumYP1kpwnP0aEa711cJjrAQrzd0UXlbJfc5aAq0F/PZHjiioqDC1NKgvIMX+o+9Bk7yuM2dg==
dependencies:
argparse "^1.0.7"
entities "~1.1.1"
entities "~2.0.0"
linkify-it "^2.0.0"
mdurl "^1.0.1"
uc.micro "^1.0.5"
Expand Down Expand Up @@ -6671,20 +6676,20 @@ vinyl@^2.0.0:
remove-trailing-separator "^1.0.1"
replace-ext "^1.0.0"

vsce@^1.69.0:
version "1.69.0"
resolved "https://registry.yarnpkg.com/vsce/-/vsce-1.69.0.tgz#3d862a42103192c1c79724d9fcb384a61e859d25"
integrity sha512-mRSlfrTb6rw8UVFZpJ3w++s0wd4S/OPjhUgSmspjiuy96HQEqOdpPF6S/ssYs0SqE/hMh6grmAYE0MLUmi1w4Q==
vsce@^1.77.0:
version "1.77.0"
resolved "https://registry.yarnpkg.com/vsce/-/vsce-1.77.0.tgz#21364d3e63095b2f54e0f185445e8ff6ab614602"
integrity sha512-8vOTCI3jGmOm0JJFu/BMAbqxpaSuka4S3hV9E6K5aWBUsDM1SGFExkIxHblnsI8sls43xP61DHorYT+K0F+GFA==
dependencies:
azure-devops-node-api "^7.2.0"
chalk "^2.4.2"
cheerio "^1.0.0-rc.1"
commander "^2.8.1"
denodeify "^1.2.1"
didyoumean "^1.2.1"
glob "^7.0.6"
lodash "^4.17.10"
markdown-it "^8.3.1"
leven "^3.1.0"
lodash "^4.17.15"
markdown-it "^10.0.0"
mime "^1.3.4"
minimatch "^3.0.3"
osenv "^0.1.3"
Expand Down

0 comments on commit e346629

Please sign in to comment.