forked from pulumi/examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a way to send events to the Event Hub
- Loading branch information
1 parent
7cc4dab
commit 4c2089e
Showing
5 changed files
with
39 additions
and
5 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { encode } from "utf8"; | ||
import { createHmac } from "crypto"; | ||
|
||
export function createSharedAccessToken(uri: string, saName: string, saKey: string): string { | ||
if (!uri || !saName || !saKey) { | ||
throw "Missing required parameter"; | ||
} | ||
var encoded = encodeURIComponent(uri); | ||
var now = new Date(); | ||
var week = 60 * 60 * 24 * 7; | ||
var ttl = Math.round(now.getTime() / 1000) + week; | ||
var signature = encoded + '\n' + ttl; | ||
var signatureUTF8 = encode(signature); | ||
var hash = createHmac('sha256', saKey).update(signatureUTF8).digest('base64'); | ||
return 'SharedAccessSignature sr=' + encoded + '&sig=' + encodeURIComponent(hash) + '&se=' + ttl + '&skn=' + saName; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
"strictNullChecks": true | ||
}, | ||
"files": [ | ||
"index.ts" | ||
"index.ts", | ||
"token.ts" | ||
] | ||
} | ||
} |