github.com/dcarley/cf-cli@v6.24.1-0.20170220111324-4225ff346898+incompatible/integration/helpers/login.go (about)

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