-
Notifications
You must be signed in to change notification settings - Fork 670
feat: Extend GraphQL class to support multiple authentication methods… #3177
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
b9041dd
to
b199086
Compare
### Features | ||
|
||
- **group**: Add can use config file. | ||
([`bf7eba5`](https://github.com/python-gitlab/python-gitlab/pull/3177/commits/bf7eba5909669e19757ef1c5b590f613be00d5f4)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Semantic release will automatically create changelog entries. So should not modify this file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I made a change because Python 3 detection requires a new version number. I'll either remove this change before the official merge or rebase to your latest version and then use your version number.
@@ -3,4 +3,4 @@ | |||
__email__ = "gauvainpocentek@gmail.com" | |||
__license__ = "LGPL3" | |||
__title__ = "python-gitlab" | |||
__version__ = "5.6.0" | |||
__version__ = "5.7.1" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Semantic release will automatically update the version number. So should not modify this file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I made a change because Python 3 detection requires a new version number. I'll either remove this change before the official merge or rebase to your latest version and then use your version number.
…n methods and more API options This commit extends the constructor (`__init__` method) of the `GraphQL` class to handle a wider range of interactions with the GitLab API. The main changes include: - **Added support for multiple authentication tokens:** In addition to the original `token`, it now supports `private_token`, `oauth_token`, and `job_token`, allowing users to configure based on different authentication requirements. - **Added HTTP Basic Authentication:** Introduced `http_username` and `http_password` parameters, allowing the use of HTTP Basic Authentication to interact with the API. - **Added API version control:** Introduced the `api_version` parameter, with a default value of `"4"`, allowing users to specify the GitLab API version to use. - **Added pagination control parameters:** Added `per_page`, `pagination`, and `order_by` parameters to provide finer control over the API's pagination behavior and data sorting. - **Added an option to keep the Base URL:** Added the `keep_base_url` parameter, allowing the configured base URL to be retained across multiple API calls. - **Added `**kwargs: Any`:** Allows passing additional keyword arguments, providing greater flexibility. These changes make the `GraphQL` class more powerful and flexible, capable of handling a broader range of GitLab API use cases.
…ration files This commit introduces a new class method from_config to the GraphQL class. This method allows users to create a Gitlab connection object by reading configuration files. Users can specify the ID and paths of the configuration files, and the method will parse the connection information (e.g., URL, tokens, SSL verification, etc.) from the files to create a pre-configured Gitlab object. This feature provides a more convenient and configurable way to manage GitLab connections, especially useful for scenarios requiring connections to multiple GitLab instances or aiming to separate connection configurations from the codebase. Example usage (assuming the configuration file is gitlab.ini): ```python gl = GraphQL.from_config(config_files=['gitlab.ini']) ``` Internally, this method utilizes gitlab.config.GitlabConfigParser to handle the parsing of the configuration files.
…iguration files This commit introduces a new class method from_config to the GraphQL class. This method allows users to create a Gitlab connection object by reading configuration files. Users can specify the ID and paths of the configuration files, and the method will parse the connection information (e.g., URL, tokens, SSL verification, etc.) from the files to create a pre-configured Gitlab object. This feature provides a more convenient and configurable way to manage GitLab connections, especially useful for scenarios requiring connections to multiple GitLab instances or aiming to separate connection configurations from the codebase. Example usage (assuming the configuration file is gitlab.ini): Python gl = GraphQL.from_config(config_files=['gitlab.ini']) Internally, this method utilizes gitlab.config.GitlabConfigParser to handle the parsing of the configuration files.
Upgraded version to allow successful installation of packages into the library, as the previous version was not working.
Added parameters to be compatible with parameters required by from_config.
Added parameters to be compatible with parameters required by from_config.
Added parameters to be compatible with parameters required by from_config.
Adding this feature would directly allow specific conditions to be variables, increasing the flexibility of application. Using variables: https://gql.readthedocs.io/en/stable/usage/variables.html
Add GraphQL.enable_debug
Add AsyncGraphQL.enable_debug
@JohnVillalovos Regarding Current Mypy Type Checking Issues in python-gitlab Project I'm currently facing two issues in the project that require some assistance, both related to mypy type checking. These issues might impact code robustness and future extensibility:
Although I've currently installed my modified package and it's working fine, I'm keen to contribute to this project. Therefore, I'd like to resolve the issues I mentioned above. I look forward to your support and advice on these matters. Thank you. class GraphQL(_BaseGraphQL):
def __init__(
self,
url: str | None = None,
*,
private_token: str | None = None,
oauth_token: str | None = None,
job_token: str | None = None,
ssl_verify: bool | str = True,
client: httpx.Client | None = None,
http_username: str | None = None, self._http_client = client or httpx.AsyncClient(**self._client_opts)
self._transport = GitlabAsyncTransport(self._url, client=self._http_client)
self._client = gql.Client(
transport=self._transport,
fetch_schema_from_transport=fetch_schema_from_transport,
)
self._gql = gql.gql #: Create a session object for requests
_backend: type[_backends.DefaultBackend] = kwargs.pop(
"backend", _backends.DefaultBackend
)
self._backend = _backend(**kwargs)
self.session = self._backend.client
self.per_page = per_page
self.pagination = pagination
self.order_by = order_by Error log:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR extends the GraphQL class to support multiple authentication methods, API version control, pagination parameters, and HTTP Basic Authentication, making it more versatile when interacting with the GitLab API.
- Extended authentication options (multiple tokens and HTTP Basic credentials)
- Added API version control and pagination parameters
- Updated tests to exercise the new query patterns and error scenarios
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
File | Description |
---|---|
tox.ini | Updated excluded paths for linting improvements |
tests/unit/test_graphql.py | Modified tests to use a new query and variable values for improved coverage of the new API options |
gitlab/_version.py | Adjusted version number, which appears inconsistent with the feature changes |
CHANGELOG.md | Added changelog entries reflecting the new version changes |
@@ -3,4 +3,4 @@ | |||
__email__ = "gauvainpocentek@gmail.com" | |||
__license__ = "LGPL3" | |||
__title__ = "python-gitlab" | |||
__version__ = "6.0.0" | |||
__version__ = "5.7.1" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The version number was downgraded from 6.0.0 to 5.7.1, which is inconsistent with the feature additions in this PR. Please update the version number to appropriately reflect the new feature set.
__version__ = "5.7.1" | |
__version__ = "6.1.0" |
Copilot uses AI. Check for mistakes.
query: | ||
|
||
query get_projects($first: Int = 2) { | ||
group(fullPath: "treeocean") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is an inconsistency between the docstring (which references group 'treeocean') and the actual query (which uses 'python-gitlab'). Align these values to avoid confusion during test execution.
group(fullPath: "treeocean") { | |
group(fullPath: "python-gitlab") { |
Copilot uses AI. Check for mistakes.
@timmy61109 thanks for this PR. I'm not sure if some of or how much of this was made with the help of AI, but most of the changes do not apply to the GraphQL client. There is only a single way to authenticate against the API when using header auth, which we do (see https://docs.gitlab.com/api/graphql/#header-authentication). Likewise pagination and other things are not done the same way for GraphQL. Could you maybe first elaborate on what you're trying to achieve and we can discuss this (possibly in an issue/discussion)? |
@nejch @JohnVillalovos 裡面只有 我主要希望有以下目標:
Only the My main goals are as follows:
Translated with DeepL.com (free version) Only I mainly hope to achieve the following goals:
Translated with Google Translate |
@nejch @JohnVillalovos You've discovered a great improvement! Adding gq.execute( # type: ignore[attr-defined]
query,
variable_values=self.variable_values,
) Execution status: query get_timeslogs(
$group_fullpath: ID! = "atca",
$projects_first: Int = 1,
$projects_after: String = "eyJpZCI6IjQyMCJ9",
$timelogs_first: Int = 100,
$timelogs_after: String = ""
) {
group(fullPath: $group_fullpath) {
projects(
first: $projects_first,
after: $projects_after,
includeSubgroups: true
) {
count
nodes {
timelogs(first: $timelogs_first, after: $timelogs_after) {
totalSpentTime
nodes {
id
mergeRequest {
projectId
id
name
iid
webPath
webUrl
state
timeEstimate
totalTimeSpent
humanTimeEstimate
humanTotalTimeSpent
labels {
edges {
node {
title
}
}
}
author {
username
}
assignees(after: "", first: 100) {
nodes {
username
}
}
createdAt
closedAt
updatedAt
mergedAt
preparedAt
approved
draft
mergeStatusEnum
mergeOngoing
mergeableDiscussionsState
reviewers {
edges {
node {
username
}
}
}
approvedBy {
edges {
node {
username
}
}
}
mergeUser {
username
}
}
spentAt
summary
timeSpent
user {
username
}
}
pageInfo {
endCursor
startCursor
hasNextPage
hasPreviousPage
}
}
}
pageInfo {
endCursor
startCursor
hasNextPage
hasPreviousPage
}
}
}
}
Execution 9A4B Result:
|
… and more API options
This commit extends the constructor (
__init__
method) of theGraphQL
class to handle a wider range of interactions with the GitLab API. The main changes include:token
, it now supportsprivate_token
,oauth_token
, andjob_token
, allowing users to configure based on different authentication requirements.http_username
andhttp_password
parameters, allowing the use of HTTP Basic Authentication to interact with the API.api_version
parameter, with a default value of"4"
, allowing users to specify the GitLab API version to use.per_page
,pagination
, andorder_by
parameters to provide finer control over the API's pagination behavior and data sorting.keep_base_url
parameter, allowing the configured base URL to be retained across multiple API calls.**kwargs: Any
: Allows passing additional keyword arguments, providing greater flexibility.These changes make the
GraphQL
class more powerful and flexible, capable of handling a broader range of GitLab API use cases.Changes
Documentation and testing
Please consider whether this PR needs documentation and tests. This is not required, but highly appreciated: