Skip to content

Commit 1bba443

Browse files
authored
Merge pull request #63 from mcanoy/deploy-key
make deploy key writeable
2 parents c624b37 + 974611d commit 1bba443

File tree

4 files changed

+39
-3
lines changed

4 files changed

+39
-3
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.redhat.labs.omp.models.gitlab;
2+
3+
import javax.json.bind.annotation.JsonbProperty;
4+
5+
import lombok.AllArgsConstructor;
6+
import lombok.Builder;
7+
import lombok.Data;
8+
import lombok.NoArgsConstructor;
9+
10+
@Data
11+
@Builder
12+
@NoArgsConstructor
13+
@AllArgsConstructor
14+
public class DeployKey {
15+
16+
private String title;
17+
18+
@JsonbProperty("can_push")
19+
private boolean canPush;
20+
21+
}

src/main/java/com/redhat/labs/omp/rest/client/GitLabService.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.jboss.resteasy.annotations.jaxrs.PathParam;
1919

2020
import com.redhat.labs.omp.models.gitlab.CommitMultiple;
21+
import com.redhat.labs.omp.models.gitlab.DeployKey;
2122
import com.redhat.labs.omp.models.gitlab.File;
2223
import com.redhat.labs.omp.models.gitlab.Group;
2324
import com.redhat.labs.omp.models.gitlab.Hook;
@@ -183,7 +184,12 @@ File updateFile(@PathParam("id") @Encoded Integer projectId, @PathParam("file_pa
183184
@Logged
184185
@Path("/projects/{id}/deploy_keys/{deploy_key}/enable")
185186
@Produces("application/json")
186-
Response enableDeployKey(@PathParam("id") @Encoded Integer projectId,
187-
@PathParam("deploy_key") @Encoded Integer deployKey);
187+
Response enableDeployKey(@PathParam("id") @Encoded Integer projectId, @PathParam("deploy_key") @Encoded Integer deployKey);
188+
189+
@PUT
190+
@Logged
191+
@Path("/projects/{id}/deploy_keys/{deploy_key_id}")
192+
@Produces("application/json")
193+
Response updateDeployKey(@PathParam("id") @Encoded Integer projectId, @PathParam("deploy_key_id") @Encoded Integer deployKeyId, DeployKey deployKey);
188194

189195
}

src/main/java/com/redhat/labs/omp/service/ProjectService.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import org.slf4j.Logger;
1212
import org.slf4j.LoggerFactory;
1313

14+
import com.redhat.labs.omp.models.gitlab.DeployKey;
1415
import com.redhat.labs.omp.models.gitlab.Project;
1516
import com.redhat.labs.omp.models.gitlab.ProjectSearchResults;
1617
import com.redhat.labs.omp.rest.client.GitLabService;
@@ -114,9 +115,11 @@ public void deleteProject(Integer projectId) {
114115
gitLabService.deleteProjectById(projectId);
115116
}
116117

117-
// enable deployment key
118+
// enable deployment key - by default it's ready only but we need to write so let's 2-step
118119
public void enableDeploymentKeyOnProject(Integer projectId, Integer deployKey) {
120+
119121
gitLabService.enableDeployKey(projectId, deployKey);
122+
gitLabService.updateDeployKey(projectId, deployKey, DeployKey.builder().title("LodeStar DK").canPush(true).build());
120123
}
121124

122125
}

src/test/java/com/redhat/labs/omp/mocks/MockGitLabService.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.eclipse.microprofile.rest.client.inject.RestClient;
1313

1414
import com.redhat.labs.omp.models.gitlab.CommitMultiple;
15+
import com.redhat.labs.omp.models.gitlab.DeployKey;
1516
import com.redhat.labs.omp.models.gitlab.File;
1617
import com.redhat.labs.omp.models.gitlab.Group;
1718
import com.redhat.labs.omp.models.gitlab.Hook;
@@ -290,4 +291,9 @@ public Group getGroupByIdOrPath(String idOrPath) {
290291
return null;
291292
}
292293

294+
@Override
295+
public Response updateDeployKey(Integer projectId, Integer deployKeyId, DeployKey deployKey) {
296+
return null;
297+
}
298+
293299
}

0 commit comments

Comments
 (0)