Skip to content

Commit

Permalink
🧹 return error when invalid host value is provided for atlassian prov…
Browse files Browse the repository at this point in the history
…ider (#4567)
  • Loading branch information
vjeffrey authored Aug 19, 2024
1 parent 4622bb2 commit 5672ec0
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions providers/atlassian/connection/jira/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package jira
import (
"context"
"errors"
"net/url"
"os"

v2 "github.com/ctreminiom/go-atlassian/jira/v2"
Expand All @@ -26,13 +27,18 @@ type JiraConnection struct {
name string
}

func isValidHostValue(val string) bool {
u, err := url.Parse(val)
return err == nil && u.Scheme != "" && u.Host != ""
}

func NewConnection(id uint32, asset *inventory.Asset, conf *inventory.Config) (*JiraConnection, error) {
host := conf.Options["host"]
if host == "" {
host = os.Getenv("ATLASSIAN_HOST")
}
if host == "" {
return nil, errors.New("you must provide an Atlassian host e.g. via ATLASSIAN_HOST env or via the --host flag")
if host == "" || !isValidHostValue(host) {
return nil, errors.New("you must provide an Atlassian host e.g. via ATLASSIAN_HOST env or via the --host flag. Host must be prefixed with https://")
}

user := conf.Options["user"]
Expand Down

0 comments on commit 5672ec0

Please sign in to comment.