本文整理汇总了Java中com.spotify.docker.client.messages.swarm.Secret类的典型用法代码示例。如果您正苦于以下问题:Java Secret类的具体用法?Java Secret怎么用?Java Secret使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Secret类属于com.spotify.docker.client.messages.swarm包,在下文中一共展示了Secret类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: shouldValidateValidSecretConfiguration
import com.spotify.docker.client.messages.swarm.Secret; //导入依赖的package包/类
@Test
public void shouldValidateValidSecretConfiguration() throws Exception {
final Version version = mock(Version.class);
final HashMap<String, String> properties = new HashMap<>();
final Secret secret = mock(Secret.class);
properties.put("Image", "alpine");
properties.put("Secrets", "src=Foo");
when(version.apiVersion()).thenReturn("1.27");
when(dockerClient.version()).thenReturn(version);
when(dockerClient.listSecrets()).thenReturn(asList(secret));
when(secret.secretSpec()).thenReturn(SecretSpec.builder().name("Foo").build());
when(secret.id()).thenReturn("service-id");
ValidationResult validationResult = new DockerSecretValidator(pluginRequest, dockerClientFactory).validate(properties);
assertFalse(validationResult.hasErrors());
}
示例2: shouldBuildSecretBindFromDockerSecretAndUseDefaultsWhenNotProvided
import com.spotify.docker.client.messages.swarm.Secret; //导入依赖的package包/类
@Test
public void shouldBuildSecretBindFromDockerSecretAndUseDefaultsWhenNotProvided() throws Exception {
final DockerSecrets dockerSecrets = DockerSecrets.fromString("src=Username");
final Secret secret = mock(Secret.class);
when(secret.secretSpec()).thenReturn(SecretSpec.builder().name("Username").build());
when(secret.id()).thenReturn("secret-id");
final List<SecretBind> secretBinds = dockerSecrets.toSecretBind(asList(secret));
assertThat(secretBinds, hasSize(1));
assertThat(secretBinds.get(0).secretName(), is("Username"));
assertThat(secretBinds.get(0).secretId(), is("secret-id"));
assertThat(secretBinds.get(0).file().name(), is("Username"));
assertThat(secretBinds.get(0).file().uid(), is("0"));
assertThat(secretBinds.get(0).file().gid(), is("0"));
assertThat(secretBinds.get(0).file().mode(), is(0444L));
}
示例3: toSecretBind
import com.spotify.docker.client.messages.swarm.Secret; //导入依赖的package包/类
public List<SecretBind> toSecretBind(List<Secret> secrets) {
final Map<String, Secret> secretMap = secrets.stream().collect(Collectors.toMap(o -> o.secretSpec().name(), o -> o));
final List<SecretBind> secretBinds = new ArrayList<>();
for (DockerSecret dockerSecret : this) {
final Secret secret = secretMap.get(dockerSecret.src);
if (secret == null) {
throw new RuntimeException(format("Secret with name `{0}` does not exist.", dockerSecret.name()));
}
LOG.debug(format("Using secret `{0}` with id `{1}`.", dockerSecret.name(), secret.id()));
final SecretFile secretFile = SecretFile.builder()
.name(dockerSecret.file())
.uid(dockerSecret.uid())
.gid(dockerSecret.gid())
.mode(dockerSecret.mode())
.build();
secretBinds.add(SecretBind.builder()
.secretId(secret.id())
.secretName(dockerSecret.name())
.file(secretFile)
.build());
}
return secretBinds;
}
示例4: shouldBuildSecretBindFromDockerSecret
import com.spotify.docker.client.messages.swarm.Secret; //导入依赖的package包/类
@Test
public void shouldBuildSecretBindFromDockerSecret() throws Exception {
final DockerSecrets dockerSecrets = DockerSecrets.fromString("src=Username, target=username, uid=uid, gid=gid, mode=0640\nsrc=Password, target=passwd, uid=uid, gid=gid, mode=0640");
final Secret secretForUsername = mock(Secret.class);
final Secret secretForPassword = mock(Secret.class);
when(secretForUsername.secretSpec()).thenReturn(SecretSpec.builder().name("Username").build());
when(secretForUsername.id()).thenReturn("username-secret-id");
when(secretForPassword.secretSpec()).thenReturn(SecretSpec.builder().name("Password").build());
when(secretForPassword.id()).thenReturn("password-secret-id");
final List<SecretBind> secretBinds = dockerSecrets.toSecretBind(asList(secretForUsername, secretForPassword));
assertThat(secretBinds, hasSize(2));
assertThat(secretBinds.get(0).secretName(), is("Username"));
assertThat(secretBinds.get(0).secretId(), is("username-secret-id"));
assertThat(secretBinds.get(0).file().name(), is("username"));
assertThat(secretBinds.get(0).file().uid(), is("uid"));
assertThat(secretBinds.get(0).file().gid(), is("gid"));
assertThat(secretBinds.get(0).file().mode(), is(0640L));
assertThat(secretBinds.get(1).secretName(), is("Password"));
assertThat(secretBinds.get(1).secretId(), is("password-secret-id"));
assertThat(secretBinds.get(1).file().name(), is("passwd"));
assertThat(secretBinds.get(1).file().uid(), is("uid"));
assertThat(secretBinds.get(1).file().gid(), is("gid"));
assertThat(secretBinds.get(1).file().mode(), is(0640L));
}
示例5: shouldErrorOutWhenSecretDoesNotExist
import com.spotify.docker.client.messages.swarm.Secret; //导入依赖的package包/类
@Test
public void shouldErrorOutWhenSecretDoesNotExist() throws Exception {
final DockerSecrets dockerSecrets = DockerSecrets.fromString("src=Username\nsrc=Password");
final Secret secret = mock(Secret.class);
when(secret.secretSpec()).thenReturn(SecretSpec.builder().name("Username").build());
when(secret.id()).thenReturn("secret-id");
thrown.expect(RuntimeException.class);
thrown.expectMessage("Secret with name `Password` does not exist.");
dockerSecrets.toSecretBind(asList(secret));
}
示例6: listSecrets
import com.spotify.docker.client.messages.swarm.Secret; //导入依赖的package包/类
@Override
public List<Secret> listSecrets() {
throw new IllegalStateException(DISCONNECTED);
}
示例7: inspectSecret
import com.spotify.docker.client.messages.swarm.Secret; //导入依赖的package包/类
@Override
public Secret inspectSecret(String string) {
throw new IllegalStateException(DISCONNECTED);
}