Skip to content

Commit

Permalink
ping instance on provider init to prevent panic
Browse files Browse the repository at this point in the history
  • Loading branch information
Dillon Giacoppo committed May 6, 2019
1 parent e093499 commit 9aa76dd
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion pkg/artifactory/provider.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package artifactory

import (
"context"
"fmt"
"net/http"

Expand Down Expand Up @@ -113,5 +114,15 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {
return nil, fmt.Errorf("either [username, password] or [api_key] or [access_token] must be set to use provider")
}

return artifactory.NewClient(d.Get("url").(string), client)
rt, err := artifactory.NewClient(d.Get("url").(string), client)

if err != nil {
return nil, err
} else if _, resp, err := rt.V1.System.Ping(context.Background()); err != nil {
return nil, err
} else if resp.StatusCode != 200 {
return nil, fmt.Errorf("failed to ping server. Got %d", resp.StatusCode)
}

return rt, nil
}

0 comments on commit 9aa76dd

Please sign in to comment.