package cmd import ( "fmt" "net/url" "strings" "github.com/spf13/cobra" "libre.sh/scim/pkg/supplier" ) var providerName, providerVersion string var setupCmd = &cobra.Command{ Use: "setup", Short: "Setup everything !", } func newSetupCommand(providerType string) *cobra.Command { var kc supplier.KeycloakSupplier var sp supplier.ServiceProviderSupplier return &cobra.Command{ Use: providerType, Short: fmt.Sprintf("Setup %s.", providerType), Example: fmt.Sprintf(`scim setup rocketchat KEYCLOAK_URL %s_URL KEYCLOAK_URL = http(s)://:@/ %s_URL = http(s)://:@`, strings.ToUpper(providerType), strings.ToUpper(providerType)), Args: cobra.ExactArgs(2), PreRun: func(cmd *cobra.Command, args []string) { clientUrl, err := url.Parse(args[0]) CheckErr(err) providerUrl, err := url.Parse(args[1]) CheckErr(err) kc, err = supplier.NewKeycloakSupplier(clientUrl) CheckErr(err) sp, err = supplier.NewServiceProviderSupplier(providerType, providerUrl, supplier.ServiceProviderOptions{ Version: providerVersion, Name: providerName, }) CheckErr(err) }, Run: func(cmd *cobra.Command, args []string) { ctx := cmd.Context() err := supplier.Reconcile(ctx, sp, kc) CheckErr(err) fmt.Println("service provider is ready") }, } } func init() { rootCmd.AddCommand(setupCmd) rootCmd.PersistentFlags().StringVar(&providerName, "provider-name", "", "Specify the name of the federation in Keycloak.") rootCmd.PersistentFlags().StringVar(&providerVersion, "provider-version", "", "Specify the version of the provider app. Defaults to latest.") setupCmd.AddCommand(newSetupCommand("rocketchat")) // setupCmd.AddCommand(newSetupCommand("nextcloud")) }