@adinsure-ops/ops-cli 4.0.0-rc6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOGS.md +55 -0
- package/LICENSE +1 -0
- package/README.md +576 -0
- package/bin/run +5 -0
- package/bin/run.cmd +3 -0
- package/lib/command.base.d.ts +17 -0
- package/lib/command.base.jira.d.ts +11 -0
- package/lib/command.base.jira.js +37 -0
- package/lib/command.base.js +73 -0
- package/lib/commands/doctor.d.ts +54 -0
- package/lib/commands/doctor.js +311 -0
- package/lib/commands/download/client.d.ts +18 -0
- package/lib/commands/download/client.js +72 -0
- package/lib/commands/download/identity-server.d.ts +18 -0
- package/lib/commands/download/identity-server.js +72 -0
- package/lib/commands/download/platform.d.ts +18 -0
- package/lib/commands/download/platform.js +72 -0
- package/lib/commands/download/scheduler.d.ts +18 -0
- package/lib/commands/download/scheduler.js +72 -0
- package/lib/commands/download/server.d.ts +18 -0
- package/lib/commands/download/server.js +72 -0
- package/lib/commands/download/studio.d.ts +20 -0
- package/lib/commands/download/studio.js +89 -0
- package/lib/commands/gitlab/next-nightly-tag.d.ts +30 -0
- package/lib/commands/gitlab/next-nightly-tag.js +171 -0
- package/lib/commands/jira/issue.d.ts +17 -0
- package/lib/commands/jira/issue.js +31 -0
- package/lib/commands/jira/labels.d.ts +22 -0
- package/lib/commands/jira/labels.js +70 -0
- package/lib/commands/log/add.d.ts +17 -0
- package/lib/commands/log/add.js +107 -0
- package/lib/commands/log/generate.d.ts +22 -0
- package/lib/commands/log/generate.js +155 -0
- package/lib/commands/log/validate.d.ts +11 -0
- package/lib/commands/log/validate.js +58 -0
- package/lib/commands/login.d.ts +23 -0
- package/lib/commands/login.js +144 -0
- package/lib/commands/npm/check.publish.d.ts +17 -0
- package/lib/commands/npm/check.publish.js +78 -0
- package/lib/commands/npm/publish.d.ts +23 -0
- package/lib/commands/npm/publish.js +163 -0
- package/lib/commands/prepare-content.d.ts +29 -0
- package/lib/commands/prepare-content.js +386 -0
- package/lib/commands/sql.d.ts +24 -0
- package/lib/commands/sql.js +147 -0
- package/lib/commands/translate.d.ts +37 -0
- package/lib/commands/translate.js +149 -0
- package/lib/commands/version.d.ts +48 -0
- package/lib/commands/version.js +267 -0
- package/lib/config.d.ts +7 -0
- package/lib/config.js +9 -0
- package/lib/hooks/init/version-override.d.ts +2 -0
- package/lib/hooks/init/version-override.js +15 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +4 -0
- package/lib/lib/command.d.ts +9 -0
- package/lib/lib/command.js +71 -0
- package/lib/lib/npm.d.ts +15 -0
- package/lib/lib/npm.js +79 -0
- package/lib/lib/npmrc.d.ts +17 -0
- package/lib/lib/npmrc.js +44 -0
- package/lib/security/cache.d.ts +7 -0
- package/lib/security/cache.js +33 -0
- package/lib/security/context.d.ts +58 -0
- package/lib/security/context.js +224 -0
- package/lib/types/changelog.types.d.ts +6 -0
- package/lib/types/changelog.types.js +2 -0
- package/lib/types/npm.types.d.ts +34 -0
- package/lib/types/npm.types.js +2 -0
- package/oclif.manifest.json +1 -0
- package/package.json +118 -0
package/lib/config.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.versionOverride = void 0;
|
|
4
|
+
const version_1 = require("../../commands/version");
|
|
5
|
+
exports.versionOverride = async function () {
|
|
6
|
+
if (process.argv[2] === 'version') {
|
|
7
|
+
try {
|
|
8
|
+
await version_1.default.run(process.argv.splice(3));
|
|
9
|
+
}
|
|
10
|
+
catch (err) {
|
|
11
|
+
this.error(err);
|
|
12
|
+
}
|
|
13
|
+
return process.exit(0);
|
|
14
|
+
}
|
|
15
|
+
};
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { run } from '@oclif/command';
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const child_process_1 = require("child_process");
|
|
5
|
+
class ChildProcessCommand {
|
|
6
|
+
/**
|
|
7
|
+
* Only Windows supported at this point
|
|
8
|
+
*/
|
|
9
|
+
async runCommand(cmd) {
|
|
10
|
+
var e_1, _a, e_2, _b;
|
|
11
|
+
let sh;
|
|
12
|
+
let args;
|
|
13
|
+
let cp;
|
|
14
|
+
// cross platform compatibility
|
|
15
|
+
if (process.platform === 'win32') {
|
|
16
|
+
sh = 'cmd';
|
|
17
|
+
args = ['/c'].concat(cmd);
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
[sh, ...args] = cmd;
|
|
21
|
+
}
|
|
22
|
+
try {
|
|
23
|
+
cp = child_process_1.spawn(sh, args, {
|
|
24
|
+
// cwd:
|
|
25
|
+
// pkg.path,
|
|
26
|
+
env: Object.assign(Object.assign({}, process.env), process.stdout.isTTY ? { FORCE_COLOR: process.env.FORCE_COLOR || '1' } : {}),
|
|
27
|
+
stdio: 'pipe',
|
|
28
|
+
shell: true
|
|
29
|
+
});
|
|
30
|
+
let data = '';
|
|
31
|
+
try {
|
|
32
|
+
for (var _c = tslib_1.__asyncValues(cp.stdout), _d; _d = await _c.next(), !_d.done;) {
|
|
33
|
+
const chunk = _d.value;
|
|
34
|
+
data += chunk;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
38
|
+
finally {
|
|
39
|
+
try {
|
|
40
|
+
if (_d && !_d.done && (_a = _c.return)) await _a.call(_c);
|
|
41
|
+
}
|
|
42
|
+
finally { if (e_1) throw e_1.error; }
|
|
43
|
+
}
|
|
44
|
+
let error = '';
|
|
45
|
+
try {
|
|
46
|
+
for (var _e = tslib_1.__asyncValues(cp.stderr), _f; _f = await _e.next(), !_f.done;) {
|
|
47
|
+
const chunk = _f.value;
|
|
48
|
+
error += chunk;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
52
|
+
finally {
|
|
53
|
+
try {
|
|
54
|
+
if (_f && !_f.done && (_b = _e.return)) await _b.call(_e);
|
|
55
|
+
}
|
|
56
|
+
finally { if (e_2) throw e_2.error; }
|
|
57
|
+
}
|
|
58
|
+
const exitCode = await new Promise((resolve, _reject) => {
|
|
59
|
+
cp.on('close', resolve);
|
|
60
|
+
});
|
|
61
|
+
if (exitCode) {
|
|
62
|
+
throw new Error(`subprocess error exit ${exitCode}, ${error}`);
|
|
63
|
+
}
|
|
64
|
+
return { data, error };
|
|
65
|
+
}
|
|
66
|
+
catch (err) {
|
|
67
|
+
throw new Error(err.message);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
exports.default = ChildProcessCommand;
|
package/lib/lib/npm.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { NpmPackage } from '../types/npm.types';
|
|
2
|
+
export default class NpmContext {
|
|
3
|
+
/**
|
|
4
|
+
* Get all workspaces
|
|
5
|
+
*/
|
|
6
|
+
getWorkspaces(): Promise<string[]>;
|
|
7
|
+
/**
|
|
8
|
+
* Get package names
|
|
9
|
+
*/
|
|
10
|
+
packageList(packages: string[] | undefined, excludes: string[] | undefined, context: any): Promise<NpmPackage[]>;
|
|
11
|
+
/**
|
|
12
|
+
* Get package all packages
|
|
13
|
+
*/
|
|
14
|
+
getAllNpmPackages(patToken?: string): Promise<string>;
|
|
15
|
+
}
|
package/lib/lib/npm.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const chalk_1 = require("chalk");
|
|
4
|
+
const fs = require("fs-extra");
|
|
5
|
+
const globby = require("globby");
|
|
6
|
+
const minimatch = require("minimatch");
|
|
7
|
+
const path = require("path");
|
|
8
|
+
const request = require("request-promise");
|
|
9
|
+
class NpmContext {
|
|
10
|
+
/**
|
|
11
|
+
* Get all workspaces
|
|
12
|
+
*/
|
|
13
|
+
async getWorkspaces() {
|
|
14
|
+
let workspaces = [];
|
|
15
|
+
try {
|
|
16
|
+
let data = await fs.readJSON('./package.json');
|
|
17
|
+
if (!data.workspaces) {
|
|
18
|
+
return [];
|
|
19
|
+
}
|
|
20
|
+
for (const workspace of data.workspaces.packages) {
|
|
21
|
+
workspaces.push(`${workspace}/+(package.json|yarn.json)`);
|
|
22
|
+
}
|
|
23
|
+
return workspaces;
|
|
24
|
+
}
|
|
25
|
+
catch (err) {
|
|
26
|
+
throw new Error(err.message);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Get package names
|
|
31
|
+
*/
|
|
32
|
+
async packageList(packages = ['**/*'], excludes = [''], context) {
|
|
33
|
+
try {
|
|
34
|
+
let workspaces = await this.getWorkspaces();
|
|
35
|
+
let searchPattern = ['**/package.json', '!**/node_modules'];
|
|
36
|
+
let pkgs = [];
|
|
37
|
+
if (workspaces.length > 0) {
|
|
38
|
+
searchPattern = workspaces.concat(['!**/node_modules']);
|
|
39
|
+
}
|
|
40
|
+
const pkgPaths = await globby(searchPattern);
|
|
41
|
+
for (const pkgPath of pkgPaths) {
|
|
42
|
+
try {
|
|
43
|
+
let data = await fs.readJSON(pkgPath);
|
|
44
|
+
if (!data.version || !data.name || excludes.indexOf(data.name) >= 0 || !packages.some(pkg => minimatch(data.name, pkg))) {
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
// create object to simply remove duplicates
|
|
48
|
+
pkgs[data.name] = {
|
|
49
|
+
name: data.name,
|
|
50
|
+
path: path.dirname(pkgPath),
|
|
51
|
+
jsonPath: pkgPath,
|
|
52
|
+
version: data.version
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
catch (err) {
|
|
56
|
+
context.warn(`Error reading package.json: ${chalk_1.default.yellow(err.message)}.`);
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return Object.values(pkgs); // return array of values
|
|
61
|
+
}
|
|
62
|
+
catch (err) {
|
|
63
|
+
throw new Error(`Unknown error: ${chalk_1.default.red(err)}`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Get package all packages
|
|
68
|
+
*/
|
|
69
|
+
async getAllNpmPackages(patToken = '') {
|
|
70
|
+
let options = {
|
|
71
|
+
uri: `https://feeds.dev.azure.com/adacta-fintech/adinsure/_apis/packaging/Feeds/feed/packages?api-version=6.0-preview.1&includeAllVersions=true&protocolType=Npm`,
|
|
72
|
+
headers: {
|
|
73
|
+
Authorization: 'Basic ' + Buffer.from(`:${patToken}`).toString('base64')
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
return request.get(options);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
exports.default = NpmContext;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export default class NpmRc {
|
|
2
|
+
private filePath;
|
|
3
|
+
private config;
|
|
4
|
+
constructor(createIfNotExists?: boolean);
|
|
5
|
+
/**
|
|
6
|
+
* Load config file
|
|
7
|
+
*/
|
|
8
|
+
load(): Promise<void>;
|
|
9
|
+
/**
|
|
10
|
+
* Add registry to config file
|
|
11
|
+
*/
|
|
12
|
+
set(key: string, value: string): Promise<void>;
|
|
13
|
+
/**
|
|
14
|
+
* Set token for Registry
|
|
15
|
+
*/
|
|
16
|
+
save(): Promise<void>;
|
|
17
|
+
}
|
package/lib/lib/npmrc.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const fs = require("fs");
|
|
4
|
+
const child_process_1 = require("child_process");
|
|
5
|
+
const os = require("os");
|
|
6
|
+
const ini = require("ini");
|
|
7
|
+
class NpmRc {
|
|
8
|
+
constructor(createIfNotExists = true) {
|
|
9
|
+
this.config = {};
|
|
10
|
+
try {
|
|
11
|
+
this.filePath = child_process_1.execSync("npm config get userconfig", { stdio: ["pipe", "pipe", "ignore"] })
|
|
12
|
+
.toString()
|
|
13
|
+
.trim();
|
|
14
|
+
}
|
|
15
|
+
catch (_a) {
|
|
16
|
+
this.filePath = os.homedir();
|
|
17
|
+
}
|
|
18
|
+
if (!fs.existsSync(this.filePath) && createIfNotExists) {
|
|
19
|
+
fs.writeFileSync(this.filePath, JSON.stringify({}));
|
|
20
|
+
}
|
|
21
|
+
if (fs.existsSync(this.filePath)) {
|
|
22
|
+
this.load();
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Load config file
|
|
27
|
+
*/
|
|
28
|
+
async load() {
|
|
29
|
+
this.config = ini.parse(fs.readFileSync(this.filePath, "utf8"));
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Add registry to config file
|
|
33
|
+
*/
|
|
34
|
+
async set(key, value) {
|
|
35
|
+
this.config[key] = value;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Set token for Registry
|
|
39
|
+
*/
|
|
40
|
+
async save() {
|
|
41
|
+
fs.writeFileSync(this.filePath, ini.encode(this.config));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.default = NpmRc;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ICachePlugin } from '@azure/msal-node';
|
|
2
|
+
export default class LocalCachePlugin implements ICachePlugin {
|
|
3
|
+
private readonly _accessTokenPath;
|
|
4
|
+
constructor(path: string);
|
|
5
|
+
beforeCacheAccess(cacheContext: any): Promise<void>;
|
|
6
|
+
afterCacheAccess(cacheContext: any): Promise<void>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const path = require("path");
|
|
4
|
+
const fs = require("fs-extra");
|
|
5
|
+
class LocalCachePlugin {
|
|
6
|
+
constructor(path) {
|
|
7
|
+
this._accessTokenPath = path;
|
|
8
|
+
}
|
|
9
|
+
async beforeCacheAccess(cacheContext) {
|
|
10
|
+
// Create folder if doesn't exists
|
|
11
|
+
if (!fs.pathExistsSync(path.dirname(this._accessTokenPath))) {
|
|
12
|
+
fs.mkdirSync(path.dirname(this._accessTokenPath), {
|
|
13
|
+
recursive: true
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
// Load file only if exists
|
|
17
|
+
if (fs.existsSync(this._accessTokenPath)) {
|
|
18
|
+
cacheContext.tokenCache.deserialize(await fs.readFile(this._accessTokenPath, "utf-8"));
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
async afterCacheAccess(cacheContext) {
|
|
22
|
+
// Create folder if doesn't exists
|
|
23
|
+
if (!fs.pathExistsSync(path.dirname(this._accessTokenPath))) {
|
|
24
|
+
fs.mkdirSync(path.dirname(this._accessTokenPath), {
|
|
25
|
+
recursive: true
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
if (cacheContext.cacheHasChanged) {
|
|
29
|
+
await fs.writeFile(this._accessTokenPath, cacheContext.tokenCache.serialize());
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.default = LocalCachePlugin;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { ParsedUrlQuery } from 'querystring';
|
|
3
|
+
/**
|
|
4
|
+
* Security context that keeps track of current authentication token.
|
|
5
|
+
* It's not recommended you instantiate this class on your own but rather inherit your commands from [[CommandBase]].
|
|
6
|
+
*/
|
|
7
|
+
export default class SecurityContext {
|
|
8
|
+
private readonly clientId;
|
|
9
|
+
private readonly devopsResourceId;
|
|
10
|
+
private readonly tenant;
|
|
11
|
+
private readonly authorityUrl;
|
|
12
|
+
private readonly redirectUri;
|
|
13
|
+
private readonly resource;
|
|
14
|
+
private readonly _accessTokenPath;
|
|
15
|
+
private _pca;
|
|
16
|
+
private _cryptoProvider;
|
|
17
|
+
private _verifier;
|
|
18
|
+
private _challenge;
|
|
19
|
+
/**
|
|
20
|
+
* Initializes [[SecurityContext]] with config directory where access token JSON will be stored.
|
|
21
|
+
* @param configDir Directory where CLI configuration is stored
|
|
22
|
+
*/
|
|
23
|
+
constructor(configDir: string);
|
|
24
|
+
/**
|
|
25
|
+
* Contacts authority server, fetches and saves the authentication token to be used in subsequent requests.
|
|
26
|
+
*
|
|
27
|
+
* @param code Authorization code used to fetch the token.
|
|
28
|
+
* @returns [[Promise<TokenResponse>]]
|
|
29
|
+
*/
|
|
30
|
+
getLoginUrl(): Promise<string>;
|
|
31
|
+
/**
|
|
32
|
+
* Gets the current authentication token.
|
|
33
|
+
* This function will also automatically try to refresh token if expired.
|
|
34
|
+
*
|
|
35
|
+
* @throws Error when authentication failed and/or call to login is needed
|
|
36
|
+
* @returns Promise that resolves bearer authentication token
|
|
37
|
+
*/
|
|
38
|
+
getToken(): Promise<string>;
|
|
39
|
+
/**
|
|
40
|
+
* Contacts authority server, fetches and saves the authentication token to be used in subsequent requests.
|
|
41
|
+
*
|
|
42
|
+
* @param code Authorization code used to fetch the token.
|
|
43
|
+
* @returns [[Promise<TokenResponse>]]
|
|
44
|
+
*/
|
|
45
|
+
acquireToken(query: ParsedUrlQuery): Promise<string>;
|
|
46
|
+
/**
|
|
47
|
+
* Acquires token using device flow.
|
|
48
|
+
*
|
|
49
|
+
* @returns [[Promise<TokenResponse>]]
|
|
50
|
+
*/
|
|
51
|
+
acquireTokenDeviceFlow(): Promise<void>;
|
|
52
|
+
/**
|
|
53
|
+
* Get NPM token for adinsure npm repositories
|
|
54
|
+
*
|
|
55
|
+
* @returns [[Promise<string>]]
|
|
56
|
+
*/
|
|
57
|
+
getNPMToken(): Promise<string>;
|
|
58
|
+
}
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const msal_node_1 = require("@azure/msal-node");
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const cache_1 = require("./cache");
|
|
6
|
+
/**
|
|
7
|
+
* Security context that keeps track of current authentication token.
|
|
8
|
+
* It's not recommended you instantiate this class on your own but rather inherit your commands from [[CommandBase]].
|
|
9
|
+
*/
|
|
10
|
+
class SecurityContext {
|
|
11
|
+
/**
|
|
12
|
+
* Initializes [[SecurityContext]] with config directory where access token JSON will be stored.
|
|
13
|
+
* @param configDir Directory where CLI configuration is stored
|
|
14
|
+
*/
|
|
15
|
+
constructor(configDir) {
|
|
16
|
+
this.clientId = 'bed40d09-53d7-4af8-bf63-3288658b65fb';
|
|
17
|
+
this.devopsResourceId = '499b84ac-1321-427f-aa17-267ca6975798';
|
|
18
|
+
this.tenant = 'adfintech.onmicrosoft.com';
|
|
19
|
+
this.authorityUrl = `https://login.microsoftonline.com/${this.tenant}/`;
|
|
20
|
+
// tslint:disable-next-line: no-http-string
|
|
21
|
+
this.redirectUri = 'http://localhost:3044';
|
|
22
|
+
this.resource = 'https://ops.adinsure.com';
|
|
23
|
+
this._verifier = null;
|
|
24
|
+
this._challenge = null;
|
|
25
|
+
this._accessTokenPath = path.resolve(configDir, 'accessToken.json');
|
|
26
|
+
this._cryptoProvider = new msal_node_1.CryptoProvider();
|
|
27
|
+
this._pca = new msal_node_1.PublicClientApplication({
|
|
28
|
+
auth: {
|
|
29
|
+
clientId: this.clientId,
|
|
30
|
+
authority: this.authorityUrl
|
|
31
|
+
},
|
|
32
|
+
cache: {
|
|
33
|
+
cachePlugin: new cache_1.default(this._accessTokenPath),
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Contacts authority server, fetches and saves the authentication token to be used in subsequent requests.
|
|
39
|
+
*
|
|
40
|
+
* @param code Authorization code used to fetch the token.
|
|
41
|
+
* @returns [[Promise<TokenResponse>]]
|
|
42
|
+
*/
|
|
43
|
+
getLoginUrl() {
|
|
44
|
+
return new Promise((resolve, reject) => {
|
|
45
|
+
// Generate PKCE Codes before starting the authorization flow
|
|
46
|
+
this._cryptoProvider.generatePkceCodes().then(({ verifier, challenge }) => {
|
|
47
|
+
this._verifier = verifier;
|
|
48
|
+
this._challenge = challenge;
|
|
49
|
+
const authCodeUrlParameters = {
|
|
50
|
+
scopes: [this.resource + "/.default"],
|
|
51
|
+
redirectUri: this.redirectUri,
|
|
52
|
+
codeChallenge: this._challenge,
|
|
53
|
+
codeChallengeMethod: 'S256'
|
|
54
|
+
};
|
|
55
|
+
// Get url to sign user in and consent to scopes needed for applicatio
|
|
56
|
+
this._pca.getAuthCodeUrl(authCodeUrlParameters).then((url) => {
|
|
57
|
+
resolve(url);
|
|
58
|
+
}).catch((error) => {
|
|
59
|
+
console.log(JSON.stringify(error));
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Gets the current authentication token.
|
|
66
|
+
* This function will also automatically try to refresh token if expired.
|
|
67
|
+
*
|
|
68
|
+
* @throws Error when authentication failed and/or call to login is needed
|
|
69
|
+
* @returns Promise that resolves bearer authentication token
|
|
70
|
+
*/
|
|
71
|
+
async getToken() {
|
|
72
|
+
const msalTokenCache = this._pca.getTokenCache();
|
|
73
|
+
const cachedAccounts = await msalTokenCache.getAllAccounts();
|
|
74
|
+
return new Promise(async (resolve, reject) => {
|
|
75
|
+
if (cachedAccounts.length > 0) {
|
|
76
|
+
this._pca.acquireTokenSilent({
|
|
77
|
+
account: cachedAccounts[0],
|
|
78
|
+
scopes: [this.resource + "/.default", "offline_access"]
|
|
79
|
+
}).then(response => {
|
|
80
|
+
if (response) {
|
|
81
|
+
let accessToken = response.accessToken;
|
|
82
|
+
resolve(accessToken);
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
reject(new Error('Error getting token, please call `ops login`.'));
|
|
86
|
+
}
|
|
87
|
+
}).catch(err => {
|
|
88
|
+
reject(new Error(err));
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
else if (process.env.AZURE_CLIENT_ID && process.env.AZURE_CLIENT_SECRET) {
|
|
92
|
+
const cca = new msal_node_1.ConfidentialClientApplication({
|
|
93
|
+
auth: {
|
|
94
|
+
clientId: process.env.AZURE_CLIENT_ID,
|
|
95
|
+
clientSecret: process.env.AZURE_CLIENT_SECRET,
|
|
96
|
+
authority: this.authorityUrl,
|
|
97
|
+
},
|
|
98
|
+
cache: {
|
|
99
|
+
cachePlugin: new cache_1.default(this._accessTokenPath),
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
const msalCcaTokenCache = cca.getTokenCache();
|
|
103
|
+
const ccaCachedAccounts = await msalCcaTokenCache.getAllAccounts();
|
|
104
|
+
if (ccaCachedAccounts.length > 0) {
|
|
105
|
+
cca.acquireTokenSilent({
|
|
106
|
+
account: ccaCachedAccounts[0],
|
|
107
|
+
scopes: [this.resource + "/.default"]
|
|
108
|
+
}).then(response => {
|
|
109
|
+
if (response) {
|
|
110
|
+
let accessToken = response.accessToken;
|
|
111
|
+
resolve(accessToken);
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
reject(new Error('Error getting token, please call `ops login`.'));
|
|
115
|
+
}
|
|
116
|
+
}).catch(err => {
|
|
117
|
+
reject(new Error(err));
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
cca.acquireTokenByClientCredential({
|
|
122
|
+
scopes: [this.resource + "/.default", "offline_access"]
|
|
123
|
+
}).then(response => {
|
|
124
|
+
if (response) {
|
|
125
|
+
let accessToken = response.accessToken;
|
|
126
|
+
resolve(accessToken);
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
reject(new Error('Error getting token, please call `ops login`.'));
|
|
130
|
+
}
|
|
131
|
+
}).catch(err => {
|
|
132
|
+
reject(new Error(err));
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
throw new Error('You are not authenticated, please call `ops login`.');
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Contacts authority server, fetches and saves the authentication token to be used in subsequent requests.
|
|
143
|
+
*
|
|
144
|
+
* @param code Authorization code used to fetch the token.
|
|
145
|
+
* @returns [[Promise<TokenResponse>]]
|
|
146
|
+
*/
|
|
147
|
+
acquireToken(query) {
|
|
148
|
+
return new Promise((resolve, _reject) => {
|
|
149
|
+
if (this._verifier === null) {
|
|
150
|
+
throw new Error(`PKCE verifier missing.`);
|
|
151
|
+
}
|
|
152
|
+
// Add PKCE code verifier to token request object
|
|
153
|
+
const tokenRequest = {
|
|
154
|
+
code: query.code,
|
|
155
|
+
scopes: [this.resource + "/.default", "offline_access"],
|
|
156
|
+
redirectUri: this.redirectUri,
|
|
157
|
+
codeVerifier: this._verifier,
|
|
158
|
+
clientInfo: query.client_info
|
|
159
|
+
};
|
|
160
|
+
this._pca.acquireTokenByCode(tokenRequest).then((token) => {
|
|
161
|
+
var _a;
|
|
162
|
+
if (token === null) {
|
|
163
|
+
throw new Error(`PKCE getting token.`);
|
|
164
|
+
}
|
|
165
|
+
if ((_a = token.account) === null || _a === void 0 ? void 0 : _a.name) {
|
|
166
|
+
resolve(token.account.name);
|
|
167
|
+
}
|
|
168
|
+
}).catch((err) => {
|
|
169
|
+
throw new Error(err);
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Acquires token using device flow.
|
|
175
|
+
*
|
|
176
|
+
* @returns [[Promise<TokenResponse>]]
|
|
177
|
+
*/
|
|
178
|
+
acquireTokenDeviceFlow() {
|
|
179
|
+
return new Promise((resolve, reject) => {
|
|
180
|
+
this._pca.acquireTokenByDeviceCode({
|
|
181
|
+
deviceCodeCallback: (response) => {
|
|
182
|
+
if (response.message) {
|
|
183
|
+
console.log(response.message);
|
|
184
|
+
}
|
|
185
|
+
},
|
|
186
|
+
scopes: [this.resource + "/.default", "offline_access"]
|
|
187
|
+
}).then(response => {
|
|
188
|
+
resolve();
|
|
189
|
+
}).catch((err) => {
|
|
190
|
+
reject(err);
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Get NPM token for adinsure npm repositories
|
|
196
|
+
*
|
|
197
|
+
* @returns [[Promise<string>]]
|
|
198
|
+
*/
|
|
199
|
+
async getNPMToken() {
|
|
200
|
+
const msalTokenCache = this._pca.getTokenCache();
|
|
201
|
+
const cachedAccounts = await msalTokenCache.getAllAccounts();
|
|
202
|
+
return new Promise((resolve, reject) => {
|
|
203
|
+
if (cachedAccounts.length > 0) {
|
|
204
|
+
this._pca.acquireTokenSilent({
|
|
205
|
+
account: cachedAccounts[0],
|
|
206
|
+
scopes: [this.devopsResourceId + "/.default", "offline_access"]
|
|
207
|
+
}).then(response => {
|
|
208
|
+
if (response) {
|
|
209
|
+
resolve(response.accessToken);
|
|
210
|
+
}
|
|
211
|
+
else {
|
|
212
|
+
reject(new Error('Error getting token, please call `ops login`.'));
|
|
213
|
+
}
|
|
214
|
+
}).catch(err => {
|
|
215
|
+
reject(new Error(err));
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
else {
|
|
219
|
+
reject();
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
exports.default = SecurityContext;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export declare type AzurePackageArray = {
|
|
2
|
+
count: number;
|
|
3
|
+
value: AzurePackage[];
|
|
4
|
+
};
|
|
5
|
+
export declare type AzurePackage = {
|
|
6
|
+
id: string;
|
|
7
|
+
normalizedName: string;
|
|
8
|
+
name: string;
|
|
9
|
+
protocolType: string;
|
|
10
|
+
url: string;
|
|
11
|
+
versions: AzurePackageVersion[];
|
|
12
|
+
};
|
|
13
|
+
export declare type AzurePackageVersion = {
|
|
14
|
+
id: string;
|
|
15
|
+
normalizedVersion: string;
|
|
16
|
+
version: string;
|
|
17
|
+
isLatest: boolean;
|
|
18
|
+
isListed: boolean;
|
|
19
|
+
storageId: string;
|
|
20
|
+
views: AzurePackageView[];
|
|
21
|
+
publishDate: string;
|
|
22
|
+
};
|
|
23
|
+
export declare type AzurePackageView = {
|
|
24
|
+
id: string;
|
|
25
|
+
name: string;
|
|
26
|
+
url: string;
|
|
27
|
+
type: boolean;
|
|
28
|
+
};
|
|
29
|
+
export declare type NpmPackage = {
|
|
30
|
+
name: string;
|
|
31
|
+
version: string;
|
|
32
|
+
path: string;
|
|
33
|
+
jsonPath: string;
|
|
34
|
+
};
|