"Invalid project" error form Google API Javascript client - javascript

I am starting to play with Google Cloud DNS and I would like to hack a small Javascript project for listing/editing zones / resourceRecords.
I started on the "Getting Started" page which explains and offers some samples of the JS query/edit process. The thing is I got at some point where Google API responds with and "Invalid project" error for all supplied values of the 'project' parameter. I am using the clientID for the web application from the Google Developer Console for the oAuth part. The project name I am using is the string named PROJECT ID in google (the same one I am using successfully in the gcloud command-line tools or the on-line JS testground).
According to this: https://content.googleapis.com/discovery/v1/apis/dns/v1beta1/rpc the dns.resourceRecordsSets.list requires two parameters: managedZone and project. If I do a call without params I get this:
[
{
"error": {
"code": 400,
"message": "Required value: managedZone",
"data": [
{
"domain": "global",
"reason": "required",
"message": "Required value: managedZone"
},
{
"domain": "global",
"reason": "required",
"message": "Required value: project"
}
]
},
"id": "gapiRpc"
}
]
which is perfectly fine...
Next I add the project and the managedZone params and then I get this:
[
{
"error": {
"code": 400,
"message": "Invalid parameter: project",
"data": [
{
"domain": "global",
"reason": "invalidParameter",
"message": "Invalid parameter: project",
"locationType": "parameter",
"location": "project"
}
]
},
"id": "gapiRpc"
}
]
Here is my API call code.... I also tried checking the JS code from Google with no success in finding the "Invalid parameter" code...
gapi.client.load('dns', 'v1beta1', function() {
var request = gapi.client.dns.resourceRecordSets.list({
'project': 'lolName',
'managedZone': 'lolZone'
});
request.execute(function(resp) {
console.log(resp);
if (resp.code == 200) {
// do some displaying
}
else {
document.getElementById('content').appendChild(document.createTextNode('Error: ' + resp.message));
}
});

Related

AWS Security Hub API does not return Latitude and Longitudes

I am working on a project which needs to display the identified AWS security threats on a globe. They have specifically asked to use Security Hub API to get the GaurdDuty, Firewall etc. identified threats by integrating them to Security Hub. We were able to correctly integrate that part and it's working fine. However, in order to display this security threat in a globe it is a must to get the latitude and longitude of the location it occurred. Even though GuardDuty identifies these location it is not returned with Security Hub API response as they mention.
For example I referred https://docs.aws.amazon.com/securityhub/1.0/APIReference/API_GetFindings.html
Here they mention that response will contain an Action field which contains all the remote IP details. But in my case this field is null for the GuardDuty incident I created. However, this as a GuardDuty product field it is returning these data. Just wanted to check whether there's anything I am missing in here.
I am expecting to see following fields in the Security Hub API response for an identified GuardDuty incident.
"Action": {
"ActionType": "string",
"AwsApiCallAction": {
"AffectedResources": {
"string" : "string"
},
"Api": "string",
"CallerType": "string",
"DomainDetails": {
"Domain": "string"
},
"FirstSeen": "string",
"LastSeen": "string",
"RemoteIpDetails": {
"City": {
"CityName": "string"
},
"Country": {
"CountryCode": "string",
"CountryName": "string"
},
"GeoLocation": {
"Lat": number,
"Lon": number
},
"IpAddressV4": "string",
"Organization": {
"Asn": number,
"AsnOrg": "string",
"Isp": "string",
"Org": "string"
}
},
"ServiceName": "string"
},
I used the #aws-sdk/client-securityhub npm package to write the program to invoke security hub API.
Following is the Javascript code I used in here.
const { SecurityHubClient, GetFindingsCommand } = require("#aws-sdk/client-securityhub");
const client = new SecurityHubClient({
region: "ap-south-1",
credentials: {
accessKeyId: "",
secretAccessKey: ""
}
});
const params = {
/** input parameters */
"Filters": {
"ProductName": [
{
"Comparison": "EQUALS",
"Value": "GuardDuty"
}
],
}
};
const command = new GetFindingsCommand(params);
async function getAllSeucrityHubFindings(){
try {
const data = await client.send(command);
console.log(JSON.stringify(data));
} catch (error) {
console.log(error);
} finally {
}
}
getAllSeucrityHubFindings();
It's highly appreciated if someone can help me to resolve this issue.
Thanks in advance

Yup: How to access the "inner" propriety in ValidationError() method

Yup contain a method name validationError whose one of properties is "inner". Accordingly with the documentation:
in the case of aggregate errors, inner is an array of ValidationErrors
throw earlier in the validation chain. When the abortEarly option is
false this is where you can inspect each error thrown, alternatively,
errors will have all of the messages from each inner error.
However, it's properly working is not quite clear to me. How exactly I do to access this property and use it in my code.
Here, I'm trying to use in this application but it seems not working.
function validator (req, res, next) {
yup.setLocale({
mixed: {
default: 'Não é válido',
}
});
const schema = yup.object().shape({
name: yup.string().required("Legendary name is required"),
type: yup.string().required("Legendary type is required"),
description: yup.string().required("Legendary description is required").min(10)
});
let messageError = new yup.ValidationError([`${req.body.name}`, `${req.body.type}`, `${req.body.description}`]);
if(!schema.isValidSync(req.body, {abortEarly: false})) {
return res.status(400).json(messageError.inner);
}
When I run it with insomnia, I get a empty array only.
Can someone help me with this, please ?
ValidationError is thrown is by the validate* methods (validate, validateSync, validateAt, and validateSyncAt) when the validation fails. isValidSync returns a boolean and doesn't throw any errors. Use validateSync and add a catch block to access the validation errors.
messageError.inner returns an empty array since messageError is a standalone ValidationError object which isn't associated with the schema in any way.
try {
schema.validateSync(req.body, { abortEarly: false })
} catch (err) {
// err is of type ValidationError
return res.status(400).json(err.inner)
}
curl -s -X POST http://localhost:5000/test | jq
[
{
"name": "ValidationError",
"path": "name",
"type": "required",
"errors": [
"Legendary name is required"
],
"inner": [],
"message": "Legendary name is required",
"params": {
"path": "name"
}
},
{
"name": "ValidationError",
"path": "type",
"type": "required",
"errors": [
"Legendary type is required"
],
"inner": [],
"message": "Legendary type is required",
"params": {
"path": "type"
}
},
{
"name": "ValidationError",
"path": "description",
"type": "required",
"errors": [
"Legendary description is required"
],
"inner": [],
"message": "Legendary description is required",
"params": {
"path": "description"
}
}
]

MercadoPago custom checkout throughs ""customer not found " error

I am working with mercadoPago Api of custom checkout. Firstly, i created a customer on mercado Api against my access token, then created a card token from the information user enter i.e card_number, security code etc, and finally i send a post request on mercadoPago payment Api by using customer email and card token but return error of "customer not found".
My request
{
"transaction_amount": 100,
"token": "2fe6477a6b238e2e90b055f5ad1f3735",
"description": "Title of what you are paying for",
"installments":1,
"payment_method_id": "visa",
"payer": {
"email" : "test#test.com"
}
}
and the response is
{
"message": "Customer not found",
"error": "bad_request",
"status": 400,
"cause": [
{
"code": 2002,
"description": "Customer not found",
"data": null
}
]
}
the url is
https://api.mercadopago.com/v1/payments?access_token=my_access_token

Node.js/Mongo schema validation error regardless of POST data

I have mongo and node playing together on AWS EC2. Node (w/ Express) can connect to Mongo so to start with I've setup a schema with two required fields "sesh" and "location".
This is the javascript that gets called for the post query:
app.post('/spotters', function(req,res){
var newSesh = new modelentry(req.body);
newSesh.save(function(err){
if(err)
res.send(err);
res.json(req.body);
});
});
modelentry is the schema of course.
I'm trying to POST the following raw/json data using Postman
{
sesh: 1,
location: [1,2]
}
However I always recieve a validation failed message, as follows:
{
"message": "hotuser validation failed",
"name": "ValidationError",
"errors": {
"location": {
"message": "Path `location` is required.",
"name": "ValidatorError",
"properties": {
"type": "required",
"message": "Path `{PATH}` is required.",
"path": "location"
},
"kind": "required",
"path": "location"
},
"sesh": {
"message": "Path `sesh` is required.",
"name": "ValidatorError",
"properties": {
"type": "required",
"message": "Path `{PATH}` is required.",
"path": "sesh"
},
"kind": "required",
"path": "sesh"
}
}
}
I have looked at a lot of example code and tried tinkering with the functions in app.post but I'm not making any progress. I would really appreciate any help.

Node ARI Client | Connect method not firing callback?

So, I've started playing with the Asterisk Restful Interface (ARI).
I have created a separate express app to do this.
I have a correctly configured instance of Asterisk 13 running. I know this because When I go to https://192.168.46.122:8088/ari/sounds in my browser, I am prompted for a username and password, which when entered, returns a valid JSON object back with the expected data...
[
{
"id": "conf-now-unmuted",
"text": "The conference is now unmuted.",
"formats": [
{
"language": "en",
"format": "gsm"
}
]
},
{
"id": "vm-nomore",
"text": "No more messages.",
"formats": [
{
"language": "en",
"format": "gsm"
}
]
},
{
"id": "vm-review",
"text": "press 1 to accept this recording press 2 to listen to it press 3 to rerecord your message",
"formats": [
{
"language": "en",
"format": "gsm"
}
]
},
{
"id": "demo-echodone",
"text": "The echo test has been completed.",
"formats": [
{
"language": "en",
"format": "gsm"
}
]
},
{
"id": "confbridge-rest-talk-vol-out",
"text": "...to reset your speaking volume to the default level.",
"formats": [
{
"language": "en",
"format": "gsm"
}
]
}, ...... etc etc
In my app.js file I have included the following code...
...
var logger = require('morgan');
var client = require('ari-client');
var url = 'https://192.168.46.122:8088/ari/sounds';
var username = 'correct_username';
var password = 'correct_password';
client.connect(url, username, password, function (err, ari) {
console.log('HELLLLLLOOOOO!!');
});
...
The issue, is that the anon callback is never fired. I never see 'HELLLLLLOOOOO!!'
Can anyone shed any light on why/under what circumstances this could happen? Are there any known bugs with the module that could be causing this?
Please let me know if you need further information about config, environment etc.
Thanks guys
UPDATE
Following comments below... I have tried the following:
client.connect(url, username, password)
.then(function(ari) {
console.log('HELLLLLLOOOOO!!');
})
.catch(function(err){
console.log('ERR: ' + err);
});
AND
client.connect(url, username, password, function (err, ari) {
if(err) console.log(err);
console.log('HELLLLLLOOOOO!!');
});
No error and no 'HELLLLLOOOOOO!!' at any point :-(
UPDATE 2
Have just visited /ari/api-docs/resources.json and got the following response... so it looks like it is present.
{
"_copyright": "Copyright (C) 2012 - 2013, Digium, Inc.",
"_author": "David M. Lee, II <dlee#digium.com>",
"_svn_revision": "$Revision: 430337 $",
"apiVersion": "1.7.0",
"swaggerVersion": "1.1",
"basePath": "http://192.168.46.122:8088/ari",
"apis": [
{
"path": "/api-docs/asterisk.{format}",
"description": "Asterisk resources"
},
{
"path": "/api-docs/endpoints.{format}",
"description": "Endpoint resources"
},
{
"path": "/api-docs/channels.{format}",
"description": "Channel resources"
},
{
"path": "/api-docs/bridges.{format}",
"description": "Bridge resources"
},
{
"path": "/api-docs/recordings.{format}",
"description": "Recording resources"
},
{
"path": "/api-docs/sounds.{format}",
"description": "Sound resources"
},
{
"path": "/api-docs/playbacks.{format}",
"description": "Playback control resources"
},
{
"path": "/api-docs/deviceStates.{format}",
"description": "Device state resources"
},
{
"path": "/api-docs/mailboxes.{format}",
"description": "Mailboxes resources"
},
{
"path": "/api-docs/events.{format}",
"description": "WebSocket resource"
},
{
"path": "/api-docs/applications.{format}",
"description": "Stasis application resources"
}
]
}
I'm now thinking it may be an SSL issue?!
Your connection is failing (for reasons outlined below), and because of an issue / upcoming-feature in node-ari-client, the failed connection is not logged.
The node-ari-client module uses Swagger, which expects to load a JSON schema describing an API. In the node-ari-client implementation, Swagger expects to find this JSON schema at %s//%s/ari/api-docs/resources.json.
So, the first thing to check is whether or not this exists / is accessible in your application:
https://192.168.46.122:8088/ari/api-docs/resources.json
There could be several reasons why this would not be available, but most likely the problem is authentication. You mention that when visiting your URL you are "prompted for a username and password". If your JSON schema (or any other files that need to be accessed without credentials) are behind authentication, you are going to need to rethink your application structure.
Currently, if there is a connection failure before Swagger has loaded the JSON schema, node-ari-client will fail silently. There is a Pull Request waiting which addresses this issue and would log the error, but in the meantime you should address the underlying issues which are preventing the connection.
If you can successfully access resources.json, there may be other issues with accessing resources. The URL you describe is accessing your service over https, but your resources.json file is telling Swagger to access it over regular http. To handle this, you could try:
Changing the basePath in your Swagger schema to use https:
"basePath": "https://192.168.46.122:8088/ari",
Adding a protocols field to your Swagger schema:
"protocols":["http", "https"]
Removing https
This is probably a good option in order to discover if https is the cause of the connection issue. Simply keep the Swagger schema exactly as is and try accessing / connecting to your services over http. Does this make a difference?

Categories