@credibledata/cred-cli 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/build.yml +23 -0
- package/.mocharc.json +10 -0
- package/.prettierignore +2 -0
- package/.prettierrc +4 -0
- package/README-DEV.md +40 -0
- package/README.md +11 -0
- package/bun.lock +1158 -0
- package/dist/client/api.js +7715 -0
- package/dist/client/api.js.map +1 -0
- package/dist/client/base.js +69 -0
- package/dist/client/base.js.map +1 -0
- package/dist/client/common.js +162 -0
- package/dist/client/common.js.map +1 -0
- package/dist/client/configuration.js +44 -0
- package/dist/client/configuration.js.map +1 -0
- package/dist/client/index.js +32 -0
- package/dist/client/index.js.map +1 -0
- package/dist/clientconfiguration.js +205 -0
- package/dist/clientconfiguration.js.map +1 -0
- package/dist/clientconfiguration.spec.js +381 -0
- package/dist/clientconfiguration.spec.js.map +1 -0
- package/dist/commands/add.js +66 -0
- package/dist/commands/add.js.map +1 -0
- package/dist/commands/connection/createconnections.js +89 -0
- package/dist/commands/connection/createconnections.js.map +1 -0
- package/dist/commands/connection/createconnections.spec.js +219 -0
- package/dist/commands/connection/createconnections.spec.js.map +1 -0
- package/dist/commands/connection/deleteconnection.js +52 -0
- package/dist/commands/connection/deleteconnection.js.map +1 -0
- package/dist/commands/connection/deleteconnection.spec.js +130 -0
- package/dist/commands/connection/deleteconnection.spec.js.map +1 -0
- package/dist/commands/connection/listconnections.js +50 -0
- package/dist/commands/connection/listconnections.js.map +1 -0
- package/dist/commands/connection/listconnections.spec.js +117 -0
- package/dist/commands/connection/listconnections.spec.js.map +1 -0
- package/dist/commands/get.js +28 -0
- package/dist/commands/get.js.map +1 -0
- package/dist/commands/group/addmember.js +75 -0
- package/dist/commands/group/addmember.js.map +1 -0
- package/dist/commands/group/addmember.spec.js +148 -0
- package/dist/commands/group/addmember.spec.js.map +1 -0
- package/dist/commands/group/creategroup.js +55 -0
- package/dist/commands/group/creategroup.js.map +1 -0
- package/dist/commands/group/creategroup.spec.js +122 -0
- package/dist/commands/group/creategroup.spec.js.map +1 -0
- package/dist/commands/group/deletegroup.js +48 -0
- package/dist/commands/group/deletegroup.js.map +1 -0
- package/dist/commands/group/deletegroup.spec.js +104 -0
- package/dist/commands/group/deletegroup.spec.js.map +1 -0
- package/dist/commands/group/getgroup.js +50 -0
- package/dist/commands/group/getgroup.js.map +1 -0
- package/dist/commands/group/getgroup.spec.js +111 -0
- package/dist/commands/group/getgroup.spec.js.map +1 -0
- package/dist/commands/group/listgroups.js +56 -0
- package/dist/commands/group/listgroups.js.map +1 -0
- package/dist/commands/group/listgroups.spec.js +118 -0
- package/dist/commands/group/listgroups.spec.js.map +1 -0
- package/dist/commands/group/removemember.js +69 -0
- package/dist/commands/group/removemember.js.map +1 -0
- package/dist/commands/group/removemember.spec.js +138 -0
- package/dist/commands/group/removemember.spec.js.map +1 -0
- package/dist/commands/groupaccesstoken/createToken.js +53 -0
- package/dist/commands/groupaccesstoken/createToken.js.map +1 -0
- package/dist/commands/groupaccesstoken/createToken.spec.js +127 -0
- package/dist/commands/groupaccesstoken/createToken.spec.js.map +1 -0
- package/dist/commands/groupaccesstoken/deleteToken.js +24 -0
- package/dist/commands/groupaccesstoken/deleteToken.js.map +1 -0
- package/dist/commands/groupaccesstoken/deleteToken.spec.js +103 -0
- package/dist/commands/groupaccesstoken/deleteToken.spec.js.map +1 -0
- package/dist/commands/groupaccesstoken/groupContainer.js +71 -0
- package/dist/commands/groupaccesstoken/groupContainer.js.map +1 -0
- package/dist/commands/groupaccesstoken/listTokens.js +25 -0
- package/dist/commands/groupaccesstoken/listTokens.js.map +1 -0
- package/dist/commands/groupaccesstoken/listTokens.spec.js +115 -0
- package/dist/commands/groupaccesstoken/listTokens.spec.js.map +1 -0
- package/dist/commands/list.js +75 -0
- package/dist/commands/list.js.map +1 -0
- package/dist/commands/misc/login.js +290 -0
- package/dist/commands/misc/login.js.map +1 -0
- package/dist/commands/misc/login.spec.js +243 -0
- package/dist/commands/misc/login.spec.js.map +1 -0
- package/dist/commands/misc/logout.js +11 -0
- package/dist/commands/misc/logout.js.map +1 -0
- package/dist/commands/misc/logout.spec.js +30 -0
- package/dist/commands/misc/logout.spec.js.map +1 -0
- package/dist/commands/misc/loopbackOAuth.js +110 -0
- package/dist/commands/misc/loopbackOAuth.js.map +1 -0
- package/dist/commands/misc/set-access-token.js +27 -0
- package/dist/commands/misc/set-access-token.js.map +1 -0
- package/dist/commands/misc/set-access-token.spec.js +65 -0
- package/dist/commands/misc/set-access-token.spec.js.map +1 -0
- package/dist/commands/package/deletepackage.js +54 -0
- package/dist/commands/package/deletepackage.js.map +1 -0
- package/dist/commands/package/deletepackage.spec.js +136 -0
- package/dist/commands/package/deletepackage.spec.js.map +1 -0
- package/dist/commands/package/listpackages.js +57 -0
- package/dist/commands/package/listpackages.js.map +1 -0
- package/dist/commands/package/listpackages.spec.js +129 -0
- package/dist/commands/package/listpackages.spec.js.map +1 -0
- package/dist/commands/package/publish.js +157 -0
- package/dist/commands/package/publish.js.map +1 -0
- package/dist/commands/package/publish.spec.js +511 -0
- package/dist/commands/package/publish.spec.js.map +1 -0
- package/dist/commands/package/updatepackage.js +75 -0
- package/dist/commands/package/updatepackage.js.map +1 -0
- package/dist/commands/package/updatepackage.spec.js +189 -0
- package/dist/commands/package/updatepackage.spec.js.map +1 -0
- package/dist/commands/project/createproject.js +75 -0
- package/dist/commands/project/createproject.js.map +1 -0
- package/dist/commands/project/createproject.spec.js +154 -0
- package/dist/commands/project/createproject.spec.js.map +1 -0
- package/dist/commands/project/deleteproject.js +49 -0
- package/dist/commands/project/deleteproject.js.map +1 -0
- package/dist/commands/project/deleteproject.spec.js +106 -0
- package/dist/commands/project/deleteproject.spec.js.map +1 -0
- package/dist/commands/project/getproject.js +44 -0
- package/dist/commands/project/getproject.js.map +1 -0
- package/dist/commands/project/getproject.spec.js +99 -0
- package/dist/commands/project/getproject.spec.js.map +1 -0
- package/dist/commands/project/listprojects.js +52 -0
- package/dist/commands/project/listprojects.js.map +1 -0
- package/dist/commands/project/listprojects.spec.js +111 -0
- package/dist/commands/project/listprojects.spec.js.map +1 -0
- package/dist/commands/project/setproject.js +26 -0
- package/dist/commands/project/setproject.js.map +1 -0
- package/dist/commands/project/setproject.spec.js +58 -0
- package/dist/commands/project/setproject.spec.js.map +1 -0
- package/dist/commands/project/updateproject.js +68 -0
- package/dist/commands/project/updateproject.js.map +1 -0
- package/dist/commands/project/updateproject.spec.js +129 -0
- package/dist/commands/project/updateproject.spec.js.map +1 -0
- package/dist/commands/rm.js +68 -0
- package/dist/commands/rm.js.map +1 -0
- package/dist/commands/set.js +17 -0
- package/dist/commands/set.js.map +1 -0
- package/dist/commands/update.js +42 -0
- package/dist/commands/update.js.map +1 -0
- package/dist/commands/version/archive-unarchive-version.js +79 -0
- package/dist/commands/version/archive-unarchive-version.js.map +1 -0
- package/dist/commands/version/archive-unarchive-version.spec.js +244 -0
- package/dist/commands/version/archive-unarchive-version.spec.js.map +1 -0
- package/dist/commands/version/listversions.js +46 -0
- package/dist/commands/version/listversions.js.map +1 -0
- package/dist/commands/version/listversions.spec.js +121 -0
- package/dist/commands/version/listversions.spec.js.map +1 -0
- package/dist/common/UserGroupId.js +112 -0
- package/dist/common/UserGroupId.js.map +1 -0
- package/dist/common/UserGroupId.spec.js +92 -0
- package/dist/common/UserGroupId.spec.js.map +1 -0
- package/dist/constants.js +90 -0
- package/dist/constants.js.map +1 -0
- package/dist/index.js +159 -0
- package/dist/index.js.map +1 -0
- package/dist/logger.js +77 -0
- package/dist/logger.js.map +1 -0
- package/dist/logger.spec.js +125 -0
- package/dist/logger.spec.js.map +1 -0
- package/dist/polyfills/file.polyfill.js +6 -0
- package/dist/polyfills/file.polyfill.js.map +1 -0
- package/dist/utils.js +110 -0
- package/dist/utils.js.map +1 -0
- package/dist/utils.spec.js +158 -0
- package/dist/utils.spec.js.map +1 -0
- package/dist/validator.js +53 -0
- package/dist/validator.js.map +1 -0
- package/dist/validator.spec.js +41 -0
- package/dist/validator.spec.js.map +1 -0
- package/docker/Dockerfile.ci +18 -0
- package/docker-compose.yml +18 -0
- package/eslint.config.mjs +45 -0
- package/generate-client.sh +27 -0
- package/mocha.setup.ts +4 -0
- package/openapitools.json +7 -0
- package/package.json +75 -0
- package/src/client/.openapi-generator/FILES +9 -0
- package/src/client/.openapi-generator/VERSION +1 -0
- package/src/client/.openapi-generator-ignore +23 -0
- package/src/client/api.ts +9729 -0
- package/src/client/base.ts +86 -0
- package/src/client/common.ts +150 -0
- package/src/client/configuration.ts +110 -0
- package/src/client/git_push.sh +57 -0
- package/src/client/index.ts +18 -0
- package/src/clientconfiguration.spec.ts +490 -0
- package/src/clientconfiguration.ts +263 -0
- package/src/commands/add.ts +125 -0
- package/src/commands/connection/createconnections.spec.ts +403 -0
- package/src/commands/connection/createconnections.ts +109 -0
- package/src/commands/connection/deleteconnection.spec.ts +189 -0
- package/src/commands/connection/deleteconnection.ts +57 -0
- package/src/commands/connection/listconnections.spec.ts +132 -0
- package/src/commands/connection/listconnections.ts +58 -0
- package/src/commands/get.ts +31 -0
- package/src/commands/group/addmember.spec.ts +257 -0
- package/src/commands/group/addmember.ts +85 -0
- package/src/commands/group/creategroup.spec.ts +146 -0
- package/src/commands/group/creategroup.ts +54 -0
- package/src/commands/group/deletegroup.spec.ts +120 -0
- package/src/commands/group/deletegroup.ts +45 -0
- package/src/commands/group/getgroup.spec.ts +129 -0
- package/src/commands/group/getgroup.ts +47 -0
- package/src/commands/group/listgroups.spec.ts +137 -0
- package/src/commands/group/listgroups.ts +45 -0
- package/src/commands/group/removemember.spec.ts +224 -0
- package/src/commands/group/removemember.ts +75 -0
- package/src/commands/groupaccesstoken/createToken.spec.ts +211 -0
- package/src/commands/groupaccesstoken/createToken.ts +72 -0
- package/src/commands/groupaccesstoken/deleteToken.spec.ts +147 -0
- package/src/commands/groupaccesstoken/deleteToken.ts +29 -0
- package/src/commands/groupaccesstoken/groupContainer.ts +83 -0
- package/src/commands/groupaccesstoken/listTokens.spec.ts +147 -0
- package/src/commands/groupaccesstoken/listTokens.ts +29 -0
- package/src/commands/list.ts +131 -0
- package/src/commands/misc/login.spec.ts +213 -0
- package/src/commands/misc/login.ts +325 -0
- package/src/commands/misc/logout.spec.ts +32 -0
- package/src/commands/misc/logout.ts +9 -0
- package/src/commands/misc/loopbackOAuth.ts +127 -0
- package/src/commands/misc/set-access-token.spec.ts +95 -0
- package/src/commands/misc/set-access-token.ts +32 -0
- package/src/commands/package/deletepackage.spec.ts +164 -0
- package/src/commands/package/deletepackage.ts +58 -0
- package/src/commands/package/listpackages.spec.ts +147 -0
- package/src/commands/package/listpackages.ts +67 -0
- package/src/commands/package/publish.spec.ts +597 -0
- package/src/commands/package/publish.ts +211 -0
- package/src/commands/package/updatepackage.spec.ts +319 -0
- package/src/commands/package/updatepackage.ts +95 -0
- package/src/commands/project/createproject.spec.ts +247 -0
- package/src/commands/project/createproject.ts +70 -0
- package/src/commands/project/deleteproject.spec.ts +123 -0
- package/src/commands/project/deleteproject.ts +48 -0
- package/src/commands/project/getproject.spec.ts +109 -0
- package/src/commands/project/getproject.ts +43 -0
- package/src/commands/project/listprojects.spec.ts +121 -0
- package/src/commands/project/listprojects.ts +62 -0
- package/src/commands/project/setproject.spec.ts +63 -0
- package/src/commands/project/setproject.ts +14 -0
- package/src/commands/project/updateproject.spec.ts +217 -0
- package/src/commands/project/updateproject.ts +82 -0
- package/src/commands/rm.ts +101 -0
- package/src/commands/set.ts +16 -0
- package/src/commands/update.ts +64 -0
- package/src/commands/version/archive-unarchive-version.spec.ts +456 -0
- package/src/commands/version/archive-unarchive-version.ts +111 -0
- package/src/commands/version/listversions.spec.ts +138 -0
- package/src/commands/version/listversions.ts +45 -0
- package/src/common/UserGroupId.spec.ts +117 -0
- package/src/common/UserGroupId.ts +137 -0
- package/src/constants.ts +116 -0
- package/src/index.ts +209 -0
- package/src/logger.spec.ts +158 -0
- package/src/logger.ts +86 -0
- package/src/polyfills/file.polyfill.ts +6 -0
- package/src/utils.spec.ts +135 -0
- package/src/utils.ts +115 -0
- package/src/validator.spec.ts +51 -0
- package/src/validator.ts +44 -0
- package/tsconfig.json +17 -0
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import { jwtDecode } from "jwt-decode";
|
|
3
|
+
import kleur from "kleur";
|
|
4
|
+
import os from "os";
|
|
5
|
+
import { ALL_ENVIRONMENTS, ASCII_TITLE, Environment } from "./constants";
|
|
6
|
+
import { logger } from "./logger";
|
|
7
|
+
|
|
8
|
+
interface ConfigFile {
|
|
9
|
+
configPerEnvironment: Partial<
|
|
10
|
+
Record<
|
|
11
|
+
Environment,
|
|
12
|
+
{
|
|
13
|
+
organization?: string;
|
|
14
|
+
project?: string;
|
|
15
|
+
auth?: { username: string; password: string };
|
|
16
|
+
vsCodeUser?: {
|
|
17
|
+
username: string;
|
|
18
|
+
email: string;
|
|
19
|
+
};
|
|
20
|
+
accessToken?: string;
|
|
21
|
+
jwtAccessToken?: string;
|
|
22
|
+
refreshToken?: string;
|
|
23
|
+
isServiceAccountToken?: boolean;
|
|
24
|
+
}
|
|
25
|
+
>
|
|
26
|
+
>;
|
|
27
|
+
activeEnvironment: Environment;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
interface JwtPayload {
|
|
31
|
+
exp: number;
|
|
32
|
+
iat?: number;
|
|
33
|
+
sub?: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export class ClientConfiguration {
|
|
37
|
+
private configPath = `${os.homedir()}/.cred`;
|
|
38
|
+
private config: ConfigFile;
|
|
39
|
+
|
|
40
|
+
constructor(customConfigPath?: string) {
|
|
41
|
+
if (customConfigPath) {
|
|
42
|
+
this.configPath = customConfigPath;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
public loadConfig(): ConfigFile {
|
|
47
|
+
try {
|
|
48
|
+
const fileContents = fs.readFileSync(this.configPath);
|
|
49
|
+
this.config = JSON.parse(fileContents.toString());
|
|
50
|
+
if (
|
|
51
|
+
!this.config.activeEnvironment ||
|
|
52
|
+
!this.config.configPerEnvironment
|
|
53
|
+
) {
|
|
54
|
+
throw new Error(
|
|
55
|
+
"Corrupted config file found, restoring to default settings.",
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
} catch (error) {
|
|
59
|
+
logger.warn(error);
|
|
60
|
+
const configPerEnvironment: ConfigFile["configPerEnvironment"] = {};
|
|
61
|
+
for (const env of ALL_ENVIRONMENTS) {
|
|
62
|
+
configPerEnvironment[env] = {};
|
|
63
|
+
}
|
|
64
|
+
this.config = {
|
|
65
|
+
configPerEnvironment,
|
|
66
|
+
activeEnvironment: "production",
|
|
67
|
+
};
|
|
68
|
+
fs.writeFileSync(this.configPath, JSON.stringify(this.config));
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
for (const env of ALL_ENVIRONMENTS) {
|
|
72
|
+
if (!this.config.configPerEnvironment[env]) {
|
|
73
|
+
this.config.configPerEnvironment[env] = {};
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return this.config;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
public setOrganization(organizationName: string) {
|
|
81
|
+
this.loadConfig();
|
|
82
|
+
// TODO: Validate organization exists and user has access.
|
|
83
|
+
const environment = this.getEnvironment();
|
|
84
|
+
this.config.configPerEnvironment[environment].organization =
|
|
85
|
+
organizationName;
|
|
86
|
+
fs.writeFileSync(this.configPath, JSON.stringify(this.config));
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
public setProject(projectName: string) {
|
|
90
|
+
this.loadConfig();
|
|
91
|
+
// TODO: Validate project exists and user has access.
|
|
92
|
+
const environment = this.getEnvironment();
|
|
93
|
+
this.config.configPerEnvironment[environment].project = projectName;
|
|
94
|
+
fs.writeFileSync(this.configPath, JSON.stringify(this.config));
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
public getOrganization() {
|
|
98
|
+
this.loadConfig();
|
|
99
|
+
const environment = this.getEnvironment();
|
|
100
|
+
return this.config.configPerEnvironment[environment].organization;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
public getProject() {
|
|
104
|
+
this.loadConfig();
|
|
105
|
+
const environment = this.getEnvironment();
|
|
106
|
+
return this.config.configPerEnvironment[environment].project;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
public setAccessToken(userToken: boolean, accessToken: string) {
|
|
110
|
+
this.loadConfig();
|
|
111
|
+
const environment = this.getEnvironment();
|
|
112
|
+
this.config.configPerEnvironment[environment].isServiceAccountToken =
|
|
113
|
+
!userToken;
|
|
114
|
+
this.config.configPerEnvironment[environment].accessToken = accessToken;
|
|
115
|
+
fs.writeFileSync(this.configPath, JSON.stringify(this.config));
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
public getAuthenticationHeader() {
|
|
119
|
+
const environment = this.getEnvironment();
|
|
120
|
+
const jwt = this.config.configPerEnvironment[environment].accessToken;
|
|
121
|
+
const isServiceAccountToken =
|
|
122
|
+
this.config.configPerEnvironment[environment].isServiceAccountToken;
|
|
123
|
+
const authType = isServiceAccountToken ? "ApiKey" : "Bearer";
|
|
124
|
+
return `${authType} ${jwt}`;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
getAccessToken() {
|
|
128
|
+
this.loadConfig();
|
|
129
|
+
const environment = this.getEnvironment();
|
|
130
|
+
return this.config.configPerEnvironment[environment].accessToken;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
public setJwtAccessToken(jwtAccessToken: string) {
|
|
134
|
+
this.loadConfig();
|
|
135
|
+
const environment = this.getEnvironment();
|
|
136
|
+
this.config.configPerEnvironment[environment].jwtAccessToken =
|
|
137
|
+
jwtAccessToken;
|
|
138
|
+
fs.writeFileSync(this.configPath, JSON.stringify(this.config));
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
public getJwtAccessToken(): string | undefined {
|
|
142
|
+
this.loadConfig();
|
|
143
|
+
const environment = this.getEnvironment();
|
|
144
|
+
return this.config.configPerEnvironment[environment].jwtAccessToken;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
public setVSCodeUser(username: string, email: string) {
|
|
148
|
+
this.loadConfig();
|
|
149
|
+
const environment = this.getEnvironment();
|
|
150
|
+
if (!this.config.configPerEnvironment[environment]) {
|
|
151
|
+
this.config.configPerEnvironment[environment] = {};
|
|
152
|
+
}
|
|
153
|
+
this.config.configPerEnvironment[environment].vsCodeUser = {
|
|
154
|
+
username,
|
|
155
|
+
email,
|
|
156
|
+
};
|
|
157
|
+
fs.writeFileSync(this.configPath, JSON.stringify(this.config));
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
public getVSCodeUser(): { username: string; email: string } | undefined {
|
|
161
|
+
this.loadConfig();
|
|
162
|
+
const environment = this.getEnvironment();
|
|
163
|
+
return this.config.configPerEnvironment[environment].vsCodeUser;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
public setRefreshToken(refreshToken: string) {
|
|
167
|
+
this.loadConfig();
|
|
168
|
+
const environment = this.getEnvironment();
|
|
169
|
+
this.config.configPerEnvironment[environment].refreshToken = refreshToken;
|
|
170
|
+
fs.writeFileSync(this.configPath, JSON.stringify(this.config));
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
public getRefreshToken(): string | undefined {
|
|
174
|
+
this.loadConfig();
|
|
175
|
+
const environment = this.getEnvironment();
|
|
176
|
+
return this.config.configPerEnvironment[environment].refreshToken;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
public doesConfigExists() {
|
|
180
|
+
this.loadConfig();
|
|
181
|
+
const environment = this.getEnvironment();
|
|
182
|
+
return Boolean(this.config.configPerEnvironment[environment]);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
public getHeaders() {
|
|
186
|
+
return {
|
|
187
|
+
Authorization: this.getAuthenticationHeader(),
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
public destroyConfig() {
|
|
192
|
+
this.loadConfig();
|
|
193
|
+
const environment = this.getEnvironment();
|
|
194
|
+
this.config.configPerEnvironment[environment] = {};
|
|
195
|
+
fs.writeFileSync(this.configPath, JSON.stringify(this.config));
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
public setEnvironment(environment: Environment) {
|
|
199
|
+
this.loadConfig();
|
|
200
|
+
this.config.activeEnvironment = environment;
|
|
201
|
+
fs.writeFileSync(this.configPath, JSON.stringify(this.config));
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
public getEnvironment() {
|
|
205
|
+
this.loadConfig();
|
|
206
|
+
return this.config.activeEnvironment || "production";
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
public isTokenValid(): { valid: boolean; reason?: string } {
|
|
210
|
+
this.loadConfig();
|
|
211
|
+
const environment = this.getEnvironment();
|
|
212
|
+
const accessToken =
|
|
213
|
+
this.config.configPerEnvironment[environment]?.accessToken;
|
|
214
|
+
|
|
215
|
+
if (!accessToken) {
|
|
216
|
+
return { valid: false, reason: "No token found. Please login." };
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
const isServiceAccountToken =
|
|
220
|
+
this.config.configPerEnvironment[environment]?.isServiceAccountToken;
|
|
221
|
+
if (isServiceAccountToken) {
|
|
222
|
+
return { valid: true };
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
try {
|
|
226
|
+
const decoded = jwtDecode<JwtPayload>(accessToken);
|
|
227
|
+
const currentTime = Math.floor(Date.now() / 1000);
|
|
228
|
+
|
|
229
|
+
if (decoded.exp && decoded.exp < currentTime) {
|
|
230
|
+
return {
|
|
231
|
+
valid: false,
|
|
232
|
+
reason: "Token expired. Please login again.",
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
return { valid: true };
|
|
237
|
+
} catch {
|
|
238
|
+
return {
|
|
239
|
+
valid: false,
|
|
240
|
+
reason: "Invalid token format. Please login again.",
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
public printStatus() {
|
|
246
|
+
this.loadConfig();
|
|
247
|
+
const tokenStatus = this.isTokenValid();
|
|
248
|
+
|
|
249
|
+
if (tokenStatus.valid) {
|
|
250
|
+
const organization = this.getOrganization();
|
|
251
|
+
const project = this.getProject();
|
|
252
|
+
|
|
253
|
+
console.log(kleur.green(ASCII_TITLE));
|
|
254
|
+
logger.info(`Organization: ${kleur.green(organization || "Not set")}`);
|
|
255
|
+
logger.info(`Project: ${kleur.green(project || "Not set")}`);
|
|
256
|
+
} else {
|
|
257
|
+
logger.error("Failed to get status");
|
|
258
|
+
logger.error(
|
|
259
|
+
tokenStatus.reason || "Please, make sure that you are logged in",
|
|
260
|
+
);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
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
|
+
.option(
|
|
25
|
+
"--replication <replicationCount>",
|
|
26
|
+
"The replication count (must be at least 1).",
|
|
27
|
+
parseInt,
|
|
28
|
+
)
|
|
29
|
+
.action((projectName, options) => {
|
|
30
|
+
createProject(
|
|
31
|
+
controlPlanesByEnv[environment],
|
|
32
|
+
projectName,
|
|
33
|
+
options.readmeFile,
|
|
34
|
+
options.replication,
|
|
35
|
+
options.debug,
|
|
36
|
+
options.yes,
|
|
37
|
+
);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
add.command("connection")
|
|
41
|
+
.argument(
|
|
42
|
+
"<connectionFileName>",
|
|
43
|
+
"The path to the file containing the connections to create.",
|
|
44
|
+
)
|
|
45
|
+
.option(
|
|
46
|
+
"--include-tables <includeTables>",
|
|
47
|
+
"The list of tables to include. Ex: {dataset/schema}.{table}",
|
|
48
|
+
)
|
|
49
|
+
.option(
|
|
50
|
+
"--exclude-tables <excludeTables>",
|
|
51
|
+
"The list of tables to exclude. Ex: {dataset/schema}.{table}",
|
|
52
|
+
)
|
|
53
|
+
.option(
|
|
54
|
+
"--skip-indexing",
|
|
55
|
+
"Disable automatic indexing for this connection.",
|
|
56
|
+
false,
|
|
57
|
+
)
|
|
58
|
+
.option("--debug")
|
|
59
|
+
.option("-y, --yes", "Skip confirmation.")
|
|
60
|
+
.action((connectionFileName, options) => {
|
|
61
|
+
createConnections(
|
|
62
|
+
controlPlanesByEnv[environment],
|
|
63
|
+
connectionFileName,
|
|
64
|
+
options.includeTables,
|
|
65
|
+
options.excludeTables,
|
|
66
|
+
options.skipIndexing,
|
|
67
|
+
options.debug,
|
|
68
|
+
options.yes,
|
|
69
|
+
);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
add.command("group")
|
|
73
|
+
.description("Add a group.")
|
|
74
|
+
.argument("<groupName>", "The name of the group to create")
|
|
75
|
+
.option("-d, --description <description>", "Description for the group")
|
|
76
|
+
.option("--debug")
|
|
77
|
+
.option("-y, --yes", "Skip confirmation.")
|
|
78
|
+
.action((groupName, options) => {
|
|
79
|
+
createGroup(
|
|
80
|
+
controlPlanesByEnv[environment],
|
|
81
|
+
groupName,
|
|
82
|
+
options.debug || false,
|
|
83
|
+
options.description,
|
|
84
|
+
);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
add.command("member")
|
|
88
|
+
.description("Add a member to a group.")
|
|
89
|
+
.argument("<groupName>", "The name of the group")
|
|
90
|
+
.argument("<memberType>", "The type of member (user or group)")
|
|
91
|
+
.argument("<memberName>", "The name of the member")
|
|
92
|
+
.argument("<role>", "The role for the member (admin or member)")
|
|
93
|
+
.option("--debug")
|
|
94
|
+
.action((groupName, memberType, memberName, role, options) => {
|
|
95
|
+
addMember(
|
|
96
|
+
controlPlanesByEnv[environment],
|
|
97
|
+
groupName,
|
|
98
|
+
memberType,
|
|
99
|
+
memberName,
|
|
100
|
+
role,
|
|
101
|
+
options.debug || false,
|
|
102
|
+
);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
add.command("group-access-token")
|
|
106
|
+
.description("Create an access token for a group.")
|
|
107
|
+
.argument("<groupName>", "The name of the group")
|
|
108
|
+
.argument("<tokenName>", "The name of the token to create")
|
|
109
|
+
.option(
|
|
110
|
+
"-e, --expires-at <expiresAt>",
|
|
111
|
+
"Token expiration date in ISO 8601 format (e.g., 2025-12-31T23:59:59Z). If not provided, token will expire in 99 years.",
|
|
112
|
+
)
|
|
113
|
+
.option("--debug")
|
|
114
|
+
.option("-j, --json-output", "Output only JSON (for use in scripts)")
|
|
115
|
+
.action((groupName, tokenName, options) => {
|
|
116
|
+
createGroupAccessToken(
|
|
117
|
+
controlPlanesByEnv[environment],
|
|
118
|
+
groupName,
|
|
119
|
+
tokenName,
|
|
120
|
+
options.expiresAt,
|
|
121
|
+
options.jsonOutput === true,
|
|
122
|
+
options.debug || false,
|
|
123
|
+
);
|
|
124
|
+
});
|
|
125
|
+
};
|