From 8e59c22fe68e380f6033f8f44a2209b14aa2f84b Mon Sep 17 00:00:00 2001 From: Salim Afiune Maya Date: Mon, 21 Oct 2024 08:58:57 -0700 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20make=20MONDOO=5FAPI=5FTOKEN=20optio?= =?UTF-8?q?nal=20(#59)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Salim Afiune Maya --- gen/gen.go | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/gen/gen.go b/gen/gen.go index 016a57c..9c8afbc 100644 --- a/gen/gen.go +++ b/gen/gen.go @@ -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 } @@ -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 { @@ -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)