Help us shape the future of Go! Take the 2026 Go Developer Survey

datahubapi

package
v1.130.3 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2026 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Overview

Package datahubapi serves the portal's DataHub Catalog and Context Docs REST surface (#718): browse/search/read over DataHub connections plus catalog metadata edits and context-document CRUD, gated per-persona. It is a separate package from pkg/portal so the portal package stays within its size budget (#594); it plugs into the portal by registering its routes on the portal mux via a registrar hook, and reads the authenticated user through portal.GetUser.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildConnection

func BuildConnection(client *dhclient.Client, semanticPlatform string, catalogMapping map[string]string, readOnly bool) (Reader, Writer, error)

BuildConnection builds the read (and, when the connection is write-enabled, the write) surfaces for a live DataHub client. A read-only connection returns a nil writer. Both surfaces share the one client.

Types

type Bridge

type Bridge interface {
	Connections() []Connection
	Reader(conn string) (Reader, bool)
	Writer(conn string) (Writer, bool)
}

Bridge exposes read/write access to the configured DataHub connections. Writer returns ok=false for an unknown or read-only connection, so a write against a read-only connection is rejected before any persona check.

type Connection

type Connection struct {
	Name     string `json:"name"`
	Writable bool   `json:"writable"`
}

Connection identifies a DataHub connection the portal can browse, and whether it is write-enabled (a connection with read_only=true is read-only no matter what tools the caller's persona grants).

type Deps

type Deps struct {
	Bridge          Bridge
	PersonaResolver portal.PersonaResolver
	AdminRoles      []string
	Audit           audit.Logger
}

Deps holds the handler dependencies. Bridge is required; Audit and PersonaResolver are optional (nil disables auditing / treats no persona as admin-only access).

type DocumentInput

type DocumentInput struct {
	ID        string `json:"id,omitempty"`
	EntityURN string `json:"entity_urn,omitempty"`
	Title     string `json:"title"`
	Content   string `json:"content"`
	Category  string `json:"category,omitempty"`
}

DocumentInput is a context-document create/update request. An empty ID creates a new document linked to EntityURN; a populated ID updates in place (EntityURN is then ignored, matching the upstream upsert contract).

type Handler

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

Handler serves the portal DataHub REST endpoints.

func NewHandler

func NewHandler(deps Deps) *Handler

NewHandler creates a DataHub REST handler.

func (*Handler) Register

func (h *Handler) Register(mux *http.ServeMux)

Register wires the DataHub REST endpoints (#718) onto the portal mux. Reads are gated on DataHub access on the persona; writes are gated per-persona (datahub_create/update/delete) and require a write-enabled connection.

type Labeler added in v1.119.0

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

Labeler resolves DataHub governance URNs to their display names over the configured connections. A reference carries no connection, so each connection is asked in registration order and the first that knows a URN names it.

func NewLabeler added in v1.119.0

func NewLabeler(bridge Bridge) *Labeler

NewLabeler returns a Labeler over the given bridge.

func (*Labeler) Labels added in v1.119.0

func (l *Labeler) Labels(ctx context.Context, urns []string) map[string]string

Labels returns the display name of each governance URN it could resolve, keyed by URN. A URN of any other kind, one no connection knows, and every URN when the resolve fails or times out are simply absent: the caller keeps its own fallback label rather than being handed a wrong one.

type OwnerChange

type OwnerChange struct {
	OwnerURN      string `json:"owner_urn"`
	OwnershipType string `json:"ownership_type,omitempty"`
}

OwnerChange is an owner to add along with its ownership type.

type Reader

type Reader interface {
	ResolveURN(ctx context.Context, urn string) (*semantic.TableIdentifier, error)
	GetTableContext(ctx context.Context, table semantic.TableIdentifier) (*semantic.TableContext, error)
	GetColumnsContext(ctx context.Context, table semantic.TableIdentifier) (map[string]*semantic.ColumnContext, error)
	SearchTables(ctx context.Context, filter semantic.SearchFilter) ([]semantic.TableSearchResult, error)
	SearchTags(ctx context.Context, query string, limit int) ([]semantic.EntityRef, error)
	SearchGlossaryTerms(ctx context.Context, query string, limit int) ([]semantic.EntityRef, error)
	ListDomains(ctx context.Context) ([]semantic.EntityRef, error)
	ListRootGlossaryNodes(ctx context.Context, offset, limit int) ([]semantic.GlossaryNode, int, error)
	ListRootGlossaryTerms(ctx context.Context, offset, limit int) ([]semantic.GlossaryTerm, int, error)
	ListGlossaryNodeChildren(ctx context.Context, nodeURN string, offset, limit int) (*semantic.GlossaryChildren, error)
	GetGlossaryParentChain(ctx context.Context, urn string) ([]semantic.GlossaryNode, error)
	// GetGlossaryTerm reads one term by URN (#1159). It is the only by-URN read
	// any governance vocabulary has upstream: a tag or a domain resolves only by
	// listing its vocabulary and matching, which is what shapes the label
	// resolver in labels.go and the deep-link paths in the portal.
	GetGlossaryTerm(ctx context.Context, urn string) (*semantic.GlossaryTerm, error)
	SearchDocuments(ctx context.Context, query string, limit int) ([]semantic.DocumentResult, error)
	BrowseDocuments(ctx context.Context, offset, limit int) ([]semantic.DocumentResult, int, error)
	GetDocument(ctx context.Context, urn string) (*semantic.DocumentResult, error)
	// GetRelatedDocuments returns the context documents attached to one entity
	// (#1158), which the corpus-wide browse and search reads cannot express.
	GetRelatedDocuments(ctx context.Context, urn string) ([]semantic.DocumentResult, error)
}

Reader is the read surface the Catalog and Context Docs tabs need over a single DataHub connection. The semantic DataHub adapter (pkg/semantic/datahub) satisfies it directly, so the reader returns the semantic types the enrichment layer already uses rather than a portal-local mirror.

type StaticBridge

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

StaticBridge is a Bridge assembled once at wiring time from a fixed set of per-connection read/write surfaces.

func NewStaticBridge

func NewStaticBridge() *StaticBridge

NewStaticBridge returns an empty StaticBridge ready for Add.

func (*StaticBridge) Add

func (b *StaticBridge) Add(name string, reader Reader, writer Writer)

Add registers a connection's surfaces. A nil writer marks the connection read-only (no writer is exposed for it).

func (*StaticBridge) Connections

func (b *StaticBridge) Connections() []Connection

Connections returns the registered connections.

func (*StaticBridge) Empty

func (b *StaticBridge) Empty() bool

Empty reports whether no connection was added.

func (*StaticBridge) Reader

func (b *StaticBridge) Reader(conn string) (Reader, bool)

Reader returns the read surface for a connection, ok=false if unknown.

func (*StaticBridge) Writer

func (b *StaticBridge) Writer(conn string) (Writer, bool)

Writer returns the write surface for a connection, ok=false if unknown or read-only.

type Writer

type Writer interface {
	UpdateDescription(ctx context.Context, urn, description string) error
	ApplyTagChanges(ctx context.Context, urn string, add, remove []string) error
	ApplyGlossaryTermChanges(ctx context.Context, urn string, add, remove []string) error
	ApplyOwnerChanges(ctx context.Context, urn string, add []OwnerChange, remove []string) error
	SetDomain(ctx context.Context, entityURN, domainURN string) error
	UnsetDomain(ctx context.Context, entityURN string) error
	// CreateGlossaryNode adds a directory to the business glossary, under
	// parentNode or at the root when it is empty, returning the new node's URN
	// (#1155).
	CreateGlossaryNode(ctx context.Context, name, definition, parentNode string) (string, error)
	// CreateGlossaryTerm adds a term to the business glossary, under parentNode
	// or at the root when it is empty, returning the new term's URN (#1158).
	// Editing a term's definition is UpdateDescription with the term's URN,
	// which is why there is no term-specific update here.
	CreateGlossaryTerm(ctx context.Context, name, definition, parentNode string) (string, error)
	// DeleteGlossaryEntity retires a glossary term or node. Upstream is one call
	// for both kinds, and it removes neither a node's children nor a term's
	// assignments, which is why the portal shows both before offering the delete.
	DeleteGlossaryEntity(ctx context.Context, urn string) error
	// CreateTag defines a new tag and returns its URN (#1156). Editing a tag's
	// description is UpdateDescription with the tag's URN, which is why there is
	// no tag-specific update here.
	CreateTag(ctx context.Context, name, description string) (string, error)
	// DeleteTag removes a tag definition. Nothing here checks what still carries
	// the tag, which is why the portal shows a tag's current usage before
	// offering the delete.
	DeleteTag(ctx context.Context, tagURN string) error
	// CreateDomain defines a new domain and returns its URN (#1157). Editing a
	// domain's description is UpdateDescription with the domain's URN, and
	// moving a table into or out of a domain is SetDomain/UnsetDomain, which is
	// why neither has a domain-specific method here.
	CreateDomain(ctx context.Context, name, description string) (string, error)
	// DeleteDomain removes a domain definition. Nothing here clears the domain
	// from the tables that carry it, which is why the portal shows a domain's
	// current membership before offering the delete.
	DeleteDomain(ctx context.Context, domainURN string) error
	UpsertContextDocument(ctx context.Context, in DocumentInput) (*semantic.DocumentResult, error)
	DeleteContextDocument(ctx context.Context, documentID string) error
}

Writer is the write surface for catalog metadata edits and context-doc CRUD over a single write-enabled connection. Tags, glossary terms, and owners are applied as batched add/remove sets rather than per-item calls: per-item writes read-modify-write DataHub's eventually consistent aspects and clobber each other (#721/#729), so the batched forms are the only lossless primitives.

Jump to

Keyboard shortcuts

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