Unable to remove User-Agent Header in API Connect call - ibm-cloud

my APIConnect API running on Bluemix is calling another API and I want to remove the User-Agent Header. I am using apim.setvariable in a Gatewayscript. Its working for some (e.g. Origin, Referer, ...) but not for the User-Agent. The User-Agent is still there.
apim.setvariable('message.headers.X-IBM-Client-Id', 'null','clear');
apim.setvariable('message.headers.X-IBM-Client-Secret', 'null', 'clear');
apim.setvariable('message.headers.Origin', 'null', 'clear');
apim.setvariable('message.headers.Referer', 'null', 'clear');
apim.setvariable('message.headers.X-Client-IP', 'null', 'clear');
apim.setvariable('request.headers.user-agent', 'null', 'clear');
apim.setvariable('request.headers.User-Agent', 'null', 'clear');
apim.setvariable('message.headers.user-agent', 'null', 'clear');
apim.setvariable('message.headers.User-Agent', 'null', 'clear');
How can I remove the User-Agent header?
Thx

Make sure you're using a Proxy node instead of an Invoke node after your gateway script.

Related

Unable to upload attatchments over the Jira API

I've seen the question asked a few times but no real answer. The Jira::Rest module appears to be out of date since username and password is not an accepted authentication method.
I am unable to add attachments via perl. My first attempt was using REST::Client with LWP::useragent. Example below
my $client = REST::Client->new();
$client->addHeader('Authorization', 'Basic ' . $config_yaml->{auth}
$client->addHeader('Content-Type', 'application/json');
$client->addHeader('X_Atlassian_Token', 'no-check');
$client->addHeader('Content' => [ file => [ $filename ], ]);
my $file_sent = $client->POST("issue/$ticket/attachments");
my $response = $file_sent->responseContent();
For some reason the response was an empty string.
I thought maybe I was missing something so I tried with a curl request
curl --request POST --url 'https://cloudurl.atlassian.net/rest/api/3/issue/[ticket_id]/attachments' \
--header 'Accept: application/json' --header "X-Atlassian-Token: no-check" \
--header 'Authorization: Basic [api auth string]' \
-F "file=#test_file_upload.txt"
The curl request returned the expected message and the ticket had the attachment. So I tried again using just LWP::UserAgent.
my $ua = LWP::UserAgent->new;
$ua->timeout(10);
$ua->env_proxy;
$ua->default_header('Accept' => 'application/json');
$ua->default_header('X-Atlassian-Token' => 'no-check');
$ua->default_header('Authorization' => 'Basic ' . $config_yaml->{auth});
my $response = $ua->post($url, Content_Type => 'multipart/form-data',
Content => [
field => [$filename],
],
);
warn $response->is_success;
warn $response->decoded_content;
For some reason this returned 200 and an empty just like when I tried with Rest::Client. I believe the URL and parts of it are correct.
If X-Atlassian-Token is ommitted I get the error specified in the documentation and if I send no content I get an error complaining about that missing. Is there something missing from my request when I make it via LWP::UserAgent or REST::Client that causes me to get no response?
For reference this is the part of the api documentation I have been trying to work from.
https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issue-attachments/#api-rest-api-3-issue-issueidorkey-attachments-post
The parts discussed on the atlassian support area do not seem to have a solution for this either.
If you have root access on the box, I'd use tcpdump -A -s2048 host cloudurl.atlassian.net and look for any differences between the successful curl and the other messages.
https://www.perlmonks.org/bare/?node_id=464442 suggests using
print $response->headers_as_string;
or
print join "\n", $file_sent->->responseHeader($_) for $file_sent->->responseHeaders();
to see what you're getting back.

POST URL with REST API token in vbs without password

I'm launching build jobs on a local Jenkins with:
curl -X POST "http://UID:TOKEN#server:port/job/DevGate/build?delay=0sec&json=%7B%22parameter%22%3A+%7B%22name%22%3A+%22DEVGATE_PACKAGELIST%22%2C+%22value%22%3A+%2212345678%3A9%22%7D%2C+%22statusCode%22%3A+%22303%22%2C+%22redirectTo%22%3A+%22.%22%7D&Submit=Build"
which translates into
curl -X POST "http://UID:TOKEN#server:port/job/DevGate/build?delay=0sec&json={"parameter": {"name": "DEVGATE_PACKAGELIST", "value": "12345678:9"}, "statusCode": "303", "redirectTo": "."}&Submit=Build"
UID being userID. TOKEN being API Token given by Jenkins/REST API. And it works. Now, this command is launched inside of a VBScript that mainly gathers data for creation of aforementioned URL. No password needed, and I'd like to keep it that way. The problem: I'd like to avoid using curl and use just native VBScript functionality.
What I've tried so far:
Dim http: Set http = CreateObject("Microsoft.XMLHTTP")
Dim url: url = "http://server:port/job/DevGate/build"
Dim data: data = "delay=0sec&json=%7B%22parameter%22:+%7B%22name%22:+%22DEVGATE_PACKAGELIST%22,+%22value%22:+%22" + the rest of data
'string2try = Base64EncodeString("UID:TOKEN")
'string2try = Base64EncodeString("UID:PASSWORD")
With http
.Open "POST", url, False
Call .SetRequestHeader("Content-Type", "application/x-www-form-urlencoded")
Call .SetRequestHeader("oAuth", token)
.Send data
'Call .SetRequestHeader("X-Api-Key", token)
'Call .SetRequestHeader("Authorization", "Bearer " & token)
'Call .SetRequestHeader("X-Auth-Token", token or string2try)
'Call .SetRequestHeader("X-Parse-REST-API-Key", token)
End With
Every permutation of that code fails authentication. How to pass my token + uid properly in VBScript without using curl?

How to use special characters in password for mule endpoint

Im trying to access an outbound-endpoint sending login password for it, but the password have a # character, so ive tryed encode it to %23 and even so im getting an error message...
How can i can send it?
My code:
<http:outbound-endpoint host="localhost" path="path/path" port="8080" user="username" password="paswd%23" exchange-pattern="request-response" doc:name="HTTP">
</http:outbound-endpoint>
And the error is:
Invalid uri 'http://username:paswd##localhost:8080/path/path
Mule version 3.4
Need to encode. As #daviddessot mentioned. That's right.
As a extention:
Feel free to use: http://www.url-encode-decode.com/
Major chars:
! - %21
$ - %24
% - %25
# - %40
Double encode the password:
password="paswd%2523"

What is the best way to versoining in install/ upgrade scripts?

Sometimes, I use any of the following mentioned names to name the install/upgrade scripts in custom modules:
install-0.1.0.0.php
upgrade-0.1.0.0-0.1.1.0.php
upgrade-0.1.1.0-0.1.2.0.php
----------------------------
install-0.1.0.php
upgrade-0.1.0.0-0.1.1.php
upgrade-0.1.1-0.1.2.php
Is there a standard way to follow for this naming conventions for install/upgrade scripts?
Versioning follows some conventions/standards, here is the code snippet from Mage.php to give an idea how module versions can be decided. This is for Magento version 1.7.0.2
array(
'major' => '1',
'minor' => '7',
'revision' => '0',
'patch' => '2',
'stability' => '',
'number' => '',
);
As I know, there's no standard way and you can name your scripts and versions as you need( it uses php version_compare anyway).

Symfony 1.4 I get the wrong values in app.yml

Obviously it is not that simple. Let's start from the beginning: I'm working on a shared project and yesterday I've been asked to add the plugin mgI18n. I followed the readme file step by step, but when it came down to run the command line to create the table used by the plugin, I got this:
database "" does not exists
I searched it, and I found out that sfConfig::get('app_mgI18nPlugin_connection'); returned an empty value. It was weird, because I've done every step right, setting the value in my app.yml and clearing symfony cache, so I logged sfConfig::getAll(); and found out that the only values for 'app_' stored here were the ones from the file app.yml in the plugin folder of kdDoctrineGuardFacebookConnectPlugin. I've already tried removing that file and clearing the cache, obtaining only to lose these values.
Here is the file contents:
project/apps/frontend/config/app.yml
all:
#other values
facebook:
appId: yyy
secret: yyy
cookie: true
script_lang: fr_FR
perms: email
mgI18nPlugin:
connection: doctrine
cultures_available:
fr: Français
en: English
it: Italiano
de: Deutsch
project/plugins/kdDoctrineGuardFacebookConnectPlugin/config/app.yml
all:
facebook:
appId: xxx
secret: xxx
cookie: true
script_lang: fr_FR
perms: email
and this is what I get when I log sfConfig::getAll(); :
array('app_facebook_appId' => 'xxx',
'app_facebook_secret' => 'xxx',
'app_facebook_cookie' => true,
'app_facebook_script_lang' => 'fr_FR',
'app_facebook_perms' => 'email',
)
Why the values for the main app.yml are not loaded? How do I correct this behaviour?
Thank you all in advance for your help, if you need more specifics I'll glady add them
If I understood you well you are in a command line task context (some sfTask). Symfony tasks by default do not run in application context. In most cases just call your task as
./symfony namespace:name --application=frontend
and you will have your configs.
If it is your own task just add it an option with default value in your configure method:
$this->addOptions(array(
new sfCommandOption('application', null, sfCommandOption::PARAMETER_REQUIRED, 'The application name', 'frontend'),
...
)
Plugin settings are loaded correctly, because plugins are configured per project not application (you enable them in ProjectConfiguration, not generated frontendConfiguration class)