|
1 | 1 | package com.uid2.shared.cloud; |
2 | 2 |
|
3 | | -import com.google.api.services.compute.ComputeScopes; |
4 | | -import com.google.auth.oauth2.GoogleCredentials; |
5 | 3 | import com.uid2.shared.Const; |
6 | | -import com.uid2.shared.Utils; |
7 | 4 | import io.vertx.core.json.JsonObject; |
8 | 5 | import org.slf4j.Logger; |
9 | 6 | import org.slf4j.LoggerFactory; |
10 | 7 |
|
11 | | -import java.io.ByteArrayInputStream; |
12 | 8 | import java.net.*; |
13 | 9 | import java.nio.file.Path; |
14 | | -import java.util.Collections; |
15 | 10 |
|
16 | 11 | public class CloudUtils { |
17 | 12 | private static final Logger LOGGER = LoggerFactory.getLogger(CloudUtils.class); |
@@ -49,42 +44,6 @@ public static TaggableCloudStorage createStorage(String cloudBucket) { |
49 | 44 | ); |
50 | 45 | } |
51 | 46 |
|
52 | | - public static GoogleCredentials getGoogleCredentialsFromConfig(JsonObject jsonConfig) { |
53 | | - GoogleCredentials credentials = getGoogleCredentialsFromConfigInternal(jsonConfig); |
54 | | - if (credentials != null && credentials.createScopedRequired()) { |
55 | | - // only needs compute readonly scope |
56 | | - LOGGER.info("Requesting scope: " + ComputeScopes.COMPUTE_READONLY); |
57 | | - credentials.createScoped(Collections.singletonList(ComputeScopes.COMPUTE_READONLY)); |
58 | | - } |
59 | | - return credentials; |
60 | | - } |
61 | | - |
62 | | - private static GoogleCredentials getGoogleCredentialsFromConfigInternal(JsonObject jsonConfig) { |
63 | | - if (System.getenv("GOOGLE_APPLICATION_CREDENTIALS") != null) { |
64 | | - try { |
65 | | - GoogleCredentials ret = GoogleCredentials.getApplicationDefault(); |
66 | | - LOGGER.info("Using GOOGLE_APPLICATION_CREDENTIALS from environment"); |
67 | | - return ret; |
68 | | - |
69 | | - } catch (Exception ex) { |
70 | | - LOGGER.error("Unable to read google credentials " + ex.getMessage(), ex); |
71 | | - return null; |
72 | | - } |
73 | | - } |
74 | | - |
75 | | - try { |
76 | | - String encodedCreds = jsonConfig.getString(Const.Config.GoogleCredentialsProp); |
77 | | - if (encodedCreds == null) return null; |
78 | | - byte[] credentials = Utils.decodeBase64String(encodedCreds); |
79 | | - if (credentials == null) return null; |
80 | | - GoogleCredentials ret = GoogleCredentials.fromStream(new ByteArrayInputStream(credentials)); |
81 | | - LOGGER.info("Using google_credentials provided through vertx-config (env or config)"); |
82 | | - return ret; |
83 | | - } catch (Exception ex) { |
84 | | - LOGGER.error("Unable to read google credentials " + ex.getMessage(), ex); |
85 | | - return null; |
86 | | - } |
87 | | - } |
88 | 47 |
|
89 | 48 | public static String normalizeFilePath(Path path) { |
90 | 49 | return normalizFilePath(path.toString()); |
|
0 commit comments