Skip to content

Commit cf8ee3b

Browse files
committed
Add secrets management (Create / List / Remove)
1 parent f760f0c commit cf8ee3b

24 files changed

+923
-1
lines changed

src/main/java/com/github/dockerjava/api/DockerClient.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import com.github.dockerjava.api.command.CreateContainerCmd;
1313
import com.github.dockerjava.api.command.CreateImageCmd;
1414
import com.github.dockerjava.api.command.CreateNetworkCmd;
15+
import com.github.dockerjava.api.command.CreateSecretCmd;
1516
import com.github.dockerjava.api.command.CreateServiceCmd;
1617
import com.github.dockerjava.api.command.CreateVolumeCmd;
1718
import com.github.dockerjava.api.command.DisconnectFromNetworkCmd;
@@ -33,6 +34,7 @@
3334
import com.github.dockerjava.api.command.ListContainersCmd;
3435
import com.github.dockerjava.api.command.ListImagesCmd;
3536
import com.github.dockerjava.api.command.ListNetworksCmd;
37+
import com.github.dockerjava.api.command.ListSecretsCmd;
3638
import com.github.dockerjava.api.command.ListServicesCmd;
3739
import com.github.dockerjava.api.command.ListSwarmNodesCmd;
3840
import com.github.dockerjava.api.command.ListTasksCmd;
@@ -48,6 +50,7 @@
4850
import com.github.dockerjava.api.command.RemoveContainerCmd;
4951
import com.github.dockerjava.api.command.RemoveImageCmd;
5052
import com.github.dockerjava.api.command.RemoveNetworkCmd;
53+
import com.github.dockerjava.api.command.RemoveSecretCmd;
5154
import com.github.dockerjava.api.command.RemoveServiceCmd;
5255
import com.github.dockerjava.api.command.RemoveVolumeCmd;
5356
import com.github.dockerjava.api.command.RenameContainerCmd;
@@ -70,6 +73,7 @@
7073
import com.github.dockerjava.api.model.AuthConfig;
7174
import com.github.dockerjava.api.model.Identifier;
7275
import com.github.dockerjava.api.model.PruneType;
76+
import com.github.dockerjava.api.model.SecretSpec;
7377
import com.github.dockerjava.api.model.ServiceSpec;
7478
import com.github.dockerjava.api.model.SwarmSpec;
7579
import com.github.dockerjava.core.RemoteApiVersion;
@@ -400,6 +404,32 @@ public interface DockerClient extends Closeable {
400404
*/
401405
PruneCmd pruneCmd(PruneType pruneType);
402406

407+
/**
408+
* Command to list all secrets. Only applicable if docker runs in swarm mode.
409+
*
410+
* @since {@link RemoteApiVersion#VERSION_1_25}
411+
* @return command
412+
*/
413+
ListSecretsCmd listSecretsCmd();
414+
415+
/**
416+
* Command to create a secret in a docker swarm. Only applicable if docker runs in swarm mode.
417+
*
418+
* @since {@link RemoteApiVersion#VERSION_1_25}
419+
* @param secretSpec the secret specification
420+
* @return command
421+
*/
422+
CreateSecretCmd createSecretCmd(SecretSpec secretSpec);
423+
424+
/**
425+
* Command to remove a secret
426+
* @param secretId secret id or secret name
427+
* @return command
428+
*/
429+
RemoveSecretCmd removeSecretCmd(String secretId);
430+
431+
432+
403433
@Override
404434
void close() throws IOException;
405435

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.github.dockerjava.api.command;
2+
3+
import com.github.dockerjava.api.exception.ConflictException;
4+
import com.github.dockerjava.api.model.SecretSpec;
5+
import com.github.dockerjava.core.RemoteApiVersion;
6+
7+
import javax.annotation.CheckForNull;
8+
9+
/**
10+
* Command to create a new secret
11+
*
12+
* @since {@link RemoteApiVersion#VERSION_1_25}
13+
*/
14+
public interface CreateSecretCmd extends SyncDockerCmd<CreateSecretResponse> {
15+
16+
@CheckForNull
17+
SecretSpec getSecretSpec();
18+
19+
CreateSecretCmd withSecretSpec(SecretSpec secretSpec);
20+
21+
/**
22+
* @throws ConflictException Named secret already exists
23+
*/
24+
@Override
25+
CreateSecretResponse exec() throws ConflictException;
26+
27+
interface Exec extends DockerCmdSyncExec<CreateSecretCmd, CreateSecretResponse> {
28+
}
29+
30+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.github.dockerjava.api.command;
2+
3+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4+
import com.fasterxml.jackson.annotation.JsonProperty;
5+
import org.apache.commons.lang.builder.ReflectionToStringBuilder;
6+
import org.apache.commons.lang.builder.ToStringStyle;
7+
8+
/**
9+
* The response of a {@link CreateSecretCmd}
10+
*/
11+
@JsonIgnoreProperties(ignoreUnknown = true)
12+
public class CreateSecretResponse {
13+
@JsonProperty("ID")
14+
private String id;
15+
16+
public String getId() {
17+
return id;
18+
}
19+
20+
@Override
21+
public String toString() {
22+
return ReflectionToStringBuilder.toString(this, ToStringStyle.SHORT_PREFIX_STYLE);
23+
}
24+
}

src/main/java/com/github/dockerjava/api/command/DockerCmdExecFactory.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,27 @@ public interface DockerCmdExecFactory extends Closeable {
214214
*/
215215
PruneCmd.Exec pruneCmdExec();
216216

217+
/**
218+
* Command to list all secrets.
219+
*
220+
* @since {@link RemoteApiVersion#VERSION_1_25}
221+
*/
222+
ListSecretsCmd.Exec createListSecretsCmdExec();
223+
224+
/**
225+
* Command to create a new secret in a docker swarm. Only applicable if docker runs in swarm mode.
226+
*
227+
* @since {@link RemoteApiVersion#VERSION_1_25}
228+
*/
229+
CreateSecretCmd.Exec createCreateSecretCmdExec();
230+
231+
/**
232+
* Command to remove a secret in a docker swarm. Only applicable if docker runs in swarm mode.
233+
*
234+
* @since {@link RemoteApiVersion#VERSION_1_25}
235+
*/
236+
RemoveSecretCmd.Exec createRemoveSecretCmdExec();
237+
217238
@Override
218239
void close() throws IOException;
219240

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.github.dockerjava.api.command;
2+
3+
import com.github.dockerjava.api.model.Container;
4+
import com.github.dockerjava.api.model.Secret;
5+
import com.github.dockerjava.api.model.Service;
6+
7+
import javax.annotation.CheckForNull;
8+
import java.util.Collection;
9+
import java.util.List;
10+
import java.util.Map;
11+
12+
/**
13+
* List secrets
14+
*
15+
*/
16+
public interface ListSecretsCmd extends SyncDockerCmd<List<Secret>> {
17+
18+
@CheckForNull
19+
Map<String, List<String>> getFilters();
20+
21+
/**
22+
* @param ids - Show only secrets with the given ids
23+
*/
24+
ListSecretsCmd withIdFilter(List<String> ids);
25+
26+
/**
27+
* @param names - Show only secrets with the given names
28+
*/
29+
ListSecretsCmd withNameFilter(List<String> names);
30+
31+
/**
32+
* @param labels - Show only secrets with the passed labels. Labels is a {@link Map} that contains label keys and values
33+
*/
34+
ListSecretsCmd withLabelFilter(Map<String, String> labels);
35+
36+
interface Exec extends DockerCmdSyncExec<ListSecretsCmd, List<Secret>> {
37+
}
38+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.github.dockerjava.api.command;
2+
3+
import com.github.dockerjava.api.exception.NotFoundException;
4+
5+
import javax.annotation.CheckForNull;
6+
import javax.annotation.Nonnull;
7+
8+
/**
9+
* Remove a secret.
10+
*/
11+
public interface RemoveSecretCmd extends SyncDockerCmd<Void> {
12+
13+
@CheckForNull
14+
String getSecretId();
15+
16+
RemoveSecretCmd withSecretId(@Nonnull String secretId);
17+
18+
/**
19+
* @throws NotFoundException
20+
* No such secret
21+
*/
22+
@Override
23+
Void exec() throws NotFoundException;
24+
25+
interface Exec extends DockerCmdSyncExec<RemoveSecretCmd, Void> {
26+
}
27+
28+
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
package com.github.dockerjava.api.model;
2+
3+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4+
import com.fasterxml.jackson.annotation.JsonInclude;
5+
import com.fasterxml.jackson.annotation.JsonProperty;
6+
import com.github.dockerjava.core.RemoteApiVersion;
7+
8+
import java.io.Serializable;
9+
import java.util.Date;
10+
11+
/**
12+
* Used for Listing secret.
13+
*
14+
* @since {@link RemoteApiVersion#VERSION_1_25}
15+
*/
16+
@JsonIgnoreProperties(ignoreUnknown = true)
17+
@JsonInclude(JsonInclude.Include.NON_NULL)
18+
public class Secret implements Serializable {
19+
public static final long serialVersionUID = 1L;
20+
21+
/**
22+
* @since 1.24
23+
*/
24+
@JsonProperty("ID")
25+
private String id;
26+
27+
/**
28+
* @since 1.24
29+
*/
30+
@JsonProperty("CreatedAt")
31+
private Date createdAt;
32+
33+
/**
34+
* @since 1.24
35+
*/
36+
@JsonProperty("UpdatedAt")
37+
private Date updatedAt;
38+
39+
/**
40+
* @since 1.24
41+
*/
42+
@JsonProperty("Spec")
43+
private ServiceSpec spec;
44+
45+
/**
46+
* @since 1.24
47+
*/
48+
@JsonProperty("Version")
49+
private ResourceVersion version;
50+
51+
public String getId() {
52+
return id;
53+
}
54+
55+
public void setId(String id) {
56+
this.id = id;
57+
}
58+
59+
public Date getCreatedAt() {
60+
return createdAt;
61+
}
62+
63+
public void setCreatedAt(Date createdAt) {
64+
this.createdAt = createdAt;
65+
}
66+
67+
public Date getUpdatedAt() {
68+
return updatedAt;
69+
}
70+
71+
public void setUpdatedAt(Date updatedAt) {
72+
this.updatedAt = updatedAt;
73+
}
74+
75+
public ServiceSpec getSpec() {
76+
return spec;
77+
}
78+
79+
public void setSpec(ServiceSpec spec) {
80+
this.spec = spec;
81+
}
82+
83+
public ResourceVersion getVersion() {
84+
return version;
85+
}
86+
87+
public void setVersion(ResourceVersion version) {
88+
this.version = version;
89+
}
90+
}

0 commit comments

Comments
 (0)