api

package
v0.0.0-...-b508d79 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2024 License: MIT Imports: 39 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RedirectURICookie = "redirecturi"
	OAuthStateCookie  = "oauthstate"
)

Variables

View Source
var ErrUnauthorized = fmt.Errorf("unauthorized")

Functions

func GetDataproduct

func GetDataproduct(ctx context.Context, id string) (*DataproductWithDataset, *APIError)

func GetDataproducts

func GetDataproducts(ctx context.Context, ids []uuid.UUID) ([]DataproductWithDataset, *APIError)

func GetDataset

func GetDataset(ctx context.Context, id string) (*Dataset, *APIError)

func GetDatasetsMinimal

func GetDatasetsMinimal(ctx context.Context) ([]*DatasetMinimal, *APIError)

func GetProductAreaWithAssets

func GetProductAreaWithAssets(ctx context.Context, id string) (*ProductAreaWithAssets, *APIError)

func GetProductAreas

func GetProductAreas(ctx context.Context) (*ProductAreasDto, *APIError)

func Init

func New

func New(
	repo *database.Repo,
	gcsClient *gcs.Client,
	teamCatalog teamkatalogen.Teamkatalogen,
	httpAPI HTTPAPI,
	authMW auth.MiddlewareHandler,
	gqlServer *handler.Server,
	promReg *prometheus.Registry,
	amplitudeClient amplitude.Amplitude,
	teamTokenCreds string,
	log *logrus.Logger,
) *chi.Mux
func Search(ctx context.Context, query *SearchOptions) (*SearchResult, *APIError)

func TrimNaisTeamPrefix

func TrimNaisTeamPrefix(team string) string

Types

type APIError

type APIError struct {
	HttpStatus int
	Err        error
	Message    string
}

func DBErrorToAPIError

func DBErrorToAPIError(err error, message string) *APIError

func NewAPIError

func NewAPIError(status int, err error, message string) *APIError

func NewInternalError

func NewInternalError(err error, message string) *APIError

func RotateNadaToken

func RotateNadaToken(ctx context.Context, team string) *APIError

func SearchTeamKatalogen

func SearchTeamKatalogen(ctx context.Context, gcpGroups []string) ([]teamkatalogen.TeamkatalogenResult, *APIError)

func (*APIError) Error

func (e *APIError) Error() string

func (*APIError) Log

func (e *APIError) Log()

type Access

type Access struct {
	ID              uuid.UUID  `json:"id"`
	Subject         string     `json:"subject"`
	Granter         string     `json:"granter"`
	Expires         *time.Time `json:"expires"`
	Created         time.Time  `json:"created"`
	Revoked         *time.Time `json:"revoked"`
	DatasetID       uuid.UUID  `json:"datasetID"`
	AccessRequestID *uuid.UUID `json:"accessRequestID"`
}

type AccessRequest

type AccessRequest struct {
	ID          uuid.UUID           `json:"id"`
	DatasetID   uuid.UUID           `json:"datasetID"`
	Subject     string              `json:"subject"`
	SubjectType string              `json:"subjectType"`
	Created     time.Time           `json:"created"`
	Status      AccessRequestStatus `json:"status"`
	Closed      *time.Time          `json:"closed"`
	Expires     *time.Time          `json:"expires"`
	Granter     *string             `json:"granter"`
	Owner       string              `json:"owner"`
	Polly       *Polly              `json:"polly"`
	Reason      *string             `json:"reason"`
}

type AccessRequestForGranter

type AccessRequestForGranter struct {
	AccessRequest
	DataproductID   uuid.UUID `json:"dataproductID"`
	DataproductSlug string    `json:"dataproductSlug"`
	DatasetName     string    `json:"datasetName"`
	DataproductName string    `json:"dataproductName"`
}

type AccessRequestStatus

type AccessRequestStatus string
const (
	AccessRequestStatusPending  AccessRequestStatus = "pending"
	AccessRequestStatusApproved AccessRequestStatus = "approved"
	AccessRequestStatusDenied   AccessRequestStatus = "denied"
)

type AccessRequestsWrapper

type AccessRequestsWrapper struct {
	AccessRequests []AccessRequest `json:"accessRequests"`
}

type AccessibleDataset

type AccessibleDataset struct {
	Dataset
	DataproductName string `json:"dataproductName"`
	Slug            string `json:"slug"`
	DpSlug          string `json:"dpSlug"`
	Group           string `json:"group"`
}

type AccessibleDatasets

type AccessibleDatasets struct {
	// owned
	Owned []*AccessibleDataset `json:"owned"`
	// granted
	Granted []*AccessibleDataset `json:"granted"`
}

type BQColumns

type BQColumns struct {
	BQColumns []*bqclient.BigqueryColumn `json:"bqColumns"`
}

type BQDatasets

type BQDatasets struct {
	BQDatasets []string `json:"bqDatasets"`
}

type BQTables

type BQTables struct {
	BQTables []*bqclient.BigQueryTable `json:"bqTables"`
}

type BigQuery

type BigQuery struct {
	ID            uuid.UUID
	DatasetID     uuid.UUID
	ProjectID     string                     `json:"projectID"`
	Dataset       string                     `json:"dataset"`
	Table         string                     `json:"table"`
	TableType     bqclient.BigQueryType      `json:"tableType"`
	LastModified  time.Time                  `json:"lastModified"`
	Created       time.Time                  `json:"created"`
	Expires       *time.Time                 `json:"expired"`
	Description   string                     `json:"description"`
	PiiTags       *string                    `json:"piiTags"`
	MissingSince  *time.Time                 `json:"missingSince"`
	PseudoColumns []string                   `json:"pseudoColumns"`
	Schema        []*bqclient.BigqueryColumn `json:"schema"`
}

type Dataproduct

type Dataproduct struct {
	ID              uuid.UUID         `json:"id"`
	Name            string            `json:"name"`
	Created         time.Time         `json:"created"`
	LastModified    time.Time         `json:"lastModified"`
	Description     *string           `json:"description"`
	Slug            string            `json:"slug"`
	Owner           *DataproductOwner `json:"owner"`
	Keywords        []string          `json:"keywords"`
	TeamName        *string           `json:"teamName"`
	ProductAreaName string            `json:"productAreaName"`
}

type DataproductOwner

type DataproductOwner struct {
	Group            string  `json:"group"`
	TeamkatalogenURL *string `json:"teamkatalogenURL"`
	TeamContact      *string `json:"teamContact"`
	TeamID           *string `json:"teamID"`
}

type DataproductWithDataset

type DataproductWithDataset struct {
	Dataproduct
	Datasets []*DatasetInDataproduct `json:"datasets"`
}

func (DataproductWithDataset) IsSearchResult

func (DataproductWithDataset) IsSearchResult()

type Dataset

type Dataset struct {
	ID                       uuid.UUID `json:"id"`
	DataproductID            uuid.UUID `json:"dataproductID"`
	Name                     string    `json:"name"`
	Created                  time.Time `json:"created"`
	LastModified             time.Time `json:"lastModified"`
	Description              *string   `json:"description"`
	Slug                     string    `json:"slug"`
	Repo                     *string   `json:"repo"`
	Pii                      PiiLevel  `json:"pii"`
	Keywords                 []string  `json:"keywords"`
	AnonymisationDescription *string   `json:"anonymisationDescription"`
	TargetUser               *string   `json:"targetUser"`
	Access                   []*Access `json:"access"`
	Mappings                 []string  `json:"mappings"`
	Datasource               *BigQuery `json:"datasource"`
	MetabaseUrl              *string   `json:"metabaseUrl"`
}

func (Dataset) IsSearchResult

func (Dataset) IsSearchResult()

type DatasetInDataproduct

type DatasetInDataproduct struct {
	ID                     uuid.UUID `json:"id"`
	DataproductID          uuid.UUID `json:"-"`
	Name                   string    `json:"name"`
	Created                time.Time `json:"created"`
	LastModified           time.Time `json:"lastModified"`
	Description            *string   `json:"description"`
	Slug                   string    `json:"slug"`
	Keywords               []string  `json:"keywords"`
	DataSourceLastModified time.Time `json:"dataSourceLastModified"`
}

type DatasetMinimal

type DatasetMinimal struct {
	ID              uuid.UUID `json:"id"`
	Name            string    `json:"name"`
	Created         time.Time `json:"created"`
	BigQueryProject string    `json:"project"`
	BigQueryDataset string    `json:"dataset"`
	BigQueryTable   string    `json:"table"`
}

type DatasourceType

type DatasourceType string

type GCPProject

type GCPProject struct {
	ID    string      `json:"id"`
	Name  string      `json:"name"`
	Group *auth.Group `json:"group"`
}

type HTTP

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

func NewHTTP

func NewHTTP(oauth2Config OAuth2, callbackURL string, repo *database.Repo, log *logrus.Entry) HTTP

func (HTTP) Callback

func (h HTTP) Callback(w http.ResponseWriter, r *http.Request)

func (HTTP) Login

func (h HTTP) Login(w http.ResponseWriter, r *http.Request)

func (HTTP) Logout

func (h HTTP) Logout(w http.ResponseWriter, r *http.Request)

type HTTPAPI

type HTTPAPI interface {
	Login(w http.ResponseWriter, r *http.Request)
	Callback(w http.ResponseWriter, r *http.Request)
	Logout(w http.ResponseWriter, r *http.Request)
}

type InsightProduct

type InsightProduct struct {
	// id of the insight product.
	ID uuid.UUID `json:"id"`
	// name of the insight product.
	Name string `json:"name"`
	// creator of the insight product.
	Creator string `json:"creator"`
	// description of the insight product.
	Description string `json:"description"`
	// type of the insight product.
	Type string `json:"type"`
	// link to the insight product.
	Link string `json:"link"`
	// keywords for the insight product used as tags.
	Keywords []string `json:"keywords"`
	// group is the owner group of the insight product
	Group string `json:"group"`
	// teamkatalogenURL of the creator
	TeamkatalogenURL *string `json:"teamkatalogenURL,omitempty"`
	// Id of the creator's team.
	TeamID *string `json:"teamID,omitempty"`
	// created is the timestamp for when the insight product was created
	Created time.Time `json:"created"`
	// lastModified is the timestamp for when the insight product was last modified
	LastModified    *time.Time `json:"lastModified,omitempty"`
	TeamName        *string    `json:"teamName"`
	ProductAreaName string     `json:"productAreaName"`
}

InsightProduct contains the metadata of insight product.

type KeywordItem

type KeywordItem struct {
	Keyword string `json:"keyword"`
	Count   int    `json:"count"`
}

type KeywordsList

type KeywordsList struct {
	KeywordItems []KeywordItem `json:"keywordItems"`
}

type Middleware

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

Middleware is a handler that exposes prometheus metrics for the number of requests, the latency and the response size, partitioned by status code, method and HTTP path.

func PrometheusMiddleware

func PrometheusMiddleware(name string, buckets ...float64) *Middleware

NewMiddleware returns a new prometheus Middleware handler.

func (*Middleware) Handler

func (m *Middleware) Handler() middleware

func (*Middleware) Initialize

func (m *Middleware) Initialize(path, method string, code int)

type MockHTTP

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

func NewMockHTTP

func NewMockHTTP(repo *database.Repo, log *logrus.Entry) *MockHTTP

func (*MockHTTP) Callback

func (h *MockHTTP) Callback(w http.ResponseWriter, r *http.Request)

func (MockHTTP) Login

func (h MockHTTP) Login(w http.ResponseWriter, r *http.Request)

func (*MockHTTP) Logout

func (h *MockHTTP) Logout(w http.ResponseWriter, r *http.Request)

func (*MockHTTP) Middleware

func (h *MockHTTP) Middleware(next http.Handler) http.Handler

type NadaToken

type NadaToken struct {
	Team  string    `json:"team"`
	Token uuid.UUID `json:"token"`
}

type OAuth2

type OAuth2 interface {
	Exchange(ctx context.Context, code string, opts ...oauth2.AuthCodeOption) (*oauth2.Token, error)
	AuthCodeURL(state string, opts ...oauth2.AuthCodeOption) string
	Verify(ctx context.Context, rawIDToken string) (*oidc.IDToken, error)
}

type PiiLevel

type PiiLevel string

type Polly

type Polly struct {
	ID uuid.UUID `json:"id"`
	QueryPolly
}

type PollyInput

type PollyInput struct {
	ID *uuid.UUID `json:"id"`
	QueryPolly
}

type ProductArea

type ProductArea struct {
	teamkatalogen.ProductArea
	Teams        []Team `json:"teams"`
	DashboardURL string `json:"dashboardURL"`
}

type ProductAreaWithAssets

type ProductAreaWithAssets struct {
	ProductArea
	Teams []TeamWithAssets `json:"teams"`
}

type ProductAreasDto

type ProductAreasDto struct {
	ProductAreas []ProductArea `json:"productAreas"`
}

type QueryPolly

type QueryPolly struct {
	ExternalID string `json:"external_id"`
	Name       string `json:"name"`
	URL        string `json:"url"`
}

type ResultItem

type ResultItem interface {
	IsSearchResult()
}

type SearchOptions

type SearchOptions struct {
	// Freetext search
	Text string `json:"text"`
	// Filter on keyword
	Keywords []string `json:"keywords"`
	// Filter on group
	Groups []string `json:"groups"`
	//Filter on team_id
	TeamIDs []string `json:"teamIDs"`
	// Filter on enabled services
	Services []string `json:"services"`
	// Filter on types
	Types []string `json:"types"`

	Limit  *int `json:"limit"`
	Offset *int `json:"offset"`
}

type SearchResult

type SearchResult struct {
	Results []*SearchResultRow `json:"results"`
}

type SearchResultRow

type SearchResultRow struct {
	Excerpt string     `json:"excerpt"`
	Result  ResultItem `json:"result"`
	Rank    float64    `json:"rank"`
}

type Story

type Story struct {
	// id of the data story.
	ID uuid.UUID `json:"id"`
	// name of the data story.
	Name string `json:"name"`
	// creator of the data story.
	Creator string `json:"creator"`
	// description of the data story.
	Description string `json:"description"`
	// keywords for the story used as tags.
	Keywords []string `json:"keywords"`
	// teamkatalogenURL of the creator.
	TeamkatalogenURL *string `json:"teamkatalogenURL"`
	// Id of the creator's team.
	TeamID *string `json:"teamID"`
	// created is the timestamp for when the data story was created.
	Created time.Time `json:"created"`
	// lastModified is the timestamp for when the dataproduct was last modified.
	LastModified *time.Time `json:"lastModified"`
	// group is the owner group of the data story.
	Group           string  `json:"group"`
	TeamName        *string `json:"teamName"`
	ProductAreaName string  `json:"productAreaName"`
}

Story contains the metadata and content of data stories.

func (Story) IsSearchResult

func (Story) IsSearchResult()

type Team

type Team struct {
	teamkatalogen.Team
	DataproductsNumber    int `json:"dataproductsNumber"`
	StoriesNumber         int `json:"storiesNumber"`
	InsightProductsNumber int `json:"insightProductsNumber"`
}

type TeamWithAssets

type TeamWithAssets struct {
	teamkatalogen.Team
	Dataproducts    []Dataproduct    `json:"dataproducts"`
	Stories         []Story          `json:"stories"`
	InsightProducts []InsightProduct `json:"insightProducts"`
	DashboardURL    string           `json:"dashboardURL"`
}

type UserInfo

type UserInfo struct {
	// name of user
	Name string `json:"name"`

	// email of user.
	Email string `json:"email"`

	// googleGroups is the google groups the user is member of.
	GoogleGroups auth.Groups `json:"googleGroups"`

	// allGoogleGroups is the all the known google groups of the user domains.
	AllGoogleGroups auth.Groups `json:"allGoogleGroups"`

	// azureGroups is the azure groups the user is member of.
	AzureGroups auth.Groups `json:"azureGroups"`

	// gcpProjects is GCP projects the user is a member of.
	GcpProjects []GCPProject `json:"gcpProjects"`

	// nadaTokens is a list of the nada tokens for each team the logged in user is a part of.
	NadaTokens []NadaToken `json:"nadaTokens"`

	// loginExpiration is when the token expires.
	LoginExpiration time.Time `json:"loginExpiration"`

	// dataproducts is a list of dataproducts with one of the users groups as owner.
	Dataproducts []Dataproduct `json:"dataproducts"`

	// accessable is a list of datasets which the user has either owns or has explicit access to.
	Accessable AccessibleDatasets `json:"accessable"`

	// stories is the stories owned by the user's group
	Stories []Story `json:"stories"`

	// insight products is the insight products owned by the user's group
	InsightProducts []InsightProduct `json:"insightProducts"`

	// accessRequests is a list of access requests where either the user or one of the users groups is owner.
	AccessRequests []AccessRequest `json:"accessRequests"`

	//accessRequestsAsGranter is a list of access requests where one of the users groups is obliged to handle.
	AccessRequestsAsGranter []AccessRequestForGranter `json:"accessRequestsAsGranter"`
}

Jump to

Keyboard shortcuts

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