本文整理匯總了Golang中github.com/concourse/go-concourse/concourse.Client.URL方法的典型用法代碼示例。如果您正苦於以下問題:Golang Client.URL方法的具體用法?Golang Client.URL怎麽用?Golang Client.URL使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/concourse/go-concourse/concourse.Client
的用法示例。
在下文中一共展示了Client.URL方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: loginWith
func (command *LoginCommand) loginWith(method atc.AuthMethod, client concourse.Client) error {
var token atc.AuthToken
switch method.Type {
case atc.AuthTypeOAuth:
fmt.Println("navigate to the following URL in your browser:")
fmt.Println("")
fmt.Printf(" %s\n", method.AuthURL)
fmt.Println("")
for {
var tokenStr string
err := interact.NewInteraction("enter token").Resolve(interact.Required(&tokenStr))
if err != nil {
return err
}
segments := strings.SplitN(tokenStr, " ", 2)
if len(segments) != 2 {
fmt.Println("token must be of the format 'TYPE VALUE', e.g. 'Bearer ...'")
continue
}
token.Type = segments[0]
token.Value = segments[1]
break
}
case atc.AuthTypeBasic:
var username string
if command.Username != "" {
username = command.Username
} else {
err := interact.NewInteraction("username").Resolve(interact.Required(&username))
if err != nil {
return err
}
}
var password string
if command.Password != "" {
password = command.Password
} else {
var interactivePassword interact.Password
err := interact.NewInteraction("password").Resolve(interact.Required(&interactivePassword))
if err != nil {
return err
}
password = string(interactivePassword)
}
newUnauthedClient := rc.NewUnauthenticatedClient(client.URL(), command.Insecure)
basicAuthClient := concourse.NewClient(
newUnauthedClient.URL(),
&http.Client{
Transport: basicAuthTransport{
username: username,
password: password,
base: newUnauthedClient.HTTPClient().Transport,
},
},
)
var err error
token, err = basicAuthClient.AuthToken()
if err != nil {
return err
}
}
return command.saveTarget(
client.URL(),
&rc.TargetToken{
Type: token.Type,
Value: token.Value,
},
)
}
示例2: Execute
func (command *LoginCommand) Execute(args []string) error {
if Fly.Target == "" {
return errors.New("name for the target must be specified (--target/-t)")
}
var client concourse.Client
var err error
if command.ATCURL != "" {
client = rc.NewUnauthenticatedClient(command.ATCURL, command.Insecure)
} else {
client, err = rc.CommandTargetClient(Fly.Target, &command.Insecure)
}
if err != nil {
return err
}
err = rc.ValidateClient(client, Fly.Target)
if err != nil {
return err
}
authMethods, err := client.ListAuthMethods()
if err != nil {
return err
}
var chosenMethod atc.AuthMethod
if command.Username != "" && command.Password != "" {
for _, method := range authMethods {
if method.Type == atc.AuthTypeBasic {
chosenMethod = method
break
}
}
if chosenMethod.Type == "" {
return errors.New("basic auth is not available")
}
} else {
switch len(authMethods) {
case 0:
return command.saveTarget(
client.URL(),
&rc.TargetToken{},
)
case 1:
chosenMethod = authMethods[0]
default:
choices := make([]interact.Choice, len(authMethods))
for i, method := range authMethods {
choices[i] = interact.Choice{
Display: method.DisplayName,
Value: method,
}
}
err = interact.NewInteraction("choose an auth method", choices...).Resolve(&chosenMethod)
if err != nil {
return err
}
}
}
return command.loginWith(chosenMethod, client)
}