Skip to content

Commit

Permalink
Revert "Revert "fix: Issue #1347: ExternalAccountCredentials serializ…
Browse files Browse the repository at this point in the history
…ation is…"

This reverts commit 5a2d943.
  • Loading branch information
BigTailWolf committed Feb 6, 2024
1 parent a24e563 commit b27088f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.math.BigDecimal;
import java.net.URI;
import java.nio.charset.StandardCharsets;
Expand Down Expand Up @@ -540,6 +541,13 @@ public CredentialSource getCredentialSource() {
return credentialSource;
}

@SuppressWarnings("unused")
private void readObject(ObjectInputStream input) throws IOException, ClassNotFoundException {
// Properly deserialize the transient transportFactory.
input.defaultReadObject();
transportFactory = newInstance(transportFactoryClassName);
}

@Nullable
public String getServiceAccountImpersonationUrl() {
return serviceAccountImpersonationUrl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1117,6 +1117,9 @@ public void serialize() throws IOException, ClassNotFoundException {
testCredentials.getServiceAccountImpersonationOptions().getLifetime(),
deserializedCredentials.getServiceAccountImpersonationOptions().getLifetime());
assertSame(deserializedCredentials.clock, Clock.SYSTEM);
assertEquals(
MockExternalAccountCredentialsTransportFactory.class,
deserializedCredentials.toBuilder().getHttpTransportFactory().getClass());
}

@Test
Expand Down Expand Up @@ -1307,17 +1310,30 @@ protected TestCredentialSource(Map<String, Object> credentialSourceMap) {
}
}

@Override
public Builder toBuilder() {
return new Builder(this);
}

public static Builder newBuilder() {
return new Builder();
}

static class Builder extends ExternalAccountCredentials.Builder {
Builder() {}

Builder(TestExternalAccountCredentials credentials) {
super(credentials);
}

@Override
public TestExternalAccountCredentials build() {
return new TestExternalAccountCredentials(this);
}

public HttpTransportFactory getHttpTransportFactory() {
return transportFactory;
}
}

protected TestExternalAccountCredentials(ExternalAccountCredentials.Builder builder) {
Expand Down

0 comments on commit b27088f

Please sign in to comment.