YAML to JSON Puppet - puppet

I'm a new to Puppet and looking to create a JSON file and get content from YAML. Any help is appreciated.
cred.yaml
---
user:pass
cred.json
{
"username": "user",
"password": "pass"
}

Related

Which method would be more appropriate here POST or PATCH?

Let's say I have a db collection with users and I want to ADD an object to an array inside one document.
It was like this:
{
_id: "636e8e1dd710eed71565741c",
username: "test",
password: "$2b$10$/s9.kRYSax380Xrxf3xyVO9Z6Otc/WVx5kBSLKfu43/wYP.TSnzvW",
tasks: [{name: task1, status: "finished"}]
}
And I am going to make it look like this:
{
_id: "636e8e1dd710eed71565741c",
username: "test",
password: "$2b$10$/s9.kRYSax380Xrxf3xyVO9Z6Otc/WVx5kBSLKfu43/wYP.TSnzvW",
tasks: [{name: task1, status: "finished"}, {name: task2, status: "unfinished"}]
}
So which method would be more appropriate here since I'm adding a new object to an embedded array and not updating one which already exists? Thank you.
The choice between POST and PATCH depends on the path of the URL. If the path contains the _id, I'd prefer
POST /collection/636e8e1dd710eed71565741c/tasks
Content-Type: application/json
{"name": "task2", "status": "unfinished"}
However, if the _id is part of the payload, I'd prefer
PATCH /collection
Content-Type: application/json
{"_id": "636e8e1dd710eed71565741c",
"tasks#add": [{"name": "task2", "status": "unfinished"}]}
But this payload format relies on "naming conventions":
The _id serves to identify the entry to be patched.
The suffix #add means that the tasks are added to the existing array.
"tasks#change": [{"name": "task1", "status": "archived"}] would instead update the existing task.
If the server knows that each task is identified by its name, the suffixes would not be necessary:
PATCH /collection
Content-Type: application/json
{"_id": "636e8e1dd710eed71565741c",
"tasks": [{"name": "task1", "status": "archived"},
{"name": "task2", "status": "unfinished"}]}
updates the existing task and adds a new one. Or even
PATCH /collection/636e8e1dd710eed71565741c/tasks
Content-Type: application/json
[{"name": "task1", "status": "archived"},
{"name": "task2", "status": "unfinished"}]
I hope these examples help you find a suitable pattern.

Logic App - Expression to get a particular substring from a json

I have out form one of the tasks in Logic App:
{
"headers": {
"Connection": "close",
"Content-Type": "application/json"
},
"body": {
"systemAlertId": "....",
"endTimeUtc": null,
"entities": [
{
"$id": "us_1",
"hostName": "...",
"azureID": "someID",
"type": "host"
},
{
"$id": "us_2",
"address": "fwdedwedwedwed",
"location": {
"countryCode": "",
},
"type": "ip"
},
],
}
}
I need initialize some variable named resourceID that contains value someID which is read from above example.
Value someID will always be found in the first member of Entities array, in that case I guess need to use function first
Any idea how expression of Initial variable should look?
Thanks
Considering the mentioned data you are receiving from Http trigger, I have used Parse JSON in order to get the inner values of the mentioned JSON. Here is how you can do it.
and now you can initialize the resourceID using 'Initialise variable' connector and set its value to azureID as per your requirement.
Have a look at the Parse JSON action.
To reference or access properties in JavaScript Object Notation (JSON) content, you can create user-friendly fields or tokens for those properties by using the Parse JSON action. That way, you can select those properties from the dynamic content list when you specify inputs for your logic app. For this action, you can either provide a JSON schema or generate a JSON schema from your sample JSON content or payload.
With the information in the JSON available in an object, you can more easily access it.

Terraform issue creating the resource "azurerm_synapse_linked_service" specifically with the "type_properties_json" field

I am trying to create a Synapse Workspace Linked Service using Terraform and am running into a constant snag with the "type_properties_json" field that is (required).
When I try to establish a Linked Service to an SFTP resource type, I can do so through the portal no problem, however trying to do so with Terraform is constantly providing me with errors. I am using the JSON code format referenced here, but the "type_properties_json" field keeps erroring out as I believe it is expecting a "String" and I am instead providing a Map[string] type.
The error I keep receiving during the terraform apply is json: cannot unmarshal string into Go value of type map[string]interface {}
My specific code looks like the following:
resource "azurerm_synapse_linked_service" "linked-service" {
synapse_workspace_id = azurerm_synapse_workspace.synapse.id
name = "name"
type = "Sftp"
type_properties_json = <<JSON
{
"host": "x.x.com",
"port": 22,
"skipHostKeyValidation": false,
"hostKeyFingerprint": "ssh-rsa 2048 xx:00:00:00:xx:00:x0:0x:0x:0x:0x:00:00:x0:x0:00",
"authenticationType": "Basic",
"userName": "whatever_name,
"password": "randompassw"
}
JSON
depends_on = [azurerm_synapse_firewall_rule.allow]
}
Running out of hope here and am now looking to crowd source to see if anyone else has ever ran into this problem!!
This is because of the password parameter you are passing. As per this Microsoft documentation, it should be passed as below:
"password": {
"type": "SecureString",
"value": "<value>"
}
Instead of
"password": <value>
I tested the same in my environment using your code where I faced the exact same issue:
So, I used the below code, applying the solution mentioned above:
resource "azurerm_synapse_linked_service" "example" {
name = "SftpLinkedService"
synapse_workspace_id = azurerm_synapse_workspace.example.id
type = "Sftp"
type_properties_json = <<TYPE
{
"host": "xxx.xx.x.x",
"port": 22,
"skipHostKeyValidation": false,
"hostKeyFingerprint": "<SSH-publicKey>",
"authenticationType": "Basic",
"userName": "adminuser",
"password": {
"type": "SecureString",
"value": "<Value>"
}
}
TYPE
depends_on = [
azurerm_synapse_firewall_rule.example,
azurerm_synapse_firewall_rule.example1
]
}
Output:

How to read nested API links within the JSON file

If my JSON file is coming out like this, what needs to happen is go to the API link within the u_parent and populate the values from that API link with sysparm_display_value=true into the df. Possible? I need to do this because this API link is giving me the same name and parent and only the link in u_parent will give me the correct parent details.
{
"u_name": "******",
"u_parent": {
"display_value": "*****",
"link": "https://*****.******.com/api/now/table/u_region_hierarchies/ed7f652f1b29341051380e93cc4bcbd7"
},
"sys_id": "159967df1b75601070bfdb9cbc4bcb35",
"sys_updated_by": "mlarcheveque",
"sys_created_on": "01/24/2021 17:31:26",
"sys_mod_count": "1",
"u_active": "true",
"u_region_id": "**********",
"sys_updated_on": "07/30/2021 14:13:33",
"sys_tags": "",
"sys_created_by": "admin"
},
The API link from that u_parent displays the following values and i want the display value from u_parent
{
"result": {
"u_name": "*****",
"u_parent": {
"display_value": "*****",
"link": "https://*****.*****.com/api/now/table/u_region_hierarchies/6d7f252f1b29341051380e93cc4bcbd7"
},
"sys_id": "217f652f1b29341051380e93cc4bcbd4",
"sys_updated_by": "mlarcheveque",
"u_id": "*****",
"sys_created_on": "07/30/2021 14:11:49",
"sys_mod_count": "0",
"sys_updated_on": "07/30/2021 14:11:49",
"sys_tags": "",
"sys_created_by": "mlarcheveque"
}
}
So i am thinking this would involve a do while loop that goes through each row and gets the value from the nested API link

How to assign more than one user via AWS CLI to a group?

Trying to assign multiple users to groups using json. Created a json file, and runnign the following:
aws iam add-user-to-group --cli-input-json file://c:\awscli\json\iam-add-user-to-group.json
Json content is:
{
"GroupName": "devops",
"UserName": ["devop1", "devop2"]
}
and getting an error:
Parameter validation failed:
Invalid type for parameter UserName, value: ['devop1', 'devop2'], type: <class 'list'>, valid types: <class 'str'>
With the community help, changed incorrect json, and realized - there is no way to run any bulk add/remove scripts in AWS CLI.
That's not a valid JSON. This is:
{
"GroupName": "devops",
"UserName": [
"devop1",
"devop2"
]
}

Resources