Wednesday, January 20, 2016

Re: [google-cloud-sql-discuss] Testing Cloud SQL Failover

Forgot to mention that my curl command now looks like this:

curl --header 'Content-Type: application/json' --header 'Authorization: Bearer OAUTH_ACCESS_TOKEN' -X POST "https://www.googleapis.com/sql/v1beta4/projects/numeric-datum-118114/instances/db-master/failover" --data '{"failoverContext":{"settingsVersion":14}}'

With the following error returned:

{
 
"error": {
 
"errors": [
   
{
   
"domain": "global",
   
"reason": "staleData",
   
"message": "Condition does not match.",
   
"locationType": "header",
   
"location": "If-Match"
   
}
 
],
 
"code": 412,
 
"message": "Condition does not match."
 
}
}


On Wednesday, January 20, 2016 at 10:42:01 AM UTC, Peter Cheesewright wrote:
I have now managed to initiate failover via the tryit utility that Vishnu pointed to above. I did have to set the failoverContext.settingsVersion but also I had to change the instance ID that I was passing from "asia-east1:db-master" to just "db-master" for it to work (putting "asia-east1:db-master" resulted in the error "The client is not authorized to make this request.").

However I still cannot get the curl command to work. I have tried using the access token returned by
gcloud auth print-access-token
as David suggested but without success. (Why is "print-access-token" not documented in "gcloud help auth" ?)

Checking that token with 
https://apis-explorer.appspot.com/apis-explorer/#search/oauth2/oauth2/v2/oauth2.tokeninfo
gives the expected email address, the following for the 'scope' property:


and the "access_type" as "offline".

Does this seem reasonable? I notice that the scope does not contain "https://www.googleapis.com/auth/sqlservice.admin" but does contain "https://www.googleapis.com/auth/cloud-platform" but then the documentation for the failover method says at least one of the 2 is required.


On Tuesday, January 19, 2016 at 10:59:10 PM UTC, Vishnu Fafat wrote:
Hi,

You will have to set failoverContext.settingsVersion in the Request body for calling failover on an instance at https://cloud.google.com/sql/docs/admin-api/v1beta4/instances/failover#try-it.
You can get the settingsVersion by listing instances in the project at https://cloud.google.com/sql/docs/admin-api/v1beta4/instances/list#try-it.
I will get the curl command documentation at https://cloud.google.com/sql/docs/high-availability#test fixed.

On Tue, Jan 19, 2016 at 2:26 PM, 'David Newgas' via Google Cloud SQL discuss <google-cloud...@googlegroups.com> wrote:
I still suggest trying gcloud auth print-access-token.

You might also want to try putting the access token into https://apis-explorer.appspot.com/apis-explorer/#search/oauth2/oauth2/v2/oauth2.tokeninfo and clicking execute. You should make sure that the scope includes those required by the API.  You should also check that the email returned has owner or editor permission on the project your instance is in.

On Tue, Jan 19, 2016 at 2:20 PM, Peter Cheesewright <pe...@microcosm.co.uk> wrote:
The token I'm using does start "ya29."
It's the token obtained from the output of
gcloud auth login
after completing the web flow.

Any other thoughts?


On Tuesday, January 19, 2016 at 5:36:48 PM UTC, David Newgas wrote:
I suspect you might be using a "authorization code" rather than an "access token". The authorization code exchanged as part of the "gcloud auth login" flow is just part of the  login process. Try using "gcloud auth print-access-token" to actually get an access token you can use. Google's access tokens (currently) start with "ya29." which should help you identify it.

David

On Tue, Jan 19, 2016 at 9:16 AM, Peter Cheesewright <pe...@microcosm.co.uk> wrote:
I've been trying to test SQL failover using the following command:

curl --header 'Content-Type: application/json' --header 'Authorization: Bearer OATH_ACCESS_TOKEN_HERE' -X POST "https://www.googleapis.com/sql/v1beta4/projects/numeric-datum-118114/instances/asia-east1:db-master/failover" --data "{}"

I started with the command here:
but it seems to be a bit off the mark. Eventually I ended up with the curl command above but I keep getting the following response:

{
 
"error": {
 
"errors": [
   
{
   
"domain": "global",
   
"reason": "authError",
   
"message": "Invalid Credentials",
   
"locationType": "header",
   
"location": "Authorization"
   
}
 
],
 
"code": 401,
 
"message": "Invalid Credentials"
 
}
}

The actual access token I'm using in the curl command is the one returned by:
gcloud auth login

I'm assuming this is the wrong thing to do? 
How do I acquire an access token that allows me to make this call?

--
You received this message because you are subscribed to the Google Groups "Google Cloud SQL discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-cloud-sql-discuss+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-cloud-sql-discuss/5ed3f23d-b82a-481f-8885-7b986bce0966%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Google Cloud SQL discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-cloud-sql-discuss+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-cloud-sql-discuss/c2543eec-71ed-426f-a06f-6672c4a0012e%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Google Cloud SQL discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-cloud-sql-discuss+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-cloud-sql-discuss/CAJZK_baXxbZRhD0Ls2ntR4FVcNoD-EP1x-dOtwx%2B5597-w23GA%40mail.gmail.com.

For more options, visit https://groups.google.com/d/optout.



--
Vishnu Fafat

--
You received this message because you are subscribed to the Google Groups "Google Cloud SQL discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-cloud-sql-discuss+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-cloud-sql-discuss/506323c0-48e9-4081-a977-2834f645cebc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment