A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/cloudflare/cfssl/commit/9ca1d0a10e7414ea22c23b7b77153a6028c51a8a below:

use go:embed · cloudflare/cfssl@9ca1d0a · GitHub

File tree Expand file treeCollapse file tree 3 files changed

+19

-46

lines changed

Filter options

Expand file treeCollapse file tree 3 files changed

+19

-46

lines changed Original file line number Diff line number Diff line change

@@ -3,8 +3,10 @@ package serve

3 3 4 4

import (

5 5

"crypto/tls"

6 +

"embed"

6 7

"errors"

7 8

"fmt"

9 +

"io/fs"

8 10

"net"

9 11

"net/http"

10 12

"net/url"

@@ -13,7 +15,6 @@ import (

13 15

"strconv"

14 16

"strings"

15 17 16 -

rice "github.com/GeertJohan/go.rice"

17 18

"github.com/cloudflare/cfssl/api"

18 19

"github.com/cloudflare/cfssl/api/bundle"

19 20

"github.com/cloudflare/cfssl/api/certadd"

@@ -81,38 +82,28 @@ func v1APIPath(path string) string {

81 82

return (&url.URL{Path: path}).String()

82 83

}

83 84 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",

89 92

}

90 93 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

94 97

}

95 98 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) {

98 100

if strings.HasPrefix(name, V1APIPrefix) {

99 101

return nil, os.ErrNotExist

100 102

}

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)

104 105

}

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)

116 107

}

117 108 118 109

var errBadSigner = errors.New("signer not initialized")

@@ -242,11 +233,8 @@ var endpoints = map[string]func() (http.Handler, error){

242 233

},

243 234 244 235

"/": 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

250 238

},

251 239 252 240

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

Original file line number Diff line number Diff line change

@@ -3,7 +3,6 @@ package serve

3 3

import (

4 4

"net/http"

5 5

"net/http/httptest"

6 -

"os"

7 6

"testing"

8 7 9 8

"github.com/cloudflare/cfssl/cli"

@@ -18,20 +17,6 @@ func TestServe(t *testing.T) {

18 17

expected[v1APIPath(endpoint)] = http.StatusOK

19 18

}

20 19 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 - 35 20

// Disabled endpoints should return '404 Not Found'

36 21

expected[v1APIPath("sign")] = http.StatusNotFound

37 22

expected[v1APIPath("authsign")] = http.StatusNotFound

Original file line number Diff line number Diff line change

@@ -1,6 +1,6 @@

1 1

module github.com/cloudflare/cfssl

2 2 3 -

go 1.14

3 +

go 1.16

4 4 5 5

require (

6 6

bitbucket.org/liamstask/goose v0.0.0-20150115234039-8488cc47d90c

You can’t perform that action at this time.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4