better-shampoo-48884
04/08/2021, 2:25 PMconst rabbitUsers = {
orchestratorclient: new random.RandomPassword("orchestratorclient", {length:32}),
orchestratoruser: new random.RandomPassword("orchestratoruser", {length:32}),
subscriptionuser: new random.RandomPassword("subscriptionuser", {length:32}),
orchestrator: new random.RandomPassword("orchestrator", {length:32}),
admin: new random.RandomPassword("admin", {length:32}),
producer: new random.RandomPassword("producer", {length:32}),
testreader: new random.RandomPassword("testreader", {length:32})
}
const rabbitPassHasher = (pass2hash : string, salt?: Buffer) => {
//let salt = Buffer.from([0x90,0x8D,0xC6,0x0A])
if (salt) {
} else {
salt = randomBytes(32)
}
console.log(salt)
//let concated = Buffer.concat([salt, Buffer.from("test12")])
let pass = Buffer.from(pass2hash)
let concated : Buffer = Buffer.concat([salt, pass])
let hash = createHash('sha256')
hash.write(concated)
let hashDigest = hash.digest()
return Buffer.concat([salt, hashDigest]).toString('base64')
}
const salt = Buffer.from([0xDE,0xAD,0xCA,0xFE])
brave-planet-10645
04/08/2021, 2:27 PMnew random.RandomPassword("foo", {length: 32}).result
right?better-shampoo-48884
04/08/2021, 2:27 PMlet rabbitLoadFile = {
"rabbit_version": "3.7.13",
"users": [{
"name": "orchestratorclient",
"password_hash": rabbitPassHasher(pulumi.interpolate`rabbitUsers.orchestratorclient.result`, salt),
"hashing_algorithm": "rabbit_password_hashing_sha256",
"tags": ""
},
....
}
Because, of course, and as it should be - rabbitUsers.orchestratorclient.result is Output<string>brave-planet-10645
04/08/2021, 2:27 PMbetter-shampoo-48884
04/08/2021, 2:28 PMbrave-planet-10645
04/08/2021, 2:29 PMbetter-shampoo-48884
04/08/2021, 2:29 PM.result
- if I could add .rabbitHashedResult
to the list, that should solve it nicelybored-oyster-3147
04/08/2021, 2:29 PMrabbitUsers.orchestratorclient.result.apply(x => rabbitPassHasher(x, salt))
better-shampoo-48884
04/08/2021, 2:30 PMbored-oyster-3147
04/08/2021, 2:31 PMbetter-shampoo-48884
04/08/2021, 2:31 PMbored-oyster-3147
04/08/2021, 2:32 PMbetter-shampoo-48884
04/08/2021, 2:32 PMbored-oyster-3147
04/08/2021, 2:35 PMOutput<string>
of the hash so then to put that in the JSON you would need to do like:
hash.apply(rabbitHash =>
{
return {
...,
"password_hash": rabbitHash,
...,
};
});
better-shampoo-48884
04/09/2021, 6:03 PM"users": [
{
"name": "orchestratorclient",
"password_hash": "Calling [toJSON] on an [Output<T>] is not supported.\n\nTo get the value of an Output as a JSON value or JSON string consider either:\n 1: o.apply(v => v.toJSON())\n 2: o.apply(v => JSON.stringify(v))\n\nSee <https://pulumi.io/help/outputs> for more details.\nThis function may throw in a future version of @pulumi/pulumi.",
"hashing_algorithm": "rabbit_password_hashing_sha256",
"tags": ""
},
😄 😄let rabbitLoadFile = {
"rabbit_version": "3.8.14",
"users": [{
"name": "orchestratorclient",
"password_hash": rabbitUsers.orchestratorclient.result.apply(x => { return rabbitPassHasher(x, salt)}),
"hashing_algorithm": "rabbit_password_hashing_sha256",
"tags": ""
},{
...
}]
}
const rabbitLoadSecret = new azure.keyvault.Secret(`rabbit-load-definition`, {
resourceGroupName: environment.rg,
vaultName: environment.vault.name,
secretName: `rabbit-load-definition`,
properties: {
value: JSON.stringify(rabbitLoadFile.apply())
}
})
value: rabbitUsers.admin.result.apply(x => { return JSON.stringify(rabbitLoadFile)})
bored-oyster-3147
04/09/2021, 6:15 PMlet rabbitLoadFile = {
"rabbit_version": "3.8.14",
"users": [{
"name": "orchestratorclient",
"password_hash": rabbitUsers.orchestratorclient.result.apply(x => { return rabbitPassHasher(x, salt)}),
"hashing_algorithm": "rabbit_password_hashing_sha256",
"tags": ""
},{
...
}]
}
properties: {
value: JSON.stringify(rabbitLoadFile.apply())
}
The value
here should accept Input<T>better-shampoo-48884
04/09/2021, 6:20 PMbored-oyster-3147
04/09/2021, 6:22 PMlet rabbitLoadFile = rabbitUsers.orchestratorclient.result.apply(password =>
{
return {
"rabbit_version": "3.8.14",
"users": [{
"name": "orchestratorclient",
"password_hash": rabbitPassHasher(password, salt),
"hashing_algorithm": "rabbit_password_hashing_sha256",
"tags": "",
}],
};
});
now your load file is an Output<object>. And then:
const rabbitLoadSecret = new azure.keyvault.Secret(`rabbit-load-definition`, {
resourceGroupName: environment.rg,
vaultName: environment.vault.name,
secretName: `rabbit-load-definition`,
properties: {
value: rabbitLoadFile.apply(x => JSON.stringify(x)),
}
})
better-shampoo-48884
04/09/2021, 6:23 PMproperties.value
?bored-oyster-3147
04/09/2021, 6:24 PMOutput<T>
in your original examplebetter-shampoo-48884
04/09/2021, 6:24 PMvalue: rabbitUsers.admin.result.apply(x => { return JSON.stringify(rabbitLoadFile)})
seems to me to be identicalbored-oyster-3147
04/09/2021, 6:24 PMbetter-shampoo-48884
04/09/2021, 6:25 PMbored-oyster-3147
04/09/2021, 6:25 PMobject
mine is Output<object>
better-shampoo-48884
04/09/2021, 6:27 PMlet rabbitLoadFile = rabbitUsers.orchestratorclient.result.apply(password =>
{
return JSON.stringify({
"rabbit_version": "3.8.14",
"users": [{
"name": "orchestratorclient",
"password_hash": rabbitPassHasher(password, salt),
"hashing_algorithm": "rabbit_password_hashing_sha256",
"tags": "",
}],
});
});
The above would be an Output<string> right?bored-oyster-3147
04/09/2021, 6:28 PMrabbitLoadFile
directly to properties.value
assuming it takes Input<string>
better-shampoo-48884
04/09/2021, 6:28 PMlet rabbitLoadFile = rabbitUsers.orchestratorclient.result.apply(pass{
"rabbit_version": "3.8.14",
"users": [{
"name": "orchestratorclient",
"password_hash": rabbitUsers.orchestratorclient.result.apply(x => { return rabbitPassHasher(x, salt)}),
"hashing_algorithm": "rabbit_password_hashing_sha256",
"tags": ""
}, {
"name": "orchestratoruser",
"password_hash": rabbitUsers.orchestratoruser.result.apply(x => { return rabbitPassHasher(x, salt)}),
"hashing_algorithm": "rabbit_password_hashing_sha256",
"tags": ""
}, {
const rabbitUsers : { [index: string]: random.RandomPassword } = {
orchestratorclient: new random.RandomPassword("orchestratorclient", {length:32}),
orchestratoruser: new random.RandomPassword("orchestratoruser", {length:32}),
subscriptionuser: new random.RandomPassword("subscriptionuser", {length:32}),
orchestrator: new random.RandomPassword("orchestrator", {length:32}),
admin: new random.RandomPassword("admin", {length:32}),
producer: new random.RandomPassword("producer", {length:32}),
testreader: new random.RandomPassword("testreader", {length:32})
}
bored-oyster-3147
04/09/2021, 6:36 PMoutput.tuple
or output.all
comes in, so you can pass multiple Output<T>
into an .apply(...)
call. Alternatively you could save the JSON.stringify(...)
until the very end and append to the users
array. So you could do:
let rabbitLoadFile = password1.apply(pw =>
{
return {
"rabbit_version": "3.8.14",
"users": [{
"name": "orchestratorclient",
"password_hash": rabbitPassHasher(pw, salt),
"hashing_algorithm": "rabbit_password_hashing_sha256",
"tags": "",
}],
};
});
and that would just be for the first password. You want to keep it as an Output<object>
so you can continue to manipulate it as an object. Then all passwords after that could look like:
rabbitLoadFile = output.all(rabbitLoadFile, password2).apply((file, pw) =>
{
// instead of adding it to the existing object
// you may want to clone it, modify the clone, and return the clone
file.users.add({
"name": "orchestratorclient",
"password_hash": rabbitPassHasher(pw, salt),
"hashing_algorithm": "rabbit_password_hashing_sha256",
"tags": "",
});
});
and then finally on properties.value
you would rabbitLoadFile.apply(x => JSON.stringify(x))
better-shampoo-48884
04/09/2021, 6:38 PMbored-oyster-3147
04/09/2021, 6:39 PMbetter-shampoo-48884
04/09/2021, 6:39 PMbored-oyster-3147
04/09/2021, 6:40 PMOutput.Tuple(...)
better-shampoo-48884
04/09/2021, 6:41 PMbored-oyster-3147
04/09/2021, 6:42 PMbetter-shampoo-48884
04/09/2021, 6:42 PM"rabbit_version": "3.8.14",
"users": [
{
"name": "orchestratorclient",
"password_hash": "3q3K/j9AhUZPSGJYsSu7xZHu6ggA2YsaSzDkWFUO6+Ch7aWQ",
"hashing_algorithm": "rabbit_password_hashing_sha256",
"tags": ""
},
{
happy days!bored-oyster-3147
04/09/2021, 7:54 PM