@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.
Files changed (259) hide show
  1. package/.github/workflows/build.yml +23 -0
  2. package/.mocharc.json +10 -0
  3. package/.prettierignore +2 -0
  4. package/.prettierrc +4 -0
  5. package/README-DEV.md +40 -0
  6. package/README.md +11 -0
  7. package/bun.lock +1158 -0
  8. package/dist/client/api.js +7715 -0
  9. package/dist/client/api.js.map +1 -0
  10. package/dist/client/base.js +69 -0
  11. package/dist/client/base.js.map +1 -0
  12. package/dist/client/common.js +162 -0
  13. package/dist/client/common.js.map +1 -0
  14. package/dist/client/configuration.js +44 -0
  15. package/dist/client/configuration.js.map +1 -0
  16. package/dist/client/index.js +32 -0
  17. package/dist/client/index.js.map +1 -0
  18. package/dist/clientconfiguration.js +205 -0
  19. package/dist/clientconfiguration.js.map +1 -0
  20. package/dist/clientconfiguration.spec.js +381 -0
  21. package/dist/clientconfiguration.spec.js.map +1 -0
  22. package/dist/commands/add.js +66 -0
  23. package/dist/commands/add.js.map +1 -0
  24. package/dist/commands/connection/createconnections.js +89 -0
  25. package/dist/commands/connection/createconnections.js.map +1 -0
  26. package/dist/commands/connection/createconnections.spec.js +219 -0
  27. package/dist/commands/connection/createconnections.spec.js.map +1 -0
  28. package/dist/commands/connection/deleteconnection.js +52 -0
  29. package/dist/commands/connection/deleteconnection.js.map +1 -0
  30. package/dist/commands/connection/deleteconnection.spec.js +130 -0
  31. package/dist/commands/connection/deleteconnection.spec.js.map +1 -0
  32. package/dist/commands/connection/listconnections.js +50 -0
  33. package/dist/commands/connection/listconnections.js.map +1 -0
  34. package/dist/commands/connection/listconnections.spec.js +117 -0
  35. package/dist/commands/connection/listconnections.spec.js.map +1 -0
  36. package/dist/commands/get.js +28 -0
  37. package/dist/commands/get.js.map +1 -0
  38. package/dist/commands/group/addmember.js +75 -0
  39. package/dist/commands/group/addmember.js.map +1 -0
  40. package/dist/commands/group/addmember.spec.js +148 -0
  41. package/dist/commands/group/addmember.spec.js.map +1 -0
  42. package/dist/commands/group/creategroup.js +55 -0
  43. package/dist/commands/group/creategroup.js.map +1 -0
  44. package/dist/commands/group/creategroup.spec.js +122 -0
  45. package/dist/commands/group/creategroup.spec.js.map +1 -0
  46. package/dist/commands/group/deletegroup.js +48 -0
  47. package/dist/commands/group/deletegroup.js.map +1 -0
  48. package/dist/commands/group/deletegroup.spec.js +104 -0
  49. package/dist/commands/group/deletegroup.spec.js.map +1 -0
  50. package/dist/commands/group/getgroup.js +50 -0
  51. package/dist/commands/group/getgroup.js.map +1 -0
  52. package/dist/commands/group/getgroup.spec.js +111 -0
  53. package/dist/commands/group/getgroup.spec.js.map +1 -0
  54. package/dist/commands/group/listgroups.js +56 -0
  55. package/dist/commands/group/listgroups.js.map +1 -0
  56. package/dist/commands/group/listgroups.spec.js +118 -0
  57. package/dist/commands/group/listgroups.spec.js.map +1 -0
  58. package/dist/commands/group/removemember.js +69 -0
  59. package/dist/commands/group/removemember.js.map +1 -0
  60. package/dist/commands/group/removemember.spec.js +138 -0
  61. package/dist/commands/group/removemember.spec.js.map +1 -0
  62. package/dist/commands/groupaccesstoken/createToken.js +53 -0
  63. package/dist/commands/groupaccesstoken/createToken.js.map +1 -0
  64. package/dist/commands/groupaccesstoken/createToken.spec.js +127 -0
  65. package/dist/commands/groupaccesstoken/createToken.spec.js.map +1 -0
  66. package/dist/commands/groupaccesstoken/deleteToken.js +24 -0
  67. package/dist/commands/groupaccesstoken/deleteToken.js.map +1 -0
  68. package/dist/commands/groupaccesstoken/deleteToken.spec.js +103 -0
  69. package/dist/commands/groupaccesstoken/deleteToken.spec.js.map +1 -0
  70. package/dist/commands/groupaccesstoken/groupContainer.js +71 -0
  71. package/dist/commands/groupaccesstoken/groupContainer.js.map +1 -0
  72. package/dist/commands/groupaccesstoken/listTokens.js +25 -0
  73. package/dist/commands/groupaccesstoken/listTokens.js.map +1 -0
  74. package/dist/commands/groupaccesstoken/listTokens.spec.js +115 -0
  75. package/dist/commands/groupaccesstoken/listTokens.spec.js.map +1 -0
  76. package/dist/commands/list.js +75 -0
  77. package/dist/commands/list.js.map +1 -0
  78. package/dist/commands/misc/login.js +290 -0
  79. package/dist/commands/misc/login.js.map +1 -0
  80. package/dist/commands/misc/login.spec.js +243 -0
  81. package/dist/commands/misc/login.spec.js.map +1 -0
  82. package/dist/commands/misc/logout.js +11 -0
  83. package/dist/commands/misc/logout.js.map +1 -0
  84. package/dist/commands/misc/logout.spec.js +30 -0
  85. package/dist/commands/misc/logout.spec.js.map +1 -0
  86. package/dist/commands/misc/loopbackOAuth.js +110 -0
  87. package/dist/commands/misc/loopbackOAuth.js.map +1 -0
  88. package/dist/commands/misc/set-access-token.js +27 -0
  89. package/dist/commands/misc/set-access-token.js.map +1 -0
  90. package/dist/commands/misc/set-access-token.spec.js +65 -0
  91. package/dist/commands/misc/set-access-token.spec.js.map +1 -0
  92. package/dist/commands/package/deletepackage.js +54 -0
  93. package/dist/commands/package/deletepackage.js.map +1 -0
  94. package/dist/commands/package/deletepackage.spec.js +136 -0
  95. package/dist/commands/package/deletepackage.spec.js.map +1 -0
  96. package/dist/commands/package/listpackages.js +57 -0
  97. package/dist/commands/package/listpackages.js.map +1 -0
  98. package/dist/commands/package/listpackages.spec.js +129 -0
  99. package/dist/commands/package/listpackages.spec.js.map +1 -0
  100. package/dist/commands/package/publish.js +157 -0
  101. package/dist/commands/package/publish.js.map +1 -0
  102. package/dist/commands/package/publish.spec.js +511 -0
  103. package/dist/commands/package/publish.spec.js.map +1 -0
  104. package/dist/commands/package/updatepackage.js +75 -0
  105. package/dist/commands/package/updatepackage.js.map +1 -0
  106. package/dist/commands/package/updatepackage.spec.js +189 -0
  107. package/dist/commands/package/updatepackage.spec.js.map +1 -0
  108. package/dist/commands/project/createproject.js +75 -0
  109. package/dist/commands/project/createproject.js.map +1 -0
  110. package/dist/commands/project/createproject.spec.js +154 -0
  111. package/dist/commands/project/createproject.spec.js.map +1 -0
  112. package/dist/commands/project/deleteproject.js +49 -0
  113. package/dist/commands/project/deleteproject.js.map +1 -0
  114. package/dist/commands/project/deleteproject.spec.js +106 -0
  115. package/dist/commands/project/deleteproject.spec.js.map +1 -0
  116. package/dist/commands/project/getproject.js +44 -0
  117. package/dist/commands/project/getproject.js.map +1 -0
  118. package/dist/commands/project/getproject.spec.js +99 -0
  119. package/dist/commands/project/getproject.spec.js.map +1 -0
  120. package/dist/commands/project/listprojects.js +52 -0
  121. package/dist/commands/project/listprojects.js.map +1 -0
  122. package/dist/commands/project/listprojects.spec.js +111 -0
  123. package/dist/commands/project/listprojects.spec.js.map +1 -0
  124. package/dist/commands/project/setproject.js +26 -0
  125. package/dist/commands/project/setproject.js.map +1 -0
  126. package/dist/commands/project/setproject.spec.js +58 -0
  127. package/dist/commands/project/setproject.spec.js.map +1 -0
  128. package/dist/commands/project/updateproject.js +68 -0
  129. package/dist/commands/project/updateproject.js.map +1 -0
  130. package/dist/commands/project/updateproject.spec.js +129 -0
  131. package/dist/commands/project/updateproject.spec.js.map +1 -0
  132. package/dist/commands/rm.js +68 -0
  133. package/dist/commands/rm.js.map +1 -0
  134. package/dist/commands/set.js +17 -0
  135. package/dist/commands/set.js.map +1 -0
  136. package/dist/commands/update.js +42 -0
  137. package/dist/commands/update.js.map +1 -0
  138. package/dist/commands/version/archive-unarchive-version.js +79 -0
  139. package/dist/commands/version/archive-unarchive-version.js.map +1 -0
  140. package/dist/commands/version/archive-unarchive-version.spec.js +244 -0
  141. package/dist/commands/version/archive-unarchive-version.spec.js.map +1 -0
  142. package/dist/commands/version/listversions.js +46 -0
  143. package/dist/commands/version/listversions.js.map +1 -0
  144. package/dist/commands/version/listversions.spec.js +121 -0
  145. package/dist/commands/version/listversions.spec.js.map +1 -0
  146. package/dist/common/UserGroupId.js +112 -0
  147. package/dist/common/UserGroupId.js.map +1 -0
  148. package/dist/common/UserGroupId.spec.js +92 -0
  149. package/dist/common/UserGroupId.spec.js.map +1 -0
  150. package/dist/constants.js +90 -0
  151. package/dist/constants.js.map +1 -0
  152. package/dist/index.js +159 -0
  153. package/dist/index.js.map +1 -0
  154. package/dist/logger.js +77 -0
  155. package/dist/logger.js.map +1 -0
  156. package/dist/logger.spec.js +125 -0
  157. package/dist/logger.spec.js.map +1 -0
  158. package/dist/polyfills/file.polyfill.js +6 -0
  159. package/dist/polyfills/file.polyfill.js.map +1 -0
  160. package/dist/utils.js +110 -0
  161. package/dist/utils.js.map +1 -0
  162. package/dist/utils.spec.js +158 -0
  163. package/dist/utils.spec.js.map +1 -0
  164. package/dist/validator.js +53 -0
  165. package/dist/validator.js.map +1 -0
  166. package/dist/validator.spec.js +41 -0
  167. package/dist/validator.spec.js.map +1 -0
  168. package/docker/Dockerfile.ci +18 -0
  169. package/docker-compose.yml +18 -0
  170. package/eslint.config.mjs +45 -0
  171. package/generate-client.sh +27 -0
  172. package/mocha.setup.ts +4 -0
  173. package/openapitools.json +7 -0
  174. package/package.json +75 -0
  175. package/src/client/.openapi-generator/FILES +9 -0
  176. package/src/client/.openapi-generator/VERSION +1 -0
  177. package/src/client/.openapi-generator-ignore +23 -0
  178. package/src/client/api.ts +9729 -0
  179. package/src/client/base.ts +86 -0
  180. package/src/client/common.ts +150 -0
  181. package/src/client/configuration.ts +110 -0
  182. package/src/client/git_push.sh +57 -0
  183. package/src/client/index.ts +18 -0
  184. package/src/clientconfiguration.spec.ts +490 -0
  185. package/src/clientconfiguration.ts +263 -0
  186. package/src/commands/add.ts +125 -0
  187. package/src/commands/connection/createconnections.spec.ts +403 -0
  188. package/src/commands/connection/createconnections.ts +109 -0
  189. package/src/commands/connection/deleteconnection.spec.ts +189 -0
  190. package/src/commands/connection/deleteconnection.ts +57 -0
  191. package/src/commands/connection/listconnections.spec.ts +132 -0
  192. package/src/commands/connection/listconnections.ts +58 -0
  193. package/src/commands/get.ts +31 -0
  194. package/src/commands/group/addmember.spec.ts +257 -0
  195. package/src/commands/group/addmember.ts +85 -0
  196. package/src/commands/group/creategroup.spec.ts +146 -0
  197. package/src/commands/group/creategroup.ts +54 -0
  198. package/src/commands/group/deletegroup.spec.ts +120 -0
  199. package/src/commands/group/deletegroup.ts +45 -0
  200. package/src/commands/group/getgroup.spec.ts +129 -0
  201. package/src/commands/group/getgroup.ts +47 -0
  202. package/src/commands/group/listgroups.spec.ts +137 -0
  203. package/src/commands/group/listgroups.ts +45 -0
  204. package/src/commands/group/removemember.spec.ts +224 -0
  205. package/src/commands/group/removemember.ts +75 -0
  206. package/src/commands/groupaccesstoken/createToken.spec.ts +211 -0
  207. package/src/commands/groupaccesstoken/createToken.ts +72 -0
  208. package/src/commands/groupaccesstoken/deleteToken.spec.ts +147 -0
  209. package/src/commands/groupaccesstoken/deleteToken.ts +29 -0
  210. package/src/commands/groupaccesstoken/groupContainer.ts +83 -0
  211. package/src/commands/groupaccesstoken/listTokens.spec.ts +147 -0
  212. package/src/commands/groupaccesstoken/listTokens.ts +29 -0
  213. package/src/commands/list.ts +131 -0
  214. package/src/commands/misc/login.spec.ts +213 -0
  215. package/src/commands/misc/login.ts +325 -0
  216. package/src/commands/misc/logout.spec.ts +32 -0
  217. package/src/commands/misc/logout.ts +9 -0
  218. package/src/commands/misc/loopbackOAuth.ts +127 -0
  219. package/src/commands/misc/set-access-token.spec.ts +95 -0
  220. package/src/commands/misc/set-access-token.ts +32 -0
  221. package/src/commands/package/deletepackage.spec.ts +164 -0
  222. package/src/commands/package/deletepackage.ts +58 -0
  223. package/src/commands/package/listpackages.spec.ts +147 -0
  224. package/src/commands/package/listpackages.ts +67 -0
  225. package/src/commands/package/publish.spec.ts +597 -0
  226. package/src/commands/package/publish.ts +211 -0
  227. package/src/commands/package/updatepackage.spec.ts +319 -0
  228. package/src/commands/package/updatepackage.ts +95 -0
  229. package/src/commands/project/createproject.spec.ts +247 -0
  230. package/src/commands/project/createproject.ts +70 -0
  231. package/src/commands/project/deleteproject.spec.ts +123 -0
  232. package/src/commands/project/deleteproject.ts +48 -0
  233. package/src/commands/project/getproject.spec.ts +109 -0
  234. package/src/commands/project/getproject.ts +43 -0
  235. package/src/commands/project/listprojects.spec.ts +121 -0
  236. package/src/commands/project/listprojects.ts +62 -0
  237. package/src/commands/project/setproject.spec.ts +63 -0
  238. package/src/commands/project/setproject.ts +14 -0
  239. package/src/commands/project/updateproject.spec.ts +217 -0
  240. package/src/commands/project/updateproject.ts +82 -0
  241. package/src/commands/rm.ts +101 -0
  242. package/src/commands/set.ts +16 -0
  243. package/src/commands/update.ts +64 -0
  244. package/src/commands/version/archive-unarchive-version.spec.ts +456 -0
  245. package/src/commands/version/archive-unarchive-version.ts +111 -0
  246. package/src/commands/version/listversions.spec.ts +138 -0
  247. package/src/commands/version/listversions.ts +45 -0
  248. package/src/common/UserGroupId.spec.ts +117 -0
  249. package/src/common/UserGroupId.ts +137 -0
  250. package/src/constants.ts +116 -0
  251. package/src/index.ts +209 -0
  252. package/src/logger.spec.ts +158 -0
  253. package/src/logger.ts +86 -0
  254. package/src/polyfills/file.polyfill.ts +6 -0
  255. package/src/utils.spec.ts +135 -0
  256. package/src/utils.ts +115 -0
  257. package/src/validator.spec.ts +51 -0
  258. package/src/validator.ts +44 -0
  259. package/tsconfig.json +17 -0
@@ -0,0 +1,147 @@
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 { deleteGroupAccessToken } from "./deleteToken";
7
+
8
+ describe("delete-group-access-token", () => {
9
+ let sandbox: sinon.SinonSandbox;
10
+ let deleteGroupAccessTokenStub: sinon.SinonStub;
11
+ let loggerStub: sinon.SinonStubbedInstance<typeof logger>;
12
+ let processExitStub: sinon.SinonStub;
13
+
14
+ beforeEach(() => {
15
+ sandbox = sinon.createSandbox();
16
+ deleteGroupAccessTokenStub = 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, "deleteGroupAccessToken")
32
+ .callsFake(deleteGroupAccessTokenStub);
33
+ });
34
+
35
+ afterEach(() => {
36
+ sandbox.restore();
37
+ });
38
+
39
+ it("should delete group access token successfully", async () => {
40
+ deleteGroupAccessTokenStub.resolves({ status: 200 });
41
+
42
+ await deleteGroupAccessToken(
43
+ "http://test-server",
44
+ "test-group",
45
+ "test-token",
46
+ false,
47
+ );
48
+
49
+ expect(deleteGroupAccessTokenStub.calledOnce).to.be.true;
50
+ expect(deleteGroupAccessTokenStub.firstCall.args[0]).to.equal("test-org");
51
+ expect(deleteGroupAccessTokenStub.firstCall.args[1]).to.equal(
52
+ "test-group",
53
+ );
54
+ expect(deleteGroupAccessTokenStub.firstCall.args[2]).to.equal(
55
+ "test-token",
56
+ );
57
+ expect(
58
+ loggerStub.info.calledWith(
59
+ sinon.match(
60
+ "Successfully deleted access token test-token. This token has been immediately revoked.",
61
+ ),
62
+ ),
63
+ ).to.be.true;
64
+ });
65
+
66
+ it("should handle missing config", async () => {
67
+ sandbox.restore();
68
+ sandbox = sinon.createSandbox();
69
+ deleteGroupAccessTokenStub = sandbox.stub();
70
+ loggerStub = sandbox.stub(logger);
71
+ processExitStub = sandbox.stub(process, "exit");
72
+
73
+ sandbox
74
+ .stub(ClientConfiguration.prototype, "doesConfigExists")
75
+ .returns(false);
76
+ sandbox
77
+ .stub(GroupsApi.prototype, "deleteGroupAccessToken")
78
+ .callsFake(deleteGroupAccessTokenStub);
79
+
80
+ const result = await deleteGroupAccessToken(
81
+ "http://test-server",
82
+ "test-group",
83
+ "test-token",
84
+ false,
85
+ );
86
+
87
+ expect(deleteGroupAccessTokenStub.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 organization", async () => {
97
+ sandbox.restore();
98
+ sandbox = sinon.createSandbox();
99
+ deleteGroupAccessTokenStub = sandbox.stub();
100
+ loggerStub = sandbox.stub(logger);
101
+ processExitStub = sandbox.stub(process, "exit");
102
+
103
+ sandbox
104
+ .stub(ClientConfiguration.prototype, "doesConfigExists")
105
+ .returns(true);
106
+ sandbox
107
+ .stub(ClientConfiguration.prototype, "getOrganization")
108
+ .returns(undefined);
109
+ sandbox
110
+ .stub(GroupsApi.prototype, "deleteGroupAccessToken")
111
+ .callsFake(deleteGroupAccessTokenStub);
112
+
113
+ const result = await deleteGroupAccessToken(
114
+ "http://test-server",
115
+ "test-group",
116
+ "test-token",
117
+ false,
118
+ );
119
+
120
+ expect(deleteGroupAccessTokenStub.called).to.be.false;
121
+ expect(result).to.be.undefined;
122
+ expect(
123
+ loggerStub.error.calledWith(
124
+ sinon.match(
125
+ "No organization set. Please login or set an organization.",
126
+ ),
127
+ ),
128
+ ).to.be.true;
129
+ });
130
+
131
+ it("should handle API errors", async () => {
132
+ const mockError = new Error("API Error");
133
+ deleteGroupAccessTokenStub.rejects(mockError);
134
+
135
+ await deleteGroupAccessToken(
136
+ "http://test-server",
137
+ "test-group",
138
+ "test-token",
139
+ true,
140
+ );
141
+
142
+ expect(deleteGroupAccessTokenStub.calledOnce).to.be.true;
143
+ expect(loggerStub.error.calledWith(sinon.match("Operation failed"))).to.be
144
+ .true;
145
+ expect(processExitStub.calledWith(1)).to.be.true;
146
+ });
147
+ });
@@ -0,0 +1,29 @@
1
+ import { logger } from "../../logger";
2
+ import { withGroupContext } from "./groupContainer";
3
+
4
+ export async function deleteGroupAccessToken(
5
+ controlPlane: string,
6
+ groupName: string,
7
+ tokenName: string,
8
+ debug: boolean,
9
+ ) {
10
+ return withGroupContext(
11
+ controlPlane,
12
+ async (context) => {
13
+ const { organizationName, groupsApi, options } = context;
14
+
15
+ logger.info(
16
+ `Deleting access token ${tokenName} from group ${groupName} in organization ${organizationName}`,
17
+ );
18
+
19
+ await groupsApi.deleteGroupAccessToken(
20
+ organizationName,
21
+ groupName,
22
+ tokenName,
23
+ options,
24
+ );
25
+ },
26
+ `Successfully deleted access token ${tokenName}. This token has been immediately revoked.`,
27
+ debug,
28
+ );
29
+ }
@@ -0,0 +1,83 @@
1
+ import { GroupsApi } from "../../client/api";
2
+ import { Configuration } from "../../client/configuration";
3
+ import { ClientConfiguration } from "../../clientconfiguration";
4
+ import { logger } from "../../logger";
5
+ import { printOutError } from "../../utils";
6
+
7
+ export interface ApiOptions {
8
+ baseURL: string;
9
+ headers: {
10
+ Authorization: string;
11
+ };
12
+ params?: Record<string, unknown>;
13
+ }
14
+
15
+ export interface GroupContext {
16
+ organizationName: string;
17
+ groupsApi: GroupsApi;
18
+ options: ApiOptions;
19
+ }
20
+
21
+ /**
22
+ * Container function that handles common ClientConfiguration checks, setup,
23
+ * error handling, and response printing for group access token operations.
24
+ *
25
+ * @param controlPlane The control plane URL
26
+ * @param handler The handler function to execute with the configured context
27
+ * @param successMessage Optional success message to display after the operation
28
+ * @param debug Whether to enable debug mode for error output
29
+ * @returns The result of the handler function, or void if validation fails
30
+ */
31
+ export async function withGroupContext<T>(
32
+ controlPlane: string,
33
+ handler: (context: GroupContext) => Promise<T>,
34
+ successMessage?: string,
35
+ debug: boolean = false,
36
+ ): Promise<T | void> {
37
+ const clientConfig = new ClientConfiguration();
38
+
39
+ if (!clientConfig.doesConfigExists()) {
40
+ logger.error("Please, make sure that you are logged in");
41
+ return;
42
+ }
43
+
44
+ const organizationName = clientConfig.getOrganization();
45
+ if (!organizationName) {
46
+ logger.error("No organization set. Please login or set an organization.");
47
+ return;
48
+ }
49
+
50
+ const options: ApiOptions = {
51
+ baseURL: controlPlane,
52
+ headers: {
53
+ Authorization: clientConfig.getAuthenticationHeader(),
54
+ },
55
+ };
56
+
57
+ const context: GroupContext = {
58
+ organizationName,
59
+ groupsApi: new GroupsApi(new Configuration()),
60
+ options,
61
+ };
62
+
63
+ try {
64
+ const result = await handler(context);
65
+
66
+ // Print response if it exists
67
+ if (result !== undefined && result !== null) {
68
+ const jsonString = JSON.stringify(result, null, 2);
69
+ console.log(jsonString);
70
+ }
71
+
72
+ // Print success message if provided
73
+ if (successMessage) {
74
+ logger.info(successMessage);
75
+ }
76
+
77
+ return result;
78
+ } catch (error) {
79
+ logger.error("Operation failed");
80
+ printOutError(error, debug);
81
+ process.exit(1);
82
+ }
83
+ }
@@ -0,0 +1,147 @@
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 { listGroupAccessTokens } from "./listTokens";
7
+
8
+ describe("list-group-access-tokens", () => {
9
+ let sandbox: sinon.SinonSandbox;
10
+ let listGroupAccessTokensStub: sinon.SinonStub;
11
+ let loggerStub: sinon.SinonStubbedInstance<typeof logger>;
12
+ let consoleLogStub: sinon.SinonStub;
13
+ let processExitStub: sinon.SinonStub;
14
+
15
+ beforeEach(() => {
16
+ sandbox = sinon.createSandbox();
17
+ listGroupAccessTokensStub = sandbox.stub();
18
+ loggerStub = sandbox.stub(logger);
19
+ consoleLogStub = sandbox.stub(console, "log");
20
+ processExitStub = sandbox.stub(process, "exit");
21
+
22
+ sandbox
23
+ .stub(ClientConfiguration.prototype, "getOrganization")
24
+ .returns("test-org");
25
+ sandbox
26
+ .stub(ClientConfiguration.prototype, "doesConfigExists")
27
+ .returns(true);
28
+ sandbox
29
+ .stub(ClientConfiguration.prototype, "getAuthenticationHeader")
30
+ .returns("Bearer test-token");
31
+
32
+ sandbox
33
+ .stub(GroupsApi.prototype, "listGroupAccessTokens")
34
+ .callsFake(listGroupAccessTokensStub);
35
+ });
36
+
37
+ afterEach(() => {
38
+ sandbox.restore();
39
+ });
40
+
41
+ it("should list group access tokens successfully", async () => {
42
+ const mockTokens = [
43
+ { tokenName: "token1", createdAt: "2024-01-01" },
44
+ { tokenName: "token2", createdAt: "2024-01-02" },
45
+ ];
46
+ const mockResponse = {
47
+ data: mockTokens,
48
+ };
49
+ listGroupAccessTokensStub.resolves(mockResponse);
50
+
51
+ const result = await listGroupAccessTokens(
52
+ "http://test-server",
53
+ "test-group",
54
+ false,
55
+ );
56
+
57
+ expect(listGroupAccessTokensStub.calledOnce).to.be.true;
58
+ expect(listGroupAccessTokensStub.firstCall.args[0]).to.equal("test-org");
59
+ expect(listGroupAccessTokensStub.firstCall.args[1]).to.equal(
60
+ "test-group",
61
+ );
62
+ expect(consoleLogStub.called).to.be.true;
63
+ expect(
64
+ loggerStub.info.calledWith(
65
+ sinon.match("Group access tokens listed successfully"),
66
+ ),
67
+ ).to.be.true;
68
+ expect(result).to.deep.equal(mockTokens);
69
+ });
70
+
71
+ it("should handle missing config", async () => {
72
+ sandbox.restore();
73
+ sandbox = sinon.createSandbox();
74
+ listGroupAccessTokensStub = sandbox.stub();
75
+ loggerStub = sandbox.stub(logger);
76
+ consoleLogStub = sandbox.stub(console, "log");
77
+ processExitStub = sandbox.stub(process, "exit");
78
+
79
+ sandbox
80
+ .stub(ClientConfiguration.prototype, "doesConfigExists")
81
+ .returns(false);
82
+ sandbox
83
+ .stub(GroupsApi.prototype, "listGroupAccessTokens")
84
+ .callsFake(listGroupAccessTokensStub);
85
+
86
+ const result = await listGroupAccessTokens(
87
+ "http://test-server",
88
+ "test-group",
89
+ false,
90
+ );
91
+
92
+ expect(listGroupAccessTokensStub.called).to.be.false;
93
+ expect(result).to.be.undefined;
94
+ expect(
95
+ loggerStub.error.calledWith(
96
+ sinon.match("Please, make sure that you are logged in"),
97
+ ),
98
+ ).to.be.true;
99
+ });
100
+
101
+ it("should handle missing organization", async () => {
102
+ sandbox.restore();
103
+ sandbox = sinon.createSandbox();
104
+ listGroupAccessTokensStub = sandbox.stub();
105
+ loggerStub = sandbox.stub(logger);
106
+ consoleLogStub = sandbox.stub(console, "log");
107
+ processExitStub = sandbox.stub(process, "exit");
108
+
109
+ sandbox
110
+ .stub(ClientConfiguration.prototype, "doesConfigExists")
111
+ .returns(true);
112
+ sandbox
113
+ .stub(ClientConfiguration.prototype, "getOrganization")
114
+ .returns(undefined);
115
+ sandbox
116
+ .stub(GroupsApi.prototype, "listGroupAccessTokens")
117
+ .callsFake(listGroupAccessTokensStub);
118
+
119
+ const result = await listGroupAccessTokens(
120
+ "http://test-server",
121
+ "test-group",
122
+ false,
123
+ );
124
+
125
+ expect(listGroupAccessTokensStub.called).to.be.false;
126
+ expect(result).to.be.undefined;
127
+ expect(
128
+ loggerStub.error.calledWith(
129
+ sinon.match(
130
+ "No organization set. Please login or set an organization.",
131
+ ),
132
+ ),
133
+ ).to.be.true;
134
+ });
135
+
136
+ it("should handle API errors", async () => {
137
+ const mockError = new Error("API Error");
138
+ listGroupAccessTokensStub.rejects(mockError);
139
+
140
+ await listGroupAccessTokens("http://test-server", "test-group", true);
141
+
142
+ expect(listGroupAccessTokensStub.calledOnce).to.be.true;
143
+ expect(loggerStub.error.calledWith(sinon.match("Operation failed"))).to.be
144
+ .true;
145
+ expect(processExitStub.calledWith(1)).to.be.true;
146
+ });
147
+ });
@@ -0,0 +1,29 @@
1
+ import { logger } from "../../logger";
2
+ import { withGroupContext } from "./groupContainer";
3
+
4
+ export async function listGroupAccessTokens(
5
+ controlPlane: string,
6
+ groupName: string,
7
+ debug: boolean,
8
+ ) {
9
+ return withGroupContext(
10
+ controlPlane,
11
+ async (context) => {
12
+ const { organizationName, groupsApi, options } = context;
13
+
14
+ logger.info(
15
+ `Listing access tokens for group ${groupName} in organization ${organizationName}`,
16
+ );
17
+
18
+ const response = await groupsApi.listGroupAccessTokens(
19
+ organizationName,
20
+ groupName,
21
+ options,
22
+ );
23
+
24
+ return response.data;
25
+ },
26
+ "Group access tokens listed successfully",
27
+ debug,
28
+ );
29
+ }
@@ -0,0 +1,131 @@
1
+ import { Command } from "commander";
2
+ import { controlPlanesByEnv, Environment } from "../constants";
3
+ import { DEFAULT_PAGE_SIZE, DEFAULT_PAGE } from "../utils";
4
+ import { listConnections } from "./connection/listconnections";
5
+ import { printOutGroups } from "./group/listgroups";
6
+ import { listGroupAccessTokens } from "./groupaccesstoken/listTokens";
7
+ import { printOutPackages } from "./package/listpackages";
8
+ import { printOutProjects } from "./project/listprojects";
9
+ import { listVersions } from "./version/listversions";
10
+
11
+ export const registerListCommands = (
12
+ cli: Command,
13
+ environment: Environment,
14
+ ) => {
15
+ const list = cli
16
+ .command("ls")
17
+ .description("List resources of a given type")
18
+ .argument("<resource>", "The resource to list");
19
+
20
+ list
21
+ .command("project")
22
+ .alias("projects")
23
+ .description("List all projects.")
24
+ .option("--debug")
25
+ .option(
26
+ "--page <number>",
27
+ `Page number (starts at ${DEFAULT_PAGE})`,
28
+ String(DEFAULT_PAGE),
29
+ )
30
+ .option(
31
+ "--page-size <number>",
32
+ `Items per page (default: all records, max: 500)`,
33
+ String(DEFAULT_PAGE_SIZE),
34
+ )
35
+ .action((options) => {
36
+ printOutProjects(
37
+ controlPlanesByEnv[environment],
38
+ options.debug,
39
+ options.page,
40
+ options.pageSize,
41
+ );
42
+ });
43
+
44
+ list
45
+ .command("connection")
46
+ .alias("connections")
47
+ .description("List all connections.")
48
+ .option("--debug")
49
+ .option(
50
+ "--page <number>",
51
+ `Page number (starts at ${DEFAULT_PAGE})`,
52
+ String(DEFAULT_PAGE),
53
+ )
54
+ .option(
55
+ "--page-size <number>",
56
+ `Items per page (default: all records, max: 500)`,
57
+ String(DEFAULT_PAGE_SIZE),
58
+ )
59
+ .action((options) => {
60
+ listConnections(
61
+ controlPlanesByEnv[environment],
62
+ options.debug,
63
+ options.page,
64
+ options.pageSize,
65
+ );
66
+ });
67
+
68
+ list
69
+ .command("package")
70
+ .alias("packages")
71
+ .description("List the packages in the active project.")
72
+ .option("--debug")
73
+ .option(
74
+ "--page <number>",
75
+ `Page number (starts at ${DEFAULT_PAGE})`,
76
+ String(DEFAULT_PAGE),
77
+ )
78
+ .option(
79
+ "--page-size <number>",
80
+ `Items per page (default: all records, max: 500)`,
81
+ String(DEFAULT_PAGE_SIZE),
82
+ )
83
+ .action((options) => {
84
+ printOutPackages(
85
+ controlPlanesByEnv[environment],
86
+ options.debug,
87
+ options.page,
88
+ options.pageSize,
89
+ );
90
+ });
91
+
92
+ list
93
+ .command("version")
94
+ .alias("versions")
95
+ .description("List the versions of a package.")
96
+ .argument(
97
+ "<packageName>",
98
+ "The name of the package to list the versions of.",
99
+ )
100
+ .option("--debug")
101
+ .action((packageName, options) => {
102
+ listVersions(
103
+ controlPlanesByEnv[environment],
104
+ packageName,
105
+ options.debug,
106
+ );
107
+ });
108
+
109
+ list
110
+ .command("group")
111
+ .alias("groups")
112
+ .description("List all groups in the organization.")
113
+ .option("--debug")
114
+ .action((options) => {
115
+ printOutGroups(controlPlanesByEnv[environment], options.debug);
116
+ });
117
+
118
+ list
119
+ .command("group-access-token")
120
+ .alias("group-access-tokens")
121
+ .description("List all access tokens for a group.")
122
+ .argument("<groupName>", "The name of the group")
123
+ .option("--debug")
124
+ .action((groupName, options) => {
125
+ listGroupAccessTokens(
126
+ controlPlanesByEnv[environment],
127
+ groupName,
128
+ options.debug,
129
+ );
130
+ });
131
+ };