本文整理汇总了Java中com.nike.vault.client.http.HttpStatus类的典型用法代码示例。如果您正苦于以下问题:Java HttpStatus类的具体用法?Java HttpStatus怎么用?Java HttpStatus使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
HttpStatus类属于com.nike.vault.client.http包,在下文中一共展示了HttpStatus类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: list
import com.nike.vault.client.http.HttpStatus; //导入依赖的package包/类
/**
* List operation for the specified path. Will return a {@link Map} with a single entry of keys which is an
* array of strings that represents the keys at that path. If Vault returns an unexpected response code, a
* {@link VaultServerException} will be thrown with the code and error details. If an unexpected I/O error is
* encountered, a {@link VaultClientException} will be thrown wrapping the underlying exception.
* <p>
* See https://www.vaultproject.io/docs/secrets/generic/index.html for details on what the list operation returns.
* </p>
*
* @param path Path to the data
* @return Map containing the keys at that path
*/
public VaultListResponse list(final String path) {
final HttpUrl url = buildUrl(SECRET_PATH_PREFIX, path + "?list=true");
logger.debug("list: requestUrl={}", url);
final Response response = execute(url, HttpMethod.GET, null);
if (response.code() == HttpStatus.NOT_FOUND) {
response.close();
return new VaultListResponse();
} else if (response.code() != HttpStatus.OK) {
parseAndThrowErrorResponse(response);
}
final Type mapType = new TypeToken<Map<String, Object>>() {
}.getType();
final Map<String, Object> rootData = parseResponseBody(response, mapType);
return gson.fromJson(gson.toJson(rootData.get("data")), VaultListResponse.class);
}
示例2: lookupSelf
import com.nike.vault.client.http.HttpStatus; //导入依赖的package包/类
/**
* Gets all the details about the client token being used by the requester. Also serves as a simple way
* to test that a token is still active. If an unexpected response is recieved, a {@link VaultServerException}
* will be thrown with details.
*
* @return Client token details
*/
public VaultClientTokenResponse lookupSelf() {
final HttpUrl url = buildUrl(AUTH_PATH_PREFIX, "token/lookup-self");
logger.debug("lookupSelf: requestUrl={}", url);
final Response response = execute(url, HttpMethod.GET, null);
if (response.code() != HttpStatus.OK) {
parseAndThrowErrorResponse(response);
}
final Type mapType = new TypeToken<Map<String, Object>>() {
}.getType();
final Map<String, Object> rootData = parseResponseBody(response, mapType);
return gson.fromJson(gson.toJson(rootData.get("data")), VaultClientTokenResponse.class);
}
示例3: init
import com.nike.vault.client.http.HttpStatus; //导入依赖的package包/类
/**
* Initializes a new Vault. The Vault must've not been previously initialized.
*
* @param secretShares The number of shares to split the master key into
* @param secretThreshold The number of shares required to reconstruct the master key.
* This must be less than or equal to secret_shares
* @return Object including the master keys and initial root token
*/
public VaultInitResponse init(final int secretShares, final int secretThreshold) {
final HttpUrl url = buildUrl(SYS_PATH_PREFIX, "init");
final Map<String, Integer> requestBody = new HashMap<>();
requestBody.put("secret_shares", secretShares);
requestBody.put("secret_threshold", secretThreshold);
final Response response = execute(url, HttpMethod.PUT, requestBody);
if (response.code() != HttpStatus.OK) {
parseAndThrowErrorResponse(response);
}
return parseResponseBody(response, VaultInitResponse.class);
}
示例4: lookup_self_returns_client_token_details
import com.nike.vault.client.http.HttpStatus; //导入依赖的package包/类
@Test
public void lookup_self_returns_client_token_details() {
final MockResponse response = new MockResponse();
response.setResponseCode(HttpStatus.OK);
response.setBody(getResponseJson("lookup-self"));
mockWebServer.enqueue(response);
final VaultClientTokenResponse actualResponse = vaultClient.lookupSelf();
assertThat(actualResponse).isNotNull();
assertThat(actualResponse.getId()).isEqualTo("ClientToken");
assertThat(actualResponse.getPath()).isEqualTo("auth/token/create");
assertThat(actualResponse.getMeta()).hasSize(2);
assertThat(actualResponse.getPolicies()).contains("web", "stage");
assertThat(actualResponse.getDisplayName()).isEqualTo("token-foo");
assertThat(actualResponse.getNumUses()).isEqualTo(0);
}
示例5: create_token_returns_ok_if_created
import com.nike.vault.client.http.HttpStatus; //导入依赖的package包/类
@Test
public void create_token_returns_ok_if_created() {
final MockResponse response = new MockResponse();
response.setResponseCode(HttpStatus.OK);
response.setBody(getResponseJson("auth"));
mockWebServer.enqueue(response);
final VaultTokenAuthRequest request = new VaultTokenAuthRequest()
.setDisplayName("RAWR")
.setId("ABCD")
.setNoDefaultPolicy(false)
.setNoParent(false)
.setNumUses(0)
.setTtl("1h");
VaultAuthResponse actualResponse = vaultClient.createToken(request);
assertThat(actualResponse).isNotNull();
assertThat(actualResponse.getClientToken()).isEqualTo("ABCD");
assertThat(actualResponse.getLeaseDuration()).isEqualTo(3600);
assertThat(actualResponse.isRenewable()).isTrue();
assertThat(actualResponse.getPolicies()).hasSize(2);
assertThat(actualResponse.getMetadata()).hasSize(1);
}
示例6: create_token_throws_exception_if_unauthorized
import com.nike.vault.client.http.HttpStatus; //导入依赖的package包/类
@Test(expected = VaultServerException.class)
public void create_token_throws_exception_if_unauthorized() {
final MockResponse response = new MockResponse();
response.setResponseCode(HttpStatus.UNAUTHORIZED);
response.setBody(getResponseJson("error"));
mockWebServer.enqueue(response);
final VaultTokenAuthRequest request = new VaultTokenAuthRequest()
.setDisplayName("RAWR")
.setId("ID")
.setNoDefaultPolicy(false)
.setNoParent(false)
.setNumUses(0)
.setTtl("1h");
vaultClient.createToken(request);
}
示例7: create_orphan_token_returns_ok_if_created
import com.nike.vault.client.http.HttpStatus; //导入依赖的package包/类
@Test
public void create_orphan_token_returns_ok_if_created() {
final MockResponse response = new MockResponse();
response.setResponseCode(HttpStatus.OK);
response.setBody(getResponseJson("auth"));
mockWebServer.enqueue(response);
final VaultTokenAuthRequest request = new VaultTokenAuthRequest()
.setDisplayName("RAWR")
.setId("ABCD")
.setNoDefaultPolicy(false)
.setNoParent(false)
.setNumUses(0)
.setTtl("1h");
VaultAuthResponse actualResponse = vaultClient.createOrphanToken(request);
assertThat(actualResponse).isNotNull();
assertThat(actualResponse.getClientToken()).isEqualTo("ABCD");
assertThat(actualResponse.getLeaseDuration()).isEqualTo(3600);
assertThat(actualResponse.isRenewable()).isTrue();
assertThat(actualResponse.getPolicies()).hasSize(2);
assertThat(actualResponse.getMetadata()).hasSize(1);
}
示例8: create_orphan_token_throws_exception_if_unauthorized
import com.nike.vault.client.http.HttpStatus; //导入依赖的package包/类
@Test(expected = VaultServerException.class)
public void create_orphan_token_throws_exception_if_unauthorized() {
final MockResponse response = new MockResponse();
response.setResponseCode(HttpStatus.UNAUTHORIZED);
response.setBody(getResponseJson("error"));
mockWebServer.enqueue(response);
final VaultTokenAuthRequest request = new VaultTokenAuthRequest()
.setDisplayName("RAWR")
.setId("ABCD")
.setNoDefaultPolicy(false)
.setNoParent(false)
.setNumUses(0)
.setTtl("1h");
vaultClient.createOrphanToken(request);
}
示例9: lookup_token_returns_client_token_details
import com.nike.vault.client.http.HttpStatus; //导入依赖的package包/类
@Test
public void lookup_token_returns_client_token_details() {
final MockResponse response = new MockResponse();
response.setResponseCode(HttpStatus.OK);
response.setBody(getResponseJson("lookup-self"));
mockWebServer.enqueue(response);
final VaultClientTokenResponse actualResponse = vaultClient.lookupToken("ClientToken");
assertThat(actualResponse).isNotNull();
assertThat(actualResponse.getId()).isEqualTo("ClientToken");
assertThat(actualResponse.getPath()).isEqualTo("auth/token/create");
assertThat(actualResponse.getMeta()).hasSize(2);
assertThat(actualResponse.getPolicies()).contains("web", "stage");
assertThat(actualResponse.getDisplayName()).isEqualTo("token-foo");
assertThat(actualResponse.getNumUses()).isEqualTo(0);
}
示例10: getEncryptedAuthData
import com.nike.vault.client.http.HttpStatus; //导入依赖的package包/类
/**
* Retrieves the encrypted auth response from Cerberus.
*
* @param iamPrincipalArn IAM principal ARN used in the row key
* @param region Current region of the running function or instance
* @return Base64 and encrypted token
*/
protected String getEncryptedAuthData(final String iamPrincipalArn, Region region) {
final String url = urlResolver.resolve();
if (StringUtils.isBlank(url)) {
throw new VaultClientException("Unable to find the Vault URL.");
}
LOGGER.info(String.format("Attempting to authenticate with AWS IAM principal ARN [%s] against [%s]",
iamPrincipalArn, url));
try {
Request.Builder requestBuilder = new Request.Builder().url(url + "/v2/auth/iam-principal")
.addHeader(HttpHeader.ACCEPT, DEFAULT_MEDIA_TYPE.toString())
.addHeader(HttpHeader.CONTENT_TYPE, DEFAULT_MEDIA_TYPE.toString())
.addHeader(ClientVersion.CERBERUS_CLIENT_HEADER, cerberusJavaClientHeaderValue)
.method(HttpMethod.POST, buildCredentialsRequestBody(iamPrincipalArn, region));
Response response = httpClient.newCall(requestBuilder.build()).execute();
if (response.code() != HttpStatus.OK) {
parseAndThrowErrorResponse(response.code(), response.body().string());
}
final Type mapType = new TypeToken<Map<String, String>>() {
}.getType();
final Map<String, String> authData = gson.fromJson(response.body().string(), mapType);
final String key = "auth_data";
if (authData.containsKey(key)) {
LOGGER.info(String.format("Authentication successful with AWS IAM principal ARN [%s] against [%s]",
iamPrincipalArn, url));
return authData.get(key);
} else {
throw new VaultClientException("Success response from IAM role authenticate endpoint missing auth data!");
}
} catch (IOException e) {
throw new VaultClientException("I/O error while communicating with Cerberus", e);
}
}
示例11: rebootInstance
import com.nike.vault.client.http.HttpStatus; //导入依赖的package包/类
/**
* Reboot an instance and make sure it comes back healthy
*/
private void rebootInstance(StackName stackName, String autoScalingGroupId, Instance instance) {
final String healthCheckUrlTmpl = HEALTH_CHECK_MAP.get(stackName.getName());
final String healthCheckUrl = String.format(healthCheckUrlTmpl, instance.getPublicDnsName());
logger.info("Checking that instance health check is reachable...");
waitForHealthCheckStatusCode(healthCheckUrl, HttpStatus.OK, EXPECTED_NUM_SUCCESSES_BEFORE_REBOOT);
final String instanceId = instance.getInstanceId();
logger.info("Setting instance state to standby: {}", instanceId);
autoScalingService.setInstanceStateToStandby(autoScalingGroupId, instanceId);
logger.info("Rebooting instance: {}", instanceId);
ec2Service.rebootEc2Instance(instanceId);
// wait for health check fail to confirm box reboot
logger.info("Waiting for health check failure to confirm reboot...");
waitForHealthCheckStatusCode(healthCheckUrl, HEALTH_CHECK_FAILED_CODE, EXPECTED_NUM_FAILURES_AFTER_REBOOT);
// wait for health check pass to confirm instance is healthy after reboot
logger.warn(Chalk.on(
"If a proxy is required to talk to the EC2 instance, then make sure it is set up." +
" Otherwise this command will never succeed.").yellow().toString());
logger.info("Waiting for health check to pass again to confirm instance is healthy...");
waitForHealthCheckStatusCode(healthCheckUrl, HttpStatus.OK, EXPECTED_NUM_SUCCESSES_AFTER_REBOOT);
logger.info("Setting instance state to in-service: {}", instanceId);
autoScalingService.setInstanceStateToInService(autoScalingGroupId, instanceId);
}
示例12: writeJson
import com.nike.vault.client.http.HttpStatus; //导入依赖的package包/类
public void writeJson(final String path, final Map<String, Object> data) {
final HttpUrl url = buildUrl(SECRET_PATH_PREFIX, path);
final Response response = execute(url, HttpMethod.POST, data);
if (response.code() != HttpStatus.NO_CONTENT) {
parseAndThrowErrorResponse(response);
}
}
示例13: readDataGenerically
import com.nike.vault.client.http.HttpStatus; //导入依赖的package包/类
/**
* Read operation for a specified path. Will return a {@link Map} of the data stored at the specified path.
* If Vault returns an unexpected response code, a {@link VaultServerException} will be thrown with the code
* and error details. If an unexpected I/O error is encountered, a {@link VaultClientException} will be thrown
* wrapping the underlying exception.
*
* @param path Path to the data
* @return Map of the data
*/
public GenericVaultResponse readDataGenerically(final String path) {
final HttpUrl url = buildUrl(SECRET_PATH_PREFIX, path);
log.debug("read: requestUrl={}", url);
final Response response = execute(url, HttpMethod.GET, null);
if (response.code() != HttpStatus.OK) {
parseAndThrowErrorResponse(response);
}
return parseResponseBody(response, GenericVaultResponse.class);
}
示例14: read
import com.nike.vault.client.http.HttpStatus; //导入依赖的package包/类
/**
* Read operation for a specified path. Will return a {@link Map} of the data stored at the specified path.
* If Vault returns an unexpected response code, a {@link VaultServerException} will be thrown with the code
* and error details. If an unexpected I/O error is encountered, a {@link VaultClientException} will be thrown
* wrapping the underlying exception.
*
* @param path Path to the data
* @return Map of the data
*/
public VaultResponse read(final String path) {
final HttpUrl url = buildUrl(SECRET_PATH_PREFIX, path);
logger.debug("read: requestUrl={}", url);
final Response response = execute(url, HttpMethod.GET, null);
if (response.code() != HttpStatus.OK) {
parseAndThrowErrorResponse(response);
}
return parseResponseBody(response, VaultResponse.class);
}
示例15: write
import com.nike.vault.client.http.HttpStatus; //导入依赖的package包/类
/**
* Write operation for a specified path and data set. If Vault returns an unexpected response code, a
* {@link VaultServerException} will be thrown with the code and error details. If an unexpected I/O
* error is encountered, a {@link VaultClientException} will be thrown wrapping the underlying exception.
*
* @param path Path for where to store the data
* @param data Data to be stored
*/
public void write(final String path, final Map<String, String> data) {
final HttpUrl url = buildUrl(SECRET_PATH_PREFIX, path);
logger.debug("write: requestUrl={}", url);
final Response response = execute(url, HttpMethod.POST, data);
if (response.code() != HttpStatus.NO_CONTENT) {
parseAndThrowErrorResponse(response);
}
}