contensis-cli 1.0.0-beta.8 → 1.0.0-beta.80
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/README.md +1146 -78
- package/dist/commands/connect.js +3 -3
- package/dist/commands/connect.js.map +2 -2
- package/dist/commands/create.js +45 -10
- package/dist/commands/create.js.map +2 -2
- package/dist/commands/diff.js +57 -0
- package/dist/commands/diff.js.map +7 -0
- package/dist/commands/execute.js +103 -0
- package/dist/commands/execute.js.map +7 -0
- package/dist/commands/get.js +107 -18
- package/dist/commands/get.js.map +2 -2
- package/dist/commands/globalOptions.js +22 -17
- package/dist/commands/globalOptions.js.map +2 -2
- package/dist/commands/import.js +46 -11
- package/dist/commands/import.js.map +2 -2
- package/dist/commands/index.js +16 -2
- package/dist/commands/index.js.map +2 -2
- package/dist/commands/list.js +53 -10
- package/dist/commands/list.js.map +2 -2
- package/dist/commands/login.js +3 -3
- package/dist/commands/login.js.map +2 -2
- package/dist/commands/push.js +9 -5
- package/dist/commands/push.js.map +2 -2
- package/dist/commands/remove.js +51 -8
- package/dist/commands/remove.js.map +2 -2
- package/dist/commands/set.js +139 -12
- package/dist/commands/set.js.map +2 -2
- package/dist/index.js +1 -1
- package/dist/index.js.map +2 -2
- package/dist/localisation/en-GB.js +193 -49
- package/dist/localisation/en-GB.js.map +2 -2
- package/dist/providers/CredentialProvider.js +36 -7
- package/dist/providers/CredentialProvider.js.map +3 -3
- package/dist/providers/SessionCacheProvider.js +21 -1
- package/dist/providers/SessionCacheProvider.js.map +2 -2
- package/dist/providers/file-provider.js +8 -4
- package/dist/providers/file-provider.js.map +3 -3
- package/dist/services/ContensisCliService.js +1092 -410
- package/dist/services/ContensisCliService.js.map +3 -3
- package/dist/shell.js +48 -14
- package/dist/shell.js.map +3 -3
- package/dist/util/console.printer.js +171 -55
- package/dist/util/console.printer.js.map +2 -2
- package/dist/util/diff.js +39 -0
- package/dist/util/diff.js.map +7 -0
- package/dist/util/index.js +8 -2
- package/dist/util/index.js.map +3 -3
- package/dist/util/logger.js +61 -29
- package/dist/util/logger.js.map +3 -3
- package/dist/util/timers.js +49 -0
- package/dist/util/timers.js.map +7 -0
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/esbuild.config.js +3 -1
- package/package.json +2 -2
- package/src/commands/connect.ts +3 -2
- package/src/commands/create.ts +61 -8
- package/src/commands/diff.ts +41 -0
- package/src/commands/execute.ts +117 -0
- package/src/commands/get.ts +150 -14
- package/src/commands/globalOptions.ts +18 -17
- package/src/commands/import.ts +57 -7
- package/src/commands/index.ts +16 -1
- package/src/commands/list.ts +85 -11
- package/src/commands/login.ts +3 -2
- package/src/commands/push.ts +10 -3
- package/src/commands/remove.ts +66 -4
- package/src/commands/set.ts +189 -9
- package/src/index.ts +1 -4
- package/src/localisation/en-GB.ts +269 -66
- package/src/providers/CredentialProvider.ts +39 -6
- package/src/providers/SessionCacheProvider.ts +29 -2
- package/src/providers/file-provider.ts +12 -4
- package/src/services/ContensisCliService.ts +1384 -484
- package/src/shell.ts +52 -15
- package/src/util/console.printer.ts +240 -78
- package/src/util/diff.ts +17 -0
- package/src/util/index.ts +16 -7
- package/src/util/logger.ts +111 -31
- package/src/util/timers.ts +24 -0
- package/src/version.ts +1 -1
|
@@ -1,12 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
BlockActionType,
|
|
3
|
+
BlockRunningStatus,
|
|
4
|
+
MigrateModelsResult,
|
|
5
|
+
MigrateStatus,
|
|
6
|
+
} from 'migratortron';
|
|
2
7
|
import { Logger } from '~/util/logger';
|
|
3
8
|
|
|
4
9
|
export const LogMessages = {
|
|
5
10
|
app: {
|
|
6
11
|
contensis: () => 'Contensis',
|
|
7
12
|
quit: () => `Goodbye 👋\n`,
|
|
8
|
-
startup: () =>
|
|
9
|
-
|
|
13
|
+
startup: (version: string) =>
|
|
14
|
+
`v${version} © 2001-${new Date().getFullYear()} Zengenti 🇬🇧. \n - Creators of Contensis and purveyors of other fine software\n\n👋 Welcome to the contensis-cli\n`,
|
|
10
15
|
help: () =>
|
|
11
16
|
'Press [CTRL]+[C] or type "quit" to return to your system shell\nPress [TAB] for suggestions\n',
|
|
12
17
|
suggestions: () =>
|
|
@@ -73,8 +78,10 @@ export const LogMessages = {
|
|
|
73
78
|
'the shared secret to use when logging in with a client id',
|
|
74
79
|
},
|
|
75
80
|
},
|
|
76
|
-
passwordPrompt: (env
|
|
77
|
-
|
|
81
|
+
passwordPrompt: (env?: string, userId?: string) =>
|
|
82
|
+
userId
|
|
83
|
+
? `Enter password for ${userId}@${env}:`
|
|
84
|
+
: `Please enter a password`,
|
|
78
85
|
failed: (env: string, userId: string) =>
|
|
79
86
|
`Unable to login to ${env} as ${userId}`,
|
|
80
87
|
success: (env: string, userId: string) =>
|
|
@@ -87,49 +94,38 @@ export const LogMessages = {
|
|
|
87
94
|
projects: {
|
|
88
95
|
list: () => `Available projects:`,
|
|
89
96
|
noList: () => `Cannot retrieve projects list`,
|
|
90
|
-
set: (projectId: string) =>
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
`[${env}] ${commit ? `Deleted` : `Will delete`} content type "${id}"`,
|
|
105
|
-
failedRemove: (env: string, id: string) =>
|
|
106
|
-
`[${env}] Unable to delete content type "${id}"`,
|
|
107
|
-
},
|
|
108
|
-
components: {
|
|
109
|
-
list: (projectId: string) => `Components in "${projectId}":`,
|
|
110
|
-
noList: (projectId: string) =>
|
|
111
|
-
`[${projectId}] Cannot retrieve components list`,
|
|
112
|
-
get: (projectId: string, componentId: string) =>
|
|
113
|
-
`[${projectId}] Component "${componentId}"`,
|
|
114
|
-
failedGet: (projectId: string, componentId: string) =>
|
|
115
|
-
`[${projectId}] Unable to get component "${componentId}"`,
|
|
116
|
-
created: (projectId: string, componentId: string, status?: string) =>
|
|
117
|
-
`[${projectId}] Component ${status}d "${componentId}"`,
|
|
118
|
-
removed: (env: string, id: string, commit: boolean) =>
|
|
119
|
-
`[${env}] ${commit ? `Deleted` : `Will delete`} component "${id}"`,
|
|
120
|
-
failedRemove: (env: string, id: string) =>
|
|
121
|
-
`[${env}] Unable to delete component "${id}"`,
|
|
122
|
-
},
|
|
123
|
-
version: {
|
|
124
|
-
set: (env: string, versionStatus: string) =>
|
|
125
|
-
`[${env}] Content version status set to "${versionStatus}"`,
|
|
126
|
-
invalid: (versionStatus: string) =>
|
|
127
|
-
`Content version status "${versionStatus}" is not valid, allowed values are "published" or "latest".`,
|
|
128
|
-
noEnv: () =>
|
|
129
|
-
`No Contensis environment set, connect to your Contensis cloud instance using "contensis connect {cms alias}"`,
|
|
97
|
+
set: (projectId: string) =>
|
|
98
|
+
`Current project is set to ${Logger.highlightText(projectId)}`,
|
|
99
|
+
failedSet: (projectId: string) =>
|
|
100
|
+
`Project ${Logger.highlightText(projectId)} not found`,
|
|
101
|
+
tip: () =>
|
|
102
|
+
`You need to set your current working project with "set project {projectId}"`,
|
|
103
|
+
created: (env: string, id: string) =>
|
|
104
|
+
`[${env}] Created project ${Logger.highlightText(id)}`,
|
|
105
|
+
failedCreate: (env: string, id: string) =>
|
|
106
|
+
`[${env}] Unable to create project ${Logger.highlightText(id)}`,
|
|
107
|
+
updated: (env: string, id: string) =>
|
|
108
|
+
`[${env}] Updated project ${Logger.highlightText(id)}`,
|
|
109
|
+
failedUpdate: (env: string, id: string) =>
|
|
110
|
+
`[${env}] Unable to update project ${Logger.highlightText(id)}`,
|
|
130
111
|
},
|
|
131
|
-
|
|
132
|
-
|
|
112
|
+
migrate: {
|
|
113
|
+
models: {
|
|
114
|
+
result: (
|
|
115
|
+
status: keyof MigrateModelsResult['project']['contentTypes']
|
|
116
|
+
) => {
|
|
117
|
+
switch (status) {
|
|
118
|
+
case 'created':
|
|
119
|
+
case 'updated':
|
|
120
|
+
return Logger.successText;
|
|
121
|
+
case 'errors':
|
|
122
|
+
return Logger.errorText;
|
|
123
|
+
default:
|
|
124
|
+
return Logger.infoText;
|
|
125
|
+
}
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
status: (status: MigrateStatus) => {
|
|
133
129
|
switch (status) {
|
|
134
130
|
case 'no change':
|
|
135
131
|
return Logger.successText;
|
|
@@ -145,23 +141,167 @@ export const LogMessages = {
|
|
|
145
141
|
return Logger.infoText;
|
|
146
142
|
}
|
|
147
143
|
},
|
|
144
|
+
},
|
|
145
|
+
models: {
|
|
146
|
+
list: (projectId: string) =>
|
|
147
|
+
`Content models in ${Logger.highlightText(projectId)}:`,
|
|
148
|
+
noList: (projectId: string) =>
|
|
149
|
+
`[${projectId}] Cannot retrieve content models`,
|
|
150
|
+
get: (projectId: string, id: string) =>
|
|
151
|
+
`[${projectId}] Content models ${Logger.infoText(`[ ${id} ]`)}`,
|
|
152
|
+
failedGet: (projectId: string, id: string) =>
|
|
153
|
+
`[${projectId}] Unable to get content models ${Logger.highlightText(id)}`,
|
|
154
|
+
},
|
|
155
|
+
contenttypes: {
|
|
156
|
+
list: (projectId: string) =>
|
|
157
|
+
`Content types in ${Logger.highlightText(projectId)}:`,
|
|
158
|
+
get: (projectId: string, id: string) =>
|
|
159
|
+
`[${projectId}] Content type ${Logger.highlightText(id)}`,
|
|
160
|
+
failedGet: (projectId: string, id: string) =>
|
|
161
|
+
`[${projectId}] Unable to get content type ${Logger.highlightText(id)}`,
|
|
162
|
+
created: (projectId: string, id: string, status?: string) =>
|
|
163
|
+
`[${projectId}] Content type ${status}d ${Logger.highlightText(id)}`,
|
|
164
|
+
removed: (env: string, id: string, commit: boolean) =>
|
|
165
|
+
`[${env}] ${
|
|
166
|
+
commit ? `Deleted` : `Will delete`
|
|
167
|
+
} content type ${Logger.highlightText(id)}`,
|
|
168
|
+
failedRemove: (env: string, id: string) =>
|
|
169
|
+
`[${env}] Unable to delete content type ${Logger.highlightText(id)}`,
|
|
170
|
+
},
|
|
171
|
+
components: {
|
|
172
|
+
list: (projectId: string) =>
|
|
173
|
+
`Components in ${Logger.highlightText(projectId)}:`,
|
|
174
|
+
get: (projectId: string, id: string) =>
|
|
175
|
+
`[${projectId}] Component ${Logger.highlightText(id)}`,
|
|
176
|
+
failedGet: (projectId: string, id: string) =>
|
|
177
|
+
`[${projectId}] Unable to get component ${Logger.highlightText(id)}`,
|
|
178
|
+
created: (projectId: string, id: string, status?: string) =>
|
|
179
|
+
`[${projectId}] Component ${status}d ${Logger.highlightText(id)}`,
|
|
148
180
|
removed: (env: string, id: string, commit: boolean) =>
|
|
149
|
-
`[${env}] ${
|
|
181
|
+
`[${env}] ${
|
|
182
|
+
commit ? `Deleted` : `Will delete`
|
|
183
|
+
} component ${Logger.highlightText(id)}`,
|
|
150
184
|
failedRemove: (env: string, id: string) =>
|
|
151
|
-
`[${env}] Unable to delete
|
|
152
|
-
|
|
153
|
-
|
|
185
|
+
`[${env}] Unable to delete component ${Logger.highlightText(id)}`,
|
|
186
|
+
},
|
|
187
|
+
version: {
|
|
188
|
+
set: (env: string, versionStatus: string) =>
|
|
189
|
+
`[${env}] Content version status set to "${versionStatus}"`,
|
|
190
|
+
invalid: (versionStatus: string) =>
|
|
191
|
+
`Content version status "${versionStatus}" is not valid, allowed values are "published" or "latest".`,
|
|
192
|
+
noEnv: () =>
|
|
193
|
+
`No Contensis environment set, connect to your Contensis cloud instance using "contensis connect {cms alias}"`,
|
|
194
|
+
},
|
|
195
|
+
entries: {
|
|
196
|
+
imported: (env: string, commit: boolean, count: number) =>
|
|
197
|
+
`[${env}] ${commit ? `Imported` : `Will import`} ${count} entries`,
|
|
198
|
+
failedImport: (env: string) => `[${env}] Unable to import entries`,
|
|
199
|
+
removed: (env: string, commit: boolean) =>
|
|
200
|
+
`[${env}] ${commit ? `Deleted` : `Will delete`} entries`,
|
|
201
|
+
failedRemove: (env: string) => `[${env}] Unable to delete entries`,
|
|
202
|
+
notFound: (env: string) => `[${env}] Entries were not found`,
|
|
203
|
+
commitTip: () => `Add --commit flag to commit the previewed changes`,
|
|
154
204
|
},
|
|
155
205
|
keys: {
|
|
156
206
|
list: (env: string) => `[${env}] API keys:`,
|
|
157
|
-
noList: (env: string) => `[${env}] Cannot retrieve API`,
|
|
207
|
+
noList: (env: string) => `[${env}] Cannot retrieve API keys`,
|
|
208
|
+
created: (env: string, name: string) =>
|
|
209
|
+
`[${env}] Created API key ${Logger.highlightText(name)}`,
|
|
210
|
+
tip: () =>
|
|
211
|
+
`Assign your new key to a role with "set role assignments", or create a new role with "create role"`,
|
|
212
|
+
failedCreate: (env: string, name: string) =>
|
|
213
|
+
`[${env}] Unable to create API key ${Logger.highlightText(name)}`,
|
|
214
|
+
removed: (env: string, id: string) =>
|
|
215
|
+
`[${env}] Deleted API key ${Logger.highlightText(id)}`,
|
|
216
|
+
failedRemove: (env: string, id: string) =>
|
|
217
|
+
`[${env}] Unable to delete API key ${Logger.highlightText(id)}`,
|
|
218
|
+
},
|
|
219
|
+
proxies: {
|
|
220
|
+
list: (env: string, projectId: string | undefined) =>
|
|
221
|
+
`[${env}] Retrieved proxies in project ${projectId}:`,
|
|
222
|
+
noList: (env: string, projectId: string | undefined) =>
|
|
223
|
+
`[${env}] Cannot retrieve proxies in project ${projectId}`,
|
|
224
|
+
// noneExist: () => `Create a role with "create renderer"`,
|
|
225
|
+
failedGet: (env: string, name: string, projectId: string) =>
|
|
226
|
+
`[${env}] Unable to find proxy ${Logger.highlightText(
|
|
227
|
+
name
|
|
228
|
+
)} in project ${projectId}`,
|
|
229
|
+
created: (env: string, name: string, projectId: string) =>
|
|
230
|
+
`[${env}] Created proxy ${Logger.highlightText(
|
|
231
|
+
name
|
|
232
|
+
)} in project ${projectId}\n`,
|
|
233
|
+
failedCreate: (env: string, name: string, projectId: string) =>
|
|
234
|
+
`[${env}] Unable to create proxy ${Logger.highlightText(
|
|
235
|
+
name
|
|
236
|
+
)} in project ${projectId}`,
|
|
237
|
+
setPayload: () => `Updating proxy with details\n`,
|
|
238
|
+
set: () => `Succesfully updated proxy\n`,
|
|
239
|
+
failedSet: (env: string, name: string, projectId: string) =>
|
|
240
|
+
`[${env}] Unable to update proxy ${Logger.highlightText(
|
|
241
|
+
name
|
|
242
|
+
)} in project ${projectId}`,
|
|
243
|
+
removed: (env: string, id: string, projectId: string) =>
|
|
244
|
+
`[${env}] Deleted proxy ${Logger.highlightText(
|
|
245
|
+
id
|
|
246
|
+
)} in project ${projectId}\n`,
|
|
247
|
+
failedRemove: (env: string, id: string, projectId: string) =>
|
|
248
|
+
`[${env}] Unable to delete proxy ${Logger.highlightText(
|
|
249
|
+
id
|
|
250
|
+
)} in project ${projectId}`,
|
|
251
|
+
},
|
|
252
|
+
renderers: {
|
|
253
|
+
list: (env: string, projectId: string | undefined) =>
|
|
254
|
+
`[${env}] Retrieved renderers in project ${projectId}:`,
|
|
255
|
+
noList: (env: string, projectId: string | undefined) =>
|
|
256
|
+
`[${env}] Cannot retrieve renderers in project ${projectId}`,
|
|
257
|
+
// noneExist: () => `Create a role with "create renderer"`,
|
|
258
|
+
failedGet: (env: string, name: string, projectId: string) =>
|
|
259
|
+
`[${env}] Unable to find renderer ${Logger.highlightText(
|
|
260
|
+
name
|
|
261
|
+
)} in project ${projectId}`,
|
|
262
|
+
created: (env: string, name: string, projectId: string) =>
|
|
263
|
+
`[${env}] Created renderer ${Logger.highlightText(
|
|
264
|
+
name
|
|
265
|
+
)} in project ${projectId}\n`,
|
|
266
|
+
failedCreate: (env: string, name: string, projectId: string) =>
|
|
267
|
+
`[${env}] Unable to create renderer ${Logger.highlightText(
|
|
268
|
+
name
|
|
269
|
+
)} in project ${projectId}`,
|
|
270
|
+
setPayload: () => `Updating renderer with details\n`,
|
|
271
|
+
set: () => `Succesfully updated renderer\n`,
|
|
272
|
+
failedSet: (env: string, name: string, projectId: string) =>
|
|
273
|
+
`[${env}] Unable to update renderer ${Logger.highlightText(
|
|
274
|
+
name
|
|
275
|
+
)} in project ${projectId}`,
|
|
276
|
+
removed: (env: string, id: string, projectId: string) =>
|
|
277
|
+
`[${env}] Deleted renderer ${Logger.highlightText(
|
|
278
|
+
id
|
|
279
|
+
)} in project ${projectId}\n`,
|
|
280
|
+
failedRemove: (env: string, id: string, projectId: string) =>
|
|
281
|
+
`[${env}] Unable to delete renderer ${Logger.highlightText(
|
|
282
|
+
id
|
|
283
|
+
)} in project ${projectId}`,
|
|
284
|
+
},
|
|
285
|
+
roles: {
|
|
286
|
+
list: (env: string) => `[${env}] Retrieved roles`,
|
|
287
|
+
noList: (env: string) => `[${env}] Cannot retrieve roles`,
|
|
288
|
+
noneExist: () => `Create a role with "create role"`,
|
|
289
|
+
failedGet: (env: string, name: string) =>
|
|
290
|
+
`[${env}] Unable to find role ${Logger.highlightText(name)}`,
|
|
158
291
|
created: (env: string, name: string) =>
|
|
159
|
-
`[${env}] Created
|
|
292
|
+
`[${env}] Created role ${Logger.highlightText(name)}\n`,
|
|
293
|
+
tip: () =>
|
|
294
|
+
`Give access to your role with "set role assignments", allow your role to do things with "set role permissions"`,
|
|
160
295
|
failedCreate: (env: string, name: string) =>
|
|
161
|
-
`[${env}] Unable to create
|
|
162
|
-
|
|
296
|
+
`[${env}] Unable to create role ${Logger.highlightText(name)}`,
|
|
297
|
+
setPayload: () => `Updating role with details\n`,
|
|
298
|
+
set: () => `Succesfully updated role\n`,
|
|
299
|
+
failedSet: (env: string, name: string) =>
|
|
300
|
+
`[${env}] Unable to update role ${Logger.highlightText(name)}`,
|
|
301
|
+
removed: (env: string, id: string) =>
|
|
302
|
+
`[${env}] Deleted role ${Logger.highlightText(id)}\n`,
|
|
163
303
|
failedRemove: (env: string, id: string) =>
|
|
164
|
-
`[${env}] Unable to delete
|
|
304
|
+
`[${env}] Unable to delete role ${Logger.highlightText(id)}`,
|
|
165
305
|
},
|
|
166
306
|
blocks: {
|
|
167
307
|
runningStatus: (status: BlockRunningStatus | 'broken') => {
|
|
@@ -180,32 +320,95 @@ export const LogMessages = {
|
|
|
180
320
|
return Logger.infoText(status);
|
|
181
321
|
}
|
|
182
322
|
},
|
|
183
|
-
get: (env: string) =>
|
|
323
|
+
get: (id: string, env: string, projectId?: string) =>
|
|
324
|
+
`[${env}] Block ${id} in project ${projectId}:`,
|
|
184
325
|
list: (env: string, projectId?: string) =>
|
|
185
326
|
`[${env}] Blocks in project ${projectId}:`,
|
|
186
327
|
noList: (env: string, projectId?: string) =>
|
|
187
328
|
`[${env}] Cannot retrieve blocks in project ${projectId}`,
|
|
329
|
+
getLogs: (id: string, branch: string, env: string, projectId?: string) =>
|
|
330
|
+
`[${env}] Requesting logs from block ${Logger.highlightText(
|
|
331
|
+
id
|
|
332
|
+
)} in branch ${branch} in project ${projectId}`,
|
|
333
|
+
failedGetLogs: (id: string, env: string, projectId?: string) =>
|
|
334
|
+
`[${env}] Unable to fetch block logs for ${Logger.highlightText(
|
|
335
|
+
id
|
|
336
|
+
)} in project ${projectId}`,
|
|
188
337
|
tryPush: (id: string, branch: string, env: string, projectId?: string) =>
|
|
189
|
-
`[${env}] Request to push block
|
|
338
|
+
`[${env}] Request to push block ${Logger.highlightText(
|
|
339
|
+
id
|
|
340
|
+
)} in branch ${branch} in project ${projectId}`,
|
|
190
341
|
pushed: (id: string, branch: string, env: string, projectId?: string) =>
|
|
191
|
-
`[${env}] Pushed block
|
|
342
|
+
`[${env}] Pushed block ${Logger.highlightText(
|
|
343
|
+
id
|
|
344
|
+
)} in branch ${branch} in project ${projectId}`,
|
|
192
345
|
failedPush: (id: string, env: string, projectId?: string) =>
|
|
193
|
-
`[${env}] Unable to push block
|
|
346
|
+
`[${env}] Unable to push block ${Logger.highlightText(
|
|
347
|
+
id
|
|
348
|
+
)} in project ${projectId}`,
|
|
349
|
+
latestVersion: (
|
|
350
|
+
version: string,
|
|
351
|
+
id: string,
|
|
352
|
+
env: string,
|
|
353
|
+
projectId?: string
|
|
354
|
+
) =>
|
|
355
|
+
`[${env}] Found latest block version ${Logger.highlightText(
|
|
356
|
+
id
|
|
357
|
+
)} in project ${projectId} ${Logger.highlightText(version)}`,
|
|
358
|
+
failedParsingVersion: () =>
|
|
359
|
+
`Did not find a "version.versionNo" in response`,
|
|
360
|
+
actionComplete: (
|
|
361
|
+
action: BlockActionType,
|
|
362
|
+
id: string,
|
|
363
|
+
env: string,
|
|
364
|
+
projectId?: string
|
|
365
|
+
) =>
|
|
366
|
+
`[${env}] Action ${Logger.highlightText(
|
|
367
|
+
action
|
|
368
|
+
)} on ${Logger.highlightText(
|
|
369
|
+
id
|
|
370
|
+
)} in project ${projectId} requested successfully`,
|
|
371
|
+
actionFailed: (
|
|
372
|
+
action: BlockActionType,
|
|
373
|
+
id: string,
|
|
374
|
+
env: string,
|
|
375
|
+
projectId?: string
|
|
376
|
+
) =>
|
|
377
|
+
`[${env}] Problem executing ${action} on block ${Logger.highlightText(
|
|
378
|
+
id
|
|
379
|
+
)} in project ${projectId}`,
|
|
194
380
|
deleted: (id: string, env: string, projectId?: string) =>
|
|
195
|
-
`[${env}] Deleted block
|
|
381
|
+
`[${env}] Deleted block ${Logger.highlightText(
|
|
382
|
+
id
|
|
383
|
+
)} in project ${projectId}`,
|
|
196
384
|
failedDelete: (id: string, env: string, projectId?: string) =>
|
|
197
|
-
`[${env}] Unable to delete block
|
|
385
|
+
`[${env}] Unable to delete block ${Logger.highlightText(
|
|
386
|
+
id
|
|
387
|
+
)} in project ${projectId}`,
|
|
388
|
+
stopFollow: (id: string, env: string, projectId?: string) =>
|
|
389
|
+
`[${env}]\n\n 👌 stop fetching new ${Logger.highlightText(
|
|
390
|
+
id
|
|
391
|
+
)} logs in project ${projectId}`,
|
|
392
|
+
timeoutFollow: (id: string, env: string, projectId?: string) =>
|
|
393
|
+
`[${env}]\n\n 🤏 pausing fetching new ${Logger.highlightText(
|
|
394
|
+
id
|
|
395
|
+
)} logs in project ${projectId} due to too many requests`,
|
|
198
396
|
},
|
|
199
397
|
webhooks: {
|
|
200
398
|
list: (env: string) => `[${env}] Webhook subscriptions:`,
|
|
201
399
|
noList: (env: string) => `[${env}] Cannot retrieve webhook subscriptions`,
|
|
400
|
+
noneExist: () => `No webhook subscriptions exist`,
|
|
202
401
|
created: (env: string, name: string) =>
|
|
203
|
-
`[${env}] Created Webhook subscription
|
|
402
|
+
`[${env}] Created Webhook subscription ${Logger.highlightText(name)}`,
|
|
204
403
|
failedCreate: (env: string, name: string) =>
|
|
205
|
-
`[${env}] Unable to create Webhook subscription
|
|
404
|
+
`[${env}] Unable to create Webhook subscription ${Logger.highlightText(
|
|
405
|
+
name
|
|
406
|
+
)}`,
|
|
206
407
|
deleted: (env: string, id: string) =>
|
|
207
|
-
`[${env}] Deleted Webhook subscription
|
|
408
|
+
`[${env}] Deleted Webhook subscription ${Logger.highlightText(id)}`,
|
|
208
409
|
failedDelete: (env: string, id: string) =>
|
|
209
|
-
`[${env}] Unable to delete Webhook subscription
|
|
410
|
+
`[${env}] Unable to delete Webhook subscription ${Logger.highlightText(
|
|
411
|
+
id
|
|
412
|
+
)}`,
|
|
210
413
|
},
|
|
211
414
|
};
|
|
@@ -10,6 +10,7 @@ interface Remarks {
|
|
|
10
10
|
|
|
11
11
|
class CredentialProvider {
|
|
12
12
|
private serviceId: string;
|
|
13
|
+
private keytar!: typeof keytar;
|
|
13
14
|
private userId: string = '';
|
|
14
15
|
private passwordFallback?: string;
|
|
15
16
|
|
|
@@ -29,9 +30,34 @@ class CredentialProvider {
|
|
|
29
30
|
this.passwordFallback = passwordFallback;
|
|
30
31
|
}
|
|
31
32
|
|
|
33
|
+
Import = async () => {
|
|
34
|
+
try {
|
|
35
|
+
this.keytar = (await import('keytar')).default;
|
|
36
|
+
} catch (ex) {
|
|
37
|
+
this.keytar = {
|
|
38
|
+
findCredentials: async () => {
|
|
39
|
+
throw ex;
|
|
40
|
+
},
|
|
41
|
+
getPassword: async () => {
|
|
42
|
+
throw ex;
|
|
43
|
+
},
|
|
44
|
+
findPassword: async () => {
|
|
45
|
+
throw ex;
|
|
46
|
+
},
|
|
47
|
+
setPassword: async () => {
|
|
48
|
+
throw ex;
|
|
49
|
+
},
|
|
50
|
+
deletePassword: async () => {
|
|
51
|
+
throw ex;
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
32
57
|
Init = async (): Promise<[Error, CredentialProvider]> => {
|
|
58
|
+
await this.Import();
|
|
33
59
|
const [err, stored] = (await to(
|
|
34
|
-
keytar.findCredentials(this.serviceId)
|
|
60
|
+
this.keytar.findCredentials(this.serviceId)
|
|
35
61
|
)) as [
|
|
36
62
|
Error,
|
|
37
63
|
{
|
|
@@ -40,8 +66,10 @@ class CredentialProvider {
|
|
|
40
66
|
}[]
|
|
41
67
|
];
|
|
42
68
|
if (err && this.passwordFallback) {
|
|
43
|
-
this.current = {
|
|
44
|
-
|
|
69
|
+
this.current = {
|
|
70
|
+
account: this.userId,
|
|
71
|
+
password: this.passwordFallback,
|
|
72
|
+
};
|
|
45
73
|
}
|
|
46
74
|
if (!err) {
|
|
47
75
|
this.remarks = { secure: true };
|
|
@@ -49,16 +77,21 @@ class CredentialProvider {
|
|
|
49
77
|
stored?.find(
|
|
50
78
|
u => u?.account?.toLowerCase() === this.userId.toLowerCase()
|
|
51
79
|
) || null;
|
|
80
|
+
|
|
81
|
+
if (!this.current && this.passwordFallback) {
|
|
82
|
+
await this.Save(this.passwordFallback);
|
|
83
|
+
return await this.Init();
|
|
84
|
+
}
|
|
52
85
|
}
|
|
53
86
|
return [err, this];
|
|
54
87
|
};
|
|
55
88
|
|
|
56
89
|
Save = async (password: string) => {
|
|
57
90
|
const [err] = await to(
|
|
58
|
-
keytar.setPassword(this.serviceId, this.userId, password)
|
|
91
|
+
this.keytar.setPassword(this.serviceId, this.userId, password)
|
|
59
92
|
);
|
|
60
93
|
|
|
61
|
-
if (!err) Logger.info(`${this.serviceId} - credentials saved`);
|
|
94
|
+
// if (!err) Logger.info(`${this.serviceId} - credentials saved`);
|
|
62
95
|
return err && !this.passwordFallback ? err : true;
|
|
63
96
|
};
|
|
64
97
|
|
|
@@ -68,7 +101,7 @@ class CredentialProvider {
|
|
|
68
101
|
return true;
|
|
69
102
|
} else {
|
|
70
103
|
const [err] = await to(
|
|
71
|
-
keytar.deletePassword(this.serviceId, this.userId)
|
|
104
|
+
this.keytar.deletePassword(this.serviceId, this.userId)
|
|
72
105
|
);
|
|
73
106
|
|
|
74
107
|
Logger.warning(`${this.serviceId} - invalid credentials removed`);
|
|
@@ -3,7 +3,8 @@ import path from 'path';
|
|
|
3
3
|
import clone from 'lodash/cloneDeep';
|
|
4
4
|
import mergeWith from 'lodash/mergeWith';
|
|
5
5
|
import unionBy from 'lodash/unionBy';
|
|
6
|
-
import {
|
|
6
|
+
import { appRootDir } from './file-provider';
|
|
7
|
+
import { isJson, tryParse } from '~/util';
|
|
7
8
|
import { Logger } from '~/util/logger';
|
|
8
9
|
|
|
9
10
|
class SessionCacheProvider {
|
|
@@ -11,7 +12,7 @@ class SessionCacheProvider {
|
|
|
11
12
|
private cache = {} as SessionCache;
|
|
12
13
|
|
|
13
14
|
constructor() {
|
|
14
|
-
this.localFilePath = path.join(
|
|
15
|
+
this.localFilePath = path.join(appRootDir, 'environments.json');
|
|
15
16
|
this.cache = {
|
|
16
17
|
currentTimestamp: new Date().toISOString(),
|
|
17
18
|
environments: {},
|
|
@@ -69,6 +70,32 @@ class SessionCacheProvider {
|
|
|
69
70
|
}
|
|
70
71
|
return this.Get();
|
|
71
72
|
};
|
|
73
|
+
|
|
74
|
+
UpdateEnv = (
|
|
75
|
+
updateContent: Partial<EnvironmentCache>,
|
|
76
|
+
env = this.cache.currentEnvironment,
|
|
77
|
+
setCurrentEnv = true
|
|
78
|
+
) => {
|
|
79
|
+
try {
|
|
80
|
+
const environment = this.cache.environments[env || ''];
|
|
81
|
+
|
|
82
|
+
this.cache.environments[env || ''] = {
|
|
83
|
+
...environment,
|
|
84
|
+
...updateContent,
|
|
85
|
+
};
|
|
86
|
+
this.Update({
|
|
87
|
+
currentEnvironment: setCurrentEnv ? env : this.cache.currentEnvironment,
|
|
88
|
+
environments: this.cache.environments,
|
|
89
|
+
});
|
|
90
|
+
} catch (ex: any) {
|
|
91
|
+
// Problem merging cache data for update
|
|
92
|
+
Logger.error(
|
|
93
|
+
`Problem updating environment "${env}" in environments.json`
|
|
94
|
+
);
|
|
95
|
+
Logger.error(ex);
|
|
96
|
+
}
|
|
97
|
+
return this.Get();
|
|
98
|
+
};
|
|
72
99
|
}
|
|
73
100
|
|
|
74
101
|
export default SessionCacheProvider;
|
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
|
+
import { homedir } from 'os';
|
|
2
3
|
import path from 'path';
|
|
3
|
-
import { path as appRoot } from 'app-root-path';
|
|
4
4
|
import { tryParse } from '~/util';
|
|
5
5
|
|
|
6
|
+
const userHomeDir = homedir();
|
|
7
|
+
|
|
8
|
+
export const appRootDir =
|
|
9
|
+
process.env.CONTAINER_CONTEXT === 'true'
|
|
10
|
+
? process.cwd()
|
|
11
|
+
: path.join(userHomeDir, '.contensis/');
|
|
12
|
+
|
|
6
13
|
export const readJsonFile = <T>(filePath: string) => {
|
|
7
14
|
const file = readFile(filePath);
|
|
8
15
|
if (file) return tryParse(file) as T | string;
|
|
@@ -42,8 +49,8 @@ export const removeFile = (filePath: string) => {
|
|
|
42
49
|
};
|
|
43
50
|
|
|
44
51
|
export const moveFile = (file: string, fromPath: string, toPath: string) => {
|
|
45
|
-
const from = path.join(
|
|
46
|
-
const to = path.join(
|
|
52
|
+
const from = path.join(appRootDir, `${fromPath}${file}`);
|
|
53
|
+
const to = path.join(appRootDir, `${toPath}${file}`);
|
|
47
54
|
if (fs.existsSync(from)) {
|
|
48
55
|
checkDir(toPath);
|
|
49
56
|
// if (!fs.existsSync(toPath)) fs.mkdirSync(toPath, { recursive: true });
|
|
@@ -69,4 +76,5 @@ export const checkDir = (filePath: string) => {
|
|
|
69
76
|
fs.mkdirSync(directoryPath, { recursive: true });
|
|
70
77
|
};
|
|
71
78
|
|
|
72
|
-
export const localPath = (filePath: string) =>
|
|
79
|
+
export const localPath = (filePath: string) =>
|
|
80
|
+
path.isAbsolute(filePath) ? filePath : path.join(appRootDir, filePath);
|