Created
May 4, 2017 20:22
-
-
Save rcabr/e1a4194521b83f7bb9bdd9c22c012424 to your computer and use it in GitHub Desktop.
Pentaho - Azure DocumentDB - Access Control on Document Resources
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Problem: | |
// Use the DocumentDB REST API from Pentaho DI (Spoon) | |
// Produce an authorization header for the request | |
// | |
// Solution: | |
// 1. Read this document https://docs.microsoft.com/en-us/rest/api/documentdb/access-control-on-documentdb-resources | |
// 2. Assuming you have serialized your record to JSON and wish to publish it via a REST Client step | |
// 3. Add a "Modified Java Script Value" step to your Pentaho Transformation with the following body. | |
//Input | |
var date = new Date().toUTCString(); | |
var verb = "post"; | |
var resourceType = "docs"; | |
var resourceLink = "dbs/db01/colls/family"; | |
var key = "<your DocumentDb key>"; | |
var value = (verb || "").toLowerCase() + "\n" + | |
(resourceType || "").toLowerCase() + "\n" + | |
(resourceLink || "") + "\n" + | |
date.toLowerCase() + "\n" + | |
"" + "\n"; | |
var keyBytes = java.util.Base64.getDecoder().decode(key); | |
var signingKey = new javax.crypto.spec.SecretKeySpec(keyBytes, "HmacSHA256"); | |
var mac = javax.crypto.Mac.getInstance("HmacSHA256"); | |
mac.init(signingKey); | |
var rawHmac = mac.doFinal(new java.lang.String(""+value).getBytes("UTF-8")); | |
var MasterToken = "master"; | |
var TokenVersion = "1.0"; | |
var sig64 = java.util.Base64.getEncoder().encodeToString(rawHmac); | |
var authString = encodeURIComponent("type=" + MasterToken + "&ver=" + TokenVersion + "&sig=" + sig64); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment