forest-cli 3.0.10 → 3.0.12-beta.1
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/bin/run +1 -1
- package/oclif.manifest.json +1 -1
- package/package.json +17 -8
- package/src/abstract-authenticated-command.js +0 -46
- package/src/abstract-command.js +0 -27
- package/src/commands/branch.js +0 -136
- package/src/commands/deploy.js +0 -90
- package/src/commands/environments/copy-layout.js +0 -116
- package/src/commands/environments/create.js +0 -62
- package/src/commands/environments/delete.js +0 -81
- package/src/commands/environments/get.js +0 -48
- package/src/commands/environments/reset.js +0 -76
- package/src/commands/environments/update.js +0 -46
- package/src/commands/environments.js +0 -41
- package/src/commands/init.js +0 -169
- package/src/commands/login.js +0 -34
- package/src/commands/logout.js +0 -18
- package/src/commands/projects/create.js +0 -262
- package/src/commands/projects/get.js +0 -53
- package/src/commands/projects.js +0 -36
- package/src/commands/push.js +0 -75
- package/src/commands/schema/apply.js +0 -140
- package/src/commands/schema/update.js +0 -70
- package/src/commands/set-origin.js +0 -59
- package/src/commands/switch.js +0 -117
- package/src/commands/user.js +0 -44
- package/src/context/command-project-create-plan.js +0 -11
- package/src/context/command-projects-common-plan.js +0 -65
- package/src/context/command-schema-update-command-plan.js +0 -4
- package/src/context/dependencies-plan.js +0 -21
- package/src/context/env-plan.js +0 -27
- package/src/context/plan.js +0 -12
- package/src/context/process-plan.js +0 -3
- package/src/context/renderers-plan.js +0 -7
- package/src/context/serializers-plan.js +0 -8
- package/src/context/services-plan.js +0 -8
- package/src/context/static.js +0 -19
- package/src/context/utils-plan.js +0 -7
- package/src/deserializers/api-error.js +0 -21
- package/src/deserializers/application-token.js +0 -15
- package/src/deserializers/branch.js +0 -8
- package/src/deserializers/environment.js +0 -5
- package/src/deserializers/job.js +0 -5
- package/src/deserializers/project.js +0 -11
- package/src/errors/application-error.js +0 -9
- package/src/errors/application-token/unable-to-create-application-token-error.js +0 -16
- package/src/errors/database/empty-database-error.js +0 -5
- package/src/errors/dumper/incompatible-liana-for-update-error.js +0 -16
- package/src/errors/dumper/invalid-forest-cli-project-structure-error.js +0 -16
- package/src/errors/forest-cli-error.js +0 -32
- package/src/index.js +0 -1
- package/src/renderers/branches.js +0 -45
- package/src/renderers/defaults.js +0 -19
- package/src/renderers/environment.js +0 -51
- package/src/renderers/environments.js +0 -51
- package/src/renderers/project.js +0 -45
- package/src/renderers/projects.js +0 -45
- package/src/serializers/application-token.js +0 -11
- package/src/serializers/deployment-request.js +0 -5
- package/src/serializers/environment.js +0 -20
- package/src/serializers/job.js +0 -5
- package/src/serializers/project.js +0 -17
- package/src/serializers/schema.js +0 -116
- package/src/services/api.js +0 -110
- package/src/services/apimap-sorter.js +0 -104
- package/src/services/application-token.js +0 -56
- package/src/services/ask-for-environment.js +0 -24
- package/src/services/authenticator.js +0 -187
- package/src/services/branch-manager.js +0 -169
- package/src/services/dumper/dumper.js +0 -503
- package/src/services/dumper/handlebars/helpers/equal.js +0 -3
- package/src/services/dumper/handlebars/helpers/indent.js +0 -3
- package/src/services/dumper/handlebars/helpers/is-array.js +0 -3
- package/src/services/dumper/handlebars/helpers/is-object.js +0 -3
- package/src/services/dumper/handlebars/helpers/sum.js +0 -3
- package/src/services/dumper/handlebars/helpers/wrap-quotes.js +0 -7
- package/src/services/dumper/handlebars/loader.js +0 -10
- package/src/services/dumper/handlebars/partials/render-nested.js +0 -27
- package/src/services/dumper/templates/app/Dockerfile.hbs +0 -6
- package/src/services/dumper/templates/app/app.hbs +0 -79
- package/src/services/dumper/templates/app/config/databases.hbs +0 -49
- package/src/services/dumper/templates/app/docker-compose.hbs +0 -33
- package/src/services/dumper/templates/app/dockerignore.hbs +0 -3
- package/src/services/dumper/templates/app/env.hbs +0 -20
- package/src/services/dumper/templates/app/forest/collection.hbs +0 -13
- package/src/services/dumper/templates/app/gitignore.hbs +0 -3
- package/src/services/dumper/templates/app/middlewares/forestadmin.hbs +0 -21
- package/src/services/dumper/templates/app/middlewares/welcome.hbs +0 -7
- package/src/services/dumper/templates/app/models/index.hbs +0 -56
- package/src/services/dumper/templates/app/models/mongo-model.hbs +0 -16
- package/src/services/dumper/templates/app/models/sequelize-model.hbs +0 -48
- package/src/services/dumper/templates/app/public/favicon.png +0 -0
- package/src/services/dumper/templates/app/routes/route.hbs +0 -61
- package/src/services/dumper/templates/app/server.hbs +0 -56
- package/src/services/dumper/templates/app/views/index.hbs +0 -73
- package/src/services/environment-manager.js +0 -139
- package/src/services/init-manager.js +0 -183
- package/src/services/job-state-checker.js +0 -57
- package/src/services/logger.js +0 -125
- package/src/services/oidc/authenticator.js +0 -109
- package/src/services/oidc/error.js +0 -32
- package/src/services/project-manager.js +0 -89
- package/src/services/projects/create/command-generate-config-getter.js +0 -61
- package/src/services/projects/create/project-creator.js +0 -89
- package/src/services/prompter/abstract-prompter.js +0 -13
- package/src/services/prompter/application-prompts.js +0 -63
- package/src/services/prompter/database-prompts.js +0 -208
- package/src/services/prompter/general-prompter.js +0 -61
- package/src/services/prompter/project-prompts.js +0 -47
- package/src/services/prompter/prompter-error.js +0 -10
- package/src/services/schema/schema-service.js +0 -154
- package/src/services/schema/update/analyzer/database-analyzer.js +0 -64
- package/src/services/schema/update/analyzer/mongo-collections-analyzer.js +0 -344
- package/src/services/schema/update/analyzer/mongo-embedded-analyzer.js +0 -226
- package/src/services/schema/update/analyzer/mongo-hasmany-analyzer.js +0 -55
- package/src/services/schema/update/analyzer/mongo-references-analyzer.js +0 -51
- package/src/services/schema/update/analyzer/mysql-table-constraints-getter.js +0 -59
- package/src/services/schema/update/analyzer/sequelize-column-type-getter.js +0 -147
- package/src/services/schema/update/analyzer/sequelize-default-value.js +0 -122
- package/src/services/schema/update/analyzer/sequelize-table-constraints-getter.js +0 -298
- package/src/services/schema/update/analyzer/sequelize-tables-analyzer.js +0 -529
- package/src/services/schema/update/database.js +0 -160
- package/src/services/schema-sender.js +0 -55
- package/src/services/spinner.js +0 -130
- package/src/services/with-current-project.js +0 -41
- package/src/utils/database-url.js +0 -33
- package/src/utils/directory-existence-checker.js +0 -17
- package/src/utils/error-handler.js +0 -63
- package/src/utils/error.js +0 -21
- package/src/utils/event-sender.js +0 -80
- package/src/utils/fields.js +0 -14
- package/src/utils/key-generator.js +0 -18
- package/src/utils/messages.js +0 -7
- package/src/utils/mongo-collections.js +0 -35
- package/src/utils/mongo-primitive-type.js +0 -44
- package/src/utils/strings.js +0 -49
- package/src/utils/terminator.js +0 -38
- package/src/utils/to-valid-package-name.js +0 -24
|
@@ -1,187 +0,0 @@
|
|
|
1
|
-
const ApplicationError = require('../errors/application-error');
|
|
2
|
-
const { ERROR_UNEXPECTED } = require('../utils/messages');
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* @class
|
|
6
|
-
* @param {import('../context/plan').Context} context
|
|
7
|
-
*/
|
|
8
|
-
function Authenticator({
|
|
9
|
-
logger, api, chalk, inquirer, jwtDecode, fs, joi, env,
|
|
10
|
-
oidcAuthenticator, applicationTokenService, mkdirp,
|
|
11
|
-
}) {
|
|
12
|
-
/**
|
|
13
|
-
* @param {string?} path
|
|
14
|
-
* @returns {string|null}
|
|
15
|
-
*/
|
|
16
|
-
this.getAuthToken = (path = env.TOKEN_PATH) => {
|
|
17
|
-
const paths = [
|
|
18
|
-
`${path}/.forest.d/.forestrc`,
|
|
19
|
-
`${path}/.forestrc`,
|
|
20
|
-
`${path}/.lumberrc`,
|
|
21
|
-
];
|
|
22
|
-
for (let i = 0; i < paths.length; i += 1) {
|
|
23
|
-
const token = this.getVerifiedToken(paths[i]);
|
|
24
|
-
if (token) return token;
|
|
25
|
-
}
|
|
26
|
-
return null;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
this.getVerifiedToken = (path) => {
|
|
30
|
-
const token = this.readAuthTokenFrom(path);
|
|
31
|
-
return token && this.verify(token);
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
this.readAuthTokenFrom = (path) => {
|
|
35
|
-
try {
|
|
36
|
-
return fs.readFileSync(path, 'utf8');
|
|
37
|
-
} catch (e) {
|
|
38
|
-
return null;
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
this.saveToken = async (token) => {
|
|
43
|
-
const path = `${env.TOKEN_PATH}/.forest.d`;
|
|
44
|
-
await mkdirp(path);
|
|
45
|
-
const forestrcPath = `${path}/.forestrc`;
|
|
46
|
-
fs.writeFileSync(forestrcPath, token);
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
this.verify = (token) => {
|
|
50
|
-
if (!token) return null;
|
|
51
|
-
let decodedToken;
|
|
52
|
-
try {
|
|
53
|
-
decodedToken = jwtDecode(token);
|
|
54
|
-
} catch (error) {
|
|
55
|
-
return null;
|
|
56
|
-
}
|
|
57
|
-
const nowInSeconds = Date.now().valueOf() / 1000;
|
|
58
|
-
if (!decodedToken.exp || nowInSeconds < decodedToken.exp) {
|
|
59
|
-
return token;
|
|
60
|
-
}
|
|
61
|
-
return null;
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
this.validateToken = (token) => !!this.verify(token)
|
|
65
|
-
|| 'Invalid token. Please enter your authentication token.';
|
|
66
|
-
|
|
67
|
-
this.logout = async (opts = {}) => {
|
|
68
|
-
const basePath = env.TOKEN_PATH;
|
|
69
|
-
|
|
70
|
-
const pathForestrc = `${basePath}/.forestrc`;
|
|
71
|
-
const forestToken = this.getVerifiedToken(pathForestrc);
|
|
72
|
-
if (forestToken) {
|
|
73
|
-
fs.unlinkSync(pathForestrc);
|
|
74
|
-
await applicationTokenService.deleteApplicationToken(forestToken);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
const pathForestForestrc = `${basePath}/.forest.d/.forestrc`;
|
|
78
|
-
const forestForestToken = this.getVerifiedToken(pathForestForestrc);
|
|
79
|
-
if (forestForestToken) {
|
|
80
|
-
fs.unlinkSync(pathForestForestrc);
|
|
81
|
-
await applicationTokenService.deleteApplicationToken(forestForestToken);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
if (opts.log) {
|
|
85
|
-
const pathLumberrc = `${basePath}/.lumberrc`;
|
|
86
|
-
const isLumberLoggedIn = this.getVerifiedToken(pathLumberrc);
|
|
87
|
-
if (isLumberLoggedIn) {
|
|
88
|
-
logger.info('You cannot be logged out with this command. Please use "lumber logout" command.');
|
|
89
|
-
} else {
|
|
90
|
-
logger.info(chalk.green('You are logged out.'));
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
this.tryLogin = async (config) => {
|
|
96
|
-
await this.logout({ log: false });
|
|
97
|
-
try {
|
|
98
|
-
const token = await this.login(config);
|
|
99
|
-
await this.saveToken(token);
|
|
100
|
-
logger.info('Login successful');
|
|
101
|
-
} catch (error) {
|
|
102
|
-
const message = error instanceof ApplicationError
|
|
103
|
-
? error.message
|
|
104
|
-
: `${ERROR_UNEXPECTED} ${chalk.red(error)}`;
|
|
105
|
-
logger.error(message);
|
|
106
|
-
}
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* @param {{
|
|
111
|
-
* email: string;
|
|
112
|
-
* password: string;
|
|
113
|
-
* token: string;
|
|
114
|
-
* }} params
|
|
115
|
-
* @returns {Promise<string>}
|
|
116
|
-
*/
|
|
117
|
-
this.login = async ({ email, password, token }) => {
|
|
118
|
-
if (token !== undefined && typeof token === 'string' && !token.trim()) {
|
|
119
|
-
throw new ApplicationError('The provided token is empty. Please provide a valid token.');
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
if (!password && !token) {
|
|
123
|
-
const sessionToken = await oidcAuthenticator.authenticate();
|
|
124
|
-
return applicationTokenService.generateApplicationToken(sessionToken);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
if (email) {
|
|
128
|
-
const validationResult = await this.validateEmail(email);
|
|
129
|
-
if (validationResult !== true) {
|
|
130
|
-
throw new ApplicationError(validationResult);
|
|
131
|
-
}
|
|
132
|
-
} else email = await this.promptEmail();
|
|
133
|
-
|
|
134
|
-
if (token) {
|
|
135
|
-
return this.loginWithToken(token);
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
try {
|
|
139
|
-
return await this.loginWithPassword(email, password);
|
|
140
|
-
} catch (e) {
|
|
141
|
-
if (e.message === 'Unauthorized') {
|
|
142
|
-
throw new ApplicationError('Incorrect email or password.');
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
throw e;
|
|
146
|
-
}
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
this.loginWithToken = (token) => {
|
|
150
|
-
const validationResult = this.validateToken(token);
|
|
151
|
-
if (validationResult !== true) {
|
|
152
|
-
throw new ApplicationError(validationResult);
|
|
153
|
-
}
|
|
154
|
-
return token;
|
|
155
|
-
};
|
|
156
|
-
|
|
157
|
-
this.validateEmail = (input) => {
|
|
158
|
-
if (!joi.string().email().validate(input).error) {
|
|
159
|
-
return true;
|
|
160
|
-
}
|
|
161
|
-
return input ? 'Invalid email' : 'Please enter your email address.';
|
|
162
|
-
};
|
|
163
|
-
|
|
164
|
-
this.promptEmail = async () => {
|
|
165
|
-
const { email } = await inquirer.prompt([{
|
|
166
|
-
type: 'input',
|
|
167
|
-
name: 'email',
|
|
168
|
-
message: 'What is your email address?',
|
|
169
|
-
validate: this.validateEmail,
|
|
170
|
-
}]);
|
|
171
|
-
return email;
|
|
172
|
-
};
|
|
173
|
-
|
|
174
|
-
this.loginWithPassword = async (email, password) => {
|
|
175
|
-
if (!password) {
|
|
176
|
-
({ password } = await inquirer.prompt([{
|
|
177
|
-
type: 'password',
|
|
178
|
-
name: 'password',
|
|
179
|
-
message: 'What is your Forest Admin password:',
|
|
180
|
-
validate: (input) => !!input || 'Please enter your password.',
|
|
181
|
-
}]));
|
|
182
|
-
}
|
|
183
|
-
return api.login(email, password);
|
|
184
|
-
};
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
module.exports = Authenticator;
|
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
const Context = require('@forestadmin/context');
|
|
2
|
-
|
|
3
|
-
const branchDeserializer = require('../deserializers/branch');
|
|
4
|
-
const EnvironmentSerializer = require('../serializers/environment');
|
|
5
|
-
const { handleError } = require('../utils/error');
|
|
6
|
-
|
|
7
|
-
const ERROR_MESSAGE_PROJECT_IN_V1 = 'This project does not support branches yet. Please migrate your environments from your Project settings first.';
|
|
8
|
-
const ERROR_MESSAGE_ENV_SECRET_ISSUE = 'Your development environment is not properly set up. Please run `forest init` first and retry.';
|
|
9
|
-
const ERROR_MESSAGE_BRANCH_ALREADY_EXISTS = 'This branch already exists.';
|
|
10
|
-
const ERROR_MESSAGE_ADDITIONAL_REMOTE_BRANCHES = 'The remote environments can\'t have additional branches.';
|
|
11
|
-
const ERROR_MESSAGE_NO_PRODUCTION_OR_REMOTE_ENVIRONMENT = 'You cannot run branch commands until this project has either a remote or a production environment.';
|
|
12
|
-
const ERROR_MESSAGE_NO_REMOTE_ENVIRONMENT = 'You cannot run this command until this project has a remote non-production environment.';
|
|
13
|
-
const ERROR_MESSAGE_BRANCH_DOES_NOT_EXIST = 'This branch doesn\'t exist.';
|
|
14
|
-
const ERROR_MESSAGE_REMOVE_BRANCH_FAILED = 'Failed to delete branch.';
|
|
15
|
-
const ERROR_MESSAGE_NOT_RIGHT_PERMISSION_LEVEL = 'You need the \'Admin\' or \'Developer\' permission level on this project to use branches.';
|
|
16
|
-
const ERROR_MESSAGE_ENVIRONMENT_NOT_FOUND = 'The environment provided doesn\'t exist.';
|
|
17
|
-
const ERROR_MESSAGE_NO_CURRENT_BRANCH = 'You don\'t have any branch to push. Use `forest branch` to create one or use `forest switch` to set your current branch.';
|
|
18
|
-
const ERROR_MESSAGE_WRONG_ENVIRONMENT_TYPE = 'The environment on which you are trying to push your modifications is not a remote environment.';
|
|
19
|
-
const ERROR_MESSAGE_NO_DESTINATION_BRANCH = 'The environment on which you are trying to push your modifications doesn\'t have current branch.';
|
|
20
|
-
|
|
21
|
-
function getBranches(envSecret) {
|
|
22
|
-
const {
|
|
23
|
-
assertPresent,
|
|
24
|
-
authenticator,
|
|
25
|
-
env,
|
|
26
|
-
superagent: agent,
|
|
27
|
-
} = Context.inject();
|
|
28
|
-
assertPresent({ authenticator, env, superagent: agent });
|
|
29
|
-
const authToken = authenticator.getAuthToken();
|
|
30
|
-
return agent
|
|
31
|
-
.get(`${env.FOREST_URL}/api/branches`)
|
|
32
|
-
.set('Authorization', `Bearer ${authToken}`)
|
|
33
|
-
.set('forest-secret-key', envSecret)
|
|
34
|
-
.send()
|
|
35
|
-
.then((response) => branchDeserializer.deserialize(response.body));
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function deleteBranch(branchName, environmentSecret) {
|
|
39
|
-
const {
|
|
40
|
-
assertPresent,
|
|
41
|
-
authenticator,
|
|
42
|
-
env,
|
|
43
|
-
superagent: agent,
|
|
44
|
-
} = Context.inject();
|
|
45
|
-
assertPresent({ authenticator, env, superagent: agent });
|
|
46
|
-
const authToken = authenticator.getAuthToken();
|
|
47
|
-
|
|
48
|
-
return agent
|
|
49
|
-
.del(`${env.FOREST_URL}/api/branches/${encodeURIComponent(branchName)}`)
|
|
50
|
-
.set('Authorization', `Bearer ${authToken}`)
|
|
51
|
-
.set('forest-secret-key', `${environmentSecret}`)
|
|
52
|
-
.send();
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function createBranch(branchName, environmentSecret, originName) {
|
|
56
|
-
const {
|
|
57
|
-
assertPresent,
|
|
58
|
-
authenticator,
|
|
59
|
-
env,
|
|
60
|
-
superagent: agent,
|
|
61
|
-
} = Context.inject();
|
|
62
|
-
assertPresent({ authenticator, env, superagent: agent });
|
|
63
|
-
const authToken = authenticator.getAuthToken();
|
|
64
|
-
|
|
65
|
-
return agent
|
|
66
|
-
.post(`${env.FOREST_URL}/api/branches`)
|
|
67
|
-
.set('Authorization', `Bearer ${authToken}`)
|
|
68
|
-
.set('forest-secret-key', `${environmentSecret}`)
|
|
69
|
-
.send({
|
|
70
|
-
branchName: encodeURIComponent(branchName),
|
|
71
|
-
originName: encodeURIComponent(originName),
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function pushBranch(environmentSecret) {
|
|
76
|
-
const {
|
|
77
|
-
assertPresent,
|
|
78
|
-
authenticator,
|
|
79
|
-
env,
|
|
80
|
-
superagent: agent,
|
|
81
|
-
} = Context.inject();
|
|
82
|
-
assertPresent({ authenticator, env, superagent: agent });
|
|
83
|
-
const authToken = authenticator.getAuthToken();
|
|
84
|
-
|
|
85
|
-
return agent
|
|
86
|
-
.post(`${env.FOREST_URL}/api/branches/push`)
|
|
87
|
-
.set('Authorization', `Bearer ${authToken}`)
|
|
88
|
-
.set('forest-secret-key', `${environmentSecret}`)
|
|
89
|
-
.send();
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
function switchBranch({ id }, environmentSecret) {
|
|
93
|
-
const {
|
|
94
|
-
assertPresent,
|
|
95
|
-
authenticator,
|
|
96
|
-
env,
|
|
97
|
-
superagent: agent,
|
|
98
|
-
} = Context.inject();
|
|
99
|
-
assertPresent({ authenticator, env, superagent: agent });
|
|
100
|
-
const authToken = authenticator.getAuthToken();
|
|
101
|
-
|
|
102
|
-
return agent
|
|
103
|
-
.put(`${env.FOREST_URL}/api/environments`)
|
|
104
|
-
.set('Authorization', `Bearer ${authToken}`)
|
|
105
|
-
.set('forest-secret-key', `${environmentSecret}`)
|
|
106
|
-
.send(EnvironmentSerializer.serialize({ currentBranchId: id }));
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
function setOrigin(originEnvironmentName, environmentSecret) {
|
|
110
|
-
const {
|
|
111
|
-
assertPresent,
|
|
112
|
-
authenticator,
|
|
113
|
-
env,
|
|
114
|
-
superagent: agent,
|
|
115
|
-
} = Context.inject();
|
|
116
|
-
assertPresent({ authenticator, env, superagent: agent });
|
|
117
|
-
const authToken = authenticator.getAuthToken();
|
|
118
|
-
|
|
119
|
-
return agent
|
|
120
|
-
.post(`${env.FOREST_URL}/api/branches/set-origin`)
|
|
121
|
-
.set('Authorization', `Bearer ${authToken}`)
|
|
122
|
-
.set('forest-secret-key', `${environmentSecret}`)
|
|
123
|
-
.send({ originEnvironmentName: encodeURIComponent(originEnvironmentName) });
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
function handleBranchError(rawError) {
|
|
127
|
-
const error = handleError(rawError);
|
|
128
|
-
switch (error) {
|
|
129
|
-
// NOTICE: When no env/project can be found through envSecret
|
|
130
|
-
case 'Not Found':
|
|
131
|
-
return ERROR_MESSAGE_ENV_SECRET_ISSUE;
|
|
132
|
-
case 'Forbidden':
|
|
133
|
-
return ERROR_MESSAGE_NOT_RIGHT_PERMISSION_LEVEL;
|
|
134
|
-
case 'Environment is not in development.':
|
|
135
|
-
return ERROR_MESSAGE_ADDITIONAL_REMOTE_BRANCHES;
|
|
136
|
-
case 'Dev Workflow disabled.':
|
|
137
|
-
return ERROR_MESSAGE_PROJECT_IN_V1;
|
|
138
|
-
case 'Branch name already exists.':
|
|
139
|
-
return ERROR_MESSAGE_BRANCH_ALREADY_EXISTS;
|
|
140
|
-
case 'No production/remote environment.':
|
|
141
|
-
return ERROR_MESSAGE_NO_PRODUCTION_OR_REMOTE_ENVIRONMENT;
|
|
142
|
-
case 'No remote environment.':
|
|
143
|
-
return ERROR_MESSAGE_NO_REMOTE_ENVIRONMENT;
|
|
144
|
-
case 'Branch does not exist.':
|
|
145
|
-
return ERROR_MESSAGE_BRANCH_DOES_NOT_EXIST;
|
|
146
|
-
case 'Failed to remove branch.':
|
|
147
|
-
return ERROR_MESSAGE_REMOVE_BRANCH_FAILED;
|
|
148
|
-
case 'Environment not found.':
|
|
149
|
-
return ERROR_MESSAGE_ENVIRONMENT_NOT_FOUND;
|
|
150
|
-
case 'No current branch.':
|
|
151
|
-
return ERROR_MESSAGE_NO_CURRENT_BRANCH;
|
|
152
|
-
case 'Environment type should be remote.':
|
|
153
|
-
return ERROR_MESSAGE_WRONG_ENVIRONMENT_TYPE;
|
|
154
|
-
case 'No destination branch.':
|
|
155
|
-
return ERROR_MESSAGE_NO_DESTINATION_BRANCH;
|
|
156
|
-
default:
|
|
157
|
-
return error;
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
module.exports = {
|
|
162
|
-
getBranches,
|
|
163
|
-
deleteBranch,
|
|
164
|
-
createBranch,
|
|
165
|
-
pushBranch,
|
|
166
|
-
switchBranch,
|
|
167
|
-
setOrigin,
|
|
168
|
-
handleBranchError,
|
|
169
|
-
};
|