...

Source file src/github.com/sassoftware/relic/config/env.go

Documentation: github.com/sassoftware/relic/config

     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 config
    18  
    19  import (
    20  	"errors"
    21  	"os"
    22  )
    23  
    24  // FromEnvironment tries to build a client-only config from environment variables. If none are set then returns nil.
    25  func FromEnvironment() (*Config, error) {
    26  	remoteURL := os.Getenv("RELIC_URL")
    27  	if remoteURL == "" {
    28  		return nil, nil
    29  	}
    30  	clientCert := os.Getenv("RELIC_CLIENT_CERT")
    31  	clientKey := os.Getenv("RELIC_CLIENT_KEY")
    32  	if clientCert == "" {
    33  		return nil, errors.New("RELIC_CLIENT_CERT must be set when RELIC_URL is set")
    34  	}
    35  	if clientKey == "" {
    36  		clientKey = clientCert
    37  	}
    38  	cfg := &Config{
    39  		Remote: &RemoteConfig{
    40  			DirectoryURL: remoteURL,
    41  			KeyFile:      clientKey,
    42  			CertFile:     clientCert,
    43  			CaCert:       os.Getenv("RELIC_CACERT"),
    44  		},
    45  	}
    46  	return cfg, cfg.Normalize("<env>")
    47  }
    48  

View as plain text