-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CLOUDP-283292. AtlasCustomRole CRDs (#3450)
Co-authored-by: Helder Santana <[email protected]>
- Loading branch information
1 parent
8bdf685
commit 3957ccd
Showing
9 changed files
with
545 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,64 @@ | ||
{ | ||
"cloud.google.com/go/kms": "apix-2", | ||
"github.com/AlecAivazis/survey/v2": "apix-2", | ||
"github.com/Azure/azure-sdk-for-go/sdk/azcore": "apix-2", | ||
"github.com/Azure/azure-sdk-for-go/sdk/azidentity": "apix-2", | ||
"github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/azkeys": "apix-2", | ||
"github.com/Masterminds/semver/v3": "apix-2", | ||
"github.com/PaesslerAG/jsonpath": "apix-2", | ||
"github.com/aws/aws-sdk-go-v2": "apix-2", | ||
"github.com/aws/aws-sdk-go-v2/config": "apix-2", | ||
"github.com/aws/aws-sdk-go-v2/credentials": "apix-2", | ||
"github.com/aws/aws-sdk-go-v2/service/kms": "apix-2", | ||
"github.com/briandowns/spinner": "apix-2", | ||
"github.com/evergreen-ci/shrub": "apix-2", | ||
"github.com/go-test/deep": "apix-2", | ||
"github.com/golang-jwt/jwt/v4": "apix-2", | ||
"github.com/golang/mock": "apix-2", | ||
"github.com/google/go-github/v61": "apix-2", | ||
"github.com/google/uuid": "atlas_kubernetes_team", | ||
"github.com/klauspost/compress": "apix-2", | ||
"github.com/mattn/go-isatty": "apix-2", | ||
"github.com/mongodb-forks/digest": "apix-2", | ||
"github.com/mongodb-labs/cobra2snooty": "apix-2", | ||
"github.com/pelletier/go-toml": "apix-2", | ||
"github.com/Netflix/go-expect": "apix-2", | ||
"github.com/creack/pty": "apix-2", | ||
"github.com/hinshun/vt10x": "apix-2", | ||
"github.com/pkg/browser": "apix-2", | ||
"github.com/spf13/afero": "apix-2", | ||
"github.com/spf13/cobra": "apix-2", | ||
"github.com/spf13/pflag": "apix-2", | ||
"github.com/spf13/viper": "apix-2", | ||
"github.com/stretchr/testify": "apix-2", | ||
"github.com/tangzero/inflector": "apix-2", | ||
"go.mongodb.org/atlas": "apix-2", | ||
"go.mongodb.org/atlas-sdk/v20241113004": "apix-2", | ||
"go.mongodb.org/atlas-sdk/v20240530005": "apix-2", | ||
"go.mongodb.org/mongo-driver": "apix-2", | ||
"golang.org/x/sys": "apix-2", | ||
"golang.org/x/tools": "apix-2", | ||
"google.golang.org/api": "apix-2", | ||
"google.golang.org/protobuf": "apix-2", | ||
"golang.org/x/mod": "apix-2", | ||
"gopkg.in/yaml.v3": "apix-2", | ||
"github.com/mongodb/mongodb-atlas-kubernetes/v2": "atlas_kubernetes_team", | ||
"k8s.io/api": "atlas_kubernetes_team", | ||
"k8s.io/apimachinery": "atlas_kubernetes_team", | ||
"k8s.io/apiserver": "atlas_kubernetes_team", | ||
"k8s.io/client-go": "atlas_kubernetes_team", | ||
"k8s.io/apiextensions-apiserver": "atlas_kubernetes_team", | ||
"sigs.k8s.io/yaml": "atlas_kubernetes_team", | ||
"sigs.k8s.io/controller-runtime": "atlas_kubernetes_team", | ||
"sigs.k8s.io/kind": "atlas_kubernetes_team", | ||
"golang.org/x/exp": "atlas_kubernetes_team", | ||
"github.com/denisbrodbeck/machineid": "apix-2", | ||
"github.com/shirou/gopsutil/v4": "apix-2", | ||
"go.opentelemetry.io/otel": "apix-2", | ||
"go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc": "apix-2", | ||
"go.opentelemetry.io/otel/sdk": "apix-2", | ||
"go.opentelemetry.io/otel/trace": "apix-2", | ||
"google.golang.org/grpc": "apix-2", | ||
"github.com/mholt/archives": "apix-2" | ||
"cloud.google.com/go/kms": "apix-2", | ||
"github.com/AlecAivazis/survey/v2": "apix-2", | ||
"github.com/Azure/azure-sdk-for-go/sdk/azcore": "apix-2", | ||
"github.com/Azure/azure-sdk-for-go/sdk/azidentity": "apix-2", | ||
"github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/azkeys": "apix-2", | ||
"github.com/Masterminds/semver/v3": "apix-2", | ||
"github.com/PaesslerAG/jsonpath": "apix-2", | ||
"github.com/aws/aws-sdk-go-v2": "apix-2", | ||
"github.com/aws/aws-sdk-go-v2/config": "apix-2", | ||
"github.com/aws/aws-sdk-go-v2/credentials": "apix-2", | ||
"github.com/aws/aws-sdk-go-v2/service/kms": "apix-2", | ||
"github.com/briandowns/spinner": "apix-2", | ||
"github.com/evergreen-ci/shrub": "apix-2", | ||
"github.com/go-test/deep": "apix-2", | ||
"github.com/golang-jwt/jwt/v4": "apix-2", | ||
"github.com/golang/mock": "apix-2", | ||
"github.com/google/go-github/v61": "apix-2", | ||
"github.com/google/uuid": "atlas_kubernetes_team", | ||
"github.com/klauspost/compress": "apix-2", | ||
"github.com/mattn/go-isatty": "apix-2", | ||
"github.com/mongodb-forks/digest": "apix-2", | ||
"github.com/mongodb-labs/cobra2snooty": "apix-2", | ||
"github.com/pelletier/go-toml": "apix-2", | ||
"github.com/Netflix/go-expect": "apix-2", | ||
"github.com/creack/pty": "apix-2", | ||
"github.com/hinshun/vt10x": "apix-2", | ||
"github.com/pkg/browser": "apix-2", | ||
"github.com/spf13/afero": "apix-2", | ||
"github.com/spf13/cobra": "apix-2", | ||
"github.com/spf13/pflag": "apix-2", | ||
"github.com/spf13/viper": "apix-2", | ||
"github.com/stretchr/testify": "apix-2", | ||
"github.com/tangzero/inflector": "apix-2", | ||
"go.mongodb.org/atlas": "apix-2", | ||
"go.mongodb.org/atlas-sdk/v20241113004": "apix-2", | ||
"go.mongodb.org/atlas-sdk/v20240530005": "apix-2", | ||
"go.mongodb.org/atlas-sdk/v20241113001": "apix-2", | ||
"go.mongodb.org/mongo-driver": "apix-2", | ||
"golang.org/x/sys": "apix-2", | ||
"golang.org/x/tools": "apix-2", | ||
"google.golang.org/api": "apix-2", | ||
"google.golang.org/protobuf": "apix-2", | ||
"golang.org/x/mod": "apix-2", | ||
"gopkg.in/yaml.v3": "apix-2", | ||
"github.com/mongodb/mongodb-atlas-kubernetes/v2": "atlas_kubernetes_team", | ||
"k8s.io/api": "atlas_kubernetes_team", | ||
"k8s.io/apimachinery": "atlas_kubernetes_team", | ||
"k8s.io/apiserver": "atlas_kubernetes_team", | ||
"k8s.io/client-go": "atlas_kubernetes_team", | ||
"k8s.io/apiextensions-apiserver": "atlas_kubernetes_team", | ||
"sigs.k8s.io/yaml": "atlas_kubernetes_team", | ||
"sigs.k8s.io/controller-runtime": "atlas_kubernetes_team", | ||
"sigs.k8s.io/kind": "atlas_kubernetes_team", | ||
"golang.org/x/exp": "atlas_kubernetes_team", | ||
"github.com/denisbrodbeck/machineid": "apix-2", | ||
"github.com/shirou/gopsutil/v4": "apix-2", | ||
"go.opentelemetry.io/otel": "apix-2", | ||
"go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc": "apix-2", | ||
"go.opentelemetry.io/otel/sdk": "apix-2", | ||
"go.opentelemetry.io/otel/trace": "apix-2", | ||
"google.golang.org/grpc": "apix-2", | ||
"github.com/mholt/archives": "apix-2" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
// Copyright 2024 MongoDB Inc | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package project | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/kubernetes/operator/features" | ||
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/kubernetes/operator/resources" | ||
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/pointer" | ||
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/store" | ||
akoapi "github.com/mongodb/mongodb-atlas-kubernetes/v2/pkg/api" | ||
akov2 "github.com/mongodb/mongodb-atlas-kubernetes/v2/pkg/api/v1" | ||
akov2common "github.com/mongodb/mongodb-atlas-kubernetes/v2/pkg/api/v1/common" | ||
akov2status "github.com/mongodb/mongodb-atlas-kubernetes/v2/pkg/api/v1/status" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
type CustomRolesRequest struct { | ||
ProjectName string | ||
ProjectID string | ||
TargetNamespace string | ||
Credentials string | ||
Version string | ||
IsIndependent bool | ||
Dict map[string]string | ||
} | ||
|
||
func BuildCustomRoles(provider store.DatabaseRoleLister, request CustomRolesRequest) ([]akov2.AtlasCustomRole, error) { | ||
roles, err := provider.DatabaseRoles(request.ProjectID) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if roles == nil { | ||
return nil, nil | ||
} | ||
|
||
result := make([]akov2.AtlasCustomRole, 0, len(roles)) | ||
|
||
for rIdx := range roles { | ||
role := &roles[rIdx] | ||
|
||
inhRoles := make([]akov2.Role, 0, len(role.GetInheritedRoles())) | ||
for _, rl := range role.GetInheritedRoles() { | ||
inhRoles = append(inhRoles, akov2.Role{ | ||
Name: rl.Role, | ||
Database: rl.Db, | ||
}) | ||
} | ||
|
||
actions := make([]akov2.Action, 0, len(role.GetActions())) | ||
for _, action := range role.GetActions() { | ||
r := make([]akov2.Resource, 0, len(action.GetResources())) | ||
for _, res := range action.GetResources() { | ||
r = append(r, akov2.Resource{ | ||
Cluster: pointer.Get(res.Cluster), | ||
Database: pointer.Get(res.Db), | ||
Collection: pointer.Get(res.Collection), | ||
}) | ||
} | ||
actions = append(actions, akov2.Action{ | ||
Name: action.Action, | ||
Resources: r, | ||
}) | ||
} | ||
|
||
akoRole := akov2.AtlasCustomRole{ | ||
TypeMeta: metav1.TypeMeta{ | ||
Kind: "AtlasCustomRole", | ||
APIVersion: "atlas.mongodb.com/v1", | ||
}, | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: resources.NormalizeAtlasName( | ||
fmt.Sprintf("%s-custom-role-%s", | ||
request.ProjectName, | ||
role.RoleName), | ||
request.Dict), | ||
Namespace: request.TargetNamespace, | ||
Labels: map[string]string{ | ||
features.ResourceVersion: request.Version, | ||
}, | ||
}, | ||
Spec: akov2.AtlasCustomRoleSpec{ | ||
Role: akov2.CustomRole{ | ||
Name: role.RoleName, | ||
InheritedRoles: inhRoles, | ||
Actions: actions, | ||
}, | ||
}, | ||
Status: akov2status.AtlasCustomRoleStatus{ | ||
Common: akoapi.Common{Conditions: []akoapi.Condition{}}, | ||
}, | ||
} | ||
if request.IsIndependent { | ||
akoRole.Spec.ExternalProjectIDRef = &akov2.ExternalProjectReference{ | ||
ID: request.ProjectID, | ||
} | ||
akoRole.Spec.LocalCredentialHolder = akoapi.LocalCredentialHolder{ | ||
ConnectionSecret: &akoapi.LocalObjectReference{ | ||
Name: resources.NormalizeAtlasName(request.Credentials, request.Dict), | ||
}, | ||
} | ||
} else { | ||
akoRole.Spec.ProjectRef = &akov2common.ResourceRefNamespaced{ | ||
Name: request.ProjectName, | ||
Namespace: request.TargetNamespace, | ||
} | ||
} | ||
result = append(result, akoRole) | ||
} | ||
return result, nil | ||
} |
Oops, something went wrong.