Skip to content

Commit

Permalink
✨ make MONDOO_API_TOKEN optional (#59)
Browse files Browse the repository at this point in the history
Signed-off-by: Salim Afiune Maya <[email protected]>
  • Loading branch information
afiune authored Oct 21, 2024
1 parent 9203067 commit 8e59c22
Showing 1 changed file with 10 additions and 9 deletions.
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")
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Accept", "application/json")
req.Header.Set("Host", apiHost)
Expand Down

0 comments on commit 8e59c22

Please sign in to comment.