common

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package common provides common libraries for the service.

Index

Constants

View Source
const (
	// CELAttributeResourceEnvironmentID is the environment ID of the resource.
	CELAttributeResourceEnvironmentID = "resource.environment_id"
	// CELAttributeResourceSchemaName is the schema name of the resource.
	CELAttributeResourceSchemaName = "resource.schema_name"
	// CELAttributeResourceTableName is the table name of the resource.
	CELAttributeResourceTableName = "resource.table_name"
	// CELAttributeResourceDatabase is the full database name of the resource (used in IAM policy conditions).
	CELAttributeResourceDatabase = "resource.database"
	// CELAttributeRequestTime is the timestamp of the request.
	CELAttributeRequestTime = "request.time"
)

CEL attribute names used by IAM policy conditions.

View Source
const (
	WorkspaceAdmin  = "workspaceAdmin"
	WorkspaceMember = "workspaceMember"
)
View Source
const (
	// SystemBotID is the ID of the system robot.
	SystemBotID = 1

	// AllUsers is the email of the pseudo allUsers account.
	AllUsers = "allUsers"

	// ServiceAccountAccessKeyPrefix is the prefix for service account access key.
	ServiceAccountAccessKeyPrefix = "sa_"
)
View Source
const (
	DefaultMetaSubLevelLimit = 21

	// MetaGUIDSplit is the separator for GUID in meta queries.
	MetaGUIDSplit = ";"
)
View Source
const (
	WorkspacePrefix            = "workspaces/"
	EnvironmentNamePrefix      = "environments/"
	InstanceNamePrefix         = "instances/"
	DatabaseIDPrefix           = "databases/"
	UserNamePrefix             = "users/"
	IdentityProviderNamePrefix = "idps/"
	RolePrefix                 = "roles/"
	GroupPrefix                = "groups/"
	DataSourceIDPrefix         = "dataSources/"
	NamespaceMappingPrefix     = "openlineage/namespaceMappings/"
	OpenLineageRunPrefix       = "openlineage/runs/"
	OpenLineageTaskPrefix      = "openlineage/tasks/"
	APIKeyPrefix               = "openlineage/apiKeys/"
	ApplicationNamePrefix      = "applications/"
	NotificationPrefix         = "notifications/"
)

nolint:revive

View Source
const DefaultInstanceMaximumConnections = 10

DefaultInstanceMaximumConnections is the maximum number of connections outstanding per instance by default.

Variables

IAMPolicyConditionCELAttributes are the variables when evaluating IAM policy condition.

View Source
var ProtojsonUnmarshaler = protojson.UnmarshalOptions{DiscardUnknown: true}

ProtojsonMarshaler is a global protojson marshaler with DiscardUnknown set to true.

Functions

func BuildMetaGUID

func BuildMetaGUID(parts ...string) string

BuildMetaGUID joins segments into a meta GUID. Every builder must use it (and every parser SplitMetaGUID) so the escaping stays symmetric.

func EscapeGUIDPart

func EscapeGUIDPart(part string) string

EscapeGUIDPart escapes the GUID separator inside one segment, so a name that contains ";" cannot shift the fields a parser reads out of a GUID.

func EvalBindingCondition

func EvalBindingCondition(expr string, requestTime time.Time) (bool, error)

EvalBindingCondition reports whether the binding condition holds. A condition that cannot be decided from the bound variables is reported as an error rather than as satisfied: see doEvalBindingCondition.

func FormatAPIKey

func FormatAPIKey(id int64) string

FormatAPIKey formats an API key resource name.

func FormatApplication

func FormatApplication(applicationID string) string

FormatApplication formats an application resource name.

func FormatApplicationAPIKey

func FormatApplicationAPIKey(applicationID string, keyID int64) string

FormatApplicationAPIKey formats a reporting key's resource name, which is nested under the application that owns it.

func FormatDBErrorEmptyRowWithQuery

func FormatDBErrorEmptyRowWithQuery(query string) error

FormatDBErrorEmptyRowWithQuery formats database error that query returns empty row.

func FormatDataSource

func FormatDataSource(instanceID, dataSourceID string) string

FormatDataSource formats a data source resource name.

func FormatDatabase

func FormatDatabase(instance string, database string) string

func FormatEnvironment

func FormatEnvironment(resourceID string) string

func FormatGroupEmail

func FormatGroupEmail(email string) string

func FormatIdentityProviderUID

func FormatIdentityProviderUID(idpID string) string

FormatIdentityProviderUID returns the idps/{idp} resource name of an identity provider, the form the settings API and the login request name one in.

func FormatInstance

func FormatInstance(resourceID string) string

func FormatNamespaceMapping

func FormatNamespaceMapping(id int64) string

FormatNamespaceMapping formats a namespace mapping resource name.

func FormatNotification

func FormatNotification(workspaceID string, id int64) string

FormatNotification formats a notification resource name.

func FormatOpenLineageRun

func FormatOpenLineageRun(guid string) string

FormatOpenLineageRun formats an OpenLineage run resource name.

func FormatOpenLineageTask

func FormatOpenLineageTask(guid string) string

FormatOpenLineageTask formats an OpenLineage task resource name.

func FormatRole

func FormatRole(role string) string

func FormatUserUID

func FormatUserUID(uid int) string

func FormatWorkspace

func FormatWorkspace(id string) string

func GUIDPrefix

func GUIDPrefix(guid string) string

GUIDPrefix returns the parent prefix of a GUID: the GUID without its last MetaGUIDSplit-separated segment. It returns "" when the GUID has no parent segment.

func GetAPIKeyID

func GetAPIKeyID(name string) (int64, error)

GetAPIKeyID returns the API key ID from its resource name.

func GetApplicationAPIKeyID

func GetApplicationAPIKeyID(name string) (string, int64, error)

GetApplicationAPIKeyID returns the application id and the numeric key id from a key's resource name.

func GetApplicationID

func GetApplicationID(name string) (string, error)

GetApplicationID returns the application id from a resource name, for a report that names the credential's owner.

func GetEnvironmentID

func GetEnvironmentID(name string) (string, error)

GetEnvironmentID returns the environment ID from a resource name.

func GetGroupEmail

func GetGroupEmail(name string) (string, error)

GetGroupEmail returns the group email.

func GetIdentityProviderID

func GetIdentityProviderID(name string) (string, error)

GetIdentityProviderID returns the identity provider ID from a resource name.

func GetInstanceDataSourceID

func GetInstanceDataSourceID(name string) (string, string, error)

GetInstanceDataSourceID returns the instance and data source IDs from a data source resource name.

func GetInstanceDatabaseID

func GetInstanceDatabaseID(name string) (string, string, error)

GetInstanceDatabaseID returns the instance ID and database ID from a resource name.

func GetInstanceFromGUID

func GetInstanceFromGUID(guid string) (string, bool)

func GetInstanceID

func GetInstanceID(name string) (string, error)

GetInstanceID returns the instance ID from a resource name.

func GetNameParentTokens

func GetNameParentTokens(name string, tokenPrefixes ...string) ([]string, error)

GetNameParentTokens returns the tokens from a resource name.

func GetNamespaceMappingID

func GetNamespaceMappingID(name string) (int64, error)

GetNamespaceMappingID returns the namespace mapping ID from its resource name.

func GetNotificationID

func GetNotificationID(name string) (int64, error)

GetNotificationID returns the notification ID from its resource name.

func GetOpenLineageIntID

func GetOpenLineageIntID(name, prefix string) (int64, error)

GetOpenLineageIntID returns the numeric resource ID of a top-level OpenLineage resource name.

func GetOpenLineageRunGUID

func GetOpenLineageRunGUID(name string) (string, error)

GetOpenLineageRunGUID returns the run GUID from its resource name.

func GetOpenLineageTaskGUID

func GetOpenLineageTaskGUID(name string) (string, error)

GetOpenLineageTaskGUID returns the task GUID from its resource name.

func GetOpenLineageToken

func GetOpenLineageToken(name, prefix string) (string, error)

GetOpenLineageToken returns the last segment of an OpenLineage resource name.

func GetRoleID

func GetRoleID(name string) (string, error)

GetRoleID returns the role ID from a role resource name (`roles/{role}`).

func GetSchemaFromGUID

func GetSchemaFromGUID(guid string) (string, bool)

func GetUIDFromName

func GetUIDFromName(name, prefix string) (int, error)

GetUIDFromName returns the UID from a resource name.

func GetUserEmail

func GetUserEmail(name string) (string, error)

GetUserEmail returns the user email from a resource name.

func GetUserID

func GetUserID(name string) (int, error)

GetUserID returns the user ID from a resource name.

func IsValidResourceID

func IsValidResourceID(id string) bool

IsValidResourceID reports whether id is a syntactically valid resource ID.

func IsValidRoleID

func IsValidRoleID(id string) bool

IsValidRoleID reports whether id is a syntactically valid role ID.

func RandomString

func RandomString(n int) (string, error)

RandomString returns a random string with length n.

func SplitMetaGUID

func SplitMetaGUID(guid string) []string

SplitMetaGUID splits a meta GUID into its segments and restores the separator inside each one, so callers get the original names back.

func TruncateString

func TruncateString(str string, limit int) (string, bool)

func TruncateUTF8Bytes

func TruncateUTF8Bytes(str string, limit int) string

TruncateUTF8Bytes cuts a string to at most limit bytes without splitting a multi-byte rune. Cutting mid-rune yields invalid UTF-8, which protobuf and JSON encoders reject outright, so a bound that slices bytes naively can drop the very record it was added to protect.

func UnescapeGUIDPart

func UnescapeGUIDPart(part string) string

UnescapeGUIDPart restores the separator escaped by EscapeGUIDPart.

func ValidatePhone

func ValidatePhone(phone string) error

ValidatePhone validates the phone number.

Types

type AuthContext

type AuthContext struct {
	Audit                  bool
	AllowWithoutCredential bool
	Permission             string
}

func GetAuthContextFromContext

func GetAuthContextFromContext(ctx context.Context) (*AuthContext, bool)

type Code

type Code int

Code is the error code.

const (
	// 0 ~ 99 general error.
	Ok             Code = 0
	Internal       Code = 1
	NotAuthorized  Code = 2
	Invalid        Code = 3
	NotFound       Code = 4
	Conflict       Code = 5
	NotImplemented Code = 6
	SizeExceeded   Code = 7

	// 101 ~ 199 db error.
	DBExecutionError Code = 102
)

Application error codes.

func ErrorCode

func ErrorCode(err error) Code

ErrorCode unwraps an application error and returns its code. Non-application errors always return EINTERNAL.

type ContextKey

type ContextKey int

ContextKey is the key type of context value.

const (
	// UserContextKey is the key name used to store user message in the context.
	UserContextKey ContextKey = iota
	AuthContextKey
	// TokenRestrictionContextKey is the key name used to store the restriction
	// carried by the access token that authenticated the request. It is absent
	// for a full-access token.
	TokenRestrictionContextKey
)

type Error

type Error struct {
	// Machine-readable error code.
	Code Code

	// Embedded error.
	Err error
}

Error represents an application-specific error. Application errors can be unwrapped by the caller to extract out the code & message.

Any non-application error (such as a disk error) should be reported as an Internal error and the human user should only see "Internal error" as the message. These low-level internal error details should only be logged and reported to the operator of the application (not the end user).

func Errorf

func Errorf(code Code, format string, args ...any) *Error

Errorf is a helper function to create an Error with given code and formatted message.

func (*Error) Error

func (e *Error) Error() string

Error implements the error interface. Not used by the application otherwise.

func (*Error) Unwrap

func (e *Error) Unwrap() error

Unwrap exposes the wrapped error so errors.Is/errors.As and the API boundary can inspect the cause behind an application code.

type ReleaseMode

type ReleaseMode string

ReleaseMode is the mode for release, such as dev or release.

const (
	// ReleaseModeProd is the prod mode.
	ReleaseModeProd ReleaseMode = "prod"
	// ReleaseModeDev is the dev mode.
	ReleaseModeDev ReleaseMode = "dev"
)

Directories

Path Synopsis
Package crypto encrypts the credentials the server keeps in its own database: the instance and data source credentials, and the LLM provider API keys.
Package crypto encrypts the credentials the server keeps in its own database: the instance and data source credentials, and the LLM provider API keys.
Package permission defines the metaxisdata permission catalog.
Package permission defines the metaxisdata permission catalog.
gen command
Command gen regenerates permission_gen.go from permission.json.
Command gen regenerates permission_gen.go from permission.json.
Package version carries the server binary build metadata.
Package version carries the server binary build metadata.

Jump to

Keyboard shortcuts

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