Skip to content

Commit 98745a5

Browse files
authored
Merge branch 'request-id' into request-id
2 parents 241c94b + ec6c02c commit 98745a5

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

common/common.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ import (
1111
"log"
1212
"os"
1313
"os/exec"
14+
"encoding/base32"
1415
"os/signal"
1516
"path/filepath"
17+
"crypto/rand"
1618
"strings"
1719
"time"
1820
"unicode"
@@ -32,6 +34,8 @@ const (
3234
FunctionsDockerImage = "fnproject/fnserver"
3335
FuncfileDockerRuntime = "docker"
3436
MinRequiredDockerVersion = "17.5.0"
37+
RequestID = "request-id"
38+
RequestedLength = 16
3539
)
3640

3741
// GetWd returns working directory.
@@ -55,6 +59,16 @@ func GetDir(c *cli.Context) string {
5559
return dir
5660
}
5761

62+
func GetRequestID() string {
63+
byteArr := make([]byte, RequestedLength)
64+
_, err := rand.Read(byteArr)
65+
if err != nil {
66+
log.Fatalf("failed to generate random number for requestID")
67+
}
68+
69+
return base32.StdEncoding.WithPadding(base32.NoPadding).EncodeToString(byteArr)
70+
}
71+
5872
// BuildFunc bumps version and builds function.
5973
func BuildFunc(c *cli.Context, fpath string, funcfile *FuncFile, buildArg []string, noCache bool) (*FuncFile, error) {
6074
var err error

main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"text/template"
1515

1616
"github.com/fnproject/cli/commands"
17+
"github.com/fnproject/cli/common"
1718
"github.com/fnproject/cli/common/color"
1819
"github.com/fnproject/cli/config"
1920
"github.com/spf13/viper"
@@ -42,8 +43,7 @@ func newFn() *cli.App {
4243
if err != nil {
4344
return err
4445
}
45-
46-
viper.Set("request-id", getRequestID())
46+
viper.Set(common.RequestID, common.GetRequestID())
4747
commandArgOverrides(c)
4848
return nil
4949
}

0 commit comments

Comments
 (0)