Skip to content
This repository has been archived by the owner on Oct 28, 2024. It is now read-only.

Commit

Permalink
Revert "add health check" (#55)
Browse files Browse the repository at this point in the history
* Revert "add health check (#44)"

This reverts commit 3b5d037.

* Update provider.go
  • Loading branch information
umairidris authored Feb 28, 2020
1 parent e560c96 commit 00b2d07
Showing 1 changed file with 2 additions and 34 deletions.
36 changes: 2 additions & 34 deletions cdap/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ package cdap

import (
"context"
"encoding/json"
"fmt"
"log"
"net/http"
"time"

Expand Down Expand Up @@ -82,38 +79,9 @@ func configureProvider(d *schema.ResourceData) (interface{}, error) {
return nil, err
}

c := &Config{
return &Config{
host: d.Get("host").(string),
httpClient: httpClient,
storageClient: storageClient,
}

if err := healthcheck(c); err != nil {
log.Printf("failed health check, trying again after 5 seconds: %v", err)
time.Sleep(5 * time.Second)
if err := healthcheck(c); err != nil {
return nil, fmt.Errorf("failed health check, possibly due to an invalid host or credentials: %v", err)
}
}
return c, nil
}

func healthcheck(c *Config) error {
addr := urlJoin(c.host, "/v3/namespaces")
req, err := http.NewRequest(http.MethodGet, addr, nil)
if err != nil {
return err
}
b, err := httpCall(c.httpClient, req)
if err != nil {
return err
}

// Invalid credentials currently result in a redirect to sign in page instead of an error.
// So check for a valid return value by unmarshalling the JSON.
var v interface{}
if err := json.Unmarshal(b, &v); err != nil {
return fmt.Errorf("failed to unmarshal response: %v\n%v", err, string(b))
}
return nil
}, nil
}

0 comments on commit 00b2d07

Please sign in to comment.