我试图从(gcr.io)的Node.js中获取可用图像及其标记的列表。
我首先使用google-auto-auth使用作用域https://www.googleapis.com/auth/devstorage.read_write对令牌进行操作,并将该令牌交换为如下所示的gcr.io令牌:
axios.get('https://gcr.io/v2/token?service=gcr.io', {
auth: {
username: '_token',
password: token // token I got from `google-auto-auth`
}
})然后,我尝试使用它来调用v2/_catalog端点:
axios.get('https://gcr.io/v2/_catalog', {
headers: {
Authorization: `Bearer ${gcrToken}`
}
})我得到了以下错误:
{
errors: [ { code: 'DENIED', message: 'Failed to retrieve projects.' } ]
}公平地说,它必须要求我的项目ID,但我应该在哪里提供呢?
为了看看我能不能让其他东西发挥作用,我试了一下:
axios.get('https://gcr.io/v2/my-project-id/my-image/tags/list', {
headers: {
Authorization: `Bearer ${gcrToken}`
}
})我得到了以下信息:
{
errors: [
{
code: 'NAME_INVALID',
message: 'Requested repository does not match bearer token resource: my-project-id/my-image'
}
]
}如何从gcr.io读取图像信息?
发布于 2017-07-14 07:43:53
在与GCR的乔恩·约翰逊进行了广泛的交流之后,我们终于发现了问题所在。如果你投这个答案,也请投乔恩的票,他超越了这个问题来解决这个问题。
在撰写这篇文章的时候,大部分这些东西都是没有记录的。
registry:catalog:*作用域。us.gcr.io上,它们把它们当作独立的注册表--我以为它们是镜像。Project Viewer角色。Basic base64(_token:<token>)一起使用,但Google令牌可以。获取GCR令牌
// Updated host
axios.get('https://us.gcr.io/v2/token?service=gcr.io', {
params: {
service: 'us.gcr.io',
scope: `registry:catalog:*`
},
auth: {
username: '_token',
password: token // token I got from `google-auto-auth`
},
})使用令牌列出存储库
const client = axios.create({
baseURL: `https://us.gcr.io/v2`,
headers: {
Authorization: `Bearer ${token}`
}
})
client.get('/_catalog').then((response) => {
console.log(response.data.repositories)
})发布于 2017-06-27 18:19:41
第一个错误可能是因为缺少项目列表的一个作用域:https://cloud.google.com/resource-manager/reference/rest/v1/projects/list#authorization
您将得到第二个错误,因为您丢失了令牌交换中的作用域。
你想要这样的东西:
https://gcr.io/v2/token?service=gcr.io&scope=repository:<my-project-id/my-image>:*参见这里的示例:https://docs.docker.com/registry/spec/auth/token/#requesting-a-token
https://stackoverflow.com/questions/44783736
复制相似问题