Chef use node_name variable in JSON role - json

Is there a way to use NODE_NAME value in a role ?
In fact, I'm writing a base role that is setting nodes hostnames and I wish to use NODE_NAME as "short_hostname".
{
"name": "Chef-RHEL",
"description": "Chef-RHEL role",
"json_class": "Chef::Role",
"default_attributes": {
"set_fqdn": "*.example.com",
"system": {
"timezone": "Europe/Paris",
"short_hostname": "{NODE_NAME}",
"domain_name": "example.com"
}
},
"override_attributes": {
},
"chef_type": "role",
"run_list": [
"recipe[system::default]"
],
"env_run_lists": {
}
}
NODE_NAME is correctly configured in /etc/chef/client.rb.
Thanks a lot !!! :)

This is not possible directly, roles are static JSON data only. You can use some kind of string replacement in the recipe code but that requires changes in the cookbook consuming the attribute first.

Related

FIWARE, NGSI-LD - Understand the #context

I am creating a data model for a particular application and I did not start from any base model; since I did not start from any base model, the context below is sufficient, correct?
"#context": [
"https://schema.lab.fiware.org/ld/context",
"https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context-v1.3.jsonld"
]
My data model is not complicated, with just these properties and entity being more "complex":
"address": {
"type": "Property",
"value": {
"streetAddress": "",
"postalCode": "",
"addressLocality": "",
"addressCountry": ""
}
},
"location": {
"type": "Point",
"coordinates": [
,
]
},
{
"id": "urn:ngsi-ld:MeasurementSensor:",
"type": "MeasurementSensor",
"measurementVariable": {
"type": "Property",
"value": "Temperature"
},
"measurementValue": {
"type": "Property",
"value": 32.0,
"unitCode": "ÂșC",
"observedAt": "2022-05-10T11:09:00.000Z"
},
"refX": {
"type": "Relationship",
"object": "urn:ngsi-ld:"
},
"#context": [
"https://schema.lab.fiware.org/ld/context",
"https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context-v1.3.jsonld"
]
}
If you are using your own custom vocabulary you should declare your types and properties in your own LD #context. For instance,
{
"#context": [
{
"MeasurementSensor": "https://example.org/my-types/MesaurementSensor"
},
"https://schema.lab.fiware.org/ld/context",
"https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context-v1.3.jsonld"
]
}
it also seems you are not using URNs properly, you should check. unitCode seems to be broken as well, as it must follow the UN/CEFACT unit codes.
Nonetheless, I would not recommend to define your own vocabulary for sensors, given there are existing Vocabularies such as SAREF or W3C SOSA that can and should be reused.
I'm not a data model expert but I do know a thing or two about NGSI-LD and NGSI-LD brokers.
The #context you use is an array of "https://schema.lab.fiware.org/ld/context" and v1.3 of the core context.
"https://schema.lab.fiware.org/ld/context" in its turn is an array of "https://fiware.github.io/data-models/context.jsonld" and v1.1 of the core context ...
And, ""https://fiware.github.io/data-models/context.jsonld" doesn't define any of the three terms you are using, so, no need to give any context for that. The terms will be expanded using the default URL of the core context (the value of the #vocab member of the core context defines the default URL).
An NGSI-LD broker has the core context built-in, you don't need to pass it, so do yourself a favor, and get faster responses by not passing the core context to the broker. No need.
And, if you need a user context, pass it in the HTTP Header "Link" instead.
Host it somewhere (an NGSi-LD broker offers that service), so you don't force the poor broker to parse the #conterxt in each and every request.
Lastly, do follow Jose Manuels recommendations and use standard names for your attributes (and value for unitCode).

FHIR one actor in two different roles

I'm creating a procedure in a transaction bundle and add practitioners as actors to the performers collection, having different functions. As far as the practitioners references are unique, all is fine. But when I'm trying to add a practitioners twice, with a different functions, an exception is thrown:
Can not process entity with ID[urn:uuid:7165d406-da59-4436-aa93-372ca882c4e5], this is not a valid FHIR ID
I found this message in HAPI FHIR unit tests, but in my case, the uuid seems to be fine. But maybe only one uuid is replaced with the id of the created practitioner.
I'm also not sure, whether this is the correct way for what I want to achieve.
I also tried to add the practioner only once and then add the second role to function.coding. But the resulting entry looks for me kinda strange:
performer": [
{
"function": {
"coding": [
{
"system": "http://somewhere/performer-role",
"code": "88888888"
},
{
"system": "http://somewhere/performer-role",
"code": "99999999",
"display": "Role-2"
}
],
"text": "Role-1"
},
"actor": {
"reference": "Practitioner/2925"
}
},
I'm fairly new to Fhir. Does anybody knows what's wrong here ?
And, what's the recommended practice, to have one performer/actor in to different roles ?
Thanks in advance
P.S. I'm using HAPI FHIR 4.0
Multiple coding repetitions would be used to convey translations - so you're saying that 888888888 and 99999999 are two different codes that represent the same role. If you want to indicate that the same Practitioner had two different roles, then you need to have two different performer repetitions. E.g.
perfomer: [
{
"function": {
"coding": [ {
"system": "http://somewhere/performer-role",
"code": "88888888"
}]},
"actor": {
"reference": "Practitioner/2925"
}
}, {
"function": {
"coding": [ {
"system": "http://somewhere/performer-role",
"code": "99999999"
}]},
"actor": {
"reference": "Practitioner/2925"
}
}
]

Validate each JSON node with different JSON schema

Im trying to make a system monitor, which is highly customisable by user. This customization is achieved by using JSON file for modeling look of system monitor. The JSON could look like this.
{
"_": "WINDOW",
"name": "myWindow",
"children": [
{
"_": "CPU",
"name": "cpuMonitor",
"freq_Unit": "MHZ"
},
{
"_": "NETWORK",
"name": "network",
"unit": "Kb/s"
},
{
"_": "DISK",
"name": "disk"
}
],
"background": "red"
}
As you can see, each object coresponds to this schema.
{
"$schema": "http://json-schema.org/draft-07/schema#",
"name":"Component",
"type": "object",
"properties":{
"_": {
"type": "string"
},
"name":{
"type":"string"
},
"childern":{
"type":"array"
}
},
"required": ["_","name"]
}
But each component has also its own schema definition. I'd like to parse whole JSON and validate each node for different schema (first if its component and then to its corresponding schema).
I had look at rapidJson and other libraries, but I didnt find solution for validating nodes for different schema. Do you know any library which could do that? Or is it even possible to validate JSON in this way?
All feedback on how to solve this will be appreciated.
Edit: Corrected schema :(
There's a simple approach involved with that, use the oneOf pattern declaration to specify the layout of the array elements. Inside these nested declarations, you specify the fixed identifier (probably the content of your _ field) as a constant, so that there is only one nested schema matching each of your panel types.
Notes:
I had to specify the constant type identifier using the enum specifier because the regular constant specifier didn't work with the library I was using. This may also have been an oversight in the revision of the specification that it was based on.
A different approach is to split the the validation steps. You simply verify that the elements of the array are objects and that they have a string field _ containing one of the supported types. When iterating over the array, you then validate each field individually according to its _ field.
In addition to Ulrich's answer, here's an example of what I'd do:
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Component",
"type": "object",
"definitions": {
"base": {
"properties": {
"name": { "type": "string" },
"children": {
"type": "array",
"items": { "$ref": "#" }
}
},
"required": [ "_", "name" ]
},
"cpu": {
"properties": {
"_": { "const": "CPU" },
"freq_Unit": "MHZ"
}
},
"network": {
"properties": {
"_": { "const": "NETWORK" },
"unit": "Kb/s"
}
},
"disk": {
"properties": {
"_": { "const": "DISK" }
}
},
"window": {
"properties": {
"_": { "const": "WINDOW" },
"background": { "enum": [ "red", "orange", "yellow", ... ] }
}
}
},
"allOf": [
{ "$ref": "#/definitions/base" },
{
"oneOf": [
{ "$ref": "#/definitions/cpu" },
{ "$ref": "#/definitions/network" },
{ "$ref": "#/definitions/disk" },
{ "$ref": "#/definitions/window" }
]
}
]
}
First, we require that any instance MUST adhere to base which declares _ and name as required properties. Additionally, we declare a children array property that requires all items also match this schema (giving us a recursive behavior). This doesn't really do much except that it allows us to declare these things in one place instead of having to declare them in the other three definitions.
(Note that we don't declare _ in the properties list. This means that any value will pass for this portion of the schema. We clean it up in the next part. If you want to ensure that future components are declared with strings, then you can add a "type": "string" requirement to that property, but I don't feel it's necessary unless others are authoring those components.)
Second, we declare each of our specific types as separate definitions, using the const keyword to isolate the one we want. This construct is analogous to a switch (or case) statement. If the instance doesn't match one of these explicit options, it fails. If it's missing one of the required base properties, it fails.
This will get you where you want to be.
To take it further, there are two more things you can do:
Add required to the other definitions to say that the specific properties are also required (e.g. freq_Unit for the cpu definition).
Declare each of the definitions in separate files. This would allow you to add a new definition by simply adding a new file and referencing it in the main schema. In my opinion, it's a bit cleaner. Some people prefer to have it all in one file, though.

How to configure multiple Consul ACL roles inside configuration file (without HTTP API)?

In the Consul ACL Internals documentation, sample configuration is provided to set some default ACL rules in both HashiCorp Configuration Language and JSON. It looks like this:
{
"key": {
"": {
"policy": "read"
},
"foo/": {
"policy": "write"
},
"foo/private": {
"policy": "deny"
}
},
"service": {
"": {
"policy": "write"
},
"secure-": {
"policy": "read"
}
},
"event": {
"": {
"policy": "write"
},
"destroy-": {
"policy": "deny"
}
},
"query": {
"": {
"policy": "read"
}
},
"keyring": "read",
"operator": "read"
}
The documentation only explains how to set up the default role.
Using the HTTP API, you can create role tokens with rules by passing JSON similar to this to the create endpoint:
{
"Name": "my-app-token",
"Type": "client",
"Rules": ""
}
But I want to be able to set this up in my static configuration files to have multiple roles with their associated policies.
How can I do this? Do I just add Name, Type, Roles and a UUID? If so, where/how do I do so?
I have figured out through the Consul Google Groups page that, according to a user, ACLs cannot currently be defined as static config files and must be configured via the HTTP API:
Currently the ACLs cannot be directly inserted into
a configuration file that Consul will read. The API is the primary way of interaction with ACLs.
(As of 10 October 2015)
https://groups.google.com/d/msg/consul-tool/fGuFTq0fvcU/f6-mwh4aCQAJ

Dealing with tree-like data structures in JSON API

Let's say we have several resources, that can exist by themselves or can be organized in a tree-like hierarchy. I called them roots, branches and leafs just for convenience. Now I want to retrieve leaf's data:
GET /leaf/1
Accept: application/vnd.api+json
which must return me something like this according to JSON API spec:
{
"data": [{
"type": "leaf",
"id": "1",
"title": "Leaf 1",
"links": {
"self": "http://example.com/leaf/1",
"branch": {
"self": "http://example.com/leaf/1/links/branch",
"related": "http://example.com/leaf/1/branch",
"linkage": { "type": "branch", "id": "5" }
},
"root": {
"self": "http://example.com/leaf/1/links/root",
"related": "http://example.com/leaf/1/root",
"linkage": { "type": "root", "id": "7" }
}
}
}],
"included": [{
"type": "branch",
"id": "5",
"title": "Branch 5",
"links": {
"self": "http://example.com/branch/5"
}
}, {
"type": "root",
"id": "7",
"title": "Root 7",
"links": {
"self": "http://example.com/root/7"
}
}]
}
From the response data I can't say that the data is hierarchical and it seems appropriate to change leaf's root:
PATCH /leaf/1
Content-Type: application/vnd.api+json
{
"data": {
"type": "leaf",
"id": 1,
"links": {
"root": {
"linkage": { "type": "root", "id": "3"}
}
}
}
}
Which is of course not possible because this leaf is connected to the branch and only then to the root, and changing the root in the schema below requires to have an id of this root's branch. Questions are:
How (if it's possible) to represent a hierarchy in the resource
representation to make it clear to an API user that the changing
relationships may require additional data?
The problem with your example is that you are viewing your data as leafs and branches, not separate objects.
REST is about managing entities. Try to look at REST URL as a name of the entity. Not some fancy tree pointer.
So, in your case PATCHing leafs is not possible like that. To change an entity you must use the same path you used to create it.
I know this answer is late, but I'm just leaving it here for others in the future.
I think the way to go is to replace the "branch" and "root" relationships with a single "parent" relationship that points to the parent node (which is of course on a branch under some root). Then, the parent relationship can be patched to any other node, without an inconsistency being introduced (since that was the problem before with someone patching root but not branch).
Then, if you still want to expose the root node, not just the direct parent, you could put this information in meta somewhere, you could add back a "root" relationship but not make it writeable (I.e. PATCH attempts would return 400/403), etc.