Skip to content

Instantly share code, notes, and snippets.

View virtualhobbit's full-sized avatar
:octocat:
Building clouds

Mark Brookfield virtualhobbit

:octocat:
Building clouds
View GitHub Profile
<UserAccounts>
<AdministratorPassword>
<Value>{{password}}</Value>
<PlainText>true</PlainText>
</AdministratorPassword>
</UserAccounts>
<AutoLogon>
<Enabled>true</Enabled>
<Username>Administrator</Username>
"builders": [
{
"type": "vsphere-iso",
"vcenter_server": "{{user `vcenter`}}",
"username": "{{user `vcenterUser`}}",
"password": "{{user `vcenterPass`}}",
"insecure_connection": true,
"vm_name": "{{user `vmName`}}",
{
"variables": {
"vcenter": "{{env `packer_vcenter`}}",
"vcenterUser": "{{env `packer_vcenterUser`}}",
"vcenterPass": "{{env `packer_vcenterPass`}}",
"vmName": "{{env `packer_vmName`}}",
"cluster": "{{env `packer_cluster`}}",
"datastore": "{{env `packer_datastore`}}",
"datastore_iso": "{{env `packer_datastoreISO`}}",
"network": "{{env `packer_network`}}",
//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
// 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);
// 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);
// 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');
// 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' +
//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;
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;