backstage

package
v2.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 3, 2024 License: Apache-2.0 Imports: 9 Imported by: 2

Documentation

Overview

Package backstage provides a client for the Backstage API.

Usage

Add the package to your project as following:

import "github.com/tdabasinskas/go-backstage"

Once imported, create a new Backstage API client to access different parts of Backstage API:

client, err := backstage.NewClient(baseURL, "default", nil)

If you want to use a custom HTTP client (for example, to handle authentication, retries or different timeouts), you can pass it as the third argument:

httpClient := &http.Client{}
client, err := backstage.NewClient(baseURL, "default", httpClient)

The client than can be used to access different parts of the API, e.g. get the list of entities, sorted in specific order:

entities, response, err := c.Catalog.Entities.s.List(context.Background(), &ListEntityOptions{
		Filters: ListEntityFilter{},
		Fields:  []string{},
		Order:   []ListEntityOrder{{ Direction: OrderDescending, Field: "metadata.name" },
	},
})

Index

Constants

View Source
const (
	// OrderAscending is used to order entities in ascending order.
	OrderAscending = "asc"

	// OrderDescending is used to order entities in descending order.
	OrderDescending = "desc"
)
View Source
const (
	DefaultNamespaceName = "default"
)
View Source
const KindAPI = "API"

KindAPI defines name for API kind.

View Source
const KindComponent = "Component"

KindComponent defines name for component kind.

View Source
const KindDomain = "Domain"

KindDomain defines name for domain kind.

View Source
const KindGroup = "Group"

KindGroup defines name for group kind.

View Source
const KindLocation = "Location"

KindLocation defines name for location kind.

View Source
const KindResource = "Resource"

KindResource defines name for resource kind.

View Source
const KindSystem = "System"

KindSystem defines name for system kind.

View Source
const KindUser = "User"

KindUser defines name for user kind.

Variables

This section is empty.

Functions

This section is empty.

Types

type ApiEntityV1alpha1

type ApiEntityV1alpha1 struct {
	Entity

	// ApiVersion is always "backstage.io/v1alpha1".
	ApiVersion string `json:"apiVersion"`

	// Kind is always "API".
	Kind string `json:"kind"`

	// Spec is the specification data describing the API itself.
	Spec *ApiEntityV1alpha1Spec `json:"spec"`
}

ApiEntityV1alpha1 describes an interface that can be exposed by a component. The API can be defined in different formats, like OpenAPI, AsyncAPI, GraphQL, gRPC, or other formats. https://github.com/backstage/backstage/blob/master/packages/catalog-model/src/schema/kinds/API.v1alpha1.schema.json

type ApiEntityV1alpha1Spec added in v2.3.0

type ApiEntityV1alpha1Spec struct {
	// Type of the API definition.
	Type string `json:"type"`

	// Lifecycle state of the API.
	Lifecycle string `json:"lifecycle"`

	// Owner is entity reference to the owner of the API.
	Owner string `json:"owner"`

	// Definition of the API, based on the format defined by the type.
	Definition string `json:"definition"`

	// System is entity reference to the system that the API belongs to.
	System string `json:"system,omitempty"`
}

ApiEntityV1alpha1Spec describes the specification data describing the API itself.

type Client

type Client struct {

	// BaseURL for API requests, e.g. http://localhost:7007/api/.
	BaseURL *url.URL

	// User agent used when communicating with the Backstage API.
	UserAgent string

	// Name of the namespace to use by default when communicating with the Backstage API.
	DefaultNamespace string

	// Catalog service to handle communication with the Backstage Catalog API.
	Catalog *catalogService
	// contains filtered or unexported fields
}

Client manages communication with the Backstage API.

func NewClient

func NewClient(baseURL string, defaultNamespace string, httpClient *http.Client) (*Client, error)

NewClient returns a new Backstage API client. If a nil httpClient is provided, a new http.Client will be used. To use API methods which require authentication, provide a http.Client that will perform the authentication.

type ComponentEntityV1alpha1

type ComponentEntityV1alpha1 struct {
	Entity

	// ApiVersion is always "backstage.io/v1alpha1".
	ApiVersion string `json:"apiVersion"`

	// Kind is always "Component".
	Kind string `json:"kind"`

	// Spec is the specification data describing the component itself.
	Spec *ComponentEntityV1alpha1Spec `json:"spec"`
}

ComponentEntityV1alpha1 describes a software component. It is typically intimately linked to the source code that constitutes the component, and should be what a developer may regard a "unit of software", usually with a distinct deployable or linkable artifact. https://github.com/backstage/backstage/blob/master/packages/catalog-model/src/schema/kinds/Component.v1alpha1.schema.json

type ComponentEntityV1alpha1Spec added in v2.3.0

type ComponentEntityV1alpha1Spec struct {
	// Type of component.
	Type string `json:"type"`

	// Lifecycle state of the component.
	Lifecycle string `json:"lifecycle"`

	// Owner is an entity reference to the owner of the component.
	Owner string `json:"owner"`

	// SubcomponentOf is an entity reference to another component of which the component is a part.
	SubcomponentOf string `json:"subcomponentOf,omitempty"`

	// ProvidesApis is an array of entity references to the APIs that are provided by the component.
	ProvidesApis []string `json:"providesApis,omitempty"`

	// ConsumesApis is an array of entity references to the APIs that are consumed by the component.
	ConsumesApis []string `json:"consumesApis,omitempty"`

	// DependsOn is an array of entity references to the components and resources that the component depends on.
	DependsOn []string `json:"dependsOn,omitempty"`

	// System is an array of references to other entities that the component depends on to function.
	System string `json:"system,omitempty"`
}

ComponentEntityV1alpha1Spec describes the specification data describing the component itself.

type DomainEntityV1alpha1

type DomainEntityV1alpha1 struct {
	Entity

	// ApiVersion is always "backstage.io/v1alpha1".
	ApiVersion string `json:"apiVersion"`

	// Kind is always "Domain".
	Kind string `json:"kind"`

	// Spec is the specification data describing the domain itself.
	Spec *DomainEntityV1alpha1Spec `json:"spec"`
}

DomainEntityV1alpha1 groups a collection of systems that share terminology, domain models, business purpose, or documentation, i.e. form a bounded context. https://github.com/backstage/backstage/blob/master/packages/catalog-model/src/schema/kinds/Domain.v1alpha1.schema.json

type DomainEntityV1alpha1Spec added in v2.3.0

type DomainEntityV1alpha1Spec struct {
	// Owner is an entity reference to the owner of the component.
	Owner string `json:"owner"`
}

DomainEntityV1alpha1Spec describes the specification data describing the domain itself.

type Entity

type Entity struct {
	// ApiVersion is the version of specification format for this particular entity that this is written against.
	ApiVersion string `json:"apiVersion"`

	// Kind is the high level entity type being described.
	Kind string `json:"kind"`

	// Metadata is metadata related to the entity. Should always be "System".
	Metadata EntityMeta `json:"metadata"`

	// Spec is the specification data describing the entity itself.
	Spec map[string]interface{} `json:"spec,omitempty"`

	// Relations that this entity has with other entities.
	Relations []EntityRelation `json:"relations,omitempty"`
}

Entity represents the parts of the format that's common to all versions/kinds of entity. https://github.com/backstage/backstage/blob/master/packages/catalog-model/src/schema/Entity.schema.json

type EntityLink struct {
	// URL in a standard uri format.
	URL string `json:"url"`

	// Title is a user-friendly display name for the link.
	Title string `json:"title,omitempty"`

	// Icon is a key representing a visual icon to be displayed in the UI.
	Icon string `json:"icon,omitempty"`

	// Type is an optional value to categorize links into specific groups.
	Type string `json:"type,omitempty"`
}

EntityLink represents a link to external information that is related to the entity. https://github.com/backstage/backstage/blob/master/packages/catalog-model/src/schema/EntityMeta.schema.json

type EntityMeta

type EntityMeta struct {
	// UID A globally unique ID for the entity. This field can not be set by the user at creation time, and the server will reject
	// an attempt to do so. The field will be populated in read operations.
	UID string `json:"uid,omitempty"`

	// Etag is an opaque string that changes for each update operation to any part of the entity, including metadata. This field
	// can not be set by the user at creation time, and the server will reject an attempt to do so. The field will be populated in read
	// operations.The field can (optionally) be specified when performing update or delete operations, and the server will then reject
	// the operation if it does not match the current stored value.
	Etag string `json:"etag,omitempty"`

	// Name of the entity. Must be unique within the catalog at any given point in time, for any given namespace + kind pair.
	Name string `json:"name"`

	// Namespace that the entity belongs to.
	Namespace string `json:"namespace,omitempty"`

	// Title is a display name of the entity, to be presented in user interfaces instead of the name property, when available.
	Title string `json:"title,omitempty"`

	// Description is a short (typically relatively few words, on one line) description of the entity.
	Description string `json:"description,omitempty"`

	// Labels are key/value pairs of identifying information attached to the entity.
	Labels map[string]string `json:"labels,omitempty"`

	// Annotations are key/value pairs of non-identifying auxiliary information attached to the entity.
	Annotations map[string]string `json:"annotations,omitempty"`

	// Tags is a list of single-valued strings, to for example classify catalog entities in various ways.
	Tags []string `json:"tags,omitempty"`

	// Links is a list of external hyperlinks related to the entity. Links can provide additional contextual
	// information that may be located outside of Backstage itself. For example, an admin dashboard or external CMS page.
	Links []EntityLink `json:"links,omitempty"`
}

EntityMeta represents metadata fields common to all versions/kinds of entity. https://github.com/backstage/backstage/blob/master/packages/catalog-model/src/schema/EntityMeta.schema.json

type EntityRelation

type EntityRelation struct {
	// Type of the relation.
	Type string `json:"type"`

	// TargetRef is the entity ref of the target of this relation.
	TargetRef string `json:"targetRef"`

	// Target is the entity of the target of this relation.
	Target EntityRelationTarget `json:"target"`
}

EntityRelation is a directed relation from one entity to another. https://github.com/backstage/backstage/blob/master/packages/catalog-model/src/schema/shared/common.schema.json

type EntityRelationTarget

type EntityRelationTarget struct {
	// Name of the target entity. Must be unique within the catalog at any given point in time, for any given namespace + kind pair.
	Name string `json:"name"`

	// Kind is the high level target entity type being described.
	Kind string `json:"kind"`

	// Namespace that the target entity belongs to.
	Namespace string `json:"namespace"`
}

EntityRelationTarget describes the target of an entity relation.

type GroupEntityV1alpha1

type GroupEntityV1alpha1 struct {
	Entity

	// ApiVersion is always "backstage.io/v1alpha1".
	ApiVersion string `json:"apiVersion"`

	// Kind is always "Group".
	Kind string `json:"kind"`

	// Spec is the specification data describing the group itself.
	Spec *GroupEntityV1alpha1Spec `json:"spec"`
}

GroupEntityV1alpha1 describes an organizational entity, such as for example a team, a business unit, or a loose collection of people in an interest group. Members of these groups are modeled in the catalog as kind User. https://github.com/backstage/backstage/blob/master/packages/catalog-model/src/schema/kinds/Group.v1alpha1.schema.json

type GroupEntityV1alpha1Spec added in v2.3.0

type GroupEntityV1alpha1Spec struct {
	// Type of group. There is currently no enforced set of values for this field, so it is left up to the adopting
	// organization to choose a nomenclature that matches their org hierarchy.
	Type string `json:"type"`

	// Profile information about the group, mainly for display purposes. All fields of this structure are also optional.
	// The email would be a group email of some form, that the group may wish to be used for contacting them.
	// The picture is expected to be a URL pointing to an image that's representative of the group, and that a browser could
	// fetch and render on a group page or similar.
	Profile struct {
		// DisplayName to present to users.
		DisplayName string `json:"displayName,omitempty"`

		// Email where this entity can be reached.
		Email string `json:"email,omitempty"`

		// Picture is a URL of an image that represents this entity.
		Picture string `json:"picture,omitempty"`
	} `json:"profile,omitempty"`

	// Parent is the immediate parent group in the hierarchy, if any. Not all groups must have a parent; the catalog supports
	// multi-root hierarchies. Groups may however not have more than one parent. This field is an entity reference.
	Parent string `json:"parent,omitempty"`

	// Children contains immediate child groups of this group in the hierarchy (whose parent field points to this group).
	// The list must be present, but may be empty if there are no child groups. The items are not guaranteed to be ordered in
	// any particular way. The entries of this array are entity references.
	Children []string `json:"children"`

	// Members contains users that are members of this group. The entries of this array are entity references.
	Members []string `json:"members,omitempty"`
}

GroupEntityV1alpha1Spec describes the specification data describing the group itself.

type ListEntityOptions

type ListEntityOptions struct {
	// Filters is a set of conditions that can be used to filter entities.
	Filters []string

	// Fields is a set of fields that can be used to limit the response.
	Fields []string

	// Order is a set of conditions that can be used to order entities.
	Order []ListEntityOrder
}

ListEntityOptions specifies the optional parameters to the catalogService.List method.

type ListEntityOrder

type ListEntityOrder struct {
	// Direction is the direction to order by.
	Direction string

	// Field is the field to order by.
	Field string
}

ListEntityOrder defines a condition that can be used to order entities.

type LocationCreateResponse

type LocationCreateResponse struct {
	// Exists is only set in dryRun mode.
	Exists bool `json:"exists,omitempty"`
	// Location contains details of created location.
	Location *LocationResponse `json:"location,omitempty"`
	// Entities is a list of entities that were discovered from the created location.
	Entities []Entity `json:"entities"`
}

LocationCreateResponse defines POST response from location endpoints.

type LocationEntityV1alpha1

type LocationEntityV1alpha1 struct {
	Entity

	// ApiVersion is always "backstage.io/v1alpha1".
	ApiVersion string `json:"apiVersion"`

	// Kind is always "Location".
	Kind string `json:"kind"`

	// Spec is the specification data describing the location itself.
	Spec *LocationEntityV1alpha1Spec `json:"spec"`
}

LocationEntityV1alpha1 is a marker that references other places to look for catalog data. https://github.com/backstage/backstage/blob/master/packages/catalog-model/src/schema/kinds/Location.v1alpha1.schema.json

type LocationEntityV1alpha1Spec added in v2.3.0

type LocationEntityV1alpha1Spec struct {
	// Type is the single location type, that's common to the targets specified in the spec. If it is left out, it is inherited
	// from the location type that originally read the entity data.
	Type string `json:"type,omitempty"`

	// Target as a string. Can be either an absolute path/URL (depending on the type), or a relative path
	// such as./details/catalog-info.yaml which is resolved relative to the location of this Location entity itself.
	Target string `json:"target,omitempty"`

	// Targets contains a list of targets as strings. They can all be either absolute paths/URLs (depending on the type),
	// or relative paths such as ./details/catalog-info.yaml which are resolved relative to the location of this Location
	// entity itself.
	Targets []string `json:"targets,omitempty"`

	// Presence describes whether the presence of the location target is required, and it should be considered an error if it
	// can not be found.
	Presence string `json:"presence,omitempty"`
}

LocationEntityV1alpha1Spec describes the specification data describing the location itself.

type LocationListResponse

type LocationListResponse struct {
	Data *LocationResponse `json:"data"`
}

LocationListResponse defines GET response to get all locations from location endpoints.

type LocationResponse

type LocationResponse struct {
	// ID of the location.
	ID string `json:"id"`
	// Type of the location.
	Type string `json:"type"`
	// Target of the location.
	Target string `json:"target"`
}

LocationResponse defines GET response to get single location from location endpoints.

type ResourceEntityV1alpha1

type ResourceEntityV1alpha1 struct {
	Entity

	// ApiVersion is always "backstage.io/v1alpha1".
	ApiVersion string `json:"apiVersion"`

	// Kind is always "Resource".
	Kind string `json:"kind"`

	// Spec is the specification data describing the resource itself.
	Spec *ResourceEntityV1alpha1Spec `json:"spec"`
}

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 ResourceEntityV1alpha1Spec added in v2.3.0

type ResourceEntityV1alpha1Spec struct {
	// Type of resource.
	Type string `json:"type"`

	// Owner is an entity reference to the owner of the resource.
	Owner string `json:"owner"`

	// DependsOn is an array of references to other entities that the resource depends on to function.
	DependsOn []string `json:"dependsOn,omitempty"`

	// System is an entity reference to the system that the resource belongs to.
	System string `json:"system,omitempty"`
}

ResourceEntityV1alpha1Spec describes the specification data describing the resource itself.

type SystemEntityV1alpha1

type SystemEntityV1alpha1 struct {
	Entity

	// ApiVersion is always "backstage.io/v1alpha1".
	ApiVersion string `json:"apiVersion"`

	// Kind is always "System".
	Kind string `json:"kind"`

	// Spec is the specification data describing the system itself.
	Spec *SystemEntityV1alpha1Spec `json:"spec"`
}

SystemEntityV1alpha1 is a collection of resources and components. The system may expose or consume one or several APIs. It is viewed as abstraction level that provides potential consumers insights into exposed features without needing a too detailed view into the details of all components. This also gives the owning team the possibility to decide about published artifacts and APIs. https://github.com/backstage/backstage/blob/master/packages/catalog-model/src/schema/kinds/System.v1alpha1.schema.json

type SystemEntityV1alpha1Spec added in v2.3.0

type SystemEntityV1alpha1Spec struct {
	// Owner is an entity reference to the owner of the system.
	Owner string `json:"owner"`

	// Domain is an entity reference to the domain that the system belongs to.
	Domain string `json:"domain,omitempty"`
}

SystemEntityV1alpha1Spec describes the specification data describing the system itself.

type UserEntityV1alpha1

type UserEntityV1alpha1 struct {
	Entity

	// ApiVersion is always "backstage.io/v1alpha1".
	ApiVersion string `json:"apiVersion"`

	// Kind is always "User".
	Kind string `json:"kind"`

	// Spec is the specification data describing the user itself.
	Spec *UserEntityV1alpha1Spec `json:"spec"`
}

UserEntityV1alpha1 describes a person, such as an employee, a contractor, or similar. Users belong to Group entities in the catalog. These catalog user entries are connected to the way that authentication within the Backstage ecosystem works. https://github.com/backstage/backstage/blob/master/packages/catalog-model/src/schema/kinds/User.v1alpha1.schema.json

type UserEntityV1alpha1Spec added in v2.3.0

type UserEntityV1alpha1Spec struct {
	// Profile information about the user, mainly for display purposes. All fields of this structure are also optional.
	// The email would be a primary email of some form, that the user may wish to be used for contacting them.
	// The picture is expected to be a URL pointing to an image that's representative of the user, and that a browser could
	// fetch and render on a profile page or similar.
	Profile struct {
		// DisplayName is a simple display name to present to users.
		DisplayName string `json:"displayName,omitempty"`

		// Email where this user can be reached.
		Email string `json:"email,omitempty"`

		// Picture is a URL of an image that represents this user.
		Picture string `json:"picture,omitempty"`
	} `json:"profile,omitempty"`

	// MemberOf is the list of groups that the user is a direct member of (i.e., no transitive memberships are listed here).
	// The list must be present, but may be empty if the user is not member of any groups. The items are not guaranteed to be
	// ordered in any particular way. The entries of this array are entity references.
	MemberOf []string `json:"memberOf,omitempty"`
}

UserEntityV1alpha1Spec describes the specification data describing the user itself.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL