You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Datastore API auth depends on being logued with the gcloud CLI (remote) #1168
This code only works if you are logued using gcloud cli.
I we are using credentials for this (keyFile.json) its kinda weird to also need to log in on the gcloud cli.
var gcloud = require('gcloud');
// Authenticating on a per-API-basis. You don't need to do this if you auth on a
// global basis (see Authentication section above).
var dataset = gcloud.datastore.dataset({
projectId: 'central-station-staging',
keyFilename: './keyFile.json'
});
dataset.get(dataset.key(['Product', 'Computer']), function(err, entity) {
console.log(err || entity);
});
// Save data to your dataset.
var blogPostData = {
title: 'How to make the perfect homemade pasta',
author: 'Andrew Chilton',
isDraft: true
};
var blogPostKey = dataset.key('BlogPost');
dataset.save({
key: blogPostKey,
data: blogPostData
}, function(err) {
// `blogPostKey` has been updated with an ID so you can do more operations
// with it, such as an update.
blogPostData.isDraft = false;
dataset.save({
key: blogPostKey,
data: blogPostData
}, function(err) {
if (!err) {
// The blog post is now published!
}
});
});
Okay, let's narrow the scope to one specific call:
vargcloud=require('gcloud');// Authenticating on a per-API-basis. You don't need to do this if you auth on a// global basis (see Authentication section above).vardataset=gcloud.datastore.dataset({projectId: '...',keyFilename: '...'});// Save data to your dataset.varblogPostData={title: 'How to make the perfect homemade pasta',author: 'Andrew Chilton',isDraft: true};varblogPostKey=dataset.key('BlogPost');dataset.save({key: blogPostKey,data: blogPostData},console.log);
My env its a VM with gcloud cli not installed, im connecting remotely (im running my app locally and i access the datastore on gae) and im getting "Error: invalid_grant" all the time, but when i run this outside the VM, with gcloud cli installed and logued with a valid session works like a charm.
The invalid_grant error is returned when trying to get an authorization token. I'm not sure why that would happen in one environment with the same project ID and key file and not another. Googling around shows that it could be an issue with the VM's time being out of sync with the Google server. Depending on your OS, maybe something like this is worth a shot: googleapis/google-api-ruby-client#84 (comment)?
Activity
stephenplusplus commentedon Mar 15, 2016
Can you show the exact code you run and the error you are getting?
sespinosa commentedon Mar 15, 2016
thats the exact code, when i run that on a env with the gcloud cli installed and logued it runs with no problem and adds the blogposts to the db
stephenplusplus commentedon Mar 16, 2016
Okay, let's narrow the scope to one specific call:
Here are my results:
This also works for our integration tests, which runs our Datastore tests on a short-lived, Travis-created Linux VM without the gcloud SDK installed.
Do you have a local Datastore instance running? And what error is being returned when you run this code after
gcloud revoke?sespinosa commentedon Mar 16, 2016
My env its a VM with gcloud cli not installed, im connecting remotely (im running my app locally and i access the datastore on gae) and im getting "Error: invalid_grant" all the time, but when i run this outside the VM, with gcloud cli installed and logued with a valid session works like a charm.
stephenplusplus commentedon Mar 16, 2016
Would you mind showing the output of:
The
invalid_granterror is returned when trying to get an authorization token. I'm not sure why that would happen in one environment with the same project ID and key file and not another. Googling around shows that it could be an issue with the VM's time being out of sync with the Google server. Depending on your OS, maybe something like this is worth a shot: googleapis/google-api-ruby-client#84 (comment)?sespinosa commentedon Mar 16, 2016
man, you are the coolest
running sudo ntpdate ntp.ubuntu.com solve my problem!
im really sorry for wasting your time.
stephenplusplus commentedon Mar 16, 2016
Not at all, I'm glad it worked!
chore(main): release 8.2.1 (#1168)
chore(main): release 8.2.1 (#1168)
chore(main): release 8.2.1 (#1168)
fix: sync to googleapis/conformance-tests@fa559a1 (#1167)
fix: remove error listener to prevent memory leak (#1168)
chore: release 5.2.1 (#1174)
fix: sync to googleapis/conformance-tests@fa559a1 (googleapis#1167)