Skip to content

Instantly share code, notes, and snippets.

Avatar
:octocat:
Building clouds

Mark Brookfield virtualhobbit

:octocat:
Building clouds
View GitHub Profile
View submitRequest.js
//Compute the full URL
var requestUrlString = "/2013-04-01/hostedzone/" + attHostedZone + "/rrset";
var request = attRestHost.createRequest("POST", requestUrlString, attBody);
//Set the authentication header
request.setHeader("Authorization", attAuthString);
request.setHeader("X-Amz-Content-Sha256", attHashedPayload);
request.setHeader("X-Amz-Date", attAmzDate);
//Execute the request and get the response
View task4.js
// Define the authentication header string
attAuthString = 'AWS4-HMAC-SHA256 Credential=' + attAccessKey + '/' + attAmzAuthDate + '/' + attRegion + '/' + attService + '/aws4_request, SignedHeaders=' + attSignedHeaders + ', Signature=' + attSignature;
System.log("Auth string is: " + attAuthString);
View task3.js
// Define the signing key in base64
var kSigningB64 = CryptoEncoding.hexToBase64(attSigningKey);
System.log("The signing key in base64 is: " + kSigningB64);
// Define the string to sign in base 64
var stringToSignB64 = CryptoEncoding.base64Encode(attStringToSign);
System.log("The string to sign in base64 is: " + stringToSignB64);
// Calculate the signature
var signature = CryptoDigest.hmacSha256(kSigningB64, stringToSignB64);
View task2.js
// Format the auth date
attAmzAuthDate = attAmzDate.split("T")[0];
// Define string to sign
attStringToSign = 'AWS4-HMAC-SHA256\n' + attAmzDate + '\n' + attAmzAuthDate + '/' + attRegion + '/' + attService + '/aws4_request\n'+ attCanonicalRequestHash;
System.log("The string to sign is: " + '\n' + '\n' + attStringToSign + '\n');
View task1.js
// Hash the payload
attHashedPayload = CryptoEncoding.base64toHex(CryptoDigest.sha256(attBody));
// Format the date
attAmzDate = System.getModule("com.hobbitcloud.aws.date").getAmzDate(new Date().toISOString());
var canonicalUri = "/2013-04-01/hostedzone/" + attHostedZone + "/rrset";
var canonicalQueryString = "";
var canonicalHeaders = 'host:' + attUrl + '\n' +
'x-amz-content-sha256:' + attHashedPayload + '\n' +
View defineBody.js
//Define XML properties
var xmlDetail = new Properties();
xmlDetail.put("{attXmlConfigAction}",inAction);
xmlDetail.put("{attXmlConfigRecord}",inRecord);
xmlDetail.put("{attXmlConfigType}",inType);
xmlDetail.put("{attXmlConfigTtl}",inTtl);
xmlDetail.put("{attXmlConfigValue}",inValue);
//Replace placeholders in XML file with correct values
var attBody = attXmlConfigBody.getContentAsMimeAttachment().content;
View getSigningkey.js
var kDate = CryptoDigest.hmacSha256(CryptoEncoding.base64Encode("AWS4" + inSecretKey), CryptoEncoding.base64Encode(inAmzAuthDate));
var kRegion = CryptoDigest.hmacSha256(kDate, CryptoEncoding.base64Encode(inRegion));
var kService = CryptoDigest.hmacSha256(kRegion, CryptoEncoding.base64Encode(inService));
var kSigning = CryptoDigest.hmacSha256(kService, CryptoEncoding.base64Encode("aws4_request"));
var keySigning = CryptoEncoding.base64toHex(kSigning);
return keySigning;
View getAmzDate.js
var dateStr;
var chars = [":","-"];
for (var i = 0; i < chars.length;i++) {
while (inDate.indexOf(chars[i]) !== -1) {
inDate = inDate.replace(chars[i],"");
}
}
dateStr = inDate.split(".")[0] + "Z";
View route53.xml
<?xml version="1.0" encoding="UTF-8"?>
<ChangeResourceRecordSetsRequest xmlns="https://route53.amazonaws.com/doc/2013-04-01/">
<ChangeBatch>
<Changes>
<Change>
<Action>{attXmlConfigAction}</Action>
<ResourceRecordSet>
<Name>{attXmlConfigRecord}</Name>
<Type>{attXmlConfigType}</Type>
<TTL>{attXmlConfigTtl}</TTL>
View osot.ps1
$ErrorActionPreference = "Stop"
$webserver = "webserver.contoso.local"
$url = "http://" + $webserver
$files = @("VMwareOSOptimizationTool.exe","VMwareOSOptimizationTool.exe.config","my_osot.xml")
$exe = $files[0]
$arg = "-o -t " + $files[2]
# Verify connectivity
if (Test-Connection $webserver -Quiet){
You can’t perform that action at this time.