@credibledata/cred-cli 0.0.6
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/.github/workflows/build.yml +23 -0
- package/.mocharc.json +10 -0
- package/.prettierignore +2 -0
- package/.prettierrc +4 -0
- package/README-DEV.md +40 -0
- package/README.md +11 -0
- package/bun.lock +1158 -0
- package/dist/client/api.js +7715 -0
- package/dist/client/api.js.map +1 -0
- package/dist/client/base.js +69 -0
- package/dist/client/base.js.map +1 -0
- package/dist/client/common.js +162 -0
- package/dist/client/common.js.map +1 -0
- package/dist/client/configuration.js +44 -0
- package/dist/client/configuration.js.map +1 -0
- package/dist/client/index.js +32 -0
- package/dist/client/index.js.map +1 -0
- package/dist/clientconfiguration.js +205 -0
- package/dist/clientconfiguration.js.map +1 -0
- package/dist/clientconfiguration.spec.js +381 -0
- package/dist/clientconfiguration.spec.js.map +1 -0
- package/dist/commands/add.js +66 -0
- package/dist/commands/add.js.map +1 -0
- package/dist/commands/connection/createconnections.js +89 -0
- package/dist/commands/connection/createconnections.js.map +1 -0
- package/dist/commands/connection/createconnections.spec.js +219 -0
- package/dist/commands/connection/createconnections.spec.js.map +1 -0
- package/dist/commands/connection/deleteconnection.js +52 -0
- package/dist/commands/connection/deleteconnection.js.map +1 -0
- package/dist/commands/connection/deleteconnection.spec.js +130 -0
- package/dist/commands/connection/deleteconnection.spec.js.map +1 -0
- package/dist/commands/connection/listconnections.js +50 -0
- package/dist/commands/connection/listconnections.js.map +1 -0
- package/dist/commands/connection/listconnections.spec.js +117 -0
- package/dist/commands/connection/listconnections.spec.js.map +1 -0
- package/dist/commands/get.js +28 -0
- package/dist/commands/get.js.map +1 -0
- package/dist/commands/group/addmember.js +75 -0
- package/dist/commands/group/addmember.js.map +1 -0
- package/dist/commands/group/addmember.spec.js +148 -0
- package/dist/commands/group/addmember.spec.js.map +1 -0
- package/dist/commands/group/creategroup.js +55 -0
- package/dist/commands/group/creategroup.js.map +1 -0
- package/dist/commands/group/creategroup.spec.js +122 -0
- package/dist/commands/group/creategroup.spec.js.map +1 -0
- package/dist/commands/group/deletegroup.js +48 -0
- package/dist/commands/group/deletegroup.js.map +1 -0
- package/dist/commands/group/deletegroup.spec.js +104 -0
- package/dist/commands/group/deletegroup.spec.js.map +1 -0
- package/dist/commands/group/getgroup.js +50 -0
- package/dist/commands/group/getgroup.js.map +1 -0
- package/dist/commands/group/getgroup.spec.js +111 -0
- package/dist/commands/group/getgroup.spec.js.map +1 -0
- package/dist/commands/group/listgroups.js +56 -0
- package/dist/commands/group/listgroups.js.map +1 -0
- package/dist/commands/group/listgroups.spec.js +118 -0
- package/dist/commands/group/listgroups.spec.js.map +1 -0
- package/dist/commands/group/removemember.js +69 -0
- package/dist/commands/group/removemember.js.map +1 -0
- package/dist/commands/group/removemember.spec.js +138 -0
- package/dist/commands/group/removemember.spec.js.map +1 -0
- package/dist/commands/groupaccesstoken/createToken.js +53 -0
- package/dist/commands/groupaccesstoken/createToken.js.map +1 -0
- package/dist/commands/groupaccesstoken/createToken.spec.js +127 -0
- package/dist/commands/groupaccesstoken/createToken.spec.js.map +1 -0
- package/dist/commands/groupaccesstoken/deleteToken.js +24 -0
- package/dist/commands/groupaccesstoken/deleteToken.js.map +1 -0
- package/dist/commands/groupaccesstoken/deleteToken.spec.js +103 -0
- package/dist/commands/groupaccesstoken/deleteToken.spec.js.map +1 -0
- package/dist/commands/groupaccesstoken/groupContainer.js +71 -0
- package/dist/commands/groupaccesstoken/groupContainer.js.map +1 -0
- package/dist/commands/groupaccesstoken/listTokens.js +25 -0
- package/dist/commands/groupaccesstoken/listTokens.js.map +1 -0
- package/dist/commands/groupaccesstoken/listTokens.spec.js +115 -0
- package/dist/commands/groupaccesstoken/listTokens.spec.js.map +1 -0
- package/dist/commands/list.js +75 -0
- package/dist/commands/list.js.map +1 -0
- package/dist/commands/misc/login.js +290 -0
- package/dist/commands/misc/login.js.map +1 -0
- package/dist/commands/misc/login.spec.js +243 -0
- package/dist/commands/misc/login.spec.js.map +1 -0
- package/dist/commands/misc/logout.js +11 -0
- package/dist/commands/misc/logout.js.map +1 -0
- package/dist/commands/misc/logout.spec.js +30 -0
- package/dist/commands/misc/logout.spec.js.map +1 -0
- package/dist/commands/misc/loopbackOAuth.js +110 -0
- package/dist/commands/misc/loopbackOAuth.js.map +1 -0
- package/dist/commands/misc/set-access-token.js +27 -0
- package/dist/commands/misc/set-access-token.js.map +1 -0
- package/dist/commands/misc/set-access-token.spec.js +65 -0
- package/dist/commands/misc/set-access-token.spec.js.map +1 -0
- package/dist/commands/package/deletepackage.js +54 -0
- package/dist/commands/package/deletepackage.js.map +1 -0
- package/dist/commands/package/deletepackage.spec.js +136 -0
- package/dist/commands/package/deletepackage.spec.js.map +1 -0
- package/dist/commands/package/listpackages.js +57 -0
- package/dist/commands/package/listpackages.js.map +1 -0
- package/dist/commands/package/listpackages.spec.js +129 -0
- package/dist/commands/package/listpackages.spec.js.map +1 -0
- package/dist/commands/package/publish.js +157 -0
- package/dist/commands/package/publish.js.map +1 -0
- package/dist/commands/package/publish.spec.js +511 -0
- package/dist/commands/package/publish.spec.js.map +1 -0
- package/dist/commands/package/updatepackage.js +75 -0
- package/dist/commands/package/updatepackage.js.map +1 -0
- package/dist/commands/package/updatepackage.spec.js +189 -0
- package/dist/commands/package/updatepackage.spec.js.map +1 -0
- package/dist/commands/project/createproject.js +75 -0
- package/dist/commands/project/createproject.js.map +1 -0
- package/dist/commands/project/createproject.spec.js +154 -0
- package/dist/commands/project/createproject.spec.js.map +1 -0
- package/dist/commands/project/deleteproject.js +49 -0
- package/dist/commands/project/deleteproject.js.map +1 -0
- package/dist/commands/project/deleteproject.spec.js +106 -0
- package/dist/commands/project/deleteproject.spec.js.map +1 -0
- package/dist/commands/project/getproject.js +44 -0
- package/dist/commands/project/getproject.js.map +1 -0
- package/dist/commands/project/getproject.spec.js +99 -0
- package/dist/commands/project/getproject.spec.js.map +1 -0
- package/dist/commands/project/listprojects.js +52 -0
- package/dist/commands/project/listprojects.js.map +1 -0
- package/dist/commands/project/listprojects.spec.js +111 -0
- package/dist/commands/project/listprojects.spec.js.map +1 -0
- package/dist/commands/project/setproject.js +26 -0
- package/dist/commands/project/setproject.js.map +1 -0
- package/dist/commands/project/setproject.spec.js +58 -0
- package/dist/commands/project/setproject.spec.js.map +1 -0
- package/dist/commands/project/updateproject.js +68 -0
- package/dist/commands/project/updateproject.js.map +1 -0
- package/dist/commands/project/updateproject.spec.js +129 -0
- package/dist/commands/project/updateproject.spec.js.map +1 -0
- package/dist/commands/rm.js +68 -0
- package/dist/commands/rm.js.map +1 -0
- package/dist/commands/set.js +17 -0
- package/dist/commands/set.js.map +1 -0
- package/dist/commands/update.js +42 -0
- package/dist/commands/update.js.map +1 -0
- package/dist/commands/version/archive-unarchive-version.js +79 -0
- package/dist/commands/version/archive-unarchive-version.js.map +1 -0
- package/dist/commands/version/archive-unarchive-version.spec.js +244 -0
- package/dist/commands/version/archive-unarchive-version.spec.js.map +1 -0
- package/dist/commands/version/listversions.js +46 -0
- package/dist/commands/version/listversions.js.map +1 -0
- package/dist/commands/version/listversions.spec.js +121 -0
- package/dist/commands/version/listversions.spec.js.map +1 -0
- package/dist/common/UserGroupId.js +112 -0
- package/dist/common/UserGroupId.js.map +1 -0
- package/dist/common/UserGroupId.spec.js +92 -0
- package/dist/common/UserGroupId.spec.js.map +1 -0
- package/dist/constants.js +90 -0
- package/dist/constants.js.map +1 -0
- package/dist/index.js +159 -0
- package/dist/index.js.map +1 -0
- package/dist/logger.js +77 -0
- package/dist/logger.js.map +1 -0
- package/dist/logger.spec.js +125 -0
- package/dist/logger.spec.js.map +1 -0
- package/dist/polyfills/file.polyfill.js +6 -0
- package/dist/polyfills/file.polyfill.js.map +1 -0
- package/dist/utils.js +110 -0
- package/dist/utils.js.map +1 -0
- package/dist/utils.spec.js +158 -0
- package/dist/utils.spec.js.map +1 -0
- package/dist/validator.js +53 -0
- package/dist/validator.js.map +1 -0
- package/dist/validator.spec.js +41 -0
- package/dist/validator.spec.js.map +1 -0
- package/docker/Dockerfile.ci +18 -0
- package/docker-compose.yml +18 -0
- package/eslint.config.mjs +45 -0
- package/generate-client.sh +27 -0
- package/mocha.setup.ts +4 -0
- package/openapitools.json +7 -0
- package/package.json +75 -0
- package/src/client/.openapi-generator/FILES +9 -0
- package/src/client/.openapi-generator/VERSION +1 -0
- package/src/client/.openapi-generator-ignore +23 -0
- package/src/client/api.ts +9729 -0
- package/src/client/base.ts +86 -0
- package/src/client/common.ts +150 -0
- package/src/client/configuration.ts +110 -0
- package/src/client/git_push.sh +57 -0
- package/src/client/index.ts +18 -0
- package/src/clientconfiguration.spec.ts +490 -0
- package/src/clientconfiguration.ts +263 -0
- package/src/commands/add.ts +125 -0
- package/src/commands/connection/createconnections.spec.ts +403 -0
- package/src/commands/connection/createconnections.ts +109 -0
- package/src/commands/connection/deleteconnection.spec.ts +189 -0
- package/src/commands/connection/deleteconnection.ts +57 -0
- package/src/commands/connection/listconnections.spec.ts +132 -0
- package/src/commands/connection/listconnections.ts +58 -0
- package/src/commands/get.ts +31 -0
- package/src/commands/group/addmember.spec.ts +257 -0
- package/src/commands/group/addmember.ts +85 -0
- package/src/commands/group/creategroup.spec.ts +146 -0
- package/src/commands/group/creategroup.ts +54 -0
- package/src/commands/group/deletegroup.spec.ts +120 -0
- package/src/commands/group/deletegroup.ts +45 -0
- package/src/commands/group/getgroup.spec.ts +129 -0
- package/src/commands/group/getgroup.ts +47 -0
- package/src/commands/group/listgroups.spec.ts +137 -0
- package/src/commands/group/listgroups.ts +45 -0
- package/src/commands/group/removemember.spec.ts +224 -0
- package/src/commands/group/removemember.ts +75 -0
- package/src/commands/groupaccesstoken/createToken.spec.ts +211 -0
- package/src/commands/groupaccesstoken/createToken.ts +72 -0
- package/src/commands/groupaccesstoken/deleteToken.spec.ts +147 -0
- package/src/commands/groupaccesstoken/deleteToken.ts +29 -0
- package/src/commands/groupaccesstoken/groupContainer.ts +83 -0
- package/src/commands/groupaccesstoken/listTokens.spec.ts +147 -0
- package/src/commands/groupaccesstoken/listTokens.ts +29 -0
- package/src/commands/list.ts +131 -0
- package/src/commands/misc/login.spec.ts +213 -0
- package/src/commands/misc/login.ts +325 -0
- package/src/commands/misc/logout.spec.ts +32 -0
- package/src/commands/misc/logout.ts +9 -0
- package/src/commands/misc/loopbackOAuth.ts +127 -0
- package/src/commands/misc/set-access-token.spec.ts +95 -0
- package/src/commands/misc/set-access-token.ts +32 -0
- package/src/commands/package/deletepackage.spec.ts +164 -0
- package/src/commands/package/deletepackage.ts +58 -0
- package/src/commands/package/listpackages.spec.ts +147 -0
- package/src/commands/package/listpackages.ts +67 -0
- package/src/commands/package/publish.spec.ts +597 -0
- package/src/commands/package/publish.ts +211 -0
- package/src/commands/package/updatepackage.spec.ts +319 -0
- package/src/commands/package/updatepackage.ts +95 -0
- package/src/commands/project/createproject.spec.ts +247 -0
- package/src/commands/project/createproject.ts +70 -0
- package/src/commands/project/deleteproject.spec.ts +123 -0
- package/src/commands/project/deleteproject.ts +48 -0
- package/src/commands/project/getproject.spec.ts +109 -0
- package/src/commands/project/getproject.ts +43 -0
- package/src/commands/project/listprojects.spec.ts +121 -0
- package/src/commands/project/listprojects.ts +62 -0
- package/src/commands/project/setproject.spec.ts +63 -0
- package/src/commands/project/setproject.ts +14 -0
- package/src/commands/project/updateproject.spec.ts +217 -0
- package/src/commands/project/updateproject.ts +82 -0
- package/src/commands/rm.ts +101 -0
- package/src/commands/set.ts +16 -0
- package/src/commands/update.ts +64 -0
- package/src/commands/version/archive-unarchive-version.spec.ts +456 -0
- package/src/commands/version/archive-unarchive-version.ts +111 -0
- package/src/commands/version/listversions.spec.ts +138 -0
- package/src/commands/version/listversions.ts +45 -0
- package/src/common/UserGroupId.spec.ts +117 -0
- package/src/common/UserGroupId.ts +137 -0
- package/src/constants.ts +116 -0
- package/src/index.ts +209 -0
- package/src/logger.spec.ts +158 -0
- package/src/logger.ts +86 -0
- package/src/polyfills/file.polyfill.ts +6 -0
- package/src/utils.spec.ts +135 -0
- package/src/utils.ts +115 -0
- package/src/validator.spec.ts +51 -0
- package/src/validator.ts +44 -0
- package/tsconfig.json +17 -0
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { expect } from "chai";
|
|
2
|
+
import sinon from "sinon";
|
|
3
|
+
import { ClientConfiguration } from "../../clientconfiguration";
|
|
4
|
+
import { logger } from "../../logger";
|
|
5
|
+
import { setAccessToken } from "./set-access-token";
|
|
6
|
+
|
|
7
|
+
describe("set-access-token", () => {
|
|
8
|
+
let sandbox: sinon.SinonSandbox;
|
|
9
|
+
let setAccessTokenStub: sinon.SinonStub;
|
|
10
|
+
let setJwtAccessTokenStub: sinon.SinonStub;
|
|
11
|
+
let setOrganizationStub: sinon.SinonStub;
|
|
12
|
+
let loggerStub: sinon.SinonStubbedInstance<typeof logger>;
|
|
13
|
+
|
|
14
|
+
beforeEach(() => {
|
|
15
|
+
sandbox = sinon.createSandbox();
|
|
16
|
+
loggerStub = sandbox.stub(logger);
|
|
17
|
+
setAccessTokenStub = sandbox.stub(
|
|
18
|
+
ClientConfiguration.prototype,
|
|
19
|
+
"setAccessToken",
|
|
20
|
+
);
|
|
21
|
+
setJwtAccessTokenStub = sandbox.stub(
|
|
22
|
+
ClientConfiguration.prototype,
|
|
23
|
+
"setJwtAccessToken",
|
|
24
|
+
);
|
|
25
|
+
setOrganizationStub = sandbox.stub(
|
|
26
|
+
ClientConfiguration.prototype,
|
|
27
|
+
"setOrganization",
|
|
28
|
+
);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
afterEach(() => {
|
|
32
|
+
sandbox.restore();
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it("should set access token successfully", () => {
|
|
36
|
+
const jwtToken = "test-jwt-token";
|
|
37
|
+
|
|
38
|
+
setAccessToken(jwtToken);
|
|
39
|
+
|
|
40
|
+
expect(setAccessTokenStub.calledOnce).to.be.true;
|
|
41
|
+
expect(setAccessTokenStub.firstCall.args).to.deep.equal([
|
|
42
|
+
false,
|
|
43
|
+
jwtToken,
|
|
44
|
+
]);
|
|
45
|
+
expect(setJwtAccessTokenStub.calledOnce).to.be.true;
|
|
46
|
+
expect(setJwtAccessTokenStub.firstCall.args[0]).to.equal(jwtToken);
|
|
47
|
+
expect(
|
|
48
|
+
loggerStub.info.calledWith(
|
|
49
|
+
sinon.match("Access token set successfully"),
|
|
50
|
+
),
|
|
51
|
+
).to.be.true;
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it("should set access token and organization when provided", () => {
|
|
55
|
+
const jwtToken = "test-jwt-token";
|
|
56
|
+
const organizationName = "test-org";
|
|
57
|
+
|
|
58
|
+
setAccessToken(jwtToken, organizationName);
|
|
59
|
+
|
|
60
|
+
expect(setAccessTokenStub.calledOnce).to.be.true;
|
|
61
|
+
expect(setJwtAccessTokenStub.calledOnce).to.be.true;
|
|
62
|
+
expect(setOrganizationStub.calledOnce).to.be.true;
|
|
63
|
+
expect(setOrganizationStub.firstCall.args[0]).to.equal(organizationName);
|
|
64
|
+
expect(
|
|
65
|
+
loggerStub.info.calledWith(
|
|
66
|
+
sinon.match("Access token set successfully"),
|
|
67
|
+
),
|
|
68
|
+
).to.be.true;
|
|
69
|
+
expect(
|
|
70
|
+
loggerStub.info.calledWith(
|
|
71
|
+
sinon.match(`Organization set to: ${organizationName}`),
|
|
72
|
+
),
|
|
73
|
+
).to.be.true;
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it("should not set organization when not provided", () => {
|
|
77
|
+
const jwtToken = "test-jwt-token";
|
|
78
|
+
|
|
79
|
+
setAccessToken(jwtToken);
|
|
80
|
+
|
|
81
|
+
expect(setOrganizationStub.called).to.be.false;
|
|
82
|
+
expect(loggerStub.info.calledWith(sinon.match(/Organization set to:/))).to
|
|
83
|
+
.be.false;
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it("should handle custom config path", () => {
|
|
87
|
+
const jwtToken = "test-jwt-token";
|
|
88
|
+
const configPath = "/custom/path/config.json";
|
|
89
|
+
|
|
90
|
+
setAccessToken(jwtToken, undefined, configPath);
|
|
91
|
+
|
|
92
|
+
expect(setAccessTokenStub.calledOnce).to.be.true;
|
|
93
|
+
expect(setJwtAccessTokenStub.calledOnce).to.be.true;
|
|
94
|
+
});
|
|
95
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ClientConfiguration } from "../../clientconfiguration";
|
|
2
|
+
import { logger } from "../../logger";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Sets a service account JWT token for CLI authentication.
|
|
6
|
+
*
|
|
7
|
+
* @param jwtToken The JWT token to use for authentication
|
|
8
|
+
* @param organizationName Optional organization name to set
|
|
9
|
+
* @param configPath Optional custom config path
|
|
10
|
+
*/
|
|
11
|
+
export function setAccessToken(
|
|
12
|
+
jwtToken: string,
|
|
13
|
+
organizationName?: string,
|
|
14
|
+
configPath?: string,
|
|
15
|
+
) {
|
|
16
|
+
const config = new ClientConfiguration(configPath);
|
|
17
|
+
|
|
18
|
+
// Set the JWT token as both access token and JWT access token
|
|
19
|
+
config.setAccessToken(false, jwtToken);
|
|
20
|
+
config.setJwtAccessToken(jwtToken);
|
|
21
|
+
|
|
22
|
+
// Set organization if provided
|
|
23
|
+
if (organizationName) {
|
|
24
|
+
config.setOrganization(organizationName);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
logger.info("Access token set successfully");
|
|
28
|
+
|
|
29
|
+
if (organizationName) {
|
|
30
|
+
logger.info(`Organization set to: ${organizationName}`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { expect } from "chai";
|
|
2
|
+
import sinon from "sinon";
|
|
3
|
+
import { PackagesApi } from "../../client/api";
|
|
4
|
+
import { ClientConfiguration } from "../../clientconfiguration";
|
|
5
|
+
import { logger } from "../../logger";
|
|
6
|
+
import { getConfirmation } from "../../utils";
|
|
7
|
+
import { deletePackage } from "./deletepackage";
|
|
8
|
+
|
|
9
|
+
describe("delete-package", () => {
|
|
10
|
+
let sandbox: sinon.SinonSandbox;
|
|
11
|
+
let deletePackageStub: sinon.SinonStub;
|
|
12
|
+
let loggerStub: sinon.SinonStubbedInstance<typeof logger>;
|
|
13
|
+
let getConfirmationStub: sinon.SinonStub;
|
|
14
|
+
|
|
15
|
+
beforeEach(() => {
|
|
16
|
+
sandbox = sinon.createSandbox();
|
|
17
|
+
deletePackageStub = sandbox.stub();
|
|
18
|
+
loggerStub = sandbox.stub(logger);
|
|
19
|
+
getConfirmationStub = sandbox.stub();
|
|
20
|
+
|
|
21
|
+
sandbox
|
|
22
|
+
.stub(ClientConfiguration.prototype, "getOrganization")
|
|
23
|
+
.returns("test-org");
|
|
24
|
+
sandbox
|
|
25
|
+
.stub(ClientConfiguration.prototype, "getProject")
|
|
26
|
+
.returns("test-project");
|
|
27
|
+
sandbox
|
|
28
|
+
.stub(ClientConfiguration.prototype, "doesConfigExists")
|
|
29
|
+
.returns(true);
|
|
30
|
+
sandbox
|
|
31
|
+
.stub(ClientConfiguration.prototype, "getHeaders")
|
|
32
|
+
.returns({ Authorization: "Bearer test-token" });
|
|
33
|
+
|
|
34
|
+
sandbox
|
|
35
|
+
.stub(PackagesApi.prototype, "deletePackage")
|
|
36
|
+
.callsFake(deletePackageStub);
|
|
37
|
+
sandbox
|
|
38
|
+
.stub(require("../../utils"), "getConfirmation")
|
|
39
|
+
.callsFake(getConfirmationStub);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
afterEach(() => {
|
|
43
|
+
sandbox.restore();
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("should delete package successfully", async () => {
|
|
47
|
+
deletePackageStub.resolves({ status: 200 });
|
|
48
|
+
getConfirmationStub.resolves(true);
|
|
49
|
+
|
|
50
|
+
await deletePackage("http://test-server", "/test-package", false, true);
|
|
51
|
+
|
|
52
|
+
expect(deletePackageStub.calledOnce).to.be.true;
|
|
53
|
+
expect(deletePackageStub.firstCall.args[0]).to.equal("test-org");
|
|
54
|
+
expect(deletePackageStub.firstCall.args[1]).to.equal("test-project");
|
|
55
|
+
expect(deletePackageStub.firstCall.args[2]).to.equal("test-package");
|
|
56
|
+
expect(deletePackageStub.firstCall.args[3]).to.deep.include({
|
|
57
|
+
baseURL: "http://test-server",
|
|
58
|
+
headers: { Authorization: "Bearer test-token" },
|
|
59
|
+
});
|
|
60
|
+
expect(
|
|
61
|
+
loggerStub.info.calledWith(
|
|
62
|
+
sinon.match("Package deleted successfully"),
|
|
63
|
+
),
|
|
64
|
+
).to.be.true;
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it("should handle package path without leading slash", async () => {
|
|
68
|
+
deletePackageStub.resolves({ status: 200 });
|
|
69
|
+
getConfirmationStub.resolves(true);
|
|
70
|
+
|
|
71
|
+
await deletePackage("http://test-server", "test-package", false, true);
|
|
72
|
+
|
|
73
|
+
expect(deletePackageStub.firstCall.args[2]).to.equal("test-package");
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it("should handle missing config", async () => {
|
|
77
|
+
sandbox.restore();
|
|
78
|
+
sandbox = sinon.createSandbox();
|
|
79
|
+
deletePackageStub = sandbox.stub();
|
|
80
|
+
loggerStub = sandbox.stub(logger);
|
|
81
|
+
getConfirmationStub = sandbox.stub();
|
|
82
|
+
|
|
83
|
+
sandbox
|
|
84
|
+
.stub(ClientConfiguration.prototype, "doesConfigExists")
|
|
85
|
+
.returns(false);
|
|
86
|
+
sandbox
|
|
87
|
+
.stub(PackagesApi.prototype, "deletePackage")
|
|
88
|
+
.callsFake(deletePackageStub);
|
|
89
|
+
sandbox
|
|
90
|
+
.stub(require("../../utils"), "getConfirmation")
|
|
91
|
+
.callsFake(getConfirmationStub);
|
|
92
|
+
|
|
93
|
+
await deletePackage("http://test-server", "/test-package", false, true);
|
|
94
|
+
|
|
95
|
+
expect(deletePackageStub.called).to.be.false;
|
|
96
|
+
expect(
|
|
97
|
+
loggerStub.error.calledWith(
|
|
98
|
+
sinon.match("Please, make sure that you are logged in"),
|
|
99
|
+
),
|
|
100
|
+
).to.be.true;
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it("should handle missing project", async () => {
|
|
104
|
+
sandbox.restore();
|
|
105
|
+
sandbox = sinon.createSandbox();
|
|
106
|
+
deletePackageStub = sandbox.stub();
|
|
107
|
+
loggerStub = sandbox.stub(logger);
|
|
108
|
+
getConfirmationStub = sandbox.stub();
|
|
109
|
+
|
|
110
|
+
sandbox
|
|
111
|
+
.stub(ClientConfiguration.prototype, "doesConfigExists")
|
|
112
|
+
.returns(true);
|
|
113
|
+
sandbox.stub(ClientConfiguration.prototype, "getProject").returns("");
|
|
114
|
+
sandbox
|
|
115
|
+
.stub(PackagesApi.prototype, "deletePackage")
|
|
116
|
+
.callsFake(deletePackageStub);
|
|
117
|
+
sandbox
|
|
118
|
+
.stub(require("../../utils"), "getConfirmation")
|
|
119
|
+
.callsFake(getConfirmationStub);
|
|
120
|
+
|
|
121
|
+
await deletePackage("http://test-server", "/test-package", false, true);
|
|
122
|
+
|
|
123
|
+
expect(deletePackageStub.called).to.be.false;
|
|
124
|
+
expect(
|
|
125
|
+
loggerStub.error.calledWith(
|
|
126
|
+
sinon.match("Please, make sure to set a project"),
|
|
127
|
+
),
|
|
128
|
+
).to.be.true;
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it("should request confirmation when autoConfirm is false", async () => {
|
|
132
|
+
deletePackageStub.resolves({ status: 200 });
|
|
133
|
+
getConfirmationStub.resolves(true);
|
|
134
|
+
|
|
135
|
+
await deletePackage("http://test-server", "/test-package", false, false);
|
|
136
|
+
|
|
137
|
+
expect(getConfirmationStub.calledOnce).to.be.true;
|
|
138
|
+
expect(deletePackageStub.calledOnce).to.be.true;
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it("should cancel when confirmation is denied", async () => {
|
|
142
|
+
getConfirmationStub.resolves(false);
|
|
143
|
+
|
|
144
|
+
await deletePackage("http://test-server", "/test-package", false, false);
|
|
145
|
+
|
|
146
|
+
expect(getConfirmationStub.calledOnce).to.be.true;
|
|
147
|
+
expect(deletePackageStub.called).to.be.false;
|
|
148
|
+
expect(loggerStub.info.calledWith(sinon.match("Operation cancelled."))).to
|
|
149
|
+
.be.true;
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
it("should handle API errors", async () => {
|
|
153
|
+
const mockError = new Error("API Error");
|
|
154
|
+
deletePackageStub.rejects(mockError);
|
|
155
|
+
getConfirmationStub.resolves(true);
|
|
156
|
+
|
|
157
|
+
await deletePackage("http://test-server", "/test-package", true, true);
|
|
158
|
+
|
|
159
|
+
expect(deletePackageStub.calledOnce).to.be.true;
|
|
160
|
+
expect(
|
|
161
|
+
loggerStub.error.calledWith(sinon.match("Failed to delete package")),
|
|
162
|
+
).to.be.true;
|
|
163
|
+
});
|
|
164
|
+
});
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { PackagesApi } from "../../client/api";
|
|
2
|
+
import { Configuration } from "../../client/configuration";
|
|
3
|
+
import { ClientConfiguration } from "../../clientconfiguration";
|
|
4
|
+
import { logger } from "../../logger";
|
|
5
|
+
import { getConfirmation, printOutError } from "../../utils";
|
|
6
|
+
|
|
7
|
+
const packagesApi = new PackagesApi(new Configuration());
|
|
8
|
+
|
|
9
|
+
export async function deletePackage(
|
|
10
|
+
packageServer: string,
|
|
11
|
+
packagePath: string,
|
|
12
|
+
debug: boolean,
|
|
13
|
+
autoConfirm: boolean,
|
|
14
|
+
) {
|
|
15
|
+
const clientConfig = new ClientConfiguration();
|
|
16
|
+
const organizationName = clientConfig.getOrganization();
|
|
17
|
+
const projectName = clientConfig.getProject();
|
|
18
|
+
const packageName = packagePath.replace("/", "");
|
|
19
|
+
|
|
20
|
+
if (!clientConfig.doesConfigExists()) {
|
|
21
|
+
logger.error("Please, make sure that you are logged in");
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (!projectName) {
|
|
26
|
+
logger.error("Please, make sure to set a project");
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (!autoConfirm) {
|
|
31
|
+
const confirmation = await getConfirmation(
|
|
32
|
+
`Are you sure you that want to delete the ${packagePath} package? This action cannot be undone.`,
|
|
33
|
+
);
|
|
34
|
+
if (!confirmation) {
|
|
35
|
+
logger.info("Operation cancelled.");
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
logger.info("Deleting package " + packagePath);
|
|
41
|
+
|
|
42
|
+
try {
|
|
43
|
+
await packagesApi.deletePackage(
|
|
44
|
+
organizationName,
|
|
45
|
+
projectName,
|
|
46
|
+
packageName,
|
|
47
|
+
{
|
|
48
|
+
baseURL: packageServer,
|
|
49
|
+
headers: clientConfig.getHeaders(),
|
|
50
|
+
},
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
logger.info("Package deleted successfully");
|
|
54
|
+
} catch (e) {
|
|
55
|
+
logger.error("Failed to delete package");
|
|
56
|
+
printOutError(e, debug);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { expect } from "chai";
|
|
2
|
+
import sinon from "sinon";
|
|
3
|
+
import { PackagesApi } from "../../client/api";
|
|
4
|
+
import { ClientConfiguration } from "../../clientconfiguration";
|
|
5
|
+
import { logger } from "../../logger";
|
|
6
|
+
import { prettifyJson } from "../../utils";
|
|
7
|
+
import { listPackages, printOutPackages } from "./listpackages";
|
|
8
|
+
|
|
9
|
+
describe("list-packages", () => {
|
|
10
|
+
let sandbox: sinon.SinonSandbox;
|
|
11
|
+
let listPackagesStub: sinon.SinonStub;
|
|
12
|
+
let loggerStub: sinon.SinonStubbedInstance<typeof logger>;
|
|
13
|
+
let consoleLogStub: sinon.SinonStub;
|
|
14
|
+
|
|
15
|
+
beforeEach(() => {
|
|
16
|
+
sandbox = sinon.createSandbox();
|
|
17
|
+
listPackagesStub = sandbox.stub();
|
|
18
|
+
loggerStub = sandbox.stub(logger);
|
|
19
|
+
consoleLogStub = sandbox.stub(console, "log");
|
|
20
|
+
|
|
21
|
+
sandbox
|
|
22
|
+
.stub(ClientConfiguration.prototype, "getOrganization")
|
|
23
|
+
.returns("test-org");
|
|
24
|
+
sandbox
|
|
25
|
+
.stub(ClientConfiguration.prototype, "getProject")
|
|
26
|
+
.returns("test-project");
|
|
27
|
+
sandbox
|
|
28
|
+
.stub(ClientConfiguration.prototype, "doesConfigExists")
|
|
29
|
+
.returns(true);
|
|
30
|
+
sandbox
|
|
31
|
+
.stub(ClientConfiguration.prototype, "getHeaders")
|
|
32
|
+
.returns({ Authorization: "Bearer test-token" });
|
|
33
|
+
|
|
34
|
+
sandbox
|
|
35
|
+
.stub(PackagesApi.prototype, "listPackages")
|
|
36
|
+
.callsFake(listPackagesStub);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
afterEach(() => {
|
|
40
|
+
sandbox.restore();
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("should list packages successfully", async () => {
|
|
44
|
+
const mockPackages = [
|
|
45
|
+
{ name: "package1", latestVersion: "1.0.0" },
|
|
46
|
+
{ name: "package2", latestVersion: "2.0.0" },
|
|
47
|
+
];
|
|
48
|
+
const mockResponse = {
|
|
49
|
+
data: mockPackages,
|
|
50
|
+
headers: {},
|
|
51
|
+
};
|
|
52
|
+
listPackagesStub.resolves(mockResponse);
|
|
53
|
+
|
|
54
|
+
const result = await listPackages("http://test-server", false);
|
|
55
|
+
|
|
56
|
+
expect(listPackagesStub.calledOnce).to.be.true;
|
|
57
|
+
expect(listPackagesStub.firstCall.args[0]).to.equal("test-org");
|
|
58
|
+
expect(listPackagesStub.firstCall.args[1]).to.equal("test-project");
|
|
59
|
+
expect(listPackagesStub.firstCall.args[2]).to.equal(-1); // limit
|
|
60
|
+
expect(listPackagesStub.firstCall.args[3]).to.equal(0); // offset
|
|
61
|
+
expect(listPackagesStub.firstCall.args[4]).to.deep.include({
|
|
62
|
+
baseURL: "http://test-server",
|
|
63
|
+
headers: { Authorization: "Bearer test-token" },
|
|
64
|
+
});
|
|
65
|
+
expect(result).to.deep.equal({
|
|
66
|
+
packages: mockPackages,
|
|
67
|
+
totalCount: undefined,
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it("should handle missing config", async () => {
|
|
72
|
+
sandbox.restore();
|
|
73
|
+
sandbox = sinon.createSandbox();
|
|
74
|
+
listPackagesStub = sandbox.stub();
|
|
75
|
+
loggerStub = sandbox.stub(logger);
|
|
76
|
+
consoleLogStub = sandbox.stub(console, "log");
|
|
77
|
+
|
|
78
|
+
sandbox
|
|
79
|
+
.stub(ClientConfiguration.prototype, "doesConfigExists")
|
|
80
|
+
.returns(false);
|
|
81
|
+
sandbox
|
|
82
|
+
.stub(PackagesApi.prototype, "listPackages")
|
|
83
|
+
.callsFake(listPackagesStub);
|
|
84
|
+
|
|
85
|
+
const result = await listPackages("http://test-server", false);
|
|
86
|
+
|
|
87
|
+
expect(listPackagesStub.called).to.be.false;
|
|
88
|
+
expect(result).to.be.undefined;
|
|
89
|
+
expect(
|
|
90
|
+
loggerStub.error.calledWith(
|
|
91
|
+
sinon.match("Please, make sure that you are logged in"),
|
|
92
|
+
),
|
|
93
|
+
).to.be.true;
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it("should handle missing project", async () => {
|
|
97
|
+
sandbox.restore();
|
|
98
|
+
sandbox = sinon.createSandbox();
|
|
99
|
+
listPackagesStub = sandbox.stub();
|
|
100
|
+
loggerStub = sandbox.stub(logger);
|
|
101
|
+
consoleLogStub = sandbox.stub(console, "log");
|
|
102
|
+
|
|
103
|
+
sandbox
|
|
104
|
+
.stub(ClientConfiguration.prototype, "doesConfigExists")
|
|
105
|
+
.returns(true);
|
|
106
|
+
sandbox.stub(ClientConfiguration.prototype, "getProject").returns("");
|
|
107
|
+
sandbox
|
|
108
|
+
.stub(PackagesApi.prototype, "listPackages")
|
|
109
|
+
.callsFake(listPackagesStub);
|
|
110
|
+
|
|
111
|
+
const result = await listPackages("http://test-server", false);
|
|
112
|
+
|
|
113
|
+
expect(listPackagesStub.called).to.be.false;
|
|
114
|
+
expect(result).to.be.undefined;
|
|
115
|
+
expect(
|
|
116
|
+
loggerStub.error.calledWith(
|
|
117
|
+
sinon.match("Please, make sure to set a project"),
|
|
118
|
+
),
|
|
119
|
+
).to.be.true;
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it("should handle API errors", async () => {
|
|
123
|
+
const mockError = new Error("API Error");
|
|
124
|
+
listPackagesStub.rejects(mockError);
|
|
125
|
+
|
|
126
|
+
const result = await listPackages("http://test-server", true);
|
|
127
|
+
|
|
128
|
+
expect(listPackagesStub.calledOnce).to.be.true;
|
|
129
|
+
expect(result).to.be.undefined;
|
|
130
|
+
expect(
|
|
131
|
+
loggerStub.error.calledWith(sinon.match("Failed to list packages")),
|
|
132
|
+
).to.be.true;
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it("should print packages when using printOutPackages", async () => {
|
|
136
|
+
const mockPackages = [{ name: "package1" }];
|
|
137
|
+
const mockResponse = {
|
|
138
|
+
data: mockPackages,
|
|
139
|
+
headers: {},
|
|
140
|
+
};
|
|
141
|
+
listPackagesStub.resolves(mockResponse);
|
|
142
|
+
|
|
143
|
+
await printOutPackages("http://test-server", false);
|
|
144
|
+
|
|
145
|
+
expect(consoleLogStub.called).to.be.true;
|
|
146
|
+
});
|
|
147
|
+
});
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { PackagesApi } from "../../client/api";
|
|
2
|
+
import { Configuration } from "../../client/configuration";
|
|
3
|
+
import { ClientConfiguration } from "../../clientconfiguration";
|
|
4
|
+
import { logger } from "../../logger";
|
|
5
|
+
import {
|
|
6
|
+
prettifyJson,
|
|
7
|
+
printOutError,
|
|
8
|
+
parsePaginationParams,
|
|
9
|
+
extractTotalCount,
|
|
10
|
+
} from "../../utils";
|
|
11
|
+
|
|
12
|
+
const packagesApi = new PackagesApi(new Configuration());
|
|
13
|
+
|
|
14
|
+
export async function listPackages(
|
|
15
|
+
controlPlane: string,
|
|
16
|
+
debug: boolean,
|
|
17
|
+
page?: string | number,
|
|
18
|
+
pageSize?: string | number,
|
|
19
|
+
) {
|
|
20
|
+
const clientConfig = new ClientConfiguration();
|
|
21
|
+
const organizationName = clientConfig.getOrganization();
|
|
22
|
+
const projectName = clientConfig.getProject();
|
|
23
|
+
|
|
24
|
+
if (!clientConfig.doesConfigExists()) {
|
|
25
|
+
logger.error("Please, make sure that you are logged in");
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (!projectName) {
|
|
30
|
+
logger.error("Please, make sure to set a project");
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
try {
|
|
35
|
+
const { limit, offset } = parsePaginationParams(page, pageSize);
|
|
36
|
+
const response = await packagesApi.listPackages(
|
|
37
|
+
organizationName,
|
|
38
|
+
projectName,
|
|
39
|
+
limit,
|
|
40
|
+
offset,
|
|
41
|
+
{
|
|
42
|
+
baseURL: controlPlane,
|
|
43
|
+
headers: clientConfig.getHeaders(),
|
|
44
|
+
},
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
const totalCount = extractTotalCount(response.headers);
|
|
48
|
+
|
|
49
|
+
return {
|
|
50
|
+
packages: response.data,
|
|
51
|
+
totalCount,
|
|
52
|
+
};
|
|
53
|
+
} catch (e) {
|
|
54
|
+
logger.error("Failed to list packages");
|
|
55
|
+
printOutError(e, debug);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export async function printOutPackages(
|
|
60
|
+
controlPlane: string,
|
|
61
|
+
debug: boolean,
|
|
62
|
+
page?: string | number,
|
|
63
|
+
pageSize?: string | number,
|
|
64
|
+
) {
|
|
65
|
+
const packages = await listPackages(controlPlane, debug, page, pageSize);
|
|
66
|
+
console.log(prettifyJson(packages));
|
|
67
|
+
}
|