Skip to content

Commit daea913

Browse files
committed
revert changes to common/ files
1 parent 59e8dd1 commit daea913

File tree

8 files changed

+57
-11
lines changed

8 files changed

+57
-11
lines changed

common/chronicle_auth.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2025 Google LLC
1+
# Copyright 2021 Google LLC
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

common/chronicle_auth_test.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2025 Google LLC
1+
# Copyright 2021 Google LLC
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -16,12 +16,13 @@
1616

1717
import os
1818
import tempfile
19+
1920
import unittest
2021
from unittest import mock
21-
22-
import chronicle_auth
2322
from google.oauth2 import service_account
2423

24+
from . import chronicle_auth
25+
2526

2627
class ChronicleAuthTest(unittest.TestCase):
2728

common/datetime_converter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2025 Google LLC
1+
# Copyright 2021 Google LLC
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

common/datetime_converter_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2025 Google LLC
1+
# Copyright 2021 Google LLC
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -17,7 +17,7 @@
1717
import datetime
1818
import unittest
1919

20-
import datetime_converter
20+
from . import datetime_converter
2121

2222

2323
class DatetimeConverterTest(unittest.TestCase):

common/project_id.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2025 Google LLC
1+
# Copyright 2024 Google LLC
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

common/project_instance.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2025 Google LLC
1+
# Copyright 2024 Google LLC
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

common/regions.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,22 @@
2020
import argparse
2121

2222
REGION_LIST = (
23+
"asia-northeast1",
2324
"asia-south1",
2425
"asia-southeast1",
2526
"australia-southeast1",
27+
"eu",
2628
"europe",
29+
"europe-west12",
2730
"europe-west2",
2831
"europe-west3",
2932
"europe-west6",
33+
"europe-west9",
34+
"me-central1",
3035
"me-central2",
3136
"me-west1",
37+
"northamerica-northeast2",
38+
"southamerica-east1",
3239
"us",
3340
)
3441

@@ -51,3 +58,21 @@ def url(base_url: str, region: str) -> str:
5158
if region != "us":
5259
base_url = base_url.replace("https://", f"https://{region}-")
5360
return base_url
61+
62+
63+
def url_always_prepend_region(base_url: str, region: str) -> str:
64+
"""Returns a regionalized URL.
65+
66+
Args:
67+
base_url: URL pointing to Chronicle API
68+
region: region in which the target project is located
69+
70+
Returns:
71+
A string containing a regionalized URL. Unlike the url() function,
72+
this function always prepends region; this function also checks whether
73+
the URL already has the region prefix, and if so, returns the URL unchanged.
74+
v1alpha samples should use this function.
75+
"""
76+
if not base_url.startswith(f"https://{region}-"):
77+
base_url = base_url.replace("https://", f"https://{region}-")
78+
return base_url

common/regions_test.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,33 @@ def test_url_asia_southeast1(self):
2626
regions.url("https://test", "asia-southeast1"),
2727
"https://asia-southeast1-test")
2828

29-
def test_url_europe(self):
29+
def test_url_eu(self):
3030
self.assertEqual(
31-
regions.url("https://test", "europe"), "https://europe-test")
31+
regions.url("https://test", "eu"), "https://eu-test")
3232

3333
def test_url_us(self):
3434
self.assertEqual(regions.url("https://test", "us"), "https://test")
3535

36+
def test_url_always_prepend_region_us(self):
37+
self.assertEqual(
38+
regions.url_always_prepend_region("https://test", "us"),
39+
"https://us-test",
40+
)
41+
42+
def test_url_always_prepend_region_e(self):
43+
self.assertEqual(
44+
regions.url_always_prepend_region("https://test", "eu"),
45+
"https://eu-test",
46+
)
47+
48+
def test_url_always_prepend_region_twice(self):
49+
url_once = regions.url_always_prepend_region("https://test", "eu")
50+
url_twice = regions.url_always_prepend_region(url_once, "eu")
51+
self.assertEqual(
52+
"https://eu-test",
53+
url_twice,
54+
)
55+
3656

3757
if __name__ == "__main__":
3858
unittest.main()

0 commit comments

Comments
 (0)