Consul ACL Rule specification (HTTP API) - acl

I'm trying to modify an ACL token I've just created by sending the following JSON via the HTTP API:
{
"ID": "UUID HERE",
"Name": "loadbalancer",
"Type": "client",
"Rules": "service {policy=read}"
}
However, this syntax for my Rules is being rejected. I've also tried sending information in JSON format similar to how it's documented in the ACL Internals page:
{
"ID: "UUID HERE",
"Name": "loadbalancer",
"Type": "client",
"Rules":
{
"service":
{
"": { "policy": "read" }
}
}
}
These are all rejected as having incorrect formatting. What's the correct syntax here?

{
"ID: "UUID HERE", ==> missing double quote in "ID"
"Name": "loadbalancer",
"Type": "client",
"Rules":
{
"service":
{
"": { "policy": "read" }
}
}
}

Related

How to merge swagger multiple files in single swagger doc file?

I have different swagger files for multiple APIs, like swagger1.json for OpenStack API, swagger2.json for Users API etc and I was trying to merge these all swagger files in one single file using remote $ref method.
Here is swagger1.json file for OpenStack api
{
"stacks": {
"get": {
"tags": [
"openstack"
],
"summary": "Returns stacks from OpenStack",
"description": "Returns all stacks from the OpenStack based on tenantId.",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"parameters": [
{
"in": "query",
"type": "string",
"name": "tenantId",
"description": "search stacks for tenantId from OpenStack",
"required": false
}
],
"responses": {
"200": {
"description": "OK"
},
"400": {
"description": "Unknown Error"
},
"401": {
"description": "Unauthorized"
}
}
}
}
}
And this is the swagger-merge.json where I want to add multiple swagger doc file using remote reference.
{
"swagger": "2.0",
"info": {
"description": "something here",
"version": "v0.7.0",
"title": "The API Gateway",
"contact": {
"email": "dp#gmail.com"
}
},
"host": "localhost",
"port":"9191",
"basePath": "/api/openstack",
"tags": [
{
"name": "OpenStackApi",
"description": "Get stacks and running instance form OpenStack"
}
],
"schemes": [
"https"
],
"paths": {
"$ref": "./swagger1.json#/stacks"
}
}
This isn't working for me. I am not able to see API methods I have written inside swagger1.json file. I have upload swaggerUI output. Any idea about what I am doing wrong and how can I solve this issue?
You can't $ref the whole contents of paths, you can only refer individual path items:
"paths": {
"/stacks": { <--- endpoint path
"$ref": "./swagger1.json#/stacks"
}
}

Why does the "schema" disappear from the "responses" object when importing an OpenAPI definition?

I can successfully import the following OpenAPI definition into Azure API Management.
However, when I export the OpenAPI definition, the "schema" name has been removed from the "responses" object. As a result, developers in my portal are not shown a schema or example for this operation.
My API definition is valid and functions correctly if added to the official editor.
How can I prevent the schema from being stripped out?
{
"swagger": "2.0",
"info": {
"title": "Foo",
"description": "Foo",
"version": "1"
},
"host": "example.org",
"schemes": [
"https"
],
"paths": {
"/foo": {
"get": {
"summary": "List all foo.",
"responses": {
"200": {
"description": "Success.",
"schema": {
"$ref": "#/definitions/Foo"
}
}
}
}
}
},
"definitions": {
"Foo": {
"type": "object",
"properties": {
"example": {
"type": "string",
"description": "An example."
}
}
}
}
}
This problem seems to occur when the definition lacks a "produces" name, in either the root object, or in the operation object.
For example, the following definition should import successfully, and then export without the "schema" being stripped away. Note that the "produces" name has been added to the root object, in between "schemes" and "paths"
{
"swagger": "2.0",
"info": {
"title": "Foo",
"description": "Foo",
"version": "1"
},
"host": "example.org",
"schemes": [
"https"
],
"produces": ["application/json"]
"paths": {
"/foo": {
"get": {
"summary": "List all foo.",
"responses": {
"200": {
"description": "Success.",
"schema": {
"$ref": "#/definitions/Foo"
}
}
}
}
}
},
"definitions": {
"Foo": {
"type": "object",
"properties": {
"example": {
"type": "string",
"description": "An example."
}
}
}
}
}

Error 400 when using Google API Explorer

I'm getting the following error when using the Google API Explorer to insert into GCP's Datastore.
I've tried using another name and ID, but still the error. How do I rectify this?
Below are the request body and error.
{
"mode": "Transactional",
"mutations": [
{
"insert": {
"key": {
"path": [
{
"id": "56294995342131231",
"name": "CL-001",
"kind": "Log"
}
],
"partitionId": {
"namespaceId": "",
"projectId": "triplog-169706"
}
},
"properties": {
"Title": {
"stringValue": "Space Needle"
},
"Longitude": {
"doubleValue": 0.00
},
"Latitude": {
"doubleValue": 0.00
},
"Date": {
"timestampValue": "2015-07-03T10:51:50.649Z"
},
"Rating": {
"integerValue": "5"
},
"Notes": {
"stringValue": "Wonderful site to see"
}
}
}
}
]
}
{
"error": {
"code": 400,
"message": "Invalid value at 'mutations[0].insert.key.path[0]' (oneof), oneof field 'id_type' is already set. Cannot set 'name'",
"status": "INVALID_ARGUMENT",
"details": [
{
"#type": "type.googleapis.com/google.rpc.BadRequest",
"fieldViolations": [
{
"field": "mutations[0].insert.key.path[0]",
"description": "Invalid value at 'mutations[0].insert.key.path[0]' (oneof), oneof field 'id_type' is already set. Cannot set 'name'"
}
]
}
]
}
}
Based on the docs, it looks like you should only be setting either a "name" or "id" in the Path Element, not both.
https://cloud.google.com/datastore/docs/reference/rest/v1/Key#PathElement
I've finally got it.
To get the "transaction", just run the beginTransaction API.
POST https://datastore.googleapis.com/v1/projects/{projectId}:beginTransaction
This will response with an identifier, which is a long string. Use that as the value of the "transaction".

Problems with v1/queryContext needed for SpagoBI integration

In version 1.7.0 of Orion CB running the docker version in Docker for Windows,
if I create a simple object doing POST http://localhost:1026/v1/updateContext
with the body:
{
"contextElements": [
{
"type": "Car",
"id": "myNewCar",
"attributes": [
{
"name": "maxSpeed",
"type": "integer",
"value": "220"
}
]
}
],
"updateAction": "APPEND"
}
I get the answer:
{
"contextResponses": [
{
"contextElement": {
"type": "Car",
"isPattern": "false",
"id": "myNewCar",
"attributes": [
{
"name": "maxSpeed",
"type": "integer",
"value": ""
}
]
},
"statusCode": {
"code": "200",
"reasonPhrase": "OK"
}
}
]
}
Then, if I do POST http://localhost:1026/v1/queryContext with the same headers and the same components with the body
{
"entities": [
{
"type": "Car",
"isPattern": "false",
"id": "myNewCar"
}
]
}
I get the following:
{
"errorCode": {
"code": "404",
"reasonPhrase": "No context element found"
}
}
Which shouldn't be problematic (I can query the entities with v2 API, for instance) if it wasn't needed for integration with data representation tools such as SpagoBI as documented in http://spagobi.readthedocs.io/en/latest/user/NGSI/README/
What can I do? I am doing something wrong with the context provision?
Thanks!
My problem was that I was using a imported Postman collection of the API (Downloaded from https://github.com/telefonicaid/fiware-orion/tree/develop/doc/apiary/v2) and accidentally I was using the header Fiware-Service.
You are right and your tests work properly.
Thanks for the prompt reply!!

Swagger editor always gives error on json

For me not a single json string worked with the swagger editor.
Here is an example which i took from the page:
{
"swaggerVersion": "2.0",
"basePath": "http://localhost:8000/greetings",
"apis": [
{
"path": "/hello/{subject}",
"operations": [
{
"method": "GET",
"summary": "Greet our subject with hello!",
"type": "string",
"nickname": "helloSubject",
"parameters": [
{
"name": "subject",
"description": "The subject to be greeted.",
"required": true,
"type": "string",
"paramType": "path"
}
]
}
]
}
],
"models": {}
}
So current error for this, is:
✖ YAML Syntax Error
Missed comma between flow collection entries at line 2, column 14: "swagger: "2.0", ^
I don't know where did you take the base code for but that syntax seems to be totally wrong (at least for swagger 2), I recommend you to take a look to the official specification.
About the code you pasted, I refactorized it, try with this one:
{
"swagger": "2.0",
"host": "localhost:8000",
"basePath": "/greetings",
"info": {
"title": "Some title",
"version": "0.0.1"
},
"paths": {
"/hello/{subject}": {
"get": {
"summary": "Greet our subject with hello!",
"parameters": [{
"name": "subject",
"description": "The subject to be greeted.",
"required": true,
"type": "string",
"in": "path"
}],
"responses": {
"default": {
"description": "Some description",
"schema": {
"type": "string"
}
}
}
}
}
}
}
Even though the OP's syntax was wrong, this is for other people who are searching for an answer and their syntax is correct.
If you are getting the JSON data from the browser and you have a browser extension that formats and displays nicely the JSON data, it might cause trouble (because of the formatting) when pasting in Swagger Editor.
If that's the case, try disabling the extension or go incognito.