Skip to content

Commit

Permalink
Validate stash-box endpoint pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
Infinite committed Dec 24, 2020
1 parent a33de18 commit 7761879
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 8 additions & 0 deletions pkg/manager/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"errors"
"io/ioutil"
"path/filepath"
"regexp"

"github.com/spf13/viper"

Expand Down Expand Up @@ -427,11 +428,18 @@ func ValidateCredentials(username string, password string) bool {
func ValidateStashBoxes(boxes []*models.StashBoxInput) error {
isMulti := len(boxes) > 1

re, err := regexp.Compile("^http.*graphql$")
if err != nil {
return errors.New("Failure to generate regular expression")
}

for _, box := range boxes {
if box.APIKey == "" {
return errors.New("Stash-box API Key cannot be blank")
} else if box.Endpoint == "" {
return errors.New("Stash-box Endpoint cannot be blank")
} else if !re.Match([]byte(box.Endpoint)) {
return errors.New("Stash-box Endpoint is invalid")
} else if isMulti && box.Name == "" {
return errors.New("Stash-box Name cannot be blank")
}
Expand Down
4 changes: 2 additions & 2 deletions ui/v2.5/src/components/Settings/StashBoxConfiguration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const Instance: React.FC<IInstanceProps> = ({
value={instance?.endpoint}
isValid={(instance?.endpoint?.length ?? 0) > 0}
onInput={(e: React.ChangeEvent<HTMLInputElement>) =>
handleInput("endpoint", e.currentTarget.value)
handleInput("endpoint", e.currentTarget.value.trim())
}
/>
<Form.Control
Expand All @@ -50,7 +50,7 @@ const Instance: React.FC<IInstanceProps> = ({
value={instance?.api_key}
isValid={(instance?.api_key?.length ?? 0) > 0}
onInput={(e: React.ChangeEvent<HTMLInputElement>) =>
handleInput("api_key", e.currentTarget.value)
handleInput("api_key", e.currentTarget.value.trim())
}
/>
<InputGroup.Append>
Expand Down

0 comments on commit 7761879

Please sign in to comment.