encoding and decoding base64.in aws appsync resolver - aws-appsync

I have a resolver that receives an argument "nextToken" ($ctx.args.nextToken) which will be in base64 string. In the request mapping template, I need to convert nextToken from base64 string into ascii string. I know that Appsync has $util.base64Decode(String) : byte[] but this function gives back byte[] but I want back an ascii string.
In addition, I will need to create base64 string from ascii string in the response mapping template. Again Appsync provides a function $util.base64Encode( byte[] ) : String but I don't know how to change my ascii string into byte[].
Anybody has any idea how to handle both situations. Thanks in advance.

VTL template $util functions for base64 accept a string and return a string.
Example VTL template:
#set($base64 = $util.base64Encode("Hello World"))
{
"label": "$util.base64Decode($base64)"
}
Returns "Hello World"

Related

Non readable - YANG

There is a way to define non readable data in yang?
module system{
leaf name{
type string;
}
leaf password{
type string;
}
}
So in this case 'password' is the non readable data.
If you wish to make the data "unreadable", you can use binary built-in type, which enables you to set an arbitrary blob of bytes (base64 encoded) as the value for a leaf. Encrypted bytes included.
leaf password {
type binary;
default "cGFzc3dvcmQ="; // <-- plain text "password"
}

How to convert a JSON string to regular string?

I have the following connection string
{"Authentication Kind":"UsernamePassword","Username":"someID1","Password":"Yu#gh456!ts","EncryptConnection":true}
I am trying to show the password with ******* , so I need to convert it to SqlConnectionStringBuilder type as its easy to replace properties with that. I am using it just fine for non-json structured strings
[System.Data.SqlClient.SqlConnectionStringBuilder]::New('{"Authentication Kind":"UsernamePassword","Username":"someID1","Password":"Yu#gh456!ts","EncryptConnection":true}')
i am getting this error:
Cannot convert value to type
System.Data.SqlClient.SqlConnectionStringBuilder
How do I convert it to a connection string thats acceptable by the SqlConnectionStringBuilder type?
You could convert it to a PSObject first.
$Json = '{"Authentication Kind":"UsernamePassword","Username":"someID1","Password":"Yu#gh456!ts","EncryptConnection":true}'
$Sql = $Json | ConvertFrom-Json
$Sql.Password
From there you can use the properties to create a new string, or convert it back to JSON.

How can I return a formatted string from a REST call?

How can I create a Restful web service that will display as a multi line result in a Windows console.
I have tried the following but it displays the \r\n as string characters instead of line feeds. Also tried just \n, 0x0A, nothing seems to work.
#RequestMapping(value="/fetchMultiLine.do", method = RequestMethod.GET)
public String fetchMultiLine(HttpServletRequest request) {
return "Lines:\r\nfirst\r\nsecond\r\netc"
}
It always interprets the new line character as string characters and displays:
Lines:\r\nfirst\r\nsecond\r\netc
When I really want
Lines:
first
second
etc
Any hope?

Talend String handling convert "0.12900-" string to -0.12900 in float

Need help with the below conversion in Talend:
"0.12900-" string to -0.12900 in float via Tmap expression.
I am not well versed with Java hence the difficulty.
You could try something like this :
row1.column.contains("-")?Float.parseFloat( "-"+ StringHandling.LEFT(row1.column,row1.column.length()-1)):Float.parseFloat(row1.column)
Float.parseFloat allows you to convert a string to a float type.
StringHandling.LEFT gets the first characters of a string, here the total length-1.
Ternary operator controls if your string contains "-", otherwise you just have to parse the "-" symbol

How can you import data that has hex strings using Mongo import?

I am using mongoimport to import a json file. In one of the fields there is potentially regex expressions that contain hex strings such as:
{ "field1" : "/\x01\x02\x03/" }
I am getting the following error "FailedToParse: Hex escape not supported"
Try using double escape, what you have fails JSON validation.
{ "field1": "/\\x01\\x02\\x03/" }
This passes validation at http://jsonlint.com/
You may have to create a special case in your code for setting and getting this value, there is also an escape notion of \u in JSON which I believe denotes a hex escape but I've never used it before.
From some research I found this handy bit of info and example.
// Store RegExp pattern as a string
// Double backslashes are required to put literal \ characters in the string
var jsonObject = { "regex": "^http:\\/\\/" };