Google reCAPTCHA Enterprise Unknown field error when Create Assessment - ruby-on-rails

I did follow their documentation on https://googleapis.dev/ruby/google-cloud-recaptcha_enterprise-v1/latest/index.html
I first added the env variable RECAPTCHA_ENTERPRISE_CREDENTIALS then run the
client = ::Google::Cloud::RecaptchaEnterprise::V1::RecaptchaEnterpriseService::Client.new
documentation says response = client.create_assessment request but documentation didn't add sample request so I did assume that it will look like in this documentation https://cloud.google.com/recaptcha-enterprise/docs/create-assessment
{
"event": {
"token": "token",
"siteKey": "key"
}
}
But when I execute the client.create_assessment it is giving me error ArgumentError: Unknown field name 'event' in initialization map entry.
I also tried to follow this https://googleapis.dev/ruby/google-cloud-recaptcha_enterprise-v1/latest/Google/Cloud/RecaptchaEnterprise/V1/RecaptchaEnterpriseService/Client.html#create_assessment-instance_method
where the parameters is request and also gives me error ArgumentError: Unknown field name 'request' in initialization map entry.
What could be the correct parameter/request for creating assessment?
Gem I used is google-cloud-recaptcha_enterprise-v1 and google-cloud-recaptcha_enterprise

So I solve this issue by using client.create_assessment(parent: "projects/{your project-id}", assessment: event) my event value was event = Google::Cloud::RecaptchaEnterprise::V1::Event.new(token: "token from execute", site_key: "your site key")
It solves the error and answers the question (but another error after this one occurred about permission denied). I Will update once resolved.

Related

Power Automate error when trying to add an attachment array from plumsail

I have a Plumsail form where a user can attach several pdf or word documents. In power automate I create an array of these documents and then attach the array to the "Start and wait for approval" action. When I run it, I get the error below:
The request failed. Error code: 'InvalidRequestContent'. Error
Message: 'The request content was invalid and could not be
deserialized: 'Could not find member 'ContentBytes' on object of type
'ApprovalsConnectorAttachment'.
I'm assuming you followed the How to send an email from Plumsail form with Power Automate Plumsail guide as it tells you to assign the HTTP GET file response to a property named ContentBytes.
While this will work with the Send an Email (V2) action (from the guide) the Start and wait for an approval action expects a property named content content.
To fix the problem append the following object to the array (note the contentproperty):
{
"name": #{items('Apply_to_each_2')?['file']},
"content": #{body('HTTP')}
}
or as an image:

Serverless - Change the content before deploy

I'm using Serverless for working with our aws lambda / appsync.
For Error Handling, we are keep erro code with message in a json file. The Codes will be unique. Something like this:
//error-code.json
{
"1"": { code: 1, message: "Invalid User Input"},
"2"": { code: 2, message: "Invalid Input"},
//... so on
}
This wil lbe deploy as layer and all the lambda will use it. Issue is we cannot use it in the resolve template. There are some of the resolver will be only template file. These template files cannot access the json file nor can access the layer. How can I use the error-code.json here?
Solution 1:
Manually write the error code in templates and make sure there are alway unique. Something like this:
#set(#errorInfo = {
"erroCode": "1",
"errorMessage": "Invalid Input"
})
$util.error("Invalid Input", "errorType", $ctx.arguments,#errorInfo)
Rejected: Becasue we have to manually check everytime for the unique of error code. In case of lot of template file, we cannot rely on it.
Solution 2:
Create a table with error code (unique) and error message. Use this table to send error from template.
Rejected: Because we use multiple app sync instance and they all connect to dirferent database. So we have to make this table in all database, and thus unique across the app-sync is not maintained.
Solution 3:
Write the placeholder in vtl where we want to send the error. Before Deploy, replace the placeholder with the actual code using pre-hook script, but not in the actual vtl file but in the generated package that serverless deploy. Does Serverless even such thing?
if your errors are all static, there is one more option for consideration.
You create one more file that holds all errors defined in Velocity.
$util.qr( $ctx.stash.put("errors", {}) ) $util.qr(
$util.qr( $ctx.stash.errors.put("ONE", { "code": 1, "message": "Invalid User
Input"} )
...
$util.qr( $ctx.stash.errors.put("TWENTY", { "code": 20, "message": "20th error description"} )
For every velocity resolver that throws errors, you inject pre-defined errors at the beginning of its request mapping's file. Whenever you want to throw an error, it's done by retrieving a pre-defined error from $ctx.stash
$util.error ( $ctx.stash.errors.ONE.message, $ctx.stash.errors.ONE.code )
The error file is generated from error-code.json, or manually typed again for simplicity. $ctx.stash is used because stash is accessible from everywhere in a resolver, including pipeline ones.

JusPayExpress Checkout error - JSURLNotPassed (102)

I am facing a strange issue in JusPayExpressCheckout SDK.
My end url is in the form of - "https://dev.merchant.com/payments/app-success"
I have two options for payment ->
1. Card Payment:
I perform the initialization of environment as:
checkout.environment(SANDBOX, merchantId: AppConstants.PaymentString.merchantId, orderId: model.orderId, cardNumber: model.cardNumber, cardExpiryYear: model.cardExpiryYear, cardExpiryMonth: model.cardExpiryMonth, cardSecurityCode: model.cardSecurityCode, nameOnCard: model.nameOnCard, authType: DEFAULT_AUTHENTICATION, saveToLocker: true, endUrlRegexes: [ "https:\\/\\/dev\\.merchant\\.com\\/payments\\/app-success.*$"])
This Works
2. NetBankingPayment
I perform the initialization of environment as:
checkout.environment(SANDBOX, merchantId: AppConstants.PaymentString.merchantId, orderId: model.orderId, netbankingBank: model.bankId, endUrlRegexes: [ "https:\\/\\/merchant\\.acko\\.com\\/payments\\/app-success.*$"])
Strange... This fails by throwing:
"error - The operation couldn’t be completed. (JuspayError error 102.)"
Even though the regex is same in both the cases.
Can someone please let me know that what is going wrong and if this is a case of wrong endUrlRegex, what is the correct regex for the endURL?
It will always work if the endURL specified while creating the order and the regex specified in the app are matching.
In your case, please check the JusPay sandbox dashboard and verify whether the selected net-banking option is configured properly. 102 error code is returned when payment URL is empty or if a suitable gateway to process the payment is not found.

How to add Error Code to validation attributes in MVC?

I'd like to be able to specify an error code to be returned from my API along with the error message in the event that validation fails. The aim is to specify a validation attribute on a property such as:
[Range(1, int.MaxValue, ErrorMessage = "Page must be 1 or greater", ErrorCode = 1234)]
And, in the event that someone requests page 0, return a 400 Bad Request with a JSON error object in the body like this:
{
"errorCode": 1234,
"errorMessage": "Page : Page must be 1 or greater"
}
I already have a custom ModelValidationFilter which returns an array of error messages from the ModelStateDictionary, so that's all working, but I can't see a straightforward way of getting the error code included in there too without overriding all of the MVC model validation classes.
This seems like a problem which should already have been solved by someone at some point, but I can't find anything to support that theory.

I'm getting troubles while uploading to Youtube with google java client: "Invalid value for: listed is not a valid value"

I'm trying to upload videos using https://code.google.com/p/youtube-api-samples/source/browse/samples/java/youtube-cmdline-uploadvideo-sample/src/main/java/com/google/api/services/samples/youtube/cmdline/youtube_cmdline_uploadvideo_sample/UploadVideo.java example
I've successfully registered on the youtube console and have obtained the client_secrets.json at https://code.google.com/apis/console/?api=youtube#project:340964720118:access
I have installed the secrets so my app can access them; everything is compiled well, but when the program is executed, I'me getting that strange errors:
GoogleJsonResponseException code: 400 : Invalid value for: listed is not a valid value
com.google.api.client.googleapis.json.GoogleJsonResponseException: 400 Bad Request
{
"code" : 400,
"errors" : [ {
"domain" : "global",
"message" : "Invalid value for: listed is not a valid value",
"reason" : "invalid"
} ],
"message" : "Invalid value for: listed is not a valid value"
}
at com.google.api.client.googleapis.json.GoogleJsonResponseException.from(GoogleJsonResponseException.java:145)
at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:113)
at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:40)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:423)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:343)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:460)
I can't find out what is wrong; since the request itself is deeply encapsulated, I can't understand what is wrong with the request...
UPD.
Thanks to
System.out.println(videoInsert.getHttpContent().toString());
call inserted before the
Video returnedVideo = videoInsert.execute();
in the sample code, I got that the JSOn formed and sent to the google is
{snippet={description=Video uploaded via YouTube Data API V3 using the Java library on Sun Sep 29 20:29:30 MSK 2013, tags=[test], title=Test Upload via Java on Sun Sep 29 20:29:30 MSK 2013}, status={privacyStatus=listed}}
But actually there is still a question what is wong with this json and why it causes the error on the the server side.
UPD 2:
And no I no longer get the message above, but the upload is still impossible. I'm getting 401 Error while trying to upload the file in that lines of the example above:
System.out.println(videoInsert.getJsonContent().toString());
System.out.println(videoInsert.getHttpContent().getType());
Video returnedVideo = videoInsert.execute();
System.out.println(returnedVideo.getId());
I supposed that I haven't authorized the request to my personal data, but I actually DID it (the request was loaded to the default browser where I have accepted it and specified the account I would like to work with). However, there is no way to check that authoriation; my google account data holds only Apps and Activity log for the google+ apps; I haven't fount my app in the list. So where I can check where I'm not logged in?
IOException: 401 Unauthorized
com.google.api.client.googleapis.json.GoogleJsonResponseException: 401 Unauthorized
at com.google.api.client.googleapis.json.GoogleJsonResponseException.from(GoogleJsonResponseException.java:145)
at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:113)
at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:40)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:423)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:343)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:460)
at ScreenRecordingExample.UploadToYoutube(ScreenRecordingExample.java:356)
Ok, I have found out that the problem appeared due to the incorrect privacyStatus value:
I had
status.setPrivacyStatus("listed");
in my code, while it seems that only public, unlisted and private are possible values
And the UPD-2 problem was resolved unfortunately in the way i don't know exactly how:
i have noticed, that in my code example there was a line
return new AuthorizationCodeInstalledApp(flow, localReceiver).authorize("user");
I have replaced 'user' with my google user name (but actually I'm not sure that it was a thing that was really needed). After that replacement the authorization attempt started again (default browser loaded the accept/decline page and there I should select one of two accounts). Since I have two accounts, the original youtube one and the common google one, and during the last attempt I have selected the google's one and got 401 error, I have selected the youtube's one this time.
so, after that the problem was resolved. I still don't know do it due to the correct username instead of 'user' or due to the correct account selection. If someoune kows the truth, please comment!

Resources