Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🧹 return error when invalid host value is provided for atlassian provider #4567

Merged
merged 1 commit into from
Aug 19, 2024
Merged
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
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
Loading