@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,247 @@
1
+ import { expect } from "chai";
2
+ import fs from "fs";
3
+ import sinon from "sinon";
4
+ import { ProjectsApi } from "../../client/api";
5
+ import { ClientConfiguration } from "../../clientconfiguration";
6
+ import { logger } from "../../logger";
7
+ import { getConfirmation } from "../../utils";
8
+ import { createProject } from "./createproject";
9
+
10
+ describe("create-project", () => {
11
+ let sandbox: sinon.SinonSandbox;
12
+ let createProjectStub: sinon.SinonStub;
13
+ let loggerStub: sinon.SinonStubbedInstance<typeof logger>;
14
+ let consoleLogStub: sinon.SinonStub;
15
+ let getConfirmationStub: sinon.SinonStub;
16
+ let readFileSyncStub: sinon.SinonStub;
17
+ let setProjectStub: sinon.SinonStub;
18
+
19
+ beforeEach(() => {
20
+ sandbox = sinon.createSandbox();
21
+ createProjectStub = sandbox.stub();
22
+ loggerStub = sandbox.stub(logger);
23
+ consoleLogStub = sandbox.stub(console, "log");
24
+ getConfirmationStub = sandbox.stub();
25
+ readFileSyncStub = sandbox.stub(fs, "readFileSync");
26
+ setProjectStub = sandbox.stub(
27
+ ClientConfiguration.prototype,
28
+ "setProject",
29
+ );
30
+
31
+ sandbox
32
+ .stub(ClientConfiguration.prototype, "getOrganization")
33
+ .returns("test-org");
34
+ sandbox
35
+ .stub(ClientConfiguration.prototype, "doesConfigExists")
36
+ .returns(true);
37
+ sandbox
38
+ .stub(ClientConfiguration.prototype, "getAuthenticationHeader")
39
+ .returns("Bearer test-token");
40
+
41
+ sandbox
42
+ .stub(ProjectsApi.prototype, "createProject")
43
+ .callsFake(createProjectStub);
44
+ sandbox
45
+ .stub(require("../../utils"), "getConfirmation")
46
+ .callsFake(getConfirmationStub);
47
+ });
48
+
49
+ afterEach(() => {
50
+ sandbox.restore();
51
+ });
52
+
53
+ it("should create project successfully", async () => {
54
+ const mockResponse = {
55
+ data: { name: "test-project", replicationCount: 2 },
56
+ };
57
+ createProjectStub.resolves(mockResponse);
58
+ getConfirmationStub.resolves(true);
59
+
60
+ await createProject(
61
+ "http://test-server",
62
+ "test-project",
63
+ "",
64
+ undefined,
65
+ false,
66
+ true,
67
+ );
68
+
69
+ expect(createProjectStub.calledOnce).to.be.true;
70
+ expect(createProjectStub.firstCall.args[0]).to.equal("test-org");
71
+ expect(createProjectStub.firstCall.args[1]).to.deep.include({
72
+ name: "test-project",
73
+ readme: "",
74
+ });
75
+ expect(setProjectStub.calledWith("test-project")).to.be.true;
76
+ expect(
77
+ loggerStub.info.calledWith(
78
+ sinon.match("Project created successfully"),
79
+ ),
80
+ ).to.be.true;
81
+ });
82
+
83
+ it("should create project with readme file", async () => {
84
+ const mockResponse = {
85
+ data: { name: "test-project" },
86
+ };
87
+ createProjectStub.resolves(mockResponse);
88
+ getConfirmationStub.resolves(true);
89
+ readFileSyncStub.returns("README content");
90
+
91
+ await createProject(
92
+ "http://test-server",
93
+ "test-project",
94
+ "/path/to/readme.md",
95
+ undefined,
96
+ false,
97
+ true,
98
+ );
99
+
100
+ expect(readFileSyncStub.calledWith("/path/to/readme.md")).to.be.true;
101
+ expect(createProjectStub.firstCall.args[1]).to.deep.include({
102
+ name: "test-project",
103
+ readme: "README content",
104
+ });
105
+ });
106
+
107
+ it("should create project with replication count", async () => {
108
+ const mockResponse = {
109
+ data: { name: "test-project", replicationCount: 5 },
110
+ };
111
+ createProjectStub.resolves(mockResponse);
112
+ getConfirmationStub.resolves(true);
113
+
114
+ await createProject(
115
+ "http://test-server",
116
+ "test-project",
117
+ "",
118
+ 5,
119
+ false,
120
+ true,
121
+ );
122
+
123
+ expect(createProjectStub.firstCall.args[1]).to.deep.include({
124
+ name: "test-project",
125
+ replicationCount: 5,
126
+ });
127
+ expect(
128
+ loggerStub.info.calledWith(sinon.match("Replication count set to 5")),
129
+ ).to.be.true;
130
+ });
131
+
132
+ it("should handle missing config", async () => {
133
+ sandbox.restore();
134
+ sandbox = sinon.createSandbox();
135
+ createProjectStub = sandbox.stub();
136
+ loggerStub = sandbox.stub(logger);
137
+ consoleLogStub = sandbox.stub(console, "log");
138
+ getConfirmationStub = sandbox.stub();
139
+ readFileSyncStub = sandbox.stub(fs, "readFileSync");
140
+ setProjectStub = sandbox.stub(
141
+ ClientConfiguration.prototype,
142
+ "setProject",
143
+ );
144
+
145
+ sandbox
146
+ .stub(ClientConfiguration.prototype, "doesConfigExists")
147
+ .returns(false);
148
+ sandbox
149
+ .stub(ProjectsApi.prototype, "createProject")
150
+ .callsFake(createProjectStub);
151
+ sandbox
152
+ .stub(require("../../utils"), "getConfirmation")
153
+ .callsFake(getConfirmationStub);
154
+
155
+ await createProject(
156
+ "http://test-server",
157
+ "test-project",
158
+ "",
159
+ undefined,
160
+ false,
161
+ true,
162
+ );
163
+
164
+ expect(createProjectStub.called).to.be.false;
165
+ expect(
166
+ loggerStub.error.calledWith(
167
+ sinon.match("Please, make sure that you are logged in"),
168
+ ),
169
+ ).to.be.true;
170
+ });
171
+
172
+ it("should reject replication count less than 1", async () => {
173
+ await createProject(
174
+ "http://test-server",
175
+ "test-project",
176
+ "",
177
+ 0,
178
+ false,
179
+ true,
180
+ );
181
+
182
+ expect(createProjectStub.called).to.be.false;
183
+ expect(
184
+ loggerStub.error.calledWith(
185
+ sinon.match("Replication count must be at least 1"),
186
+ ),
187
+ ).to.be.true;
188
+ });
189
+
190
+ it("should request confirmation when autoConfirm is false", async () => {
191
+ const mockResponse = {
192
+ data: { name: "test-project" },
193
+ };
194
+ createProjectStub.resolves(mockResponse);
195
+ getConfirmationStub.resolves(true);
196
+
197
+ await createProject(
198
+ "http://test-server",
199
+ "test-project",
200
+ "",
201
+ undefined,
202
+ false,
203
+ false,
204
+ );
205
+
206
+ expect(getConfirmationStub.calledOnce).to.be.true;
207
+ expect(createProjectStub.calledOnce).to.be.true;
208
+ });
209
+
210
+ it("should cancel when confirmation is denied", async () => {
211
+ getConfirmationStub.resolves(false);
212
+
213
+ await createProject(
214
+ "http://test-server",
215
+ "test-project",
216
+ "",
217
+ undefined,
218
+ false,
219
+ false,
220
+ );
221
+
222
+ expect(getConfirmationStub.calledOnce).to.be.true;
223
+ expect(createProjectStub.called).to.be.false;
224
+ expect(loggerStub.info.calledWith(sinon.match("Operation cancelled."))).to
225
+ .be.true;
226
+ });
227
+
228
+ it("should handle API errors", async () => {
229
+ const mockError = new Error("API Error");
230
+ createProjectStub.rejects(mockError);
231
+ getConfirmationStub.resolves(true);
232
+
233
+ await createProject(
234
+ "http://test-server",
235
+ "test-project",
236
+ "",
237
+ undefined,
238
+ true,
239
+ true,
240
+ );
241
+
242
+ expect(createProjectStub.calledOnce).to.be.true;
243
+ expect(
244
+ loggerStub.error.calledWith(sinon.match("Failed to create project")),
245
+ ).to.be.true;
246
+ });
247
+ });
@@ -0,0 +1,70 @@
1
+ import fs from "fs";
2
+ import { Project, ProjectsApi } from "../../client/api";
3
+ import { Configuration } from "../../client/configuration";
4
+ import { ClientConfiguration } from "../../clientconfiguration";
5
+ import { logger } from "../../logger";
6
+ import { getConfirmation, printOutError } from "../../utils";
7
+
8
+ const projectsApi = new ProjectsApi(new Configuration());
9
+
10
+ export async function createProject(
11
+ controlPlane: string,
12
+ projectName: string,
13
+ readmeFile: string,
14
+ replicationCount: number | undefined,
15
+ debug: boolean,
16
+ autoConfirm: boolean,
17
+ ) {
18
+ const clientConfig = new ClientConfiguration();
19
+
20
+ if (!clientConfig.doesConfigExists()) {
21
+ logger.error("Please, make sure that you are logged in");
22
+ return;
23
+ }
24
+ if (replicationCount !== undefined && replicationCount < 1) {
25
+ logger.error("Replication count must be at least 1");
26
+ return;
27
+ }
28
+ if (!autoConfirm) {
29
+ const confirmation = await getConfirmation(
30
+ `Are you sure you that want to create a project named ${projectName}?`,
31
+ );
32
+ if (!confirmation) {
33
+ logger.info("Operation cancelled.");
34
+ return;
35
+ }
36
+ }
37
+ logger.info("Creating project " + projectName);
38
+
39
+ let readmeContents = "";
40
+ if (readmeFile) {
41
+ readmeContents = fs.readFileSync(readmeFile).toString();
42
+ }
43
+
44
+ try {
45
+ const project: Project = { name: projectName, readme: readmeContents };
46
+ if (replicationCount !== undefined) {
47
+ project.replicationCount = replicationCount;
48
+ }
49
+ await projectsApi
50
+ .createProject(clientConfig.getOrganization(), project, {
51
+ baseURL: controlPlane,
52
+ headers: {
53
+ Authorization: clientConfig.getAuthenticationHeader(),
54
+ },
55
+ })
56
+ .then((response) => {
57
+ const jsonString = JSON.stringify(response.data, null, 2);
58
+ console.log(jsonString);
59
+ // Make the new project the default project.
60
+ clientConfig.setProject(projectName);
61
+ if (replicationCount !== undefined) {
62
+ logger.info(`Replication count set to ${replicationCount}`);
63
+ }
64
+ });
65
+ logger.info("Project created successfully");
66
+ } catch (e) {
67
+ logger.error("Failed to create project");
68
+ printOutError(e, debug);
69
+ }
70
+ }
@@ -0,0 +1,123 @@
1
+ import { expect } from "chai";
2
+ import sinon from "sinon";
3
+ import { ProjectsApi } from "../../client/api";
4
+ import { ClientConfiguration } from "../../clientconfiguration";
5
+ import { logger } from "../../logger";
6
+ import { getConfirmation } from "../../utils";
7
+ import { deleteProject } from "./deleteproject";
8
+
9
+ describe("delete-project", () => {
10
+ let sandbox: sinon.SinonSandbox;
11
+ let deleteProjectStub: sinon.SinonStub;
12
+ let loggerStub: sinon.SinonStubbedInstance<typeof logger>;
13
+ let getConfirmationStub: sinon.SinonStub;
14
+
15
+ beforeEach(() => {
16
+ sandbox = sinon.createSandbox();
17
+ deleteProjectStub = 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, "doesConfigExists")
26
+ .returns(true);
27
+ sandbox
28
+ .stub(ClientConfiguration.prototype, "getAuthenticationHeader")
29
+ .returns("Bearer test-token");
30
+
31
+ sandbox
32
+ .stub(ProjectsApi.prototype, "deleteProject")
33
+ .callsFake(deleteProjectStub);
34
+ sandbox
35
+ .stub(require("../../utils"), "getConfirmation")
36
+ .callsFake(getConfirmationStub);
37
+ });
38
+
39
+ afterEach(() => {
40
+ sandbox.restore();
41
+ });
42
+
43
+ it("should delete project successfully", async () => {
44
+ deleteProjectStub.resolves({ status: 200 });
45
+ getConfirmationStub.resolves(true);
46
+
47
+ await deleteProject("http://test-server", "test-project", false, true);
48
+
49
+ expect(deleteProjectStub.calledOnce).to.be.true;
50
+ expect(deleteProjectStub.firstCall.args[0]).to.equal("test-org");
51
+ expect(deleteProjectStub.firstCall.args[1]).to.equal("test-project");
52
+ expect(deleteProjectStub.firstCall.args[2]).to.deep.include({
53
+ baseURL: "http://test-server",
54
+ headers: { Authorization: "Bearer test-token" },
55
+ });
56
+ expect(
57
+ loggerStub.info.calledWith(
58
+ sinon.match("Project deleted successfully"),
59
+ ),
60
+ ).to.be.true;
61
+ });
62
+
63
+ it("should handle missing config", async () => {
64
+ sandbox.restore();
65
+ sandbox = sinon.createSandbox();
66
+ deleteProjectStub = sandbox.stub();
67
+ loggerStub = sandbox.stub(logger);
68
+ getConfirmationStub = sandbox.stub();
69
+
70
+ sandbox
71
+ .stub(ClientConfiguration.prototype, "doesConfigExists")
72
+ .returns(false);
73
+ sandbox
74
+ .stub(ProjectsApi.prototype, "deleteProject")
75
+ .callsFake(deleteProjectStub);
76
+ sandbox
77
+ .stub(require("../../utils"), "getConfirmation")
78
+ .callsFake(getConfirmationStub);
79
+
80
+ await deleteProject("http://test-server", "test-project", false, true);
81
+
82
+ expect(deleteProjectStub.called).to.be.false;
83
+ expect(
84
+ loggerStub.error.calledWith(
85
+ sinon.match("Please, make sure that you are logged in"),
86
+ ),
87
+ ).to.be.true;
88
+ });
89
+
90
+ it("should request confirmation when autoConfirm is false", async () => {
91
+ deleteProjectStub.resolves({ status: 200 });
92
+ getConfirmationStub.resolves(true);
93
+
94
+ await deleteProject("http://test-server", "test-project", false, false);
95
+
96
+ expect(getConfirmationStub.calledOnce).to.be.true;
97
+ expect(deleteProjectStub.calledOnce).to.be.true;
98
+ });
99
+
100
+ it("should cancel when confirmation is denied", async () => {
101
+ getConfirmationStub.resolves(false);
102
+
103
+ await deleteProject("http://test-server", "test-project", false, false);
104
+
105
+ expect(getConfirmationStub.calledOnce).to.be.true;
106
+ expect(deleteProjectStub.called).to.be.false;
107
+ expect(loggerStub.info.calledWith(sinon.match("Operation cancelled."))).to
108
+ .be.true;
109
+ });
110
+
111
+ it("should handle API errors", async () => {
112
+ const mockError = new Error("API Error");
113
+ deleteProjectStub.rejects(mockError);
114
+ getConfirmationStub.resolves(true);
115
+
116
+ await deleteProject("http://test-server", "test-project", true, true);
117
+
118
+ expect(deleteProjectStub.calledOnce).to.be.true;
119
+ expect(
120
+ loggerStub.error.calledWith(sinon.match("Failed to delete project")),
121
+ ).to.be.true;
122
+ });
123
+ });
@@ -0,0 +1,48 @@
1
+ import { ProjectsApi } 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 projectsApi = new ProjectsApi(new Configuration());
8
+
9
+ export async function deleteProject(
10
+ controlPlane: string,
11
+ projectName: string,
12
+ debug: boolean,
13
+ autoConfirm: boolean,
14
+ ) {
15
+ const clientConfig = new ClientConfiguration();
16
+
17
+ if (!clientConfig.doesConfigExists()) {
18
+ logger.error("Please, make sure that you are logged in");
19
+ return;
20
+ }
21
+ if (!autoConfirm) {
22
+ const confirmation = await getConfirmation(
23
+ `Are you sure you that want to delete the ${projectName} project? This action cannot be undone.`,
24
+ );
25
+ if (!confirmation) {
26
+ logger.info("Operation cancelled.");
27
+ return;
28
+ }
29
+ }
30
+ logger.info("Deleting project " + projectName);
31
+
32
+ try {
33
+ await projectsApi.deleteProject(
34
+ clientConfig.getOrganization(),
35
+ projectName,
36
+ {
37
+ baseURL: controlPlane,
38
+ headers: {
39
+ Authorization: clientConfig.getAuthenticationHeader(),
40
+ },
41
+ },
42
+ );
43
+ logger.info("Project deleted successfully");
44
+ } catch (e) {
45
+ logger.error("Failed to delete project");
46
+ printOutError(e, debug);
47
+ }
48
+ }
@@ -0,0 +1,109 @@
1
+ import { expect } from "chai";
2
+ import sinon from "sinon";
3
+ import { ProjectsApi } from "../../client/api";
4
+ import { ClientConfiguration } from "../../clientconfiguration";
5
+ import { logger } from "../../logger";
6
+ import { prettifyJson } from "../../utils";
7
+ import { getProject } from "./getproject";
8
+
9
+ describe("get-project", () => {
10
+ let sandbox: sinon.SinonSandbox;
11
+ let getProjectStub: sinon.SinonStub;
12
+ let loggerStub: sinon.SinonStubbedInstance<typeof logger>;
13
+ let consoleLogStub: sinon.SinonStub;
14
+
15
+ beforeEach(() => {
16
+ sandbox = sinon.createSandbox();
17
+ getProjectStub = 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, "doesConfigExists")
26
+ .returns(true);
27
+ sandbox
28
+ .stub(ClientConfiguration.prototype, "getHeaders")
29
+ .returns({ Authorization: "Bearer test-token" });
30
+
31
+ sandbox
32
+ .stub(ProjectsApi.prototype, "getProject")
33
+ .callsFake(getProjectStub);
34
+ });
35
+
36
+ afterEach(() => {
37
+ sandbox.restore();
38
+ });
39
+
40
+ it("should get project successfully", async () => {
41
+ const mockProjectData = {
42
+ name: "test-project",
43
+ replicationCount: 3,
44
+ };
45
+ const mockResponse = {
46
+ data: mockProjectData,
47
+ };
48
+ getProjectStub.resolves(mockResponse);
49
+
50
+ await getProject("http://test-server", "test-project", false);
51
+
52
+ expect(getProjectStub.calledOnce).to.be.true;
53
+ expect(getProjectStub.firstCall.args[0]).to.equal("test-org");
54
+ expect(getProjectStub.firstCall.args[1]).to.equal("test-project");
55
+ expect(getProjectStub.firstCall.args[2]).to.equal(false);
56
+ expect(getProjectStub.firstCall.args[3]).to.deep.include({
57
+ baseURL: "http://test-server",
58
+ headers: { Authorization: "Bearer test-token" },
59
+ });
60
+ expect(consoleLogStub.calledWith(prettifyJson(mockProjectData))).to.be
61
+ .true;
62
+ });
63
+
64
+ it("should handle missing config", async () => {
65
+ sandbox.restore();
66
+ sandbox = sinon.createSandbox();
67
+ getProjectStub = sandbox.stub();
68
+ loggerStub = sandbox.stub(logger);
69
+ consoleLogStub = sandbox.stub(console, "log");
70
+
71
+ sandbox
72
+ .stub(ClientConfiguration.prototype, "doesConfigExists")
73
+ .returns(false);
74
+ sandbox
75
+ .stub(ProjectsApi.prototype, "getProject")
76
+ .callsFake(getProjectStub);
77
+
78
+ await getProject("http://test-server", "test-project", false);
79
+
80
+ expect(getProjectStub.called).to.be.false;
81
+ expect(
82
+ loggerStub.error.calledWith(
83
+ sinon.match("Please, make sure that you are logged in"),
84
+ ),
85
+ ).to.be.true;
86
+ });
87
+
88
+ it("should handle missing project name", async () => {
89
+ await getProject("http://test-server", "", false);
90
+
91
+ expect(getProjectStub.called).to.be.false;
92
+ expect(
93
+ loggerStub.error.calledWith(
94
+ sinon.match("Please, make sure to provide a project name"),
95
+ ),
96
+ ).to.be.true;
97
+ });
98
+
99
+ it("should handle API errors", async () => {
100
+ const mockError = new Error("API Error");
101
+ getProjectStub.rejects(mockError);
102
+
103
+ await getProject("http://test-server", "test-project", true);
104
+
105
+ expect(getProjectStub.calledOnce).to.be.true;
106
+ expect(loggerStub.error.calledWith(sinon.match("Failed to get project")))
107
+ .to.be.true;
108
+ });
109
+ });
@@ -0,0 +1,43 @@
1
+ import { ProjectsApi } from "../../client/api";
2
+ import { Configuration } from "../../client/configuration";
3
+ import { ClientConfiguration } from "../../clientconfiguration";
4
+ import { logger } from "../../logger";
5
+ import { prettifyJson, printOutError } from "../../utils";
6
+
7
+ const projectsApi = new ProjectsApi(new Configuration());
8
+
9
+ export async function getProject(
10
+ controlPlane: string,
11
+ projectName: string,
12
+ debug: boolean,
13
+ ) {
14
+ const clientConfig = new ClientConfiguration();
15
+ const organizationName = clientConfig.getOrganization();
16
+
17
+ if (!clientConfig.doesConfigExists()) {
18
+ logger.error("Please, make sure that you are logged in");
19
+ return;
20
+ }
21
+
22
+ if (!projectName) {
23
+ logger.error("Please, make sure to provide a project name");
24
+ return;
25
+ }
26
+
27
+ try {
28
+ const response = await projectsApi.getProject(
29
+ organizationName,
30
+ projectName,
31
+ false,
32
+ {
33
+ baseURL: controlPlane,
34
+ headers: clientConfig.getHeaders(),
35
+ },
36
+ );
37
+
38
+ console.log(prettifyJson(response.data));
39
+ } catch (e) {
40
+ logger.error("Failed to get project");
41
+ printOutError(e, debug);
42
+ }
43
+ }