K8s/Annotations: Use manager/source annotations rather than repo (#101313)
Co-authored-by: Stephanie Hingtgen <stephanie.hingtgen@grafana.com>
This commit is contained in:
co-authored by
Stephanie Hingtgen
parent
e7baf9804e
commit
dc2defd84f
@@ -102,7 +102,10 @@ type IndexableDocument struct {
|
||||
References ResourceReferences `json:"reference,omitempty"`
|
||||
|
||||
// When the resource is managed by an upstream repository
|
||||
RepoInfo *utils.ResourceRepositoryInfo `json:"repo,omitempty"`
|
||||
Manager *utils.ManagerProperties `json:"manager,omitempty"`
|
||||
|
||||
// When the manager knows about file paths
|
||||
Source *utils.SourceProperties `json:"source,omitempty"`
|
||||
}
|
||||
|
||||
func (m *IndexableDocument) Type() string {
|
||||
@@ -173,7 +176,14 @@ func NewIndexableDocument(key *ResourceKey, rv int64, obj utils.GrafanaMetaAcces
|
||||
CreatedBy: obj.GetCreatedBy(),
|
||||
UpdatedBy: obj.GetUpdatedBy(),
|
||||
}
|
||||
doc.RepoInfo, _ = obj.GetRepositoryInfo()
|
||||
m, ok := obj.GetManagerProperties()
|
||||
if ok {
|
||||
doc.Manager = &m
|
||||
}
|
||||
s, ok := obj.GetSourceProperties()
|
||||
if ok {
|
||||
doc.Source = &s
|
||||
}
|
||||
ts := obj.GetCreationTimestamp()
|
||||
if !ts.Time.IsZero() {
|
||||
doc.Created = ts.Time.UnixMilli()
|
||||
@@ -265,10 +275,11 @@ const SEARCH_FIELD_CREATED_BY = "createdBy"
|
||||
const SEARCH_FIELD_UPDATED = "updated"
|
||||
const SEARCH_FIELD_UPDATED_BY = "updatedBy"
|
||||
|
||||
const SEARCH_FIELD_REPOSITORY_NAME = "repo.name"
|
||||
const SEARCH_FIELD_REPOSITORY_PATH = "repo.path"
|
||||
const SEARCH_FIELD_REPOSITORY_HASH = "repo.hash"
|
||||
const SEARCH_FIELD_REPOSITORY_TIME = "repo.time"
|
||||
const SEARCH_FIELD_MANAGER_KIND = "manager.kind"
|
||||
const SEARCH_FIELD_MANAGER_ID = "manager.id"
|
||||
const SEARCH_FIELD_SOURCE_PATH = "source.path"
|
||||
const SEARCH_FIELD_SOURCE_CHECKSUM = "source.checksum"
|
||||
const SEARCH_FIELD_SOURCE_TIME = "source.timestampMillis"
|
||||
|
||||
const SEARCH_FIELD_SCORE = "_score" // the match score
|
||||
const SEARCH_FIELD_EXPLAIN = "_explain" // score explanation as JSON object
|
||||
|
||||
@@ -33,17 +33,20 @@ func TestStandardDocumentBuilder(t *testing.T) {
|
||||
"resource": "playlists",
|
||||
"name": "test1"
|
||||
},
|
||||
"name": "test1",
|
||||
"rv": 10,
|
||||
"title": "test playlist unified storage",
|
||||
"title_phrase": "test playlist unified storage",
|
||||
"created": 1717236672000,
|
||||
"createdBy": "user:ABC",
|
||||
"updatedBy": "user:XYZ",
|
||||
"name": "test1",
|
||||
"repo": {
|
||||
"name": "something",
|
||||
"manager": {
|
||||
"kind": "repo",
|
||||
"id": "something"
|
||||
},
|
||||
"source": {
|
||||
"path": "path/in/system.json",
|
||||
"hash": "xyz"
|
||||
"checksum": "xyz"
|
||||
}
|
||||
}`, string(jj))
|
||||
}`, string(jj))
|
||||
}
|
||||
|
||||
@@ -456,12 +456,9 @@ func (s *server) newEvent(ctx context.Context, user claims.AuthInfo, key *Resour
|
||||
}
|
||||
}
|
||||
|
||||
repo, err := obj.GetRepositoryInfo()
|
||||
if err != nil {
|
||||
return nil, NewBadRequestError("invalid repository info")
|
||||
}
|
||||
if repo != nil {
|
||||
err = s.writeHooks.CanWriteValueFromRepository(ctx, user, repo.Name)
|
||||
m, ok := obj.GetManagerProperties()
|
||||
if ok && m.Kind == utils.ManagerKindRepo {
|
||||
err = s.writeHooks.CanWriteValueFromRepository(ctx, user, m.Identity)
|
||||
if err != nil {
|
||||
return nil, AsErrorResult(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user