Skip to content

Commit

Permalink
Use slug in GitHub dex config (#82)
Browse files Browse the repository at this point in the history
* Set slug as team name field in GitHub config

* Marshal GitHub connector config with JSON annotations

* Fix imports

* Fix imports
  • Loading branch information
mogottsch authored Sep 14, 2023
1 parent 213d478 commit f02ad1b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions pkg/idp/provider/github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ 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"
"github.com/giantswarm/microerror"
"github.com/go-logr/logr"
githubclient "github.com/google/go-github/v50/github"
"github.com/skratchdot/open-golang/open"
"gopkg.in/yaml.v2"
)

const (
Expand All @@ -32,6 +32,7 @@ const (
ClientIDKey = "client-id"
ClientSecretKey = "client-secret"
DefaultHost = "github.com"
TeamNameFieldSlug = "slug"
)

type Github struct {
Expand Down Expand Up @@ -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)
}
Expand Down
25 changes: 25 additions & 0 deletions pkg/yaml/yaml.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit f02ad1b

Please sign in to comment.