Meraki group policy deployment using API via Ansible uri module - json

I am trying to create a Meraki group policy via API using Ansible. When running the ansible-playbook, I get "New group policies must have a name" error message. Name is added in the json files.
Can you please check the json and playbook files and help and sorting this issue.
Many Thanks.
Playbook.yml
- name: Group Policy via API
hosts: localhost
gather_facts: no
tasks:
- name: Deploy Group Policy
uri:
url: https://api.meraki.com/api/v1/networks/xxxxxxxxxxxxxxxxxxx/groupPolicies
method: POST
return_content: yes
headers:
X-Cisco-Meraki-API-Key:xxxxxxxxxxxxxxxxxxxxxxxxxxx
body_format: json
body: "{{ lookup('ansible.builtin.file','create_body_4.json') | to_json }}"
create_body.json
{
"name": "test01"
}
I have also tried the RequestBody(JSON) from the Meraki example (https://developer.cisco.com/meraki/api-v1/#!create-network-group-policy) but still get the same error message. It seems like "create_body.json" file is not in correct format hence "name" is not parsed properly.
Many thanks.
Issue Resolved:
Removed | "to_json" from body as file was already in json
Correct format is
body: "{{ lookup('ansible.builtin.file','create_body_4.json')

Related

how to create swagger editor yaml file for fromData Parameters to 1.Upload file from Local and 2.Pass json value [duplicate]

I am trying to use Swagger to define an API that accepts an actual file and a schema object that describes the contents of a file. Here is a snippet of the Swagger YAML. However it won't validate in the Swagger Editor.
/document:
post:
summary: Api Summary
description: Api Description
consumes:
- multipart/form-data
parameters:
- name: documentDetails
in: formData
description: Document Details
required: true
schema:
$ref: '#/definitions/Document'
- name: document
in: formData
description: The actual document
required: true
type: file
The Swagger Editor throws the following validation error:
Swagger Error: Data does not match any schemas from 'oneOf'
Am I missing something? Or Is this not a supported feature of Swagger?
This is possible in OpenAPI 3.0, but not in OpenAPI/Swagger 2.0.
OpenAPI/Swagger 2.0 does not support objects in form data. Form parameters can be primitive values, arrays of primitives, and files, but not objects. So your example cannot be described using OpenAPI 2.0.
In OpenAPI 3.0, you can use:
paths:
/document:
post:
summary: Api Summary
description: Api Description
requestBody:
required: true
content:
multipart/form-data:
# Form parameters from 2.0 become body schema properties in 3.0
schema:
type: object
properties:
# Schema properties correspond to individual parts
# of the multipart request
document:
# In 3.0, files are binary strings
type: string
format: binary
description: The actual document
documentDetails:
$ref: '#/components/schemas/Document'
# The default Content-Type for objects is `application/json`
required:
- document
- documentDetails
Relevant parts of the 3.0 Specification:
Considerations for File Uploads
Special Considerations for multipart Content
swagger does not support type 'object' in formData, only as body parameters.
It is not possible using Swagger 2.0 , you can only read it as a type 'file' ,
https://swagger.io/docs/specification/2-0/file-upload/
On a related note please be aware that uploading array of files is also not supported in Swagger 2.0 but it is supported in Open API 3.0 .
https://github.com/OAI/OpenAPI-Specification/issues/254

openAPI unable to resolve ref to external file. Component name contains invalid characters

I'm trying to split a large yml into a bunch of smaller yml documents. I followed the example provided by David Garcia here, and then using OpenAPI CodeGenerator to generate my models. OpenAPI Generator complained that [BUG] attribute components.schemas.Schema name doesn't adhere to regular expression ^[a-zA-Z0-9.-_]+$. So, I tried playing with David Garcia's example by cloning his repo and deploying locally, but I get the same error. I decided to check it in the swagger editor, and I get the same issue, but the error message says
Semantic error at components.schemas.$ref
Component names can only contain the characters A-Z a-z 0-9 - . _
Jump to line 25
I'm using the yaml from David Garcia's example:
openapi: "3.0.0"
info:
version: 1.0.0
title: Swagger Petstore
description: Multi-file boilerplate for OpenAPI Specification.
license:
name: MIT
contact:
name: API Support
url: http://www.example.com/support
email: support#example.com
servers:
- url: http://petstore.swagger.io/v1
tags:
- name: pets
paths:
/pets:
$ref: "./resources/pets.yaml"
/pets/{petId}:
$ref: "./resources/pet.yaml"
components:
parameters:
$ref: "./parameters/_index.yaml"
schemas:
$ref: "./schemas/_index.yaml"
responses:
$ref: "./_index.yaml"
You can easily paste this into the editor and see the errors yourself. The OpenAPI Specification says components objects can either be an Object or a Reference, i.e. Map[string, Schema Object | Reference Object], and the Schema Object definition says, "Alternatively, any time a Schema Object can be used, a Reference Object can be used in its place. "
I'm aware that I can sub it down within the yaml document, like so:
components:
parameters:
petId:
$ref: "./parameters/path/petId.yaml"
schemas:
pets:
$ref: "./schemas/Pets.yaml"
responses:
responseSchema:
$ref: "./response/pets200.yaml"
But why can't I reference an external index? The online example says yes and the open api spec says yes, but I can't get it to work.
It's a common misconception that the OpenAPI Specification allows $ref anywhere. Actually, $ref is only allowed in places where the OpenAPI Specification says the value of a field can be a "Reference Object" or a "Schema Object".
Specifically, this snippet is NOT valid OpenAPI syntax:
components:
parameters:
$ref: "./parameters/_index.yaml"
schemas:
$ref: "./schemas/_index.yaml"
responses:
$ref: "./_index.yaml"
Map[string, Schema Object | Reference Object] means that the components.schemas node must be a map where the keys are schema names and the values are either inline schemas or schema references. As in your second example (which is valid OpenAPI syntax):
components:
parameters: # Map
petId: # <string,
$ref: "./parameters/path/petId.yaml" # Reference Object>
schemas:
pets:
$ref: "./schemas/Pets.yaml"
responses:
responseSchema:
$ref: "./response/pets200.yaml"
The workaround that some implementations use to handle $refs in any places is to pre-process the spec using a generic JSON $ref resolver (such as json-refs) to resolve those non-standard $refs. For example, the blog post you took this example from uses swagger-cli to resolve non-standard $refs and create a single merged file.

Add custom params to prometheus scrape request

We have metrics endpoint enabled in our application to get metrics. It requires custom parameter, how to configure prometheus.yaml to send custom param as part of each metrics scrape
Below is my prometheus.yml configuration
# Sample METRICS
- job_name: 'sys-metrics'
metrics_path: '/sys/metrics'
# Optional HTTP URL parameters.
params:
-user-id: ['myemail#email.com']
scrape_interval: 3s
static_configs:
- targets: ['dev.devhost.domain.com:12345']
When I start server, I get marshal error
parsing YAML file prometheus.yml: yaml: unmarshal errors:\n line 37: field -user-id not found in type config.plain"
Any help appreciated
under params, user-id is child element, add tab to resolve. as I defined at same level, prometheus expected to be one of pre-defined config.
params:
-user-id: ['myemail#email.com']
Issue solved

How to encrypt sns topic at rest to avoid cloud alters

Currently sns topics are getting generated from an ansible script, below is the snippet where I think it is getting generated.
Resources:
NotificaionTopic:
Type: "AWS::SNS::Topic"
Properties:
Subscription:
- Endpoint: xxxx#test.com
protocol: email
I need to encrypt the sns topics, can you please let me what changes I need to make so that it will start encrypting sns topics.
Any help is much appreciated.
If you provide a KmsMasterKeyId to the resource, the service will encrypt the topic.
Type: AWS::SNS::Topic
Properties:
ContentBasedDeduplication: Boolean
DisplayName: String
KmsMasterKeyId: String
Subscription:
- Subscription
Tags:
- Tag
TopicName: String
See https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-sns-topic.html

Can't create composite roles in Keycloak using Admin REST Api

I'm attempting to manage roles and composites programmatically in my Keycloak 6.0.1 system using the Admin REST API. According to the documentation, this is what I want to be using:
https://www.keycloak.org/docs-api/6.0/rest-api/index.html#_roles_resource
Right off the bat, my base URL for Keycloak's API seems to be:
https://example.com/auth/admin
instead of /auth, as the docs seem to suggest. If I use the base URL specified in the docs I get a 404. I discovered this alternate URL structure by inspecting what the Kubernetes admin page was doing when I manage the installation through my browser.
In any case, I am now successfully creating roles using the POST /{realm}/clients/{id}/roles endpoint. Problems begin when I try to add a composite using POST /{realm}/clients/{id}/roles/{role-name}/composites with a POST like this:
/auth/admin/realms/REDACTED/clients/546052d9-6ba1-483e-93a5-a5fda51505b8/roles/%5ECouponAttemptsLog%25Unowned%25Write/composites
authorization: Bearer REDACTED
Content-Type: application/json
Accept: */*
Content-Length: 217
User-Agent: node-fetch/1.0 (+https://github.com/bitinn/node-fetch)
Accept-Encoding: gzip,deflate
Connection: close
Host: REDACTED
{"roles":[{"name":"^CouponAttemptsLog/id%Unowned%Write"},{"name":"^CouponAttemptsLog/code%Unowned%Write"},{"name":"^CouponAttemptsLog/eventId%Unowned%Write"},{"name":"^CouponAttemptsLog/attemptedDate%Unowned%Write"}]}
The error message logged by Keycloak is:
14:18:02,617 ERROR [org.keycloak.services.error.KeycloakErrorHandler] (default task-4884) Uncaught server error: com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `java.util.ArrayList` out of START_OBJECT token
...and Keycloak returns a 500 response with no text.
As far as I can tell, this matches the expected request shape specified in the Keycloak 6 API documentation, and I'm at a loss for what could be causing this deserialization failure. Just for yuks, I tried sending in a naked JSON array as the body, with no improvement.
What am I doing wrong? I understand that the error from Keycloak means it's trying to convert something to an ArrayList which can't be, but I'm at a loss to figure out what and why.
It wants an array of role objects. Try this:
[
{
"name": "^CouponAttemptsLog/id%Unowned%Write"
},
{
"name": "^CouponAttemptsLog/code%Unowned%Write"
},
{
"name": "^CouponAttemptsLog/eventId%Unowned%Write"
},
{
"name": "^CouponAttemptsLog/attemptedDate%Unowned%Write"
}
]
Glancing at the code, I think you'll need to include a role id in addition the name...even if the doc says all fields within RoleRepresentation are optional.
I don't know if you solved your problem but in my case I need to use both id and name while assigning roles to composite role. And yes "partial" roles need to be created before assignment to composite role.
[
{
"id": UUID of created role
"name": "^CouponAttemptsLog/id%Unowned%Write"
}
]
Flow in my looks like this:
In a loop create partial role(s) - Keycloak api return location of new role in headers so you need to call GET to obtain role's json
Push {"id": UUID} to array - or even better {"id": UUID, "name": name } or whole role's representation (to call composites id is enough but in case of service roles you need both
Create composite role
Call composites endpoint