use of com.walmartlabs.concord.common.secret.UsernamePassword in project concord by walmartlabs.
the class GitClient method execWithCredentials.
private String execWithCredentials(Command cmd, Secret secret) {
Path key = null;
Path ssh = null;
Path askpass = null;
Map<String, String> env = new HashMap<>();
env.put("GIT_TERMINAL_PROMPT", "0");
try {
if (secret instanceof KeyPair) {
KeyPair keyPair = (KeyPair) secret;
key = createSshKeyFile(keyPair);
ssh = createUnixGitSSH(key);
env.put("GIT_SSH", ssh.toAbsolutePath().toString());
env.put("GIT_SSH_COMMAND", ssh.toAbsolutePath().toString());
// supply a dummy value for DISPLAY so ssh will invoke SSH_ASKPASS
if (!env.containsKey("DISPLAY")) {
env.put("DISPLAY", ":");
}
log.info("using GIT_SSH to set credentials");
} else if (secret instanceof UsernamePassword) {
UsernamePassword userPass = (UsernamePassword) secret;
askpass = createUnixStandardAskpass(userPass);
env.put("GIT_ASKPASS", askpass.toAbsolutePath().toString());
env.put("SSH_ASKPASS", askpass.toAbsolutePath().toString());
log.info("using GIT_ASKPASS to set credentials ");
} else if (secret instanceof BinaryDataSecret) {
BinaryDataSecret token = (BinaryDataSecret) secret;
askpass = createUnixStandardAskpass(new UsernamePassword(new String(token.getData()), "".toCharArray()));
env.put("GIT_ASKPASS", askpass.toAbsolutePath().toString());
log.info("using GIT_ASKPASS to set credentials ");
}
env.put("GIT_HTTP_LOW_SPEED_LIMIT", String.valueOf(cfg.httpLowSpeedLimit()));
env.put("GIT_HTTP_LOW_SPEED_TIME", String.valueOf(cfg.httpLowSpeedTime().getSeconds()));
return exec(Command.builder().from(cmd).putAllEnv(env).build());
} catch (IOException e) {
throw new RepositoryException("Failed to setup credentials", e);
} finally {
deleteTempFile(key);
deleteTempFile(ssh);
deleteTempFile(askpass);
}
}
use of com.walmartlabs.concord.common.secret.UsernamePassword in project concord by walmartlabs.
the class SecretIT method testSecretDataUpdate.
@Test
public void testSecretDataUpdate() throws Exception {
String orgName = "org_" + randomString();
OrganizationsApi orgApi = new OrganizationsApi(getApiClient());
orgApi.createOrUpdate(new OrganizationEntry().setName(orgName));
// ---
String secretName = "secret_" + randomString();
generateKeyPair(orgName, null, secretName, false, null);
// ---
UpdateSecretRequest request = UpdateSecretRequest.builder().usernamePassword(CreateSecretRequest.UsernamePassword.of("test", "q1")).build();
SecretClient secretClient = new SecretClient(getApiClient());
secretClient.updateSecret(orgName, secretName, request);
UsernamePassword up = secretClient.getData(orgName, secretName, null, SecretEntry.TypeEnum.USERNAME_PASSWORD);
assertNotNull(up);
assertEquals("test", up.getUsername());
assertArrayEquals("q1".toCharArray(), up.getPassword());
}
use of com.walmartlabs.concord.common.secret.UsernamePassword in project concord by walmartlabs.
the class SecretServiceImpl method exportCredentials.
@Override
public Map<String, String> exportCredentials(Context ctx, String instanceId, String workDir, String orgName, String name, String password) throws Exception {
UsernamePassword up = get(ctx, orgName, name, password, SecretEntry.TypeEnum.USERNAME_PASSWORD);
Map<String, String> m = new HashMap<>();
m.put("username", up.getUsername());
m.put("password", new String(up.getPassword()));
return m;
}
use of com.walmartlabs.concord.common.secret.UsernamePassword in project concord by walmartlabs.
the class SecretManager method createUsernamePassword.
/**
* Stores a new username and password secret.
*/
public DecryptedUsernamePassword createUsernamePassword(UUID orgId, UUID projectId, String name, String storePassword, String username, char[] password, SecretVisibility visibility, String secretStoreType) {
orgManager.assertAccess(orgId, true);
UsernamePassword p = buildUsernamePassword(username, password);
UUID id = create(name, orgId, projectId, p, storePassword, visibility, secretStoreType, INSERT);
return new DecryptedUsernamePassword(id);
}
Aggregations