Skip to content

Commit

Permalink
Merge pull request #75 from crossplane-contrib/feat/oidc-service-acco…
Browse files Browse the repository at this point in the history
…unts

ServiceAccountRoleIDExtractor
  • Loading branch information
Breee authored Apr 9, 2024
2 parents 0c8fa63 + ccd7bde commit e6b1042
Show file tree
Hide file tree
Showing 20 changed files with 565 additions and 26 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export TERRAFORM_NATIVE_PROVIDER_BINARY ?= terraform-provider-keycloak_v4.4.0

export TERRAFORM_DOCS_PATH ?= docs/resources

export GOLANGCILINT_VERSION ?= 1.57.2

PLATFORMS ?= linux_amd64 linux_arm64

# -include will silently skip missing files, which allows us
Expand Down
6 changes: 0 additions & 6 deletions apis/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@ Copyright 2021 Upbound Inc.
//go:generate bash -c "find ../internal/controller -type d -empty -delete"
//go:generate rm -rf ../examples-generated

// HACK: fetch latest docs from master branch, git clone https://github.com/mrparkers/terraform-provider-keycloak/${TERRAFORM_DOCS_PATH} to ../.work/${TERRAFORM_PROVIDER_SOURCE}/${TERRAFORM_DOCS_PATH}
//go:generate rm -rf ../.work/latest_provider
//go:generate git clone https://github.com/mrparkers/terraform-provider-keycloak.git ../.work/latest_provider
//go:generate rm -rf ../.work/${TERRAFORM_PROVIDER_SOURCE}/${TERRAFORM_DOCS_PATH}
//go:generate cp -r ../.work/latest_provider/${TERRAFORM_DOCS_PATH} ../.work/${TERRAFORM_PROVIDER_SOURCE}/${TERRAFORM_DOCS_PATH}
//go:generate rm -rf ../.work/latest_provider
// Generate documentation from Terraform docs.
//go:generate go run github.com/crossplane/upjet/cmd/scraper -n ${TERRAFORM_PROVIDER_SOURCE} -r ../.work/${TERRAFORM_PROVIDER_SOURCE}/${TERRAFORM_DOCS_PATH} -o ../config/provider-metadata.yaml --prelude-xpath "//text()[contains(., \"page_title\")]"

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 24 additions & 1 deletion apis/openidclient/v1alpha1/zz_clientserviceaccountrole_types.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 40 additions & 0 deletions apis/openidclient/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

65 changes: 65 additions & 0 deletions apis/openidclient/v1alpha1/zz_generated.resolvers.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions cmd/provider/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ func main() {
}

if *enableManagementPolicies {
o.Features.Enable(features.EnableBetaManagementPolicies)
log.Info("Beta feature enabled", "flag", features.EnableBetaManagementPolicies)
o.Features.Enable(features.EnableBetaManagementPolicies)
log.Info("Beta feature enabled", "flag", features.EnableBetaManagementPolicies)
}

if *enableExternalSecretStores {
o.SecretStoreConfigGVK = &v1alpha1.StoreConfigGroupVersionKind
log.Info("Alpha feature enabled", "flag", features.EnableAlphaExternalSecretStores)
Expand Down
32 changes: 32 additions & 0 deletions config/common/common.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package common

import (
"github.com/crossplane/crossplane-runtime/pkg/fieldpath"
"github.com/crossplane/crossplane-runtime/pkg/reference"
xpresource "github.com/crossplane/crossplane-runtime/pkg/resource"
)

const (
// SelfPackagePath is the golang path for this package.
SelfPackagePath = "github.com/crossplane-contrib/provider-keycloak/config/common"

// PathServiceAccountRoleIDExtractor is the golang path to ARNExtractor function
// in this package.
PathServiceAccountRoleIDExtractor = SelfPackagePath + ".ServiceAccountRoleIDExtractor()"
)

func ServiceAccountRoleIDExtractor() reference.ExtractValueFn {

Check failure on line 18 in config/common/common.go

View workflow job for this annotation

GitHub Actions / lint

exported function `ServiceAccountRoleIDExtractor` should have comment or be unexported (golint)

Check failure on line 18 in config/common/common.go

View workflow job for this annotation

GitHub Actions / lint

exported function `ServiceAccountRoleIDExtractor` should have comment or be unexported (golint)

Check failure on line 18 in config/common/common.go

View workflow job for this annotation

GitHub Actions / lint

exported function `ServiceAccountRoleIDExtractor` should have comment or be unexported (golint)
return func(mg xpresource.Managed) string {
paved, err := fieldpath.PaveObject(mg)
if err != nil {
// todo(hasan): should we log this error?
return ""
}
r, err := paved.GetString("status.atProvider.serviceAccountUserId")
if err != nil {
// todo(hasan): should we log this error?
return ""
}
return r
}
}
4 changes: 3 additions & 1 deletion config/openidclient/config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package openidclient

import "github.com/crossplane/upjet/pkg/config"
import (
"github.com/crossplane/upjet/pkg/config"
)

const (
// Group is the short group for this provider.
Expand Down
18 changes: 18 additions & 0 deletions config/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/crossplane/upjet/pkg/config"
ujconfig "github.com/crossplane/upjet/pkg/config"

"github.com/crossplane-contrib/provider-keycloak/config/common"
"github.com/crossplane-contrib/provider-keycloak/config/defaults"
"github.com/crossplane-contrib/provider-keycloak/config/group"
"github.com/crossplane-contrib/provider-keycloak/config/mapper"
Expand Down Expand Up @@ -85,7 +86,24 @@ func KnownReferencers() config.ResourceOption { //nolint:gocyclo
r.References["client_id"] = config.Reference{
Type: "github.com/crossplane-contrib/provider-keycloak/apis/openidclient/v1alpha1.Client",
}
case "service_account_user_id":
r.References["service_account_user_id"] = config.Reference{
Type: "github.com/crossplane-contrib/provider-keycloak/apis/openidclient/v1alpha1.Client",
Extractor: common.PathServiceAccountRoleIDExtractor,
RefFieldName: "ServiceAccountUserClientIDRef",
SelectorFieldName: "ServiceAccountUserClientIDSelector",
}
r.LateInitializer = config.LateInitializer{
IgnoredFields: []string{"service_account_user_id"},
}

// case "role":
// r.References["role"] = config.Reference{
// Type: "github.com/crossplane-contrib/provider-keycloak/apis/role/v1alpha1.Role",
// Extractor: `github.com/crossplane/upjet/pkg/resource.ExtractParamPath("name", false)`,
// }
}

}
}
}
Loading

0 comments on commit e6b1042

Please sign in to comment.