postgres

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AggregatedPoliciesStatusDB

type AggregatedPoliciesStatusDB interface {
	GetPolicyIDsByLeafHub(ctx context.Context, schema string, tableName string, leafHubName string) (set.Set, error)
	InsertOrUpdateAggregatedPolicyCompliance(ctx context.Context, schema string, tableName string, leafHubName string,
		policyID string, appliedClusters int, nonCompliantClusters int) error
	DeleteAllComplianceRows(ctx context.Context, schema string, tableName string, leafHubName string,
		policyID string) error
}

AggregatedPoliciesStatusDB is the db interface required to manage aggregated policy info.

type BatchBuilder

type BatchBuilder interface {
	// Build builds the batch object.
	Build() interface{}
}

BatchBuilder is an interface to build a batch that can be used to be sent to db.

type BatchSenderDB

type BatchSenderDB interface {
	// SendBatch sends a batch operation to the db and returns list of errors if there were any.
	SendBatch(ctx context.Context, batch interface{}) error
}

BatchSenderDB is the db interface required for sending batch updates.

type ControlInfoDB

type ControlInfoDB interface {
	// UpdateHeartbeat inserts or updates heartbeat for a leaf hub.
	UpdateHeartbeat(ctx context.Context, schema string, tableName string, leafHubName string) error
}

ControlInfoDB is the db interface required to manage control info status.

type GenericBatchBuilder

type GenericBatchBuilder interface {
	BatchBuilder
	// Insert adds the given (id, payload) to the batch to be inserted to the db.
	Insert(id string, payload interface{})
	// Update adds the given (id, payload) to the batch to be updated in the db.
	Update(id string, payload interface{})
	// Delete adds the given id to the batch to be deleted from db.
	Delete(id string)
}

GenericBatchBuilder is a generic interface for building a batch to update global objects information in db.

type GenericLocalBatchBuilder

type GenericLocalBatchBuilder interface {
	BatchBuilder
	// Insert adds the given payload to the batch to be inserted to the db.
	Insert(payload interface{})
	// Update adds the given payload to the batch to be updated in the db.
	Update(payload interface{})
	// Delete adds the given id to the batch to be deleted from db.
	Delete(id string)
}

GenericLocalBatchBuilder is a generic interface for building a batch to update local objects information in db.

type GenericStatusResourceDB

type GenericStatusResourceDB interface {
	BatchSenderDB
	// GetResourceIDToVersionByLeafHub returns a map from resource id to its resourceVersion.
	GetResourceIDToVersionByLeafHub(ctx context.Context, schema string, tableName string,
		leafHubName string) (map[string]string, error)
	NewGenericBatchBuilder(schema string, tableName string, leafHubName string) GenericBatchBuilder
}

GenericStatusResourceDB is the db interface required to manage generic status resources.

type LocalPoliciesStatusDB

type LocalPoliciesStatusDB interface {
	BatchSenderDB
	// GetLocalResourceIDToVersionByLeafHub returns a map from local resource id to its resourceVersion.
	GetLocalResourceIDToVersionByLeafHub(ctx context.Context, schema string, tableName string,
		leafHubName string) (map[string]string, error)
	// NewGenericLocalBatchBuilder returns generic local batch builder.
	NewGenericLocalBatchBuilder(schema string, tableName string, leafHubName string) GenericLocalBatchBuilder
}

LocalPoliciesStatusDB is the db interface required to manage local policies.

type ManagedClustersBatchBuilder

type ManagedClustersBatchBuilder interface {
	BatchBuilder
	// Insert adds the given (cluster payload, error string) to the batch to be inserted to the db.
	Insert(clusterID string, payload interface{}, errorString string)
	// Update adds the given arguments to the batch to update clusterName with the given payload in db.
	Update(clusterID string, clusterName string, payload interface{})
	// Delete adds delete statement to the batch to delete the given cluster from db.
	Delete(clusterName string)
}

ManagedClustersBatchBuilder is an interface for building a batch to update managed clusters information in db.

type ManagedClustersStatusDB

type ManagedClustersStatusDB interface {
	BatchSenderDB
	// GetManagedClustersByLeafHub returns a map from clusterName to its resourceVersion.
	GetManagedClustersByLeafHub(ctx context.Context, schema string, tableName string,
		leafHubName string) (map[string]string, error)
	// NewManagedClustersBatchBuilder returns managed clusters batch builder.
	NewManagedClustersBatchBuilder(schema string, tableName string, leafHubName string) ManagedClustersBatchBuilder
}

ManagedClustersStatusDB is the db interface required to manage managed clusters status.

type PoliciesBatchBuilder

type PoliciesBatchBuilder interface {
	BatchBuilder
	// Insert adds the given (policyID, clusterName, errorString, compliance) to the batch to be inserted to the db.
	Insert(policyID string, clusterName string, errorString string, compliance database.ComplianceStatus)
	// Update adds the given (policyID, compliance) to the batch to be updated in the db.
	UpdatePolicyCompliance(policyID string, compliance database.ComplianceStatus)
	// Update adds the given (policyID, clusterName, compliance) to the batch to be updated in the db.
	UpdateClusterCompliance(policyID string, clusterName string, compliance database.ComplianceStatus)
	// DeletePolicy adds delete statement to the batch to delete the given policyID from db.
	DeletePolicy(policyID string)
	// DeleteClusterStatus adds delete statement to the batch to delete the given (policyID,clusterName) from db.
	DeleteClusterStatus(policyID string, clusterName string)
}

PoliciesBatchBuilder is an interface for building a batch to update policies status information in db.

type PoliciesStatusDB

type PoliciesStatusDB interface {
	BatchSenderDB
	// GetComplianceStatusByLeafHub returns a map of policies, each maps to a set of clusters.
	GetComplianceStatusByLeafHub(ctx context.Context, schema string, tableName string,
		leafHubName string) (map[string]*PolicyClustersSets, error)
	// GetNonCompliantClustersByLeafHub returns a map of policies, each maps to sets of (NonCompliant,Unknown) clusters.
	GetNonCompliantClustersByLeafHub(ctx context.Context, schema string, tableName string,
		leafHubName string) (map[string]*PolicyClustersSets, error)
	// NewPoliciesBatchBuilder returns policies status batch builder.
	NewPoliciesBatchBuilder(schema string, tableName string, leafHubName string) PoliciesBatchBuilder
}

PoliciesStatusDB is the db interface required to manage policies status.

type PolicyClustersSets

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

PolicyClustersSets is a data structure to hold both non compliant clusters set and unknown clusters set.

func NewPolicyClusterSets

func NewPolicyClusterSets() *PolicyClustersSets

NewPolicyClusterSets creates a new instance of PolicyClustersSets.

func (*PolicyClustersSets) AddCluster

func (sets *PolicyClustersSets) AddCluster(clusterName string, complianceStatus database.ComplianceStatus)

AddCluster adds the given cluster name to the given compliance status clusters set.

func (*PolicyClustersSets) GetAllClusters

func (sets *PolicyClustersSets) GetAllClusters() set.Set

GetAllClusters returns the clusters set of a policy (union of compliant/nonCompliant/unknown clusters).

func (*PolicyClustersSets) GetClusters

func (sets *PolicyClustersSets) GetClusters(complianceStatus database.ComplianceStatus) set.Set

GetClusters returns the clusters set by compliance status.

type PostgreSQL

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

PostgreSQL abstracts management of PostgreSQL client.

func NewStatusPostgreSQL

func NewStatusPostgreSQL(ctx context.Context, dataConfig *database.DatabaseConfig) (*PostgreSQL, error)

NewStatusPostgreSQL creates a new instance of PostgreSQL object.

func (*PostgreSQL) DeleteAllComplianceRows

func (p *PostgreSQL) DeleteAllComplianceRows(ctx context.Context, schema string, tableName string, leafHubName string,
	policyID string,
) error

DeleteAllComplianceRows delete all compliance rows from the db by leaf hub and policy.

func (*PostgreSQL) GetComplianceStatusByLeafHub

func (p *PostgreSQL) GetComplianceStatusByLeafHub(ctx context.Context, schema string, tableName string,
	leafHubName string,
) (map[string]*PolicyClustersSets, error)

GetComplianceStatusByLeafHub returns a map of policies, each maps to a set of clusters.

func (*PostgreSQL) GetLocalResourceIDToVersionByLeafHub

func (p *PostgreSQL) GetLocalResourceIDToVersionByLeafHub(ctx context.Context, schema string, tableName string,
	leafHubName string,
) (map[string]string, error)

GetLocalResourceIDToVersionByLeafHub returns a map from resource id to its resourceVersion.

func (*PostgreSQL) GetManagedClustersByLeafHub

func (p *PostgreSQL) GetManagedClustersByLeafHub(ctx context.Context, schema string, tableName string,
	leafHubName string,
) (map[string]string, error)

GetManagedClustersByLeafHub returns list of managed clusters and for each managed cluster it's resourceVersion.

func (*PostgreSQL) GetNonCompliantClustersByLeafHub

func (p *PostgreSQL) GetNonCompliantClustersByLeafHub(ctx context.Context, schema string, tableName string,
	leafHubName string,
) (map[string]*PolicyClustersSets, error)

GetNonCompliantClustersByLeafHub returns a map of policies, each maps to sets of (NonCompliant,Unknown) clusters.

func (*PostgreSQL) GetPolicyIDsByLeafHub

func (p *PostgreSQL) GetPolicyIDsByLeafHub(ctx context.Context, schema string, tableName string,
	leafHubName string,
) (set.Set, error)

GetPolicyIDsByLeafHub returns policy IDs of a specific leaf hub.

func (*PostgreSQL) GetPoolSize

func (p *PostgreSQL) GetPoolSize() int32

GetPoolSize returns the max number of connections.

func (*PostgreSQL) GetResourceIDToVersionByLeafHub

func (p *PostgreSQL) GetResourceIDToVersionByLeafHub(ctx context.Context, schema string, tableName string,
	leafHubName string,
) (map[string]string, error)

GetResourceIDToVersionByLeafHub returns a map from resource id to its resourceVersion.

func (*PostgreSQL) InsertOrUpdateAggregatedPolicyCompliance

func (p *PostgreSQL) InsertOrUpdateAggregatedPolicyCompliance(ctx context.Context, schema string, tableName string,
	leafHubName string, policyID string, appliedClusters int, nonCompliantClusters int,
) error

InsertOrUpdateAggregatedPolicyCompliance inserts or updates aggregated policy compliance row in the database.

func (*PostgreSQL) NewGenericBatchBuilder

func (p *PostgreSQL) NewGenericBatchBuilder(schema string, tableName string,
	leafHubName string,
) GenericBatchBuilder

NewGenericBatchBuilder creates a new instance of GenericBatchBuilder.

func (*PostgreSQL) NewGenericLocalBatchBuilder

func (p *PostgreSQL) NewGenericLocalBatchBuilder(schema string, tableName string,
	leafHubName string,
) GenericLocalBatchBuilder

NewGenericLocalBatchBuilder creates a new instance of GenericLocalBatchBuilder.

func (*PostgreSQL) NewManagedClustersBatchBuilder

func (p *PostgreSQL) NewManagedClustersBatchBuilder(schema string, tableName string,
	leafHubName string,
) ManagedClustersBatchBuilder

NewManagedClustersBatchBuilder creates a new instance of ManagedClustersBatchBuilder.

func (*PostgreSQL) NewPoliciesBatchBuilder

func (p *PostgreSQL) NewPoliciesBatchBuilder(schema string, tableName string,
	leafHubName string,
) PoliciesBatchBuilder

NewPoliciesBatchBuilder creates a new instance of PoliciesBatchBuilder.

func (*PostgreSQL) SendBatch

func (p *PostgreSQL) SendBatch(ctx context.Context, batch interface{}) error

SendBatch sends a batch operation to the db and returns list of errors if there were any.

func (*PostgreSQL) Stop

func (p *PostgreSQL) Stop()

Stop function stops PostgreSQL client.

func (*PostgreSQL) UpdateHeartbeat

func (p *PostgreSQL) UpdateHeartbeat(ctx context.Context, schema string, tableName string, leafHubName string) error

UpdateHeartbeat inserts or updates heartbeat for a leaf hub.

type StatusTransportBridgeDB

StatusTransportBridgeDB is the db interface required by status transport bridge.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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