Skip to content

Commit

Permalink
Remove support for DEBUG_ASSETS_PATH (gravitational#21346)
Browse files Browse the repository at this point in the history
* Remove support for DEBUG_ASSETS_PATH now that webapps is in the same repository.

* Remove unused DebugEnvVar variable.

* Don't return an error when explicitly build without webassets.

* Create a simple util to return a http file system for apiserver tests.

* revert

* Add missing license.

* Add comment and remove lint exception.

* add in lint exception.
  • Loading branch information
hatched authored Feb 8, 2023
1 parent 5122f30 commit 5e68f63
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 135 deletions.
9 changes: 0 additions & 9 deletions constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,15 +261,6 @@ const (
// ComponentUsageReporting is the component responsible for reporting usage metrics.
ComponentUsageReporting = "usage-reporting"

// DebugEnvVar tells tests to use verbose debug output
DebugEnvVar = "DEBUG"

// DebugAssetsPath allows users to set the path of the webassets if debug
// mode is enabled.
// For example,
// `DEBUG=1 DEBUG_ASSETS_PATH=/path/to/webassets/ teleport start`.
DebugAssetsPath = "DEBUG_ASSETS_PATH"

// VerboseLogEnvVar forces all logs to be verbose (down to DEBUG level)
VerboseLogsEnvVar = "TELEPORT_DEBUG"

Expand Down
22 changes: 2 additions & 20 deletions lib/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import (
"os"
"path/filepath"
"runtime"
"strconv"
"strings"
"sync"
"sync/atomic"
Expand Down Expand Up @@ -5010,30 +5009,13 @@ func getPublicAddr(authClient auth.ReadAppsAccessPoint, a App) (string, error) {
// newHTTPFileSystem creates a new HTTP file system for the web handler.
// It uses external configuration to make the decision
func newHTTPFileSystem() (http.FileSystem, error) {
if !isDebugMode() {
fs, err := teleport.NewWebAssetsFilesystem() //nolint:staticcheck // linter fails on non-linux system as only linux implementation returns useful values.
if err != nil { //nolint:staticcheck // linter fails on non-linux system as only linux implementation returns useful values.
return nil, trace.Wrap(err)
}
return fs, nil
}

// Use the supplied HTTP filesystem path (defaults to the current dir).
assetsPath := os.Getenv(teleport.DebugAssetsPath)
fs, err := web.NewDebugFileSystem(assetsPath)
if err != nil {
fs, err := teleport.NewWebAssetsFilesystem() //nolint:staticcheck // linter fails on non-linux system as only linux implementation returns useful values.
if err != nil { //nolint:staticcheck // linter fails on non-linux system as only linux implementation returns useful values.
return nil, trace.Wrap(err)
}
return fs, nil
}

// isDebugMode determines if teleport is running in a "debug" mode.
// It looks at DEBUG environment variable
func isDebugMode() bool {
v, _ := strconv.ParseBool(os.Getenv(teleport.DebugEnvVar))
return v
}

// readOrGenerateHostID tries to read the `host_uuid` from Kubernetes storage (if available) or local storage.
// If the read operation returns no `host_uuid`, this function tries to pick it from the first static identity provided.
// If no static identities were defined for the process, a new id is generated depending on the joining process:
Expand Down
19 changes: 0 additions & 19 deletions lib/service/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,25 +62,6 @@ func TestMain(m *testing.M) {
os.Exit(m.Run())
}

func TestServiceDebugModeEnv(t *testing.T) {
require.False(t, isDebugMode())

for _, test := range []struct {
debugVal string
isDebug bool
}{
{"no", false},
{"0", false},
{"1", true},
{"true", true},
} {
t.Run(fmt.Sprintf("%v=%v", teleport.DebugEnvVar, test.debugVal), func(t *testing.T) {
t.Setenv(teleport.DebugEnvVar, test.debugVal)
require.Equal(t, test.isDebug, isDebugMode())
})
}
}

func TestServiceSelfSignedHTTPS(t *testing.T) {
cfg := &Config{
DataDir: t.TempDir(),
Expand Down
4 changes: 2 additions & 2 deletions lib/web/apiserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ func newWebSuiteWithConfig(t *testing.T, cfg webSuiteConfig) *WebSuite {

// Expired sessions are purged immediately
var sessionLingeringThreshold time.Duration
fs, err := NewDebugFileSystem("../../webassets/teleport")
fs, err := newDebugFileSystem()
require.NoError(t, err)

handler, err := NewHandler(Config{
Expand Down Expand Up @@ -6783,7 +6783,7 @@ func createProxy(ctx context.Context, t *testing.T, proxyID string, node *regula
require.NoError(t, err)
t.Cleanup(func() { require.NoError(t, proxyServer.Close()) })

fs, err := NewDebugFileSystem("../../webassets/teleport")
fs, err := newDebugFileSystem()
require.NoError(t, err)
handler, err := NewHandler(Config{
Proxy: revTunServer,
Expand Down
40 changes: 40 additions & 0 deletions lib/web/apiserver_test_utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright 2023 Gravitational, Inc
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package web

import (
"net/http"
"os"
"path/filepath"

"github.com/gravitational/trace"
)

// NewDebugFileSystem returns the HTTP file system implementation
func newDebugFileSystem() (http.FileSystem, error) {
// If the location of the UI changes on disk then this will need to be updated.
assetsPath := "../../webassets/teleport"

// Ensure we have the built assets available before continuing.
for _, af := range []string{"index.html", "/app"} {
_, err := os.Stat(filepath.Join(assetsPath, af))
if err != nil {
return nil, trace.Wrap(err)
}
}
log.Infof("Using filesystem for serving web assets: %s.", assetsPath)

return http.Dir(assetsPath), nil
}
42 changes: 0 additions & 42 deletions lib/web/assets.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,53 +21,11 @@ import (
"io"
"net/http"
"os"
"path"
"path/filepath"
"strings"

"github.com/gravitational/trace"
)

// NewDebugFileSystem returns the HTTP file system implementation rooted
// at the specified assetsPath.
func NewDebugFileSystem(assetsPath string) (http.FileSystem, error) {
assetsToCheck := []string{"index.html", "/app"}
if assetsPath == "" {
exePath, err := executableFolder()
if err != nil {
return nil, trace.Wrap(err)
}

_, err = os.Stat(path.Join(exePath, "../../e"))
isEnterprise := !os.IsNotExist(err)

if isEnterprise {
// enterprise web assets
assetsPath = path.Join(exePath, "../../webassets/e/teleport")
} else {
// community web assets
assetsPath = path.Join(exePath, "../webassets/teleport")
}
}

for _, af := range assetsToCheck {
_, err := os.Stat(filepath.Join(assetsPath, af))
if err != nil {
return nil, trace.Wrap(err)
}
}
log.Infof("Using filesystem for serving web assets: %s.", assetsPath)
return http.Dir(assetsPath), nil
}

func executableFolder() (string, error) {
p, err := os.Executable()
if err != nil {
return "", trace.Wrap(err)
}
return filepath.Dir(filepath.Clean(p)), nil
}

// resource struct implements http.File interface on top of zip.File object
type resource struct {
reader io.ReadCloser
Expand Down
43 changes: 0 additions & 43 deletions lib/web/static_test.go

This file was deleted.

0 comments on commit 5e68f63

Please sign in to comment.