Skip to content

Instantly share code, notes, and snippets.

Created July 26, 2019 15:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oliverholliday/45bab094c85cc726d1754f0b3b3691bf to your computer and use it in GitHub Desktop.
Save oliverholliday/45bab094c85cc726d1754f0b3b3691bf to your computer and use it in GitHub Desktop.
import PartnerToken from "./PartnerToken";
var token2 = new PartnerToken("test");
import * as hashjs from "hash.js";
import * as pulumi from "@pulumi/pulumi";
import * as crypto from "crypto";
import { CreateResult } from "@pulumi/pulumi/dynamic";
export type PartnerTokenResult = {
tokenId: string;
tokenValue: string;
export const generatePartnerToken = (): PartnerTokenResult => {
const entropyLength = 20;
const tokenIdLength = 4;
var bytes = crypto.randomBytes(20);
var tokenIdbytes = bytes.slice(0, tokenIdLength);
var tokenValuebytes = bytes.slice(tokenIdLength, entropyLength);
var tokenId = tokenIdbytes.toString('hex');
var tokenValue = hashjs.sha256().update(tokenValuebytes).digest("hex").slice(0, 32);
return ({
tokenId: tokenId,
tokenValue: tokenValue
export class PartnerTokenProvider implements pulumi.dynamic.ResourceProvider {
async create(_: any): Promise<CreateResult> {
var token = generatePartnerToken();
return { id: token.tokenId, outs: token };
export default class PartnerToken extends pulumi.dynamic.Resource {
public readonly tokenId: pulumi.Output<string>;
public readonly tokenValue: pulumi.Output<string>;
public readonly token: pulumi.Output<string>;
constructor(name: string, props: {} = {}, opts?: pulumi.CustomResourceOptions) {
super(new PartnerTokenProvider(), name, props, opts);
pulumi:pulumi:Stack (blah-dev):
(node:15960) ExperimentalWarning: queueMicrotask() is experimental.
error: Running program 'C:\dev\goodfellow\blah' failed with an unhandled exception:
TypeError: Cannot read property 'apply' of undefined
at Object.<anonymous> (C:\dev\goodfellow\blah\index.ts:5:19)
at Module._compile (internal/modules/cjs/loader.js:722:30)
at Module.m._compile (C:\dev\goodfellow\blah\node_modules\ts-node\src\index.ts:439:23)
at Module._extensions..js (internal/modules/cjs/loader.js:733:10)
at Object.require.extensions.(anonymous function) [as .ts] (C:\dev\goodfellow\blah\node_modules\ts-node\src\index.ts:442:12)
at Module.load (internal/modules/cjs/loader.js:620:32)
at tryModuleLoad (internal/modules/cjs/loader.js:560:12)
at Function.Module._load (internal/modules/cjs/loader.js:552:3)
at Module.require (internal/modules/cjs/loader.js:658:17)
at require (internal/modules/cjs/helpers.js:22:18)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment