Skip to content

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

Open
wants to merge 20 commits into
base: main
Choose a base branch
from

Conversation

timmy61109
Copy link

@timmy61109 timmy61109 commented Apr 18, 2025

… 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.

Changes

Documentation and testing

Please consider whether this PR needs documentation and tests. This is not required, but highly appreciated:

…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant