Is Avro Schema Registry compatibility lost when using arrays? - avro

I'm using Confluent Avro Schema Registry with backward compatibility option. I upload this schema which is a record inside an array (the [ ]-brackets). This record only contains one string field.
curl -X POST -i -H "Content-Type: application/vnd.schemaregistry.v1+json" --data '{"schema": "[{\"type\": \"record\", \"name\": \"TestRecord\", \"namespace\": \"com.company\", \"fields\": [{\"name\": \"testname\", \"type\": \"string\"}]}]"}' http://localhost:8081/subjects/test99-value/versions
Everything goes well and I get a success response back (200).
Now I want to sanity check this so I remove the string field and I add a integer field. This should definitely not be compatible, neither forward nor backwards.
curl -X POST -i -H "Content-Type: application/vnd.schemaregistry.v1+json" --data '{"schema": "[{\"type\": \"record\", \"name\": \"TestRecord\", \"namespace\": \"com.company\", \"fields\": [{\"name\": \"testname2\", \"type\": \"int\"}]}]"}' http://localhost:8081/subjects/test99-value/versions
The problem is that this also returns a success even though this cannot possibly be correct. Am I missing something very basic here?
If I do this with a record that isn't inside an array I get the expected error from the schema registry.

Related

Ratpack/Groovy - read the body of a call

I want to create a "mock" server using Ratpack/Groovy and we need to read the data-raw from a call
I haven't had a problem reading headers or parameters, but I need to read the body of a request
Examplle:
curl --location --POST request 'http://localhost:5050/authenticate' \
--header 'Content-type: application/json' \
--raw-data '{
"username": "testbase01#domain.com",
"password": "12345678"
}'
we need to parse and process the username and password fields
We have tried to read the request.body, or the body.text, but we have not been successful.
Basically the example found in the solution at https://stackoverflow.com/questions/23636248/parse-json-in-ratpack-groovy would be what we need, but it hasn't worked for us either
Our environment has the following dependencies
#Grab('io.ratpack:ratpack-groovy:1.6.1'),
#Grab('org.slf4j:slf4j-simple:1.7.22'),
#Grab("io.ratpack:ratpack-jackson:0.9.17")
and we are using https://github.com/Vad1mo/hello-world-rest as primary image
If you have a small example, to be able to adapt it to our needs

Microsoft Graph REST API to UPDATE Microsoft Planner Tasks?

I think this might be a simple quote escape issue, but can’t figure it out.
I am trying to update a microsoft planner task using CURL with REST API. I can CREATE tasks (from a custom application called FileMaker to Microsoft Planner using Microsoft Graph API) without issue, but when I try to UPDATE a planner task, I get an error that "The If-Match header must be specified for this kind of request." But I am including the If-Match header, just might not be entering it correctly.
The URL is:
"https://graph.microsoft.com/v1.0/planner/tasks/" & $microsoftplannerTaskID
The CURLOPTIONS, I am entering within FileMaker is ...
"-X PATCH " &
" -H "Authorization: Bearer " & $$userToken & """ &
" -H "Content-Type: application/json"" &
" -H "If-Match: " & $microsoftPlannerTasketag & """ &
" -d #$PlannerTaskDetails"
ENDS UP LOOKING LIKE THIS …
-X PATCH -H "Authorization: Bearer wEXu<>k_QQY" -H "Content-Type: application/json" -H "If-Match: W/"JzEtVGFzayAgQEBAQEBAQBAQEBARCc="" -d #$PlannerTaskDetails
When I CREATE the task initially, the response show …
"#odata.etag":"W/"JzEtVGFzayAgQEBAQEBAQEBAQEBAQEBARCc=""
Which I am using in the cURL header above. BUT … I am stripping the W/ and the quotes. The W/ means it is a “weak”, and I assume we don’t include that in the PATCH header, but I did try adding it anyway with no success.
Here is Microsoft’s UPDATE PLANNERTASK reference …
https://learn.microsoft.com/en-us/graph/api/plannertask-update?view=graph-rest-1.0&tabs=http
I can update tasks using POSTMAN without issue, but I dont know what their header looks like when it sends the request.
I can get it to work in Postman and in there I have entered for the Plan ETag variable this …
W/"JzEtVGFzayAgQEBAQEBAQEBAQEBAQEBARCc="
I notice in postman the header shows etag is
W/"JzEtVGFzayAgQEBAQEBAQEBAQEBAQEBARCc="
And the body returns as
"#odata.etag": "W/"JzEtVGFzayAgQEBAQEBAQEBAQEBAQEBARCc="",
It’s got to be a simple syntax issue with my curloption variable, but I can’t figure it out.
I also tried removing the W/ in the If-Match header, so it looks like this:
-H "If-Match: "JzEtVGFzayAgQEBAQEBAQEBAQEBAQEBARCc=""
And the extra quotes in the If-Match header, so it looks like this:
-H "If-Match: JzEtVGFzayAgQEBAQEBAQEBAQEBAQEBARCc="
All of these result in the same “if-match” error.
One interesting thing …if I change the If-Match to include a slash in front of the quotes
-H "If-Match: "JzEtVGFzayAgQEBAQEBAQEBAQEBAQEBARCc=""
I get an error 10 “requested data is missing” in Filemaker’s script debugger and no response from the insert from url statement. Makes sense though, since it is reading this as “if-match: ”
And same thing if I add the W/ back in
-H "If-Match: W/"JzEtVGFzayAgQEBAQEBAQEBAQEBAQEBARCc=""
Gives me error 10 as well
If you have any thoughts, I would greatly appreciate your help!!
Try this:
"-X PATCH " &
"-H " & quote("Authorization: Bearer " & $$userToken) &
"-H " & quote("Content-Type: application/json") &
"-H " & quote("If-Match: W/" & quote($microsoftPlannerTasketag)) &
"-d #$PlannerTaskDetails"

how to Parse json data into a chef recipe attributes

How to parse a json output from a rest curl command as an attribute value in the default.rb file
Use Case:
In the Chef recipe Attributes --> attributes.rb file has the following default attributes which will be consumed by my recipe and these values needs to be randomly generated using a curl command which outputs it in form of a json output
default['agent']['id'] = 'F73D3CA4-!#!#-653A-XXXX-BBBBBB'
default['agent']['token'] = '90F1C7EA-*()*-YYYY-2528-ZZZZZZ'
This value is used in the recipes --> act.rb
Syntax used
tenant_id = node['agent']['id']
token = node['agent']['token']
The recipe makes use of the tenant_id and token in the following way in the recepie
dsa_args << " \"tenantID:#{tenant_id}\" \"tenantPassword:#{token}\""
The curl command to get the the id and token is:
curl --insecure -X GET -H "content-type: application/json" -H
"Accept: application/json" -d '{}'
https://XXX.XX.XXX.XX/rest/bat/rant/tenant?
name=Ante%20Data%20Wortyu%20Details
The Output is in the below format
{"id":"16","name":"Ante Data Wortyu Details","state":"ACTIVE", "tenantID":"F73D3CA4-!#!#-653A-XXXX-BBBBBB","tenantPassword":"90F1C7EA-()-YYYY-2528-ZZZZZZ"}
How would one pass the json formated output into my Chef Recipe or to the attributes file.
I went through the below link to get it completed but it fails with unauthorised errors:
https://www.twilio.com/blog/2015/10/4-ways-to-parse-a-json-api-with-ruby.html
Any help is greatly appreciated.
Thank you,
This is somewhat contrived and might not suit your entire use-case, but is an example of how you could parse the response body of an HTTP request as JSON and use it for Chef attributes.
# recipes/something.rb
require 'rest-client'
require 'json'
jsonResponse = JSON.parse(RestClient.get(URL))
node.override['agent']['id'] = jsonResponse["tenantID"]
node.override['agent']['token'] = jsonResponse["tenantPassword"]

cURL POST --data-binary vs --form

I have a simple question regarding to the usage of cURL. Didn't find much during my Google search or Man page to get a clear answer.
In here talks about using either --data vs --form on sending file/attachment. I'm curious to know what are the main difference and under what scenarios you would pick --data-binary VS --form ?
The POST "body" can be sent via either --data (for application/x-www-form-urlencoded) or --form (for multipart/form-data):
-F "foo=bar" # 'foo' value is 'bar'
-F "foo=<foovalue.txt" # the specified file is sent as plain text input
-F "foo=#foovalue.txt" # the specified file is sent as an attachment
-d "foo=bar"
-d "foo=<foovalue.txt"
-d "foo=#foovalue.txt"
-d "#entirebody.txt" # the specified file is used as the POST body
--data-binary "#binarybody.jpg"
The difference is explained in the HTML 4.01 Specification section on Forms:
application/x-www-form-urlencoded is the default content type.
The content type "application/x-www-form-urlencoded" is inefficient for sending large quantities of binary data or text containing non-ASCII characters. The content type "multipart/form-data" should be used for submitting forms that contain files, non-ASCII data, and binary data.
That's exactly the main difference, type of data that's being sent to the server (application/x-www-form-urlencoded vs multipart/form-data)

mime-encoded as application/octet-stream

I am doing curl POST to a service with body containing some json data. I am getting the response as "request body was not mime-encoded as application/octet-stream". What does the response mean?
You probably need to supply a Content-Type header. Depending on what your web server is expecting, you might want to supply it either the mimetype "text/plain" or perhaps "application/x-www-form-urlencoded". In Curl, just include the argument:
-H "Content-Type: text/plain"
So your request will be something like:
curl -i -X POST --data-binary "#your.json" -H "Content-Type: text/plain"
Or substitute "text/plain" for the appropriate mime-type.
So, probably what's happening at the moment is that your web server is being given the content type application/octet-stream, and not understanding what to do with your plain text json content. If you run curl with "-v" it will give you a verbose description of the sent and received headers so you can see what Content-Type it's giving your server by default.
The input have to be a "application".
What you asking for is a mimetype.
Read more here: http://en.wikipedia.org/wiki/Internet_media_type
Please add more information for more informations.

Resources