Skip to content

Commit

Permalink
chore(deps): update dependency com.google.cloud:libraries-bom to v24.…
Browse files Browse the repository at this point in the history
…2.0 (#1204)

* chore(deps): update dependency com.google.cloud:libraries-bom to v24.2.0

* 🦉 Updates from OwlBot

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

* chore: make hmac key cleanup more robust

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
Co-authored-by: BenWhitehead <BenWhitehead@users.noreply.github.com>
  • Loading branch information
3 people committed Jan 11, 2022
1 parent af11cf8 commit ece0fe5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -19,7 +19,7 @@ If you are using Maven with [BOM][libraries-bom], add this to your pom.xml file
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>libraries-bom</artifactId>
<version>24.1.2</version>
<version>24.2.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand Down
Expand Up @@ -69,6 +69,7 @@
import com.google.cloud.storage.Cors;
import com.google.cloud.storage.DataGeneration;
import com.google.cloud.storage.HmacKey;
import com.google.cloud.storage.HmacKey.HmacKeyState;
import com.google.cloud.storage.HttpMethod;
import com.google.cloud.storage.PostPolicyV4;
import com.google.cloud.storage.PostPolicyV4.PostFieldsV4;
Expand Down Expand Up @@ -2426,8 +2427,11 @@ public void testBlobAcl() {

@Test
public void testHmacKey() {
ServiceAccount serviceAccount = ServiceAccount.of(System.getenv("IT_SERVICE_ACCOUNT_EMAIL"));
String serviceAccountEmail = System.getenv("IT_SERVICE_ACCOUNT_EMAIL");
assertNotNull("Unable to determine service account email", serviceAccountEmail);
ServiceAccount serviceAccount = ServiceAccount.of(serviceAccountEmail);
try {
cleanUpHmacKeys(serviceAccount);

HmacKey hmacKey = storage.createHmacKey(serviceAccount);
String secretKey = hmacKey.getSecretKey();
Expand Down Expand Up @@ -2500,10 +2504,18 @@ public void testHmacKey() {

assertEquals(2, Iterators.size(metadatas.getValues().iterator()));
} finally {
Page<HmacKey.HmacKeyMetadata> metadatas =
storage.listHmacKeys(Storage.ListHmacKeysOption.serviceAccount(serviceAccount));
for (HmacKey.HmacKeyMetadata hmacKeyMetadata : metadatas.iterateAll()) {
storage.updateHmacKeyState(hmacKeyMetadata, HmacKey.HmacKeyState.INACTIVE);
cleanUpHmacKeys(serviceAccount);
}
}

private void cleanUpHmacKeys(ServiceAccount serviceAccount) {
Page<HmacKey.HmacKeyMetadata> metadatas =
storage.listHmacKeys(Storage.ListHmacKeysOption.serviceAccount(serviceAccount));
for (HmacKey.HmacKeyMetadata hmacKeyMetadata : metadatas.iterateAll()) {
if (hmacKeyMetadata.getState() == HmacKeyState.ACTIVE) {
hmacKeyMetadata = storage.updateHmacKeyState(hmacKeyMetadata, HmacKeyState.INACTIVE);
}
if (hmacKeyMetadata.getState() == HmacKeyState.INACTIVE) {
storage.deleteHmacKey(hmacKeyMetadata);
}
}
Expand Down
2 changes: 1 addition & 1 deletion samples/snippets/pom.xml
Expand Up @@ -30,7 +30,7 @@
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>libraries-bom</artifactId>
<version>24.1.2</version>
<version>24.2.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand Down

0 comments on commit ece0fe5

Please sign in to comment.