Skip to content

Commit ec6c02c

Browse files
committed
Squashed commit of the following:
commit d4b4fa7 Author: JadeRedworth <[email protected]> Date: Fri Aug 17 16:45:22 2018 +0100 move generation of request id to common.go commit 70f44cc Author: JadeRedworth <[email protected]> Date: Fri Aug 17 14:32:55 2018 +0100 remove func folder commit 735b2eb Author: JadeRedworth <[email protected]> Date: Fri Aug 17 11:40:23 2018 +0100 Create request-id to be set as a header on the request for oracle provider requests.
1 parent 687df96 commit ec6c02c

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"text/template"
1212

1313
"github.com/fnproject/cli/commands"
14+
"github.com/fnproject/cli/common"
1415
"github.com/fnproject/cli/common/color"
1516
"github.com/fnproject/cli/config"
1617
"github.com/spf13/viper"
@@ -29,6 +30,8 @@ func newFn() *cli.App {
2930
if err != nil {
3031
return err
3132
}
33+
34+
viper.Set(common.RequestID, common.GetRequestID())
3235
commandArgOverrides(c)
3336
return nil
3437
}

objects/app/apps.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"github.com/fnproject/fn_go/models"
1818
"github.com/fnproject/fn_go/provider"
1919
"github.com/jmoiron/jsonq"
20+
"github.com/spf13/viper"
2021
"github.com/urfave/cli"
2122
)
2223

@@ -26,7 +27,8 @@ type appsCmd struct {
2627
}
2728

2829
func (a *appsCmd) list(c *cli.Context) error {
29-
params := &apiapps.GetAppsParams{Context: context.Background()}
30+
ctx := provider.WithRequestID(context.Background(), viper.GetString("request-id"))
31+
params := &apiapps.GetAppsParams{Context: ctx}
3032
var resApps []*models.App
3133
for {
3234
resp, err := a.client.Apps.GetApps(params)

0 commit comments

Comments
 (0)