1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 // Package railsproxy implements Arvados APIs by proxying to the
6 // RailsAPI server on the local machine.
16 "git.curoverse.com/arvados.git/lib/controller/rpc"
17 "git.curoverse.com/arvados.git/sdk/go/arvados"
18 "git.curoverse.com/arvados.git/sdk/go/auth"
21 // For now, FindRailsAPI always uses the rails API running on this
23 func FindRailsAPI(cluster *arvados.Cluster) (*url.URL, bool, error) {
25 for target := range cluster.Services.RailsAPI.InternalURLs {
26 target := url.URL(target)
28 if strings.HasPrefix(target.Host, "localhost:") || strings.HasPrefix(target.Host, "127.0.0.1:") || strings.HasPrefix(target.Host, "[::1]:") {
33 return nil, false, fmt.Errorf("Services.RailsAPI.InternalURLs is empty")
35 return best, cluster.TLS.Insecure, nil
38 func NewConn(cluster *arvados.Cluster) *rpc.Conn {
39 url, insecure, err := FindRailsAPI(cluster)
43 return rpc.NewConn(cluster.ClusterID, url, insecure, provideIncomingToken)
46 func provideIncomingToken(ctx context.Context) ([]string, error) {
47 incoming, ok := ctx.Value(auth.ContextKeyCredentials).(*auth.Credentials)
49 return nil, errors.New("no token provided")
51 return incoming.Tokens, nil