Skip to content
This repository has been archived by the owner on Jul 23, 2024. It is now read-only.

remove workflow-service-sdk dependency from prebuilt-tasks #492

Merged
merged 3 commits into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 0 additions & 18 deletions prebuilt-tasks/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,6 @@
<artifactId>notification-service-sdk</artifactId>
<version>${revision}</version>
</dependency>
<dependency>
<groupId>dev.parodos</groupId>
<artifactId>workflow-service-sdk</artifactId>
<version>${revision}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
Expand All @@ -103,19 +98,16 @@
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
</dependency>

<dependency>
<groupId>org.eclipse.jgit</groupId>
<artifactId>org.eclipse.jgit</artifactId>
<version>${jgit-version}</version>
</dependency>

<dependency>
<groupId>com.github.mwiede</groupId>
<artifactId>jsch</artifactId>
<version>0.2.9</version>
</dependency>

<dependency>
<groupId>org.eclipse.jgit</groupId>
<artifactId>org.eclipse.jgit.ssh.jsch</artifactId>
Expand All @@ -127,25 +119,21 @@
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk18on</artifactId>
<version>1.73</version>
</dependency>

<dependency>
<groupId>org.eclipse.jgit</groupId>
<artifactId>org.eclipse.jgit.ssh.apache</artifactId>
<version>${jgit-version}</version>
</dependency>

<dependency>
<groupId>org.eclipse.jgit</groupId>
<artifactId>org.eclipse.jgit.gpg.bc</artifactId>
<version>${jgit-version}</version>
</dependency>

<dependency>
<groupId>org.eclipse.jgit</groupId>
<artifactId>org.eclipse.jgit.archive</artifactId>
Expand Down Expand Up @@ -178,7 +166,6 @@
<version>${azure-resourcemanager-version}</version>
</dependency>
<!-- End libraries for Azure access -->

<dependency>
<groupId>io.fabric8</groupId>
<artifactId>kubernetes-client</artifactId>
Expand All @@ -200,34 +187,29 @@
<artifactId>generator-annotations</artifactId>
<version>${fabric8.version}</version>
</dependency>

<!-- This specific version is needed for openshift server mock -->
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>mockwebserver</artifactId>
<version>4.11.0</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.sshd</groupId>
<artifactId>sshd-core</artifactId>
<version>2.10.0</version>
<type>test-jar</type>
</dependency>

<dependency>
<groupId>org.apache.sshd</groupId>
<artifactId>sshd-common</artifactId>
<version>2.10.0</version>
</dependency>

<dependency>
<groupId>org.apache.sshd</groupId>
<artifactId>sshd-git</artifactId>
<version>2.10.0</version>
</dependency>

</dependencies>

<build>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import java.util.UUID;

import com.redhat.parodos.infrastructure.Notifier;
import com.redhat.parodos.infrastructure.ProjectRequester;
import com.redhat.parodos.notification.sdk.model.NotificationMessageCreateRequestDTO;
import com.redhat.parodos.workflow.exception.MissingParameterException;
import com.redhat.parodos.workflow.task.BaseWorkFlowTask;
Expand All @@ -29,10 +28,6 @@
import com.redhat.parodos.workflows.work.WorkStatus;
import lombok.extern.slf4j.Slf4j;

import static com.redhat.parodos.tasks.project.consts.ProjectAccessRequestConstant.ACCESS_REQUEST_APPROVAL_USERNAMES;
import static com.redhat.parodos.tasks.project.consts.ProjectAccessRequestConstant.ACCESS_REQUEST_ID;
import static com.redhat.parodos.tasks.project.consts.ProjectAccessRequestConstant.NOTIFICATION_SUBJECT_ACCESS_REQUEST_APPROVAL;

/**
* Project access request approval workflow task
*
Expand All @@ -42,13 +37,19 @@
@Slf4j
public class ProjectAccessRequestApprovalWorkFlowTask extends BaseWorkFlowTask {

private final ProjectRequester projectRequester;
private static final String ACCESS_REQUEST_ID = "ACCESS_REQUEST_ID";

private static final String ACCESS_REQUEST_APPROVAL_USERNAMES = "ACCESS_REQUEST_APPROVAL_USERNAMES";

private static final String NOTIFICATION_SUBJECT_ACCESS_REQUEST_APPROVAL = "Project Access Request Approval";

private final String serviceUrl;

private final Notifier notifier;

public ProjectAccessRequestApprovalWorkFlowTask(ProjectRequester projectRequester, Notifier notifier) {
public ProjectAccessRequestApprovalWorkFlowTask(String serviceUrl, Notifier notifier) {
super();
this.projectRequester = projectRequester;
this.serviceUrl = serviceUrl;
this.notifier = notifier;
}

Expand All @@ -69,8 +70,8 @@ public WorkReport execute(WorkContext workContext) {
NotificationMessageCreateRequestDTO notificationMessageCreateRequestDTO = new NotificationMessageCreateRequestDTO();
notificationMessageCreateRequestDTO.setSubject(NOTIFICATION_SUBJECT_ACCESS_REQUEST_APPROVAL);
notificationMessageCreateRequestDTO.setUsernames(Arrays.stream(approvalUsernames.split(",")).toList());
notificationMessageCreateRequestDTO.setBody(getMessage(
String.format("%s/api/v1/projects/access/%s", projectRequester.getBasePath(), accessRequestId)));
notificationMessageCreateRequestDTO
.setBody(getMessage("%s/api/v1/projects/access/%s".formatted(serviceUrl, accessRequestId)));
notifier.send(notificationMessageCreateRequestDTO);
return new DefaultWorkReport(WorkStatus.COMPLETED, workContext);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import java.util.List;
import java.util.Objects;

import com.redhat.parodos.infrastructure.ProjectRequester;
import com.redhat.parodos.sdk.invoker.ApiException;
import com.redhat.parodos.sdk.model.AccessRequestDTO;
import com.redhat.parodos.sdk.model.AccessResponseDTO;
import com.redhat.parodos.project.enums.Role;
import com.redhat.parodos.tasks.project.dto.AccessRequestDTO;
import com.redhat.parodos.tasks.project.dto.AccessResponseDTO;
import com.redhat.parodos.utils.RestUtils;
import com.redhat.parodos.workflow.exception.MissingParameterException;
import com.redhat.parodos.workflow.parameter.WorkParameter;
import com.redhat.parodos.workflow.parameter.WorkParameterType;
Expand All @@ -18,20 +18,33 @@
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;

import static com.redhat.parodos.tasks.project.consts.ProjectAccessRequestConstant.ACCESS_REQUEST_APPROVAL_USERNAMES;
import static com.redhat.parodos.tasks.project.consts.ProjectAccessRequestConstant.ACCESS_REQUEST_ESCALATION_USERNAME;
import static com.redhat.parodos.tasks.project.consts.ProjectAccessRequestConstant.ACCESS_REQUEST_ID;
import static com.redhat.parodos.tasks.project.consts.ProjectAccessRequestConstant.PARAMETER_ROLE;
import static com.redhat.parodos.tasks.project.consts.ProjectAccessRequestConstant.PARAMETER_ROLE_DEFAULT;
import static com.redhat.parodos.tasks.project.consts.ProjectAccessRequestConstant.PARAMETER_USERNAME;
import org.springframework.http.ResponseEntity;

@Slf4j
public class ProjectAccessRequestWorkFlowTask extends BaseWorkFlowTask {

private final ProjectRequester projectRequester;
private static final String PARAMETER_USERNAME = "USERNAME";

public ProjectAccessRequestWorkFlowTask(ProjectRequester projectRequester) {
this.projectRequester = projectRequester;
private static final String PARAMETER_ROLE = "ROLE";

private static final String PARAMETER_ROLE_DEFAULT = "DEVELOPER";

private static final String ACCESS_REQUEST_ID = "ACCESS_REQUEST_ID";

private static final String ACCESS_REQUEST_APPROVAL_USERNAMES = "ACCESS_REQUEST_APPROVAL_USERNAMES";

private static final String ACCESS_REQUEST_ESCALATION_USERNAME = "ACCESS_REQUEST_ESCALATION_USERNAME";

private final String serviceUrl;

private final String serviceUsername;

private final String servicePassword;

public ProjectAccessRequestWorkFlowTask(String serviceUrl, String serviceUsername, String servicePassword) {
this.serviceUrl = serviceUrl;
this.serviceUsername = serviceUsername;
this.servicePassword = servicePassword;
}

@Override
Expand All @@ -48,30 +61,35 @@ public WorkReport execute(WorkContext workContext) {
}

try {
AccessRequestDTO.RoleEnum.valueOf(role.toUpperCase());
Role.valueOf(role.toUpperCase());
}
catch (IllegalArgumentException e) {
log.error("Exception when trying to convert role requested: {}", e.getMessage());
return new DefaultWorkReport(WorkStatus.FAILED, workContext, e);
}

AccessRequestDTO accessRequestDTO = new AccessRequestDTO();
accessRequestDTO.setUsername(username);
accessRequestDTO.setRole(AccessRequestDTO.RoleEnum.valueOf(role.toUpperCase()));
accessRequestDTO.setUsername(username);
try {
AccessResponseDTO accessResponseDTO = projectRequester.createAccess(getProjectId(workContext),
accessRequestDTO);
addParameter(ACCESS_REQUEST_ID, Objects.requireNonNull(accessResponseDTO.getAccessRequestId()).toString());
addParameter(ACCESS_REQUEST_APPROVAL_USERNAMES,
String.join(",", Objects.requireNonNull(accessResponseDTO.getApprovalSentTo())));
addParameter(ACCESS_REQUEST_ESCALATION_USERNAME, String.join(",", accessResponseDTO.getEscalationSentTo()));
return new DefaultWorkReport(WorkStatus.COMPLETED, workContext);
String urlString = "%s/api/v1/projects/%s/access".formatted(serviceUrl, getProjectId(workContext));
AccessRequestDTO requestDTO = AccessRequestDTO.builder().username(username)
.role(Role.valueOf(role.toUpperCase())).build();
ResponseEntity<AccessResponseDTO> responseDTO = RestUtils.executePost(urlString, requestDTO,
serviceUsername, servicePassword, AccessResponseDTO.class);
if (responseDTO.getStatusCode().is2xxSuccessful()) {
log.info("Rest call completed with response: {}", responseDTO.getBody());
addParameter(ACCESS_REQUEST_ID,
Objects.requireNonNull(responseDTO.getBody()).getAccessRequestId().toString());
addParameter(ACCESS_REQUEST_APPROVAL_USERNAMES,
String.join(",", Objects.requireNonNull(responseDTO.getBody()).getApprovalSentTo()));
addParameter(ACCESS_REQUEST_ESCALATION_USERNAME,
String.join(",", Objects.requireNonNull(responseDTO.getBody()).getEscalationSentTo()));
return new DefaultWorkReport(WorkStatus.COMPLETED, workContext);
}
log.error("Call to the api was not successful with status code: {}", responseDTO.getStatusCode());
}
catch (ApiException e) {
log.error("There was an issue with the api call: {}", e.getMessage());
return new DefaultWorkReport(WorkStatus.FAILED, workContext);
catch (Exception e) {
log.error("There was an issue with the REST call: {}", e.getMessage());
}
return new DefaultWorkReport(WorkStatus.FAILED, workContext);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@
import java.util.Objects;
import java.util.UUID;

import com.redhat.parodos.infrastructure.ProjectRequester;
import com.redhat.parodos.sdk.invoker.ApiException;
import com.redhat.parodos.sdk.model.AccessStatusResponseDTO;
import com.redhat.parodos.tasks.project.dto.AccessStatusResponseDTO;
import com.redhat.parodos.utils.RestUtils;
import com.redhat.parodos.workflow.exception.MissingParameterException;
import com.redhat.parodos.workflow.task.checker.BaseWorkFlowCheckerTask;
import com.redhat.parodos.workflows.work.DefaultWorkReport;
Expand All @@ -30,7 +29,7 @@
import com.redhat.parodos.workflows.workflow.WorkFlow;
import lombok.extern.slf4j.Slf4j;

import static com.redhat.parodos.tasks.project.consts.ProjectAccessRequestConstant.ACCESS_REQUEST_ID;
import org.springframework.http.ResponseEntity;

/**
* Project access request approval workflow checker task
Expand All @@ -41,12 +40,20 @@
@Slf4j
public class ProjectAccessRequestApprovalWorkFlowCheckerTask extends BaseWorkFlowCheckerTask {

private final ProjectRequester projectRequester;
private static final String ACCESS_REQUEST_ID = "ACCESS_REQUEST_ID";

private final String serviceUrl;

private final String serviceUsername;

private final String servicePassword;

public ProjectAccessRequestApprovalWorkFlowCheckerTask(WorkFlow projectAccessRequestApprovalEscalationWorkFlow,
long sla, ProjectRequester projectRequester) {
long sla, String serviceUrl, String serviceUsername, String servicePassword) {
super(projectAccessRequestApprovalEscalationWorkFlow, sla);
this.projectRequester = projectRequester;
this.serviceUrl = serviceUrl;
this.serviceUsername = serviceUsername;
this.servicePassword = servicePassword;
}

@Override
Expand All @@ -62,22 +69,30 @@ public WorkReport checkWorkFlowStatus(WorkContext workContext) {
}

try {
AccessStatusResponseDTO accessStatusResponseDTO = projectRequester.getAccessStatus(accessRequestId);
switch (Objects.requireNonNull(accessStatusResponseDTO.getStatus())) {
case REJECTED -> {
log.info("Project access request {} is rejected!", accessStatusResponseDTO.getAccessRequestId());
return new DefaultWorkReport(WorkStatus.REJECTED, workContext);
}
case APPROVED -> {
log.info("Project access request {} is completed!", accessStatusResponseDTO.getAccessRequestId());
return new DefaultWorkReport(WorkStatus.COMPLETED, workContext);
String urlString = "%s/api/v1/projects/access/%s/status".formatted(serviceUrl, accessRequestId);
ResponseEntity<AccessStatusResponseDTO> responseDTO = RestUtils.restExchange(urlString, serviceUsername,
servicePassword, AccessStatusResponseDTO.class);
if (!responseDTO.getStatusCode().is2xxSuccessful()) {
log.error("Call to the api was not successful: {}", responseDTO.getStatusCode());
}
else {
log.info("Rest call completed with response: {}", responseDTO.getBody());
switch (Objects.requireNonNull(responseDTO.getBody()).getStatus()) {
case APPROVED -> {
log.info("Project access request {} is approved", responseDTO.getBody().getAccessRequestId());
return new DefaultWorkReport(WorkStatus.COMPLETED, workContext);
}
case REJECTED -> {
log.info("Project access request {} is rejected", responseDTO.getBody().getAccessRequestId());
return new DefaultWorkReport(WorkStatus.REJECTED, workContext);
}
default -> log.info("Project access request {} is waiting for approval",
responseDTO.getBody().getAccessRequestId());
}
default -> log.info("Project access request {} awaits for approval",
accessStatusResponseDTO.getAccessRequestId());
}
}
catch (ApiException e) {
log.error("There was an issue with the api call: {}", e.getMessage());
catch (Exception e) {
log.error("There was an issue with the REST call: {}", e.getMessage());
}
return new DefaultWorkReport(WorkStatus.FAILED, workContext);
}
Expand Down

This file was deleted.

Loading
Loading