@credibledata/cred-cli 0.1.0

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 (170) hide show
  1. package/.eslintrc +33 -0
  2. package/.github/workflows/build.yml +23 -0
  3. package/.mocharc.json +10 -0
  4. package/.prettierignore +1 -0
  5. package/.prettierrc +4 -0
  6. package/README.md +40 -0
  7. package/bun.lock +1259 -0
  8. package/dist/client/api.js +7022 -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 +163 -0
  19. package/dist/clientconfiguration.js.map +1 -0
  20. package/dist/clientconfiguration.spec.js +92 -0
  21. package/dist/clientconfiguration.spec.js.map +1 -0
  22. package/dist/commands/add.js +61 -0
  23. package/dist/commands/add.js.map +1 -0
  24. package/dist/commands/connection/createconnections.js +62 -0
  25. package/dist/commands/connection/createconnections.js.map +1 -0
  26. package/dist/commands/connection/deleteconnection.js +52 -0
  27. package/dist/commands/connection/deleteconnection.js.map +1 -0
  28. package/dist/commands/connection/listconnections.js +44 -0
  29. package/dist/commands/connection/listconnections.js.map +1 -0
  30. package/dist/commands/get.js +28 -0
  31. package/dist/commands/get.js.map +1 -0
  32. package/dist/commands/group/addmember.js +73 -0
  33. package/dist/commands/group/addmember.js.map +1 -0
  34. package/dist/commands/group/creategroup.js +55 -0
  35. package/dist/commands/group/creategroup.js.map +1 -0
  36. package/dist/commands/group/deletegroup.js +48 -0
  37. package/dist/commands/group/deletegroup.js.map +1 -0
  38. package/dist/commands/group/getgroup.js +50 -0
  39. package/dist/commands/group/getgroup.js.map +1 -0
  40. package/dist/commands/group/listgroups.js +56 -0
  41. package/dist/commands/group/listgroups.js.map +1 -0
  42. package/dist/commands/group/removemember.js +68 -0
  43. package/dist/commands/group/removemember.js.map +1 -0
  44. package/dist/commands/groupaccesstoken/createToken.js +49 -0
  45. package/dist/commands/groupaccesstoken/createToken.js.map +1 -0
  46. package/dist/commands/groupaccesstoken/deleteToken.js +24 -0
  47. package/dist/commands/groupaccesstoken/deleteToken.js.map +1 -0
  48. package/dist/commands/groupaccesstoken/groupContainer.js +71 -0
  49. package/dist/commands/groupaccesstoken/groupContainer.js.map +1 -0
  50. package/dist/commands/groupaccesstoken/listTokens.js +25 -0
  51. package/dist/commands/groupaccesstoken/listTokens.js.map +1 -0
  52. package/dist/commands/list.js +68 -0
  53. package/dist/commands/list.js.map +1 -0
  54. package/dist/commands/misc/login.js +166 -0
  55. package/dist/commands/misc/login.js.map +1 -0
  56. package/dist/commands/misc/login.spec.js +138 -0
  57. package/dist/commands/misc/login.spec.js.map +1 -0
  58. package/dist/commands/misc/logout.js +11 -0
  59. package/dist/commands/misc/logout.js.map +1 -0
  60. package/dist/commands/misc/set-access-token.js +27 -0
  61. package/dist/commands/misc/set-access-token.js.map +1 -0
  62. package/dist/commands/package/deletepackage.js +54 -0
  63. package/dist/commands/package/deletepackage.js.map +1 -0
  64. package/dist/commands/package/listpackages.js +52 -0
  65. package/dist/commands/package/listpackages.js.map +1 -0
  66. package/dist/commands/package/publish.js +134 -0
  67. package/dist/commands/package/publish.js.map +1 -0
  68. package/dist/commands/package/updatepackage.js +75 -0
  69. package/dist/commands/package/updatepackage.js.map +1 -0
  70. package/dist/commands/package/updatepackage.spec.js +139 -0
  71. package/dist/commands/package/updatepackage.spec.js.map +1 -0
  72. package/dist/commands/project/createproject.js +65 -0
  73. package/dist/commands/project/createproject.js.map +1 -0
  74. package/dist/commands/project/deleteproject.js +49 -0
  75. package/dist/commands/project/deleteproject.js.map +1 -0
  76. package/dist/commands/project/getproject.js +44 -0
  77. package/dist/commands/project/getproject.js.map +1 -0
  78. package/dist/commands/project/listprojects.js +46 -0
  79. package/dist/commands/project/listprojects.js.map +1 -0
  80. package/dist/commands/project/setproject.js +26 -0
  81. package/dist/commands/project/setproject.js.map +1 -0
  82. package/dist/commands/rm.js +68 -0
  83. package/dist/commands/rm.js.map +1 -0
  84. package/dist/commands/set.js +17 -0
  85. package/dist/commands/set.js.map +1 -0
  86. package/dist/commands/update.js +29 -0
  87. package/dist/commands/update.js.map +1 -0
  88. package/dist/commands/version/archive-unarchive-version.js +79 -0
  89. package/dist/commands/version/archive-unarchive-version.js.map +1 -0
  90. package/dist/commands/version/archive-unarchive-version.spec.js +244 -0
  91. package/dist/commands/version/archive-unarchive-version.spec.js.map +1 -0
  92. package/dist/commands/version/listversions.js +46 -0
  93. package/dist/commands/version/listversions.js.map +1 -0
  94. package/dist/common/UserGroupId.js +112 -0
  95. package/dist/common/UserGroupId.js.map +1 -0
  96. package/dist/constants.js +54 -0
  97. package/dist/constants.js.map +1 -0
  98. package/dist/index.js +137 -0
  99. package/dist/index.js.map +1 -0
  100. package/dist/logger.js +77 -0
  101. package/dist/logger.js.map +1 -0
  102. package/dist/polyfills/file.polyfill.js +6 -0
  103. package/dist/polyfills/file.polyfill.js.map +1 -0
  104. package/dist/utils.js +51 -0
  105. package/dist/utils.js.map +1 -0
  106. package/dist/validator.js +53 -0
  107. package/dist/validator.js.map +1 -0
  108. package/dist/validator.spec.js +41 -0
  109. package/dist/validator.spec.js.map +1 -0
  110. package/docker/Dockerfile.ci +10 -0
  111. package/docker-compose.yml +18 -0
  112. package/mocha.setup.ts +4 -0
  113. package/openapitools.json +7 -0
  114. package/package.json +67 -0
  115. package/src/client/.openapi-generator/FILES +8 -0
  116. package/src/client/.openapi-generator/VERSION +1 -0
  117. package/src/client/.openapi-generator-ignore +23 -0
  118. package/src/client/api.ts +8408 -0
  119. package/src/client/base.ts +86 -0
  120. package/src/client/common.ts +150 -0
  121. package/src/client/configuration.ts +110 -0
  122. package/src/client/git_push.sh +57 -0
  123. package/src/client/index.ts +18 -0
  124. package/src/clientconfiguration.spec.ts +116 -0
  125. package/src/clientconfiguration.ts +204 -0
  126. package/src/commands/add.ts +106 -0
  127. package/src/commands/connection/createconnections.ts +67 -0
  128. package/src/commands/connection/deleteconnection.ts +57 -0
  129. package/src/commands/connection/listconnections.ts +39 -0
  130. package/src/commands/get.ts +31 -0
  131. package/src/commands/group/addmember.ts +83 -0
  132. package/src/commands/group/creategroup.ts +54 -0
  133. package/src/commands/group/deletegroup.ts +45 -0
  134. package/src/commands/group/getgroup.ts +47 -0
  135. package/src/commands/group/listgroups.ts +45 -0
  136. package/src/commands/group/removemember.ts +74 -0
  137. package/src/commands/groupaccesstoken/createToken.ts +68 -0
  138. package/src/commands/groupaccesstoken/deleteToken.ts +24 -0
  139. package/src/commands/groupaccesstoken/groupContainer.ts +83 -0
  140. package/src/commands/groupaccesstoken/listTokens.ts +24 -0
  141. package/src/commands/list.ts +90 -0
  142. package/src/commands/misc/login.spec.ts +128 -0
  143. package/src/commands/misc/login.ts +142 -0
  144. package/src/commands/misc/logout.ts +9 -0
  145. package/src/commands/misc/set-access-token.ts +32 -0
  146. package/src/commands/package/deletepackage.ts +58 -0
  147. package/src/commands/package/listpackages.ts +44 -0
  148. package/src/commands/package/publish.ts +179 -0
  149. package/src/commands/package/updatepackage.spec.ts +221 -0
  150. package/src/commands/package/updatepackage.ts +95 -0
  151. package/src/commands/project/createproject.ts +59 -0
  152. package/src/commands/project/deleteproject.ts +48 -0
  153. package/src/commands/project/getproject.ts +43 -0
  154. package/src/commands/project/listprojects.ts +36 -0
  155. package/src/commands/project/setproject.ts +14 -0
  156. package/src/commands/rm.ts +106 -0
  157. package/src/commands/set.ts +16 -0
  158. package/src/commands/update.ts +41 -0
  159. package/src/commands/version/archive-unarchive-version.spec.ts +456 -0
  160. package/src/commands/version/archive-unarchive-version.ts +111 -0
  161. package/src/commands/version/listversions.ts +45 -0
  162. package/src/common/UserGroupId.ts +137 -0
  163. package/src/constants.ts +70 -0
  164. package/src/index.ts +183 -0
  165. package/src/logger.ts +86 -0
  166. package/src/polyfills/file.polyfill.ts +5 -0
  167. package/src/utils.ts +34 -0
  168. package/src/validator.spec.ts +51 -0
  169. package/src/validator.ts +44 -0
  170. package/tsconfig.json +20 -0
@@ -0,0 +1,204 @@
1
+ import fs from "fs";
2
+ import kleur from "kleur";
3
+ import os from "os";
4
+ import { ASCII_TITLE, Environment } from "./constants";
5
+ import { logger } from "./logger";
6
+
7
+ interface ConfigFile {
8
+ configPerEnvironment: Partial<
9
+ Record<
10
+ Environment,
11
+ {
12
+ organization?: string;
13
+ project?: string;
14
+ auth?: { username: string; password: string };
15
+ vsCodeUser?: {
16
+ username: string;
17
+ email: string;
18
+ };
19
+ accessToken?: string;
20
+ jwtAccessToken?: string;
21
+ refreshToken?: string;
22
+ isServiceAccountToken?: boolean;
23
+ }
24
+ >
25
+ >;
26
+ activeEnvironment: Environment;
27
+ }
28
+
29
+ export class ClientConfiguration {
30
+ private configPath = `${os.homedir()}/.cred`;
31
+ private config: ConfigFile;
32
+
33
+ constructor(customConfigPath?: string) {
34
+ if (customConfigPath) {
35
+ this.configPath = customConfigPath;
36
+ }
37
+ }
38
+
39
+ public loadConfig(): ConfigFile {
40
+ try {
41
+ const fileContents = fs.readFileSync(this.configPath);
42
+ this.config = JSON.parse(fileContents.toString());
43
+ if (
44
+ !this.config.activeEnvironment ||
45
+ !this.config.configPerEnvironment
46
+ ) {
47
+ throw new Error(
48
+ "Corrupted config file found, restoring to default settings.",
49
+ );
50
+ }
51
+ } catch (error) {
52
+ logger.warn(error);
53
+ this.config = {
54
+ configPerEnvironment: {
55
+ production: {},
56
+ staging: {},
57
+ localhost: {},
58
+ },
59
+ activeEnvironment: "production",
60
+ };
61
+ // Ensure the config file exists with default settings
62
+ fs.writeFileSync(this.configPath, JSON.stringify(this.config));
63
+ }
64
+
65
+ return this.config;
66
+ }
67
+
68
+ public setOrganization(organizationName: string) {
69
+ this.loadConfig();
70
+ // TODO: Validate organization exists and user has access.
71
+ const environment = this.getEnvironment();
72
+ this.config.configPerEnvironment[environment].organization =
73
+ organizationName;
74
+ fs.writeFileSync(this.configPath, JSON.stringify(this.config));
75
+ }
76
+
77
+ public setProject(projectName: string) {
78
+ this.loadConfig();
79
+ // TODO: Validate project exists and user has access.
80
+ const environment = this.getEnvironment();
81
+ this.config.configPerEnvironment[environment].project = projectName;
82
+ fs.writeFileSync(this.configPath, JSON.stringify(this.config));
83
+ }
84
+
85
+ public getOrganization() {
86
+ this.loadConfig();
87
+ const environment = this.getEnvironment();
88
+ return this.config.configPerEnvironment[environment].organization;
89
+ }
90
+
91
+ public getProject() {
92
+ this.loadConfig();
93
+ const environment = this.getEnvironment();
94
+ return this.config.configPerEnvironment[environment].project;
95
+ }
96
+
97
+ public setAccessToken(userToken: boolean, accessToken: string) {
98
+ this.loadConfig();
99
+ const environment = this.getEnvironment();
100
+ this.config.configPerEnvironment[environment].isServiceAccountToken = !userToken;
101
+ this.config.configPerEnvironment[environment].accessToken = accessToken;
102
+ fs.writeFileSync(this.configPath, JSON.stringify(this.config));
103
+ }
104
+
105
+ public getAuthenticationHeader() {
106
+ const environment = this.getEnvironment();
107
+ const jwt = this.config.configPerEnvironment[environment].accessToken;
108
+ const isServiceAccountToken = this.config.configPerEnvironment[environment].isServiceAccountToken;
109
+ const authType = isServiceAccountToken ? "ApiKey" : "Bearer";
110
+ return `${authType} ${jwt}`;
111
+ }
112
+
113
+ getAccessToken() {
114
+ this.loadConfig();
115
+ const environment = this.getEnvironment();
116
+ return this.config.configPerEnvironment[environment].accessToken;
117
+ }
118
+
119
+ public setJwtAccessToken(jwtAccessToken: string) {
120
+ this.loadConfig();
121
+ const environment = this.getEnvironment();
122
+ this.config.configPerEnvironment[environment].jwtAccessToken =
123
+ jwtAccessToken;
124
+ fs.writeFileSync(this.configPath, JSON.stringify(this.config));
125
+ }
126
+
127
+ public getJwtAccessToken(): string | undefined {
128
+ this.loadConfig();
129
+ const environment = this.getEnvironment();
130
+ return this.config.configPerEnvironment[environment].jwtAccessToken;
131
+ }
132
+
133
+ public setVSCodeUser(username: string, email: string) {
134
+ this.loadConfig();
135
+ const environment = this.getEnvironment();
136
+ if (!this.config.configPerEnvironment[environment]) {
137
+ this.config.configPerEnvironment[environment] = {};
138
+ }
139
+ this.config.configPerEnvironment[environment].vsCodeUser = {
140
+ username,
141
+ email,
142
+ };
143
+ fs.writeFileSync(this.configPath, JSON.stringify(this.config));
144
+ }
145
+
146
+ public getVSCodeUser(): { username: string; email: string } | undefined {
147
+ this.loadConfig();
148
+ const environment = this.getEnvironment();
149
+ return this.config.configPerEnvironment[environment].vsCodeUser;
150
+ }
151
+
152
+ public setRefreshToken(refreshToken: string) {
153
+ this.loadConfig();
154
+ const environment = this.getEnvironment();
155
+ this.config.configPerEnvironment[environment].refreshToken = refreshToken;
156
+ fs.writeFileSync(this.configPath, JSON.stringify(this.config));
157
+ }
158
+
159
+ public getRefreshToken(): string | undefined {
160
+ this.loadConfig();
161
+ const environment = this.getEnvironment();
162
+ return this.config.configPerEnvironment[environment].refreshToken;
163
+ }
164
+
165
+ public doesConfigExists() {
166
+ this.loadConfig();
167
+ const environment = this.getEnvironment();
168
+ return Boolean(this.config.configPerEnvironment[environment]);
169
+ }
170
+
171
+ public getHeaders() {
172
+ return {
173
+ Authorization: `Bearer ${this.getAccessToken()}`,
174
+ };
175
+ }
176
+
177
+ public destroyConfig() {
178
+ this.loadConfig();
179
+ const environment = this.getEnvironment();
180
+ this.config.configPerEnvironment[environment] = {};
181
+ fs.writeFileSync(this.configPath, JSON.stringify(this.config));
182
+ }
183
+
184
+ public setEnvironment(environment: Environment) {
185
+ this.loadConfig();
186
+ this.config.activeEnvironment = environment;
187
+ fs.writeFileSync(this.configPath, JSON.stringify(this.config));
188
+ }
189
+
190
+ public getEnvironment() {
191
+ this.loadConfig();
192
+ return this.config.activeEnvironment || "production";
193
+ }
194
+
195
+ public printStatus() {
196
+ this.loadConfig();
197
+ const organization = this.getOrganization();
198
+ const project = this.getProject();
199
+ // eslint-disable-next-line no-console
200
+ console.log(kleur.green(ASCII_TITLE));
201
+ logger.info(`Organization: ${kleur.green(organization || "Not set")}`);
202
+ logger.info(`Project: ${kleur.green(project || "Not set")}`);
203
+ }
204
+ }
@@ -0,0 +1,106 @@
1
+ import { Command } from "commander";
2
+ import { controlPlanesByEnv, Environment } from "../constants";
3
+ import { createConnections } from "./connection/createconnections";
4
+ import { addMember } from "./group/addmember";
5
+ import { createGroup } from "./group/creategroup";
6
+ import { createGroupAccessToken } from "./groupaccesstoken/createToken";
7
+ import { createProject } from "./project/createproject";
8
+
9
+ export const registerAddCommands = (cli: Command, environment: Environment) => {
10
+ const add = cli
11
+ .command("add")
12
+ .description("Add a resource")
13
+ .argument("<resource>", "The resource to add");
14
+
15
+ add.command("project")
16
+ .description("Add a project.")
17
+ .argument("<projectName>", "The name of the project to create.")
18
+ .option("--debug")
19
+ .option("-y, --yes", "Skip confirmation.")
20
+ .option(
21
+ "--readmeFile <readmeFile>",
22
+ "The path to the readme file for the project.",
23
+ )
24
+ .action((projectName, options) => {
25
+ createProject(
26
+ controlPlanesByEnv[environment],
27
+ projectName,
28
+ options.readmeFile,
29
+ options.debug,
30
+ options.yes,
31
+ );
32
+ });
33
+
34
+ add.command("connection")
35
+ .argument(
36
+ "<connectionFileName>",
37
+ "The path to the file containing the connections to create.",
38
+ )
39
+ .option("--debug")
40
+ .option("-y, --yes", "Skip confirmation.")
41
+ .action((connectionFileName, options) => {
42
+ createConnections(
43
+ controlPlanesByEnv[environment],
44
+ connectionFileName,
45
+ options.debug,
46
+ options.yes,
47
+ );
48
+ });
49
+
50
+ add.command("group")
51
+ .description("Add a group.")
52
+ .argument("<groupName>", "The name of the group to create")
53
+ .option("-d, --description <description>", "Description for the group")
54
+ .option("--debug")
55
+ .option("-y, --yes", "Skip confirmation.")
56
+ .action((groupName, options) => {
57
+ createGroup(
58
+ controlPlanesByEnv[environment],
59
+ groupName,
60
+ options.debug || false,
61
+ options.description,
62
+ );
63
+ });
64
+
65
+ add.command("member")
66
+ .description("Add a member to a group.")
67
+ .argument("<groupName>", "The name of the group")
68
+ .argument("<memberType>", "The type of member (user or group)")
69
+ .argument("<memberName>", "The name of the member")
70
+ .argument("<role>", "The role for the member (admin or member)")
71
+ .option("--debug")
72
+ .action((groupName, memberType, memberName, role, options) => {
73
+ addMember(
74
+ controlPlanesByEnv[environment],
75
+ groupName,
76
+ memberType,
77
+ memberName,
78
+ role,
79
+ options.debug || false,
80
+ );
81
+ });
82
+
83
+
84
+ add.command("group-access-token")
85
+ .description("Create an access token for a group.")
86
+ .argument(
87
+ "<groupName>",
88
+ "The name of the group",
89
+ )
90
+ .argument("<tokenName>", "The name of the token to create")
91
+ .option(
92
+ "-e, --expires-at <expiresAt>",
93
+ "Token expiration date in ISO 8601 format (e.g., 2025-12-31T23:59:59Z). If not provided, token will expire in 99 years.",
94
+ )
95
+ .option("--debug")
96
+ .action((groupName, tokenName, options) => {
97
+ createGroupAccessToken(
98
+ controlPlanesByEnv[environment],
99
+ groupName,
100
+ tokenName,
101
+ options.expiresAt,
102
+ options.debug || false,
103
+ );
104
+ });
105
+
106
+ };
@@ -0,0 +1,67 @@
1
+ import fs from "fs";
2
+ import { Connection, ConnectionsApi } 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 connectionsApi = new ConnectionsApi(new Configuration());
9
+
10
+ export const createConnections = async (
11
+ controlPlane: string,
12
+ connectionFileName: string,
13
+ debug: boolean,
14
+ autoConfirm: boolean,
15
+ ) => {
16
+ const clientConfig = new ClientConfiguration();
17
+ const organizationName = clientConfig.getOrganization();
18
+ const projectName = clientConfig.getProject();
19
+
20
+ if (!clientConfig.doesConfigExists()) {
21
+ logger.error("Please, make sure that you are logged in");
22
+ return;
23
+ }
24
+
25
+ if (!projectName) {
26
+ logger.error("Please, make sure to set a project");
27
+ return;
28
+ }
29
+
30
+ const connections = JSON.parse(
31
+ fs.readFileSync(connectionFileName, "utf8"),
32
+ ) as Connection[];
33
+
34
+ for (const connection of connections) {
35
+
36
+ if (!/^[a-zA-Z_][a-zA-Z0-9_]+$/.test(connection.name)) {
37
+ logger.error(`Connection name can only contain letters, numbers, and underscores for connection and should start with a letter or underscore: ${connection.name}`);
38
+ continue;
39
+ }
40
+
41
+ if (!autoConfirm) {
42
+ const confirmation = await getConfirmation(
43
+ `Are you sure you that want to create a connection named ${connection.name}?`,
44
+ );
45
+ if (!confirmation) {
46
+ logger.info("Operation cancelled.");
47
+ return;
48
+ }
49
+ }
50
+ try {
51
+ await connectionsApi.createConnection(
52
+ organizationName,
53
+ projectName,
54
+ connection,
55
+ false,
56
+ {
57
+ baseURL: controlPlane,
58
+ headers: clientConfig.getHeaders(),
59
+ },
60
+ );
61
+ logger.info(`Connection ${connection.name} created successfully`);
62
+ } catch (error) {
63
+ logger.error(`Failed to create connection ${connection.name}`);
64
+ printOutError(error, debug);
65
+ }
66
+ }
67
+ };
@@ -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,39 @@
1
+ import { ConnectionsApi } 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 connectionsApi = new ConnectionsApi(new Configuration());
8
+
9
+ export const listConnections = async (controlPlane: string, debug: boolean) => {
10
+ const clientConfig = new ClientConfiguration();
11
+ const organizationName = clientConfig.getOrganization();
12
+ const projectName = clientConfig.getProject();
13
+
14
+ if (!clientConfig.doesConfigExists()) {
15
+ logger.error("Please, make sure that you are logged in");
16
+ return;
17
+ }
18
+
19
+ if (!projectName) {
20
+ logger.error("Please, make sure to set a project");
21
+ return;
22
+ }
23
+
24
+ try {
25
+ const response = await connectionsApi.listConnections(
26
+ organizationName,
27
+ projectName,
28
+ {
29
+ baseURL: controlPlane,
30
+ headers: clientConfig.getHeaders(),
31
+ },
32
+ );
33
+
34
+ console.log(prettifyJson(response.data));
35
+ } catch (e) {
36
+ logger.error("Failed to list connections");
37
+ printOutError(e, debug);
38
+ }
39
+ };
@@ -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,83 @@
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
+ }
51
+
52
+ // Validate role
53
+ if (role !== "admin" && role !== "member") {
54
+ logger.error("Error: role must be either 'admin' or 'member'");
55
+ process.exit(1);
56
+ }
57
+
58
+ const groupMember: GroupMember = {
59
+ userGroupId: userGroupId.getValue(),
60
+ status: role as "admin" | "member",
61
+ };
62
+
63
+ const request: AddGroupMembersRequest = {
64
+ members: [groupMember],
65
+ };
66
+
67
+ try {
68
+ await groupsApi.addGroupMembers(organizationName, groupName, request, {
69
+ baseURL: controlPlane,
70
+ headers: {
71
+ Authorization: clientConfig.getAuthenticationHeader(),
72
+ },
73
+ });
74
+
75
+ logger.info(
76
+ `Successfully added ${memberType} ${memberName} to group ${groupName} with role ${role}`,
77
+ );
78
+ } catch (error) {
79
+ logger.error("Failed to add member to group");
80
+ printOutError(error, debug);
81
+ process.exit(1);
82
+ }
83
+ }
@@ -0,0 +1,54 @@
1
+ import { Group, 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
+ const groupsApi = new GroupsApi(new Configuration());
8
+
9
+ export async function createGroup(
10
+ controlPlane: string,
11
+ groupName: string,
12
+ debug: boolean,
13
+ description?: string,
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
+
22
+ const organizationName = clientConfig.getOrganization();
23
+ if (!organizationName) {
24
+ logger.error("No organization set. Please login or set an organization.");
25
+ return;
26
+ }
27
+
28
+ logger.info(
29
+ `Creating group ${groupName} in organization ${organizationName}`,
30
+ );
31
+
32
+ const group: Group = {
33
+ organizationName,
34
+ groupName,
35
+ description: description || `Group ${groupName}`,
36
+ };
37
+
38
+ try {
39
+ const response = await groupsApi.createGroup(organizationName, group, {
40
+ baseURL: controlPlane,
41
+ headers: {
42
+ Authorization: clientConfig.getAuthenticationHeader(),
43
+ },
44
+ });
45
+
46
+ const jsonString = JSON.stringify(response.data, null, 2);
47
+ console.log(jsonString);
48
+ logger.info("Group created successfully");
49
+ } catch (error) {
50
+ logger.error("Failed to create group");
51
+ printOutError(error, debug);
52
+ process.exit(1);
53
+ }
54
+ }
@@ -0,0 +1,45 @@
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
+ const groupsApi = new GroupsApi(new Configuration());
8
+
9
+ export async function deleteGroup(
10
+ controlPlane: string,
11
+ groupName: string,
12
+ debug: boolean,
13
+ ) {
14
+ const clientConfig = new ClientConfiguration();
15
+
16
+ if (!clientConfig.doesConfigExists()) {
17
+ logger.error("Please, make sure that you are logged in");
18
+ return;
19
+ }
20
+
21
+ const organizationName = clientConfig.getOrganization();
22
+ if (!organizationName) {
23
+ logger.error("No organization set. Please login or set an organization.");
24
+ return;
25
+ }
26
+
27
+ logger.info(
28
+ `Deleting group ${groupName} from organization ${organizationName}`,
29
+ );
30
+
31
+ try {
32
+ await groupsApi.deleteGroup(organizationName, groupName, {
33
+ baseURL: controlPlane,
34
+ headers: {
35
+ Authorization: clientConfig.getAuthenticationHeader(),
36
+ },
37
+ });
38
+
39
+ logger.info("Group deleted successfully");
40
+ } catch (error) {
41
+ logger.error("Failed to delete group");
42
+ printOutError(error, debug);
43
+ process.exit(1);
44
+ }
45
+ }