[WIP] Use RoG token for gitlab.com API GET requests#286
[WIP] Use RoG token for gitlab.com API GET requests#286kkaarreell wants to merge 1 commit intomainfrom
Conversation
For URLs starting with https://gitlab.com/api/ use configured RoG API token. Currently, in order to be able to fetch a file from gitlab.com one has to tranform the URL into the following format: https://gitlab.com/api/v4/projects/<project_id>/repository/files/<path_to_file>/raw?ref=main where: - project path like redhat/rhel/tests/pkgname has to be URL encoded, i.e. redhat%2Frhel%2Ftests%2Fsetroubleshoot-plugins - file path has to be also URL encoded, i.e. path%2Fto%2Ffile - non-default branch has to be specified as well
Reviewer's GuideIntroduces support for automatically using the RoG API token when making GitLab.com API GET requests by extending the generic get_request function with a CLIContext, injecting the PRIVATE-TOKEN header when appropriate, and propagating the new context parameter through serialization helpers and CLI entry points. Sequence diagram for GET request with RoG token injectionsequenceDiagram
participant Caller
participant CLIContext
participant get_request
participant requests
Caller->>get_request: Call get_request(url, ctx)
get_request->>CLIContext: Access settings.rog_token
get_request->>requests: GET url with PRIVATE-TOKEN header (if applicable)
requests-->>get_request: Response
get_request-->>Caller: Return response
Class diagram for updated get_request and context propagationclassDiagram
class CLIContext {
settings: Settings
}
class Settings {
rog_token: str
}
class get_request {
+get_request(url, krb, attempts, delay, ctx, response_content)
}
class SerializableT {
+from_yaml_file(filepath)
+from_yaml_url(url, ctx)
}
class RecipeConfig {
+from_yaml_with_includes(location, ctx, stack)
}
class IssueConfig {
+from_yaml_with_include(location, ctx)
+read_file(location, ctx)
}
CLIContext --> Settings
SerializableT ..> get_request : uses
RecipeConfig ..> SerializableT : uses
IssueConfig ..> SerializableT : uses
IssueConfig ..> RecipeConfig : uses
get_request ..> CLIContext : uses
get_request ..> Settings : uses
get_request ..> requests : calls
get_request ..> HTTPKerberosAuth : uses
get_request ..> ResponseContentType : uses
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey there - I've reviewed your changes - here's some feedback:
Blocking issues:
- Detected a 'requests' call without a timeout set. By default, 'requests' calls wait until the connection is closed. This means a 'requests' call without a timeout will hang the program if a response is never received. Consider setting a timeout for all 'requests'. (link)
- Detected a 'requests' call without a timeout set. By default, 'requests' calls wait until the connection is closed. This means a 'requests' call without a timeout will hang the program if a response is never received. Consider setting a timeout for all 'requests'. (link)
General comments:
- Consider simplifying context propagation by using a shared request session or config object instead of adding
ctxto every method signature and call site. - The
get_requestimplementation only injects the token header in the non-Kerberos branch—unify the request invocation so headers are applied consistently even whenkrb=True. - Double-check that all
get_requestcallers pass the newctxargument, as any missing call sites could break GitLab API requests when the RoG token is required.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider simplifying context propagation by using a shared request session or config object instead of adding `ctx` to every method signature and call site.
- The `get_request` implementation only injects the token header in the non-Kerberos branch—unify the request invocation so headers are applied consistently even when `krb=True`.
- Double-check that all `get_request` callers pass the new `ctx` argument, as any missing call sites could break GitLab API requests when the RoG token is required.
## Individual Comments
### Comment 1
<location> `newa/__init__.py:359-362` </location>
<code_context>
r = requests.get(
url,
auth=HTTPKerberosAuth(delegate=True),
) if krb else requests.get(url, headers=headers)
</code_context>
<issue_to_address>
**security (python.requests.best-practice.use-timeout):** Detected a 'requests' call without a timeout set. By default, 'requests' calls wait until the connection is closed. This means a 'requests' call without a timeout will hang the program if a response is never received. Consider setting a timeout for all 'requests'.
```suggestion
r = requests.get(
url,
auth=HTTPKerberosAuth(delegate=True),
, timeout=30) if krb else requests.get(url, headers=headers)
```
*Source: opengrep*
</issue_to_address>
### Comment 2
<location> `newa/__init__.py:362` </location>
<code_context>
) if krb else requests.get(url, headers=headers)
</code_context>
<issue_to_address>
**security (python.requests.best-practice.use-timeout):** Detected a 'requests' call without a timeout set. By default, 'requests' calls wait until the connection is closed. This means a 'requests' call without a timeout will hang the program if a response is never received. Consider setting a timeout for all 'requests'.
```suggestion
) if krb else requests.get(url, headers=headers, timeout=30)
```
*Source: opengrep*
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| r = requests.get( | ||
| url, | ||
| auth=HTTPKerberosAuth(delegate=True), | ||
| ) if krb else requests.get(url) | ||
| ) if krb else requests.get(url, headers=headers) |
There was a problem hiding this comment.
security (python.requests.best-practice.use-timeout): Detected a 'requests' call without a timeout set. By default, 'requests' calls wait until the connection is closed. This means a 'requests' call without a timeout will hang the program if a response is never received. Consider setting a timeout for all 'requests'.
| r = requests.get( | |
| url, | |
| auth=HTTPKerberosAuth(delegate=True), | |
| ) if krb else requests.get(url) | |
| ) if krb else requests.get(url, headers=headers) | |
| r = requests.get( | |
| url, | |
| auth=HTTPKerberosAuth(delegate=True), | |
| , timeout=30) if krb else requests.get(url, headers=headers) |
Source: opengrep
| url, | ||
| auth=HTTPKerberosAuth(delegate=True), | ||
| ) if krb else requests.get(url) | ||
| ) if krb else requests.get(url, headers=headers) |
There was a problem hiding this comment.
security (python.requests.best-practice.use-timeout): Detected a 'requests' call without a timeout set. By default, 'requests' calls wait until the connection is closed. This means a 'requests' call without a timeout will hang the program if a response is never received. Consider setting a timeout for all 'requests'.
| ) if krb else requests.get(url, headers=headers) | |
| ) if krb else requests.get(url, headers=headers, timeout=30) |
Source: opengrep
For URLs starting with https://gitlab.com/api/ use configured RoG API token.
Currently, in order to be able to fetch a file from gitlab.com one has to tranform the URL into the following format:
https://gitlab.com/api/v4/projects/<project_id>/repository/files/<path_to_file>/raw?ref=main
where:
Summary by Sourcery
Introduce support for using the RoG API token for GitLab.com GET requests and propagate the CLIContext through HTTP and YAML loading functions.
Enhancements: