Skip to content

Commit 76e5e22

Browse files
alecbcscmelone
andauthored
Set a global requester for the Hubcast application (llnl#239)
* remove configurability of "requesters" we currently allow users to set "requester" strings for calls to GitHub and GitLab. They don't seem to get used anywhere in the authentication process for either site, other than getting used as the user-string for each request. Rather than having to explain this nuance to the user, I propose we use `hubcast` as our user agent and simplify our configuration. The wording is confusing and heavily implies that it is of functional importance. If someone needs to figure out where a request is coming from, I think "hubcast" as the user agent, combined with signals like the github app id or github token id, is more than enough for any diagnosis. * Set REQUESTER global in Hubcast __main__ Signed-off-by: Alec Scott <alec@llnl.gov> * Swap from self.user -> self.requester for the client user-agent Signed-off-by: Alec Scott <alec@llnl.gov> Co-authored-by: Caetano Melone <cmelone@llnl.gov> --------- Signed-off-by: Alec Scott <alec@llnl.gov> Co-authored-by: Caetano Melone <melone1@llnl.gov> Co-authored-by: Caetano Melone <cmelone@llnl.gov>
1 parent 3140fb3 commit 76e5e22

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

src/hubcast/__main__.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717

1818
log = logging.getLogger(__name__)
1919

20+
# Set requester for both GitHub and GitLab clients to
21+
# identify Hubcast via the user-agent header
22+
REQUESTER = "hubcast"
23+
2024

2125
def main():
2226
app = web.Application()
@@ -70,11 +74,11 @@ def main():
7074
sys.exit(1)
7175

7276
gh_client_factory = GitHubClientFactory(
73-
conf.gh.app_id, conf.gh.privkey, conf.gh.requester, conf.gh.bot_user
77+
conf.gh.app_id, conf.gh.privkey, REQUESTER, conf.gh.bot_user
7478
)
7579
gl_client_factory = GitLabClientFactory(
7680
conf.gl.instance_url,
77-
conf.gl.requester,
81+
REQUESTER,
7882
conf.gl.token,
7983
conf.gl.callback_url,
8084
conf.gl.webhook_secret,

src/hubcast/clients/gitlab/client.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ def create_client(self, user: str):
3434
"""creates a GitLabClient for a specific user"""
3535
return GitLabClient(
3636
self.auth,
37+
self.requester,
3738
self.instance_url,
3839
self.callback_url,
3940
self.webhook_secret,
@@ -45,12 +46,14 @@ class GitLabClient:
4546
def __init__(
4647
self,
4748
auth: GitLabAuthenticator,
49+
requester: str,
4850
instance_url: str,
4951
callback_url: str,
5052
webhook_secret: str,
5153
user: str,
5254
):
5355
self.auth = auth
56+
self.requester = requester
5457
self.instance_url = instance_url
5558
self.callback_url = callback_url
5659
self.webhook_secret = webhook_secret
@@ -72,7 +75,7 @@ async def set_webhook(self, gl_fullname: str, data: Dict):
7275
async with aiohttp.ClientSession() as session:
7376
gl = gidgetlab.aiohttp.GitLabAPI(
7477
session,
75-
requester=self.user,
78+
requester=self.requester,
7679
access_token=gl_token,
7780
url=self.instance_url,
7881
)
@@ -117,7 +120,7 @@ async def get_latest_pipeline(self, gl_fullname: str, ref: str) -> int:
117120
async with aiohttp.ClientSession() as session:
118121
gl = gidgetlab.aiohttp.GitLabAPI(
119122
session,
120-
requester=self.user,
123+
requester=self.requester,
121124
access_token=gl_token,
122125
url=self.instance_url,
123126
)
@@ -141,7 +144,7 @@ async def run_pipeline(self, gl_fullname: str, ref: str) -> str:
141144
async with aiohttp.ClientSession() as session:
142145
gl = gidgetlab.aiohttp.GitLabAPI(
143146
session,
144-
requester=self.user,
147+
requester=self.requester,
145148
access_token=gl_token,
146149
url=self.instance_url,
147150
)
@@ -164,7 +167,7 @@ async def retry_pipeline_jobs(self, gl_fullname: str, pipeline_id: int) -> str:
164167
async with aiohttp.ClientSession() as session:
165168
gl = gidgetlab.aiohttp.GitLabAPI(
166169
session,
167-
requester=self.user,
170+
requester=self.requester,
168171
access_token=gl_token,
169172
url=self.instance_url,
170173
)

src/hubcast/config.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,13 @@ class GitHubConfig:
3434
def __init__(self):
3535
self.app_id = env_get("HC_GH_APP_IDENTIFIER")
3636
self.privkey = env_get("HC_GH_PRIVATE_KEY")
37-
self.requester = env_get("HC_GH_REQUESTER")
3837
self.webhook_secret = env_get("HC_GH_SECRET")
3938
self.bot_user = env_get("HC_GH_BOT_USER")
4039

4140

4241
class GitLabConfig:
4342
def __init__(self):
4443
self.instance_url = env_get("HC_GL_URL")
45-
# requester identifies the app making requests, it doesn't
46-
# perform any auth function but is included in user-agent
47-
self.requester = env_get("HC_GL_REQUESTER")
4844
self.token = env_get("HC_GL_TOKEN")
4945
self.token_type = env_get("HC_GL_TOKEN_TYPE", default="impersonation")
5046
self.webhook_secret = env_get("HC_GL_SECRET")

0 commit comments

Comments
 (0)