orgsdb

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2021 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IDGenerator

type IDGenerator interface {
	// NextID generates a next unique ID.
	NextID() (uint64, error)
}

IDGenerator defines an interface to generate unique ID accross the cluster

type OrgsDb

type OrgsDb interface {
	db.IDGenerator
	OrgsReadOnlyDb

	// LoginUser returns User
	LoginUser(ctx context.Context, user *model.User) (*model.User, error)
	// CreateUser creates model.User if it does not exist
	CreateUser(ctx context.Context, provider, email string) (*model.User, error)

	// UpdateOrg inserts or updates Organization in "unknown" state
	UpdateOrg(ctx context.Context, org *model.Organization) (*model.Organization, error)
	// UpdateOrgStatus updates the status and approver
	UpdateOrgStatus(ctx context.Context, org *model.Organization) (*model.Organization, error)
	// RemoveOrg deletes org and all its members
	RemoveOrg(ctx context.Context, id uint64) error

	// UpdateRepo inserts or updates Repository
	UpdateRepo(ctx context.Context, repo *model.Repository) (*model.Repository, error)

	// AddOrgMember adds a user to Org
	AddOrgMember(ctx context.Context, orgID, userID uint64, role, membershipSource string) (*model.OrgMembership, error)
	// RemoveOrgMembers removes users from the org
	RemoveOrgMembers(ctx context.Context, orgID uint64, all bool) ([]*model.OrgMembership, error)
	// RemoveOrgMember remove users from the org
	RemoveOrgMember(ctx context.Context, orgID, memberID uint64) (*model.OrgMembership, error)

	// UpdateFRNResponse updates cached FRN response
	UpdateFRNResponse(ctx context.Context, filerID uint64, response string) (*model.FccFRNResponse, error)
	// DeleteFRNResponse deletes cached FRN response
	DeleteFRNResponse(ctx context.Context, filerID uint64) (*model.FccFRNResponse, error)

	// UpdateFccContactResponse updates cached Contact response
	UpdateFccContactResponse(ctx context.Context, frn string, response string) (*model.FccContactResponse, error)
	// DeleteFccContactResponse deletes cached Contact response
	DeleteFccContactResponse(ctx context.Context, frn string) (*model.FccContactResponse, error)

	// CreateApprovalToken returns ApprovalToken
	CreateApprovalToken(ctx context.Context, token *model.ApprovalToken) (*model.ApprovalToken, error)
	// UseApprovalToken returns ApprovalToken if token and code match, and the token was not used
	UseApprovalToken(ctx context.Context, token, code string) (*model.ApprovalToken, error)
	// GetOrgApprovalTokens returns all tokens for Organization
	GetOrgApprovalTokens(ctx context.Context, orgID uint64) ([]*model.ApprovalToken, error)
	// DeleteApprovalToken deletes the token
	DeleteApprovalToken(ctx context.Context, id uint64) error

	// CreateAPIKey returns APIKey
	CreateAPIKey(ctx context.Context, token *model.APIKey) (*model.APIKey, error)
	// DeleteAPIKey deletes the key
	DeleteAPIKey(ctx context.Context, id uint64) error

	// CreateSubscription creates subscription
	CreateSubscription(ctx context.Context, sub *model.Subscription) (*model.Subscription, error)

	// UpdateSubscriptionStatus updates subscription status
	UpdateSubscriptionStatus(ctx context.Context, sub *model.Subscription) (*model.Subscription, error)

	// UpdateSubscriptionAndOrgStatus updates status of subscription and org in a single transaction
	UpdateSubscriptionAndOrgStatus(ctx context.Context, sub *model.Subscription, org *model.Organization) (*model.Subscription, *model.Organization, error)

	// RemoveSubscription deletes subscription
	RemoveSubscription(ctx context.Context, id uint64) error
}

OrgsDb defines an interface for CRUD operations on Orgs

type OrgsReadOnlyDb

type OrgsReadOnlyDb interface {
	// GetUser returns User
	GetUser(ctx context.Context, id uint64) (*model.User, error)
	// GetOrg returns Organization
	GetOrg(ctx context.Context, id uint64) (*model.Organization, error)
	// GetOrgByExternalID returns Organization by external ID
	GetOrgByExternalID(ctx context.Context, provider, externalID string) (*model.Organization, error)
	// GetOrgByRegistrationID returns Organization by registration ID
	GetOrgByRegistrationID(ctx context.Context, provider, regID string) (*model.Organization, error)
	// GetOrgFromApprovalToken returns Organization byapproval token
	GetOrgFromApprovalToken(ctx context.Context, token string) (*model.Organization, error)
	// GetRepo returns Repository
	GetRepo(ctx context.Context, id uint64) (*model.Repository, error)
	// GetOrgMembers returns list of membership info
	GetOrgMembers(ctx context.Context, orgID uint64) ([]*model.OrgMemberInfo, error)
	// GetUserMemberships returns list of membership info
	GetUserMemberships(ctx context.Context, userID uint64) ([]*model.OrgMemberInfo, error)
	// GetUserOrgs returns list of orgs
	GetUserOrgs(ctx context.Context, userID uint64) ([]*model.Organization, error)
	// GetFRNResponse returns cached FRN response
	GetFRNResponse(ctx context.Context, filerID uint64) (*model.FccFRNResponse, error)
	// GetFccContactResponse returns cached Contact response
	GetFccContactResponse(ctx context.Context, frn string) (*model.FccContactResponse, error)
	// GetAPIKey returns APIKey and updates its Used time
	GetAPIKey(ctx context.Context, id uint64) (*model.APIKey, error)
	// FindAPIKey returns APIKey and updates its Used time
	FindAPIKey(ctx context.Context, key string) (*model.APIKey, error)
	// GetOrgAPIKeys returns all API keys for Organization
	GetOrgAPIKeys(ctx context.Context, orgID uint64) ([]*model.APIKey, error)
	// GetSubscription returns subscription with the given id
	GetSubscription(ctx context.Context, id, userID uint64) (*model.Subscription, error)
	// GetSubscriptionByExternalID returns subscription with the given external id
	GetSubscriptionByExternalID(ctx context.Context, externalID string) (*model.Subscription, error)
	// ListSubscriptions lists user's subscriptions
	ListSubscriptions(ctx context.Context, userID uint64) ([]*model.Subscription, error)

	// GetUsersCount returns number of users
	GetUsersCount(ctx context.Context) (uint64, error)
	// GetOrgsCount returns number of organizations
	GetOrgsCount(ctx context.Context) (uint64, error)
}

OrgsReadOnlyDb defines an interface for Read operations on Orgs

type Provider

type Provider interface {
	db.IDGenerator
	OrgsDb

	// DB returns underlying DB connection
	DB() *sql.DB

	// Close connection and release resources
	Close() (err error)
}

Provider provides complete DB access

func New

func New(driverName, dataSourceName, migrationsDir string, forceVersion int, nextID func() (uint64, error)) (Provider, error)

New creates a Provider instance

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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