Skip to content

Commit

Permalink
feat(resolvers): add transformer for non-cross-reference resolvers
Browse files Browse the repository at this point in the history
  • Loading branch information
Breee committed Jul 8, 2024
1 parent 6cb329f commit 0fe0998
Show file tree
Hide file tree
Showing 15 changed files with 113 additions and 52 deletions.
2 changes: 2 additions & 0 deletions cmd/provider/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"github.com/crossplane-contrib/provider-keycloak/apis"
"github.com/crossplane-contrib/provider-keycloak/apis/v1alpha1"
"github.com/crossplane-contrib/provider-keycloak/config"
resolverapis "github.com/crossplane-contrib/provider-keycloak/internal/apis"
"github.com/crossplane-contrib/provider-keycloak/internal/clients"
"github.com/crossplane-contrib/provider-keycloak/internal/controller"
"github.com/crossplane-contrib/provider-keycloak/internal/features"
Expand Down Expand Up @@ -88,6 +89,7 @@ func main() {
metrics.Registry.MustRegister(metricRecorder)
metrics.Registry.MustRegister(stateMetrics)
kingpin.FatalIfError(apis.AddToScheme(mgr.GetScheme()), "Cannot add keycloak APIs to scheme")
kingpin.FatalIfError(resolverapis.BuildScheme(apis.AddToSchemes), "Cannot register the keycloak APIs with the API resolver's runtime scheme")

provider, err := config.GetProvider(false)
kingpin.FatalIfError(err, "Cannot get provider configuration")
Expand Down
18 changes: 9 additions & 9 deletions config/authentication/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func Configure(p *config.Provider) {
p.AddResourceConfigurator("keycloak_authentication_subflow", func(r *config.Resource) {
r.ShortGroup = Group
r.References["parent_flow_alias"] = config.Reference{
Type: "github.com/crossplane-contrib/provider-keycloak/apis/authenticationflow/v1alpha1.Flow",
TerraformName: "keycloak_authentication_flow",
Extractor: common.PathAuthenticationFlowAliasExtractor,
RefFieldName: "ParentFlowAliasRef",
SelectorFieldName: "ParentFlowAliasSelector",
Expand All @@ -27,7 +27,7 @@ func Configure(p *config.Provider) {
p.AddResourceConfigurator("keycloak_authentication_execution", func(r *config.Resource) {
r.ShortGroup = Group
r.References["parent_flow_alias"] = config.Reference{
Type: "github.com/crossplane-contrib/provider-keycloak/apis/authenticationflow/v1alpha1.Flow",
TerraformName: "keycloak_authentication_flow",
Extractor: common.PathAuthenticationFlowAliasExtractor,
RefFieldName: "ParentFlowAliasRef",
SelectorFieldName: "ParentFlowAliasSelector",
Expand All @@ -36,43 +36,43 @@ func Configure(p *config.Provider) {
p.AddResourceConfigurator("keycloak_authentication_execution_config", func(r *config.Resource) {
r.ShortGroup = Group
r.References["execution_id"] = config.Reference{
Type: "github.com/crossplane-contrib/provider-keycloak/apis/authenticationflow/v1alpha1.Execution",
TerraformName: "keycloak_authentication_execution",
}
})
p.AddResourceConfigurator("keycloak_authentication_bindings", func(r *config.Resource) {
r.ShortGroup = Group
r.References["browser_flow"] = config.Reference{
Type: "github.com/crossplane-contrib/provider-keycloak/apis/authenticationflow/v1alpha1.Flow",
TerraformName: "keycloak_authentication_flow",
Extractor: common.PathAuthenticationFlowAliasExtractor,
RefFieldName: "BrowserFlowRef",
SelectorFieldName: "BrowserFlowSelector",
}
r.References["registration_flow"] = config.Reference{
Type: "github.com/crossplane-contrib/provider-keycloak/apis/authenticationflow/v1alpha1.Flow",
TerraformName: "keycloak_authentication_flow",
Extractor: common.PathAuthenticationFlowAliasExtractor,
RefFieldName: "RegistrationFlowRef",
SelectorFieldName: "RegistrationFlowSelector",
}
r.References["direct_grant_flow"] = config.Reference{
Type: "github.com/crossplane-contrib/provider-keycloak/apis/authenticationflow/v1alpha1.Flow",
TerraformName: "keycloak_authentication_flow",
Extractor: common.PathAuthenticationFlowAliasExtractor,
RefFieldName: "DirectGrantFlowRef",
SelectorFieldName: "DirectGrantFlowSelector",
}
r.References["reset_credentials_flow"] = config.Reference{
Type: "github.com/crossplane-contrib/provider-keycloak/apis/authenticationflow/v1alpha1.Flow",
TerraformName: "keycloak_authentication_flow",
Extractor: common.PathAuthenticationFlowAliasExtractor,
RefFieldName: "ResetCredentialsFlowRef",
SelectorFieldName: "ResetCredentialsFlowSelector",
}
r.References["client_authentication_flow"] = config.Reference{
Type: "github.com/crossplane-contrib/provider-keycloak/apis/authenticationflow/v1alpha1.Flow",
TerraformName: "keycloak_authentication_flow",
Extractor: common.PathAuthenticationFlowAliasExtractor,
RefFieldName: "ClientAuthenticationFlowRef",
SelectorFieldName: "ClientAuthenticationFlowSelector",
}
r.References["docker_authentication_flow"] = config.Reference{
Type: "github.com/crossplane-contrib/provider-keycloak/apis/authenticationflow/v1alpha1.Flow",
TerraformName: "keycloak_authentication_flow",
Extractor: common.PathAuthenticationFlowAliasExtractor,
RefFieldName: "DockerAuthenticationFlowRef",
SelectorFieldName: "DockerAuthenticationFlowSelector",
Expand Down
6 changes: 3 additions & 3 deletions config/defaults/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ func Configure(p *config.Provider) {
p.AddResourceConfigurator("keycloak_default_roles", func(r *config.Resource) {
r.ShortGroup = "defaults"
r.References["default_roles"] = config.Reference{
Type: "github.com/crossplane-contrib/provider-keycloak/apis/role/v1alpha1.Role",
Extractor: `github.com/crossplane/upjet/pkg/resource.ExtractParamPath("name", false)`,
TerraformName: "keycloak_role",
Extractor: `github.com/crossplane/upjet/pkg/resource.ExtractParamPath("name", false)`,
}

})
Expand All @@ -20,7 +20,7 @@ func Configure(p *config.Provider) {
r.ShortGroup = "defaults"
r.Kind = "DefaultGroups"
r.References["group_ids"] = config.Reference{
Type: "github.com/crossplane-contrib/provider-keycloak/apis/group/v1alpha1.Group",
TerraformName: "keycloak_group",
}

})
Expand Down
8 changes: 4 additions & 4 deletions config/group/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,29 @@ func Configure(p *config.Provider) {
r.ShortGroup = "group"

r.References["parent_id"] = config.Reference{
Type: "Group",
TerraformName: "keycloak_group",
}
})
p.AddResourceConfigurator("keycloak_group_memberships", func(r *config.Resource) {
// We need to override the default group that upjet generated for
r.ShortGroup = "group"
r.References["group_id"] = config.Reference{
Type: "Group",
TerraformName: "keycloak_group",
}

})
p.AddResourceConfigurator("keycloak_group_roles", func(r *config.Resource) {
// We need to override the default group that upjet generated for
r.ShortGroup = "group"
r.References["group_id"] = config.Reference{
Type: "Group",
TerraformName: "keycloak_group",
}
})
p.AddResourceConfigurator("keycloak_group_permissions", func(r *config.Resource) {
// We need to override the default group that upjet generated for
r.ShortGroup = "group"
r.References["group_id"] = config.Reference{
Type: "Group",
TerraformName: "keycloak_group",
}
})
}
2 changes: 1 addition & 1 deletion config/identityprovider/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func Configure(p *config.Provider) {
p.AddResourceConfigurator("keycloak_custom_identity_provider_mapper", func(r *config.Resource) {
r.ShortGroup = Group
r.References["realm"] = config.Reference{
Type: "github.com/crossplane-contrib/provider-keycloak/apis/realm/v1alpha1.Realm",
TerraformName: "keycloak_realm",
}
})
}
28 changes: 14 additions & 14 deletions config/ldap/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,83 +16,83 @@ func Configure(p *config.Provider) {
p.AddResourceConfigurator("keycloak_ldap_user_attribute_mapper", func(r *config.Resource) {
r.ShortGroup = Group
r.References["ldap_user_federation_id"] = config.Reference{
Type: "github.com/crossplane-contrib/provider-keycloak/apis/ldap/v1alpha1.UserFederation",
TerraformName: "keycloak_ldap_user_federation",
}
})

p.AddResourceConfigurator("keycloak_ldap_role_mapper", func(r *config.Resource) {
r.ShortGroup = Group
r.References["ldap_user_federation_id"] = config.Reference{
Type: "github.com/crossplane-contrib/provider-keycloak/apis/ldap/v1alpha1.UserFederation",
TerraformName: "keycloak_ldap_user_federation",
}
})

p.AddResourceConfigurator("keycloak_ldap_group_mapper", func(r *config.Resource) {
r.ShortGroup = Group
r.References["ldap_user_federation_id"] = config.Reference{
Type: "github.com/crossplane-contrib/provider-keycloak/apis/ldap/v1alpha1.UserFederation",
TerraformName: "keycloak_ldap_user_federation",
}

})

p.AddResourceConfigurator("keycloak_ldap_hardcoded_role_mapper", func(r *config.Resource) {
r.ShortGroup = Group
r.References["ldap_user_federation_id"] = config.Reference{
Type: "github.com/crossplane-contrib/provider-keycloak/apis/ldap/v1alpha1.UserFederation",
TerraformName: "keycloak_ldap_user_federation",
}
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)`,
TerraformName: "keycloak_role",
Extractor: `github.com/crossplane/upjet/pkg/resource.ExtractParamPath("name", false)`,
}

})

p.AddResourceConfigurator("keycloak_ldap_hardcoded_group_mapper", func(r *config.Resource) {
r.ShortGroup = Group
r.References["ldap_user_federation_id"] = config.Reference{
Type: "github.com/crossplane-contrib/provider-keycloak/apis/ldap/v1alpha1.UserFederation",
TerraformName: "keycloak_ldap_user_federation",
}
r.References["group"] = config.Reference{
Type: "github.com/crossplane-contrib/provider-keycloak/apis/group/v1alpha1.Group",
Extractor: `github.com/crossplane/upjet/pkg/resource.ExtractParamPath("name", false)`,
TerraformName: "keycloak_group",
Extractor: `github.com/crossplane/upjet/pkg/resource.ExtractParamPath("name", false)`,
}
})

p.AddResourceConfigurator("keycloak_ldap_msad_user_account_control_mapper", func(r *config.Resource) {
r.ShortGroup = Group
r.References["ldap_user_federation_id"] = config.Reference{
Type: "github.com/crossplane-contrib/provider-keycloak/apis/ldap/v1alpha1.UserFederation",
TerraformName: "keycloak_ldap_user_federation",
}

})

p.AddResourceConfigurator("keycloak_ldap_msad_lds_user_account_control_mapper", func(r *config.Resource) {
r.ShortGroup = Group
r.References["ldap_user_federation_id"] = config.Reference{
Type: "github.com/crossplane-contrib/provider-keycloak/apis/ldap/v1alpha1.UserFederation",
TerraformName: "keycloak_ldap_user_federation",
}

})

p.AddResourceConfigurator("keycloak_ldap_hardcoded_attribute_mapper", func(r *config.Resource) {
r.ShortGroup = Group
r.References["ldap_user_federation_id"] = config.Reference{
Type: "github.com/crossplane-contrib/provider-keycloak/apis/ldap/v1alpha1.UserFederation",
TerraformName: "keycloak_ldap_user_federation",
}

})

p.AddResourceConfigurator("keycloak_ldap_full_name_mapper", func(r *config.Resource) {
r.ShortGroup = Group
r.References["ldap_user_federation_id"] = config.Reference{
Type: "github.com/crossplane-contrib/provider-keycloak/apis/ldap/v1alpha1.UserFederation",
TerraformName: "keycloak_ldap_user_federation",
}
})

p.AddResourceConfigurator("keycloak_ldap_custom_mapper", func(r *config.Resource) {
r.ShortGroup = Group
r.References["ldap_user_federation_id"] = config.Reference{
Type: "github.com/crossplane-contrib/provider-keycloak/apis/ldap/v1alpha1.UserFederation",
TerraformName: "keycloak_ldap_user_federation",
}
})
}
4 changes: 2 additions & 2 deletions config/mapper/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ func Configure(p *config.Provider) {
p.AddResourceConfigurator("keycloak_generic_protocol_mapper", func(r *config.Resource) {
r.ShortGroup = "client"
r.References["client_scope_id"] = config.Reference{
Type: "github.com/crossplane-contrib/provider-keycloak/apis/openidclient/v1alpha1.ClientScope",
TerraformName: "keycloak_openid_client_scope",
}
})

p.AddResourceConfigurator("keycloak_generic_role_mapper", func(r *config.Resource) {
r.ShortGroup = "client"
r.References["role_id"] = config.Reference{
Type: "github.com/crossplane-contrib/provider-keycloak/apis/role/v1alpha1.Role",
TerraformName: "keycloak_role",
}

})
Expand Down
2 changes: 1 addition & 1 deletion config/oidc/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func Configure(p *config.Provider) {
// We need to override the default group that upjet generated for
r.ShortGroup = "oidc"
r.References["realm"] = config.Reference{
Type: "github.com/crossplane-contrib/provider-keycloak/apis/realm/v1alpha1.Realm",
TerraformName: "keycloak_realm",
}
r.References["first_broker_login_flow_alias"] = config.Reference{
Type: "github.com/crossplane-contrib/provider-keycloak/apis/authenticationflow/v1alpha1.Flow",
Expand Down
26 changes: 24 additions & 2 deletions config/openidclient/config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package openidclient

import (
"github.com/crossplane-contrib/provider-keycloak/config/common"
"github.com/crossplane/upjet/pkg/config"
)

Expand All @@ -16,10 +17,10 @@ func Configure(p *config.Provider) {
r.ShortGroup = Group

r.References["authentication_flow_binding_overrides.browser_id"] = config.Reference{
Type: "github.com/crossplane-contrib/provider-keycloak/apis/authenticationflow/v1alpha1.Flow",
TerraformName: "keycloak_authentication_flow",
}
r.References["authentication_flow_binding_overrides.direct_grant_id"] = config.Reference{
Type: "github.com/crossplane-contrib/provider-keycloak/apis/authenticationflow/v1alpha1.Flow",
TerraformName: "keycloak_authentication_flow",
}

})
Expand All @@ -36,6 +37,27 @@ func Configure(p *config.Provider) {

p.AddResourceConfigurator("keycloak_openid_client_service_account_role", func(r *config.Resource) {
r.ShortGroup = Group
// The id of the client that provides the role.
r.References["client_id"] = config.Reference{

TerraformName: "keycloak_openid_client",
Extractor: common.PathUUIDExtractor,
}
// The id of the service account that is assigned the role (the service account of the client that "consumes" the role).
r.References["service_account_user_id"] = config.Reference{
TerraformName: "keycloak_openid_client",
Extractor: common.PathServiceAccountRoleIDExtractor,
RefFieldName: "ServiceAccountUserClientIDRef",
SelectorFieldName: "ServiceAccountUserClientIDSelector",
}
// The name of the role that is assigned.
r.References["role"] = config.Reference{
TerraformName: "keycloak_role",
Extractor: `github.com/crossplane/upjet/pkg/resource.ExtractParamPath("name", false)`,
}
r.LateInitializer = config.LateInitializer{
IgnoredFields: []string{"service_account_user_id"},
}

})

Expand Down
2 changes: 1 addition & 1 deletion config/openidgroup/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ func Configure(p *config.Provider) {
r.ShortGroup = "openidgroup"

r.References["client_scope_id"] = config.Reference{
Type: "github.com/crossplane-contrib/provider-keycloak/apis/openidclient/v1alpha1.ClientScope",
TerraformName: "keycloak_openid_client_scope",
}
})
}
16 changes: 8 additions & 8 deletions config/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,16 +128,16 @@ func KnownReferencers() config.ResourceOption { //nolint:gocyclo
switch k {
case "realm_id":
r.References["realm_id"] = config.Reference{
Type: "github.com/crossplane-contrib/provider-keycloak/apis/realm/v1alpha1.Realm",
TerraformName: "keycloak_realm",
}
case "client_id":
r.References["client_id"] = config.Reference{
Type: "github.com/crossplane-contrib/provider-keycloak/apis/openidclient/v1alpha1.Client",
Extractor: common.PathUUIDExtractor,
TerraformName: "keycloak_openid_client",
Extractor: common.PathUUIDExtractor,
}
case "service_account_user_id":
r.References["service_account_user_id"] = config.Reference{
Type: "github.com/crossplane-contrib/provider-keycloak/apis/openidclient/v1alpha1.Client",
TerraformName: "keycloak_openid_client",
Extractor: common.PathServiceAccountRoleIDExtractor,
RefFieldName: "ServiceAccountUserClientIDRef",
SelectorFieldName: "ServiceAccountUserClientIDSelector",
Expand All @@ -148,14 +148,14 @@ func KnownReferencers() config.ResourceOption { //nolint:gocyclo

case "role_ids":
r.References["role_ids"] = config.Reference{
Type: "github.com/crossplane-contrib/provider-keycloak/apis/role/v1alpha1.Role",
Extractor: common.PathUUIDExtractor,
TerraformName: "keycloak_role",
Extractor: common.PathUUIDExtractor,
}

case "role_id":
r.References["role_id"] = config.Reference{
Type: "github.com/crossplane-contrib/provider-keycloak/apis/role/v1alpha1.Role",
Extractor: common.PathUUIDExtractor,
TerraformName: "keycloak_role",
Extractor: common.PathUUIDExtractor,
}
}

Expand Down
2 changes: 1 addition & 1 deletion config/role/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ func Configure(p *config.Provider) {
// this resource, which would be "github"
r.ShortGroup = "role"
r.References["composite_roles"] = config.Reference{
Type: "Role",
TerraformName: "keycloak_role",
}
})
}
2 changes: 1 addition & 1 deletion config/saml/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func Configure(p *config.Provider) {
// We need to override the default group that upjet generated for
r.ShortGroup = "saml"
r.References["realm"] = config.Reference{
Type: "github.com/crossplane-contrib/provider-keycloak/apis/realm/v1alpha1.Realm",
TerraformName: "keycloak_realm",
}
})
p.AddResourceConfigurator("keycloak_saml_client", func(r *config.Resource) {
Expand Down
Loading

0 comments on commit 0fe0998

Please sign in to comment.