github.com/cloudfoundry-attic/cli-with-i18n@v6.32.1-0.20171002233121-7401370d3b85+incompatible/integration/helpers/login.go (about)

     1  package helpers
     2  
     3  import (
     4  	"fmt"
     5  	"os"
     6  	"strconv"
     7  	"strings"
     8  
     9  	. "github.com/onsi/gomega"
    10  	. "github.com/onsi/gomega/gexec"
    11  )
    12  
    13  func SetAPI() (string, string) {
    14  	apiURL := GetAPI()
    15  	skipSSLValidation := skipSSLValidation()
    16  	Eventually(CF("api", apiURL, skipSSLValidation)).Should(Exit(0))
    17  	return apiURL, skipSSLValidation
    18  }
    19  
    20  func UnsetAPI() {
    21  	Eventually(CF("api", "--unset")).Should(Exit(0))
    22  }
    23  
    24  func skipSSLValidation() string {
    25  	if skip, err := strconv.ParseBool(os.Getenv("SKIP_SSL_VALIDATION")); err == nil && !skip {
    26  		return ""
    27  	}
    28  	return "--skip-ssl-validation"
    29  }
    30  
    31  func GetAPI() string {
    32  	apiURL := os.Getenv("CF_API")
    33  	if apiURL == "" {
    34  		return "https://api.bosh-lite.com"
    35  	}
    36  	if !strings.HasPrefix(apiURL, "http") {
    37  		apiURL = fmt.Sprintf("https://%s", apiURL)
    38  	}
    39  
    40  	return apiURL
    41  }
    42  
    43  func LoginCF() string {
    44  	username, password := GetCredentials()
    45  	Eventually(CF("auth", username, password)).Should(Exit(0))
    46  
    47  	return username
    48  }
    49  
    50  func GetCredentials() (string, string) {
    51  	username := os.Getenv("CF_USERNAME")
    52  	if username == "" {
    53  		username = "admin"
    54  	}
    55  	password := os.Getenv("CF_PASSWORD")
    56  	if password == "" {
    57  		password = "admin"
    58  	}
    59  	return username, password
    60  }
    61  
    62  func LogoutCF() {
    63  	Eventually(CF("logout")).Should(Exit(0))
    64  }
    65  
    66  func TargetOrgAndSpace(org string, space string) {
    67  	Eventually(CF("target", "-o", org, "-s", space)).Should(Exit(0))
    68  }
    69  
    70  func TargetOrg(org string) {
    71  	Eventually(CF("target", "-o", org)).Should(Exit(0))
    72  }
    73  
    74  func ClearTarget() {
    75  	LogoutCF()
    76  	LoginCF()
    77  }