Search in sources :

Example 1 with HmacKey

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);
}
Also used : HmacKeyMetadata(com.google.cloud.storage.HmacKey.HmacKeyMetadata) HmacKey(com.google.cloud.storage.HmacKey) Test(org.junit.Test)

Example 2 with HmacKey

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);
}
Also used : HmacKeyMetadata(com.google.cloud.storage.HmacKey.HmacKeyMetadata) HmacKey(com.google.cloud.storage.HmacKey) Test(org.junit.Test)

Example 3 with HmacKey

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;
}
Also used : HmacKeyMetadata(com.google.cloud.storage.HmacKey.HmacKeyMetadata) ServiceAccount(com.google.cloud.storage.ServiceAccount) Storage(com.google.cloud.storage.Storage) HmacKey(com.google.cloud.storage.HmacKey) Date(java.util.Date)

Example 4 with 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);
}
Also used : HmacKey(com.google.cloud.storage.HmacKey) Test(org.junit.Test)

Example 5 with 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());
}
Also used : HmacKeyMetadata(com.google.cloud.storage.HmacKey.HmacKeyMetadata) HmacKey(com.google.cloud.storage.HmacKey) Test(org.junit.Test)

Aggregations

HmacKey (com.google.cloud.storage.HmacKey)6 HmacKeyMetadata (com.google.cloud.storage.HmacKey.HmacKeyMetadata)5 Test (org.junit.Test)5 ServiceAccount (com.google.cloud.storage.ServiceAccount)1 Storage (com.google.cloud.storage.Storage)1 Date (java.util.Date)1