Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removes --skip-browser-session-auth option #344

Merged
merged 13 commits into from
Nov 13, 2023
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ If you want to build the development version the easiest (after switching branch
1. Build and start the vite web server, to support error reporting and hot-reloading: `just web/dev` in one terminal. Keep the terminal window open.
- This will launch the `vite` web server on `http://127.0.0.1:9000`
2. Within a new terminal window, build the development version of the CLI: `just build-dev`. Keep this terminal open, so that you can rebuild as needed.
3. Within a new terminal window, launch the development version of the CLI for the current platform (with these parameters): `./connect-client publish-ui <PROJECT_PATH> --listen=127.0.0.1:9001 --open-browser-at="http://127.0.0.1:9000" --skip-browser-session-auth`
- *Where** `<PROJECT_PATH>` above is replaced with a location of a sample project. For example, with a python project at `~/dev/connect-content/bundles/python-flaskapi`, your complete command line would become: `./connect-client publish-ui ~/dev/connect-content/bundles/python-flaskapi --listen=127.0.0.1:9001 --open-browser-at="http://127.0.0.1:9000" --skip-browser-session-auth`.
3. Within a new terminal window, launch the development version of the CLI for the current platform (with these parameters): `./connect-client publish-ui <PROJECT_PATH> --listen=127.0.0.1:9001 --open-browser-at="http://127.0.0.1:9000"`
- *Where** `<PROJECT_PATH>` above is replaced with a location of a sample project. For example, with a python project at `~/dev/connect-content/bundles/python-flaskapi`, your complete command line would become: `./connect-client publish-ui ~/dev/connect-content/bundles/python-flaskapi --listen=127.0.0.1:9001 --open-browser-at="http://127.0.0.1:9000"`.
- This launches the CLI and configures it to listen on port `9001`, while launching a browser to the address which is being served by the `vite` web server.

You now should have a Web UX loaded within the browser, which is loading from the `vite` dev server, but has its APIs serviced from the CLI backend.
Expand Down
1 change: 0 additions & 1 deletion cmd/connect-client/commands/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,6 @@ func (cmd *PublishUICmd) Run(args *cli_types.CommonArgs, ctx *cli_types.CLIConte
"/",
cmd.UIArgs,
&cmd.PublishArgs,
ctx.LocalToken,
ctx.Fs,
ctx.Accounts,
log,
Expand Down
10 changes: 1 addition & 9 deletions cmd/connect-client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/rstudio/connect-client/internal/events"
"github.com/rstudio/connect-client/internal/logging"
"github.com/rstudio/connect-client/internal/project"
"github.com/rstudio/connect-client/internal/services"
"github.com/spf13/afero"
)

Expand All @@ -37,11 +36,7 @@ func logVersion(log logging.Logger) {
func makeContext(log logging.Logger) (*cli_types.CLIContext, error) {
fs := afero.NewOsFs()
accountList := accounts.NewAccountList(fs, log)
token, err := services.NewLocalToken()
if err != nil {
return nil, err
}
ctx := cli_types.NewCLIContext(accountList, token, fs, log)
ctx := cli_types.NewCLIContext(accountList, fs, log)
return ctx, nil
}

Expand Down Expand Up @@ -75,9 +70,6 @@ func main() {
if cli.Debug {
ctx.Logger = events.NewLogger(true)
}
if cli.Token != nil {
ctx.LocalToken = *cli.Token
}
cmd, ok := args.Selected().Target.Interface().(commands.StatefulCommand)
if ok {
// For these commands, we need to load saved deployment state
Expand Down
1 change: 0 additions & 1 deletion cmd/connect-client/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,5 @@ func (s *MainSuite) TestMakeContext() {
ctx, err := makeContext(log)
s.Nil(err)
s.NotNil(ctx.Accounts)
s.NotEqual(ctx.LocalToken, "")
s.Equal(log, ctx.Logger)
}
2 changes: 1 addition & 1 deletion extensions/positron/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ const executable: string = "connect-client";
export type Command = string;

export const create = (port: number, subcommand: string = "publish-ui"): Command => {
return `${executable} ${subcommand} --listen=127.0.0.1:${port} test/sample-content/fastapi-simple --skip-browser-session-auth`;
return `${executable} ${subcommand} --listen=127.0.0.1:${port} test/sample-content/fastapi-simple`;
};
37 changes: 16 additions & 21 deletions internal/cli_types/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,48 +5,43 @@ package cli_types
import (
"github.com/rstudio/connect-client/internal/accounts"
"github.com/rstudio/connect-client/internal/logging"
"github.com/rstudio/connect-client/internal/services"
"github.com/rstudio/connect-client/internal/state"
"github.com/rstudio/connect-client/internal/util"

"github.com/spf13/afero"
)

type CommonArgs struct {
Debug bool `help:"Enable debug mode." env:"CONNECT_DEBUG"`
Profile string `help:"Enable CPU profiling"`
Token *services.LocalToken `help:"Authentication token for the publishing UI. Default auto-generates a token."`
Debug bool `help:"Enable debug mode." env:"CONNECT_DEBUG"`
Profile string `help:"Enable CPU profiling"`
}

type Log interface {
logging.Logger
}

type CLIContext struct {
Accounts accounts.AccountList
LocalToken services.LocalToken
Fs afero.Fs
Logger logging.Logger
Accounts accounts.AccountList
Fs afero.Fs
Logger logging.Logger
}

func NewCLIContext(accountList accounts.AccountList, token services.LocalToken, fs afero.Fs, log logging.Logger) *CLIContext {
func NewCLIContext(accountList accounts.AccountList, fs afero.Fs, log logging.Logger) *CLIContext {
return &CLIContext{
Accounts: accountList,
LocalToken: token,
Fs: fs,
Logger: log,
Accounts: accountList,
Fs: fs,
Logger: log,
}
}

type UIArgs struct {
Interactive bool `short:"i" help:"Launch a browser to show the UI at the listen address."`
OpenBrowserAt string `help:"Launch a browser to show the UI at specific network address." placeholder:"HOST[:PORT]" hidden:""`
SkipBrowserSessionAuth bool `help:"Skip Browser Token Auth Checks" hidden:""`
Theme string `help:"UI theme, 'light' or 'dark'." hidden:""`
Listen string `help:"Network address to listen on." placeholder:"HOST[:PORT]" default:"localhost:0"`
AccessLog bool `help:"Log all HTTP requests."`
TLSKeyFile string `help:"Path to TLS private key file for the UI server."`
TLSCertFile string `help:"Path to TLS certificate chain file for the UI server."`
Interactive bool `short:"i" help:"Launch a browser to show the UI at the listen address."`
OpenBrowserAt string `help:"Launch a browser to show the UI at specific network address." placeholder:"HOST[:PORT]" hidden:""`
Theme string `help:"UI theme, 'light' or 'dark'." hidden:""`
Listen string `help:"Network address to listen on." placeholder:"HOST[:PORT]" default:"localhost:0"`
AccessLog bool `help:"Log all HTTP requests."`
TLSKeyFile string `help:"Path to TLS private key file for the UI server."`
TLSCertFile string `help:"Path to TLS certificate chain file for the UI server."`
}

type PublishArgs struct {
Expand Down
5 changes: 1 addition & 4 deletions internal/cli_types/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (

"github.com/rstudio/connect-client/internal/accounts"
"github.com/rstudio/connect-client/internal/logging"
"github.com/rstudio/connect-client/internal/services"
"github.com/rstudio/connect-client/internal/util/utiltest"
"github.com/stretchr/testify/suite"
)
Expand All @@ -22,13 +21,11 @@ func TestCLIContextSuite(t *testing.T) {

func (s *CLIContextSuite) TestNewCLIContext() {
accountList := &accounts.MockAccountList{}
token := services.LocalToken("abc123")
fs := utiltest.NewMockFs()
log := logging.New()

ctx := NewCLIContext(accountList, token, fs, log)
ctx := NewCLIContext(accountList, fs, log)
s.Equal(accountList, ctx.Accounts)
s.Equal(token, ctx.LocalToken)
s.Equal(log, ctx.Logger)
accountList.AssertNotCalled(s.T(), "GetAllAccounts")
}
26 changes: 2 additions & 24 deletions internal/services/api/http_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (

"github.com/rstudio/connect-client/internal/logging"
"github.com/rstudio/connect-client/internal/project"
"github.com/rstudio/connect-client/internal/services"
"github.com/rstudio/connect-client/internal/services/middleware"
"github.com/rstudio/connect-client/internal/state"

Expand All @@ -28,8 +27,6 @@ type Service struct {
certFile string
openBrowser bool
openBrowserAt string
skipAuth bool
token services.LocalToken
addr net.Addr
log logging.Logger
}
Expand All @@ -45,19 +42,9 @@ func NewService(
certFile string,
openBrowser bool,
openBrowserAt string,
skipAuth bool,
accessLog bool,
token services.LocalToken,
log logging.Logger) *Service {

if project.DevelopmentBuild() && skipAuth {
log.Warn("Service is operating in DEVELOPMENT MODE with NO browser to server authentication")
} else {
handler = middleware.AuthRequired(log, handler)
handler = middleware.CookieSession(log, handler)
handler = middleware.LocalTokenSession(token, log, handler)
}

if accessLog {
handler = middleware.LogRequest("Access Log", log, handler)
}
Expand All @@ -72,8 +59,6 @@ func NewService(
certFile: certFile,
openBrowser: openBrowser,
openBrowserAt: openBrowserAt,
skipAuth: skipAuth,
token: token,
addr: nil,
log: log,
}
Expand All @@ -90,7 +75,7 @@ func (svc *Service) isTLS() (bool, error) {
}
}

func (svc *Service) getURL(includeToken bool) *url.URL {
func (svc *Service) getURL() *url.URL {
scheme := "http"
isTLS, _ := svc.isTLS()
if isTLS {
Expand All @@ -103,11 +88,6 @@ func (svc *Service) getURL(includeToken bool) *url.URL {
Path: path,
Fragment: fragment,
}
if includeToken {
appURL.RawQuery = url.Values{
"token": []string{string(svc.token)},
}.Encode()
}
return appURL
}

Expand All @@ -124,9 +104,7 @@ func (svc *Service) Run() error {
}

svc.addr = listener.Addr()

// If not development mode, then you get a token added to the URL
appURL := svc.getURL(!(project.DevelopmentBuild() && svc.skipAuth))
appURL := svc.getURL()

svc.log.Info("UI server running", "url", appURL.String())
fmt.Println(appURL.String())
Expand Down
17 changes: 0 additions & 17 deletions internal/services/local_token.go

This file was deleted.

26 changes: 0 additions & 26 deletions internal/services/local_token_test.go

This file was deleted.

35 changes: 0 additions & 35 deletions internal/services/middleware/auth_required.go

This file was deleted.

52 changes: 0 additions & 52 deletions internal/services/middleware/cookie_auth.go

This file was deleted.

Loading