I have a project from which I want to copy few container images to another project using a node application. I use container-image-builder module for the same. The copying works with service account credentials,but I want to use user account credentials. The Oauth credentials allow only copying of images within the project but not across multiple projects as OAuth credentials restricts to a single project per application. Is there any other solution so that I can use the user account? Tried the following:
app.get('/demo',function(req,res){
imageCopy();
...
});
app.listen(8080);
async function imageCopy(){
var imgName = 'us.gcr.io/myProj/hello-world';
var trgtImg = 'us.gcr.io/targetProj/hello-world';
var _clientOptions = {
clientId: "xxxx.apps.googleusercontent.com",
clientSecret: "yyyy",
redirectUri: "https://domain/XYZ"
}
var auth = imgBuilder.auth(imgName,"push,pull",{
'us.gcr.io':{
clientOptions: _clientOptions
}
});
auth.then(async function(credentials){
const image = new imgBuilder.Image(imgName,trgtImg,credentials);
const result = await image.save(['dev-latest']);
console.log(result);
});
}
and also extracted the token and sent the same
var auth = new google.auth.OAuth2(
config.google.clientId,
config.google.clientSecret,
config.google.redirectUri
};
function initialize(appRouter, serviceListener)
{
log.debug('initialize');
appRouter.get('/XYZ/login',renderLoginPage);
appRouter.get('/XYZ', proceed );
listener = serviceListener;
}
function renderLoginPage(req, res){
res.render('auth.html',{
title: "xxxx",
....
login_btn_description: "Login with Google",
login_link: generateGoogleURL()
});
}
function generateGoogleURL(){
return auth.generateAuthUrl({
access_type: 'offline',
prompt: 'consent',
scope: appScope
});
}
function proceed(req,res){
const qs = new url.URL(req.url,config.devhostname);
const code = qs.searchParams.get('code');
getGoogleAccountFromCode(code).then(function(){
imageCopy();
...
}).catch(console.error);
}
async function getGoogleAccountFromCode(code) {
const data = await auth.getToken(code);
tokens = data.tokens;
auth.setCredentials(tokens)
}
async function imageCopy(){
var imgName = 'gcr.io/myProj/hello-world';
var trgtImg = 'gcr.io/trgtProj/hello-world';
const image = new authParam.Image(imgName,trgtImg,{'gcr.io':{
clientOptions: tokens
}
});
const result = await image.save(['dev-latest']);
}
Oauth credentials is restricted for single project , so what credentials of user-account should I use?