Skip to content

Commit 1ef2da2

Browse files
committed
Create request-id to be set as a header on the request for oracle provider
requests. remove func folder Bump fn_go to 0.2.12. 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 1547b1a commit 1ef2da2

File tree

5 files changed

+47
-6
lines changed

5 files changed

+47
-6
lines changed

Gopkg.lock

Lines changed: 12 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ ignored = ["github.com/Azure/go-ansiterm*"]
3131

3232
[[constraint]]
3333
name = "github.com/fnproject/fn_go"
34-
version = "0.2.11"
34+
version = "0.2.12"
3535

3636
[[constraint]]
3737
name = "github.com/giantswarm/semver-bump"

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: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,35 @@ package main
22

33
import (
44
"bytes"
5+
"crypto/rand"
6+
"encoding/base32"
57
"fmt"
68
"io"
9+
"log"
710
"os"
811
"sort"
912
"strings"
1013
"text/tabwriter"
1114
"text/template"
1215

1316
"github.com/fnproject/cli/commands"
17+
"github.com/fnproject/cli/common"
1418
"github.com/fnproject/cli/common/color"
1519
"github.com/fnproject/cli/config"
1620
"github.com/spf13/viper"
1721
"github.com/urfave/cli"
1822
)
1923

24+
func getRequestID() string {
25+
byteArr := make([]byte, 16)
26+
_, err := rand.Read(byteArr)
27+
if err != nil {
28+
log.Fatalf("failed to generate random number for requestID")
29+
}
30+
31+
return base32.StdEncoding.WithPadding(base32.NoPadding).EncodeToString(byteArr)
32+
}
33+
2034
func newFn() *cli.App {
2135
app := cli.NewApp()
2236
app.Name = "fn"
@@ -29,6 +43,8 @@ func newFn() *cli.App {
2943
if err != nil {
3044
return err
3145
}
46+
47+
viper.Set(common.RequestID, common.GetRequestID())
3248
commandArgOverrides(c)
3349
return nil
3450
}

objects/app/apps.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@ import (
1212

1313
"github.com/fnproject/cli/client"
1414
"github.com/fnproject/cli/common"
15-
fnclient "github.com/fnproject/fn_go/client"
15+
fnclient "github.com/fnproject/fn_go/client"
1616
apiapps "github.com/fnproject/fn_go/client/apps"
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)