postman how to set an environment url variable after importing a large amount of endpoints - postman

I've just imported around 1000+ endpoints into a new collection from a swagger endpoint (awesome feature btw).
What i would like to do now is for this collection add an env variable into the url as its the same collection from Dev to Stage to Prod.
A simple regex or string match substitution would be great but I cant find anyway to do this. Is it possible?

In the exported collection JSON we can see objects of the following form:
"url": {
"raw": "https://example.com/user",
"host": [
"https://example.com"
],
"path": [
"user"
]
}
The goal is to convert them to:
"url": {
"raw": "{{someUrl}}/user",
"host": [
"{{someUrl}}"
],
"path": [
"user"
]
}
Using sed we can achive this as follows:
Export collection to postman_collection.json
Use sed to replace https://example.com with {{someUrl}}:
sed -i -- 's/https:\/\/example.com/{{someUrl}}/g' postman_collection.json
Re-import the collection
Create Postman environment variable someUrl in Dev, Stage, and Prod environments.

Related

Artifactory jfrog - download artifact with regex and exclude

I'm just trying to download every artifact for example:
maven-dsd-snapshot-local/com/dsds/aem/tenants/dcihub/dcihub-wrapper/1221.1.0-SNAPSHOT
/something-wrapper-2023.1.0-20230206.113149-31.zip
but NOT
maven-dsd-snapshot-local/com/dsds/aem/platform/platform-wrapper/2023.1.0-SNAPSHOT/platform-wrapper-2023.1.0-20230206.113149-51.zip
That is what I'm trying to do in Jenkins using Artifactory plugin:
Artifactory_BUILD_PATH = """{
"files": [
{
"pattern": "${repo}/(?!.*platform-wrapper).*-wrapper/.*.zip",
"target": "/tmp/artifacts/",
"flat": "true",
"build": "${buildName}/LATEST"
}
]
}"""
However when I do that I get:
java.lang.ArrayIndexOutOfBoundsException
With negative regex this works and match correctly all the wrapper paths:
Artifactory_BUILD_PATH = """{
"files": [
{
"pattern": "${repo}/*-wrapper/*.zip",
"target": "/tmp/artifacts/",
"flat": "true",
"build": "${buildName}/LATEST"
}
]
}"""
END GOAL:
Match all paths that have wrapper in it, but exclude platform-wrapper.
The download command only supports wildcards. It does not support regular expressions.
You can make use of the exclusions field in order to exclude certain paths.
See the File Specs documentation for more details.

Jenkins, groovy map, AWS

I would like to create an environment map for AWS in Jenkins.
So I have multiple account id with multiple repository and the repositories have to use dedicated account ids.
For example:
if (repoName == 'test1'){
environment = [
env: [ "name": "test1_env", "id": "test1_id"],
[ "name": "test2_env", "id": "test2_id"]
]
}
else if (repoName == 'test2_env'){
environment = [
env: [ "name": "test3_env", "id": "test3_id"],
[ "name": "test4_env", "id": "test4_id"]
]
}
choices = environment.env['name'].join('\n')
pipeline {
parameters {
choice(name: 'Environment', choices: "${choices}", description: 'Choose Environment')
This part give back a list which contains env names, but I don't know how can I use these elements on a proper way.
choices = environment.env['name'].join('\n')
So the process should be:
Env chosen by repo name > user choose the env > based on the env name chose the aws account id > jenkins run the pipeline on the chosen account
Thanks for you help!

Ho to fix aws-cli cloudfront update distribution command?

I have been trying to execute below command but it resulted in an error
aws cloudfront update-distribution --id E29BDBENPXM1VE \
--Origins '{ "Items": [{
"OriginPath": "",
"CustomOriginConfig": {
"OriginSslProtocols": {
"Items": [
"TLSv1",
"TLSv1.1",
"TLSv1.2"
],
"Quantity": 3
}
}
}
]
}'
ERROR::: Unknown options: { "Items": [{
"OriginPath": "",
"CustomOriginConfig": {
"OriginSslProtocols": {
"Items": [
"TLSv1",
"TLSv1.1",
"TLSv1.2"
],
"Quantity": 3
}
}
}
]
}, --Origins
I have to remove cloudfront : OriginSslProtocols:SSLv3
aws cloudfront update-distribution --id E29BDBENPXM1VE \
--Origins '{ "Items": [{
"OriginPath": "",
"CustomOriginConfig": {
"OriginSslProtocols": {
"Items": [
"TLSv1",
"TLSv1.1",
"TLSv1.2"
],
"Quantity": 3
}
}
}
]
}'
1) How to fix above code,if not possible if there any command other than below command to disable/remove OriginSslProtocols:SSLv3
aws cloudfront update-distribution --id E29BDBENPXM1VE --distribution-config file://secure-ssl.json --if-match E35YV3CGILXQDJ
You are using the right command and it should be possible to do what you want.
However, it is slightly more complicated.
The corresponding reference page for the cli command aws cloudfront update-distribution says:
When you update a distribution, there are more required fields than when you create a distribution.
That is why you must follow the steps which are given in the cli reference [1]:
Submit a GetDistributionConfig request to get the current configuration and an Etag header for the distribution.
Update the XML document that was returned in the response to your GetDistributionConfig request to include your changes.
Submit an UpdateDistribution request to update the configuration for your distribution:
In the request body, include the XML document that you updated in Step 2. The request body must include an XML document with a DistributionConfig element.
Set the value of the HTTP If-Match header to the value of the ETag header that CloudFront returned when you submitted the GetDistributionConfig request in Step 1.
Review the response to the UpdateDistribution request to confirm that the configuration was successfully updated.
Optional: Submit a GetDistribution request to confirm that your changes have propagated. When propagation is complete, the value of Status is Deployed .
Fore info about the correct xml format is given in the CloudFront API Reference [2].
References
[1] https://docs.aws.amazon.com/cli/latest/reference/cloudfront/update-distribution.html
[2] https://docs.aws.amazon.com/cloudfront/latest/APIReference/API_UpdateDistribution.html

How to change AWS environment variables with ShellCommandActivity

I want to dynamically increment my environment variables (dates) for my AWS datapipeline and was wondering if someone has achieved this through ShellCommandActivity by changing the config.json file?
{
"values": ..{}
}
Not sure what you are trying to achieve. You can use nested expressions in your pipeline definition anywhere;
#{format(#scheduledStartTime, 'YYYY-MM-dd')}
E.g. as parameters you can use in your "command":
"parameters": [
{
"id": "myDate",
"type" : "DateTime"
}
],
"values": {
"myDate": "#{minusDays(myDateTime,1)}"
}
Or get a date as part of the shell command that is being executed:
date -v -1d
More info:
http://docs.aws.amazon.com/datapipeline/latest/DeveloperGuide/dp-pipeline-expressions.html

System.getenv() returning VCAP_SERVICES : "******"

System.getenv() is returning json with VCAP_SERVICES : "******". My cloud foundry java spring-boot app is bound to three services. If I give cf env app_name in CLI, its returning all bound services correctly. Also VCAP_APPLICATION and other fields in returned json are just fine except this one.
A Little background:
I need to get service name, label and plan for all the services bound to my app. I'm new to cloud foundry and spring-boot, so don't know how to use spring cloud connectors in my code.
The value in the VCAP_SERVICES environment variable will be a JSON string that you need to parse, and it will give you an object describing all the bound services, including data like name, label, and plan. If you Google "vcap services" or "cloud foundry environment variables" the first result is this doc, and it has a section on VCAP_SERVICES. Here's the example they provide of what this JSON object looks like (after parsing):
{
"elephantsql": [
{
"name": "elephantsql-c6c60",
"label": "elephantsql",
"tags": [
"postgres",
"postgresql",
"relational"
],
"plan": "turtle",
"credentials": {
"uri": "postgres://seilbmbd:ABcdEF#babar.elephantsql.com:5432/seilbmbd"
}
}
],
"sendgrid": [
{
"name": "mysendgrid",
"label": "sendgrid",
"tags": [
"smtp"
],
"plan": "free",
"credentials": {
"hostname": "smtp.sendgrid.net",
"username": "QvsXMbJ3rK",
"password": "HCHMOYluTv"
}
}
]
}
As you suggest wanting to try to to acces this info in your code you should consider the cloud foundry java client, good intro here and its really easy to get up and running. I've found that the api is somewhat limited but its worth looking at - http://docs.cloudfoundry.org/buildpacks/java/java-client.html