Skip to content

Commit 7614d6c

Browse files
authored
Merge pull request #1236 from blotus/use-go-embed
Replace go.rice with go embed
2 parents 04def84 + 33661a2 commit 7614d6c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

108 files changed

+26
-9808
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
dist/*
2-
cli/serve/rice-box.go
32
coverage.txt
43
profile.out
54
bin

Dockerfile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
FROM golang:1.14.1@sha256:08d16c1e689e86df1dae66d8ef4cec49a9d822299ec45e68a810c46cb705628d
1+
FROM golang:1.16.15@sha256:35fa3cfd4ec01a520f6986535d8f70a5eeef2d40fb8019ff626da24989bdd4f1
22

33
WORKDIR /workdir
44
COPY . /workdir
55

66
RUN git clone https://github.com/cloudflare/cfssl_trust.git /etc/cfssl && \
77
make clean && \
8-
make bin/rice && ./bin/rice embed-go -i=./cli/serve && \
98
make all && cp bin/* /usr/bin/
109

1110
EXPOSE 8888

Dockerfile.alpine

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:1.14.1-alpine3.11@sha256:244a736db4a1d2611d257e7403c729663ce2eb08d4628868f9d9ef2735496659 as builder
1+
FROM golang:1.16.15-alpine3.15@sha256:9743f230f26d1e300545f0330fd4a514f554c535d967563ee77bf634906502b6 as builder
22

33
WORKDIR /workdir
44
COPY . /workdir
@@ -8,7 +8,6 @@ RUN set -x && \
88

99
RUN git clone https://github.com/cloudflare/cfssl_trust.git /etc/cfssl && \
1010
make clean && \
11-
make bin/rice && ./bin/rice embed-go -i=./cli/serve && \
1211
make all
1312

1413
FROM alpine:3.11

Makefile

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,10 @@ export GOPROXY := off
77
.PHONY: all
88
all: bin/cfssl bin/cfssl-bundle bin/cfssl-certinfo bin/cfssl-newkey bin/cfssl-scan bin/cfssljson bin/mkbundle bin/multirootca
99

10-
bin/%: $(shell find . -type f -name '*.go') cli/serve/rice-box.go
10+
bin/%: $(shell find . -type f -name '*.go')
1111
@mkdir -p $(dir $@)
1212
go build -ldflags $(LDFLAGS) -o $@ ./cmd/$(@F)
1313

14-
cli/serve/rice-box.go: bin/rice $(shell find cli/serve/static -type f)
15-
cli/serve/rice-box.go:
16-
./bin/rice embed-go -i=./cli/serve
17-
1814
.PHONY: install
1915
install: install-cfssl install-cfssl-bundle install-cfssl-certinfo install-cfssl-newkey install-cfssl-scan install-cfssljson install-mkbundle install-multirootca
2016

@@ -27,10 +23,6 @@ serve: bin/cfssl
2723
serve:
2824
./bin/cfssl serve
2925

30-
bin/rice: $(shell find vendor -type f -name '*.go')
31-
@mkdir -p $(dir $@)
32-
go build -o $@ ./vendor/github.com/GeertJohan/go.rice/rice
33-
3426
bin/golint: $(shell find vendor -type f -name '*.go')
3527
@mkdir -p $(dir $@)
3628
go build -o $@ ./vendor/golang.org/x/lint/golint

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
CFSSL is CloudFlare's PKI/TLS swiss army knife. It is both a command line
1010
tool and an HTTP API server for signing, verifying, and bundling TLS
11-
certificates. It requires Go 1.12+ to build.
11+
certificates. It requires Go 1.16+ to build.
1212

1313
Note that certain linux distributions have certain algorithms removed
1414
(RHEL-based distributions in particular), so the golang from the
@@ -30,7 +30,7 @@ CFSSL consists of:
3030
### Building
3131

3232
Building cfssl requires a
33-
[working Go 1.12+ installation](http://golang.org/doc/install).
33+
[working Go 1.16+ installation](http://golang.org/doc/install).
3434

3535
```
3636
$ git clone [email protected]:cloudflare/cfssl.git
@@ -60,7 +60,7 @@ You can set the `GOOS` and `GOARCH` environment variables to have Go cross compi
6060

6161
### Installation
6262

63-
Installation requires a [working Go 1.14+ installation](http://golang.org/doc/install).
63+
Installation requires a [working Go 1.16+ installation](http://golang.org/doc/install).
6464
Alternatively, [prebuilt binaries are available](https://github.com/cloudflare/cfssl/releases)
6565

6666
```

cli/serve/serve.go

Lines changed: 18 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ package serve
33

44
import (
55
"crypto/tls"
6+
"embed"
67
"errors"
78
"fmt"
9+
"io/fs"
810
"net"
911
"net/http"
1012
"net/url"
@@ -13,7 +15,6 @@ import (
1315
"strconv"
1416
"strings"
1517

16-
rice "github.com/GeertJohan/go.rice"
1718
"github.com/cloudflare/cfssl/api"
1819
"github.com/cloudflare/cfssl/api/bundle"
1920
"github.com/cloudflare/cfssl/api/certadd"
@@ -81,38 +82,28 @@ func v1APIPath(path string) string {
8182
return (&url.URL{Path: path}).String()
8283
}
8384

84-
// httpBox implements http.FileSystem which allows the use of Box with a http.FileServer.
85-
// Attempting to Open an API endpoint will result in an error.
86-
type httpBox struct {
87-
*rice.Box
88-
redirects map[string]string
85+
//go:embed static
86+
var staticContent embed.FS
87+
88+
var staticRedirections = map[string]string{
89+
"bundle": "index.html",
90+
"scan": "index.html",
91+
"packages": "index.html",
8992
}
9093

91-
func (hb *httpBox) findStaticBox() (err error) {
92-
hb.Box, err = rice.FindBox("static")
93-
return
94+
type staticFS struct {
95+
fs fs.FS
96+
redirections map[string]string
9497
}
9598

96-
// Open returns a File for non-API enpoints using the http.File interface.
97-
func (hb *httpBox) Open(name string) (http.File, error) {
99+
func (s *staticFS) Open(name string) (fs.File, error) {
98100
if strings.HasPrefix(name, V1APIPrefix) {
99101
return nil, os.ErrNotExist
100102
}
101-
102-
if location, ok := hb.redirects[name]; ok {
103-
return hb.Box.Open(location)
103+
if location, ok := s.redirections[name]; ok {
104+
return s.fs.Open(location)
104105
}
105-
106-
return hb.Box.Open(name)
107-
}
108-
109-
// staticBox is the box containing all static assets.
110-
var staticBox = &httpBox{
111-
redirects: map[string]string{
112-
"/scan": "/index.html",
113-
"/bundle": "/index.html",
114-
"/packages": "/index.html",
115-
},
106+
return s.fs.Open(name)
116107
}
117108

118109
var errBadSigner = errors.New("signer not initialized")
@@ -242,11 +233,8 @@ var endpoints = map[string]func() (http.Handler, error){
242233
},
243234

244235
"/": func() (http.Handler, error) {
245-
if err := staticBox.findStaticBox(); err != nil {
246-
return nil, err
247-
}
248-
249-
return http.FileServer(staticBox), nil
236+
subFS, _ := fs.Sub(staticContent, "static")
237+
return http.FileServer(http.FS(&staticFS{fs: subFS, redirections: staticRedirections})), nil
250238
},
251239

252240
"health": func() (http.Handler, error) {

cli/serve/serve_test.go

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package serve
33
import (
44
"net/http"
55
"net/http/httptest"
6-
"os"
76
"testing"
87

98
"github.com/cloudflare/cfssl/cli"
@@ -18,20 +17,6 @@ func TestServe(t *testing.T) {
1817
expected[v1APIPath(endpoint)] = http.StatusOK
1918
}
2019

21-
err := staticBox.Walk("", func(path string, info os.FileInfo, err error) error {
22-
if err != nil {
23-
return err
24-
}
25-
26-
if !info.IsDir() {
27-
expected["/"+path] = http.StatusOK
28-
}
29-
return nil
30-
})
31-
if err != nil {
32-
t.Error(err)
33-
}
34-
3520
// Disabled endpoints should return '404 Not Found'
3621
expected[v1APIPath("sign")] = http.StatusNotFound
3722
expected[v1APIPath("authsign")] = http.StatusNotFound

go.mod

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
module github.com/cloudflare/cfssl
22

3-
go 1.14
3+
go 1.16
44

55
require (
66
bitbucket.org/liamstask/goose v0.0.0-20150115234039-8488cc47d90c
7-
github.com/GeertJohan/go.rice v1.0.2
87
github.com/census-instrumentation/opencensus-proto v0.3.0 // indirect
98
github.com/certifi/gocertifi v0.0.0-20210507211836-431795d63e8d // indirect
109
github.com/cloudflare/backoff v0.0.0-20161212185259-647f3cdfc87a
1110
github.com/cloudflare/redoctober v0.0.0-20201013214028-99c99a8e7544
1211
github.com/cncf/udpa/go v0.0.0-20210322005330-6414d713912e // indirect
1312
github.com/coreos/go-systemd/v22 v22.3.2 // indirect
14-
github.com/daaku/go.zipexe v1.0.1 // indirect
1513
github.com/envoyproxy/protoc-gen-validate v0.6.1 // indirect
1614
github.com/form3tech-oss/jwt-go v3.2.3+incompatible // indirect
1715
github.com/go-sql-driver/mysql v1.6.0

go.sum

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,6 @@ github.com/Azure/go-autorest v12.0.0+incompatible/go.mod h1:r+4oMnoxhatjLLJ6zxSW
6262
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
6363
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
6464
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
65-
github.com/GeertJohan/go.incremental v1.0.0 h1:7AH+pY1XUgQE4Y1HcXYaMqAI0m9yrFqo/jt0CW30vsg=
66-
github.com/GeertJohan/go.incremental v1.0.0/go.mod h1:6fAjUhbVuX1KcMD3c8TEgVUqmo4seqhv0i0kdATSkM0=
67-
github.com/GeertJohan/go.rice v1.0.2 h1:PtRw+Tg3oa3HYwiDBZyvOJ8LdIyf6lAovJJtr7YOAYk=
68-
github.com/GeertJohan/go.rice v1.0.2/go.mod h1:af5vUNlDNkCjOZeSGFgIJxDje9qdjsO6hshx0gTmZt4=
6965
github.com/GoogleCloudPlatform/cloudsql-proxy v0.0.0-20191009163259-e802c2cb94ae/go.mod h1:mjwGPas4yKduTyubHvD1Atl9r1rUq8DfVy+gkVvZ+oo=
7066
github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0=
7167
github.com/Masterminds/goutils v1.1.0/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU=
@@ -80,8 +76,6 @@ github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWX
8076
github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI=
8177
github.com/VividCortex/gohistogram v1.0.0/go.mod h1:Pf5mBqqDxYaXu3hDrrU+w6nw50o/4+TcAqDqk/vUH7g=
8278
github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5/go.mod h1:SkGFH1ia65gfNATL8TAiHDNxPzPdmEL5uirI2Uyuz6c=
83-
github.com/akavel/rsrc v0.8.0 h1:zjWn7ukO9Kc5Q62DOJCcxGpXC18RawVtYAGdz2aLlfw=
84-
github.com/akavel/rsrc v0.8.0/go.mod h1:uLoCtb9J+EyAqh+26kdrTgmzRBFPGOolLWKpdxkKq+c=
8579
github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7/go.mod h1:6zEj6s6u/ghQa61ZWa/C2Aw3RkjiTBOix7dkqa1VLIs=
8680
github.com/alecthomas/kingpin v2.2.6+incompatible/go.mod h1:59OFYbFVLKQKq+mqrL6Rw5bR0c3ACQaawgXx0QYndlE=
8781
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
@@ -184,9 +178,6 @@ github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsr
184178
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
185179
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
186180
github.com/creack/pty v1.1.11/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
187-
github.com/daaku/go.zipexe v1.0.0/go.mod h1:z8IiR6TsVLEYKwXAoE/I+8ys/sDkgTzSL0CLnGVd57E=
188-
github.com/daaku/go.zipexe v1.0.1 h1:wV4zMsDOI2SZ2m7Tdz1Ps96Zrx+TzaK15VbUaGozw0M=
189-
github.com/daaku/go.zipexe v1.0.1/go.mod h1:5xWogtqlYnfBXkSB1o9xysukNP9GTvaNkqzUZbt3Bw8=
190181
github.com/davecgh/go-spew v0.0.0-20161028175848-04cdfd42973b/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
191182
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
192183
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
@@ -422,7 +413,6 @@ github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANyt
422413
github.com/influxdata/influxdb1-client v0.0.0-20191209144304-8bf82d3c094d/go.mod h1:qj24IKcXYK6Iy9ceXlo3Tc+vtHo9lIhSX5JddghvEPo=
423414
github.com/jarcoal/httpmock v1.0.5/go.mod h1:ATjnClrvW/3tijVmpL/va5Z3aAyGvqU3gCT8nX0Txik=
424415
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo=
425-
github.com/jessevdk/go-flags v1.4.0 h1:4IU2WS7AumrZ/40jfhf4QVDMsQwqA7VEHozFRrGARJA=
426416
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
427417
github.com/jhump/protoreflect v1.6.1/go.mod h1:RZQ/lnuN+zqeRVpQigTwO6o0AJUkxbnSnpuG7toUTG4=
428418
github.com/jhump/protoreflect v1.8.2 h1:k2xE7wcUomeqwY0LDCYA16y4WWfyTcMx5mKhk0d4ua0=
@@ -546,8 +536,6 @@ github.com/nats-io/nkeys v0.1.0/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxzi
546536
github.com/nats-io/nkeys v0.1.3/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w=
547537
github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c=
548538
github.com/nishanths/predeclared v0.0.0-20200524104333-86fad755b4d3/go.mod h1:nt3d53pc1VYcphSCIaYAJtnPYnr3Zyn8fMq2wvPGPso=
549-
github.com/nkovacs/streamquote v1.0.0 h1:PmVIV08Zlx2lZK5fFZlMZ04eHcDTIFJCv/5/0twVUow=
550-
github.com/nkovacs/streamquote v1.0.0/go.mod h1:BN+NaZ2CmdKqUuTUXUEm9j95B2TRbpOWpxbJYzzgUsc=
551539
github.com/oklog/oklog v0.3.2/go.mod h1:FCV+B7mhrz4o+ueLpx+KqkyXRGMWOYEvfiXtdGtbWGs=
552540
github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA=
553541
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
@@ -724,10 +712,6 @@ github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtX
724712
github.com/urfave/cli v1.22.4/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
725713
github.com/urfave/cli v1.22.5 h1:lNq9sAHXK2qfdI8W+GRItjCEkI+2oR4d+MEHy1CKXoU=
726714
github.com/urfave/cli v1.22.5/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
727-
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
728-
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
729-
github.com/valyala/fasttemplate v1.0.1 h1:tY9CJiPnMXf1ERmG2EyK7gNUd+c6RKGD0IfU8WdUSz8=
730-
github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8=
731715
github.com/weppos/publicsuffix-go v0.13.1-0.20210123135404-5fd73613514e/go.mod h1:HYux0V0Zi04bHNwOHy4cXJVz/TQjYonnF6aoYhj+3QE=
732716
github.com/weppos/publicsuffix-go v0.15.1-0.20210511084619-b1f36a2d6c0b h1:FsyNrX12e5BkplJq7wKOLk0+C6LZ+KGXvuEcKUYm5ss=
733717
github.com/weppos/publicsuffix-go v0.15.1-0.20210511084619-b1f36a2d6c0b/go.mod h1:HYux0V0Zi04bHNwOHy4cXJVz/TQjYonnF6aoYhj+3QE=

tools.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
//go:build tools
12
// +build tools
23

34
package tools
45

56
import (
67
_ "bitbucket.org/liamstask/goose/cmd/goose"
7-
_ "github.com/GeertJohan/go.rice/rice"
88
_ "golang.org/x/lint/golint"
99
)

0 commit comments

Comments
 (0)