Skip to content

Commit 8670c91

Browse files
authored
Merge branch 'main' into default-checksum-json-read
2 parents 2ac63c7 + da1ccb1 commit 8670c91

8 files changed

Lines changed: 880 additions & 260 deletions

File tree

.github/workflows/update_librarian_googleapis.yaml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,18 @@ jobs:
5757
uses: actions/setup-go@v5
5858
with:
5959
go-version: '>=1.20.2'
60-
- name: Run librarian update
60+
- name: Get librarian version
61+
id: librarian
6162
run: |
6263
version=$(go run github.com/googleapis/librarian/cmd/librarian@latest config get version)
63-
go run "github.com/googleapis/librarian/cmd/librarian@${version}" update sources.googleapis
64+
echo "version=${version}" >> $GITHUB_OUTPUT
65+
- name: Run librarian update
66+
run: |
67+
go run "github.com/googleapis/librarian/cmd/librarian@${{ steps.librarian.outputs.version }}" update sources.googleapis
6468
- name: Get latest commit
6569
id: commit
6670
run: |
67-
version=$(go run github.com/googleapis/librarian/cmd/librarian@latest config get version)
68-
new_commit=$(go run "github.com/googleapis/librarian/cmd/librarian@${version}" config get sources.googleapis.commit)
71+
new_commit=$(go run "github.com/googleapis/librarian/cmd/librarian@${{ steps.librarian.outputs.version }}" config get sources.googleapis.commit)
6972
echo "new_commit=${new_commit}" >> $GITHUB_OUTPUT
7073
echo "short_commit=${new_commit:0:7}" >> $GITHUB_OUTPUT
7174
# TODO(https://github.com/googleapis/librarian/issues/6220): Remove this step.
@@ -115,14 +118,14 @@ jobs:
115118
- name: Run librarian install
116119
if: steps.detect_librarian.outputs.has_changes == 'true'
117120
run: |
118-
go run github.com/googleapis/librarian/cmd/librarian@latest install
121+
go run "github.com/googleapis/librarian/cmd/librarian@${{ steps.librarian.outputs.version }}" install
119122
echo "$HOME/.cache/librarian/bin/java_tools/bin" >> $GITHUB_PATH
120123
env:
121124
PYTHONPATH: ${{ github.workspace }}/sdk-platform-java/hermetic_build/library_generation/owlbot
122125
- name: Generate Libraries
123126
if: steps.detect_librarian.outputs.has_changes == 'true'
124127
run: |
125-
go run github.com/googleapis/librarian/cmd/librarian@latest generate --all
128+
go run "github.com/googleapis/librarian/cmd/librarian@${{ steps.librarian.outputs.version }}" generate --all
126129
- name: Commit and Create PR
127130
if: steps.detect_librarian.outputs.has_changes == 'true'
128131
env:

google-auth-library-java/oauth2_http/java/com/google/auth/oauth2/DefaultCredentialsProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ private final GoogleCredentials getDefaultCredentialsUnsynchronized(
239239
return credentials;
240240
}
241241

242-
private final File getWellKnownCredentialsFile() {
242+
private final File getWellKnownCredentialsFile() throws IOException {
243243
return GoogleAuthUtils.getWellKnownCredentialsFile(this);
244244
}
245245

google-auth-library-java/oauth2_http/java/com/google/auth/oauth2/GoogleAuthUtils.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
package com.google.auth.oauth2;
3333

3434
import java.io.File;
35+
import java.io.IOException;
3536

3637
/**
3738
* This public class provides shared utilities for common OAuth2 utils or ADC. It also exposes
@@ -45,7 +46,7 @@ public class GoogleAuthUtils {
4546
* @return the path to the well-known Application Default Credentials file location
4647
*/
4748
public static final String getWellKnownCredentialsPath() {
48-
return getWellKnownCredentialsFile(DefaultCredentialsProvider.DEFAULT).getAbsolutePath();
49+
return getWellKnownCredentialsPath(DefaultCredentialsProvider.DEFAULT);
4950
}
5051

5152
/**
@@ -54,7 +55,11 @@ public static final String getWellKnownCredentialsPath() {
5455
* @return the path to the well-known Application Default Credentials file location
5556
*/
5657
static final String getWellKnownCredentialsPath(DefaultCredentialsProvider provider) {
57-
return getWellKnownCredentialsFile(provider).getAbsolutePath();
58+
try {
59+
return getWellKnownCredentialsFile(provider).getAbsolutePath();
60+
} catch (IOException e) {
61+
throw new RuntimeException(e);
62+
}
5863
}
5964

6065
/**
@@ -64,13 +69,18 @@ static final String getWellKnownCredentialsPath(DefaultCredentialsProvider provi
6469
* purposes)
6570
* @return the well-known Application Default Credentials file
6671
*/
67-
static final File getWellKnownCredentialsFile(DefaultCredentialsProvider provider) {
72+
static final File getWellKnownCredentialsFile(DefaultCredentialsProvider provider)
73+
throws IOException {
6874
File cloudConfigPath;
6975
String envPath = provider.getEnv("CLOUDSDK_CONFIG");
7076
if (envPath != null) {
7177
cloudConfigPath = new File(envPath);
7278
} else if (provider.getOsName().indexOf("windows") >= 0) {
73-
File appDataPath = new File(provider.getEnv("APPDATA"));
79+
String appData = provider.getEnv("APPDATA");
80+
if (appData == null) {
81+
throw new IOException(DefaultCredentialsProvider.CLOUDSDK_MISSING_CREDENTIALS);
82+
}
83+
File appDataPath = new File(appData);
7484
cloudConfigPath = new File(appDataPath, provider.CLOUDSDK_CONFIG_DIRECTORY);
7585
} else {
7686
File configPath = new File(provider.getProperty("user.home", ""), ".config");

google-auth-library-java/oauth2_http/javatests/com/google/auth/oauth2/DefaultCredentialsProviderTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,20 @@ void getDefaultCredentials_noCredentials_throws() {
115115
assertEquals(DefaultCredentialsProvider.CLOUDSDK_MISSING_CREDENTIALS, message);
116116
}
117117

118+
@Test
119+
void getDefaultCredentials_windowsMissingAppData_throws() {
120+
// When APPDATA is unset on Windows, the ADC resolution should fail gracefully
121+
// with a structured missing credentials exception, rather than crashing with an NPE.
122+
MockHttpTransportFactory transportFactory = new MockHttpTransportFactory();
123+
TestDefaultCredentialsProvider testProvider = new TestDefaultCredentialsProvider();
124+
testProvider.setProperty("os.name", "windows");
125+
testProvider.setEnv("APPDATA", null);
126+
127+
IOException e =
128+
assertThrows(IOException.class, () -> testProvider.getDefaultCredentials(transportFactory));
129+
assertEquals(DefaultCredentialsProvider.CLOUDSDK_MISSING_CREDENTIALS, e.getMessage());
130+
}
131+
118132
@Test
119133
void getDefaultCredentials_noCredentialsSandbox_throwsNonSecurity() {
120134
MockHttpTransportFactory transportFactory = new MockHttpTransportFactory();

0 commit comments

Comments
 (0)