-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
kind_resource.go
57 lines (44 loc) · 2.18 KB
/
kind_resource.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
51
52
53
54
55
56
57
package backstage
import (
"context"
"net/http"
)
// KindResource defines name for resource kind.
const KindResource = "Resource"
// ResourceEntityV1alpha1 describes the infrastructure a system needs to operate, like BigTable databases, Pub/Sub topics, S3 buckets
// or CDNs. Modelling them together with components and systems allows to visualize resource footprint, and create tooling around them.
// https://github.com/backstage/backstage/blob/master/packages/catalog-model/src/schema/kinds/Resource.v1alpha1.schema.json
type ResourceEntityV1alpha1 struct {
Entity
// ApiVersion is always "backstage.io/v1alpha1".
ApiVersion string `json:"apiVersion" yaml:"apiVersion"`
// Kind is always "Resource".
Kind string `json:"kind" yaml:"kind"`
// Spec is the specification data describing the resource itself.
Spec *ResourceEntityV1alpha1Spec `json:"spec" yaml:"spec"`
}
// ResourceEntityV1alpha1Spec describes the specification data describing the resource itself.
type ResourceEntityV1alpha1Spec struct {
// Type of resource.
Type string `json:"type" yaml:"type"`
// Owner is an entity reference to the owner of the resource.
Owner string `json:"owner" yaml:"owner"`
// DependsOn is an array of references to other entities that the resource depends on to function.
DependsOn []string `json:"dependsOn,omitempty" yaml:"dependsOn,omitempty"`
// System is an entity reference to the system that the resource belongs to.
System string `json:"system,omitempty" yaml:"system,omitempty"`
}
// resourceService handles communication with the resource related methods of the Backstage Catalog API.
type resourceService typedEntityService[ResourceEntityV1alpha1]
// newResourceService returns a new instance of resource-type entityService.
func newResourceService(s *entityService) *resourceService {
return &resourceService{
client: s.client,
apiPath: s.apiPath,
}
}
// Get returns a resource entity identified by the name and the namespace ("default", if not specified) it belongs to.
func (s *resourceService) Get(ctx context.Context, n string, ns string) (*ResourceEntityV1alpha1, *http.Response, error) {
cs := (typedEntityService[ResourceEntityV1alpha1])(*s)
return cs.get(ctx, KindResource, n, ns)
}