@@ -126,12 +126,22 @@ private static String getDefaultCredentialsFilePath() {
126126 * @throws IOException thrown when a file can not be found
127127 */
128128 public static ServiceAccountKey setupKeyFlow (CoreConfiguration cfg )
129- throws CredentialsInFileNotFoundException , IOException {
129+ throws IOException {
130130 return setupKeyFlow (cfg , new EnvironmentVariables ());
131131 }
132132
133+ /**
134+ * Sets up the KeyFlow Authentication
135+ *
136+ * @param cfg Configuration
137+ * @param env Environment variables
138+ * @return Service account key
139+ * @throws CredentialsInFileNotFoundException thrown when no service account key or private key
140+ * can be found
141+ * @throws IOException thrown when a file can not be found
142+ */
133143 protected static ServiceAccountKey setupKeyFlow (CoreConfiguration cfg , EnvironmentVariables env )
134- throws CredentialsInFileNotFoundException , IOException {
144+ throws IOException {
135145 // Explicit config in code
136146 if (Utils .isStringSet (cfg .getServiceAccountKey ())) {
137147 ServiceAccountKey saKey = ServiceAccountKey .loadFromJson (cfg .getServiceAccountKey ());
@@ -184,13 +194,21 @@ protected static ServiceAccountKey setupKeyFlow(CoreConfiguration cfg, Environme
184194 return saKey ;
185195 }
186196
197+ /**
198+ * Loads the private key into the service account key
199+ *
200+ * @param cfg Configuration
201+ * @param env Environment variables
202+ * @param saKey Service account key
203+ * @throws PrivateKeyNotFoundException if the private key could not be found
204+ */
187205 protected static void loadPrivateKey (
188- CoreConfiguration cfg , EnvironmentVariables env , ServiceAccountKey saKey )
189- throws PrivateKeyNotFoundException {
190- if (!saKey . getCredentials () .isPrivateKeySet ()) {
206+ CoreConfiguration cfg , EnvironmentVariables env , ServiceAccountKey saKey ) {
207+ ServiceAccountCredentials credentials = saKey . getCredentials ();
208+ if (!credentials .isPrivateKeySet ()) {
191209 try {
192210 String privateKey = getPrivateKey (cfg , env );
193- saKey . getCredentials () .setPrivateKey (privateKey );
211+ credentials .setPrivateKey (privateKey );
194212 } catch (CredentialsInFileNotFoundException | IOException e ) {
195213 throw new PrivateKeyNotFoundException ("could not find private key" , e );
196214 }
@@ -228,7 +246,7 @@ protected static void loadPrivateKey(
228246 * pathKey can not be found
229247 */
230248 private static String getPrivateKey (CoreConfiguration cfg , EnvironmentVariables env )
231- throws CredentialsInFileNotFoundException , IOException {
249+ throws IOException {
232250 // Explicit code config
233251 // Get private key
234252 if (Utils .isStringSet (cfg .getPrivateKey ())) {
@@ -286,7 +304,7 @@ private static String getPrivateKey(CoreConfiguration cfg, EnvironmentVariables
286304 */
287305 protected static String readValueFromCredentialsFile (
288306 String path , String valueKey , String pathKey )
289- throws IOException , CredentialsInFileNotFoundException {
307+ throws IOException {
290308 // Read credentials file
291309 String fileContent =
292310 new String (Files .readAllBytes (Paths .get (path )), StandardCharsets .UTF_8 );
0 commit comments