Debian Codegraph @

config/env.go

raw symbols SCIP
1 //
2 // Copyright (c) SAS Institute Inc.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16
17 package configscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/config`/
18
19 import (
20 "errorsscip-go gomod github.com/golang/go/src go1.18 errors/"
21 "osscip-go gomod github.com/golang/go/src go1.18 os/"
22 )
23
24 // FromEnvironment tries to build a client-only config from environment variables. If none are set then returns nil.
25 func FromEnvironmentscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/config`/FromEnvironment().() (*Configscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/config`/Config#, error) {
26 remoteURL := osscip-go gomod github.com/golang/go/src go1.18 os/.Getenvscip-go gomod github.com/golang/go/src go1.18 os/Getenv().("RELIC_URL")
27 if remoteURL == "" {
28 return nil, nil
29 }
30 clientCert := osscip-go gomod github.com/golang/go/src go1.18 os/.Getenvscip-go gomod github.com/golang/go/src go1.18 os/Getenv().("RELIC_CLIENT_CERT")
31 clientKey := osscip-go gomod github.com/golang/go/src go1.18 os/.Getenvscip-go gomod github.com/golang/go/src go1.18 os/Getenv().("RELIC_CLIENT_KEY")
32 accessToken := osscip-go gomod github.com/golang/go/src go1.18 os/.Getenvscip-go gomod github.com/golang/go/src go1.18 os/Getenv().("RELIC_ACCESS_TOKEN")
33 if clientCert == "" && accessToken == "" {
34 return nil, errorsscip-go gomod github.com/golang/go/src go1.18 errors/.Newscip-go gomod github.com/golang/go/src go1.18 errors/New().("RELIC_CLIENT_CERT or RELIC_ACCESS_TOKEN must be set when RELIC_URL is set")
35 }
36 if clientKey == "" {
37 clientKey = clientCert
38 }
39 cfg := &Configscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/config`/Config#{
40 Remotescip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/config`/Config#Remote.: &RemoteConfigscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/config`/RemoteConfig#{
41 DirectoryURLscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/config`/RemoteConfig#DirectoryURL.: remoteURL,
42 KeyFilescip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/config`/RemoteConfig#KeyFile.: clientKey,
43 CertFilescip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/config`/RemoteConfig#CertFile.: clientCert,
44 AccessTokenscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/config`/RemoteConfig#AccessToken.: accessToken,
45 CaCertscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/config`/RemoteConfig#CaCert.: osscip-go gomod github.com/golang/go/src go1.18 os/.Getenvscip-go gomod github.com/golang/go/src go1.18 os/Getenv().("RELIC_CACERT"),
46 },
47 }
48 return cfg, cfg.Normalizescip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/config`/Config#Normalize().("<env>")
49 }