Skip to content

Commit

Permalink
Merge pull request #1236 from blotus/use-go-embed
Browse files Browse the repository at this point in the history
Replace go.rice with go embed
  • Loading branch information
nickysemenza authored Aug 19, 2022
2 parents 04def84 + 33661a2 commit 7614d6c
Show file tree
Hide file tree
Showing 108 changed files with 26 additions and 9,808 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
dist/*
cli/serve/rice-box.go
coverage.txt
profile.out
bin
Expand Down
3 changes: 1 addition & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
FROM golang:1.14.1@sha256:08d16c1e689e86df1dae66d8ef4cec49a9d822299ec45e68a810c46cb705628d
FROM golang:1.16.15@sha256:35fa3cfd4ec01a520f6986535d8f70a5eeef2d40fb8019ff626da24989bdd4f1

WORKDIR /workdir
COPY . /workdir

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

EXPOSE 8888
Expand Down
3 changes: 1 addition & 2 deletions Dockerfile.alpine
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.14.1-alpine3.11@sha256:244a736db4a1d2611d257e7403c729663ce2eb08d4628868f9d9ef2735496659 as builder
FROM golang:1.16.15-alpine3.15@sha256:9743f230f26d1e300545f0330fd4a514f554c535d967563ee77bf634906502b6 as builder

WORKDIR /workdir
COPY . /workdir
Expand All @@ -8,7 +8,6 @@ RUN set -x && \

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

FROM alpine:3.11
Expand Down
10 changes: 1 addition & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,10 @@ export GOPROXY := off
.PHONY: all
all: bin/cfssl bin/cfssl-bundle bin/cfssl-certinfo bin/cfssl-newkey bin/cfssl-scan bin/cfssljson bin/mkbundle bin/multirootca

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

cli/serve/rice-box.go: bin/rice $(shell find cli/serve/static -type f)
cli/serve/rice-box.go:
./bin/rice embed-go -i=./cli/serve

.PHONY: install
install: install-cfssl install-cfssl-bundle install-cfssl-certinfo install-cfssl-newkey install-cfssl-scan install-cfssljson install-mkbundle install-multirootca

Expand All @@ -27,10 +23,6 @@ serve: bin/cfssl
serve:
./bin/cfssl serve

bin/rice: $(shell find vendor -type f -name '*.go')
@mkdir -p $(dir $@)
go build -o $@ ./vendor/github.com/GeertJohan/go.rice/rice

bin/golint: $(shell find vendor -type f -name '*.go')
@mkdir -p $(dir $@)
go build -o $@ ./vendor/golang.org/x/lint/golint
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

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

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

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

```
$ git clone git@github.com:cloudflare/cfssl.git
Expand Down Expand Up @@ -60,7 +60,7 @@ You can set the `GOOS` and `GOARCH` environment variables to have Go cross compi

### Installation

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

```
Expand Down
48 changes: 18 additions & 30 deletions cli/serve/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package serve

import (
"crypto/tls"
"embed"
"errors"
"fmt"
"io/fs"
"net"
"net/http"
"net/url"
Expand All @@ -13,7 +15,6 @@ import (
"strconv"
"strings"

rice "github.com/GeertJohan/go.rice"
"github.com/cloudflare/cfssl/api"
"github.com/cloudflare/cfssl/api/bundle"
"github.com/cloudflare/cfssl/api/certadd"
Expand Down Expand Up @@ -81,38 +82,28 @@ func v1APIPath(path string) string {
return (&url.URL{Path: path}).String()
}

// httpBox implements http.FileSystem which allows the use of Box with a http.FileServer.
// Attempting to Open an API endpoint will result in an error.
type httpBox struct {
*rice.Box
redirects map[string]string
//go:embed static
var staticContent embed.FS

var staticRedirections = map[string]string{
"bundle": "index.html",
"scan": "index.html",
"packages": "index.html",
}

func (hb *httpBox) findStaticBox() (err error) {
hb.Box, err = rice.FindBox("static")
return
type staticFS struct {
fs fs.FS
redirections map[string]string
}

// Open returns a File for non-API enpoints using the http.File interface.
func (hb *httpBox) Open(name string) (http.File, error) {
func (s *staticFS) Open(name string) (fs.File, error) {
if strings.HasPrefix(name, V1APIPrefix) {
return nil, os.ErrNotExist
}

if location, ok := hb.redirects[name]; ok {
return hb.Box.Open(location)
if location, ok := s.redirections[name]; ok {
return s.fs.Open(location)
}

return hb.Box.Open(name)
}

// staticBox is the box containing all static assets.
var staticBox = &httpBox{
redirects: map[string]string{
"/scan": "/index.html",
"/bundle": "/index.html",
"/packages": "/index.html",
},
return s.fs.Open(name)
}

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

"/": func() (http.Handler, error) {
if err := staticBox.findStaticBox(); err != nil {
return nil, err
}

return http.FileServer(staticBox), nil
subFS, _ := fs.Sub(staticContent, "static")
return http.FileServer(http.FS(&staticFS{fs: subFS, redirections: staticRedirections})), nil
},

"health": func() (http.Handler, error) {
Expand Down
15 changes: 0 additions & 15 deletions cli/serve/serve_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package serve
import (
"net/http"
"net/http/httptest"
"os"
"testing"

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

err := staticBox.Walk("", func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}

if !info.IsDir() {
expected["/"+path] = http.StatusOK
}
return nil
})
if err != nil {
t.Error(err)
}

// Disabled endpoints should return '404 Not Found'
expected[v1APIPath("sign")] = http.StatusNotFound
expected[v1APIPath("authsign")] = http.StatusNotFound
Expand Down
4 changes: 1 addition & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
module github.com/cloudflare/cfssl

go 1.14
go 1.16

require (
bitbucket.org/liamstask/goose v0.0.0-20150115234039-8488cc47d90c
github.com/GeertJohan/go.rice v1.0.2
github.com/census-instrumentation/opencensus-proto v0.3.0 // indirect
github.com/certifi/gocertifi v0.0.0-20210507211836-431795d63e8d // indirect
github.com/cloudflare/backoff v0.0.0-20161212185259-647f3cdfc87a
github.com/cloudflare/redoctober v0.0.0-20201013214028-99c99a8e7544
github.com/cncf/udpa/go v0.0.0-20210322005330-6414d713912e // indirect
github.com/coreos/go-systemd/v22 v22.3.2 // indirect
github.com/daaku/go.zipexe v1.0.1 // indirect
github.com/envoyproxy/protoc-gen-validate v0.6.1 // indirect
github.com/form3tech-oss/jwt-go v3.2.3+incompatible // indirect
github.com/go-sql-driver/mysql v1.6.0
Expand Down
16 changes: 0 additions & 16 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,6 @@ github.com/Azure/go-autorest v12.0.0+incompatible/go.mod h1:r+4oMnoxhatjLLJ6zxSW
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/GeertJohan/go.incremental v1.0.0 h1:7AH+pY1XUgQE4Y1HcXYaMqAI0m9yrFqo/jt0CW30vsg=
github.com/GeertJohan/go.incremental v1.0.0/go.mod h1:6fAjUhbVuX1KcMD3c8TEgVUqmo4seqhv0i0kdATSkM0=
github.com/GeertJohan/go.rice v1.0.2 h1:PtRw+Tg3oa3HYwiDBZyvOJ8LdIyf6lAovJJtr7YOAYk=
github.com/GeertJohan/go.rice v1.0.2/go.mod h1:af5vUNlDNkCjOZeSGFgIJxDje9qdjsO6hshx0gTmZt4=
github.com/GoogleCloudPlatform/cloudsql-proxy v0.0.0-20191009163259-e802c2cb94ae/go.mod h1:mjwGPas4yKduTyubHvD1Atl9r1rUq8DfVy+gkVvZ+oo=
github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0=
github.com/Masterminds/goutils v1.1.0/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU=
Expand All @@ -80,8 +76,6 @@ github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWX
github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI=
github.com/VividCortex/gohistogram v1.0.0/go.mod h1:Pf5mBqqDxYaXu3hDrrU+w6nw50o/4+TcAqDqk/vUH7g=
github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5/go.mod h1:SkGFH1ia65gfNATL8TAiHDNxPzPdmEL5uirI2Uyuz6c=
github.com/akavel/rsrc v0.8.0 h1:zjWn7ukO9Kc5Q62DOJCcxGpXC18RawVtYAGdz2aLlfw=
github.com/akavel/rsrc v0.8.0/go.mod h1:uLoCtb9J+EyAqh+26kdrTgmzRBFPGOolLWKpdxkKq+c=
github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7/go.mod h1:6zEj6s6u/ghQa61ZWa/C2Aw3RkjiTBOix7dkqa1VLIs=
github.com/alecthomas/kingpin v2.2.6+incompatible/go.mod h1:59OFYbFVLKQKq+mqrL6Rw5bR0c3ACQaawgXx0QYndlE=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
Expand Down Expand Up @@ -184,9 +178,6 @@ github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsr
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/creack/pty v1.1.11/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/daaku/go.zipexe v1.0.0/go.mod h1:z8IiR6TsVLEYKwXAoE/I+8ys/sDkgTzSL0CLnGVd57E=
github.com/daaku/go.zipexe v1.0.1 h1:wV4zMsDOI2SZ2m7Tdz1Ps96Zrx+TzaK15VbUaGozw0M=
github.com/daaku/go.zipexe v1.0.1/go.mod h1:5xWogtqlYnfBXkSB1o9xysukNP9GTvaNkqzUZbt3Bw8=
github.com/davecgh/go-spew v0.0.0-20161028175848-04cdfd42973b/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
Expand Down Expand Up @@ -422,7 +413,6 @@ github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANyt
github.com/influxdata/influxdb1-client v0.0.0-20191209144304-8bf82d3c094d/go.mod h1:qj24IKcXYK6Iy9ceXlo3Tc+vtHo9lIhSX5JddghvEPo=
github.com/jarcoal/httpmock v1.0.5/go.mod h1:ATjnClrvW/3tijVmpL/va5Z3aAyGvqU3gCT8nX0Txik=
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo=
github.com/jessevdk/go-flags v1.4.0 h1:4IU2WS7AumrZ/40jfhf4QVDMsQwqA7VEHozFRrGARJA=
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/jhump/protoreflect v1.6.1/go.mod h1:RZQ/lnuN+zqeRVpQigTwO6o0AJUkxbnSnpuG7toUTG4=
github.com/jhump/protoreflect v1.8.2 h1:k2xE7wcUomeqwY0LDCYA16y4WWfyTcMx5mKhk0d4ua0=
Expand Down Expand Up @@ -546,8 +536,6 @@ github.com/nats-io/nkeys v0.1.0/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxzi
github.com/nats-io/nkeys v0.1.3/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w=
github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c=
github.com/nishanths/predeclared v0.0.0-20200524104333-86fad755b4d3/go.mod h1:nt3d53pc1VYcphSCIaYAJtnPYnr3Zyn8fMq2wvPGPso=
github.com/nkovacs/streamquote v1.0.0 h1:PmVIV08Zlx2lZK5fFZlMZ04eHcDTIFJCv/5/0twVUow=
github.com/nkovacs/streamquote v1.0.0/go.mod h1:BN+NaZ2CmdKqUuTUXUEm9j95B2TRbpOWpxbJYzzgUsc=
github.com/oklog/oklog v0.3.2/go.mod h1:FCV+B7mhrz4o+ueLpx+KqkyXRGMWOYEvfiXtdGtbWGs=
github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA=
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
Expand Down Expand Up @@ -724,10 +712,6 @@ github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtX
github.com/urfave/cli v1.22.4/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
github.com/urfave/cli v1.22.5 h1:lNq9sAHXK2qfdI8W+GRItjCEkI+2oR4d+MEHy1CKXoU=
github.com/urfave/cli v1.22.5/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasttemplate v1.0.1 h1:tY9CJiPnMXf1ERmG2EyK7gNUd+c6RKGD0IfU8WdUSz8=
github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8=
github.com/weppos/publicsuffix-go v0.13.1-0.20210123135404-5fd73613514e/go.mod h1:HYux0V0Zi04bHNwOHy4cXJVz/TQjYonnF6aoYhj+3QE=
github.com/weppos/publicsuffix-go v0.15.1-0.20210511084619-b1f36a2d6c0b h1:FsyNrX12e5BkplJq7wKOLk0+C6LZ+KGXvuEcKUYm5ss=
github.com/weppos/publicsuffix-go v0.15.1-0.20210511084619-b1f36a2d6c0b/go.mod h1:HYux0V0Zi04bHNwOHy4cXJVz/TQjYonnF6aoYhj+3QE=
Expand Down
2 changes: 1 addition & 1 deletion tools.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//go:build tools
// +build tools

package tools

import (
_ "bitbucket.org/liamstask/goose/cmd/goose"
_ "github.com/GeertJohan/go.rice/rice"
_ "golang.org/x/lint/golint"
)
2 changes: 0 additions & 2 deletions vendor/github.com/GeertJohan/go.incremental/.gitignore

This file was deleted.

22 changes: 0 additions & 22 deletions vendor/github.com/GeertJohan/go.incremental/LICENSE

This file was deleted.

53 changes: 0 additions & 53 deletions vendor/github.com/GeertJohan/go.incremental/README.md

This file was deleted.

5 changes: 0 additions & 5 deletions vendor/github.com/GeertJohan/go.incremental/doc.go

This file was deleted.

3 changes: 0 additions & 3 deletions vendor/github.com/GeertJohan/go.incremental/go.mod

This file was deleted.

Loading

0 comments on commit 7614d6c

Please sign in to comment.