consuming latest package version

This commit is contained in:
Sumiran Aggarwal
2019-11-08 10:33:24 +05:30
parent 691d3a0f33
commit 0d77ccf518
25 changed files with 500 additions and 517 deletions

View File

@@ -1,8 +1,8 @@
{
"_from": "actions-secret-parser@^1.0.1",
"_id": "actions-secret-parser@1.0.1",
"_id": "actions-secret-parser@1.0.2",
"_inBundle": false,
"_integrity": "sha512-4xenKyEwVp23mKVPUdP/NfipbrmFNbjf5+1FBAbGNdmMO+Awjoh4TnxrPdTy5yN7N6JUOBEtUgVVcOvzxfJu/Q==",
"_integrity": "sha512-TfhtynQqxPO1b+o1AJAvuVdhI98lAGCQbwoOGRvwFCd1nxhZugZNBrCxfVWUN8P1J5x6Xw0QNBqSe7cCugUZ/w==",
"_location": "/actions-secret-parser",
"_phantomChildren": {},
"_requested": {
@@ -16,10 +16,11 @@
"fetchSpec": "^1.0.1"
},
"_requiredBy": [
"#USER",
"/"
],
"_resolved": "https://registry.npmjs.org/actions-secret-parser/-/actions-secret-parser-1.0.1.tgz",
"_shasum": "d0298dceb0858e2e8c5addb3a16bfbaf75428dab",
"_resolved": "https://registry.npmjs.org/actions-secret-parser/-/actions-secret-parser-1.0.2.tgz",
"_shasum": "8bf3b0bcbb523afe5d7a92c32d9facb1fdbd64b1",
"_spec": "actions-secret-parser@^1.0.1",
"_where": "D:\\GithubActions\\login",
"author": {
@@ -41,6 +42,9 @@
"devDependencies": {
"typescript": "^3.6.3"
},
"files": [
"lib/**/**"
],
"homepage": "https://github.com/Microsoft/pipelines-appservice-lib/tree/master/packages/utility",
"keywords": [
"secret",
@@ -58,5 +62,5 @@
"prepare": "npm run build",
"test": "echo \"Error: no test specified\" && exit 1"
},
"version": "1.0.1"
"version": "1.0.2"
}

View File

@@ -1,97 +0,0 @@
var core = require('@actions/core');
var jp = require('jsonpath');
var xpath = require('xpath');
var domParser = require('xmldom').DOMParser;
export enum FormatType {
"JSON",
"XML"
}
/**
* Takes content as string and format type (xml, json).
* Exposes getSecret method to get value of specific secret in object and set it as secret.
*/
export class SecretParser {
private dom: string;
private contentType: FormatType;
constructor(content: string, contentType: FormatType) {
switch(contentType) {
case FormatType.JSON:
try {
this.dom = JSON.parse(content);
}
catch (ex) {
throw new Error('Content is not a valid JSON object');
}
break;
case FormatType.XML:
try {
this.dom = new domParser().parseFromString(content);
}
catch (ex) {
throw new Error('Content is not a valid XML object');
}
break;
default:
throw new Error(`Given format: ${contentType} is not supported. Valid options are JSON, XML.`)
}
this.contentType = contentType;
}
/**
*
* @param key jsonpath or xpath depending on content type
* @param isSecret should the value parsed be a secret. Deafult: true
* @param variableName optional. If provided value will be exported with this variable name
* @returns a string value or empty string if key not found
*/
public getSecret(key: string, isSecret: boolean = true, variableName?: string): string {
let value: string = "";
switch(this.contentType) {
case FormatType.JSON:
value = this.extractJsonPath(key, isSecret, variableName);
break;
case FormatType.XML:
value = this.extractXmlPath(key, isSecret, variableName);
break;
}
return value;
}
private extractJsonPath(key: string, isSecret: boolean = false, variableName?: string): string {
let value = jp.query(this.dom, key);
if(value.length == 0) {
core.debug("Cannot find key: " + key)
return "";
}
else if(value.length > 1) {
core.debug("Multiple values found for key: " + key + ". Please give jsonPath which points to a single value.");
return "";
}
return this.handleSecret(key, value[0], isSecret, variableName);
}
private extractXmlPath(key: string, isSecret: boolean = false, variableName?: string): string {
let value = xpath.select("string(" + key + ")", this.dom);
return this.handleSecret(key, value, isSecret, variableName);
}
private handleSecret(key: string, value: string, isSecret: boolean, variableName: string): string {
if(!!value) {
if(isSecret) {
core.setSecret(value);
}
if(!!variableName) {
core.exportVariable(variableName, value);
}
return value;
}
else {
core.debug("Cannot find key: " + key);
return "";
}
}
}

View File

@@ -1,11 +0,0 @@
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"declaration": true,
"outDir": "./lib",
"strict": false
},
"include": ["src"],
"exclude": ["node_modules", "**/__tests__/*"]
}