-
Notifications
You must be signed in to change notification settings - Fork 104
/
app_meta.go
50 lines (37 loc) · 1.06 KB
/
app_meta.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Copyright 2020 VMware, Inc.
// SPDX-License-Identifier: Apache-2.0
package app
import (
"encoding/json"
"fmt"
"k8s.io/apimachinery/pkg/runtime/schema"
)
type Meta struct {
LabelKey string `json:"labelKey"`
LabelValue string `json:"labelValue"`
LastChangeName string `json:"lastChangeName,omitempty"`
LastChange ChangeMeta `json:"lastChange,omitempty"`
UsedGVs []schema.GroupVersion `json:"usedGVs,omitempty"`
UsedGKs *[]schema.GroupKind `json:"usedGKs,omitempty"`
}
func NewAppMetaFromData(data map[string]string) (Meta, error) {
var meta Meta
err := json.Unmarshal([]byte(data["spec"]), &meta)
if err != nil {
return Meta{}, fmt.Errorf("Parsing app metadata: %w", err)
}
return meta, nil
}
func (m Meta) AsString() string {
bytes, err := json.Marshal(m)
if err != nil {
panic(fmt.Sprintf("Encoding app meta: %s", err))
}
return string(bytes)
}
func (m Meta) AsData() map[string]string {
return map[string]string{"spec": m.AsString()}
}
func (m Meta) Labels() map[string]string {
return map[string]string{m.LabelKey: m.LabelValue}
}