go - 如何使用 openshift-go-client 的用户名和密码验证?
问题描述
我尝试使用 Openshift go-client 来访问 Openshift 中的对象。但是我没有通过用户名和密码进行身份验证。有谁知道如何使用具有用户名和密码身份验证的客户端?创建配置时是否忘记了任何参数?
我不想通过 Kubeconfig 进行身份验证。
我已经使用用户名和密码身份验证创建了 REST 配置。或者,我尝试了 Bearer-Token 方法,它返回了预期的结果。我尝试了以下方法:
insecureCommunication := true
restConfig := rest.Config{
Host: "https://my-url.net",
}
authInfo := auth.Info{
User: "username",
Password: "password",
Insecure: &insecureCommunication,
}
restConfig, err := authInfo.MergeWithConfig(restConfig)
buildV1Client, err := buildv1.NewForConfig(&restConfig)
if err != nil {
fmt.Println(err)
return err
}
builds, err := buildV1Client.Builds("namespace").List(metav1.ListOptions{})
if err != nil {
fmt.Println(err)
return err
}
fmt.Printf("There are %d builds in project %s\n", len(builds.Items), openshift.namespace)
// List names of all builds
for i, build := range builds.Items {
fmt.Printf("index %d: Name of the build: %s", i, build.Name)
}
我希望请求与不记名令牌一样成功。但我总是得到一个user "system:anonymous" cannot list builds.build.openshift.io in project "namespace"
错误。
有谁知道我该如何解决这个问题?
谢谢
解决方案
推荐阅读
- googlebot - 谷歌真的想找到 admin.php 吗?
- google-analytics - 如何在 BigQuery 的表格中添加适当的平台(hits.datasource)?
- javascript - 从url下载pdf,保存在文件中,压缩然后下载zip
- azure-servicebus-topics - Azure 主题订阅订阅者
- .htaccess - 如何使用查询字符串将 URL 条目重定向到特定文件?
- sql-server - SQL Server [本地慢 - 远程快]
- javascript - 导航后视频不再播放
- asp.net - 是否可以允许用户从已发布的 Web 应用程序连接到他们自己的数据库?
- java - 如何在 EDT 中运行摆动输入对话框并获取返回值?
- unity3d - 如何将记事本文件转换为 C#?