X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/b8be976adfabb17718dee8c569129cdf28036380..9bc524ae6d516f1be41cc8a7c6a76a96bbd9578c:/sdk/go/arvadosclient/arvadosclient.go diff --git a/sdk/go/arvadosclient/arvadosclient.go b/sdk/go/arvadosclient/arvadosclient.go index 8cdfa484bd..e3cbfcf13e 100644 --- a/sdk/go/arvadosclient/arvadosclient.go +++ b/sdk/go/arvadosclient/arvadosclient.go @@ -15,6 +15,8 @@ import ( "regexp" "strings" "time" + + "git.curoverse.com/arvados.git/sdk/go/arvados" ) type StringMatcher func(string) bool @@ -86,6 +88,12 @@ type ArvadosClient struct { // the client is outside the cluster. External bool + // Base URIs of Keep services, e.g., {"https://host1:8443", + // "https://host2:8443"}. If this is nil, Keep clients will + // use the arvados.v1.keep_services.accessible API to discover + // available services. + KeepServiceURIs []string + // Discovery document DiscoveryDoc Dict @@ -95,9 +103,28 @@ type ArvadosClient struct { Retries int } -// Create a new ArvadosClient, initialized with standard Arvados environment -// variables ARVADOS_API_HOST, ARVADOS_API_TOKEN, and (optionally) -// ARVADOS_API_HOST_INSECURE. +// New returns an ArvadosClient using the given arvados.Client +// configuration. This is useful for callers who load arvados.Client +// fields from configuration files but still need to use the +// arvadosclient.ArvadosClient package. +func New(c *arvados.Client) (*ArvadosClient, error) { + return &ArvadosClient{ + Scheme: "https", + ApiServer: c.APIHost, + ApiToken: c.AuthToken, + ApiInsecure: c.Insecure, + Client: &http.Client{Transport: &http.Transport{ + TLSClientConfig: &tls.Config{InsecureSkipVerify: c.Insecure}}}, + External: false, + Retries: 2, + lastClosedIdlesAt: time.Now(), + }, nil +} + +// MakeArvadosClient creates a new ArvadosClient using the standard +// environment variables ARVADOS_API_HOST, ARVADOS_API_TOKEN, +// ARVADOS_API_HOST_INSECURE, ARVADOS_EXTERNAL_CLIENT, and +// ARVADOS_KEEP_SERVICES. func MakeArvadosClient() (ac ArvadosClient, err error) { var matchTrue = regexp.MustCompile("^(?i:1|yes|true)$") insecure := matchTrue.MatchString(os.Getenv("ARVADOS_API_HOST_INSECURE")) @@ -113,6 +140,18 @@ func MakeArvadosClient() (ac ArvadosClient, err error) { External: external, Retries: 2} + for _, s := range strings.Split(os.Getenv("ARVADOS_KEEP_SERVICES"), " ") { + if s == "" { + continue + } + if u, err := url.Parse(s); err != nil { + return ac, fmt.Errorf("ARVADOS_KEEP_SERVICES: %q: %s", s, err) + } else if !u.IsAbs() { + return ac, fmt.Errorf("ARVADOS_KEEP_SERVICES: %q: not an absolute URI", s) + } + ac.KeepServiceURIs = append(ac.KeepServiceURIs, s) + } + if ac.ApiServer == "" { return ac, MissingArvadosApiHost }