Skip to content

Conversation

harshithb3304
Copy link
Contributor

No description provided.

@Copilot Copilot AI review requested due to automatic review settings September 24, 2025 08:17
Copy link
Contributor

@Copilot Copilot AI left a 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.

Comment on lines 4042 to 4044
public String fetchAllDeploymentConfigs() {
try {
deploymentConfigs = DeploymentConfigDao.instance.findAll();
Copy link
Preview

Copilot AI Sep 24, 2025

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.

Suggested change
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.

Comment on lines +66 to +77
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;
}
Copy link
Preview

Copilot AI Sep 24, 2025

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.

Suggested change
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<>();
Copy link
Preview

Copilot AI Sep 24, 2025

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.

Suggested change
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.

Comment on lines +46 to +55
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;
}

Copy link
Preview

Copilot AI Sep 24, 2025

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.

Suggested change
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.

Comment on lines +56 to +65
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;
}

Copy link
Preview

Copilot AI Sep 24, 2025

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.

Suggested change
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.

Comment on lines 3966 to 3975
// 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;

Copy link
Contributor

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.

Comment on lines 4052 to 4125
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) {
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants