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
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions gen/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,16 @@ import (
func main() {
flag.Parse()

token, ok := os.LookupEnv("MONDOO_API_TOKEN")
if !ok {
log.Fatalln(fmt.Errorf("MONDOO_API_TOKEN environment variable not set"))
}
err := generateSchema(token, ".")
err := generateSchema(".")
if err != nil {
log.Fatalln(err)
}
}

// generateSchema generates the mondoogql package in basePath.
func generateSchema(token string, basePath string) error {
func generateSchema(basePath string) error {
// fetch the graphql schema
schema, err := loadSchema(token)
schema, err := loadSchema()
if err != nil {
return err
}
Expand Down Expand Up @@ -74,7 +70,7 @@ func generateSchema(token string, basePath string) error {
}

// loadSchema loads the GraphQL schema from the Mondoo API.
func loadSchema(token string) (schema interface{}, err error) {
func loadSchema() (schema interface{}, err error) {
introspection := `
{
__schema {
Expand Down Expand Up @@ -189,7 +185,12 @@ fragment TypeRef on __Type {
}

// set headers
req.Header.Set("Authorization", "bearer "+token)
token, ok := os.LookupEnv("MONDOO_API_TOKEN")
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

}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Accept", "application/json")
req.Header.Set("Host", apiHost)
Expand Down
Loading