AppEngine Standard: how to dispatch based on service name and version? - google-app-engine

Is there a way via the dispatch.yaml file to dispatch a request to the right service based on the version and the service name ?
I mean, I have this request:
https://va4-0-0-dot-api-acceptance-dot-myapp.appspot.com/auth/user
It is sent by my api-acceptance service but I'd like it to go to my auth-acceptance service.
I have written in my dispatch those rules, but it does not work...
- url: "va4-0-0.myapp.appspot.com/auth/*"
service: auth-acceptance
- url: "api-acceptance.myapp.appspot.com/auth/*"
service: auth-acceptance

According to the documentation, the URL pattern that you're using:
https://[VERSION_ID]-dot-[SERVICE_ID]-dot-[MY_PROJECT_ID].appspot.com
will be bypassed by the dispatch.yaml file, so it's not possible to reroute the request this way.
Using the above pattern you are already being very specific to which service and version you want to route the request.
So either you change the URL to https://[VERSION_ID]-dot-auth-acceptance-dot-[MY_PROJECT_ID].appspot.com/auth/user or use a default routing which can later be overriden by a dispatch.yaml.

Related

Is there any way to customize the URL of a HTTP request trigger?

My logic app HTTP url is something like this:
https://prod-98.eastus.logic.azure.com/workflows/8767e7ecd19c45adbfb01d681e35a888/triggers/manual/paths/invoke/ABCDEFG/api-version=2016-10-01&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=U-M0hnvs9BICC_JV7_nTJRQhWg5oZnD_SVo9Sbm03oo
It is not presentable.
I like to make the URL of HTTP request trigger more polished and presentable.
Is there any way to customize the URL of a HTTP request trigger?
Using a clean custom DNS and URL path ( like https://MyDnsName.com/Path/Action ) is the prefrable solution, but anything better than what currenty provided would do.
As far as I know, When a HTTP request is received trigger will automatically generate the URL, and it cannot be changed manually.
This URL includes query parameters that specify a Shared Access Signature (SAS) key, which is used for authentication.
I haven't thought of a way to completely customize the URL to https://MyDnsName.com/Path/Action, but there are two ways to make it look more meaningful.
1. Function App Proxy
After you create an Azure Function App, you can create an proxy.
After you create Azure Function App proxy, your URL is in this format:
https://<function-name>.azurewebsites.net/xxx
2. API management
After creating an Azure API Management service instance, you can customize the URL suffix.
After you create a API management, your URL is in this form:
https://<API management-name>.azure-api.net/xxx

Appengine: Routing to a different appspot.com

I have a app
abc.appspot.com
Now, I want a url abc.appspot.com/blog. This url should serve from abcblog.appspot.com. I don't want a redirect.
Is this possible with dispatch.yaml
Basically, I want to introduce a blog in my app, but from a different appspot.com.
You can use the default routing by routing via URL or you can use routing with a dispatch file.
For your case I think creating a dispatch file will be the suitable way to do what you want since it will override the App Engine's routing rules and you can define your own custom routing rules.
To create a dispatch file you should put it in your root directory of your default service and you can define up to 20 routing rules in the dispatch file.
An example from the documentation:
dispatch:
# Send all mobile traffic to the mobile frontend.
- url: "*/mobile/*"
service: mobile-frontend
# Send all work to the one static backend.
- url: "*/work/*"
service: static-backend
You can check this to see how to properly configure your dispatch.yaml.

How to make a service discovery for Google App Engine? How to get service URL?

I want to get URL's of services for particular project, how can I do this?
I need URL's like .appspot.com
I tried App Engine Admin api, but it can only provide names of the services.
you can get url's of App Engine services's versions through API calls, in 3 steps:
1) authenticate and get an access-token to the App Engine Admin API:
gcloud auth application-default print-access-token
2) with the access token, list all services in App Engine, and get their version ID (in the nested field "allocations"), and service ID:
curl -H "Authorization: Bearer [MY_ACCESS_TOKEN]" https://appengine.googleapis.com/v1/apps/[MY_PROJECT_ID]/services
3) with the version ID and service ID, get the full data on the version:
curl -H "Authorization: Bearer [MY_ACCESS_TOKEN]" https://appengine.googleapis.com/v1/apps/[MY_PROJECT_ID]/services/[SERVICE_ID]/versions/[VERSION_ID]/?view=FULL
The field versionUrl delivers the app URL for this specific version, in the following form:
default service:
https://[VERSION_ID]-dot-[PROJECT_ID].appspot.com
other services:
https://[SERVICE_ID]-dot-[VERSION_ID]-dot-[PROJECT_ID].appspot.com
From there, you can build your own service discovery.
The URL of a service other than default follows this pattern:
service-dot-projectID.appspot.com
So for example if your service's name is helloworld and your project ID is myprojectid then the URL would be helloworld-dot-myprojectid.appspot.com
If you're manually constructing urls to services within the same project, you may find it easier to setup some dispatch rules.
https://cloud.google.com/appengine/docs/standard/python3/reference/dispatch-yaml
The dispatch.yaml allows you to override routing rules. You can use the dispatch.yaml to send incoming requests to a specific service (formerly known as modules) based on the path or hostname in the URL.
Depending on your needs, you can construct your url off of app_identity.get_default_version_hostname() without worrying about the underlying service, since the dispatch rules will route to the service by the url path.

Appending some info to each requset in REST API

I have an angular application. From frontend I can set some value. This value is something like config, which can be changed.
It is simple string variable. How to attach this config to each REST request ?
I ask mainly about approach.
Maybe pass it via headers is good idea ?
For angular 1.x, write an Interceptor:
For purposes of global error handling, authentication, or any kind of
synchronous or asynchronous pre-processing of request or
postprocessing of responses, it is desirable to be able to intercept
requests before they are handed to the server and responses before
they are handed over to the application code that initiated these
requests
For angular 2.x / 4.x, RequestOptions should be the key to solve your problem. Set base url for angular 2 http requests
I'm using angular2, my solution is create a Service and inject "Http" dependency, then write two methods "get", "post", these methods add an entry to header before calling "Http", in other component / service, I just inject this Service class, then call its "get" or "post".
Your code should be somewhat like this If your working in angular 1.3 or less
The data should be sent as body data to server
var basecall = Restangular.all('url');
bascall.post($scope.config).then(function(data){
})

Parsing Oauth 2.0 return parameters in angular-ui-router

I'm attempting to authenticate a user using Google's Oauth 2.0 API. When my app HREF's to the Google authentication page, it successfully passes information back to my AngularJS app. However, I'm not sure how best to handle the returned URL-encoded data.
This is the format it is returned as:
#access_token=...
&token_type=Bearer
&expires_in=3600
My main problem is that this string begins with # instead of ? as is traditionally done with URL encoded parameters.
In my stateProvider config, I've implemented the callback state as such:
.state 'auth.googlecallback',
url: '/googlecallback/#{accessToken}&token_type={tokenType}&expires_in={expiresIn}'
templateUrl: 'views/auth/googlecallback.html'
controller: 'GoogleCallbackCtrl as gVm'
The above URL is an example of what I have tried. When the url is simply /googlecallback/, the page loads successfully, even when navigated to using the Google Oauth link. But the moment I had the # symbol, the state breaks and I can't parse the state params for the data inside.
I've looked into using the angular-oauth library on GitHub, but it hasn't been updated in 2 years, and it doesn't appear to allow Oauth authentication for more than just Google (I want to use Facebook and Google).
What is the correct way to handle the the Oauth URL data in angular-ui-router?
To be frank, I don't think this will actually answer your question, but I was helping some friends with this earlier today. They were unable to handle the URI via the ui-router. Instead, they had to delegate parsing the parameters and making the appropriate request to their view controller. Using the Angular $location service and some remapping functions, we were able to get the parameters out of the # query syntax into a hash that he was able to push back to the server in his request. The code looked similarly to the following:
var paramsArray = $location.hash().split('&')
var payload = {};
angular.forEach(paramsArray, function (param) {
var arr = param.split('='),
key = param[0],
value = param[1];
payload[key] = value;
});
This could absolutely be simplified but this was what he was trying to accomplish for his strategy.
That all being said, I'm personally not a fan of trying to accomplish OAuth strategy on the client. You have private keys that usually need to get exchanged to complete the full handshake. If possible, it would be best if you did the following:
Redirect the client to the appropriate OAuth path
Have the redirect go to a server endpoint that can process the oauth request and complete the handshake.
Have the server endpoint that the oauth request redirected to, redirect to your success landing page with any additional response
objects required by your application.
Doing this would protect your private keys and most web frameworks have modules/packages/gems/plugins/etc. for implementing oauth for all the mainstream providers. Hope this helps you in the right direction.

Resources