Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ Dockerfile
/rocketpool/rocketpool-daemon-linux-arm64
.vscode-ctags
build/
*api-token
28 changes: 28 additions & 0 deletions rocketpool-cli/cli/prompt/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import (
"regexp"
"strconv"
"strings"
"syscall"

"golang.org/x/term"

"github.com/rocket-pool/smartnode/rocketpool-cli/cli/color"
)
Expand All @@ -32,6 +35,31 @@ func Prompt(initialPrompt string, expectedFormat string, incorrectFormatPrompt s

}

// PromptPassword reads a password from the terminal without echoing it.
func PromptPassword(initialPrompt string, expectedFormat string, incorrectFormatPrompt string) string {
fmt.Println(initialPrompt)

var input string
var init bool
for !init || !regexp.MustCompile(expectedFormat).MatchString(input) {
if init {
fmt.Println("")
fmt.Println(incorrectFormatPrompt)
} else {
init = true
}

if bytes, err := term.ReadPassword(syscall.Stdin); err != nil {
fmt.Println(fmt.Errorf("Could not read password: %w", err))
} else {
input = string(bytes)
}
}
fmt.Println("")

return input
}

// Prompt for confirmation
func Confirm(fmtStr string, args ...any) bool {
initialPrompt := fmt.Sprintf(fmtStr, args...)
Expand Down
45 changes: 0 additions & 45 deletions rocketpool-cli/cli/prompt/prompt_unix.go

This file was deleted.

8 changes: 0 additions & 8 deletions rocketpool-cli/cli/prompt/prompt_windows.go

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
//go:build !windows

package term

import (
Expand Down
15 changes: 0 additions & 15 deletions rocketpool-cli/cli/term/term_windows.go

This file was deleted.

71 changes: 71 additions & 0 deletions rocketpool-cli/service/config/settings-api.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package config

import (
"github.com/rocket-pool/smartnode/shared/services/config"
)

// The page wrapper for the API config
type ApiConfigPage struct {
mainDisplay *MainDisplay
homePage *page
page *page
layout *standardLayout
masterConfig *config.RocketPoolConfig
}

func NewApiConfigPage(home *settingsHome) *ApiConfigPage {
configPage := &ApiConfigPage{
mainDisplay: home.md,
homePage: home.homePage,
masterConfig: home.md.Config,
}
configPage.createContent()
configPage.initPage(false)
return configPage
}

func NewApiConfigPageForNative(home *settingsNativeHome) *ApiConfigPage {
configPage := &ApiConfigPage{
mainDisplay: home.md,
homePage: home.homePage,
masterConfig: home.md.Config,
}
configPage.createContent()
configPage.initPage(true)
return configPage
}

func (configPage *ApiConfigPage) initPage(isNative bool) {
id := "settings-api"
if isNative {
id = "settings-api-native"
}
configPage.page = newPage(
configPage.homePage,
id,
"API",
"Select this to configure the Smart Node HTTP API, including the listen port, how it is exposed, the bearer token, and the request rate limit.",
configPage.layout.grid,
)
}

func (configPage *ApiConfigPage) getPage() *page {
return configPage.page
}

func (configPage *ApiConfigPage) createContent() {
configPage.layout = newStandardLayout()
configPage.layout.createForm(&configPage.masterConfig.Smartnode.Network, "API Settings")
configPage.layout.setupEscapeReturnHomeHandler(configPage.mainDisplay, configPage.homePage)

_ = configPage.masterConfig.SyncAPITokenFromDisk(true)

items := createParameterizedFormItems(configPage.masterConfig.Api.GetParameters(), configPage.layout)
configPage.layout.mapParameterizedFormItems(items...)
configPage.layout.addFormItems(items)
configPage.layout.refresh()
}

func (configPage *ApiConfigPage) handleLayoutChanged() {
configPage.layout.refresh()
}
7 changes: 7 additions & 0 deletions rocketpool-cli/service/config/settings-home.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type settingsHome struct {
saveButton *tview.Button
wizardButton *tview.Button
smartnodePage *SmartnodeConfigPage
apiPage *ApiConfigPage
ecPage *ExecutionConfigPage
fallbackPage *FallbackConfigPage
ccPage *ConsensusConfigPage
Expand Down Expand Up @@ -42,6 +43,7 @@ func newSettingsHome(md *MainDisplay) *settingsHome {

// Create the settings subpages
home.smartnodePage = NewSmartnodeConfigPage(home)
home.apiPage = NewApiConfigPage(home)
home.ecPage = NewExecutionConfigPage(home)
home.ccPage = NewConsensusConfigPage(home)
home.fallbackPage = NewFallbackConfigPage(home)
Expand All @@ -52,6 +54,7 @@ func newSettingsHome(md *MainDisplay) *settingsHome {
home.addonsPage = NewAddonsPage(home)
settingsSubpages := []settingsPage{
home.smartnodePage,
home.apiPage,
home.ecPage,
home.ccPage,
home.fallbackPage,
Expand Down Expand Up @@ -223,6 +226,10 @@ func (home *settingsHome) refresh() {
home.smartnodePage.layout.refresh()
}*/

if home.apiPage != nil {
home.apiPage.handleLayoutChanged()
}

if home.ecPage != nil {
home.ecPage.layout.refresh()
}
Expand Down
7 changes: 7 additions & 0 deletions rocketpool-cli/service/config/settings-native-home.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type settingsNativeHome struct {
saveButton *tview.Button
wizardButton *tview.Button
smartnodePage *NativeSmartnodeConfigPage
apiPage *ApiConfigPage
nativePage *NativePage
fallbackPage *NativeFallbackConfigPage
metricsPage *NativeMetricsConfigPage
Expand All @@ -38,12 +39,14 @@ func newSettingsNativeHome(md *MainDisplay) *settingsNativeHome {

// Create the settings subpages
home.smartnodePage = NewNativeSmartnodeConfigPage(home)
home.apiPage = NewApiConfigPageForNative(home)
home.nativePage = NewNativePage(home)
home.fallbackPage = NewNativeFallbackConfigPage(home)
home.metricsPage = NewNativeMetricsConfigPage(home)
home.alertingPage = NewAlertingConfigPageForNative(home)
settingsSubpages := []*page{
home.smartnodePage.page,
home.apiPage.page,
home.nativePage.page,
home.fallbackPage.page,
home.metricsPage.page,
Expand Down Expand Up @@ -210,6 +213,10 @@ func (home *settingsNativeHome) refresh() {
home.smartnodePage.layout.refresh()
}*/

if home.apiPage != nil {
home.apiPage.handleLayoutChanged()
}

if home.nativePage != nil {
home.nativePage.layout.refresh()
}
Expand Down
7 changes: 7 additions & 0 deletions rocketpool-cli/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,13 @@ func configureService(configPath string, isNative, yes bool, composeFiles []stri
return err
}

// Native vs Docker is stored in user-settings.yml. The --daemon-path flag is
// the historical CLI hint, but a native install opened without -d must not
// take the Docker restart path (e.g. rocketpool3_node).
if cfg != nil && cfg.IsNativeMode {
isNative = true
}

isUpdate := !isNew && oldCfg != nil

app := tview.NewApplication()
Expand Down
16 changes: 16 additions & 0 deletions rocketpool/api/response/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ type NotFoundError struct{ Path string }

func (e *NotFoundError) Error() string { return fmt.Sprintf("not found: %s", e.Path) }

// UnauthorizedError signals that the caller did not supply a valid API token.
type UnauthorizedError struct{}

func (e *UnauthorizedError) Error() string { return "unauthorized" }

// TooManyRequestsError signals that the caller exceeded the API rate limit.
type TooManyRequestsError struct{}

func (e *TooManyRequestsError) Error() string { return "too many requests" }

// WriteResponse serialises response as JSON and writes it to w.
// response must be a pointer to a struct with string fields named Status and Error.
// On error it writes 400 for BadRequestError and 500 for everything else.
Expand Down Expand Up @@ -66,9 +76,15 @@ func WriteResponse(w http.ResponseWriter, response interface{}, responseError er
if ef.String() != "" {
var br *BadRequestError
var nf *NotFoundError
var unauth *UnauthorizedError
var tooMany *TooManyRequestsError
switch {
case errors.As(responseError, &br):
statusCode = http.StatusBadRequest
case errors.As(responseError, &unauth):
statusCode = http.StatusUnauthorized
case errors.As(responseError, &tooMany):
statusCode = http.StatusTooManyRequests
case errors.As(responseError, &nf):
statusCode = http.StatusNotFound
default:
Expand Down
Loading
Loading