Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.github.dockerjava.api.command;

import com.github.dockerjava.api.model.AuthConfig;
import com.github.dockerjava.api.model.ServiceSpec;

import javax.annotation.CheckForNull;
Expand All @@ -24,6 +25,11 @@ public interface UpdateServiceCmd extends SyncDockerCmd<Void> {

UpdateServiceCmd withVersion(Long version);

@CheckForNull
AuthConfig getAuthConfig();

UpdateServiceCmd withAuthConfig(AuthConfig authConfig);

interface Exec extends DockerCmdSyncExec<UpdateServiceCmd, Void> {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.github.dockerjava.api.command.UpdateServiceCmd;
import com.github.dockerjava.api.exception.NotFoundException;
import com.github.dockerjava.api.model.AuthConfig;
import com.github.dockerjava.api.model.ServiceSpec;
import com.github.dockerjava.core.RemoteApiVersion;
import org.apache.commons.lang3.builder.EqualsBuilder;
Expand All @@ -11,6 +12,7 @@

import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import java.util.Objects;

/**
* @since {@link RemoteApiVersion#VERSION_1_24}
Expand All @@ -33,6 +35,8 @@ public class UpdateServiceCmdImpl extends AbstrDockerCmd<UpdateServiceCmd, Void>
*/
private Long version;

private AuthConfig authConfig;

public UpdateServiceCmdImpl(Exec exec, String serviceId, ServiceSpec serviceSpec) {
super(exec);
withServiceId(serviceId);
Expand Down Expand Up @@ -87,6 +91,19 @@ public UpdateServiceCmdImpl withVersion(Long version) {
return this;
}

@CheckForNull
public AuthConfig getAuthConfig() {
return authConfig;
}

@CheckForNull
@Override
public UpdateServiceCmd withAuthConfig(AuthConfig authConfig) {
Objects.requireNonNull(authConfig, "authConfig was not specified");
this.authConfig = authConfig;
return this;
}

/**
* @throws NotFoundException No such service
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package com.github.dockerjava.core.exec;

import com.fasterxml.jackson.core.type.TypeReference;
import com.github.dockerjava.api.command.CreateServiceResponse;
import com.github.dockerjava.api.command.UpdateServiceCmd;
import com.github.dockerjava.core.DockerClientConfig;
import com.github.dockerjava.core.InvocationBuilder;
import com.github.dockerjava.core.MediaType;
import com.github.dockerjava.core.WebTarget;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;

/**
* Update service settings.
*/
Expand All @@ -27,11 +28,11 @@ protected Void execute(UpdateServiceCmd command) {
.queryParam("version", command.getVersion());

LOGGER.trace("POST: {}", webResource);
try {
webResource.request().accept(MediaType.APPLICATION_JSON).post(command.getServiceSpec()).close();
} catch (IOException e) {
throw new RuntimeException(e);
}
InvocationBuilder builder = resourceWithOptionalAuthConfig(command.getAuthConfig(), webResource.request())
.accept(MediaType.APPLICATION_JSON);

builder.post(command.getServiceSpec(), new TypeReference<CreateServiceResponse>() {
});
return null;
}
}