Skip to content
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

feat: error checking for initial API token call #1080

Merged
merged 3 commits into from Feb 8, 2024

Conversation

MrGiga
Copy link
Contributor

@MrGiga MrGiga commented Feb 6, 2024

Description

If the API token is invalid or expired, the current implementation does not return that error to inform the end user. This implementation adds error checking, returns that error and then does not continue. This should make debugging much easier compared to it's current state. From my research there are two possible error formats.

First error response: 401 unauthorized
{"message":"401 Unauthorized"}

Second possible error response: Token has expired
{"error":"invalid_token","error_description":"Token is expired. You can either do re-authorization or token refresh."}

Migrations required

None

Verification

Provide a bad or expired API token to the module. It should fail and output the reason for failure.

Copy link
Contributor

github-actions bot commented Feb 6, 2024

Hey @MrGiga! 👋

Thank you for your contribution to the project. Please refer to the contribution rules for a quick overview of the process.

Make sure that this PR clearly explains:

  • the problem being solved
  • the best way a reviewer and you can test your changes

With submitting this PR you confirm that you hold the rights of the code added and agree that it will published under this LICENSE.

The following ChatOps commands are supported:

  • /help: notifies a maintainer to help you out

Simply add a comment with the command in the first line. If you need to pass more information, separate it with a blank line from the command.

This message was generated automatically. You are welcome to improve it.

@MrGiga MrGiga changed the title Error checking for API runner registration !feat Error checking for API runner registration Feb 6, 2024
@MrGiga MrGiga changed the title !feat Error checking for API runner registration feat: Error checking for API runner registration Feb 6, 2024
@MrGiga MrGiga changed the title feat: Error checking for API runner registration feat: error checking for initial API token call Feb 6, 2024
@MrGiga MrGiga marked this pull request as ready for review February 6, 2024 21:26
@MrGiga
Copy link
Contributor Author

MrGiga commented Feb 6, 2024

Code is slightly incomplete due to the following:

  1. Is there specific semantics that the error output needs to follow?
  2. What should be outputted to cover scenario where token is null and there is no message or error_description? Currently it just continues.

@kayman-mk
Copy link
Collaborator

Code is slightly incomplete due to the following:

  1. Is there specific semantics that the error output needs to follow?
    No. It's fine as it is.
  1. What should be outputted to cover scenario where token is null and there is no message or error_description? Currently it just continues.
    I think, we ignore this for now, as the GitLab API specification says, that this is the format of error messages. So we can expect an error message. By the way: Good job to include the error_description as well!

https://docs.gitlab.com/ee/api/rest/#sudo
https://docs.gitlab.com/ee/api/rest/#data-validation-and-error-reporting

Copy link
Collaborator

@kayman-mk kayman-mk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for contributing. This makes the debugging of the registration process easier.

template/gitlab-runner.tftpl Outdated Show resolved Hide resolved
@kayman-mk kayman-mk merged commit 6b3740a into cattle-ops:main Feb 8, 2024
19 checks passed
kayman-mk pushed a commit that referenced this pull request Feb 15, 2024
🤖 I have created a release *beep* *boop*
---


##
[7.4.0](7.3.1...7.4.0)
(2024-02-15)


### Features

* error checking for initial API token call
([#1080](#1080))
([6b3740a](6b3740a))


### Bug Fixes

* rename `pull_policies` to `pull_policy` in `config.toml`
([#1084](#1084))
([df39014](df39014))
* repair errors in startup shell script
([#1087](#1087))
([9b7c465](9b7c465))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

---------

Co-authored-by: cattle-ops-releaser-2[bot] <134548870+cattle-ops-releaser-2[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
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.

None yet

2 participants