-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
.bazelrc: support .user-bazelrc for optional artifacts
Signed-off-by: Øyvind Harboe <[email protected]>
- Loading branch information
Showing
3 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
build --incompatible_strict_action_env | ||
try-import %workspace%/.user-bazelrc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
bazel-* | ||
copyright.txt | ||
build/ | ||
.user-bazelrc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import subprocess | ||
import json | ||
import re | ||
import sys | ||
|
||
|
||
def get_gcloud_auth_token(): | ||
with open(".user-bazelrc") as f: | ||
all = f.read() | ||
# The username is in the .user-bazelrc file as "# user: <username>" | ||
# fish it out using a regex | ||
USER = re.search(r"# user: (.*)", all).group(1) | ||
|
||
# Run gcloud command to get the authentication token | ||
result = subprocess.run( | ||
["gcloud", "auth", "print-access-token", USER], | ||
capture_output=True, text=True, check=True) | ||
token = result.stdout.strip() | ||
return token | ||
|
||
|
||
def generate_credentials(): | ||
# Get the Bearer token from gcloud | ||
bearer_token = get_gcloud_auth_token() | ||
|
||
# Create the JSON object with the required format | ||
credentials = { | ||
"headers": { | ||
"Authorization": [f"Bearer {bearer_token}"] | ||
} | ||
} | ||
return credentials | ||
|
||
|
||
def main(): | ||
if len(sys.argv) != 2 or sys.argv[1] != "get": | ||
sys.exit("Usage: python credential_helper.py get") | ||
|
||
credentials = generate_credentials() | ||
print(json.dumps(credentials, indent=2)) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |