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

✨ make MONDOO_API_TOKEN optional #59

Merged
merged 1 commit into from
Oct 21, 2024
Merged

✨ make MONDOO_API_TOKEN optional #59

merged 1 commit into from
Oct 21, 2024

Conversation

afiune
Copy link
Contributor

@afiune afiune commented Oct 18, 2024

If the API token is not set, we get this error:

$ make generate
echo "Ensure the MONDOO_API_TOKEN environment variable is set."
Ensure the MONDOO_API_TOKEN environment variable is set.

And when set to something, we get this:

make generate
echo "Generating code..."
Generating code...
go generate ./...
using endpoint http://127.0.0.1:8989/query
2024/10/18 16:55:10 non-200 OK status code: 401 Unauthorized body: "{\"code\":16,\"message\":\"request permission unauthenticated\"}"
exit status 1
mondoogql.go:4: running "go": exit status 1
make: *** [generate] Error 1

This code avoids setting the auth header when the API token is not needed.

Signed-off-by: Salim Afiune Maya <afiune@mondoo.com>
if ok {
req.Header.Set("Authorization", "bearer "+token)
} else {
log.Println("MONDOO_API_TOKEN environment variable not set")

Choose a reason for hiding this comment

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

what happens then if there's no api token set? wouldnt the next calls fail?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it doesn't on our dev environment. it works. look at #58

Copy link
Member

Choose a reason for hiding this comment

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

Its ok to make this optional. Right now, I think we should add a github action workflow that uses prod and re-generates the client when changes happens and open a PR. We should avoid using dev for the generation of the client.

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 for the GH action, this has been on my backlog for some time. I can look into it this week

@afiune afiune merged commit 8e59c22 into main Oct 21, 2024
4 checks passed
@afiune afiune deleted the afiune/token-optional branch October 21, 2024 15:59
@github-actions github-actions bot locked and limited conversation to collaborators Oct 21, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants