@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,57 @@
|
|
|
1
|
+
import { ConnectionsApi } 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 connectionsApi = new ConnectionsApi(new Configuration());
|
|
8
|
+
|
|
9
|
+
export const deleteConnection = async (
|
|
10
|
+
controlPlane: string,
|
|
11
|
+
connectionName: string,
|
|
12
|
+
debug: boolean,
|
|
13
|
+
autoConfirm: boolean,
|
|
14
|
+
) => {
|
|
15
|
+
const clientConfig = new ClientConfiguration();
|
|
16
|
+
const organizationName = clientConfig.getOrganization();
|
|
17
|
+
const projectName = clientConfig.getProject();
|
|
18
|
+
|
|
19
|
+
if (!clientConfig.doesConfigExists()) {
|
|
20
|
+
logger.error("Please, make sure that you are logged in");
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (!projectName) {
|
|
25
|
+
logger.error("Please, make sure to set a project");
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (!autoConfirm) {
|
|
30
|
+
const confirmation = await getConfirmation(
|
|
31
|
+
`Are you sure you that want to delete the ${connectionName} connection? This action cannot be undone.`,
|
|
32
|
+
);
|
|
33
|
+
if (!confirmation) {
|
|
34
|
+
logger.info("Operation cancelled.");
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
logger.info("Deleting connection " + connectionName);
|
|
40
|
+
|
|
41
|
+
try {
|
|
42
|
+
await connectionsApi.deleteConnection(
|
|
43
|
+
organizationName,
|
|
44
|
+
projectName,
|
|
45
|
+
connectionName,
|
|
46
|
+
{
|
|
47
|
+
baseURL: controlPlane,
|
|
48
|
+
headers: clientConfig.getHeaders(),
|
|
49
|
+
},
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
logger.info("Connection deleted successfully");
|
|
53
|
+
} catch (e) {
|
|
54
|
+
logger.error("Failed to delete connection");
|
|
55
|
+
printOutError(e, debug);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { expect } from "chai";
|
|
2
|
+
import sinon from "sinon";
|
|
3
|
+
import { ConnectionsApi } from "../../client/api";
|
|
4
|
+
import { ClientConfiguration } from "../../clientconfiguration";
|
|
5
|
+
import { logger } from "../../logger";
|
|
6
|
+
import { prettifyJson } from "../../utils";
|
|
7
|
+
import { listConnections } from "./listconnections";
|
|
8
|
+
|
|
9
|
+
describe("list-connections", () => {
|
|
10
|
+
let sandbox: sinon.SinonSandbox;
|
|
11
|
+
let listConnectionsStub: sinon.SinonStub;
|
|
12
|
+
let loggerStub: sinon.SinonStubbedInstance<typeof logger>;
|
|
13
|
+
let consoleLogStub: sinon.SinonStub;
|
|
14
|
+
|
|
15
|
+
beforeEach(() => {
|
|
16
|
+
sandbox = sinon.createSandbox();
|
|
17
|
+
listConnectionsStub = 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(ConnectionsApi.prototype, "listConnections")
|
|
36
|
+
.callsFake(listConnectionsStub);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
afterEach(() => {
|
|
40
|
+
sandbox.restore();
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("should list connections successfully", async () => {
|
|
44
|
+
const mockConnections = [
|
|
45
|
+
{ name: "conn1", type: "postgres" },
|
|
46
|
+
{ name: "conn2", type: "mysql" },
|
|
47
|
+
];
|
|
48
|
+
const mockResponse = {
|
|
49
|
+
data: mockConnections,
|
|
50
|
+
headers: {},
|
|
51
|
+
};
|
|
52
|
+
listConnectionsStub.resolves(mockResponse);
|
|
53
|
+
|
|
54
|
+
await listConnections("http://test-server", false);
|
|
55
|
+
|
|
56
|
+
expect(listConnectionsStub.calledOnce).to.be.true;
|
|
57
|
+
expect(listConnectionsStub.firstCall.args[0]).to.equal("test-org");
|
|
58
|
+
expect(listConnectionsStub.firstCall.args[1]).to.equal("test-project");
|
|
59
|
+
expect(listConnectionsStub.firstCall.args[2]).to.equal(-1); // limit
|
|
60
|
+
expect(listConnectionsStub.firstCall.args[3]).to.equal(0); // offset
|
|
61
|
+
expect(listConnectionsStub.firstCall.args[4]).to.deep.include({
|
|
62
|
+
baseURL: "http://test-server",
|
|
63
|
+
headers: { Authorization: "Bearer test-token" },
|
|
64
|
+
});
|
|
65
|
+
expect(consoleLogStub.calledOnce).to.be.true;
|
|
66
|
+
const loggedValue = consoleLogStub.firstCall.args[0];
|
|
67
|
+
const parsed = JSON.parse(loggedValue);
|
|
68
|
+
expect(parsed).to.have.property("connections");
|
|
69
|
+
expect(parsed.connections).to.deep.equal(mockConnections);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it("should handle missing config", async () => {
|
|
73
|
+
sandbox.restore();
|
|
74
|
+
sandbox = sinon.createSandbox();
|
|
75
|
+
listConnectionsStub = sandbox.stub();
|
|
76
|
+
loggerStub = sandbox.stub(logger);
|
|
77
|
+
consoleLogStub = sandbox.stub(console, "log");
|
|
78
|
+
|
|
79
|
+
sandbox
|
|
80
|
+
.stub(ClientConfiguration.prototype, "doesConfigExists")
|
|
81
|
+
.returns(false);
|
|
82
|
+
sandbox
|
|
83
|
+
.stub(ConnectionsApi.prototype, "listConnections")
|
|
84
|
+
.callsFake(listConnectionsStub);
|
|
85
|
+
|
|
86
|
+
await listConnections("http://test-server", false);
|
|
87
|
+
|
|
88
|
+
expect(listConnectionsStub.called).to.be.false;
|
|
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
|
+
listConnectionsStub = 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(ConnectionsApi.prototype, "listConnections")
|
|
109
|
+
.callsFake(listConnectionsStub);
|
|
110
|
+
|
|
111
|
+
await listConnections("http://test-server", false);
|
|
112
|
+
|
|
113
|
+
expect(listConnectionsStub.called).to.be.false;
|
|
114
|
+
expect(
|
|
115
|
+
loggerStub.error.calledWith(
|
|
116
|
+
sinon.match("Please, make sure to set a project"),
|
|
117
|
+
),
|
|
118
|
+
).to.be.true;
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it("should handle API errors", async () => {
|
|
122
|
+
const mockError = new Error("API Error");
|
|
123
|
+
listConnectionsStub.rejects(mockError);
|
|
124
|
+
|
|
125
|
+
await listConnections("http://test-server", true);
|
|
126
|
+
|
|
127
|
+
expect(listConnectionsStub.calledOnce).to.be.true;
|
|
128
|
+
expect(
|
|
129
|
+
loggerStub.error.calledWith(sinon.match("Failed to list connections")),
|
|
130
|
+
).to.be.true;
|
|
131
|
+
});
|
|
132
|
+
});
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { ConnectionsApi } 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 connectionsApi = new ConnectionsApi(new Configuration());
|
|
13
|
+
|
|
14
|
+
export const listConnections = async (
|
|
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 connectionsApi.listConnections(
|
|
37
|
+
organizationName,
|
|
38
|
+
projectName,
|
|
39
|
+
limit,
|
|
40
|
+
offset,
|
|
41
|
+
{
|
|
42
|
+
baseURL: controlPlane,
|
|
43
|
+
headers: clientConfig.getHeaders(),
|
|
44
|
+
},
|
|
45
|
+
);
|
|
46
|
+
const totalCount = extractTotalCount(response.headers);
|
|
47
|
+
|
|
48
|
+
const payload = {
|
|
49
|
+
connections: response.data,
|
|
50
|
+
totalCount,
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
console.log(prettifyJson(payload));
|
|
54
|
+
} catch (e) {
|
|
55
|
+
logger.error("Failed to list connections");
|
|
56
|
+
printOutError(e, debug);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import { controlPlanesByEnv, Environment } from "../constants";
|
|
3
|
+
import { getGroup } from "./group/getgroup";
|
|
4
|
+
import { getProject } from "./project/getproject";
|
|
5
|
+
|
|
6
|
+
export const registerGetCommands = (cli: Command, environment: Environment) => {
|
|
7
|
+
const get = cli
|
|
8
|
+
.command("get")
|
|
9
|
+
.description("Get a resource")
|
|
10
|
+
.argument("<resource>", "The resource to get (project | group)");
|
|
11
|
+
|
|
12
|
+
get.command("project")
|
|
13
|
+
.description("Get a project by name.")
|
|
14
|
+
.argument("<projectName>", "The name of the project to get.")
|
|
15
|
+
.option("--debug")
|
|
16
|
+
.action((projectName, options) => {
|
|
17
|
+
getProject(
|
|
18
|
+
controlPlanesByEnv[environment],
|
|
19
|
+
projectName,
|
|
20
|
+
options.debug,
|
|
21
|
+
);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
get.command("group")
|
|
25
|
+
.description("Get a group by name.")
|
|
26
|
+
.argument("<groupName>", "The name of the group to get.")
|
|
27
|
+
.option("--debug")
|
|
28
|
+
.action((groupName, options) => {
|
|
29
|
+
getGroup(controlPlanesByEnv[environment], groupName, options.debug);
|
|
30
|
+
});
|
|
31
|
+
};
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
import { expect } from "chai";
|
|
2
|
+
import sinon from "sinon";
|
|
3
|
+
import { GroupsApi } from "../../client/api";
|
|
4
|
+
import { ClientConfiguration } from "../../clientconfiguration";
|
|
5
|
+
import { logger } from "../../logger";
|
|
6
|
+
import { addMember } from "./addmember";
|
|
7
|
+
|
|
8
|
+
describe("add-member", () => {
|
|
9
|
+
let sandbox: sinon.SinonSandbox;
|
|
10
|
+
let addGroupMembersStub: sinon.SinonStub;
|
|
11
|
+
let loggerStub: sinon.SinonStubbedInstance<typeof logger>;
|
|
12
|
+
let processExitStub: sinon.SinonStub;
|
|
13
|
+
|
|
14
|
+
beforeEach(() => {
|
|
15
|
+
sandbox = sinon.createSandbox();
|
|
16
|
+
addGroupMembersStub = sandbox.stub();
|
|
17
|
+
loggerStub = sandbox.stub(logger);
|
|
18
|
+
processExitStub = sandbox.stub(process, "exit");
|
|
19
|
+
|
|
20
|
+
sandbox
|
|
21
|
+
.stub(ClientConfiguration.prototype, "getOrganization")
|
|
22
|
+
.returns("test-org");
|
|
23
|
+
sandbox
|
|
24
|
+
.stub(ClientConfiguration.prototype, "doesConfigExists")
|
|
25
|
+
.returns(true);
|
|
26
|
+
sandbox
|
|
27
|
+
.stub(ClientConfiguration.prototype, "getAuthenticationHeader")
|
|
28
|
+
.returns("Bearer test-token");
|
|
29
|
+
|
|
30
|
+
sandbox
|
|
31
|
+
.stub(GroupsApi.prototype, "addGroupMembers")
|
|
32
|
+
.callsFake(addGroupMembersStub);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
afterEach(() => {
|
|
36
|
+
sandbox.restore();
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("should add user member successfully", async () => {
|
|
40
|
+
const mockResponse = {
|
|
41
|
+
data: {},
|
|
42
|
+
};
|
|
43
|
+
addGroupMembersStub.resolves(mockResponse);
|
|
44
|
+
|
|
45
|
+
await addMember(
|
|
46
|
+
"http://test-server",
|
|
47
|
+
"test-group",
|
|
48
|
+
"user",
|
|
49
|
+
"test-user",
|
|
50
|
+
"admin",
|
|
51
|
+
false,
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
expect(addGroupMembersStub.calledOnce).to.be.true;
|
|
55
|
+
expect(addGroupMembersStub.firstCall.args[0]).to.equal("test-org");
|
|
56
|
+
expect(addGroupMembersStub.firstCall.args[1]).to.equal("test-group");
|
|
57
|
+
expect(addGroupMembersStub.firstCall.args[2]).to.deep.include({
|
|
58
|
+
members: [
|
|
59
|
+
{
|
|
60
|
+
userGroupId: "user:test-user",
|
|
61
|
+
status: "admin",
|
|
62
|
+
},
|
|
63
|
+
],
|
|
64
|
+
});
|
|
65
|
+
expect(
|
|
66
|
+
loggerStub.info.calledWith(
|
|
67
|
+
sinon.match(
|
|
68
|
+
"Successfully added user test-user to group test-group with role admin",
|
|
69
|
+
),
|
|
70
|
+
),
|
|
71
|
+
).to.be.true;
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it("should add group member successfully", async () => {
|
|
75
|
+
const mockResponse = {
|
|
76
|
+
data: {},
|
|
77
|
+
};
|
|
78
|
+
addGroupMembersStub.resolves(mockResponse);
|
|
79
|
+
|
|
80
|
+
await addMember(
|
|
81
|
+
"http://test-server",
|
|
82
|
+
"test-group",
|
|
83
|
+
"group",
|
|
84
|
+
"test-subgroup",
|
|
85
|
+
"member",
|
|
86
|
+
false,
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
expect(addGroupMembersStub.firstCall.args[2]).to.deep.include({
|
|
90
|
+
members: [
|
|
91
|
+
{
|
|
92
|
+
userGroupId: "group:test-subgroup",
|
|
93
|
+
status: "member",
|
|
94
|
+
},
|
|
95
|
+
],
|
|
96
|
+
});
|
|
97
|
+
expect(
|
|
98
|
+
loggerStub.info.calledWith(
|
|
99
|
+
sinon.match(
|
|
100
|
+
"Successfully added group test-subgroup to group test-group with role member",
|
|
101
|
+
),
|
|
102
|
+
),
|
|
103
|
+
).to.be.true;
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it("should handle case-insensitive member type", async () => {
|
|
107
|
+
const mockResponse = {
|
|
108
|
+
data: {},
|
|
109
|
+
};
|
|
110
|
+
addGroupMembersStub.resolves(mockResponse);
|
|
111
|
+
|
|
112
|
+
await addMember(
|
|
113
|
+
"http://test-server",
|
|
114
|
+
"test-group",
|
|
115
|
+
"USER",
|
|
116
|
+
"test-user",
|
|
117
|
+
"admin",
|
|
118
|
+
false,
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
expect(
|
|
122
|
+
addGroupMembersStub.firstCall.args[2].members[0].userGroupId,
|
|
123
|
+
).to.equal("user:test-user");
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it("should handle missing config", async () => {
|
|
127
|
+
sandbox.restore();
|
|
128
|
+
sandbox = sinon.createSandbox();
|
|
129
|
+
addGroupMembersStub = sandbox.stub();
|
|
130
|
+
loggerStub = sandbox.stub(logger);
|
|
131
|
+
processExitStub = sandbox.stub(process, "exit");
|
|
132
|
+
|
|
133
|
+
sandbox
|
|
134
|
+
.stub(ClientConfiguration.prototype, "doesConfigExists")
|
|
135
|
+
.returns(false);
|
|
136
|
+
sandbox
|
|
137
|
+
.stub(GroupsApi.prototype, "addGroupMembers")
|
|
138
|
+
.callsFake(addGroupMembersStub);
|
|
139
|
+
|
|
140
|
+
await addMember(
|
|
141
|
+
"http://test-server",
|
|
142
|
+
"test-group",
|
|
143
|
+
"user",
|
|
144
|
+
"test-user",
|
|
145
|
+
"admin",
|
|
146
|
+
false,
|
|
147
|
+
);
|
|
148
|
+
|
|
149
|
+
expect(addGroupMembersStub.called).to.be.false;
|
|
150
|
+
expect(
|
|
151
|
+
loggerStub.error.calledWith(
|
|
152
|
+
sinon.match("Please, make sure that you are logged in"),
|
|
153
|
+
),
|
|
154
|
+
).to.be.true;
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
it("should handle missing organization", async () => {
|
|
158
|
+
sandbox.restore();
|
|
159
|
+
sandbox = sinon.createSandbox();
|
|
160
|
+
addGroupMembersStub = sandbox.stub();
|
|
161
|
+
loggerStub = sandbox.stub(logger);
|
|
162
|
+
processExitStub = sandbox.stub(process, "exit");
|
|
163
|
+
|
|
164
|
+
sandbox
|
|
165
|
+
.stub(ClientConfiguration.prototype, "doesConfigExists")
|
|
166
|
+
.returns(true);
|
|
167
|
+
sandbox
|
|
168
|
+
.stub(ClientConfiguration.prototype, "getOrganization")
|
|
169
|
+
.returns(undefined);
|
|
170
|
+
sandbox
|
|
171
|
+
.stub(GroupsApi.prototype, "addGroupMembers")
|
|
172
|
+
.callsFake(addGroupMembersStub);
|
|
173
|
+
|
|
174
|
+
await addMember(
|
|
175
|
+
"http://test-server",
|
|
176
|
+
"test-group",
|
|
177
|
+
"user",
|
|
178
|
+
"test-user",
|
|
179
|
+
"admin",
|
|
180
|
+
false,
|
|
181
|
+
);
|
|
182
|
+
|
|
183
|
+
expect(addGroupMembersStub.called).to.be.false;
|
|
184
|
+
expect(
|
|
185
|
+
loggerStub.error.calledWith(
|
|
186
|
+
sinon.match(
|
|
187
|
+
"No organization set. Please login or set an organization.",
|
|
188
|
+
),
|
|
189
|
+
),
|
|
190
|
+
).to.be.true;
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
it("should reject invalid member type", async () => {
|
|
194
|
+
await addMember(
|
|
195
|
+
"http://test-server",
|
|
196
|
+
"test-group",
|
|
197
|
+
"invalid",
|
|
198
|
+
"test-user",
|
|
199
|
+
"admin",
|
|
200
|
+
false,
|
|
201
|
+
);
|
|
202
|
+
|
|
203
|
+
expect(addGroupMembersStub.called).to.be.false;
|
|
204
|
+
expect(
|
|
205
|
+
loggerStub.error.calledWith(
|
|
206
|
+
sinon.match(
|
|
207
|
+
(value: string) =>
|
|
208
|
+
typeof value === "string" &&
|
|
209
|
+
value.includes("memberType") &&
|
|
210
|
+
value.includes("must be either 'user' or 'group'"),
|
|
211
|
+
),
|
|
212
|
+
),
|
|
213
|
+
).to.be.true;
|
|
214
|
+
expect(processExitStub.calledWith(1)).to.be.true;
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
it("should reject invalid role", async () => {
|
|
218
|
+
await addMember(
|
|
219
|
+
"http://test-server",
|
|
220
|
+
"test-group",
|
|
221
|
+
"user",
|
|
222
|
+
"test-user",
|
|
223
|
+
"invalid-role",
|
|
224
|
+
false,
|
|
225
|
+
);
|
|
226
|
+
|
|
227
|
+
expect(addGroupMembersStub.called).to.be.false;
|
|
228
|
+
expect(
|
|
229
|
+
loggerStub.error.calledWith(
|
|
230
|
+
sinon.match(/role must be either 'admin' or 'member'/),
|
|
231
|
+
),
|
|
232
|
+
).to.be.true;
|
|
233
|
+
expect(processExitStub.calledWith(1)).to.be.true;
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
it("should handle API errors", async () => {
|
|
237
|
+
const mockError = new Error("API Error");
|
|
238
|
+
addGroupMembersStub.rejects(mockError);
|
|
239
|
+
|
|
240
|
+
await addMember(
|
|
241
|
+
"http://test-server",
|
|
242
|
+
"test-group",
|
|
243
|
+
"user",
|
|
244
|
+
"test-user",
|
|
245
|
+
"admin",
|
|
246
|
+
true,
|
|
247
|
+
);
|
|
248
|
+
|
|
249
|
+
expect(addGroupMembersStub.calledOnce).to.be.true;
|
|
250
|
+
expect(
|
|
251
|
+
loggerStub.error.calledWith(
|
|
252
|
+
sinon.match("Failed to add member to group"),
|
|
253
|
+
),
|
|
254
|
+
).to.be.true;
|
|
255
|
+
expect(processExitStub.calledWith(1)).to.be.true;
|
|
256
|
+
});
|
|
257
|
+
});
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AddGroupMembersRequest,
|
|
3
|
+
GroupMember,
|
|
4
|
+
GroupsApi,
|
|
5
|
+
} from "../../client/api";
|
|
6
|
+
import { Configuration } from "../../client/configuration";
|
|
7
|
+
import { ClientConfiguration } from "../../clientconfiguration";
|
|
8
|
+
import { UserGroupId } from "../../common/UserGroupId";
|
|
9
|
+
import { logger } from "../../logger";
|
|
10
|
+
import { printOutError } from "../../utils";
|
|
11
|
+
|
|
12
|
+
const groupsApi = new GroupsApi(new Configuration());
|
|
13
|
+
|
|
14
|
+
export async function addMember(
|
|
15
|
+
controlPlane: string,
|
|
16
|
+
groupName: string,
|
|
17
|
+
memberType: string,
|
|
18
|
+
memberName: string,
|
|
19
|
+
role: string,
|
|
20
|
+
debug: boolean,
|
|
21
|
+
) {
|
|
22
|
+
const clientConfig = new ClientConfiguration();
|
|
23
|
+
|
|
24
|
+
if (!clientConfig.doesConfigExists()) {
|
|
25
|
+
logger.error("Please, make sure that you are logged in");
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const organizationName = clientConfig.getOrganization();
|
|
30
|
+
if (!organizationName) {
|
|
31
|
+
logger.error("No organization set. Please login or set an organization.");
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
logger.info(
|
|
36
|
+
`Adding ${memberType} ${memberName} to group ${groupName} in organization ${organizationName} with role ${role}`,
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
// Create UserGroupId based on member type
|
|
40
|
+
let userGroupId: UserGroupId;
|
|
41
|
+
if (memberType.toLowerCase() === "user") {
|
|
42
|
+
userGroupId = UserGroupId.forUser(memberName);
|
|
43
|
+
} else if (memberType.toLowerCase() === "group") {
|
|
44
|
+
userGroupId = UserGroupId.forGroup(memberName);
|
|
45
|
+
} else {
|
|
46
|
+
logger.error(
|
|
47
|
+
`Error: memberType ${memberType} must be either 'user' or 'group'`,
|
|
48
|
+
);
|
|
49
|
+
process.exit(1);
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Validate role
|
|
54
|
+
if (role !== "admin" && role !== "member") {
|
|
55
|
+
logger.error("Error: role must be either 'admin' or 'member'");
|
|
56
|
+
process.exit(1);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const groupMember: GroupMember = {
|
|
61
|
+
userGroupId: userGroupId.getValue(),
|
|
62
|
+
status: role as "admin" | "member",
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const request: AddGroupMembersRequest = {
|
|
66
|
+
members: [groupMember],
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
try {
|
|
70
|
+
await groupsApi.addGroupMembers(organizationName, groupName, request, {
|
|
71
|
+
baseURL: controlPlane,
|
|
72
|
+
headers: {
|
|
73
|
+
Authorization: clientConfig.getAuthenticationHeader(),
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
logger.info(
|
|
78
|
+
`Successfully added ${memberType} ${memberName} to group ${groupName} with role ${role}`,
|
|
79
|
+
);
|
|
80
|
+
} catch (error) {
|
|
81
|
+
logger.error("Failed to add member to group");
|
|
82
|
+
printOutError(error, debug);
|
|
83
|
+
process.exit(1);
|
|
84
|
+
}
|
|
85
|
+
}
|