asset

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FieldName            = "name"
	FieldDescription     = "description"
	FieldUserDescription = "user_description"
	FieldTags            = "tags"
	FieldMetadata        = "metadata"
	FieldSchema          = "schema"
	FieldQuery           = "query"
	FieldQueryLanguage   = "query_language"
	FieldSources         = "sources"
	FieldEnvironments    = "environments"
	FieldExternalLinks   = "external_links"
)

Field name constants for change tracking and notifications

Variables

View Source
var (
	ErrInvalidInput  = errors.New("invalid input")
	ErrAssetNotFound = errors.New("asset not found")
	ErrAlreadyExists = errors.New("asset already exists")
)
View Source
var (
	ErrNotFound     = errors.New("asset not found")
	ErrConflict     = errors.New("asset already exists")
	ErrInvalidQuery = errors.New("invalid search query")
)

Functions

This section is empty.

Types

type Asset

type Asset struct {
	ID              string                 `json:"id,omitempty"`
	ParentMRN       *string                `json:"parent_mrn,omitempty"`
	Name            *string                `json:"name,omitempty"`
	Description     *string                `json:"description,omitempty"`
	UserDescription *string                `json:"user_description,omitempty"`
	Type            string                 `json:"type"`
	Providers       []string               `json:"providers"`
	MRN             *string                `json:"mrn,omitempty"`
	Schema          map[string]string      `json:"schema,omitempty"`
	Metadata        map[string]interface{} `json:"metadata,omitempty"`
	Sources         []AssetSource          `json:"sources,omitempty"`
	Tags            []string               `json:"tags,omitempty"`
	Environments    map[string]Environment `json:"environments,omitempty"`
	Query           *string                `json:"query,omitempty"`
	QueryLanguage   *string                `json:"query_language,omitempty"`
	IsStub          bool                   `json:"is_stub"`
	ExternalLinks   []ExternalLink         `json:"external_links,omitempty"`
	HasRunHistory   bool                   `json:"has_run_history"`
	CreatedAt       time.Time              `json:"created_at,omitempty"`
	UpdatedAt       time.Time              `json:"updated_at,omitempty"`
	LastSyncAt      time.Time              `json:"last_sync_at,omitempty"`
	CreatedBy       string                 `json:"created_by,omitempty"`
}

type AssetSource

type AssetSource struct {
	Name       string                 `json:"name"`
	LastSyncAt time.Time              `json:"last_sync_at"`
	Properties map[string]interface{} `json:"properties"`
	Priority   int                    `json:"priority"`
}

func UpdateSources

func UpdateSources(existing, new []AssetSource) []AssetSource

type AssetSummary

type AssetSummary struct {
	Types     map[string]AssetTypeSummary `json:"types"`
	Providers map[string]int              `json:"providers"`
	Tags      map[string]int              `json:"tags"`
}

type AssetTerm added in v0.4.0

type AssetTerm struct {
	TermID            string    `json:"term_id"`
	TermName          string    `json:"term_name"`
	Definition        string    `json:"definition"`
	Source            string    `json:"source"` // "user" or "plugin:name"
	CreatedAt         time.Time `json:"created_at"`
	CreatedBy         *string   `json:"created_by,omitempty"`
	CreatedByUsername *string   `json:"created_by_username,omitempty"`
}

type AssetTypeSummary

type AssetTypeSummary struct {
	Count   int    `json:"count"`
	Service string `json:"service"`
}

type AvailableFilters

type AvailableFilters struct {
	Types     map[string]int `json:"types"`
	Providers map[string]int `json:"providers"`
	Tags      map[string]int `json:"tags"`
}

type CreateInput

type CreateInput struct {
	Name          *string                `json:"name" validate:"required"`
	MRN           *string                `json:"mrn" validate:"required"`
	Type          string                 `json:"type" validate:"required"`
	Providers     []string               `json:"providers" validate:"required"`
	Description   *string                `json:"description"`
	Metadata      map[string]interface{} `json:"metadata"`
	Schema        map[string]string      `json:"schema"`
	Tags          []string               `json:"tags"`
	CreatedBy     string                 `json:"created_by" validate:"required"`
	Sources       []AssetSource          `json:"sources"`
	Environments  map[string]Environment `json:"environments"`
	ExternalLinks []ExternalLink         `json:"external_links"`
	Query         *string                `json:"query,omitempty"`
	QueryLanguage *string                `json:"query_language,omitempty"`
	IsStub        bool                   `json:"is_stub"`
}

type Environment

type Environment struct {
	Name     string                 `json:"name"`
	Path     string                 `json:"path"`
	Metadata map[string]interface{} `json:"metadata,omitempty"`
}
type ExternalLink struct {
	Name string `json:"name"`
	Icon string `json:"icon"`
	URL  string `json:"url"`
}

type Filter

type Filter struct {
	Types        []string   `json:"types,omitempty"`
	Providers    []string   `json:"providers,omitempty"`
	Tags         []string   `json:"tags,omitempty"`
	ParentMRN    *string    `json:"parent_mrn,omitempty"`
	UpdatedAt    *time.Time `json:"updated_at,omitempty"`
	UpdatedAfter *time.Time `json:"updated_after,omitempty"`
	Limit        int        `json:"limit,omitempty"`
	Offset       int        `json:"offset,omitempty"`
	Environment  *string    `json:"environment,omitempty"`
	IncludeStubs bool       `json:"include_stubs,omitempty"`
	OwnerType    *string    `json:"owner_type,omitempty"`
	OwnerID      *string    `json:"owner_id,omitempty"`
}

type HistogramBucket added in v0.3.0

type HistogramBucket struct {
	Date     string `json:"date"`
	Total    int    `json:"total"`
	Complete int    `json:"complete"`
	Fail     int    `json:"fail"`
	Running  int    `json:"running"`
	Abort    int    `json:"abort"`
	Other    int    `json:"other"`
}

type Logger

type Logger interface {
	Info(msg string, fields ...interface{})
	Error(msg string, err error, fields ...interface{})
}

type MembershipObserver added in v0.5.0

type MembershipObserver interface {
	OnAssetCreated(ctx context.Context, asset *Asset)
	OnAssetDeleted(ctx context.Context, assetID string) error
}

MembershipObserver is notified when assets are created or deleted. This allows the data product membership service to update memberships.

type MetadataContext

type MetadataContext struct {
	Query   string            `json:"query"`
	Filters map[string]string `json:"filters"`
}

type MetadataFieldSuggestion

type MetadataFieldSuggestion struct {
	Field     string      `json:"field"`
	Type      string      `json:"type"`
	Count     int         `json:"count"`
	Example   interface{} `json:"example"`
	PathParts []string    `json:"path_parts"`
	Types     []string    `json:"types"`
}

type MetadataValueSuggestion

type MetadataValueSuggestion struct {
	Value   string `json:"value"`
	Count   int    `json:"count"`
	Example *Asset `json:"example,omitempty"`
}

type MetricsClient

type MetricsClient interface {
	Count(name string, value int64, tags ...string)
	Timing(name string, value time.Duration, tags ...string)
}

type NotificationObserver added in v0.6.0

type NotificationObserver interface {
	OnAssetUpdated(ctx context.Context, asset *Asset, changeType string, changedFields []string)
	OnAssetDeleted(ctx context.Context, asset *Asset)
}

NotificationObserver is notified when assets are modified.

type PostgresRepository

type PostgresRepository struct {
	// contains filtered or unexported fields
}

func NewPostgresRepository

func NewPostgresRepository(db *pgxpool.Pool, recorder metrics.Recorder) *PostgresRepository

func (*PostgresRepository) AddTerms added in v0.4.0

func (r *PostgresRepository) AddTerms(ctx context.Context, assetID string, termIDs []string, source string, createdBy string) error

AddTerms associates glossary terms with an asset

func (*PostgresRepository) Create

func (r *PostgresRepository) Create(ctx context.Context, asset *Asset) error

func (*PostgresRepository) Delete

func (r *PostgresRepository) Delete(ctx context.Context, id string) error

func (*PostgresRepository) DeleteByMRN added in v0.3.0

func (r *PostgresRepository) DeleteByMRN(ctx context.Context, mrn string) error

func (*PostgresRepository) Get

func (r *PostgresRepository) Get(ctx context.Context, id string) (*Asset, error)

func (*PostgresRepository) GetAssetsByTerm added in v0.4.0

func (r *PostgresRepository) GetAssetsByTerm(ctx context.Context, termID string, limit, offset int) ([]*Asset, int, error)

GetAssetsByTerm retrieves all assets associated with a glossary term

func (*PostgresRepository) GetByMRN

func (r *PostgresRepository) GetByMRN(ctx context.Context, qualifiedName string) (*Asset, error)

func (*PostgresRepository) GetByMRNs

func (r *PostgresRepository) GetByMRNs(ctx context.Context, mrns []string) ([]*Asset, error)

func (*PostgresRepository) GetByTypeAndName

func (r *PostgresRepository) GetByTypeAndName(ctx context.Context, assetType, name string) (*Asset, error)

func (*PostgresRepository) GetMetadataFields

func (r *PostgresRepository) GetMetadataFields(ctx context.Context) ([]MetadataFieldSuggestion, error)

func (*PostgresRepository) GetMetadataFieldsWithContext

func (r *PostgresRepository) GetMetadataFieldsWithContext(ctx context.Context, queryContext *MetadataContext) ([]MetadataFieldSuggestion, error)

func (*PostgresRepository) GetMetadataValues

func (r *PostgresRepository) GetMetadataValues(ctx context.Context, field string, prefix string, limit int) ([]MetadataValueSuggestion, error)

func (*PostgresRepository) GetMetadataValuesWithContext

func (r *PostgresRepository) GetMetadataValuesWithContext(ctx context.Context, field string, prefix string, limit int, queryContext *MetadataContext) ([]MetadataValueSuggestion, error)

func (*PostgresRepository) GetMyAssets added in v0.4.0

func (r *PostgresRepository) GetMyAssets(ctx context.Context, userID string, teamIDs []string, limit, offset int) ([]*Asset, int, error)

GetMyAssets retrieves assets owned by a user or their teams with a single optimized query

func (*PostgresRepository) GetRunHistory added in v0.3.0

func (r *PostgresRepository) GetRunHistory(ctx context.Context, assetID string, limit, offset int) ([]*RunHistory, int, error)

func (*PostgresRepository) GetRunHistoryHistogram added in v0.3.0

func (r *PostgresRepository) GetRunHistoryHistogram(ctx context.Context, assetID string, days int) ([]HistogramBucket, error)

func (*PostgresRepository) GetTagSuggestions

func (r *PostgresRepository) GetTagSuggestions(ctx context.Context, prefix string, limit int) ([]string, error)

func (*PostgresRepository) GetTerms added in v0.4.0

func (r *PostgresRepository) GetTerms(ctx context.Context, assetID string) ([]AssetTerm, error)

GetTerms retrieves all glossary terms associated with an asset

func (*PostgresRepository) ListByPattern

func (r *PostgresRepository) ListByPattern(ctx context.Context, pattern string, assetType string) ([]*Asset, error)

func (*PostgresRepository) RemoveTerm added in v0.4.0

func (r *PostgresRepository) RemoveTerm(ctx context.Context, assetID string, termID string) error

RemoveTerm removes a glossary term association from an asset

func (*PostgresRepository) Search

func (r *PostgresRepository) Search(ctx context.Context, filter SearchFilter, calculateCounts bool) ([]*Asset, int, AvailableFilters, error)

func (*PostgresRepository) Summary

func (r *PostgresRepository) Summary(ctx context.Context) (*AssetSummary, error)

func (*PostgresRepository) Update

func (r *PostgresRepository) Update(ctx context.Context, asset *Asset) error

type Repository

type Repository interface {
	Create(ctx context.Context, asset *Asset) error
	Get(ctx context.Context, id string) (*Asset, error)
	GetByMRN(ctx context.Context, qualifiedName string) (*Asset, error)
	Search(ctx context.Context, filter SearchFilter, calculateCounts bool) ([]*Asset, int, AvailableFilters, error)
	GetMyAssets(ctx context.Context, userID string, teamIDs []string, limit, offset int) ([]*Asset, int, error)
	Summary(ctx context.Context) (*AssetSummary, error)
	Update(ctx context.Context, asset *Asset) error
	Delete(ctx context.Context, id string) error
	DeleteByMRN(ctx context.Context, mrn string) error
	ListByPattern(ctx context.Context, pattern string, assetType string) ([]*Asset, error)
	GetByMRNs(ctx context.Context, mrns []string) ([]*Asset, error)
	GetByTypeAndName(ctx context.Context, assetType, name string) (*Asset, error)
	GetMetadataFieldsWithContext(ctx context.Context, queryContext *MetadataContext) ([]MetadataFieldSuggestion, error)
	GetMetadataValuesWithContext(ctx context.Context, field string, prefix string, limit int, queryContext *MetadataContext) ([]MetadataValueSuggestion, error)
	GetMetadataFields(ctx context.Context) ([]MetadataFieldSuggestion, error)
	GetMetadataValues(ctx context.Context, field string, prefix string, limit int) ([]MetadataValueSuggestion, error)
	GetTagSuggestions(ctx context.Context, prefix string, limit int) ([]string, error)
	GetRunHistory(ctx context.Context, assetID string, limit, offset int) ([]*RunHistory, int, error)
	GetRunHistoryHistogram(ctx context.Context, assetID string, days int) ([]HistogramBucket, error)

	AddTerms(ctx context.Context, assetID string, termIDs []string, source string, createdBy string) error
	RemoveTerm(ctx context.Context, assetID string, termID string) error
	GetTerms(ctx context.Context, assetID string) ([]AssetTerm, error)
	GetAssetsByTerm(ctx context.Context, termID string, limit, offset int) ([]*Asset, int, error)
}

type RunHistory added in v0.3.0

type RunHistory struct {
	ID           string     `json:"id"`
	RunID        string     `json:"run_id"`
	JobName      string     `json:"job_name"`
	JobNamespace string     `json:"job_namespace"`
	Status       string     `json:"status"`
	StartTime    *time.Time `json:"start_time,omitempty"`
	EndTime      *time.Time `json:"end_time,omitempty"`
	DurationMs   *int64     `json:"duration_ms,omitempty"`
	Type         string     `json:"type"`
	EventTime    time.Time  `json:"event_time"`
}

type SearchFilter

type SearchFilter struct {
	Query        string   `json:"query" validate:"omitempty"`
	Types        []string `json:"types" validate:"omitempty"`
	Providers    []string `json:"providers" validate:"omitempty"`
	Tags         []string `json:"tags" validate:"omitempty"`
	Limit        int      `json:"limit" validate:"omitempty,gte=0"`
	Offset       int      `json:"offset" validate:"omitempty,gte=0"`
	IncludeStubs bool     `json:"include_stubs,omitempty"`
	OwnerType    *string  `json:"owner_type,omitempty"`
	OwnerID      *string  `json:"owner_id,omitempty"`
}

type Service

type Service interface {
	Create(ctx context.Context, input CreateInput) (*Asset, error)
	Get(ctx context.Context, id string) (*Asset, error)
	GetByMRN(ctx context.Context, qualifiedName string) (*Asset, error)
	Search(ctx context.Context, filter SearchFilter, calculateCounts bool) ([]*Asset, int, AvailableFilters, error)
	GetMyAssets(ctx context.Context, userID string, teamIDs []string, limit, offset int) ([]*Asset, int, error)
	Summary(ctx context.Context) (*AssetSummary, error)
	Update(ctx context.Context, id string, input UpdateInput) (*Asset, error)
	Delete(ctx context.Context, id string) error
	DeleteByMRN(ctx context.Context, mrn string) error
	AddTag(ctx context.Context, id string, tag string) (*Asset, error)
	RemoveTag(ctx context.Context, id string, tag string) (*Asset, error)
	ListByPattern(ctx context.Context, pattern string, assetType string) ([]*Asset, error)
	GetByMRNs(ctx context.Context, mrns []string) (map[string]*Asset, error)
	GetByTypeAndName(ctx context.Context, assetType, name string) (*Asset, error)
	GetMetadataFields(ctx context.Context, queryContext *MetadataContext) ([]MetadataFieldSuggestion, error)
	GetMetadataValues(ctx context.Context, field string, prefix string, limit int, queryContext *MetadataContext) ([]MetadataValueSuggestion, error)
	GetTagSuggestions(ctx context.Context, prefix string, limit int) ([]string, error)
	GetRunHistory(ctx context.Context, assetID string, limit, offset int) ([]*RunHistory, int, error)
	GetRunHistoryHistogram(ctx context.Context, assetID string, days int) ([]HistogramBucket, error)

	AddTerms(ctx context.Context, assetID string, termIDs []string, source string, createdBy string) error
	RemoveTerm(ctx context.Context, assetID string, termID string) error
	GetTerms(ctx context.Context, assetID string) ([]AssetTerm, error)
	GetAssetsByTerm(ctx context.Context, termID string, limit, offset int) ([]*Asset, int, error)

	// SetMembershipObserver registers an observer for asset create/delete events.
	SetMembershipObserver(observer MembershipObserver)
	// AddMembershipObserver registers an additional observer for asset create/delete events.
	AddMembershipObserver(observer MembershipObserver)
	// SetNotificationObserver registers an observer for asset update notifications.
	SetNotificationObserver(observer NotificationObserver)
}

func NewService

func NewService(repo Repository, opts ...ServiceOption) Service

type ServiceOption

type ServiceOption func(*service)

func WithMetrics

func WithMetrics(metrics MetricsClient) ServiceOption

type UpdateInput

type UpdateInput struct {
	Name             *string                `json:"name"`
	Description      *string                `json:"description"`
	UserDescription  *string                `json:"user_description"`
	Metadata         map[string]interface{} `json:"metadata"`
	Type             string                 `json:"type"`
	Providers        []string               `json:"providers"`
	Schema           map[string]string      `json:"schema"`
	Tags             []string               `json:"tags"`
	Sources          []AssetSource          `json:"sources"`
	Environments     map[string]Environment `json:"environments"`
	ExternalLinks    []ExternalLink         `json:"external_links"`
	Query            *string                `json:"query,omitempty"`
	QueryLanguage    *string                `json:"query_language,omitempty"`
	SkipNotification bool                   `json:"-"`
}

Jump to

Keyboard shortcuts

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