本文整理汇总了Golang中github.com/concourse/go-concourse/concourse.Client.ListAuthMethods方法的典型用法代码示例。如果您正苦于以下问题:Golang Client.ListAuthMethods方法的具体用法?Golang Client.ListAuthMethods怎么用?Golang Client.ListAuthMethods使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/concourse/go-concourse/concourse.Client
的用法示例。
在下文中一共展示了Client.ListAuthMethods方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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)
}