|
| 1 | +// |
| 2 | +// DISCLAIMER |
| 3 | +// |
| 4 | +// Copyright 2025 ArangoDB GmbH, Cologne, Germany |
| 5 | +// |
| 6 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | +// you may not use this file except in compliance with the License. |
| 8 | +// You may obtain a copy of the License at |
| 9 | +// |
| 10 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +// |
| 12 | +// Unless required by applicable law or agreed to in writing, software |
| 13 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | +// See the License for the specific language governing permissions and |
| 16 | +// limitations under the License. |
| 17 | +// |
| 18 | +// Copyright holder is ArangoDB GmbH, Cologne, Germany |
| 19 | +// |
| 20 | + |
| 21 | +package definition |
| 22 | + |
| 23 | +import ( |
| 24 | + shared "github.com/arangodb/kube-arangodb/pkg/apis/shared" |
| 25 | + "github.com/arangodb/kube-arangodb/pkg/util" |
| 26 | +) |
| 27 | + |
| 28 | +func (x *AuthorizationV1PermissionRequest) Validate() error { |
| 29 | + if x == nil { |
| 30 | + x = &AuthorizationV1PermissionRequest{} |
| 31 | + } |
| 32 | + |
| 33 | + return shared.WithErrors( |
| 34 | + shared.PrefixResourceErrorFunc("user", func() error { |
| 35 | + return validateActionName(x.User) |
| 36 | + }), |
| 37 | + shared.PrefixResourceError("roles", shared.ValidateList(x.Roles, func(s string) error { |
| 38 | + return validateActionName(s) |
| 39 | + })), |
| 40 | + shared.PrefixResourceErrorFunc("action", func() error { |
| 41 | + return validateActionName(x.Action) |
| 42 | + }), |
| 43 | + shared.PrefixResourceErrorFunc("resource", func() error { |
| 44 | + return shared.ValidateRequiredNotEmpty(&x.Resource) |
| 45 | + }), |
| 46 | + ) |
| 47 | +} |
| 48 | + |
| 49 | +func (x *AuthorizationV1PermissionRequest) Hash() string { |
| 50 | + if x == nil { |
| 51 | + return "" |
| 52 | + } |
| 53 | + return util.SHA256FromStringMap(map[string]string{ |
| 54 | + "user": util.SHA256FromString(x.GetUser()), |
| 55 | + "roles": util.SHA256FromStringArray(x.GetRoles()...), |
| 56 | + "action": util.SHA256FromString(x.GetAction()), |
| 57 | + "resource": util.SHA256FromString(x.GetResource()), |
| 58 | + }) |
| 59 | +} |
0 commit comments