diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f92bf0..0e21509 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Changed + +- Changed GitHub connector config to include `teamNameField: slug` by default. + ## [0.8.0] - 2023-08-02 ### Added diff --git a/pkg/idp/provider/github/github.go b/pkg/idp/provider/github/github.go index df3dfdb..59f1a5c 100644 --- a/pkg/idp/provider/github/github.go +++ b/pkg/idp/provider/github/github.go @@ -11,6 +11,7 @@ import ( "github.com/giantswarm/dex-operator/pkg/idp/provider" "github.com/giantswarm/dex-operator/pkg/idp/provider/github/manifest" "github.com/giantswarm/dex-operator/pkg/key" + "github.com/giantswarm/dex-operator/pkg/yaml" "github.com/bradleyfalzon/ghinstallation/v2" githubconnector "github.com/dexidp/dex/connector/github" @@ -18,7 +19,6 @@ import ( "github.com/go-logr/logr" githubclient "github.com/google/go-github/v50/github" "github.com/skratchdot/open-golang/open" - "gopkg.in/yaml.v2" ) const ( @@ -32,6 +32,7 @@ const ( ClientIDKey = "client-id" ClientSecretKey = "client-secret" DefaultHost = "github.com" + TeamNameFieldSlug = "slug" ) type Github struct { @@ -174,9 +175,10 @@ func (g *Github) CreateOrUpdateApp(config provider.AppConfig, ctx context.Contex Teams: []string{g.Team}, }, }, - RedirectURI: config.RedirectURI, + RedirectURI: config.RedirectURI, + TeamNameField: TeamNameFieldSlug, } - data, err := yaml.Marshal(connectorConfig) + data, err := yaml.MarshalWithJsonAnnotations(connectorConfig) if err != nil { return provider.ProviderApp{}, microerror.Mask(err) } diff --git a/pkg/yaml/yaml.go b/pkg/yaml/yaml.go new file mode 100644 index 0000000..6736252 --- /dev/null +++ b/pkg/yaml/yaml.go @@ -0,0 +1,25 @@ +package yaml + +import ( + "encoding/json" + + yamllib "gopkg.in/yaml.v2" + + "github.com/giantswarm/microerror" +) + +// MarshalWithJsonAnnotations marshals the given value to YAML, but uses the +// JSON annotations of the struct fields. +func MarshalWithJsonAnnotations(v any) ([]byte, error) { + jsonData, jsonErr := json.Marshal(v) + if jsonErr != nil { + return nil, microerror.Mask(jsonErr) + } + var mapData map[string]interface{} + jsonErr = json.Unmarshal(jsonData, &mapData) + if jsonErr != nil { + return nil, microerror.Mask(jsonErr) + } + data, yamlErr := yamllib.Marshal(mapData) + return data, yamlErr +}