How to set default namesevers for a Google Cloud DNS zone? - gcloud

I'm using Google's CloudDNS API to batch upload a bunch of domains to Google Cloud. I want to be able to override the default nameservers that Google randomly assigns for example
ns-cloud-e1.google.com
ns-cloud-e2.google.com
ns-cloud-e3.google.com
ns-cloud-e4.google.com
to
n1.domain.com
n2.domain.com
n3.domain.com
I've noticed that Google's CloudDNS API's documentation references the following
nameServerSet (string) -
Optionally specifies the NameServerSet for this ManagedZone. A
NameServerSet is a set of DNS name servers that all host the same
ManagedZones. Most users will leave this field unset.
Though when trying to use this property via the CloudDNS, I receive a response from the API saying that the data provided through data is invalid. I passed through in the format of "n1.domain.com.,n2.domain.com.,n3.domain.com.". I've also tried passing through an array of nameservers and a RecordResourceSet class from the Google PHP package, with no avail.
Is this the correct format I should be following or is it not possible to pre-define the nameservers when the managed zone is created and instead have to do this after the zone is created?
Code example below, $cloud_dns->service is an instance of Google_Service_Dns
$cloud_dns->service->managedZones
->create(
'blah',
new Google_Service_Dns_ManagedZone([
'dnsName' => $dns_name_formatted,
'name' => 'app-' . $domain_name,
'description' => 'Batch Uploaded Domain',
'nameServerSet' => 'n1.domain.com.,n2.domain.com.,n3.domain.com.'
]),
);

You may wish to consider filing this issue with Google's public Issue Tracker.
You're not the first to encounter this and that question is 4 years old and remains unanswered :-(
Regardless of language SDK, the underlying call can be tested using Google's APIs Explorer and specifically ManagedZones:create which conveniently includes the relevant API method. You can plug in your values and try it out (securely) within the browser, or:
NAME="yourdomain-com"
DNS="yourdomain.com." # Must end with a period (.)
TOKEN=$(gcloud auth print-access-token)
curl \
--request POST \
--header "Authorization: Bearer ${TOKEN}" \
--header "Accept: application/json" \
--header "Content-Type: application/json" \
--data "{\"nameServerSet\":\"n1.domain.com.,n2.domain.com.\",\"name\":\"${NAME}\",\"dnsName\":\"${DNS}\",\"description\":\"\"}" \
"https://dns.googleapis.com/dns/v1/projects/${PROJECT}/managedZones"
I tried to craft a request using nameServerSet using the API directly and am unable. It's thus not a language SDK issue but a question of whether|how this property may be set.
It's somewhat interesting to note that you can't set name servers when creating zones through the console (link). But, you may subsequently change them. The console POSTs to ManagedZone:changes, e.g.:
POST https://www.googleapis.com/dns/v1beta2/projects/${PROJECT}/managedZones/${NAME}/changes
{
"additions": [
{
"name": "...",
"type": "NS",
"ttl": 21600,
"rrdatas": [
"ns-cloud-d1.googledomains.com.",
"ns-cloud-d3.googledomains.com.",
"ns-cloud-d4.googledomains.com."
]
}
],
"deletions": [
{
"name": "...",
"type": "NS",
"ttl": 21600,
"rrdatas": [
"n1.domain.com.",
"n2.domain.com.",
"n3.domain.com."
]
}
]
}

Related

GitHub API find all files with extension

I want to get links of all GitHub files with specific extension. I found out that I can use extension:bin to search for all *.bin files, URL https://github.com/search?q=extension%3Abin&type=Code
I found Using GitHub API to retrieve files with specific extension
but this answer deals with specific repository.
Update: I was trying https://api.github.com/search/code?q=extension:ifc+size:1000..1500 but response is
{
"message": "Validation Failed",
"errors": [
{
"message": "Must include at least one user, organization, or repository",
}
]
}
Do we have a method in GitHub API to search in all repositories? I didn't find here https://docs.github.com/en/rest/search#search-code
Root cause analysis
I have reproduced the issue by performing an HTTP request without the authorization header:
$ curl \
--request GET \
--header 'Accept: application/vnd.github+json' \
'https://api.github.com/search/code?q=extension:ifc+size:1000..1500'
{
"message": "Validation Failed",
"errors": [
{
"message": "Must include at least one user, organization, or repository",
"resource": "Search",
"field": "q",
"code": "invalid"
}
],
"documentation_url": "https://docs.github.com/v3/search/"
}
Root cause
Therefore, it looks like you have missed the authorization header.
Solution
Perform an HTTP request with the appropriate authorization header.
Draft example command line
curl \
--request GET \
--header 'Accept: application/vnd.github+json' \
--header 'Authorization: Bearer <TOKEN>' \
'https://api.github.com/search/code?q=extension:ifc+size:1000..1500'
The example command line has worked fine (returned search results) for me.
Please, replace <TOKEN> with a GitHub personal access token.
Additional references
Search: Search code - GitHub Docs.
Question. How to search for code in GitHub with GitHub API? - Stack Overflow.

When Iot Agent sends data within milliseconds, the values are not notified to Draco subscription

Our device sends millisecond level telemetry data to Fiware. The payload contains DeviceId, DeviceDateTime and Attribute values as follows:
{"humidity":50.5,"device_id":"WS-100","devicetime":"2020-06-08T17:38:35.629+5:30"}
But we have observed that millisecond level tracking is not available in MongoDB and also Fiware does not notify the Draco subscription when data received at millisecond level. It only sends one payload per second. This is our Draco subscription:
curl -iX POST \
'http://52.172.34.29:1026/v2/subscriptions?options=skipInitialNotification' \
-H 'Content-Type: application/json' \
-H 'fiware-service: openiot' \
-H 'fiware-servicepath: /' \
-d '{
"description": "Subscription",
"subject": {
"entities": [
{
"idPattern": ".*"
}
],
"condition": {
"attrs": []
}
},
"notification": {
"http": {
"url": "http://52.172.34.29:3003/v2/notify"
},
"attrs": [],
"onlyChangedAttrs":true,
"throttling": 5
}
}'
Can you please let us know how to handle this millisecond changes in Orion subscription.
Thanks!
Milliseconds support is part of Orion backlog (see issues #3412, #2670 and #432) but it has not been implemented yet. I know there are people in the FIWARE community working on this feature, but I don't know when it will be available.
However, even if Orion doesn't support milliseconds natively, the application always has the option to manage it itself. For instance, using a devicetimeMs which value is an integer with time in milliseconds, included along with the other data when you send a telemetry measure. This is the typical workaround.
UPDATE: milliseconds support for DateTime attributes and metadata has been implemented. The feature will be avaiable in next Orion version (2.5.0) but it can be used right now if you get :latest container from dockerhub.

How to list all assets in a catalog in watson data science experience?

I have created a Watson data science experience (DSX) account, created a catalog into it and added data assets to it.
I am trying to use the REST APIs as documented at: https://developer.ibm.com/api/view/id-1084:title-Watson_Data_Platform_Core_Services#id36962
... to retrieve the assets using curl.
curl -H "Authorization: Bearer <---stripped the auth token --->" -X GET 'https://api.dataplatform.ibm.com/v2/assets?catalog_id=bd2b56c3-091f-4ff5-beab-b3a1da85488d'
I get the following response:
{
"errors": [
{
"code": "invalid_parameter",
"message": "COMSV3006E: Missing or Invalid 'asset' id",
"target": {
"name": "asset",
"type": "parameter"
}
}
],
"trace": "e7b07khusvkj7s0ymgrggm6si"
}
How do I specify the asset id to retrieve the same?
Also, I am looking to upload assets, assign metadata/tags to existing assets using REST APIs. Is there any documentation/tutorial available, which can help explain me that?
One option is the search api, although it is listed as deprecated:
curl -X POST -d '{"query":"asset.asset_state:available"}' -H "Content-Type: application/json" https://api.dataplatform.ibm.com/v2/catalogs/<catalog_guid>/types/<type>/search -H "Authorization: Bearer ...."
https://developer.ibm.com/api/view/id-1084:title-Watson_Data_Platform_Core_Services#id37001
For <type>, you probably want data_asset, but you can also look up all existing types:
curl -X GET https://api.dataplatform.ibm.com/v2/catalogs/<catalog_guid>/types -H "Authorization: Bearer ...."
https://developer.ibm.com/api/view/id-1084:title-Watson_Data_Platform_Core_Services#id36916

Couchbase create document fails through sync-gateway public rest API

As per Couchbase Sync-Gateway REST API documentation here below mentioned cURL should create a document in the specified database.
Below is the generated cURL from Postman.
curl -X PUT -H "Cache-Control: no-cache" -H "Postman-Token: 498d0fb6-77ac-9335-2379-14258c6731c7" -d '' "http://192.168.244.174:4984/db/"
I also tried adding JSON to the body of the request.
But when I send the put request through Postman, instead of creating a new document, it tries to create a new database and the JSON response is
{
"error": "Precondition Failed",
"reason": "Database already exists"
}
Am I missing something or it was a bug? Is there any other way to create a document to sync gateway?
There is a mistake in the documentation.
As per documentation,
You can either specify the document ID by including the _id object in the request message body, or let the software generate an ID.
But Couchbase REST API does not seem to work like that (may be they are not updating their documentation regularly). You need to provide the id in the URL like /{db}/{id}.
The below cURL worked for me.
curl -X PUT -H "Content-Type: application/json" -H "Cache-Control: no-cache" -H "Postman-Token: 75ab844e-5130-708e-69e9-e87f878108b4" -d '{"name": "xxx",
"full_name": "xxx yyy"}' "http://192.168.244.174:4984/db/123"
JSON response is
{
"id": "123",
"ok": true,
"rev": "1-9324dabc947fc963a754b113d1215ac3"
}

AdMob : How to query admob for my app earnings

I've already configured adMob for my Android apps and have no problem with that.
Right now I'm looking for any way to check my apps earnings (if possible for each of the apps separately) in any given moment.
Somebody knows if there's any API, library or Web Service I can use to access my AdMob account and get info about my apps' statistics and so on ?
I've already checked the official APK but it seems only intended to show the ads in your app and nothing else.
Thanks in advance
I answer myself.
I was doing some research, and I found that after the recent changes on AdMob, and the migration to AdSense, you must use the AdSense API to get this info.
In particular, each Android app is associated with a "adunit" id, so if you want to check the info of any particular app you might use:
https://developers.google.com/adsense/management/v1.4/reference/accounts/reports/generate
with the following data:
accountId = your Publisher ID (pub-XXXXXXX)
startDate and endDate = The interval of dates you want to check
dimension = AD_UNIT_ID
metric = EARNINGS
With this query you'll have the required info, separated by App.
You get the results in JSON form.
There is an AdMob API available to get the AdMob specific data.
It provides a possibility to generate network and mediation reports available. It could be as simple as:
curl -X POST https://admob.googleapis.com/v1/accounts/<your_publisher_id>/mediationReport:generate \
-H "Authorization: Bearer <access_token>" \
-H "Content-Type: application/json" \
--data #- << EOF
{
"report_spec": {
"date_range": {
"start_date": {"year": 2020, "month": 4, "day": 1},
"end_date": {"year": 2020, "month": 4, "day": 1}
},
"dimensions": ["AD_SOURCE", "AD_UNIT", "PLATFORM"],
"metrics": ["ESTIMATED_EARNINGS"]
}
}
EOF
.net: https://developers.google.com/api-client-library/dotnet/apis/admob/v1
java: https://github.com/googleapis/google-api-java-client-services/tree/master/clients/google-api-services-admob/v1
Get an Oauth2.0 access token
With oauth2l
install: https://github.com/google/oauth2l
oauth2l header --json <path_to_secret_json> https://www.googleapis.com/auth/admob.report
path_to_secret_json - is one from the credentials page on the google cloud console.
With curl
Replace the oauth2_client_id with the one you have in your “Cloud project credentials - OAuth 2.0 client IDs” page. (https://console.developers.google.com/apis/credentials?project=)
https://accounts.google.com/o/oauth2/auth?access_type=offline&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fadmob.report&response_type=code&client_id=&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob
Open this link in incognito browser mode;
Follow the instruction, and accept the consonant screen with AdMob publisher's account;
Copy the code, it would be needed for the following request:
curl -L \
-d "client_id=<oauth2_client_id>" \
-d "client_secret=<oauth2_secret>" \
-d "grant_type=authorization_code" \
-d "code=<sign_in_code_from_the_previous_step>" \
-d "redirect_uri=urn:ietf:wg:oauth:2.0:oob" \
https://accounts.google.com/o/oauth2/token
oaut2_client_id and oauth2_secret can be found on the OAuth 2.0 client Id page.
Response:
{
"access_token": "<access_token>",
"expires_in": 3600,
"refresh_token": "<refresh_token>",
"scope": "https://www.googleapis.com/auth/admob.report",
"token_type": "Bearer"
}