From 344bad01df5b27d023b5aa8f849e79588362b616 Mon Sep 17 00:00:00 2001 From: Bill Sager Date: Wed, 29 Jan 2025 14:41:58 -0800 Subject: [PATCH 1/5] remove deprecated CLI commands no longer needed --- cmd/publisher/commands/accounts.go | 79 ------------- cmd/publisher/commands/credentials.go | 111 ------------------ cmd/publisher/commands/deploy.go | 78 ------------ cmd/publisher/commands/init.go | 72 ------------ cmd/publisher/commands/redeploy.go | 63 ---------- cmd/publisher/commands/requirements.go | 8 -- cmd/publisher/commands/requirements_create.go | 65 ---------- cmd/publisher/commands/requirements_show.go | 40 ------- cmd/publisher/main.go | 10 +- 9 files changed, 2 insertions(+), 524 deletions(-) delete mode 100644 cmd/publisher/commands/accounts.go delete mode 100644 cmd/publisher/commands/credentials.go delete mode 100644 cmd/publisher/commands/deploy.go delete mode 100644 cmd/publisher/commands/init.go delete mode 100644 cmd/publisher/commands/redeploy.go delete mode 100644 cmd/publisher/commands/requirements.go delete mode 100644 cmd/publisher/commands/requirements_create.go delete mode 100644 cmd/publisher/commands/requirements_show.go diff --git a/cmd/publisher/commands/accounts.go b/cmd/publisher/commands/accounts.go deleted file mode 100644 index 52b3ef471..000000000 --- a/cmd/publisher/commands/accounts.go +++ /dev/null @@ -1,79 +0,0 @@ -package commands - -// Copyright (C) 2023 by Posit Software, PBC. - -import ( - "fmt" - "time" - - "github.com/posit-dev/publisher/internal/accounts" - "github.com/posit-dev/publisher/internal/cli_types" - "github.com/posit-dev/publisher/internal/clients/connect" - "github.com/posit-dev/publisher/internal/events" -) - -type testAccountCmd struct { - AccountName string `kong:"arg,required" help:"Nickname of the account to test."` -} - -func (cmd *testAccountCmd) Run(args *cli_types.CommonArgs, ctx *cli_types.CLIContext) error { - account, err := ctx.Accounts.GetAccountByName(cmd.AccountName) - if err != nil { - return err - } - // TODO: create and call a generic factory to make a new client for any account - client, err := connect.NewConnectClient(account, 30*time.Second, events.NewNullEmitter(), ctx.Logger) - if err != nil { - return err - } - user, err := client.TestAuthentication(ctx.Logger) - if err != nil { - return err - } - if user.FirstName != "" || user.LastName != "" { - fmt.Printf("Name: %s %s\n", user.FirstName, user.LastName) - } - if user.Username != "" { - fmt.Printf("Username: %s\n", user.Username) - } - if user.Id != "" { - fmt.Printf("ID: %s\n", user.Id) - } - if user.Email != "" { - fmt.Printf("Email: %s\n", user.Email) - } - return nil -} - -type listAccountsCmd struct{} - -func (cmd *listAccountsCmd) Run(args *cli_types.CommonArgs, ctx *cli_types.CLIContext) error { - accounts, err := ctx.Accounts.GetAccountsByServerType(accounts.ServerTypeConnect) - if err != nil { - return err - } - if len(accounts) == 0 { - fmt.Println("No accounts found. Use rsconnect or rsconnect-python to register an account.") - } else { - fmt.Println() - for _, account := range accounts { - fmt.Printf("Nickname: \"%s\"\n", account.Name) - fmt.Printf(" Server URL: %s\n", account.URL) - fmt.Printf(" Configured via: %s\n", account.Source.Description()) - fmt.Printf(" Authentication: %s\n", account.AuthType.Description()) - if account.Insecure { - fmt.Println(" Insecure mode (TLS host/certificate validation disabled)") - } - if account.Certificate != "" { - fmt.Println(" Client TLS certificate data provided") - } - fmt.Println() - } - } - return nil -} - -type AccountCommands struct { - ListAccounts listAccountsCmd `kong:"cmd" help:"List publishing accounts."` - TestAccount testAccountCmd `kong:"cmd" help:"Verify connectivity and credentials for a publishing account."` -} diff --git a/cmd/publisher/commands/credentials.go b/cmd/publisher/commands/credentials.go deleted file mode 100644 index 14e1f676a..000000000 --- a/cmd/publisher/commands/credentials.go +++ /dev/null @@ -1,111 +0,0 @@ -// Copyright (C) 2024 by Posit Software, PBC. - -package commands - -import ( - "encoding/json" - "fmt" - - "github.com/posit-dev/publisher/internal/cli_types" - "github.com/posit-dev/publisher/internal/credentials" - "github.com/posit-dev/publisher/internal/logging" -) - -type CredentialsCommand struct { - Create CreateCredentialCommand `kong:"cmd" help:"Create a credential"` - Delete DeleteCredentialCommand `kong:"cmd" help:"Delete a credential"` - Get GetCredentialCommand `kong:"cmd" help:"Get a credential"` - List ListCredentialsCommand `kong:"cmd" help:"List credentials"` -} - -type CreateCredentialCommand struct { - Name string `kong:"arg,required,help='Credential nickname'"` - URL string `kong:"arg,required,help='Server URL'"` - ApiKey string `kong:"arg,required,help='Server API Key'"` -} - -func (cmd *CreateCredentialCommand) Run(args *cli_types.CommonArgs, ctx *cli_types.CLIContext) error { - cs, err := credentials.NewCredentialsService(logging.NewDiscardLogger()) - if err != nil { - return err - } - - cred, err := cs.Set(cmd.Name, cmd.URL, cmd.ApiKey) - if err != nil { - return err - } - - body, err := json.MarshalIndent(cred, "", "\t") - if err != nil { - return err - } - - fmt.Println(string(body)) - return nil -} - -type DeleteCredentialCommand struct { - GUID string `kong:"arg,required,help='Credential identifier'"` -} - -func (cmd *DeleteCredentialCommand) Run(args *cli_types.CommonArgs, ctx *cli_types.CLIContext) error { - cs, err := credentials.NewCredentialsService(logging.NewDiscardLogger()) - if err != nil { - return err - } - - err = cs.Delete(cmd.GUID) - if err != nil { - return err - } - - fmt.Println("ok") - return nil -} - -type GetCredentialCommand struct { - GUID string `kong:"arg,required,help='Credential identifier'"` -} - -func (cmd *GetCredentialCommand) Run(args *cli_types.CommonArgs, ctx *cli_types.CLIContext) error { - cs, err := credentials.NewCredentialsService(logging.NewDiscardLogger()) - if err != nil { - return err - } - - cred, err := cs.Get(cmd.GUID) - if err != nil { - return err - } - - body, err := json.MarshalIndent(cred, "", "\t") - if err != nil { - return err - } - - fmt.Println(string(body)) - return nil -} - -type ListCredentialsCommand struct { -} - -func (cmd *ListCredentialsCommand) Run(args *cli_types.CommonArgs, ctx *cli_types.CLIContext) error { - cs, err := credentials.NewCredentialsService(logging.NewDiscardLogger()) - if err != nil { - return err - } - - creds, err := cs.List() - if err != nil { - return err - } - - body, err := json.MarshalIndent(creds, "", "\t") - if err != nil { - return err - } - - fmt.Println(string(body)) - return nil -} diff --git a/cmd/publisher/commands/deploy.go b/cmd/publisher/commands/deploy.go deleted file mode 100644 index 6bd2bef84..000000000 --- a/cmd/publisher/commands/deploy.go +++ /dev/null @@ -1,78 +0,0 @@ -package commands - -// Copyright (C) 2023 by Posit Software, PBC. - -import ( - "fmt" - "os" - - "github.com/posit-dev/publisher/internal/accounts" - "github.com/posit-dev/publisher/internal/cli_types" - "github.com/posit-dev/publisher/internal/config" - "github.com/posit-dev/publisher/internal/deployment" - "github.com/posit-dev/publisher/internal/events" - "github.com/posit-dev/publisher/internal/initialize" - "github.com/posit-dev/publisher/internal/publish" - "github.com/posit-dev/publisher/internal/state" - "github.com/posit-dev/publisher/internal/util" -) - -type DeployCmd struct { - Path util.Path `help:"Path to project directory containing files to publish." arg:"" default:"."` - AccountName string `name:"account" short:"a" help:"Nickname of the publishing account to use (run list-accounts to see them)."` - ConfigName string `name:"config" short:"c" help:"Configuration name (in .posit/publish/)"` - SaveName string `name:"name" short:"n" help:"Save deployment with this name (in .posit/deployments/)"` - Account *accounts.Account `kong:"-"` - Config *config.Config `kong:"-"` - // NOTE: Currently hardcoded to insecure = false. No CLI param added for now. -} - -func (cmd *DeployCmd) Run(args *cli_types.CommonArgs, ctx *cli_types.CLIContext) error { - absPath, err := cmd.Path.Abs() - if err != nil { - return err - } - - ctx.Logger = events.NewCLILogger(args.Verbose, os.Stderr) - - if cmd.SaveName != "" { - err = util.ValidateFilename(cmd.SaveName) - if err != nil { - return err - } - exists, err := deployment.GetDeploymentPath(absPath, cmd.SaveName).Exists() - if err != nil { - return err - } - if exists { - return fmt.Errorf("there is already a deployment named '%s'; did you mean to use the 'redeploy' command?", cmd.SaveName) - } - } else { - cmd.SaveName, err = deployment.UntitledDeploymentName(absPath) - if err != nil { - return err - } - } - i := initialize.NewDefaultInitialize() - err = i.InitIfNeeded(absPath, cmd.ConfigName, ctx.Logger) - if err != nil { - return err - } - stateStore, err := state.New(absPath, cmd.AccountName, cmd.ConfigName, "", cmd.SaveName, ctx.Accounts, nil, false) - if err != nil { - return err - } - fmt.Printf("Deploy to server %s using account %s and configuration %s, creating deployment %s\n", - stateStore.Account.URL, - stateStore.Account.Name, - stateStore.ConfigName, - stateStore.SaveName) - - rExecutable := util.Path{} - pythonExecutable := util.Path{} - publisher, err := publish.NewFromState(stateStore, rExecutable, pythonExecutable, events.NewCliEmitter(os.Stderr, ctx.Logger), ctx.Logger) - if err != nil { - return err - } - return publisher.PublishDirectory() -} diff --git a/cmd/publisher/commands/init.go b/cmd/publisher/commands/init.go deleted file mode 100644 index 13a747c1c..000000000 --- a/cmd/publisher/commands/init.go +++ /dev/null @@ -1,72 +0,0 @@ -package commands - -// Copyright (C) 2023 by Posit Software, PBC. - -import ( - "fmt" - "os" - "strings" - - "github.com/posit-dev/publisher/internal/cli_types" - "github.com/posit-dev/publisher/internal/config" - "github.com/posit-dev/publisher/internal/initialize" - "github.com/posit-dev/publisher/internal/util" -) - -type InitCommand struct { - Path util.Path `help:"Path to project directory containing files to publish." arg:"" default:"."` - Python util.Path `help:"Path to Python interpreter for this content, if it is Python-based. Default is the Python 3 on your PATH."` - R util.Path `help:"Path to R interpreter for this content, if it is R-based. Default is the R on your PATH."` - ConfigName string `name:"config" short:"c" help:"Configuration name to create (in .posit/publish/)"` -} - -const contentTypeDetectionFailed = "Could not determine content type and entrypoint.\n\n" + - "Edit the configuration file (%s) \n" + - "and set the 'type' to a valid deployment type. Valid types are: \n%s\n\n" + - "Set 'entrypoint' to the main file being deployed. For apps and APIs\n" + - "this is usually app.py, api.py, app.R, or plumber.R; for reports,\n" + - "it is your .qmd, .Rmd, or .ipynb file.\n" - -func formatValidTypes() string { - t := config.AllValidContentTypeNames() - const perLine = 3 - result := "" - for i := 0; i < len(t); i += perLine { - var line []string - if i+perLine >= len(t) { - line = t[i:] - } else { - line = t[i : i+perLine] - } - result += " " + strings.Join(line, ", ") + "\n" - } - return result -} - -func (cmd *InitCommand) Run(args *cli_types.CommonArgs, ctx *cli_types.CLIContext) error { - absPath, err := cmd.Path.Abs() - if err != nil { - return err - } - - if cmd.ConfigName == "" { - cmd.ConfigName = config.DefaultConfigName - } - i := initialize.NewDefaultInitialize() - cfg, err := i.Init(absPath, cmd.ConfigName, cmd.Python, cmd.R, ctx.Logger) - if err != nil { - return err - } - configPath := config.GetConfigPath(absPath, cmd.ConfigName) - if cfg.Type == config.ContentTypeUnknown { - fmt.Printf(contentTypeDetectionFailed, configPath, formatValidTypes()) - return nil - } else { - fmt.Printf("Created config file '%s'\n", configPath.String()) - if args.Verbose >= 2 { - fmt.Println() - cfg.Write(os.Stdout) - } - } - return nil -} diff --git a/cmd/publisher/commands/redeploy.go b/cmd/publisher/commands/redeploy.go deleted file mode 100644 index 4fa1d368e..000000000 --- a/cmd/publisher/commands/redeploy.go +++ /dev/null @@ -1,63 +0,0 @@ -package commands - -// Copyright (C) 2023 by Posit Software, PBC. - -import ( - "fmt" - "os" - "strings" - - "github.com/posit-dev/publisher/internal/cli_types" - "github.com/posit-dev/publisher/internal/config" - "github.com/posit-dev/publisher/internal/deployment" - "github.com/posit-dev/publisher/internal/events" - "github.com/posit-dev/publisher/internal/initialize" - "github.com/posit-dev/publisher/internal/publish" - "github.com/posit-dev/publisher/internal/state" - "github.com/posit-dev/publisher/internal/util" -) - -type RedeployCmd struct { - TargetName string `name:"deployment-name" arg:"" help:"Name of deployment to update (in .posit/deployments/)"` - Path util.Path `help:"Path to project directory containing files to publish." arg:"" default:"."` - ConfigName string `name:"config" short:"c" help:"Configuration name (in .posit/publish/)"` - Config *config.Config `kong:"-"` - Target *deployment.Deployment `kong:"-"` - // NOTE: Currently hardcoded to insecure = false. No CLI param added for now. -} - -func (cmd *RedeployCmd) Run(args *cli_types.CommonArgs, ctx *cli_types.CLIContext) error { - absPath, err := cmd.Path.Abs() - if err != nil { - return err - } - ctx.Logger = events.NewCLILogger(args.Verbose, os.Stderr) - - i := initialize.NewDefaultInitialize() - err = i.InitIfNeeded(absPath, cmd.ConfigName, ctx.Logger) - if err != nil { - return err - } - cmd.TargetName = strings.TrimSuffix(cmd.TargetName, ".toml") - err = util.ValidateFilename(cmd.TargetName) - if err != nil { - return fmt.Errorf("invalid deployment name '%s': %w", cmd.TargetName, err) - } - stateStore, err := state.New(absPath, "", cmd.ConfigName, cmd.TargetName, "", ctx.Accounts, nil, false) - if err != nil { - return err - } - fmt.Printf("Redeploy %s to server %s using account %s and configuration %s\n", - stateStore.TargetName, - stateStore.Account.URL, - stateStore.Account.Name, - stateStore.ConfigName) - - rExecutable := util.Path{} - pythonExecutable := util.Path{} - publisher, err := publish.NewFromState(stateStore, rExecutable, pythonExecutable, events.NewCliEmitter(os.Stderr, ctx.Logger), ctx.Logger) - if err != nil { - return err - } - return publisher.PublishDirectory() -} diff --git a/cmd/publisher/commands/requirements.go b/cmd/publisher/commands/requirements.go deleted file mode 100644 index c12c37ce7..000000000 --- a/cmd/publisher/commands/requirements.go +++ /dev/null @@ -1,8 +0,0 @@ -package commands - -// Copyright (C) 2023 by Posit Software, PBC. - -type RequirementsCommands struct { - Create CreateRequirementsCommand `kong:"cmd" help:"Create a requirements.txt file from your project's dependencies and a Python installation containing the packages."` - Show ShowRequirementsCommand `kong:"cmd" help:"Show your project's dependencies."` -} diff --git a/cmd/publisher/commands/requirements_create.go b/cmd/publisher/commands/requirements_create.go deleted file mode 100644 index e5160e657..000000000 --- a/cmd/publisher/commands/requirements_create.go +++ /dev/null @@ -1,65 +0,0 @@ -package commands - -// Copyright (C) 2023 by Posit Software, PBC. - -import ( - "errors" - "fmt" - "os" - - "github.com/posit-dev/publisher/internal/cli_types" - "github.com/posit-dev/publisher/internal/inspect" - "github.com/posit-dev/publisher/internal/inspect/dependencies/pydeps" - "github.com/posit-dev/publisher/internal/util" -) - -type CreateRequirementsCommand struct { - Path util.Path `help:"Path to project directory containing files to publish." arg:"" default:"."` - Python util.Path `help:"Path to Python interpreter for this content, if it is Python-based. Default is the Python 3 on your PATH."` - Output string `short:"o" help:"Name of output file." default:"requirements.txt"` - Force bool `short:"f" help:"Overwrite the output file, if it exists."` -} - -var errRequirementsFileExists = errors.New("the requirements file already exists; use the -f option to overwrite it") - -func (cmd *CreateRequirementsCommand) Run(args *cli_types.CommonArgs, ctx *cli_types.CLIContext) error { - absPath, err := cmd.Path.Abs() - if err != nil { - return err - } - reqPath := absPath.Join(cmd.Output) - exists, err := reqPath.Exists() - if err != nil { - return err - } - if exists && !cmd.Force { - return errRequirementsFileExists - } - inspector, _ := inspect.NewPythonInspector(absPath, cmd.Python, ctx.Logger, nil, nil) - reqs, incomplete, pythonExecutable, err := inspector.ScanRequirements(absPath) - if err != nil { - return err - } - err = pydeps.WriteRequirementsFile(reqPath, reqs, util.NewAbsolutePath("bogus python executable", nil)) - if err != nil { - return err - } - fmt.Fprintf(os.Stderr, "Wrote file %s:\n", cmd.Output) - fmt.Println("Using package information from", pythonExecutable) - if len(incomplete) > 0 { - fmt.Println("Warning: could not find some package versions in your local Python library.") - fmt.Println("Consider installing these packages and re-running.") - for _, pkg := range incomplete { - fmt.Println(pkg) - } - } - content, err := reqPath.ReadFile() - if err != nil { - return err - } - _, err = os.Stdout.Write(content) - if err != nil { - return err - } - return nil -} diff --git a/cmd/publisher/commands/requirements_show.go b/cmd/publisher/commands/requirements_show.go deleted file mode 100644 index 89b070df2..000000000 --- a/cmd/publisher/commands/requirements_show.go +++ /dev/null @@ -1,40 +0,0 @@ -package commands - -// Copyright (C) 2023 by Posit Software, PBC. - -import ( - "fmt" - "strings" - - "github.com/posit-dev/publisher/internal/cli_types" - "github.com/posit-dev/publisher/internal/inspect" - "github.com/posit-dev/publisher/internal/util" -) - -type ShowRequirementsCommand struct { - Path util.Path `help:"Path to project directory containing files to publish." arg:"" default:"."` - Python util.Path `help:"Path to Python interpreter for this content, if it is Python-based. Default is the Python 3 on your PATH."` -} - -func (cmd *ShowRequirementsCommand) Run(args *cli_types.CommonArgs, ctx *cli_types.CLIContext) error { - absPath, err := cmd.Path.Abs() - if err != nil { - return err - } - inspector, _ := inspect.NewPythonInspector(absPath, cmd.Python, ctx.Logger, nil, nil) - reqs, incomplete, pythonExecutable, err := inspector.ScanRequirements(absPath) - if err != nil { - return err - } - if len(incomplete) > 0 { - fmt.Println("# Warning: could not find some package versions in your local Python library.") - fmt.Println("# Consider installing these packages and re-running.") - for _, pkg := range incomplete { - fmt.Println("#", pkg) - } - } - fmt.Println("# Project dependencies for", absPath) - fmt.Println("# Using package information from", pythonExecutable) - fmt.Println(strings.Join(reqs, "\n")) - return nil -} diff --git a/cmd/publisher/main.go b/cmd/publisher/main.go index 802e3dd9c..c8a553e44 100644 --- a/cmd/publisher/main.go +++ b/cmd/publisher/main.go @@ -20,14 +20,8 @@ import ( type cliSpec struct { cli_types.CommonArgs - - Credentials commands.CredentialsCommand `kong:"cmd" help:"Manage credentials."` - Deploy commands.DeployCmd `kong:"cmd" help:"Create a new deployment."` - Init commands.InitCommand `kong:"cmd" help:"Create a configuration file based on the contents of the project directory."` - Redeploy commands.RedeployCmd `kong:"cmd" help:"Update an existing deployment."` - Requirements commands.RequirementsCommands `kong:"cmd" help:"Create a Python requirements.txt file."` - UI commands.UICmd `kong:"cmd" help:"Serve the publisher UI."` - Version commands.VersionCmd `kong:"cmd" help:"Show the client software version and exit."` + UI commands.UICmd `kong:"cmd" help:"Serve the publisher UI."` + Version commands.VersionCmd `kong:"cmd" help:"Show the client software version and exit."` } func logVersion(log logging.Logger) { From 71063976e381467041301cdee9d1ad237de834ea Mon Sep 17 00:00:00 2001 From: Bill Sager Date: Wed, 29 Jan 2025 15:14:32 -0800 Subject: [PATCH 2/5] Reduce UI commands down to only what is used by VSCode extension --- cmd/publisher/commands/ui.go | 21 +++---- internal/services/api/api_service.go | 18 +++--- internal/services/api/http_service.go | 79 ++++++++------------------- 3 files changed, 40 insertions(+), 78 deletions(-) diff --git a/cmd/publisher/commands/ui.go b/cmd/publisher/commands/ui.go index a8dffc6b3..2ed3cda32 100644 --- a/cmd/publisher/commands/ui.go +++ b/cmd/publisher/commands/ui.go @@ -11,13 +11,7 @@ import ( ) type UICmd struct { - Path util.Path `help:"Path to project directory containing files to publish." arg:"" default:"."` - Interactive bool `short:"i" help:"Launch a browser to show the UI."` - OpenBrowserAt string `help:"Network address to use when launching the browser." 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"` - 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."` + Listen string `help:"Network address to listen on." placeholder:"HOST[:PORT]" default:"localhost:0"` } func (cmd *UICmd) Run(args *cli_types.CommonArgs, ctx *cli_types.CLIContext) error { @@ -31,7 +25,8 @@ func (cmd *UICmd) Run(args *cli_types.CommonArgs, ctx *cli_types.CLIContext) err log := events.NewLoggerWithSSE(args.Verbose, emitter) ctx.Logger.Info("created SSE logger") - absPath, err := cmd.Path.Abs() + path := util.NewPath(".", nil) + absPath, err := path.Abs() if err != nil { return err } @@ -40,13 +35,13 @@ func (cmd *UICmd) Run(args *cli_types.CommonArgs, ctx *cli_types.CLIContext) err // for better error handling and startup performance. svc := api.NewService( "/", - cmd.Interactive, - cmd.OpenBrowserAt, - cmd.Theme, + // cmd.Interactive, + // cmd.OpenBrowserAt, + // cmd.Theme, cmd.Listen, true, - cmd.TLSKeyFile, - cmd.TLSCertFile, + // cmd.TLSKeyFile, + // cmd.TLSCertFile, absPath, ctx.Accounts, log, diff --git a/internal/services/api/api_service.go b/internal/services/api/api_service.go index a7cbe961d..838c610cd 100644 --- a/internal/services/api/api_service.go +++ b/internal/services/api/api_service.go @@ -23,13 +23,13 @@ const APIPrefix string = "api" func NewService( fragment string, - interactive bool, - openBrowserAt string, - theme string, + // interactive bool, + // openBrowserAt string, + // theme string, listen string, accessLog bool, - tlsKeyFile string, - tlsCertFile string, + // tlsKeyFile string, + // tlsCertFile string, dir util.AbsolutePath, lister accounts.AccountList, log logging.Logger, @@ -42,10 +42,10 @@ func NewService( handler, listen, fragment, - tlsKeyFile, - tlsCertFile, - interactive, - openBrowserAt, + // tlsKeyFile, + // tlsCertFile, + // interactive, + // openBrowserAt, accessLog, log, ) diff --git a/internal/services/api/http_service.go b/internal/services/api/http_service.go index 319fe115a..a53540eed 100644 --- a/internal/services/api/http_service.go +++ b/internal/services/api/http_service.go @@ -11,22 +11,19 @@ import ( "strings" "github.com/posit-dev/publisher/internal/logging" - "github.com/posit-dev/publisher/internal/project" "github.com/posit-dev/publisher/internal/services/middleware" - - "github.com/pkg/browser" ) type Service struct { - handler http.HandlerFunc - listen string - path string - keyFile string - certFile string - openBrowser bool - openBrowserAt string - addr net.Addr - log logging.Logger + handler http.HandlerFunc + listen string + path string + // keyFile string + // certFile string + // openBrowser bool + // openBrowserAt string + addr net.Addr + log logging.Logger } var errTlsRequiredFiles error = errors.New("TLS requires both a private key file and a certificate chain file") @@ -35,10 +32,10 @@ func newHTTPService( handler http.HandlerFunc, listen string, path string, - keyFile string, - certFile string, - openBrowser bool, - openBrowserAt string, + // keyFile string, + // certFile string, + // openBrowser bool, + // openBrowserAt string, accessLog bool, log logging.Logger) *Service { @@ -48,35 +45,20 @@ func newHTTPService( handler = middleware.PanicRecovery(log, handler) return &Service{ - handler: handler, - listen: listen, - path: path, - keyFile: keyFile, - certFile: certFile, - openBrowser: openBrowser, - openBrowserAt: openBrowserAt, - addr: nil, - log: log, - } -} - -func (svc *Service) isTLS() (bool, error) { - if svc.keyFile != "" && svc.certFile != "" { - return true, nil - } else if svc.keyFile != "" || svc.certFile != "" { - // It's an error to only provide one of the files - return false, errTlsRequiredFiles - } else { - return false, nil + handler: handler, + listen: listen, + path: path, + // keyFile: keyFile, + // certFile: certFile, + // openBrowser: openBrowser, + // openBrowserAt: openBrowserAt, + addr: nil, + log: log, } } func (svc *Service) getURL() *url.URL { scheme := "http" - isTLS, _ := svc.isTLS() - if isTLS { - scheme = "https" - } path, fragment, _ := strings.Cut(svc.path, "#") appURL := &url.URL{ Scheme: scheme, @@ -88,11 +70,6 @@ func (svc *Service) getURL() *url.URL { } func (svc *Service) Run() error { - isTLS, err := svc.isTLS() - if err != nil { - return err - } - // Open listener first so the browser can connect listener, err := net.Listen("tcp", svc.listen) if err != nil { @@ -105,17 +82,7 @@ func (svc *Service) Run() error { svc.log.Info("UI server running", "url", appURL.String()) fmt.Println(appURL.String()) - if project.DevelopmentBuild() && svc.openBrowserAt != "" { - browser.OpenURL(svc.openBrowserAt) - } else if svc.openBrowser { - browser.OpenURL(appURL.String()) - } - - if isTLS { - err = http.ServeTLS(listener, svc.handler, svc.certFile, svc.keyFile) - } else { - err = http.Serve(listener, svc.handler) - } + err = http.Serve(listener, svc.handler) if err != nil && err != http.ErrServerClosed { return fmt.Errorf("UI server error: %s", err) } From 751360698c936a38bad0fb40d78b7eeefb07eadd Mon Sep 17 00:00:00 2001 From: Bill Sager Date: Thu, 30 Jan 2025 16:53:14 -0800 Subject: [PATCH 3/5] remove comments --- cmd/publisher/commands/ui.go | 5 ----- internal/services/api/api_service.go | 9 --------- 2 files changed, 14 deletions(-) diff --git a/cmd/publisher/commands/ui.go b/cmd/publisher/commands/ui.go index 2ed3cda32..a7c5f9868 100644 --- a/cmd/publisher/commands/ui.go +++ b/cmd/publisher/commands/ui.go @@ -35,13 +35,8 @@ func (cmd *UICmd) Run(args *cli_types.CommonArgs, ctx *cli_types.CLIContext) err // for better error handling and startup performance. svc := api.NewService( "/", - // cmd.Interactive, - // cmd.OpenBrowserAt, - // cmd.Theme, cmd.Listen, true, - // cmd.TLSKeyFile, - // cmd.TLSCertFile, absPath, ctx.Accounts, log, diff --git a/internal/services/api/api_service.go b/internal/services/api/api_service.go index 838c610cd..86fd02af9 100644 --- a/internal/services/api/api_service.go +++ b/internal/services/api/api_service.go @@ -23,13 +23,8 @@ const APIPrefix string = "api" func NewService( fragment string, - // interactive bool, - // openBrowserAt string, - // theme string, listen string, accessLog bool, - // tlsKeyFile string, - // tlsCertFile string, dir util.AbsolutePath, lister accounts.AccountList, log logging.Logger, @@ -42,10 +37,6 @@ func NewService( handler, listen, fragment, - // tlsKeyFile, - // tlsCertFile, - // interactive, - // openBrowserAt, accessLog, log, ) From cc4a526a7b2b1796adcf551218fe3e4ace398423 Mon Sep 17 00:00:00 2001 From: Bill Sager Date: Thu, 30 Jan 2025 16:57:38 -0800 Subject: [PATCH 4/5] adding back path parameter per PR request --- cmd/publisher/commands/ui.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cmd/publisher/commands/ui.go b/cmd/publisher/commands/ui.go index a7c5f9868..129bb1d89 100644 --- a/cmd/publisher/commands/ui.go +++ b/cmd/publisher/commands/ui.go @@ -11,7 +11,8 @@ import ( ) type UICmd struct { - Listen string `help:"Network address to listen on." placeholder:"HOST[:PORT]" default:"localhost:0"` + Path util.Path `help:"Sets the current working directory for the agent." arg:"" default:"."` + Listen string `help:"Network address to listen on." placeholder:"HOST[:PORT]" default:"localhost:0"` } func (cmd *UICmd) Run(args *cli_types.CommonArgs, ctx *cli_types.CLIContext) error { @@ -25,8 +26,7 @@ func (cmd *UICmd) Run(args *cli_types.CommonArgs, ctx *cli_types.CLIContext) err log := events.NewLoggerWithSSE(args.Verbose, emitter) ctx.Logger.Info("created SSE logger") - path := util.NewPath(".", nil) - absPath, err := path.Abs() + absPath, err := cmd.Path.Abs() if err != nil { return err } From 145e23013cd9b979ebc548945dc2ae1b7536e597 Mon Sep 17 00:00:00 2001 From: Bill Sager Date: Fri, 31 Jan 2025 14:24:36 -0800 Subject: [PATCH 5/5] Remove temporary commented code and unused error message --- internal/services/api/http_service.go | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/internal/services/api/http_service.go b/internal/services/api/http_service.go index a53540eed..c0287a301 100644 --- a/internal/services/api/http_service.go +++ b/internal/services/api/http_service.go @@ -3,7 +3,6 @@ package api // Copyright (C) 2023 by Posit Software, PBC. import ( - "errors" "fmt" "net" "net/http" @@ -18,24 +17,14 @@ type Service struct { handler http.HandlerFunc listen string path string - // keyFile string - // certFile string - // openBrowser bool - // openBrowserAt string - addr net.Addr - log logging.Logger + addr net.Addr + log logging.Logger } -var errTlsRequiredFiles error = errors.New("TLS requires both a private key file and a certificate chain file") - func newHTTPService( handler http.HandlerFunc, listen string, path string, - // keyFile string, - // certFile string, - // openBrowser bool, - // openBrowserAt string, accessLog bool, log logging.Logger) *Service { @@ -48,12 +37,8 @@ func newHTTPService( handler: handler, listen: listen, path: path, - // keyFile: keyFile, - // certFile: certFile, - // openBrowser: openBrowser, - // openBrowserAt: openBrowserAt, - addr: nil, - log: log, + addr: nil, + log: log, } }