Skip to content

Commit 26a2662

Browse files
authored
Merge pull request #990 from GitGuardian/plalanne/-/add-default-eu-support-for-hmsl
Add default EU support for HMSL
2 parents 8d86a3a + 3b2504f commit 26a2662

File tree

2 files changed

+29
-10
lines changed

2 files changed

+29
-10
lines changed

ggshield/core/config/config.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,14 +142,15 @@ def add_ignored_match(self, *args: Any, **kwargs: Any) -> None:
142142
@property
143143
def saas_api_url(self) -> str:
144144
"""
145-
The GIM SaaS instance (used to get JWT tokens).
146-
It is not configurable, but can be overridden with the
147-
GITGUARDIAN_SAAS_URL environment variable for tests.
145+
The GIM SaaS instance used to get JWT tokens.
146+
This can be overridden with the GITGUARDIAN_SAAS_URL environment variable.
147+
If the HMSL URL is different from the default, we derive the SaaS API from it.
148+
Otherwise the SaaS API URL is actually the one derived from the dashboard
148149
"""
149-
if "api" in self.hmsl_url: # case https://api.hasmysecretleaked.[...]
150+
if self.hmsl_url != DEFAULT_HMSL_URL and "api" in self.hmsl_url:
150151
default_value = self.hmsl_url.replace("hasmysecretleaked", "gitguardian")
151-
else: # case https://hasmysecretleaked.[...]
152-
default_value = self.hmsl_url.replace("hasmysecretleaked", "api")
152+
else:
153+
default_value = self.api_url
153154

154155
return os.environ.get(
155156
"GITGUARDIAN_SAAS_URL",

tests/unit/verticals/hmsl/test_hmsl_utils.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,31 @@ def test_hmsl_other_env_config_values(isolated_fs, hmsl_no_env_vars, monkeypatch
4949
WHEN getting HasMySecretLeaked config values
5050
THEN the values are correctly set
5151
"""
52+
# If the user defines a custom HMSL URL
5253
monkeypatch.setenv(
53-
"GITGUARDIAN_HMSL_URL", "https://hasmysecretleaked.secretdomain.net"
54+
"GITGUARDIAN_HMSL_URL", "https://hasmysecretleaked.env.gitguardian.com"
5455
)
56+
# They are also expected to set a corresponding GitGuardian instance
57+
monkeypatch.setenv("GITGUARDIAN_INSTANCE", "https://dashboard.env.gitguardian.com")
5558
config = Config()
56-
assert config.hmsl_url == "https://hasmysecretleaked.secretdomain.net"
57-
assert config.hmsl_audience == "https://hasmysecretleaked.secretdomain.net"
58-
assert config.saas_api_url == "https://api.secretdomain.net"
59+
assert config.hmsl_url == "https://hasmysecretleaked.env.gitguardian.com"
60+
assert config.hmsl_audience == "https://hasmysecretleaked.env.gitguardian.com"
61+
assert config.saas_api_url == "https://api.env.gitguardian.com"
62+
63+
64+
def test_hmsl_region_specific_config_values(isolated_fs, hmsl_no_env_vars, monkeypatch):
65+
"""
66+
GIVEN another SaaS environment
67+
WHEN getting HasMySecretLeaked config values
68+
THEN the values are correctly set
69+
"""
70+
monkeypatch.setenv(
71+
"GITGUARDIAN_INSTANCE", "https://dashboard.region3.gitguardian.com"
72+
)
73+
config = Config()
74+
assert config.hmsl_url == "https://api.hasmysecretleaked.com"
75+
assert config.hmsl_audience == "https://api.hasmysecretleaked.com"
76+
assert config.saas_api_url == "https://api.region3.gitguardian.com"
5977

6078

6179
def test_no_token(isolated_fs, hmsl_no_env_vars):

0 commit comments

Comments
 (0)