Inject Key Storage Password into Option's ValuesUrl - parameter-passing

I'm trying to request a raw file from a Gitlab repository as a values JSON file for my job option. The only way so far that I managed to do it is by writing my secret token as plain text in the request URL:
https://mycompanygitlab.com/api/v4/projects/XXXX/repository/files/path%2Fto%2Fmy%2Ffile.json/raw?ref=main&private_token=MyV3ry53cr3Tt0k3n
I've tried using option cascading; I created a Secure password Input Option called gitlab_token which points to a Key Storage Password and tried every possible notation (with or without .value, quoted or unquoted option) in the valuesUrl field of the second option, instead of the plain token, but I keep receiving this error message pointing an invalid char at the position of the dollar sign:
I've redacted sensitive info and edited the error print accordingly

I reproduced your issue. It works using a text option, you can use the value in this way: ${option.mytoken.value}.
- defaultTab: nodes
description: ''
executionEnabled: true
id: e4f114d5-b3af-44a5-936f-81d984797481
loglevel: INFO
name: ResultData
nodeFilterEditable: false
options:
- name: mytoken
value: deda66698444
- name: apiendpoint
valuesUrl: https://mocki.io/v1/xxxxxxxx-xxxx-xxxx-xxxx-${option.mytoken.value}
plugins:
ExecutionLifecycle: null
scheduleEnabled: true
sequence:
commands:
- exec: echo ${option.mytoken}
- exec: echo ${option.apiendpoint}
keepgoing: false
strategy: node-first
uuid: e4f114d5-b3af-44a5-936f-81d984797481
Another workaround (if you don't want to use a plain text option) could be to pass the secure option to an inline script and manage the logic from there.
Please open a new issue here.

Related

Not allow duplicate tags in yml file

I am trying to validate my sample yml using yml schema file.
a.yml data file:
test:
version1
test:
version1
s.yml schema file:
type: map
mapping:
test:
type: str
required: yes
unique: yes
In my perl code i am using YML inbuilt module and validate my data file with schema file as followed:
eval { validate(YAML::LoadFile(s.yml), YAML::LoadFile(a.yml)) };
I was expecting to fail the validation because of having duplicate tags 'type:'. Is there a way to not allow duplicate tags in yml file while validating against schema schema.
I notice that loading is failing with warning:
Name "YAML::SortKeys" used only once: possible typo at test.plline 21.
YAML Warning: Duplicate map key found. Ignoring.
Code: YAML_LOAD_WARN_DUPLICATE_KEY
Line: 1
Document: 1
Currently i am using 'use warnings FATAL => qw(all);', Still my script is passing. Not sure why it still pass with warnings.
Can we make it Error?
YAML::PP forbids duplicate keys by default (*).
use YAML::PP;
my $yaml = <<"EOM";
foo: a
foo: b
EOM
YAML::PP::Load($yaml);
__END__
Duplicate key 'foo' at /.../YAML/PP/Parser.pm line 61.
You are using YAML.pm, which is not recommened anymore, as it was written for YAML 1.0 and also has other problems.
(*) YAML::PP forbids duplicate keys since version 0.027. Before they were ignored.

SaltStack - Unable to check if file exists on minion

I am trying to check if a particular file with some extension exists on a centos host using salt stack.
create:
cmd.run:
- name: touch /tmp/filex
{% set output = salt['cmd.run']("ls /tmp/filex") %}
output:
cmd.run:
- name: "echo {{ output }}"
Even if the file exists, I am getting the error as below:
ls: cannot access /tmp/filex: No such file or directory
I see that you already accepted an answer for this that talks about jinja being rendered first. which is true. but i wanted to add to that you don't have to use cmd.run to check the file. there is a state that is built in to salt for this.
file.exists will check for a file or directories existence in a stateful way.
One of the things about salt is you should be looking for ways to get away from cmd.run when you can.
create:
file.managed:
- name: /tmp/filex
check_file:
file.exists:
- name: /tmp/filex
- require:
- file: create
In SaltStack Jinja is evaluated before YAML. The file creation will (cmd.run) be executed after Jinja. So your Jinja variable is empty because the file isn’t created, yet.
See https://docs.saltproject.io/en/latest/topics/jinja/index.html
Jinja statements such as your set output line are evaluated when the sls file is rendered, before any of the states in it are executed. It's not seeing the file because the file hasn't been created yet.
Moving the check to the state definition should fix it:
output:
cmd.run:
- name: ls /tmp/filex
# if your underlying intent is to ensure something runs only
# once the file exists, you can enforce that here
- require:
- cmd: create

GitHub Actions - How to trim a string in a condition?

How can I trim a string in a condition in GitHub actions workflow?
In the following example, the comment can contains accidentally spaces and new lines. I want to trim the spaces in github.event.comment.body:
steps:
- name: "Check CLA signed"
if: github.event.comment.body == 'I have read the CLA Document and I hereby sign the CLA'
NOTE: Skip to the end for a better answer.
I believe GitHub Actions expressions are very limited to checking basic things in a workflow, rather than offering programming capabilities.
If you need to go the route of checking different ways of writing a message, your best option is to run a check against the string in a step:
steps:
...
- name: Check if person has accepted and signed CLA
shell: python
run: |
import sys
def check_user_accepted_and_signed(text):
"""Some complex natural language processing will go here"""
comment = '''${{ github.event.comment.body }}'''
if not check_user_accepted_and_signed(comment):
sys.exit(1) # This will abort the job
- name: Not accepted or signed
if: ${{ failure() }}
run: optionally do something if the check fails
- name: Move on if the check passed
run: ...
In the code above, you could also replace the inline Python snippet with a script call from your code base, for a cleaner code:
steps:
- uses: actions/checkout#v3
- name: Check if person has accepted and signed CLA
run: ./scripts/check-accepted-signed-cla.sh '${{ toJSON(github.event.comment.body) }}'
# Single quotes and JSON string prevents bad whitespace interpretation
Simpler is usually better
IMHO though, you'd be better off -- and safer! -- doing simple things. Here's an idea:
Set up your GitHub repository with a default pull request body containing a checkbox, for example:
Write your description.
---
- [ ] I have read the CLA and hereby sign it.
In your workflow, check for that checkbox and fail if it's not checked. Shopify/task-list-checker can be of great help here!
You can find all functions that github actions support here
I think you can use contains function for cover your case

I'm gettng a error while sending a JSON string using ansible

Here i want to send a json string to a url . please check my syntax and let me know whats the problem in my code.
ansiblejson.yml
hosts:localhost
sudo:yes
tasks
- name:send jenkins-jobs
uri
url:"i gave URL here"
method:PUT
return_content:yes
body:-"{{'Name:sai','Node:node number','EventId:123'}}"
status_code:204
body_format:json
Here is the error iam getting
The error appears to be have in "c:/ansiblejson.yml" line 4, column 8, but may be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be :
sudo:yes
tasks:
^ here
First of all, please fix the code formatting.
Don't use backspace only whitespace, because of YAML.
Ansible is telling you everything that you need to know, you forgot an semicolon after the tasks section:
hosts: localhost
sudo: yes
tasks:
- name:send jenkins-jobs
Also, from Ansible 2.2, you should use not sudo: yes, but become: yes, and then what user that you want to become; root, sudo etc...

Inno Setup parameter with quotes in [Run] section

I use [Run] section to modify the merit value of some codecs with commandmerit.exe that supports command-line.
So the syntax is:
Commandmerit.exe "{E2B7DF46-38C5-11D5-91F6-00104BDB8FF9}" "0x800000"
{E2B7DF46-38C5-11D5-91F6-00104BDB8FF9} is the CLSID of the codec and
0x800000 is the value of the new merit, but when I put this line in [Run] section :
Filename: "{app}\Commandmerit.exe"; Parameters: ""{F8FC6C1F-DE81-41A8-90FF-0316FDD439FD}" "0x10000000""; WorkingDir: "{app}"
The flowing error is displayed:
Mismatched or misplaced quotes on parameter.
If I put this line:
Filename: "{app}\Commandmerit.exe"; Parameters: """{F8FC6C1F-DE81-41A8-90FF-0316FDD439FD}" "0x10000000"""; WorkingDir: "{app}"
The flowing error is displayed :
Unknown constant ...... use two consecutive"{" if .....
If I put this line:
Filename: "{app}\Commandmerit.exe"; Parameters: """{{F8FC6C1F-DE81-41A8-90FF-0316FDD439FD}}" "0x10000000"""; WorkingDir: "{app}"
Then no error is displayed but it seems that the commandmerite.exe don't understand the parameter, so after the installer finishes the merit still unchanged.
To add quotes to a parameter, you must double up each quote, and then put quotes around the entire value.
Your second attempt was close but you forgot the middle ones.
Filename: "{app}\Commandmerit.exe"; Parameters: """{F8FC6C1F-DE81-41A8-90FF-0316FDD439FD}"" ""0x10000000"""; WorkingDir: "{app}"
I can see two different things in your problem.
First, is the { having a special meaning in inno setup, because it is the start of a constant. So, you have to escape the { by doubling it, e.g. {{. There is no need to escape the closing bracket because it is treated as the end of a constant only if it is a start for that constant.
Second, is that you're trying to pass " as part of the string, but that seems unnecessary in this case, since the purpose of the " character in the command line parameters is to allow the use of blank spaces inside a single parameter, but none of your parameters have spaces.
All that said, you must try writing your command like this:
[run]
Filename: "{app}\Commandmerit.exe"; Parameters: {{F8FC6C1F-DE81-41A8-90FF-0316FDD439FD} 0x10000000; WorkingDir: "{app}"