dbhelpers

package
v5.1.3+incompatible Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2021 License: Apache-2.0, BSD-2-Clause, BSD-3-Clause, + 1 more Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const BaseLimit = "\nLIMIT"
View Source
const BaseOffset = "\nOFFSET"
View Source
const BaseOrderBy = "\nORDER BY"
View Source
const BaseWhere = "\nWHERE"

Variables

This section is empty.

Functions

func AddTenancyCheck

func AddTenancyCheck(where string, queryValues map[string]interface{}, tenantColumnName string, tenantIDs []int) (string, map[string]interface{})

AddTenancyCheck takes a WHERE clause (can be ""), the associated queryValues (can be empty), a tenantColumnName that should provide a bigint corresponding to the tenantID of the object being checked (this may require a CAST), and an array of the tenantIDs the user has access to; it returns a where clause and associated queryValues including filtering based on tenancy.

func BuildWhereAndOrderByAndPagination

func BuildWhereAndOrderByAndPagination(parameters map[string]string, queryParamsToSQLCols map[string]WhereColumnInfo) (string, string, string, map[string]interface{}, []error)

func CDNExists

func CDNExists(cdnName string, tx *sql.Tx) (bool, error)

Returns true if the cdn exists

func CachegroupHasTopologyBasedDeliveryServicesOnCDN

func CachegroupHasTopologyBasedDeliveryServicesOnCDN(tx *sql.Tx, cachegroupID int, CDNID int) (bool, error)

CheckCachegroupHasTopologyBasedDeliveryServicesOnCDN returns true if the given cachegroup is assigned to any topologies with delivery services assigned on the given CDN.

func CachegroupParameterAssociationExists

func CachegroupParameterAssociationExists(id int, cachegroup int, tx *sql.Tx) (bool, error)

CachegroupParameterAssociationExists returns whether a cachegroup parameter association with the given parameter id exists, and any error.

func CheckOriginServerInDSCG

func CheckOriginServerInDSCG(tx *sql.Tx, dsID int, dsTopology string) (error, error, int)

CheckOriginServerInDSCG checks if a DS has ORG server and if it does, to make sure the cachegroup is part of DS

func CheckTopology

func CheckTopology(tx *sqlx.Tx, ds tc.DeliveryServiceNullableV30) (int, error, error)

CheckTopology returns an error if the given Topology does not exist or if one of the Topology's Cache Groups is empty with respect to the Delivery Service's CDN.

func CheckTopologyOrgServerCGInDSCG

func CheckTopologyOrgServerCGInDSCG(tx *sql.Tx, cdnIds []int, dsTopology string, topologyCGNames []string) (error, error, int)

CheckTopologyOrgServerCGInDSCG checks if ORG server are part of DS. IF they are then the user is not allowed to remove the ORG servers from the associated DS's topology

func CommitIf

func CommitIf(tx *sql.Tx, doCommit *bool)

CommitIf commits if doCommit is true at the time of execution. This is designed as a defer helper.

Example:

tx, err := db.Begin()
txCommit := false
defer dbhelpers.CommitIf(tx, &txCommit)
if err := tx.Exec("select ..."); err != nil {
  return errors.New("executing: " + err.Error())
}
txCommit = true
return nil

func GetCDNDSes

func GetCDNDSes(tx *sql.Tx, cdn tc.CDNName) (map[tc.DeliveryServiceName]struct{}, error)

func GetCDNDomainFromName

func GetCDNDomainFromName(tx *sql.Tx, cdnName tc.CDNName) (string, bool, error)

GetCDNDomainFromName returns the domain, whether the cdn exists, and any error.

func GetCDNIDFromName

func GetCDNIDFromName(tx *sql.Tx, name tc.CDNName) (int, bool, error)

GetCDNIDFromName returns the ID of the CDN if a CDN with the name exists

func GetCDNNameFromID

func GetCDNNameFromID(tx *sql.Tx, id int64) (tc.CDNName, bool, error)

func GetCDNs

func GetCDNs(tx *sql.Tx) (map[tc.CDNName]struct{}, error)

func GetCacheGroupNameFromID

func GetCacheGroupNameFromID(tx *sql.Tx, id int) (tc.CacheGroupName, bool, error)

GetCacheGroupNameFromID Get Cache Group name from a given ID

func GetDSCDNIdFromID

func GetDSCDNIdFromID(tx *sql.Tx, dsID int) (int, bool, error)

GetDSCDNIdFromID loads the DeliveryService's cdn ID from the database, from the delivery service ID. Returns whether the delivery service was found, and any error.

func GetDSIDAndCDNFromName

func GetDSIDAndCDNFromName(tx *sql.Tx, xmlID string) (int, tc.CDNName, bool, error)

GetDSIDAndCDNFromName returns the delivery service ID and cdn name given from the delivery service name, whether a result existed, and any error.

func GetDSNameAndCDNFromID

func GetDSNameAndCDNFromID(tx *sql.Tx, id int) (tc.DeliveryServiceName, tc.CDNName, bool, error)

returns returns the delivery service name and cdn, whether it existed, and any error.

func GetDSNameFromID

func GetDSNameFromID(tx *sql.Tx, id int) (tc.DeliveryServiceName, bool, error)

GetDSNameFromID loads the DeliveryService's xml_id from the database, from the ID. Returns whether the delivery service was found, and any error.

func GetDSRequiredCapabilitiesFromID

func GetDSRequiredCapabilitiesFromID(id int, tx *sql.Tx) ([]string, error)

GetDSRequiredCapabilitiesFromID returns the server's capabilities.

func GetDSTenantIDFromXMLID

func GetDSTenantIDFromXMLID(tx *sql.Tx, xmlid string) (int, bool, error)

GetDSTenantIDFromXMLID fetches the ID of the Tenant to whom the Delivery Service identified by the the provided XMLID belongs. It returns, in order, the requested ID (if one could be found), a boolean indicating whether or not a Delivery Service with the provided xmlid could be found, and an error for logging in case something unexpected goes wrong.

func GetDeliveryServiceCDNsByTopology

func GetDeliveryServiceCDNsByTopology(tx *sql.Tx, topology string) ([]int, error)

GetDeliveryServiceCDNsByTopology returns a slice of CDN IDs for all delivery services assigned to the given topology.

func GetDeliveryServiceType

func GetDeliveryServiceType(dsID int, tx *sql.Tx) (tc.DSType, bool, error)

GetDeliveryServiceType returns the type of the deliveryservice.

func GetDeliveryServiceTypeRequiredCapabilitiesAndTopology

func GetDeliveryServiceTypeRequiredCapabilitiesAndTopology(dsID int, tx *sql.Tx) (tc.DSType, []string, *string, bool, error)

GetDeliveryServiceTypeAndTopology returns the type of the deliveryservice and the name of its topology.

func GetDeliveryServicesWithTopologies

func GetDeliveryServicesWithTopologies(tx *sql.Tx, dsIDs []int) ([]int, error)

GetDeliveryServicesWithTopologies returns a list containing the delivery services in the given dsIDs list that have a topology assigned. An error indicates unexpected errors that occurred when querying.

func GetFederationIDForUserIDByXMLID

func GetFederationIDForUserIDByXMLID(tx *sql.Tx, userID int, xmlid string) (uint, bool, error)

GetFederationIDForUserIDByXMLID retrieves the ID of the Federation assigned to the user defined by userID on the Delivery Service identified by xmlid. If no such federation exists, the boolean returned will be 'false', while the error indicates unexpected errors that occurred when querying.

func GetFederationNameFromID

func GetFederationNameFromID(id int, tx *sql.Tx) (string, bool, error)

GetFederationNameFromID returns the federation's name, whether a federation with ID exists, or any error.

func GetFederationResolversByFederationID

func GetFederationResolversByFederationID(tx *sql.Tx, fedID int) ([]tc.FederationResolver, error)

GetFederationResolversByFederationID fetches all of the federation resolvers currently assigned to a federation. In the event of an error, it will return an empty slice and the error.

func GetGlobalParam

func GetGlobalParam(tx *sql.Tx, name string) (string, bool, error)

GetGlobalParams returns the value of the global param, whether it existed, or any error

func GetParam

func GetParam(tx *sql.Tx, name string, configFile string) (string, bool, error)

GetParam returns the value of the param, whether it existed, or any error.

func GetParamNameByID

func GetParamNameByID(tx *sql.Tx, id int) (string, bool, error)

GetParamNameByID returns the name of the param, whether it existed, or any error.

func GetPrivLevelFromRoleID

func GetPrivLevelFromRoleID(tx *sql.Tx, id int) (int, bool, error)

GetPrivLevelFromRoleID returns the priv_level associated with a role, whether it exists, and any error. This method exists on a temporary basis. After priv_level is fully deprecated and capabilities take over, this method will not only no longer be needed, but the corresponding new privilege check should be done via the primary database query for the users endpoint. The users json response will contain a list of capabilities in the future, whereas now the users json response currently does not contain privLevel. See the wiki page on the roles/capabilities as a system: https://cwiki.apache.org/confluence/pages/viewpage.action?pageId=68715910

func GetProfileIDFromName

func GetProfileIDFromName(name string, tx *sql.Tx) (int, bool, error)

GetProfileIDFromName returns the profile's ID, whether a profile with name exists, or any error.

func GetProfileNameFromID

func GetProfileNameFromID(id int, tx *sql.Tx) (string, bool, error)

GetProfileNameFromID returns the profile's name, whether a profile with ID exists, or any error.

func GetServerCapabilitiesFromName

func GetServerCapabilitiesFromName(name string, tx *sql.Tx) ([]string, error)

GetServerCapabilitiesFromName returns the server's capabilities.

func GetServerIDFromName

func GetServerIDFromName(serverName string, tx *sql.Tx) (int, bool, error)

GetServerIDFromName gets server id from a given name

func GetServerInfo

func GetServerInfo(serverID int, tx *sql.Tx) (tc.ServerInfo, bool, error)

GetServerInfo returns a ServerInfo struct, whether the server exists, and an error (if one occurs).

func GetServerInfosFromHostNames

func GetServerInfosFromHostNames(tx *sql.Tx, hostNames []string) ([]tc.ServerInfo, error)

GetServerInfosFromHostNames returns the ServerInfo structs of the given server host names or an error if any occur.

func GetServerInfosFromIDs

func GetServerInfosFromIDs(tx *sql.Tx, ids []int) ([]tc.ServerInfo, error)

GetServerInfosFromIDs returns the ServerInfo structs of the given server IDs or an error if any occur.

func GetServerNameFromID

func GetServerNameFromID(tx *sql.Tx, id int) (string, bool, error)

func GetServersInterfaces

func GetServersInterfaces(ids []int, tx *sql.Tx) (map[int]map[string]tc.ServerInterfaceInfo, error)

GetServerInterfaces, given the IDs of one or more servers, returns all of their network interfaces mapped by their ids, or an error if one occurs during retrieval.

func GetStatusByID

func GetStatusByID(id int, tx *sql.Tx) (tc.StatusNullable, bool, error)

GetStatusByID returns a Status struct, a bool for whether or not a status of the given ID exists, and an error (if one occurs).

func GetStatusByName

func GetStatusByName(name string, tx *sql.Tx) (tc.StatusNullable, bool, error)

GetStatusByName returns a Status struct, a bool for whether or not a status of the given name exists, and an error (if one occurs).

func GetTopologyCachegroups

func GetTopologyCachegroups(tx *sql.Tx, name string) ([]int, []string, error)

GetTopologyCachegroups returns an array of cachegroup IDs and an array of cachegroup names for the given topology, or any error.

func GetTypeIDByName

func GetTypeIDByName(t string, tx *sql.Tx) (int, bool, error)

GetTypeIDByName reports the id of the type and whether or not a type exists with the given name.

func GetUserByEmail

func GetUserByEmail(email string, tx *sql.Tx) (tc.User, bool, error)

GetUserByEmail retrieves the user with the given email. If no such user exists, the boolean returned will be 'false', while the error indicates unexpected errors that occurred when querying.

func GetUserByID

func GetUserByID(id int, tx *sql.Tx) (tc.User, bool, error)

GetUserByID returns the user with the requested ID if one exists. The second return value is a boolean indicating whether said user actually did exist, and the third contains any error encountered along the way.

func ScanCachegroupsServerCapabilities

func ScanCachegroupsServerCapabilities(rows *sql.Rows) (map[string][]int, map[int]map[string]struct{}, map[int]int, error)

ScanCachegroupsServerCapabilities, given rows of (server ID, CDN ID, cachegroup name, server capabilities), returns a map of cachegroup names to server IDs, a map of server IDs to a map of their capabilities, a map of server IDs to CDN IDs, and an error (if one occurs).

func TopologyExists

func TopologyExists(tx *sql.Tx, name string) (bool, error)

TopologyExists checks if a Topology with the given name exists. Returns whether or not the Topology exists, along with any encountered error.

func UsernameExists

func UsernameExists(uname string, tx *sql.Tx) (bool, error)

UsernameExists reports whether or not the the given username exists as a user in the database to which the passed transaction refers. If anything goes wrong when checking the existence of said user, the error is directly returned to the caller. Note that in that case, no real meaning should be assigned to the returned boolean value.

Types

type WhereColumnInfo

type WhereColumnInfo struct {
	Column  string
	Checker func(string) error
}

Jump to

Keyboard shortcuts

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