scim/pkg/supplier/url.go
2022-06-16 10:14:40 +02:00

28 lines
595 B
Go

package supplier
import (
"fmt"
"net/url"
)
func validateUrl(u *url.URL) error {
if u.Scheme == "" {
return fmt.Errorf("scheme cannot be empty")
}
if u.Scheme != "http" && u.Scheme != "https" {
return fmt.Errorf("%s scheme is not valid", u.Scheme)
}
if u.Host == "" {
return fmt.Errorf("host can't be empty")
}
if u.User == nil {
return fmt.Errorf("credentials must be provided")
}
if u.User.Username() == "" {
return fmt.Errorf("username can't be empty")
}
if p, ok := u.User.Password(); !ok || p == "" {
return fmt.Errorf("password can't be empty")
}
return nil
}