A way to pass data to instance from external file - cloudify

I'd like to pass configuration file to an instance through metadata. Currently for testing purposes I'm just concatenating text inside the blueprint, like this:
RE_vm:
type: cloudify.openstack.nodes.Server
properties:
resource_id: { concat: ['router_cp_', { get_input: client_name }] }
server:
image: { get_input: re_image }
flavor: { get_input: re_flavor }
key_name: ''
install_agent: false
openstack_config: *openstack_config
interfaces:
cloudify.interfaces.lifecycle:
create:
inputs:
args:
meta:
hostname: { concat: ['vMX-RE-', { get_input: client_name }] }
(...)
files:
"/var/db/configfile": { concat: ["groups {\n
re0 {\n
system {\n
host-name %hostname%;\n
}\n
interfaces {\n
unit 0 {\n
address ", { get_attribute: [left_port, fixed_ip_address] }, "/", { get_input: left_network_mask }, ";\n
}\n
}\n
}\n
global {\n
system {\n
root-authentication {\n
encrypted-password \"", { get_secret: encrypted_password }, "\"; ## SECRET-DATA\n
}\n
}\n
}\n
}\n
"]}
relationships:
- target: mgmt_port
type: cloudify.openstack.server_connected_to_port
But for real-life use, this is not feasible. How can I point to an external file and pass it to the instance?
I haven't found any apparent way of doing that in the documentation.
And preferably I'd like to dynamically fill some variables, based on inputs or some rules (like in Ansible templates).
How can I do that with Cloudify?

If I understand correctly what you are asking for, you can either use SSH connection to the VM (using fabric plugin) and upload the file or it's content to the VM; Or you could use the cloudify-utilities-plugin and use the configuration plugin for this.
For dynamically filling the inputs, you can change the inputs value when creating the deployment, inputs could be in a file (with file changed per deployment), or added to the cfy deployment create as variables, in cmd line or UI.

Related

Api gateway get item dynamodb configuration

Hi i need get an item from dynamodb through api gateway and i configure the resources like this:
i configure the integration method like the next picture:
and the mapping template is like this:
but when i test apigateway launch this error
Execution failed due to configuration error:
No match for output mapping and no default output mapping configured.
Endpoint Response Status Code: 200
Gateway response type: API_CONFIGURATION_ERROR with status code: 500
I followed these two tutorials and performed get on my dynamoDB table.
My table has primary key name "pk".
Tutorials: Video & Blog
If i write my dynamo request body like yours it does not fetch any record
{
"TableName": "apiG",
"Key": {
"pk": {
"S": "key1"
}
}
}
But if I form my request like
{
"TableName": "apiG",
"PrimaryKey": "pk",
"KeyConditionExpression": "pk = :v1",
"ExpressionAttributeValues": {
":v1": {
"S": "key1"
}
}
}
I get the desired response from dynamoDB.
Your error looks like you have some mix up in your integration response and method response. In the simplest form, keep your method response as default i.e. "HTTP Status: 200 Models: application/json => Empty" and leave your integration response as API Gateway console creates it for you.
This will make sure your DynamoDB output is sent without modification to your browser/output.
I transformed my dynamo output using following mapping template in integration response.
#set($inputRoot = $input.path('$'))
{
"content": [
#foreach($elem in $inputRoot.Items) {
"key": "$elem.pk.S",
"value": "$elem.pv.S"
}#if($foreach.hasNext),#end
#end
]
}
and it produced following output.
{
"content": [
{
"key": "key1",
"value": "val1"
}
]
}
P.S. i had a dynamo table named 'apiG' with primaryKey 'pk' and following the exported swagger from my experiment. Hope it helps.
openapi: "3.0.1"
info:
title: "dynamoProxy"
version: "2020-05-01T06:45:38Z"
servers:
- url: "https://aaaaaaaaaa.execute-api.us-east-2.amazonaws.com/{basePath}"
variables:
basePath:
default: "/test"
paths:
/db:
get:
responses:
200:
description: "200 response"
content:
application/json:
schema:
$ref: "#/components/schemas/Empty"
x-amazon-apigateway-integration:
credentials: "arn:aws:iam::111111111111:role/apiGddbRole"
uri: "arn:aws:apigateway:us-east-2:dynamodb:action/Query"
responses:
default:
statusCode: "200"
responseTemplates:
application/json: "#set($inputRoot = $input.path('$'))\n{\n \"content\"\
: [\n #foreach($elem in $inputRoot.Items) {\n \"\
key\": \"$elem.pk.S\",\n \"value\": \"$elem.pv.S\"\n \
\ }#if($foreach.hasNext),#end\n\t#end\n ]\n}"
passthroughBehavior: "when_no_templates"
httpMethod: "POST"
requestTemplates:
application/json: "{\n \"TableName\": \"apiG\",\n \"PrimaryKey\":\
\ \"pk\",\n \"KeyConditionExpression\": \"pk = :v1\",\n \"ExpressionAttributeValues\"\
: {\n \":v1\": {\n \"S\": \"key1\"\n }\n }\n\
}"
type: "aws"
components:
schemas:
Empty:
title: "Empty Schema"
type: "object"
Cheers!

How to describe request body properly using OpenAPI and API Platform?

I am struggling getting the right definition for the request body used from within Symfony Api Platform:
From the image above, what my endpoint is expecting is a JSON containing required values. I am defining required values to be in the path but that is NOT true and they don't belong even to: query, header or cookies.
I have tried two definitions (and I've removed some lines that aren't relevant for the resolution):
// the definition result is on the first image on this post
resources:
App\Entity\Cases:
collectionOperations:
case_assign:
swagger_context:
parameters:
- name: assign_type
in: path
description: 'The assignee type: worker or reviewer'
required: true
type: string
// ....
- in: body
name: body
description: 'Object needed to perform a case assignment'
required: true
example: {
"assign_type": "worker",
"assigned_by": 1,
"assigned_to": 1,
"cases": {
"0": 109855,
"1": 109849,
"2": 109845
}
}
And the second definition looks like:
resources:
App\Entity\Cases:
collectionOperations:
case_assign:
swagger_context:
summary: 'Assign a worker or a reviewer to a case'
parameters:
- name: body
in: body
required: true
schema:
type: array
items:
assign_type:
name: assign_type
description: 'The assignee type: worker or reviewer'
required: true
type: string
And here is the result:
None of them seem to be doing what I need or expect, what I am doing wrong? Can I get some help?
I have also read several pages/post without found a good example or the right way to do it (see the following list):
https://github.com/api-platform/api-platform/issues/1019
https://api-platform.com/docs/core/swagger/
https://idratherbewriting.com/learnapidoc/pubapis_swagger_intro.html
https://swagger.io/docs/specification/describing-parameters/
https://swagger.io/docs/specification/describing-request-body/
How to describe this POST JSON request body in OpenAPI (Swagger)?
You can use a SwaggerDecorator as described in the docs to override the generated swagger.json and change pretty much anything you like. You will need to edit the definitions for v2
"paths": {
"/todos": {
"post": {
"parameters": [
{
"name": "todo",
"in": "body",
"description": "The new Todo resource",
"schema": {
"$ref": "#/definitions/Todo"
}
}
]
}}}
"definitions": {
"Todo": {
"type": "object",
"description": "",
"properties": {
"text": {
"required": true,
"description": "This text will be added to the schema as a description",
"type": "string"
},...
or the components.schemas in Openapi v3:
"components": {
"schemas": {
"Todo": {
"type": "object",
"description": "",
"properties": {
"text": {
"required": true,
"minLength": 4,
"example": "some example text",
"description": "This text will be added to the schema as a description",
"type": "string"
},...
Your other option is to use the "swagger_context" ("openapi_context" for openapi v3) of the #ApiResource or #ApiProperty Annotations. Valid options should be in the swagger docs.
/**
* This text will be added to the schema as a description
* #ApiProperty(
* swaggerContext={"required"=true},
* openapiContext={"required"=true, "minLength"=4, "example"="some example text"})
* #ORM\Column(type="string", length=255)
*/
private $text;
Would result in:
example doc
Edit:
I just noticed that there is an error in your yaml configuration. You are trying to setup the documentation for an array. I assume you want to actually send an object
parameters:
- name: body
in: body
required: true
schema:
type: object
required: #only for swagger v2
- assign_type
properties:
assign_type:
description: 'The assignee type: worker or reviewer'
required: true #only for openapi v3
type: string
assigned_by:
...
You can check the correct syntax for Data Types here.

Smart Home device implementing Alexa.Speaker Interface not responding to volume change request

My Alexa Smart Home Skill for Entertainment Devices implements a few capabilities of API version 3, including the Alexa.Speaker Interface.
As far as I understand from the documentation, it should respond to voice commands such as “Alexa, set the volume of device to 5”, however Alexa always responds with "Sorry, I can't control the volume on your device".
The discovery response of the device looks like this
{
endpointId: 'music1',
friendlyName: 'pillow',
description: 'Music on Kodi',
manufacturerName: 'Cubox-i',
displayCategories: [],
capabilities: [
{
type: 'AlexaInterface',
interface: 'Alexa.PowerController',
version: '1.0',
properties: {
supported: [
{
name: 'powerState',
},
],
},
},
{
type: 'AlexaInterface',
interface: 'Alexa.PlaybackController',
version: '1.0',
properties: {},
},
{
type: 'AlexaInterface',
interface: 'Alexa.Speaker',
version: '1.0',
properties: {
supported: [
{
name: 'volume',
},
{
name: 'muted',
},
],
},
},
],
}
The discovery seems to work fine, as the PowerController interface is being responded to fine (e.g. "Alexa, turn on pillow").
I can see discovery, PowerController and PlaybackController requests and responses in the AWS Lambda logs.
Any voice commands to Speaker (whether trying to set the volume to 20, increasing it by 5, or asking to mute or unmute pillow) do not produce any requests to my Lambda and result in the response mentioned above – or in the case of muting in "Pillow doesn't support that".
Instead of
properties: {
supported: [
{
name: 'volume',
},
{
name: 'muted',
},
],
},
this JSON ,use this:
'properties.supported':[{
name: 'volume',
},
{
name: 'muted',
}]
This is a bug they are trying to solve,but till then,this will work,please let me know if this particular solution works for you.
To addition to 'properties.supported' the version should be 1 (not 3). The Speaker interface discovery response should look like:
{
"type": "AlexaInterface",
"interface": "Alexa.Speaker",
"version": "1.0",
"properties.supported":[
{
"name": "muted",
},
{
"name": "volume"
}]
}

Google Cloud Endpoints - Auth0 - "id_token verification failed: Invalid token signature"

I am trying to setup Auth0 with Google Cloud Endpoints.
I followed instructions from
https://cloud.google.com/endpoints/docs/frameworks/python/quickstart-frameworks-python
https://cloud.google.com/endpoints/docs/openapi-configuration
https://cloud.google.com/endpoints/docs/authenticating-users
I want to call "http://10.50.10.31:8080/_ah/api/echo/v1/test/" from my iOS app with an Auth0 authenticated user I already created from the Auth0 iOS SDK.
let url = URL(string: "http://10.50.10.31:8080/_ah/api/echo/v1/test/")!
var request = URLRequest(url: url)
request.addValue("Bearer \(session.token.idToken)", forHTTPHeaderField: "Authorization")
let task = URLSession.shared.dataTask(with: request) { data, response, error in
print(data)
print(response)
}
task.resume()
The Swift code works fine. The session.idToken comes from the Auth0 iOS framework.
The file app.yaml is
runtime: python27
api_version: 1
threadsafe: true
env_variables:
# The following values are to be replaced by information from the output of
# 'gcloud service-management deploy swagger.json' command.
ENDPOINTS_SERVICE_NAME: echo-api.endpoints.duskmotion-2016.cloud.goog
ENDPOINTS_SERVICE_VERSION: 2017-02-16r0
builtins:
- appstats: on
- admin_redirect: on
- deferred: on
- remote_api: on
libraries:
- name: jinja2
version: "2.6"
- name: markupsafe
version: "0.15"
- name: pycrypto
version: "2.6.1"
- name: enum
version: "0.9.23"
- name: protorpc
version: "1.0"
- name: pytz
version: "2016.4"
- name: six
version: "1.9.0"
- name: ssl
version: "2.7.11"
- name: werkzeug
version: "0.11.10"
inbound_services:
- warmup
handlers:
- url: /favicon.ico
static_files: application/static/img/favicon.ico
upload: application/static/img/favicon.ico
- url: /robots.txt
static_files: application/static/robots.txt
upload: application/static/robots.txt
- url: /gae_mini_profiler/static
static_dir: lib/gae_mini_profiler/static
- url: /gae_mini_profiler/.*
script: lib.gae_mini_profiler.main.application
- url: /static
static_dir: application/static
- url: /admin/logout
script: run.application.app
secure: always
login: required
- url: /admin/.*
script: run.application.app
secure: always
login: admin
auth_fail_action: redirect
- url: /_ah/warmup
script: run.application.app
secure: always
- url: /_ah/.*
script: run.application.urls.api
- url: .*
script: run.application.app
secure: always
skip_files:
- ^(.*/)?#.*#$
- ^(.*/)?.*~$
- ^(.*/)?.*\.py[co]$
- ^(.*/)?.*/RCS/.*$
- ^(.*/)?.*\(dev\).tmpl
- ^(.*/)?\..*$
- ^(.*/)?setuptools/script \(dev\).tmpl$
The file main.py is
import endpoints
from protorpc import message_types
from protorpc import messages
from protorpc import remote
auth0_issuer = endpoints.Issuer(
issuer='https://duskmotion.auth0.com/',
jwks_uri='https://duskmotion.auth0.com/.well-known/jwks.json')
class EchoRequest(messages.Message):
content = messages.StringField(1)
class EchoResponse(messages.Message):
"""A proto Message that contains a simple string field."""
content = messages.StringField(1)
ECHO_RESOURCE = endpoints.ResourceContainer(
EchoRequest,
n=messages.IntegerField(2, default=1))
#endpoints.api(name='echo', version='v1', issuers={"auth0-jwk" : auth0_issuer})
class EchoApi(remote.Service):
#endpoints.method(
# This method takes a ResourceContainer defined above.
message_types.VoidMessage,
# This method returns an Echo message.
EchoResponse,
path='test',
http_method='GET',
name='echo_test_get')
def echo_test_get(self, request):
# auth = request.headers.get('Authorization', None)
import logging
logging.info(request)
user = endpoints.get_current_user()
content = "Nothing"
if user:
content = "It is working"
import logging
logging.info(content)
if not user:
raise endpoints.UnauthorizedException
return EchoResponse(content=content)
api = endpoints.api_server([EchoApi])
After being generating API file, I manually added the "Security" "x-security" and "securityDefinitions".
The file echov1openapi.json looks like
{
"basePath": "/_ah/api",
"consumes": [
"application/json"
],
"definitions": {
"ApplicationUrlsEchoResponse": {
"properties": {
"content": {
"type": "string"
}
},
"type": "object"
}
},
"host": "echo-api.endpoints.duskmotion-2016.cloud.goog",
"info": {
"title": "echo",
"version": "v1"
},
"paths": {
"/echo/v1/test": {
"get": {
"operationId": "EchoApi_echoTestGet",
"parameters": [],
"responses": {
"200": {
"description": "A successful response",
"schema": {
"$ref": "#/definitions/ApplicationUrlsEchoResponse"
}
}
},
"security": [
{
"auth0_jwk": []
}
]
}
}
},
"produces": [
"application/json"
],
"schemes": [
"http"
],
"x-security": [{
"auth0_jwk": {
"audiences": [
"xxxxxxxxxxxxxxxxxx"
]
}
}],
"securityDefinitions": {
"auth0_jwk": {
"authorizationUrl": "https://duskmotion.auth0.com/authorize",
"flow": "implicit",
"type": "oauth2",
"x-issuer": "https://duskmotion.auth0.com/",
"x-jwks_uri": "https://duskmotion.auth0.com/.well-known/jwks.json"
}
},
"swagger": "2.0"
}
When I run locally on Google App Engine development server, I get
DEBUG 2017-02-16 23:55:25,551 users_id_token.py:198] Checking for id_token.
DEBUG 2017-02-16 23:55:25,551 users_id_token.py:485] Loading certs from https://www.googleapis.com/service_accounts/v1/metadata/raw/federated-signon#system.gserviceaccount.com
DEBUG 2017-02-16 23:55:25,568 users_id_token.py:269] id_token verification failed: Invalid token signature
DEBUG 2017-02-16 23:55:25,569 users_id_token.py:209] Checking for oauth token.
DEBUG 2017-02-16 23:55:25,569 users_id_token.py:340] Fetching token info from https://www.googleapis.com/oauth2/v1/tokeninfo
ERROR 2017-02-16 23:55:25,840 users_id_token.py:349] Token info endpoint returned status 400: Invalid Value
The debug lines 2 and 5 are from myself.
Why do the *.googleapis.com endpoints are getting called instead of my *.auth0.com?
What am I missing in my settings an in the .py file to make it work?
This is a a known issue with Endpoints Frameworks on the development server, and is reported on the project issue tracker: 3rd-party auth does not work with dev-server #55.
See also the related Google Groups thread for an ongoing discussion.

Running Dalekjs Tests on Saucelabs with Grunt

what i want:
run dalekjs-tests on saucelabs with grunt
what i did:
installed grunt-dalek, dalek-driver-sauce
created grunt config:
dalek: {
options: {
driver: ['sauce'],
browser: ['chrome'],
advanced: {
"driver.sauce": {
user: "xxx",
key: "xxx"
}
}
}
}
what my problem is
Warning: Cannot read property '0' of null Use --force to continue.
finally i had some time to dig deeper into this. the error came from dalek-driver-sauce.
Function _verfiyBrowserConfig inside browser.js caused the problem.
var browser = browsers[0][browserName] || null;
in my config i was missing the browsers property.
the dalek-driver-sauce docs are kind of misleading there:
if you would like to have a more control over the browser/OS combinations that are available, you are able to configure you custom combinations
the browsers config inside advanced-config is mandatory!
a final working grunt-config looked like this:
dalek: {
options: {
driver: ['sauce'],
advanced: {
"driver.sauce": {
user: "xxx",
key: "xxx"
},
browsers: [{
chrome: {
"platform": "OS X 10.6",
"actAs": "chrome",
"version": 27
}
}]
}
},
mytest: ['test.js']
}

Resources