cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Announcements

1659
Views
0
Helpful
15
Replies
Anish Somadevan
Beginner

Multi-line argument is not supported.

 

Hi,

Am trying to do base64 encoding on a script. I have a local variable in my CPO process which has the script. The script contains nearly 20 lines. I use the following power shell script for base64 encoding,

[System.Convert]::ToBase64String([System.Text.Encoding]::UNICODE.GetBytes($(args[0]))

 

But I get an error stating, "Multi-line argument is not supported". I tried enabling the check for multiline in the local varaible, but it didnt work either.Can you please suggest how to resolve this?

 

Anish

 

15 REPLIES 15
Shaun Roberts
Cisco Employee

You need to convert the multi-line string to a single line string.

 

I wrote a function to do this and it's in my Automation Function Toolkit tap. You can find that @ https://supportforums.cisco.com/document/129151/automation-function-tools-version-2000-10-23-2013

 

--Shaun

--Shaun Roberts
Principal Engineer, CX
shaurobe@cisco.com

Thanks Shaun for the TAP file. I was able to convert the multiline script to a single line.  But while encoding it to base64  using Windows Power shell command, it throws an error "The paging file is too small for this operation to complete" . And the process took nearly 20 mts to complete. But when i reduce the script length to around 6 to 8 lines and try, it works, but again time taken is around 4 mts.Can you please porvide any solution?

Found this article on powershell and that error:
http://stackoverflow.com/questions/12076905/powershell-remoting-and-page-file

 

I would suggest some web searching for help in that issue. I've never seen it, but I've never done remote installs either :)

 

How long does it take when you execute it manually? Is 4 minutes a big deal? Assuming the timeout on the powershell activity is longer you should be ok, right?

--Shaun Roberts
Principal Engineer, CX
shaurobe@cisco.com

I have completed the base64 encoding of the UserData. Am using a utility tool which encodes the data to a base64 format. Thanks to your TAP file which converts the multiline enocded data to single line. I invoke the tool through a powershell command of CPO process. But when ipass this to calculate the AWS signature, its running for nearly 30 minutes without any output. When i reduce my UserData length to around 4 to 5 lines, it calculates the signature perfectly. Am using a powershell script to calculate the signature. The same below,

$secret, $data, $awshost = $args

[Reflection.Assembly]::LoadWithPartialName("System.Security") | Out-Null

$params = $data.replace("%%","%")
$verb = "POST"
$url = "/"

$data = [String]::Format("{0}`n{1}`n{2}`n{3}", $verb, $awshost, $url, $params)

$encoder = New-Object System.Text.UTF8Encoding
$sha256 = New-Object System.Security.Cryptography.HMACSHA256
$sha256.Key = $encoder.GetBytes($secret)
$hmac = $sha256.ComputeHash($encoder.GetBytes($data))
$enc = [System.Convert]::ToBase64String($hmac)
$hash = [System.Uri]::EscapeDataString($enc)
$null = [Reflection.Assembly]::LoadWithPartialName("System.Web")
$hash = [System.Web.HttpUtility]::UrlEncode($enc)

$hash.toString()

 

Could you please suggest how to resolve this. Is there any other command to create the signature?

If you run the script directly in powershell, how long does it take?

 

Are you running that code actually in the powershell window in CPO or are you just calling the script name? (like .\myscript.ps)

--Shaun Roberts
Principal Engineer, CX
shaurobe@cisco.com

It takes hardly 5 seconds if i run the same commands in my local windows power shell window. Yes, am running the commands in the powershell window in CPO. Am not using a script.

ok, since it's quick -- would it be possible to write the script, save it as a .ps/.ps1 file and then pass in stuff as parameters to that. Just thinking aloud :)

--Shaun Roberts
Principal Engineer, CX
shaurobe@cisco.com

I have wriiten the commands in a ps1 script file and pass the necessary arguments to it. It generates the signature. But unfortunately, it creates the same signature everytime for different requests.

The script that i use is,

param(
  [string]$secret,
  [string]$data,
  [string]$awshost
)
$secret, $data, $awshost = $args

[Reflection.Assembly]::LoadWithPartialName("System.Security") | Out-Null

$params = $data.replace("%%","%")
$verb = "POST"
$url = "/"

$data = [String]::Format("{0}`n{1}`n{2}`n{3}", $verb, $awshost, $url, $params)

$encoder = New-Object System.Text.UTF8Encoding
$sha256 = New-Object System.Security.Cryptography.HMACSHA256
$sha256.Key = $encoder.GetBytes($secret)
$hmac = $sha256.ComputeHash($encoder.GetBytes($data))
$enc = [System.Convert]::ToBase64String($hmac)
$hash = [System.Uri]::EscapeDataString($enc)
$null = [Reflection.Assembly]::LoadWithPartialName("System.Web")
$hash = [System.Web.HttpUtility]::UrlEncode($enc)

$hash.toString()

Any suggestions please

Am sorry, the value for data parameter was being sent as null coz i didnt configure it properly. But after i have corrected it, the signature calculation again takes a long time. But the same script with same values works in my local powershell window(but giving same signature always!!)

Svetlana Kryukova
Participant

I think you may need to expand on your use case a little bit...

Which activity are you trying to use? (I am assuming Execute Windows PowerShell Script).

Why can't you put the script INTO the activity itself, it is much safer that way?

If for some reason you cannot do that, you could consider using Write File activity to write your script to the remote machine (in preparation of execution) and then run an Execute Windows Command  or Execute Windows PowerShell Script activity to run the script (from file) and then destroy the file.

Yes, am using the Execute Windows Power shell Script. Am creating an AWS VM and sending the script as the UserData Query param. The script installs chef- client in the VM. Sorry I didn;t understand what does put the script into activity meant. The script creates a directory and then creates a file in that directory with execution scripts which is later executed. Could you please explain how to implement this? And i need to do it using HTTP Query API -- UserData(param)

 

 

I am getting really confused.

If you are trying to use HTTP, why are you using PowerShell? Why can't you use Web HTTP Request activity?

If you are trying to create a file (with a script in it), why can't you use Write File activity to create a script file? (again, why use PowerShell for that)?

Execute Windows PowerShell Script activity has script as one of the arguments. That argument does not accept variables, but that is for the script that the PowerShell then executes. So if you are trying to allow the user to define the script that Execute Windows PowerShell activity executes that won't work.

Suppose you wanted to write a process that takes a PowerShell script as an input (multi-line) string variable and run it on a specified Windows target. Now, I would say that this is a security risk, and you shouldn't write a process like this but here is how you could write it...

1. Add "Write File" activity, which takes your input variable and writes to the Windows target (to a predefined directory)

2. Add Execute Windows Command to run poweshell from the command-line on the WIndows target and execute the script from the file you just written in step 1.

3. Add Execute Windows Command that deletes the script file you created in step 1.

I hope this clears some things up.

 

 

I am using HTTP Query API to create an AWS VM. I want to install chef client on that VM.So i send the chef client installation script as a Query param (UserData). But the UserData param should be base64 encoded one. So i use a Power shell script in my workflow to encode the script. The script consists of nearly 20 lines.

Am not sure how to write the file to a remote VM which am going to create. If am able to do that, then it would be easier for me to call and execute the file from the workflow.

Hope this clears things out. Could you please suggest any poossible workaround?

 

I think it is getting clearer...

How about this...

  1. Use "Write File" activity to write the contents of the script (to be base64-encoded) into a file on the local PO server. Hint... You might want to use a unique file name for your process instance (file name based on process instance ID would give you that functionality)
  2. Use "Execute Windows PowerShell Script" or "Execute Windows Command" to run a script that reads the file (written in step 1), does base64 encoding on it, and returns the encoded result as output
  3. Use HTTP Request activity, and refer to the output of the activity in step 2, in the HTTP parameter/header in which you need the base64-encoded script.
  4. Delete file created in step 1.

There maybe another approach for Steps 1 & 2, via XSL Transform activity. There are a number of ideas on the internet for doing base64-encoding inside XSL.

Content for Community-Ad
This widget could not be displayed.