INFRA-2701 | Dhruv | fix merge conflicts
This commit is contained in:
@@ -139,8 +139,8 @@
|
||||
"serviceAccount": true,
|
||||
"instance": {
|
||||
"count": 2,
|
||||
"cpu": 1,
|
||||
"memory": "3Gi"
|
||||
"cpu": $CPU,
|
||||
"memory": "$MEMORY"
|
||||
},
|
||||
"namespace": "$NAMESPACE",
|
||||
"exposedPorts": [
|
||||
|
||||
@@ -9,7 +9,4 @@ public class Stage {
|
||||
|
||||
private String type;
|
||||
private String approvalType;
|
||||
private String outputSlackChannel;
|
||||
private String extraLinks;
|
||||
private String tagSlackMembers;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@ package com.navi.infra.portal.v2.jit.dto;
|
||||
import com.navi.infra.portal.v2.environment.entity.Environment;
|
||||
import com.navi.infra.portal.v2.vertical.entity.Vertical;
|
||||
import javax.validation.constraints.Email;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Pattern;
|
||||
import javax.validation.constraints.Positive;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
@@ -37,4 +39,11 @@ public class JitRequestDto {
|
||||
private Long grantWindow;
|
||||
|
||||
private Long grantAt;
|
||||
|
||||
@NotNull
|
||||
@Pattern(
|
||||
regexp = "^[a-zA-Z0-9][a-zA-Z0-9 .:/@]+.{8,}",
|
||||
message = "Invalid values used in justification"
|
||||
)
|
||||
private String justification;
|
||||
}
|
||||
|
||||
@@ -66,6 +66,8 @@ public class JitRequest extends BaseEntity {
|
||||
|
||||
private LocalDateTime grantAt;
|
||||
|
||||
private String justification;
|
||||
|
||||
private String requestorSlackMessageTimestamp;
|
||||
|
||||
private String channelSlackMessageTimestamp;
|
||||
@@ -83,7 +85,8 @@ public class JitRequest extends BaseEntity {
|
||||
String resourceAction,
|
||||
JitRequestStatus status,
|
||||
Long grantWindow,
|
||||
LocalDateTime grantAt
|
||||
LocalDateTime grantAt,
|
||||
String justification
|
||||
) {
|
||||
this.requestedFor = requestedFor;
|
||||
this.requestedBy = requestedBy;
|
||||
@@ -96,5 +99,6 @@ public class JitRequest extends BaseEntity {
|
||||
this.status = status;
|
||||
this.grantWindow = grantWindow;
|
||||
this.grantAt = grantAt;
|
||||
this.justification = justification;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ public interface JitRequestsRepository extends JpaRepository<JitRequest, Long> {
|
||||
+ "AND resource_type = :resourceType AND environment = :env "
|
||||
+ "AND resource_action = :resourceAction "
|
||||
+ "AND :grantAt BETWEEN grant_at AND grant_at + interval '1 hour' * grant_window "
|
||||
+ "AND status='PENDING'",
|
||||
+ "AND status IN ('PENDING','APPROVED')",
|
||||
nativeQuery = true)
|
||||
List<JitRequest> findDuplicateRequestsByUser(
|
||||
Long requestedForId,
|
||||
|
||||
@@ -423,7 +423,8 @@ class JitServiceImpl implements JitService {
|
||||
JitRequestStatus.PENDING, jitRequestDto.getGrantWindow(),
|
||||
jitRequestDto.getGrantAt() == null ? LocalDateTime.now() :
|
||||
Instant.ofEpochSecond(jitRequestDto.getGrantAt()).atZone(ZoneId.systemDefault())
|
||||
.toLocalDateTime());
|
||||
.toLocalDateTime(),
|
||||
jitRequestDto.getJustification());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -24,6 +24,11 @@ public class SlackBotUtil {
|
||||
String.format("*%s*\n%s", title, text));
|
||||
}
|
||||
|
||||
private SlackMessageText createTextLineField(String title, String text) {
|
||||
return new SlackMessageText(SlackMessageTextType.MARKDOWN,
|
||||
String.format("*%s*: %s", title, text));
|
||||
}
|
||||
|
||||
private ArrayList<SlackMessageText> createReviewMessage(
|
||||
String userEmail,
|
||||
JitRequest jitRequest,
|
||||
@@ -33,17 +38,19 @@ public class SlackBotUtil {
|
||||
createTextBoxField("ID",
|
||||
String.join("-", jitRequest.getId().toString(),
|
||||
jitApproval.getId().toString())),
|
||||
createTextBoxField("User", userEmail),
|
||||
createTextBoxField("Vertical", jitRequest.getVertical().toString()),
|
||||
createTextBoxField("Environment", jitRequest.getEnvironment().toString()),
|
||||
createTextBoxField("Resource", jitRequest.getResourceType()),
|
||||
createTextBoxField("Action", jitRequest.getResourceAction()),
|
||||
createTextBoxField("Grant At/On",
|
||||
jitRequest.getGrantAt().truncatedTo(ChronoUnit.MINUTES).toString()),
|
||||
createTextBoxField("Grant Window(Hours)",
|
||||
jitRequest.getGrantWindow().toString()),
|
||||
createTextBoxField("Review as", jitApproval.getTeam().getName()),
|
||||
createTextBoxField("Status", jitApproval.getAction().toString())
|
||||
createTextBoxField("USER", userEmail),
|
||||
createTextBoxField("VERTICAL", jitRequest.getVertical().toString()),
|
||||
createTextBoxField("ENVIRONMENT", jitRequest.getEnvironment().toString()),
|
||||
createTextBoxField("ACTION - RESOURCE",
|
||||
String.format("%s - %s", jitRequest.getResourceAction().toUpperCase(),
|
||||
jitRequest.getResourceType())),
|
||||
createTextBoxField("GRANT TIME",
|
||||
String.format("%s for %s hours",
|
||||
jitRequest.getGrantAt().truncatedTo(ChronoUnit.MINUTES),
|
||||
jitRequest.getGrantWindow().toString())),
|
||||
createTextBoxField("REVIEW AS", jitApproval.getTeam().getName()),
|
||||
createTextBoxField("STATUS", jitApproval.getAction().toString()),
|
||||
createTextLineField("JUSTIFICATION", jitRequest.getJustification())
|
||||
));
|
||||
}
|
||||
|
||||
@@ -78,21 +85,40 @@ public class SlackBotUtil {
|
||||
|
||||
if (!pendingTeams.isEmpty()) {
|
||||
infoMessageFields = infoMessageFields.concat(createTextLineField(
|
||||
String.format("\tReviews pending from: %s\n", String.join(", ", pendingTeams))));
|
||||
String.format("\t*REVIEWS PENDING FROM:* %s\n", String.join(", ", pendingTeams))));
|
||||
}
|
||||
if (!approvedTeams.isEmpty()) {
|
||||
infoMessageFields = infoMessageFields.concat(
|
||||
createReviewInfoMessage("Approved by", approvedBy, approvedTeams));
|
||||
createReviewInfoMessage("*APPROVED BY*", approvedBy, approvedTeams));
|
||||
}
|
||||
if (!rejectedTeams.isEmpty()) {
|
||||
infoMessageFields = infoMessageFields.concat(
|
||||
createReviewInfoMessage("Rejected by", rejectedBy, rejectedTeams));
|
||||
createReviewInfoMessage("*REJECTED BY*", rejectedBy, rejectedTeams));
|
||||
}
|
||||
infoMessageFields = infoMessageFields.concat(createTextLineField(
|
||||
String.format("\tCurrent Status: %s", jitRequest.getStatus().toString())));
|
||||
String.format("\t*CURRENT STATUS:* %s", jitRequest.getStatus().toString())));
|
||||
return new SlackMessageText(SlackMessageTextType.MARKDOWN, infoMessageFields);
|
||||
}
|
||||
|
||||
|
||||
|
||||
private ArrayList<SlackMessageText> createDetailsMessage(
|
||||
JitRequest jitRequest
|
||||
) {
|
||||
return new ArrayList<>(Arrays.asList(
|
||||
createTextBoxField("VERTICAL", jitRequest.getVertical().toString()),
|
||||
createTextBoxField("ENVIRONMENT", jitRequest.getEnvironment().toString()),
|
||||
createTextBoxField("ACTION - RESOURCE",
|
||||
String.format("%s - %s", jitRequest.getResourceAction().toUpperCase(),
|
||||
jitRequest.getResourceType())),
|
||||
createTextBoxField("GRANT TIME",
|
||||
String.format("%s for %s hours",
|
||||
jitRequest.getGrantAt().truncatedTo(ChronoUnit.MINUTES),
|
||||
jitRequest.getGrantWindow().toString())),
|
||||
createTextLineField("JUSTIFICATION", jitRequest.getJustification())
|
||||
));
|
||||
}
|
||||
|
||||
private ArrayList<SlackMessageElement> createActionButtons(JitApproval jitApproval) {
|
||||
return new ArrayList<>(Arrays.asList(
|
||||
createButton("Approve", jitApproval.getId().toString(), "actionApprove",
|
||||
@@ -222,10 +248,20 @@ public class SlackBotUtil {
|
||||
SlackMessageText channelInfoMessage = createInfoMessage(jitRequest, pendingTeams,
|
||||
approvedTeams, approvedBy,
|
||||
rejectedTeams, rejectedBy);
|
||||
SlackBotMessageBlock reviewRequestSection = new SlackBotMessageBlock(
|
||||
SlackBotMessageBlock infoSection = new SlackBotMessageBlock(
|
||||
SlackMessageBlockType.SECTION, channelInfoMessage, null, null);
|
||||
|
||||
SlackBotMessageBlock dividerSection = new SlackBotMessageBlock(
|
||||
SlackMessageBlockType.DIVIDER, null, null, null);
|
||||
|
||||
ArrayList<SlackMessageText> detailedMessageFields = createDetailsMessage(jitRequest);
|
||||
|
||||
SlackBotMessageBlock reviewRequestSection = new SlackBotMessageBlock(
|
||||
SlackMessageBlockType.SECTION, null, null, detailedMessageFields);
|
||||
|
||||
ArrayList<SlackBotMessageBlock> blocks = new ArrayList<>();
|
||||
blocks.add(infoSection);
|
||||
blocks.add(dividerSection);
|
||||
blocks.add(reviewRequestSection);
|
||||
return new SlackBotAttachment(color.color, blocks);
|
||||
}
|
||||
|
||||
@@ -28,6 +28,11 @@ public class LbGroupNamingByNamespace extends LbGroupNamingStrategy {
|
||||
String cluster,
|
||||
CommonIngressCreator commonIngressCreator
|
||||
) {
|
||||
if(loadBalancer.getGroupNameFromData() != null){
|
||||
log.info("LoadBalancer with endpoint {} has group name {} assigned already, not changing group name",loadBalancer.getEndpoint(),loadBalancer.getGroupNameFromData());
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isNewLoadbalancer(oldLb) & !groupNameChanged(loadBalancer, namespace,
|
||||
team.getName())) {
|
||||
log.debug(
|
||||
|
||||
@@ -105,7 +105,10 @@ public abstract class LbGroupNamingStrategy {
|
||||
) {
|
||||
if (groupNameMap.containsKey(groupName)) {
|
||||
if (groupNameMap.get(groupName) >= threshold) {
|
||||
return findFirstAvailableGroupName(groupName, groupNameMap, threshold);
|
||||
String newGroupName = findFirstAvailableGroupName(groupName, groupNameMap, threshold);
|
||||
log.info("Threshold for groupName {} breached, creating a new group name {}",groupName, newGroupName);
|
||||
return commonIngressCreator.createGroup(newGroupName, cluster, namespace, environment,
|
||||
team);
|
||||
}
|
||||
} else {
|
||||
if (lbType.equals(LoadBalancerType.ALB)) {
|
||||
|
||||
@@ -8,13 +8,12 @@ import lombok.Setter;
|
||||
@Getter
|
||||
@Setter
|
||||
public class DeploymentStatusRequestDto {
|
||||
|
||||
ExtraResourceDeploymentDto elasticCache;
|
||||
private ExtraResourceDeploymentDto database;
|
||||
@JsonProperty("docdb")
|
||||
private ExtraResourceDeploymentDto docDb;
|
||||
@JsonProperty("s3_buckets")
|
||||
private List<ExtraResourceDeploymentDto> s3Buckets;
|
||||
ExtraResourceDeploymentDto elasticCache;
|
||||
@JsonProperty("dynamodb")
|
||||
private List<ExtraResourceDeploymentDto> dynamoDb;
|
||||
private ExtraResourceDeploymentDto deployment;
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
ALTER TABLE jit_requests ADD COLUMN justification character varying(500);
|
||||
@@ -90,10 +90,10 @@ class JitServiceImplTest {
|
||||
|
||||
jitRequestDto = new JitRequestDto("alpha@one.com", "beta@two.com",
|
||||
Vertical.NAVIPAY, "Infra", Environment.PROD, "DB", "dev-db",
|
||||
"read", 1L, null);
|
||||
"read", 1L, null, "some justification");
|
||||
jitRequestWithId = new JitRequest(requestedFor, requestedBy, Vertical.NAVIPAY,
|
||||
new Team("Infra"), Environment.PROD, "DB", "dev-db", "read", JitRequestStatus.PENDING,
|
||||
1L, LocalDateTime.now());
|
||||
1L, LocalDateTime.now(), "some justification");
|
||||
jitRequestWithId.setId(1L);
|
||||
}
|
||||
|
||||
@@ -122,7 +122,7 @@ class JitServiceImplTest {
|
||||
|
||||
JitRequest jitRequest = new JitRequest(requestedFor, requestedBy, Vertical.NAVIPAY,
|
||||
new Team("Infra"), Environment.PROD, "DB", "dev-db", "read", JitRequestStatus.PENDING,
|
||||
1L, LocalDateTime.now());
|
||||
1L, LocalDateTime.now(), "some justification");
|
||||
JitApproval jitApprovalOne = new JitApproval(jitRequest, reviewerOne, jitRequest.getTeam(),
|
||||
JitRequestStatus.PENDING);
|
||||
jitApprovalOne.setId(1L);
|
||||
@@ -157,7 +157,7 @@ class JitServiceImplTest {
|
||||
public void testCreateJitRequestWithNoAdditionalReviewers() throws IOException {
|
||||
JitRequest jitRequest = new JitRequest(requestedFor, requestedBy, Vertical.NAVIPAY,
|
||||
new Team("Infra"), Environment.PROD, "DB", "dev-db", "read", JitRequestStatus.PENDING,
|
||||
1L, LocalDateTime.now());
|
||||
1L, LocalDateTime.now(), "some justification");
|
||||
User reviewerOne = new User();
|
||||
reviewerOne.setEmail("charlie@three.com");
|
||||
when(teamService.findByName("Security")).thenReturn(new Team("Security"));
|
||||
|
||||
@@ -6,8 +6,8 @@ import com.navi.infra.portal.v2.environment.entity.Environment;
|
||||
import com.navi.infra.portal.v2.jit.entity.JitApproval;
|
||||
import com.navi.infra.portal.v2.jit.entity.JitRequest;
|
||||
import com.navi.infra.portal.v2.jit.entity.JitRequestStatus;
|
||||
import com.navi.infra.portal.v2.vertical.entity.Vertical;
|
||||
import com.navi.infra.portal.v2.slackbotclient.SlackBotAttachment;
|
||||
import com.navi.infra.portal.v2.vertical.entity.Vertical;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
@@ -20,7 +20,7 @@ public class SlackBotUtilTest {
|
||||
String userEmail = "test@domain.com";
|
||||
JitRequest jitRequest = new JitRequest(new User(), new User(), Vertical.SA,
|
||||
new Team("Infra"), Environment.DEV, "RDS", "dev-db",
|
||||
"read", JitRequestStatus.PENDING, 5L, LocalDateTime.now());
|
||||
"read", JitRequestStatus.PENDING, 5L, LocalDateTime.now(), "some justification");
|
||||
JitApproval jitApproval = new JitApproval();
|
||||
User testUser = new User();
|
||||
|
||||
@@ -61,6 +61,6 @@ public class SlackBotUtilTest {
|
||||
new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), new ArrayList<>(),
|
||||
SlackColor.INFO);
|
||||
|
||||
Assertions.assertEquals(1, result.getBlocks().size()); // Section
|
||||
Assertions.assertEquals(3, result.getBlocks().size());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user