-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathindex.ts
More file actions
45 lines (37 loc) · 1.43 KB
/
index.ts
File metadata and controls
45 lines (37 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { keys, replace, split } from 'lodash';
import { RANDOM_PATTERN, REGISTRY, GITHUB_REGISTRY } from '../constant';
import Credential from '@serverless-devs/credential';
import SecretManager from '@serverless-devs/secret';
export { default as getInputs } from './get-inputs';
export const tryfun = async (fn: Function, ...args: any[]) => {
try {
return await fn(...args);
} catch (ex) {}
};
export const getUrlWithLatest = (name: string) => {
if (REGISTRY.CUSTOM_URL === GITHUB_REGISTRY) {
if (split(name, '/').length === 1) {
return `${REGISTRY.CUSTOM_URL}/devsapp/${name}`;
}
return `${REGISTRY.CUSTOM_URL}/${name}`;
}
return `${REGISTRY.V3}/packages/${name}/release/latest`
};
export const getUrlWithVersion = (name: string, versionId: string) => `${REGISTRY.V3}/packages/${name}/release/tags/${encodeURIComponent(versionId)}`;
export const randomId = () => Math.random().toString(36).substring(2, 6);
export const getAllCredential = async ({ logger }: any) => {
const c = new Credential({ logger });
return keys(c.getAll());
};
export const getDefaultValue = (value: any) => {
if (typeof value !== 'string') return;
return replace(value, RANDOM_PATTERN, randomId());
};
export const getNumberDefaultValue = (value: any) => {
if (typeof value !== 'number') return;
return value;
};
export const getSecretManager = () => {
const secretManager = SecretManager.getInstance();
return secretManager;
};