From b771e204e956c291eb02f8ae7329312db184736d Mon Sep 17 00:00:00 2001 From: rawdaGastan Date: Tue, 26 Nov 2024 13:30:35 +0200 Subject: [PATCH] update go and nodejs examples --- examples/go/kubernetes/main.go | 17 ++++++++++++----- examples/go/network/main.go | 18 +++++++++++++----- examples/go/virtual_machine/main.go | 17 ++++++++++++----- examples/go/zdb/main.go | 17 ++++++++++++----- examples/nodejs/gateway_fqdn/package.json | 2 +- examples/nodejs/gateway_name/package.json | 2 +- examples/nodejs/kubernetes/package.json | 2 +- examples/nodejs/network/package.json | 2 +- examples/nodejs/virtual_machine/package.json | 2 +- examples/nodejs/zdb/package.json | 2 +- 10 files changed, 55 insertions(+), 26 deletions(-) diff --git a/examples/go/kubernetes/main.go b/examples/go/kubernetes/main.go index c322d1b..861112a 100644 --- a/examples/go/kubernetes/main.go +++ b/examples/go/kubernetes/main.go @@ -1,18 +1,25 @@ package main import ( - "crypto/rand" - "encoding/base64" + "math/rand" "os" + "strings" "github.com/pulumi/pulumi/sdk/v3/go/pulumi" "github.com/threefoldtech/pulumi-threefold/sdk/go/threefold" ) func randomString() string { - bytes := make([]byte, 8) - rand.Read(bytes) - return base64.URLEncoding.EncodeToString(bytes)[:8] + var alphabet []rune = []rune("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz") + + var sb strings.Builder + + for i := 0; i < 8; i++ { + ch := alphabet[rand.Intn(len(alphabet))] + sb.WriteRune(ch) + } + + return sb.String() } func main() { diff --git a/examples/go/network/main.go b/examples/go/network/main.go index 91980a5..dc1434d 100644 --- a/examples/go/network/main.go +++ b/examples/go/network/main.go @@ -1,18 +1,26 @@ package main import ( - "encoding/base64" "os" + "strings" + + "math/rand" "github.com/pulumi/pulumi/sdk/v3/go/pulumi" "github.com/threefoldtech/pulumi-threefold/sdk/go/threefold" - "golang.org/x/exp/rand" ) func randomString() string { - bytes := make([]byte, 8) - rand.Read(bytes) - return base64.URLEncoding.EncodeToString(bytes)[:8] + var alphabet []rune = []rune("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz") + + var sb strings.Builder + + for i := 0; i < 8; i++ { + ch := alphabet[rand.Intn(len(alphabet))] + sb.WriteRune(ch) + } + + return sb.String() } func main() { diff --git a/examples/go/virtual_machine/main.go b/examples/go/virtual_machine/main.go index d74be7f..3c301bc 100644 --- a/examples/go/virtual_machine/main.go +++ b/examples/go/virtual_machine/main.go @@ -1,18 +1,25 @@ package main import ( - "crypto/rand" - "encoding/base64" + "math/rand" "os" + "strings" "github.com/pulumi/pulumi/sdk/v3/go/pulumi" "github.com/threefoldtech/pulumi-threefold/sdk/go/threefold" ) func randomString() string { - bytes := make([]byte, 8) - rand.Read(bytes) - return base64.URLEncoding.EncodeToString(bytes)[:8] + var alphabet []rune = []rune("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz") + + var sb strings.Builder + + for i := 0; i < 8; i++ { + ch := alphabet[rand.Intn(len(alphabet))] + sb.WriteRune(ch) + } + + return sb.String() } func main() { diff --git a/examples/go/zdb/main.go b/examples/go/zdb/main.go index 5825f6a..b9a5f50 100644 --- a/examples/go/zdb/main.go +++ b/examples/go/zdb/main.go @@ -1,19 +1,26 @@ package main import ( - "crypto/rand" - "encoding/base64" "fmt" + "math/rand" "os" + "strings" "github.com/pulumi/pulumi/sdk/v3/go/pulumi" "github.com/threefoldtech/pulumi-threefold/sdk/go/threefold" ) func randomString() string { - bytes := make([]byte, 8) - rand.Read(bytes) - return base64.URLEncoding.EncodeToString(bytes)[:8] + var alphabet []rune = []rune("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz") + + var sb strings.Builder + + for i := 0; i < 8; i++ { + ch := alphabet[rand.Intn(len(alphabet))] + sb.WriteRune(ch) + } + + return sb.String() } func main() { diff --git a/examples/nodejs/gateway_fqdn/package.json b/examples/nodejs/gateway_fqdn/package.json index 5fdfbaa..bf90d3b 100644 --- a/examples/nodejs/gateway_fqdn/package.json +++ b/examples/nodejs/gateway_fqdn/package.json @@ -5,7 +5,7 @@ }, "dependencies": { "@pulumi/pulumi": "^3.0.0", - "@threefold/pulumi": "^0.7.2", + "@threefold/pulumi": "^0.8.1", "typescript": "^4.0.0" } } diff --git a/examples/nodejs/gateway_name/package.json b/examples/nodejs/gateway_name/package.json index 5fdfbaa..bf90d3b 100644 --- a/examples/nodejs/gateway_name/package.json +++ b/examples/nodejs/gateway_name/package.json @@ -5,7 +5,7 @@ }, "dependencies": { "@pulumi/pulumi": "^3.0.0", - "@threefold/pulumi": "^0.7.2", + "@threefold/pulumi": "^0.8.1", "typescript": "^4.0.0" } } diff --git a/examples/nodejs/kubernetes/package.json b/examples/nodejs/kubernetes/package.json index 5fdfbaa..bf90d3b 100644 --- a/examples/nodejs/kubernetes/package.json +++ b/examples/nodejs/kubernetes/package.json @@ -5,7 +5,7 @@ }, "dependencies": { "@pulumi/pulumi": "^3.0.0", - "@threefold/pulumi": "^0.7.2", + "@threefold/pulumi": "^0.8.1", "typescript": "^4.0.0" } } diff --git a/examples/nodejs/network/package.json b/examples/nodejs/network/package.json index 5fdfbaa..bf90d3b 100644 --- a/examples/nodejs/network/package.json +++ b/examples/nodejs/network/package.json @@ -5,7 +5,7 @@ }, "dependencies": { "@pulumi/pulumi": "^3.0.0", - "@threefold/pulumi": "^0.7.2", + "@threefold/pulumi": "^0.8.1", "typescript": "^4.0.0" } } diff --git a/examples/nodejs/virtual_machine/package.json b/examples/nodejs/virtual_machine/package.json index 06900a6..e5434d2 100644 --- a/examples/nodejs/virtual_machine/package.json +++ b/examples/nodejs/virtual_machine/package.json @@ -5,7 +5,7 @@ }, "dependencies": { "@pulumi/pulumi": "^3.131.0", - "@threefold/pulumi": "^0.7.2", + "@threefold/pulumi": "^0.8.1", "typescript": "^4.0.0" } } diff --git a/examples/nodejs/zdb/package.json b/examples/nodejs/zdb/package.json index 5fdfbaa..bf90d3b 100644 --- a/examples/nodejs/zdb/package.json +++ b/examples/nodejs/zdb/package.json @@ -5,7 +5,7 @@ }, "dependencies": { "@pulumi/pulumi": "^3.0.0", - "@threefold/pulumi": "^0.7.2", + "@threefold/pulumi": "^0.8.1", "typescript": "^4.0.0" } }