Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(gcs): assign scopes to app default creds when needed #920

Merged
merged 1 commit into from
Apr 19, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.services.storage.Storage;
import com.google.api.services.storage.StorageScopes;
import com.netflix.spinnaker.halyard.core.provider.v1.google.GoogleCredentials;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -35,6 +36,7 @@
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Collections;

@Component
@Slf4j
Expand All @@ -57,7 +59,12 @@ public Storage googleStorage() {
String applicationName = "Spinnaker/Halyard";
HttpRequestInitializer requestInitializer;
try {
requestInitializer = GoogleCredentials.setHttpTimeout(GoogleCredential.getApplicationDefault());
GoogleCredential credential = GoogleCredential.getApplicationDefault();
if (credential.createScopedRequired()) {
credential = credential.createScoped(Collections.singleton(StorageScopes.DEVSTORAGE_FULL_CONTROL));
}
requestInitializer = GoogleCredentials.setHttpTimeout(credential);

log.info("Loaded application default credential for reading BOMs & profiles.");
} catch (Exception e) {
requestInitializer = GoogleCredentials.retryRequestInitializer();
Expand Down