Skip to content

Commit

Permalink
Removes the --skip-browser-session-auth option
Browse files Browse the repository at this point in the history
  • Loading branch information
tdstein committed Nov 8, 2023
1 parent 4349c35 commit aba093d
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 36 deletions.
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
15 changes: 7 additions & 8 deletions internal/cli_types/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,13 @@ func NewCLIContext(accountList accounts.AccountList, token services.LocalToken,
}

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
22 changes: 2 additions & 20 deletions internal/services/api/http_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,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 +44,10 @@ 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,7 +62,6 @@ func NewService(
certFile: certFile,
openBrowser: openBrowser,
openBrowserAt: openBrowserAt,
skipAuth: skipAuth,
token: token,
addr: nil,
log: log,
Expand All @@ -90,7 +79,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 +92,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 +108,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
1 change: 0 additions & 1 deletion internal/services/ui/ui_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ func NewUIService(
ui.TLSCertFile,
ui.Interactive,
ui.OpenBrowserAt,
ui.SkipBrowserSessionAuth,
ui.AccessLog,
token,
log,
Expand Down
4 changes: 1 addition & 3 deletions test/cy/cypress/e2e/home.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ describe('Landing', () => {
beforeEach(() => {
cy.visit({
url: '/',
qs: { token: Cypress.env('token') }
});
});
it('.should() - assert that <title> is correct', () => {
Expand All @@ -13,8 +12,7 @@ describe('Landing', () => {
describe('Check Files', () => {
beforeEach(() => {
cy.visit({
url: '/',
qs: { token: Cypress.env('token') }
url: '/'
});
});
it('files should be listed', () => {
Expand Down
4 changes: 2 additions & 2 deletions test/cy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
"scripts": {
"lint": "eslint --ext .js,.ts,.cjs .",
"fix": "eslint --ext .js,.ts,.cjs . --fix",
"start": "just ../../run publish-ui --listen 127.0.0.1:9000 --token=token ./test/sample-content/fastapi-simple",
"start": "just ../../run publish-ui --listen 127.0.0.1:9000 ./test/sample-content/fastapi-simple",
"test": "start-server-and-test --expect 401 start http-get://127.0.0.1:9000 run",
"open": "cypress open",
"run": "cypress run --env token=token"
"run": "cypress run"
},
"devDependencies": {
"cypress": "^13.3.0",
Expand Down

0 comments on commit aba093d

Please sign in to comment.