Provisioning: Rename k8s origin metadata to repo (#96524)

This commit is contained in:
Ryan McKinley
2024-11-15 17:26:14 +03:00
committed by GitHub
parent 2e62f75166
commit cc6d057a18
23 changed files with 198 additions and 154 deletions
+5 -5
View File
@@ -60,12 +60,12 @@ func (s *Storage) prepareObjectForStorage(ctx context.Context, newObject runtime
obj.SetResourceVersion("")
obj.SetSelfLink("")
// Read+write will verify that origin format is accurate
origin, err := obj.GetOriginInfo()
// Read+write will verify that repository format is accurate
repo, err := obj.GetRepositoryInfo()
if err != nil {
return nil, err
}
obj.SetOriginInfo(origin)
obj.SetRepositoryInfo(repo)
obj.SetUpdatedBy("")
obj.SetUpdatedTimestamp(nil)
obj.SetCreatedBy(user.GetUID())
@@ -115,11 +115,11 @@ func (s *Storage) prepareObjectForUpdate(ctx context.Context, updateObject runti
obj.SetResourceVersion("") // removed from saved JSON because the RV is not yet calculated
// Read+write will verify that origin format is accurate
origin, err := obj.GetOriginInfo()
repo, err := obj.GetRepositoryInfo()
if err != nil {
return nil, err
}
obj.SetOriginInfo(origin)
obj.SetRepositoryInfo(repo)
obj.SetUpdatedBy(user.GetUID())
obj.SetUpdatedTimestampMillis(time.Now().UnixMilli())
+4 -4
View File
@@ -9,7 +9,7 @@ import (
type WriteAccessHooks struct {
// When configured, this will make sure a user is allowed to save to a given origin
Origin func(ctx context.Context, user claims.AuthInfo, origin string) bool
CanWriteValueFromRepoCheck func(ctx context.Context, user claims.AuthInfo, origin string) bool
}
type LifecycleHooks interface {
@@ -20,11 +20,11 @@ type LifecycleHooks interface {
Stop(context.Context) error
}
func (a *WriteAccessHooks) CanWriteOrigin(ctx context.Context, user claims.AuthInfo, uid string) error {
if a.Origin == nil || uid == "UI" {
func (a *WriteAccessHooks) CanWriteValueFromRepository(ctx context.Context, user claims.AuthInfo, uid string) error {
if a.CanWriteValueFromRepoCheck == nil || uid == "UI" {
return nil // default to OK
}
if !a.Origin(ctx, user, uid) {
if !a.CanWriteValueFromRepoCheck(ctx, user, uid) {
return fmt.Errorf("not allowed to write resource at origin")
}
return nil
+4 -4
View File
@@ -394,12 +394,12 @@ func (s *server) newEvent(ctx context.Context, user claims.AuthInfo, key *Resour
}
}
origin, err := obj.GetOriginInfo()
repo, err := obj.GetRepositoryInfo()
if err != nil {
return nil, NewBadRequestError("invalid origin info")
return nil, NewBadRequestError("invalid repository info")
}
if origin != nil {
err = s.writeHooks.CanWriteOrigin(ctx, user, origin.Name)
if repo != nil {
err = s.writeHooks.CanWriteValueFromRepository(ctx, user, repo.Name)
if err != nil {
return nil, AsErrorResult(err)
}
+6 -6
View File
@@ -60,9 +60,9 @@ func TestSimpleServer(t *testing.T) {
"uid": "xyz",
"namespace": "default",
"annotations": {
"grafana.app/originName": "elsewhere",
"grafana.app/originPath": "path/to/item",
"grafana.app/originTimestamp": "2024-02-02T00:00:00Z"
"grafana.app/repoName": "elsewhere",
"grafana.app/repoPath": "path/to/item",
"grafana.app/repoTimestamp": "2024-02-02T00:00:00Z"
}
},
"spec": {
@@ -176,9 +176,9 @@ func TestSimpleServer(t *testing.T) {
"namespace": "default",
"uid": "xyz",
"annotations": {
"grafana.app/originName": "elsewhere",
"grafana.app/originPath": "path/to/item",
"grafana.app/originTimestamp": "2024-02-02T00:00:00Z"
"grafana.app/repoName": "elsewhere",
"grafana.app/repoPath": "path/to/item",
"grafana.app/repoTimestamp": "2024-02-02T00:00:00Z"
}
},
"spec": {
@@ -8,9 +8,9 @@
"creationTimestamp": "2024-10-30T18:30:54Z",
"annotations": {
"grafana.app/createdBy": "user:be2g71ke8yoe8b",
"grafana.app/originHash": "Grafana v9.2.0 (NA)",
"grafana.app/originName": "UI",
"grafana.app/originPath": "/dashboard/new"
"grafana.app/repoHash": "Grafana v9.2.0 (NA)",
"grafana.app/repoName": "UI",
"grafana.app/repoPath": "/dashboard/new"
},
"managedFields": [
{
@@ -23,9 +23,9 @@
"f:metadata": {
"f:annotations": {
".": {},
"f:grafana.app/originHash": {},
"f:grafana.app/originName": {},
"f:grafana.app/originPath": {}
"f:grafana.app/repoHash": {},
"f:grafana.app/repoName": {},
"f:grafana.app/repoPath": {}
},
"f:generateName": {}
},
@@ -7,10 +7,7 @@
"uid": "86ab200a-e8b0-47ce-bbc1-8c2e078b0956",
"creationTimestamp": "2024-10-30T20:24:07Z",
"annotations": {
"grafana.app/createdBy": "user:be2g71ke8yoe8b",
"grafana.app/originHash": "Grafana v9.2.0 (NA)",
"grafana.app/originName": "UI",
"grafana.app/originPath": "/dashboard/new"
"grafana.app/createdBy": "user:be2g71ke8yoe8b"
},
"managedFields": [
{
@@ -7,10 +7,7 @@
"uid": "86ab200a-e8b0-47ce-bbc1-8c2e078b0956-2",
"creationTimestamp": "2024-10-30T20:24:07Z",
"annotations": {
"grafana.app/createdBy": "user:be2g71ke8yoe8b",
"grafana.app/originHash": "Grafana v9.2.0 (NA)",
"grafana.app/originName": "UI",
"grafana.app/originPath": "/dashboard/new"
"grafana.app/createdBy": "user:be2g71ke8yoe8b"
},
"managedFields": [
{
+1 -4
View File
@@ -7,10 +7,7 @@
"uid": "aaaa-bbbb",
"creationTimestamp": "2024-11-01T19:42:22Z",
"annotations": {
"grafana.app/createdBy": "user:1",
"grafana.app/originName": "SQL",
"grafana.app/originPath": "15",
"grafana.app/originTimestamp": "2024-11-01T19:42:22Z"
"grafana.app/createdBy": "user:1"
}
},
"spec": {
@@ -8,9 +8,9 @@
"creationTimestamp": "2024-11-01T19:42:22Z",
"annotations": {
"grafana.app/createdBy": "user:1",
"grafana.app/originName": "SQL",
"grafana.app/originPath": "15",
"grafana.app/originTimestamp": "2024-11-01T19:42:22Z"
"grafana.app/repoName": "SQL",
"grafana.app/repoPath": "15",
"grafana.app/repoTimestamp": "2024-11-01T19:42:22Z"
}
},
"spec": {
@@ -8,9 +8,9 @@
"creationTimestamp": "2024-11-01T19:42:22Z",
"annotations": {
"grafana.app/createdBy": "user:1",
"grafana.app/originName": "SQL",
"grafana.app/originPath": "15",
"grafana.app/originTimestamp": "2024-11-01T19:42:22Z"
"grafana.app/repoName": "SQL",
"grafana.app/repoPath": "15",
"grafana.app/repoTimestamp": "2024-11-01T19:42:22Z"
}
},
"spec": {