Skip to content

Commit

Permalink
fix: remove isLagoonGroup() function
Browse files Browse the repository at this point in the history
The lagoon-projects attribute is deprecated as of Lagoon v2.18.

See uselagoon/lagoon#3612 for details.
  • Loading branch information
smlx committed Apr 19, 2024
1 parent e2daf63 commit 8d95c03
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 21 deletions.
2 changes: 1 addition & 1 deletion internal/sync/indexpatterns.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func generateIndexPatterns(log *zap.Logger, groups []keycloak.Group,
var patterns []string
var err error
for _, group := range groups {
if !isLagoonGroup(group) || isProjectGroup(log, group) {
if isProjectGroup(log, group) {
continue
}
patterns, err = generateIndexPatternsForGroup(log, group, projectNames,
Expand Down
22 changes: 8 additions & 14 deletions internal/sync/roles.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,6 @@ func isProjectGroup(log *zap.Logger, group keycloak.Group) bool {
return true
}

// isLagoonGroup inspects the given group to determine if it is a Lagoon group.
//
// All Lagoon groups (project groups and regular groups) have a lagoon-projects
// attribute, which is checked by this function.
func isLagoonGroup(group keycloak.Group) bool {
_, ok := group.Attributes["lagoon-projects"]
return ok
}

// isInt returns true if the given string looks like a base-10 integer.
func isInt(s string) bool {
_, err := strconv.Atoi(s)
Expand Down Expand Up @@ -193,10 +184,13 @@ func generateRegularGroupRole(log *zap.Logger, projectNames map[int]string,
// generateRoles returns a slice of roles generated from the given slice of
// keycloak Groups.
//
// Any groups which are not recognized as either project groups or regular
// Lagoon groups are ignored.
func generateRoles(log *zap.Logger, groups []keycloak.Group,
projectNames map[int]string) map[string]opensearch.Role {
// Any groups which are not recognized as project groups are assumed to be
// Lagoon groups.
func generateRoles(
log *zap.Logger,
groups []keycloak.Group,
projectNames map[int]string,
) map[string]opensearch.Role {
roles := map[string]opensearch.Role{}
var name string
var role *opensearch.Role
Expand All @@ -209,7 +203,7 @@ func generateRoles(log *zap.Logger, groups []keycloak.Group,
zap.String("group name", group.Name), zap.Error(err))
continue
}
} else if isLagoonGroup(group) {
} else {
name, role, err = generateRegularGroupRole(log, projectNames, group)
if err != nil {
log.Warn("couldn't generate role for regular group",
Expand Down
6 changes: 3 additions & 3 deletions internal/sync/rolesmapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ func calculateRoleMappingDiff(
// generateRolesMapping returns a slice of rolesmapping generated from the
// given slice of keycloak Groups.
//
// Any groups which are not recognized as either project groups or regular
// Lagoon groups are ignored.
// Any groups which are not recognized as project groups are assumed to be
// Lagoon groups.
func generateRolesMapping(log *zap.Logger,
groups []keycloak.Group) map[string]opensearch.RoleMapping {
rolesmapping := map[string]opensearch.RoleMapping{}
Expand All @@ -79,7 +79,7 @@ func generateRolesMapping(log *zap.Logger,
Users: []string{},
},
}
} else if isLagoonGroup(group) {
} else {
rolesmapping[group.Name] = opensearch.RoleMapping{
RoleMappingPermissions: opensearch.RoleMappingPermissions{
BackendRoles: []string{group.Name},
Expand Down
8 changes: 5 additions & 3 deletions internal/sync/tenants.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,13 @@ func calculateTenantDiff(existing, required map[string]opensearch.Tenant) (
//
// Only regular Lagoon groups are associated with a tenant, so project groups
// are ignored.
func generateTenants(log *zap.Logger,
groups []keycloak.Group) map[string]opensearch.Tenant {
func generateTenants(
log *zap.Logger,
groups []keycloak.Group,
) map[string]opensearch.Tenant {
tenants := map[string]opensearch.Tenant{}
for _, group := range groups {
if !isLagoonGroup(group) || isProjectGroup(log, group) {
if isProjectGroup(log, group) {
continue
}
tenants[group.Name] = opensearch.Tenant{
Expand Down

0 comments on commit 8d95c03

Please sign in to comment.