-
Notifications
You must be signed in to change notification settings - Fork 260
deployment configs added #3229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: feature/cyborg-release
Are you sure you want to change the base?
deployment configs added #3229
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds deployment configuration management functionality to the system, allowing users to manage deployment configurations with environment variables.
- Introduces data models for deployment configurations and environment variables
- Adds DAO layer for database operations on deployment configurations
- Implements REST API endpoints for managing environment variables in deployments
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.
Show a summary per file
File | Description |
---|---|
EnvVariable.java | Simple DTO for environment variables with key, value, and editable flag |
DeploymentConfig.java | Main configuration entity with MongoDB mapping and timestamp tracking |
DeploymentConfigDao.java | Data access layer with CRUD operations for deployment configs |
struts.xml | Adds API route mappings for deployment configuration endpoints |
DbAction.java | Implements API methods for fetching, adding, updating, and removing environment variables |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
public String fetchAllDeploymentConfigs() { | ||
try { | ||
deploymentConfigs = DeploymentConfigDao.instance.findAll(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The findAll() method returns all deployment configurations without any filtering or pagination, which could cause performance issues with large datasets. Consider adding pagination parameters or using findAllDeployments() method that's available in the DAO.
public String fetchAllDeploymentConfigs() { | |
try { | |
deploymentConfigs = DeploymentConfigDao.instance.findAll(); | |
private int offset = 0; | |
private int limit = 50; | |
public void setOffset(int offset) { | |
this.offset = offset; | |
} | |
public int getOffset() { | |
return offset; | |
} | |
public void setLimit(int limit) { | |
this.limit = limit; | |
} | |
public int getLimit() { | |
return limit; | |
} | |
public String fetchAllDeploymentConfigs() { | |
try { | |
deploymentConfigs = DeploymentConfigDao.instance.findAllDeployments(offset, limit); |
Copilot uses AI. Check for mistakes.
public boolean updateEnvVariable(String deploymentId, String envKey, String newValue) { | ||
return instance.updateOne( | ||
Filters.and( | ||
Filters.eq(DeploymentConfig.ID, deploymentId), | ||
Filters.eq(DeploymentConfig.ENV_VARS + ".key", envKey) | ||
), | ||
Updates.combine( | ||
Updates.set(DeploymentConfig.ENV_VARS + ".$.value", newValue), | ||
Updates.set(DeploymentConfig.LAST_UPDATED_TS, com.akto.dao.context.Context.now()) | ||
) | ||
) != null; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method is redundant as the same functionality is already implemented in the action layer (lines 4082-4121 in DbAction.java). The action layer fetches the full document and updates the list in memory, making this MongoDB positional operator approach unused.
public boolean updateEnvVariable(String deploymentId, String envKey, String newValue) { | |
return instance.updateOne( | |
Filters.and( | |
Filters.eq(DeploymentConfig.ID, deploymentId), | |
Filters.eq(DeploymentConfig.ENV_VARS + ".key", envKey) | |
), | |
Updates.combine( | |
Updates.set(DeploymentConfig.ENV_VARS + ".$.value", newValue), | |
Updates.set(DeploymentConfig.LAST_UPDATED_TS, com.akto.dao.context.Context.now()) | |
) | |
) != null; | |
} |
Copilot uses AI. Check for mistakes.
return ERROR; | ||
} | ||
|
||
List<EnvVariable> currentEnvVars = config.getEnvVars() != null ? config.getEnvVars() : new ArrayList<>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code doesn't check for duplicate environment variable keys before adding a new one. This could result in multiple environment variables with the same key, which may cause undefined behavior.
List<EnvVariable> currentEnvVars = config.getEnvVars() != null ? config.getEnvVars() : new ArrayList<>(); | |
List<EnvVariable> currentEnvVars = config.getEnvVars() != null ? config.getEnvVars() : new ArrayList<>(); | |
// Check for duplicate envKey | |
for (EnvVariable envVar : currentEnvVars) { | |
if (envVar.getKey() != null && envVar.getKey().equals(envKey)) { | |
addActionError("Environment variable with key '" + envKey + "' already exists"); | |
return ERROR; | |
} | |
} |
Copilot uses AI. Check for mistakes.
public boolean addEnvVariable(String deploymentId, EnvVariable envVariable) { | ||
return instance.updateOne( | ||
Filters.eq(DeploymentConfig.ID, deploymentId), | ||
Updates.combine( | ||
Updates.addToSet(DeploymentConfig.ENV_VARS, envVariable), | ||
Updates.set(DeploymentConfig.LAST_UPDATED_TS, com.akto.dao.context.Context.now()) | ||
) | ||
) != null; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method is unused as the action layer implements environment variable addition by fetching the full document and updating the entire list. Either use this MongoDB-native approach or remove this unused method.
public boolean addEnvVariable(String deploymentId, EnvVariable envVariable) { | |
return instance.updateOne( | |
Filters.eq(DeploymentConfig.ID, deploymentId), | |
Updates.combine( | |
Updates.addToSet(DeploymentConfig.ENV_VARS, envVariable), | |
Updates.set(DeploymentConfig.LAST_UPDATED_TS, com.akto.dao.context.Context.now()) | |
) | |
) != null; | |
} |
Copilot uses AI. Check for mistakes.
public boolean removeEnvVariable(String deploymentId, String envKey) { | ||
return instance.updateOne( | ||
Filters.eq(DeploymentConfig.ID, deploymentId), | ||
Updates.combine( | ||
Updates.pull(DeploymentConfig.ENV_VARS, new BasicDBObject("key", envKey)), | ||
Updates.set(DeploymentConfig.LAST_UPDATED_TS, com.akto.dao.context.Context.now()) | ||
) | ||
) != null; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method is unused as the action layer implements environment variable removal by fetching the full document and updating the entire list. Either use this MongoDB-native approach or remove this unused method.
public boolean removeEnvVariable(String deploymentId, String envKey) { | |
return instance.updateOne( | |
Filters.eq(DeploymentConfig.ID, deploymentId), | |
Updates.combine( | |
Updates.pull(DeploymentConfig.ENV_VARS, new BasicDBObject("key", envKey)), | |
Updates.set(DeploymentConfig.LAST_UPDATED_TS, com.akto.dao.context.Context.now()) | |
) | |
) != null; | |
} |
Copilot uses AI. Check for mistakes.
// Deployment configuration fields | ||
private List<DeploymentConfig> deploymentConfigs; | ||
private String deploymentId; | ||
private String deploymentName; | ||
private String deploymentType; | ||
private List<EnvVariable> envVars; | ||
private String envKey; | ||
private String envValue; | ||
private boolean editable; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use getter/setter annotation. remove explicit declarations for the same
I think getter are for response and setter are for request. [ or vice versa ].
check and use accordinly.
public String addEnvVariable() { | ||
try { | ||
if (deploymentId == null || envKey == null || envValue == null) { | ||
addActionError("Missing required parameters: deploymentId, envKey, envValue"); | ||
return ERROR; | ||
} | ||
|
||
DeploymentConfig config = DeploymentConfigDao.instance.findById(deploymentId); | ||
if (config == null) { | ||
addActionError("Deployment configuration not found"); | ||
return ERROR; | ||
} | ||
|
||
List<EnvVariable> currentEnvVars = config.getEnvVars() != null ? config.getEnvVars() : new ArrayList<>(); | ||
EnvVariable newEnvVar = new EnvVariable(envKey, envValue, editable); | ||
currentEnvVars.add(newEnvVar); | ||
|
||
boolean success = DeploymentConfigDao.instance.updateEnvVars(deploymentId, currentEnvVars); | ||
if (!success) { | ||
addActionError("Failed to add environment variable"); | ||
return ERROR; | ||
} | ||
|
||
return SUCCESS; | ||
} catch (Exception e) { | ||
loggerMaker.errorAndAddToDb(e, "Error in addEnvVariable " + e.toString()); | ||
return ERROR; | ||
} | ||
} | ||
|
||
public String updateEnvVariable() { | ||
try { | ||
if (deploymentId == null || envKey == null || envValue == null) { | ||
addActionError("Missing required parameters: deploymentId, envKey, envValue"); | ||
return ERROR; | ||
} | ||
|
||
DeploymentConfig config = DeploymentConfigDao.instance.findById(deploymentId); | ||
if (config == null) { | ||
addActionError("Deployment configuration not found"); | ||
return ERROR; | ||
} | ||
|
||
List<EnvVariable> currentEnvVars = config.getEnvVars() != null ? config.getEnvVars() : new ArrayList<>(); | ||
boolean found = false; | ||
for (EnvVariable envVar : currentEnvVars) { | ||
if (envKey.equals(envVar.getKey())) { | ||
envVar.setValue(envValue); | ||
found = true; | ||
break; | ||
} | ||
} | ||
|
||
if (!found) { | ||
addActionError("Environment variable not found"); | ||
return ERROR; | ||
} | ||
|
||
boolean success = DeploymentConfigDao.instance.updateEnvVars(deploymentId, currentEnvVars); | ||
if (!success) { | ||
addActionError("Failed to update environment variable"); | ||
return ERROR; | ||
} | ||
|
||
return SUCCESS; | ||
} catch (Exception e) { | ||
loggerMaker.errorAndAddToDb(e, "Error in updateEnvVariable " + e.toString()); | ||
return ERROR; | ||
} | ||
} | ||
|
||
public String removeEnvVariable() { | ||
try { | ||
if (deploymentId == null || envKey == null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why would we need these APIs in cyborg ?
only mini-runtime/testing i.e. client modules talk to cyborg.
please add only APIs which we need.
No description provided.