unable to puppet lookup a hiera interpolated hash - hiera

getting a string instead of array
this is my common.yaml
aa::params:
- '--params:"abc.com'
- 'abc2.com'
test::packages:
package1:
ensure:'present'
install_options: "%{lookup('aa:params')}"
this is my manifest file
$packages = lookup("test::packages",undef,undef,'')
$params= lookup("aa::params",undef,undef,'')
$packages.each | String $packagename, Hash $attributes | {
notify { " ${packagename}, ${attributes[ensure]},${attributes['install_options]},${params} hello ":
}
}
expected
"package1,present,[--params="abc.com, abc2.com"],[--params="abc.com, abc2.com"] hello"
actual
"package1,present,["--params=\"abc.com", "abc2.com\""],[--params="abc.com, abc2.com"] hello"
It looks like array is getting stringified can someone please explain why I am getting like this

Interpolating the results of a lookup into a string always results in a string. If you want the actual array instead of a strigyfied version you should use alias instead. Your common.yaml would look something like this:
aa::params:
- '--params:"abc.com'
- 'abc2.com'
test::packages:
package1:
ensure:'present'
install_options: "%{alias('aa:params')}"
Here is the related documentation.

Related

Karate Api : check if a phrase is available response object array

I've a response
{ errors: [
{
code: 123,
reason: "this is the cause for a random problem where the last part of this string is dynamically generated"
} ,
{
code: 234,
reason: "Some other error for another random reason"
}
...
...
}
Now when I validate this response
I use following
...
...
And match response.errors[*].reason contains "this is the cause"
This validation fails, because there is an equality check for complete String for every reason ,
I all I want is, to validate that inside the errors array, if there is any error object, which has a reason string type property, starting with this is the cause phrase.
I tried few wild cards but didn't work either, how to do it ?
For complex things like this, just switch to JS.
* def found = response.errors.find(x => x.reason.startsWith('this is the cause'))
* match found == { code: 123, reason: '#string' }
# you can also do
* if (found) karate.log('found')
Any questions :)

Terraform template_file get pass all received variables to a function

is there in Terraforom in template_files a way to pass through all the received variables to other place?
I mean something similar than $# in bash.
For example:
resource "template_file" "some_template" {
template = "my_template.tpl")}"
vars {
var1 = "value1"
var2 = "value2"
}
}
and then from the rendered file:
#!/bin/bash
echo "Var1: ${var1}"
echo "Var2: ${var2}"
echo "But I want it in someway similar to this:"
for v in $#; do
echo "$v";
done
According to the documentation, no.
From https://www.terraform.io/docs/providers/template/d/file.html
Variables for interpolation within the template. Note that variables
must all be primitives. Direct references to lists or maps will cause
a validation error.
Primitives in terraform are string, number and boolean.
So it means you can not pass a hash or a list to group all the variables in one.
Use join and pass all the variables as one and parse/split them within a script (with tr/IFS tricks)
join("; ", [var.myvar1, var.myvar2, var.myvar3])
and then
IN="${allvars}"
IFS=';' read -ra ADDR <<< "$IN"
for i in "${ADDR[#]}"; do
echo "$i"
done

Content in received ActiveMQBytesMessage is empty

When I receive a ActiveMQBytesMessage, the Content property has exactly the expected length, but all bytes are zero, it looks like an uninitialized buffer with just the correct length.
I also tried ReadBytes(buffer, length) on the message object, and got the same empty buffer.
I'm pretty sure that the messages arrives correctly at the broker, because I can look into the XML representation of the message via the ActiveMQ web interface, and there I can see the correct Base64 representation in <content><data>
I'm using the latest version 1.5.6.
Any ideas what I might be doing wrong?
Update
How I create the message before sending it using a publisher:
var binMessage = new ActiveMQBytesMessage();
binMessage.Content = /* ... */
This is what a message looks like on the web interface (queue browser):
<org.apache.activemq.command.ActiveMQBytesMessage>
<commandId>5</commandId>
<!-- ... -->
<content>
<data>H4sIAN[...]AA=</data>
<offset>0</offset>
<length>305</length>
</content>
<!-- ... -->
</org.apache.activemq.command.ActiveMQBytesMessage>
This is what I basically do in my MessageListener:
Console.WriteLine("Message ID: " + message.NMSMessageId);
var bytesMessage = message as IBytesMessage;
if (bytesMessage != null)
{
Console.WriteLine("Content length: " + bytesMessage.Content.Length);
Console.WriteLine("Content: " + BitConverter.ToString(bytesMessage.Content));
}
This gives me the correct content length, but the actual content is just empty (hex output is just 00-00-00 etc.).
I believe this is working as its currently designed. The Content field is read and returned to you by the first call to Content where you display the length. At this point the message is now read to the end of its data stream. Before you can call Content again and re-read the data you need to reset the message.
Something like this should work.
Console.WriteLine("Message ID: " + message.NMSMessageId);
var bytesMessage = message as IBytesMessage;
if (bytesMessage != null)
{
byte[] content = bytesMessage.Content;
Console.WriteLine("Content length: " + content.Length);
Console.WriteLine("Content: " + BitConverter.ToString(content));
}

Ruby on Rails - string to array weird formatting in email parsing

I can get the body of an email in String format like so
body = params[:plain]
And when I output it, it looks like:
Hi there.
--
John B.
Sent from my iPhone.
Now, when I try and split by newline body.split("\n") I get:
---
- ! 'Hi there.'
- ''
- ! '-- '
- John B.
- ''
- Sent from my iPhone.
I don't really understand the extra hyphens and bangs. Any thoughts?
Also if I do body[2] I get --, but body.index("--") returns me nothing.
UPDATE
In my ReceivingMails controller:
...
def create
body = params[:plain]
parsed_body = parse_body(body)
Comment.new(:content => parsed_body)
end
private
def parse_body(body)
split = body.split("\n")
sig_index = split.index("-- ")
return split[0, sig_index].join("\n")
end
In my view, comments are shown as: <%= simple_format(comment.content)%>
UPDATE 2
When I do something like, body.split("\n").to_s I get what the expected array should look like (as String): ["Hi there. ", "", "-- ", "John B.", "", "Sent from my iPhone."]
I don't think params[:plain] is actually a string - I think you should test it to find out what it actually is. For example try:
puts params[:plain].class

How to set default values for Tcl variables?

I have some Tcl scripts that are executed by defining variables in the command-line invocation:
$ tclsh84 -cmd <script>.tcl -DEF<var1>=<value1> -DEF<var2>=<value2>
Is there a way to check if var1 and var2 are NOT defined at the command line and then assign them with a set of default values?
I tried the keywords global, variable, and set, but they all give me this error when I say "if {$<var1>==""}": "can't read <var1>: no such variable"
I'm not familiar with the -def option on tclsh.
However, to check if a variable is set, instead of using 'catch', you can also use 'info exist ':
if { ![info exists blah] } {
set blah default_value
}
Alternatively you can use something like the cmdline package from tcllib. This allows you to set up defaults for binary flags and name/value arguments, and give them descriptions so that a formatted help message can be displayed. For example, if you have a program that requires an input filename, and optionally an output filename and a binary option to compress the output, you might use something like:
package require cmdline
set sUsage "Here you put a description of what your program does"
set sOptions {
{inputfile.arg "" "Input file name - this is required"}
{outputfile.arg "out.txt" "Output file name, if not given, out.txt will be used"}
{compressoutput "0" "Binary flag to indicate whether the output file will be compressed"}
}
array set options [::cmdline::getoptions argv $sOptions $sUsage]
if {$options(inputfile) == ""} {puts "[::cmdline::usage $sOptions $sUsage]";exit}
The .arg suffix indicates this is a name/value pair argument, if that is not listed, it will assume it is a binary flag.
You can catch your command to prevent error from aborting the script.
if { [ catch { set foo $<var1> } ] } {
set <var1> defaultValue
}
(Warning: I didn't check the exact syntax with a TCL interpreter, the above script is just to give the idea).