Enable Dialogflow API on Google Cloud Project using Service Accounts - google-cloud-platform

I'm trying to create new Agents in different projects using Service Accounts (I don't know any alternative to Service Accounts) but as I suspect because Service Accounts are specific to a project, I cannot enable the corresponding Dialogflow API using any kind of REST API or something alike. Any help is kindly appreciated.

Beside using the Cloud console, you can enable Cloud APIs using Cloud SDK and Service Usage API
Using Gcloud command:
gcloud services enable dialogflow.googleapis.com
Using RESTful API services.enable method:
POST https://serviceusage.googleapis.com/v1/projects/12345678901/services/dialogflow.googleapis.com:enable
The used service account requires serviceusage.services.enable that you can include in a custom role and assign it to the used service account.
The following is the link for the console method:
https://console.cloud.google.com/flows/enableapi?project=[YOUR_PROJECT]&apiid=dialogflow.googleapis.com

Related

Google Cloud (API GATEWAY) Custom Domain

I am currently building a rest api, for this I am using Google Cloud API Gateway and Google Cloud Run. I've been looking at all the google cloud documentation and researching elsewhere and I can't find how to add a custom domain to an API gateway instance. The funny thing is that there is more documentation for Google Cloud endpoints, I could find how to do it with endpoints but it does not apply to my use case.
I have 10 instances of google cloud run each one running a microservice respectively and I want to join everything in a single domain and add support with openapi, but I have failed in the attempt.
In any case, if someone has managed to customize the domain of an api gateway instance, I would appreciate if you could guide me, greetings.
For the beta release, custom domain names are not supported on GCP for API Gateway. Since it is still beta as of today, if you want to use a custom domain, you could use Cloud Endpoints in Cloud Run or you could even look into using Microservices in App Engine.

How do I make a new API in the Google Cloud Platform console?

In AWS, making a new API is as easy as going to the API Gateway service and clicking "Create API". How do I do the same in GCP? The Endpoints service does not appear to offer any way of creating an API.
At GCP there are several offers to deploy APIs, and as you have pointed Cloud Endpoints do not offer to ways to create aPI, but it provides frameworks to to base on and to integrate with the actual application hosting offers (App Engine, Compute Engine GKE, Cloud Run, Cloud Functions).
I would follow this tutorial in order to create the base for your API and later deploy and test your API. Notice that in those tutorial App Engine is used to deploy your API.

How to invoke gcloud CLI or API command within Dialogflow fulfillment webhook code?

I would like to know, how to invoke gcloud CLI or API command from Dialogflow fulfillment webhook code.
Here's an example objective: I would like to trigger the creation of Google cloud compute engine, from the Google actions invocation. So I'll be writing a dialogflow fulfillment to achieve the compute engine creation.
I've researched the Google Dialogflow documentation and it does not have much detail about invoking the "gcloud" command in Fulfillment webhook code.
So it would be good to know,
Is there any dialogflow libraries can be used to invoke gcloud CLI or API?
How to handle the those requests within dialogflow fulfillment code?
Are these details are available in a documentation? if yes, please share the URL.
This question would be helpful to developers, who are seeking for similar information on developing Google actions using Dialogflow.
I'm not sure what you mean by gcloud CLI or API, you may need to be more specific as to what you'd like to achieve.
But in case I understand correctly, you'd like to trigger some gcloud API functions. If that's the case; Dialogflow fulfillment (usually) runs o Firebase Cloud Functions. If you're using Firebase for your deployment, you can use gcloud node.js client library to use Google Cloud Platform services.
If you're using your own fulfillment server, you may use the appropriate gcloud client library for that as well.
Q1. Is there any dialogflow libraries can be used to invoke gcloud CLI or API?
Answer:
Google has node.js SDK libraries, that can be imported into Dialogflow webhook code.
So, the creation of Google cloud compute resources are possible through the nodejs library “google-cloud/compute”
Q2. How to handle the those requests within dialogflow fulfillment code?
Answer:
Perform the below changes in the Dialogflow webhook code
In package.json add the compute library in dependencies section,
"dependencies": {
"actions-on-google": "^2.2.0",
….
….
"#google-cloud/compute": "^0.12.0"
}
In index.js file utilize the compute library
// Imports the Google Cloud client library
const Compute = require('#google-cloud/compute');
// Creates a client
const compute = new Compute();
Therefore the “compute” object created above can be used to implement all the functionalities related to Google Cloud Compute resource.
Q3. Are these details are available in a documentation? if yes, please share the URL.
Answer:
Refer Google Cloud Compute Library Documentation Here
Refer Google Cloud Compute Library Documentation for creating compute resource

REST API to Login to Google Platform using Service Account

I have created a service account on Google Cloud Platform. I am using a standalone Java program which uses GCP Java Client API to get the Authentication Token ID by taking service account JSON file. By using the Token ID, I can create a compute instance.
I don't want to use Java API or gcloud tool, is there a REST API exists which takes required details and return Token ID?
I went through the GCP documentation and could not find any details for the authentication and authorization through REST using Service Account.
I have created a service account on Google Cloud Platform. I am using
a standalone Java program which uses GCP Java Client API to get the
Authentication Token ID by taking service account JSON file. By using
the Token ID, I can create a compute instance.
Using a service account is the correct and recommended method to authenticate and authorize software applications.
Note. The assumption here is that the software application is running on your systems under your control. If instead you are installing software on a user's desktop or system not under your control, then you would use Google OAuth 2.0 (Google Accounts) to obtain User Credentials to authorize your application.
Another method is to issue short-lived temporary credentials from a service account credential that are time limited. These short-lived credentials are created on your server and then handed to the client.
I don't want to use Java API or gcloud tool, is there a REST API
exists which takes required details and return Token ID?
You have the classic "Chicken or Egg" situation. You need credentials to authenticate and authorize otherwise anyone could create credentials. Google Service Account credentials provides this. To create service account credentials, use the Google Cloud Console or gcloud CLI to download the service account Json file.
I went through the GCP documentation and could not find any details
for the authentication and authorization through REST using Service
Account.
This question is confusing. Do you want to use Service Account credentials to authorize your Google API calls OR do you want to call a Google API to obtain credentials?
In the first case, once you create service account credentials, they are used to authorize your API calls. You add the Access Token to the HTTP header when making API calls.
For the second case, use Google OAuth 2.0 to obtain credentials. Google OAuth 2.0 uses Google Accounts for authentication. This method provides you with an Access Token (just like a service account) and a Refresh Token and Client ID token. You will need to add the Google Accounts user identity to your Google Cloud IAM which provides for authorization (privileges).

GCP enable services/apis via Rest API or python module

How can I enable/disable APIs/Services in Google Cloud Project via Restful APIs or python?
For example, I want to enable following API/Service in a project.
https://console.developers.google.com/apis/api/iam.googleapis.com/overview?project=
You can programmatically enable or disable a GCP service using the Service Usage API. There are also methods for batch operations and querying service state. See the link below to the documentation.
https://cloud.google.com/service-usage/docs/reference/rest/v1/services