scim/pkg/cmd/config.go

53 lines
1.4 KiB
Go

package cmd
import (
"github.com/go-playground/validator/v10"
"github.com/spf13/viper"
"libre.sh/scim/pkg/supplier"
)
type ProviderType string
const (
RocketChat ProviderType = "rocketchat"
Nextcloud ProviderType = "nextcloud"
)
type Config struct {
Client Client `validate:"required"`
Provider Provider `validate:"required"`
}
type Client struct {
supplier.ServiceProviderConfig `validate:"required"`
Realm string `validate:"required"`
}
type Provider struct {
supplier.ServiceProviderConfig `validate:"required"`
Type ProviderType `validate:"required"`
}
func GetConfig() (Config, error) {
config := Config{
Client: Client{
Realm: viper.GetString("client.realm"),
ServiceProviderConfig: supplier.ServiceProviderConfig{
Host: viper.GetString("client.host"),
Username: viper.GetString("client.username"),
Password: viper.GetString("client.password"),
},
},
Provider: Provider{
Type: ProviderType(viper.GetString("provider.type")),
ServiceProviderConfig: supplier.ServiceProviderConfig{
Name: viper.GetString("provider.name"),
Host: viper.GetString("provider.host"),
Username: viper.GetString("provider.username"),
Password: viper.GetString("provider.password"),
},
},
}
validate := validator.New()
return config, validate.Struct(config)
}