github.com/Venafi/vcert/v5@v5.10.2/examples/simple-cli/vars.go (about)

     1  /*
     2   * Copyright 2018 Venafi, 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 main
    18  
    19  import (
    20  	"encoding/json"
    21  	"fmt"
    22  	"io/ioutil"
    23  	"log"
    24  	"os"
    25  
    26  	"github.com/Venafi/vcert/v5"
    27  	"github.com/Venafi/vcert/v5/pkg/endpoint"
    28  )
    29  
    30  var mockConfig, cloudConfig, tppConfig *vcert.Config
    31  
    32  var dummy_pass = "CyberArkT3stP4ZZC0de%jQX^J=4H"
    33  
    34  func init() {
    35  	mockConfig = &vcert.Config{
    36  		ConnectorType: endpoint.ConnectorTypeFake,
    37  	}
    38  
    39  	cloudConfig = &vcert.Config{
    40  		ConnectorType: endpoint.ConnectorTypeCloud,
    41  		BaseUrl:       os.Getenv("CLOUD_URL"),
    42  		Credentials:   &endpoint.Authentication{APIKey: os.Getenv("CLOUD_APIKEY")},
    43  		Zone:          os.Getenv("CLOUD_ZONE"),
    44  	}
    45  
    46  	tppConfig = &vcert.Config{
    47  		ConnectorType: endpoint.ConnectorTypeTPP,
    48  		BaseUrl:       os.Getenv("TPP_URL"),
    49  		Credentials: &endpoint.Authentication{
    50  			User:     os.Getenv("TPP_USER"),
    51  			Password: os.Getenv("TPP_PASSWORD")},
    52  		Zone: os.Getenv("TPP_ZONE"),
    53  	}
    54  	trustBundleFilePath := os.Getenv("TRUST_BUNDLE_PATH")
    55  	if trustBundleFilePath != "" {
    56  		buf, err := ioutil.ReadFile(trustBundleFilePath)
    57  		if err != nil {
    58  			panic(err)
    59  		}
    60  		tppConfig.ConnectionTrust = string(buf)
    61  	}
    62  
    63  }
    64  
    65  var pp = func(a interface{}) {
    66  	b, err := json.MarshalIndent(a, "", "    ")
    67  	if err != nil {
    68  		fmt.Println("error:", err)
    69  	}
    70  	log.Println(string(b))
    71  }