Skip to content

Commit 1053148

Browse files
committed
Add list, create, inspect and remove docker config commands docker-java#1481
1 parent 4387250 commit 1053148

23 files changed

Lines changed: 942 additions & 0 deletions

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import com.github.dockerjava.api.command.CopyArchiveFromContainerCmd;
1010
import com.github.dockerjava.api.command.CopyArchiveToContainerCmd;
1111
import com.github.dockerjava.api.command.CopyFileFromContainerCmd;
12+
import com.github.dockerjava.api.command.CreateConfigCmd;
1213
import com.github.dockerjava.api.command.CreateContainerCmd;
1314
import com.github.dockerjava.api.command.CreateImageCmd;
1415
import com.github.dockerjava.api.command.CreateNetworkCmd;
@@ -21,6 +22,7 @@
2122
import com.github.dockerjava.api.command.ExecStartCmd;
2223
import com.github.dockerjava.api.command.InfoCmd;
2324
import com.github.dockerjava.api.command.InitializeSwarmCmd;
25+
import com.github.dockerjava.api.command.InspectConfigCmd;
2426
import com.github.dockerjava.api.command.InspectContainerCmd;
2527
import com.github.dockerjava.api.command.InspectExecCmd;
2628
import com.github.dockerjava.api.command.InspectImageCmd;
@@ -31,6 +33,7 @@
3133
import com.github.dockerjava.api.command.JoinSwarmCmd;
3234
import com.github.dockerjava.api.command.KillContainerCmd;
3335
import com.github.dockerjava.api.command.LeaveSwarmCmd;
36+
import com.github.dockerjava.api.command.ListConfigsCmd;
3437
import com.github.dockerjava.api.command.ListContainersCmd;
3538
import com.github.dockerjava.api.command.ListImagesCmd;
3639
import com.github.dockerjava.api.command.ListNetworksCmd;
@@ -47,6 +50,7 @@
4750
import com.github.dockerjava.api.command.PruneCmd;
4851
import com.github.dockerjava.api.command.PullImageCmd;
4952
import com.github.dockerjava.api.command.PushImageCmd;
53+
import com.github.dockerjava.api.command.RemoveConfigCmd;
5054
import com.github.dockerjava.api.command.RemoveContainerCmd;
5155
import com.github.dockerjava.api.command.RemoveImageCmd;
5256
import com.github.dockerjava.api.command.RemoveNetworkCmd;
@@ -435,12 +439,47 @@ public interface DockerClient extends Closeable {
435439

436440
/**
437441
* Command to remove a secret
442+
*
443+
* @since {@link RemoteApiVersion#VERSION_1_25}
438444
* @param secretId secret id or secret name
439445
* @return command
440446
*/
441447
RemoveSecretCmd removeSecretCmd(String secretId);
442448

443449

450+
/**
451+
* Command to list all configs. Only applicable if docker runs in swarm mode.
452+
*
453+
* @since {@link RemoteApiVersion#VERSION_1_30}
454+
* @return command
455+
*/
456+
ListConfigsCmd listConfigsCmd();
457+
458+
/**
459+
* Command to create a config in a docker swarm. Only applicable if docker runs in swarm mode.
460+
*
461+
* @since {@link RemoteApiVersion#VERSION_1_30}
462+
* @return command
463+
*/
464+
CreateConfigCmd createConfigCmd();
465+
466+
/**
467+
* Command to inspect a service
468+
*
469+
* @since {@link RemoteApiVersion#VERSION_1_30}
470+
* @param configId config id or config name
471+
* @return command
472+
*/
473+
InspectConfigCmd inspectConfigCmd(String configId);
474+
475+
/**
476+
* Command to remove a config
477+
* @since {@link RemoteApiVersion#VERSION_1_30}
478+
* @param configId config id or config name
479+
* @return command
480+
*/
481+
RemoveConfigCmd removeConfigCmd(String configId);
482+
444483

445484
@Override
446485
void close() throws IOException;
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package com.github.dockerjava.api.command;
2+
3+
import com.github.dockerjava.api.exception.ConflictException;
4+
5+
import javax.annotation.CheckForNull;
6+
import java.util.Map;
7+
8+
/**
9+
* Command to create a new config
10+
*
11+
* @since {@link RemoteApiVersion#VERSION_1_30}
12+
*/
13+
public interface CreateConfigCmd extends SyncDockerCmd<CreateConfigResponse> {
14+
15+
@CheckForNull
16+
String getName();
17+
18+
@CheckForNull
19+
String getData();
20+
21+
@CheckForNull
22+
Map<String, String> getLabels();
23+
24+
/**
25+
* @param name
26+
* - The new config name.
27+
*/
28+
CreateConfigCmd withName(String name);
29+
30+
/**
31+
* @param data
32+
* - The new config data.
33+
*/
34+
CreateConfigCmd withData(byte[] data);
35+
36+
/**
37+
* @param labels
38+
* - A mapping of labels keys and values. Labels are a mechanism for applying metadata to Docker objects.
39+
*/
40+
CreateConfigCmd withLabels(Map<String, String> labels);
41+
42+
/**
43+
* @throws ConflictException Named config already exists
44+
*/
45+
@Override
46+
CreateConfigResponse exec() throws ConflictException;
47+
48+
interface Exec extends DockerCmdSyncExec<CreateConfigCmd, CreateConfigResponse> {
49+
}
50+
51+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.github.dockerjava.api.command;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
import lombok.EqualsAndHashCode;
5+
import lombok.ToString;
6+
7+
/**
8+
* The response of a {@link CreateConfigCmd}
9+
*/
10+
@EqualsAndHashCode
11+
@ToString
12+
public class CreateConfigResponse {
13+
@JsonProperty("ID")
14+
private String id;
15+
16+
public String getId() {
17+
return id;
18+
}
19+
}

docker-java-api/src/main/java/com/github/dockerjava/api/command/DelegatingDockerCmdExecFactory.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,26 @@ public RemoveSecretCmd.Exec createRemoveSecretCmdExec() {
380380
return getDockerCmdExecFactory().createRemoveSecretCmdExec();
381381
}
382382

383+
@Override
384+
public ListConfigsCmd.Exec createListConfigsCmdExec() {
385+
return getDockerCmdExecFactory().createListConfigsCmdExec();
386+
}
387+
388+
@Override
389+
public CreateConfigCmd.Exec createCreateConfigCmdExec() {
390+
return getDockerCmdExecFactory().createCreateConfigCmdExec();
391+
}
392+
393+
@Override
394+
public InspectConfigCmd.Exec createInspectConfigCmdExec() {
395+
return getDockerCmdExecFactory().createInspectConfigCmdExec();
396+
}
397+
398+
@Override
399+
public RemoveConfigCmd.Exec createRemoveConfigCmdExec() {
400+
return getDockerCmdExecFactory().createRemoveConfigCmdExec();
401+
}
402+
383403
@Override
384404
public void close() throws IOException {
385405
getDockerCmdExecFactory().close();

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,35 @@ public interface DockerCmdExecFactory extends Closeable {
236236
*/
237237
RemoveSecretCmd.Exec createRemoveSecretCmdExec();
238238

239+
/**
240+
* Command to list all configs.
241+
*
242+
* @since {@link RemoteApiVersion#VERSION_1_30}
243+
*/
244+
ListConfigsCmd.Exec createListConfigsCmdExec();
245+
246+
/**
247+
* Command to inspect a config in a docker swarm. Only applicable if docker runs in swarm mode.
248+
*
249+
* @since {@link RemoteApiVersion#VERSION_1_30}
250+
*/
251+
InspectConfigCmd.Exec createInspectConfigCmdExec();
252+
253+
/**
254+
* Command to create a new config in a docker swarm. Only applicable if docker runs in swarm mode.
255+
*
256+
* @since {@link RemoteApiVersion#VERSION_1_30}
257+
*/
258+
CreateConfigCmd.Exec createCreateConfigCmdExec();
259+
260+
/**
261+
* Command to remove a config in a docker swarm. Only applicable if docker runs in swarm mode.
262+
*
263+
* @since {@link RemoteApiVersion#VERSION_1_30}
264+
*/
265+
RemoveConfigCmd.Exec createRemoveConfigCmdExec();
266+
267+
239268
@Override
240269
void close() throws IOException;
241270

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

0 commit comments

Comments
 (0)