Skip to content

Commit

Permalink
add support for environment id argument
Browse files Browse the repository at this point in the history
  • Loading branch information
yaronya committed May 9, 2024
1 parent 63277a5 commit 8887b5b
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 15 deletions.
10 changes: 8 additions & 2 deletions node/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,20 @@ The order of precedence of the arguments is:
- Alias: `-p`

### Blueprint ID
> The Blueprint ID you would like to deploy with (Required for new environments)
> The Blueprint ID you wish to deploy with (Required for new environments)
- Usage: `--blueprintId`
- Alias: `-b`

### Environment Name
> The environment name you would like to create, or deploy to an existing one (Required for existing environments)
> The environment name you wish to create, or deploy to an existing one (Required for existing environments)
- Usage: `--environmentName`
- Alias: `-e`

### Environment ID
> The environment id you wish to re-deploy. If both the environment name and ID are specified, the environment ID will take precedence
- Usage: `--environmentId`
- Alias: N/A

### Workspace Name
> (Optional) - A name for Terraform Workspace created for your new environment. This cannot be changed after an environment was created
- Usage: `--workspaceName`
Expand Down Expand Up @@ -138,6 +143,7 @@ This file holds your last action's required parameters and will spare you from r
- `ENV0_PROJECT_ID`
- `ENV0_BLUEPRINT_ID`
- `ENV0_ENVIRONMENT_NAME`
- `ENV0_ENVIRONMENT_ID`

## API Reference

Expand Down
8 changes: 8 additions & 0 deletions node/src/config/arguments.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const {
BLUEPRINT_ID,
WORKSPACE_NAME,
ENVIRONMENT_NAME,
ENVIRONMENT_ID,
ENVIRONMENT_VARIABLES,
TERRAFORM_VARIABLES,
SENSITIVE_ENVIRONMENT_VARIABLES,
Expand Down Expand Up @@ -67,6 +68,13 @@ const argumentsMap = {
prompt: 'Environment Name',
group: ['deploy', 'destroy', 'approve', 'cancel', 'configure']
},
[ENVIRONMENT_ID]: {
name: ENVIRONMENT_NAME,
type: String,
description: 'The environment id you want to perform the action on',
prompt: 'Environment ID',
group: ['deploy', 'destroy', 'approve', 'cancel', 'configure']
},
[BLUEPRINT_ID]: {
name: BLUEPRINT_ID,
alias: 'b',
Expand Down
1 change: 1 addition & 0 deletions node/src/config/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const options = {
PROJECT_ID: 'projectId',
BLUEPRINT_ID: 'blueprintId',
ENVIRONMENT_NAME: 'environmentName',
ENVIRONMENT_ID: 'environmentId',
WORKSPACE_NAME: 'workspaceName',
ENVIRONMENT_VARIABLES: 'environmentVariables',
TERRAFORM_VARIABLES: 'terraformVariables',
Expand Down
5 changes: 3 additions & 2 deletions node/src/lib/config-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const logger = require('./logger');

const CONFIG_FILE = path.join(os.homedir(), '.env0', 'config.json');

const { API_KEY, API_SECRET, ORGANIZATION_ID, PROJECT_ID, BLUEPRINT_ID, ENVIRONMENT_NAME } = options;
const { API_KEY, API_SECRET, ORGANIZATION_ID, PROJECT_ID, BLUEPRINT_ID, ENVIRONMENT_NAME, ENVIRONMENT_ID } = options;

const INCLUDED_OPTIONS = [API_KEY, API_SECRET, ORGANIZATION_ID, PROJECT_ID, BLUEPRINT_ID, ENVIRONMENT_NAME];

Expand All @@ -17,7 +17,8 @@ const envVarToOptionMapper = {
ENV0_ORGANIZATION_ID: ORGANIZATION_ID,
ENV0_PROJECT_ID: PROJECT_ID,
ENV0_BLUEPRINT_ID: BLUEPRINT_ID,
ENV0_ENVIRONMENT_NAME: ENVIRONMENT_NAME
ENV0_ENVIRONMENT_NAME: ENVIRONMENT_NAME,
ENV0_ENVIRONMENT_ID: ENVIRONMENT_ID
};

const getEnvVars = () => {
Expand Down
28 changes: 17 additions & 11 deletions node/src/lib/deploy-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,32 @@ class DeployUtils {
await apiClient.init(options[API_KEY], options[API_SECRET]);
}

async getEnvironment(environmentName, projectId) {
const environments = await apiClient.callApi('get', `environments?projectId=${projectId}&name=${environmentName}`);
async getEnvironment(options) {
const { environmentName, environmentId, projectId } = options;

return isEmpty(environments) ? undefined : environments[0];
if (environmentId) {
return await apiClient.callApi('get', `environments/${environmentId}`);
} else {
const environments = await apiClient.callApi(
'get',
`environments?projectId=${projectId}&name=${environmentName}`
);
return isEmpty(environments) ? undefined : environments[0];
}
}

async getDeployment(deploymentLogId) {
return await apiClient.callApi('get', `environments/deployments/${deploymentLogId}`);
}

async getDeploymentSteps(deploymentLogId) {
return await apiClient.callApi('get', `deployments/${deploymentLogId}/steps`)
return await apiClient.callApi('get', `deployments/${deploymentLogId}/steps`);
}

async getDeploymentStepLog(deploymentLogId, stepName, startTime) {
return await apiClient.callApi(
'get',
`deployments/${deploymentLogId}/steps/${stepName}/log`,
{ params: { startTime } }
)
return await apiClient.callApi('get', `deployments/${deploymentLogId}/steps/${stepName}/log`, {
params: { startTime }
});
}

async updateEnvironment(environment, data) {
Expand Down Expand Up @@ -106,8 +112,8 @@ class DeployUtils {
const { status } = steps.find(step => step.name === stepName);
const stepInProgress = status === 'IN_PROGRESS';

const { events, nextStartTime, hasMoreLogs } = await withRetry(
() => this.getDeploymentStepLog(deploymentLogId, stepName, startTime)
const { events, nextStartTime, hasMoreLogs } = await withRetry(() =>
this.getDeploymentStepLog(deploymentLogId, stepName, startTime)
);

events.forEach(event => logger.info(event.message));
Expand Down

0 comments on commit 8887b5b

Please sign in to comment.