Add secrets management (Create / List / Remove) · Sandeep-source/docker-java@cf8ee3b · GitHub
Skip to content

Commit cf8ee3b

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

24 files changed

Lines changed: 923 additions & 1 deletion

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

Lines changed: 30 additions & 0 deletions
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

0 commit comments

Comments
 (0)