Skip to content

Commit

Permalink
update api and site config to use username/password API authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
mbthornton-lbl committed Nov 14, 2024
1 parent 32bc277 commit 792aab2
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
12 changes: 6 additions & 6 deletions nmdc_automation/api/nmdcapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ def __init__(self, site_configuration: Union[str, Path, SiteConfig]):
site_configuration = SiteConfig(site_configuration)
self.config = site_configuration
self._base_url = self.config.api_url
self.client_id = self.config.client_id
self.client_secret = self.config.client_secret
self.username = self.config.username
self.password = self.config.password
if self._base_url[-1] != "/":
self._base_url += "/"

Expand All @@ -71,16 +71,16 @@ def _get_token(self, *args, **kwargs):

def get_token(self):
"""
Get a token using a client id/secret.
Get a token using username/password
"""
h = {
"accept": "application/json",
"Content-Type": "application/x-www-form-urlencoded",
}
data = {
"grant_type": "client_credentials",
"client_id": self.client_id,
"client_secret": self.client_secret,
"grant_type": "password",
"client_id": self.username,
"client_secret": self.password,
}
url = self._base_url + "token"
resp = requests.post(url, headers=h, data=data).json()
Expand Down
8 changes: 4 additions & 4 deletions nmdc_automation/config/siteconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ def workflows_config(self):
return self.config_data["workflows"]["workflows_config"]

@property
def client_id(self):
return self.config_data["credentials"]["client_id"]
def username(self):
return self.config_data["credentials"]["username"]

@property
def client_secret(self):
return self.config_data["credentials"]["client_secret"]
def password(self):
return self.config_data["credentials"]["password"]

@property
def allowed_workflows(self):
Expand Down
4 changes: 2 additions & 2 deletions tests/site_configuration_test.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ activity_id_state = "/Path/to/activity_id_state"
workflows_config = "workflows.yaml"

[credentials]
client_id = "sys0wm66"
client_secret = "O8Q!64t,^xy:"
username = "nmdc_automation"
password = "xxxxxxx"
4 changes: 2 additions & 2 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ def test_config(monkeypatch, test_data_dir, base_test_dir):
assert conf.agent_state is None # not in test config
assert conf.activity_id_state
assert conf.workflows_config
assert conf.client_id
assert conf.client_secret
assert conf.username
assert conf.password
assert conf.allowed_workflows


Expand Down

0 comments on commit 792aab2

Please sign in to comment.