scim/pkg/supplier/factory.go

42 lines
871 B
Go
Raw Normal View History

2022-06-10 11:51:19 +00:00
package supplier
import (
"fmt"
2022-06-16 08:14:40 +00:00
"net/url"
2022-06-10 11:51:19 +00:00
"github.com/go-resty/resty/v2"
)
2022-06-16 08:14:40 +00:00
type ServiceProviderOptions struct {
Version string
Name string
}
func NewServiceProviderSupplier(name string, u *url.URL, opts ServiceProviderOptions) (ServiceProviderSupplier, error) {
if err := validateUrl(u); err != nil {
return nil, err
}
pass, _ := u.User.Password()
user := u.User.Username()
u.User = nil
config := spConfig{
Host: u.String(),
Username: user,
Password: pass,
Name: opts.Name,
Version: opts.Version,
}
2022-06-10 11:51:19 +00:00
switch name {
case "rocketchat":
return &rocketchat{
// until the app is added to the marketplace.
2022-06-16 08:14:40 +00:00
sideLoading: true,
spConfig: config,
2022-06-10 11:51:19 +00:00
Client: resty.New().
SetBaseURL(config.Host).
SetHeader("Content-Type", "application/json"),
}, nil
}
return nil, fmt.Errorf("unkown service provider : %s", name)
}