use of com.google.cloud.storage.HmacKey in project google-cloud-java by GoogleCloudPlatform.
the class ITStorageHmacKeySnippets method testDeleteHmacKey.
@Test
public void testDeleteHmacKey() {
HmacKey hmacKey = storage.createHmacKey(ServiceAccount.of(HMAC_KEY_TEST_SERVICE_ACCOUNT));
HmacKeyMetadata metadata = storage.updateHmacKeyState(hmacKey.getMetadata(), HmacKeyState.INACTIVE);
storageSnippets.deleteHmacKey(metadata.getAccessId(), PROJECT_ID);
}
use of com.google.cloud.storage.HmacKey in project google-cloud-java by GoogleCloudPlatform.
the class ITStorageHmacKeySnippets method testGetHmacKey.
@Test
public void testGetHmacKey() {
HmacKey hmacKey = storage.createHmacKey(ServiceAccount.of(HMAC_KEY_TEST_SERVICE_ACCOUNT));
HmacKeyMetadata metadata = storageSnippets.getHmacKey(hmacKey.getMetadata().getAccessId(), PROJECT_ID);
assertNotNull(metadata);
}
use of com.google.cloud.storage.HmacKey in project google-cloud-java by GoogleCloudPlatform.
the class StorageSnippets method createHmacKey.
/**
* Example of creating an HMAC key for a service account *
*/
public HmacKey createHmacKey(String serviceAccountEmail, String projectId) throws StorageException {
// [START storage_create_hmac_key]
// Instantiate a Google Cloud Storage client
Storage storage = StorageOptions.getDefaultInstance().getService();
// The service account email for which the new HMAC key will be created.
// String serviceAccountEmail = "service-account@iam.gserviceaccount.com";
//
// The ID of the project to which the service account belongs.
// String projectId = "project-id";
ServiceAccount account = ServiceAccount.of(serviceAccountEmail);
HmacKey hmacKey = storage.createHmacKey(account, Storage.CreateHmacKeyOption.projectId(projectId));
String secret = hmacKey.getSecretKey();
HmacKeyMetadata metadata = hmacKey.getMetadata();
System.out.println("The Base64 encoded secret is: " + secret);
System.out.println("Do not miss that secret, there is no API to recover it.");
System.out.println("The HMAC key metadata is:");
System.out.println("ID: " + metadata.getId());
System.out.println("Access ID: " + metadata.getAccessId());
System.out.println("Project ID: " + metadata.getProjectId());
System.out.println("Service Account Email: " + metadata.getServiceAccount().getEmail());
System.out.println("State: " + metadata.getState().toString());
System.out.println("Time Created: " + new Date(metadata.getCreateTime()).toString());
System.out.println("Time Updated: " + new Date(metadata.getUpdateTime()).toString());
System.out.println("ETag: " + metadata.getEtag());
// [END storage_create_hmac_key]
return hmacKey;
}
use of com.google.cloud.storage.HmacKey in project google-cloud-java by GoogleCloudPlatform.
the class ITStorageHmacKeySnippets method testCreateHmacKey.
@Test
public void testCreateHmacKey() {
HmacKey hmacKey = storageSnippets.createHmacKey(HMAC_KEY_TEST_SERVICE_ACCOUNT, PROJECT_ID);
assertNotNull(hmacKey);
}
use of com.google.cloud.storage.HmacKey in project google-cloud-java by GoogleCloudPlatform.
the class ITStorageHmacKeySnippets method testDeactivateHmacKey.
@Test
public void testDeactivateHmacKey() {
HmacKey hmacKey = storage.createHmacKey(ServiceAccount.of(HMAC_KEY_TEST_SERVICE_ACCOUNT));
HmacKeyMetadata metadata = storageSnippets.deactivateHmacKey(hmacKey.getMetadata().getAccessId(), PROJECT_ID);
assertEquals(HmacKeyState.INACTIVE, metadata.getState());
}
Aggregations