add support for unsigned manifests to SizedDigests() in Go SDK
[arvados.git] / sdk / go / arvados / client.go
index d6d610da91f9d48d90a5dc5d750adb9c681b47a6..36f4eb52ae298982dfa09ddf82b0cea08c2604f7 100644 (file)
@@ -10,6 +10,8 @@ import (
        "net/http"
        "net/url"
        "os"
+       "strings"
+       "time"
 )
 
 // A Client is an HTTP client with an API endpoint and a set of
@@ -20,8 +22,8 @@ import (
 // of results using List APIs.
 type Client struct {
        // HTTP client used to make requests. If nil,
-       // http.DefaultClient or InsecureHTTPClient will be used.
-       Client *http.Client
+       // DefaultSecureClient or InsecureHTTPClient will be used.
+       Client *http.Client `json:"-"`
 
        // Hostname (or host:port) of Arvados API server.
        APIHost string
@@ -32,6 +34,13 @@ type Client struct {
        // Accept unverified certificates. This works only if the
        // Client field is nil: otherwise, it has no effect.
        Insecure bool
+
+       // Override keep service discovery with a list of base
+       // URIs. (Currently there are no Client methods for
+       // discovering keep services so this is just a convenience for
+       // callers who use a Client to initialize an
+       // arvadosclient.ArvadosClient.)
+       KeepServiceURIs []string `json:",omitempty"`
 }
 
 // The default http.Client used by a Client with Insecure==true and
@@ -39,16 +48,26 @@ type Client struct {
 var InsecureHTTPClient = &http.Client{
        Transport: &http.Transport{
                TLSClientConfig: &tls.Config{
-                       InsecureSkipVerify: true}}}
+                       InsecureSkipVerify: true}},
+       Timeout: 5 * time.Minute}
+
+// The default http.Client used by a Client otherwise.
+var DefaultSecureClient = &http.Client{
+       Timeout: 5 * time.Minute}
 
 // NewClientFromEnv creates a new Client that uses the default HTTP
 // client with the API endpoint and credentials given by the
 // ARVADOS_API_* environment variables.
 func NewClientFromEnv() *Client {
+       var svcs []string
+       if s := os.Getenv("ARVADOS_KEEP_SERVICES"); s != "" {
+               svcs = strings.Split(s, " ")
+       }
        return &Client{
-               APIHost:   os.Getenv("ARVADOS_API_HOST"),
-               AuthToken: os.Getenv("ARVADOS_API_TOKEN"),
-               Insecure:  os.Getenv("ARVADOS_API_HOST_INSECURE") != "",
+               APIHost:         os.Getenv("ARVADOS_API_HOST"),
+               AuthToken:       os.Getenv("ARVADOS_API_TOKEN"),
+               Insecure:        os.Getenv("ARVADOS_API_HOST_INSECURE") != "",
+               KeepServiceURIs: svcs,
        }
 }
 
@@ -169,7 +188,7 @@ func (c *Client) httpClient() *http.Client {
        case c.Insecure:
                return InsecureHTTPClient
        default:
-               return http.DefaultClient
+               return DefaultSecureClient
        }
 }