Documentation ¶
Overview ¶
Package common provides functions and structs used by multiple Cacao services for interacting with Kubernetes clusters, NATS queues, and other services
Index ¶
- Variables
- func CreateCloudEvent(request []byte, eventType string, source string, id string) ([]byte, error)
- func CreateResourceName(username, name, id string) string
- func FixName(name string) string
- func GetNATSInfo(defaultClusterID string, defaultClientID string, defaultConnAddress string) map[string]string
- func GetRequestFromCloudEvent(msg []byte) (dataBytes []byte, err error)
- func PtrOf[T any](data T) *T
- func PublishRequest(request Request, subject string, source string, connAddress string) (result []byte, err error)
- func RegisterMonitoring(subject string, natsInfo map[string]string)
- func StanQueueSubscriber(subject string, queue string, cb stan.MsgHandler, natsInfo map[string]string, ...)
- func StanSubscriber(subject string, cb stan.MsgHandler, natsInfo map[string]string, ...)
- func StreamingPublish(request []byte, natsInfo map[string]string, subject string, source string) error
- func StreamingQueueSubscriber(subject string, queue string, action func([]byte, map[string]string), ...)
- func StreamingSubscriber(subject string, action func([]byte, map[string]string), ...)
- func StreamingTestSubscriber(subject string, queue string, action func([]byte, map[string]string), ...)
- func SynchronousSubscriber(subject string, queue string, ...)
- func SynchronousTestSubscriber(subject string, queue string, ...)
- type BasicRequest
- func (r *BasicRequest) GetBuildID() string
- func (r *BasicRequest) GetClusterID() string
- func (r *BasicRequest) GetError() Error
- func (r *BasicRequest) GetGitSecretID() string
- func (r *BasicRequest) GetRedacted() BasicRequest
- func (r *BasicRequest) GetRegistrySecretID() string
- func (r *BasicRequest) GetRunID() string
- func (r *BasicRequest) GetUser() User
- func (r *BasicRequest) GetWorkflowID() string
- func (r *BasicRequest) SetBuildID(value string)
- func (r *BasicRequest) SetClusterID(value string)
- func (r *BasicRequest) SetGitSecretID(value string)
- func (r *BasicRequest) SetRegistrySecretID(value string)
- func (r *BasicRequest) SetRunID(value string)
- func (r *BasicRequest) SetUser(value User)
- func (r *BasicRequest) SetWorkflowID(value string)
- type BuildStatus
- type BuildStep
- type CRUD
- type CacaoBase
- type Cluster
- type DatabaseAdapter
- func (d DatabaseAdapter) Create(collectionName string, document CacaoBase) (err error)
- func (d DatabaseAdapter) Delete(collectionName, id string) (err error)
- func (d DatabaseAdapter) GetMock() (m *mock.Mock)
- func (d DatabaseAdapter) Read(collectionName string, id string) (data []byte, err error)
- func (d DatabaseAdapter) ReadFor(collectionName, key, value string) (results []map[string]interface{}, err error)
- func (d DatabaseAdapter) ReadForUser(collectionName, owner string) (results []map[string]interface{}, err error)
- func (d DatabaseAdapter) Replace(collectionName string, document CacaoBase) (err error)
- func (d DatabaseAdapter) Update(collectionName string, document CacaoBase) (err error)
- type Error
- type MockedAdapter
- func (d MockedAdapter) Create(collectionName string, document CacaoBase) error
- func (d MockedAdapter) Delete(collectionName, id string) error
- func (d MockedAdapter) GetMock() *mock.Mock
- func (d MockedAdapter) Read(collectionName, id string) ([]byte, error)
- func (d MockedAdapter) ReadFor(collectionName, key, value string) ([]map[string]interface{}, error)
- func (d MockedAdapter) ReadForUser(collectionName, owner string) ([]map[string]interface{}, error)
- func (d MockedAdapter) Replace(collectionName string, document CacaoBase) error
- func (d MockedAdapter) Update(collectionName string, document CacaoBase) error
- type Repository
- type Request
- type Secret
- type SecretType
- type User
Constants ¶
This section is empty.
Variables ¶
var MonitoringSubject = "Phylax.CreateSubscriber"
MonitoringSubject is the subject phylax monitors for creating subscribers
Functions ¶
func CreateCloudEvent ¶
CreateCloudEvent takes a JSON byte slice and uses it as the data for a new CloudEvent object Marshaled as a JSON byte slice
func CreateResourceName ¶
CreateResourceName is used to create a K8s resource name that is both unique and informative to users:
<username:limit to 8>-<name:limit to 32 chars>-<xid>
func GetNATSInfo ¶
func GetNATSInfo(defaultClusterID string, defaultClientID string, defaultConnAddress string) map[string]string
GetNATSInfo returns a map containing necessary NATS connection variables. It is used to get this information from environment variables or use the defaults
func GetRequestFromCloudEvent ¶
GetRequestFromCloudEvent will unmarshal a CloudEvent object and unmarshal the data field into JSON bytes
func PtrOf ¶
func PtrOf[T any](data T) *T
PtrOf return a pointer to the data.
Useful for converting constants and literal, e.g. PtrOf(true), PtrOf("foobar")
func PublishRequest ¶
func PublishRequest(request Request, subject string, source string, connAddress string) (result []byte, err error)
PublishRequest can be used to create a CloudEvent and publish it on NATS. It expects a reply
func RegisterMonitoring ¶
RegisterMonitoring is used to monitor a separate streaming channel
func StanQueueSubscriber ¶
func StanQueueSubscriber(subject string, queue string, cb stan.MsgHandler, natsInfo map[string]string, wg *sync.WaitGroup)
StanQueueSubscriber creates a NATS Streaming Subscriber that will listen on a subject as a queue subscriber and perform asynchronous actions. The cb parameter can by any function which conforms to the stan.MsgHandler type (i.e. accepts *stan.Msg as a parameter). For information on queue subscribers, see https://docs.nats.io/developing-with-nats-streaming/queues
func StanSubscriber ¶
func StanSubscriber(subject string, cb stan.MsgHandler, natsInfo map[string]string, wg *sync.WaitGroup)
StanSubscriber creates a NATS Streaming Subscriber that will listen on a subject and perform asynchronous actions. The cb parameter can by any function which conforms to the stan.MsgHandler type (i.e. accepts *stan.Msg as a parameter)
func StreamingPublish ¶
func StreamingPublish(request []byte, natsInfo map[string]string, subject string, source string) error
StreamingPublish can be used to create a CloudEvent and publish it on NATS Streaming
func StreamingQueueSubscriber ¶
func StreamingQueueSubscriber(subject string, queue string, action func([]byte, map[string]string), natsInfo map[string]string, wg *sync.WaitGroup)
StreamingQueueSubscriber creates a NATS Streaming Queue Subscriber that will listen on a subject and perform asynchronous actions. The action function should accept a []byte that represents JSON data, and a map[string]string, which represents NATS connection info.
func StreamingSubscriber ¶
func StreamingSubscriber(subject string, action func([]byte, map[string]string), natsInfo map[string]string, wg *sync.WaitGroup)
StreamingSubscriber creates a NATS Streaming Subscriber that will listen on a subject and perform asynchronous actions. The action function should accept a []byte that represents JSON data, and a map[string]string, which represents NATS connection info.
func StreamingTestSubscriber ¶
func StreamingTestSubscriber(subject string, queue string, action func([]byte, map[string]string), natsInfo map[string]string, wg *sync.WaitGroup)
StreamingTestSubscriber is the same as StreamingSubscriber but will exit after receiving and processing one request
func SynchronousSubscriber ¶
func SynchronousSubscriber(subject string, queue string, action func([]byte, *nats.Msg, map[string]string), natsInfo map[string]string, wg *sync.WaitGroup)
SynchronousSubscriber is used to synchronously respond to requests
func SynchronousTestSubscriber ¶
func SynchronousTestSubscriber(subject string, queue string, action func([]byte, *nats.Msg, map[string]string), natsInfo map[string]string, wg *sync.WaitGroup)
SynchronousTestSubscriber is the same as SynchronousSubscriber but will exit after receiving and processing one request
Types ¶
type BasicRequest ¶
type BasicRequest struct { User User `json:"user,omitempty"` ClusterID string `json:"cluster_id,omitempty"` RegistrySecretID string `json:"registry_secret_id,omitempty"` GitSecretID string `json:"git_secret_id,omitempty"` WorkflowID string `json:"workflow_id,omitempty"` BuildID string `json:"build_id,omitempty"` RunID string `json:"run_id,omitempty"` Error Error `json:"error,omitempty"` }
BasicRequest is the simplest implementation of the Request interface and is intended to be included as an embedded/anonymous struct in extending types
func (*BasicRequest) GetGitSecretID ¶
func (r *BasicRequest) GetGitSecretID() string
GetGitSecretID ...
func (*BasicRequest) GetRedacted ¶
func (r *BasicRequest) GetRedacted() BasicRequest
GetRedacted will return a new BasicRequest with the confidential fields removed from the User's Secrets and Clusters
func (*BasicRequest) GetRegistrySecretID ¶
func (r *BasicRequest) GetRegistrySecretID() string
GetRegistrySecretID ...
func (*BasicRequest) GetWorkflowID ¶
func (r *BasicRequest) GetWorkflowID() string
GetWorkflowID ...
func (*BasicRequest) SetClusterID ¶
func (r *BasicRequest) SetClusterID(value string)
SetClusterID ...
func (*BasicRequest) SetGitSecretID ¶
func (r *BasicRequest) SetGitSecretID(value string)
SetGitSecretID ...
func (*BasicRequest) SetRegistrySecretID ¶
func (r *BasicRequest) SetRegistrySecretID(value string)
SetRegistrySecretID ...
func (*BasicRequest) SetWorkflowID ¶
func (r *BasicRequest) SetWorkflowID(value string)
SetWorkflowID ...
type BuildStatus ¶
type BuildStatus struct { Complete bool `json:"complete"` Success bool `json:"success"` Info string `json:"info"` }
BuildStatus is used to get information about a Build. Info will be a container's output log
type BuildStep ¶
type BuildStep struct { Image string `bson:"image" json:"image,omitempty" yaml:"image,omitempty"` Dockerfile string `bson:"dockerfile" json:"dockerfile,omitempty" yaml:"dockerfile,omitempty"` Args []core.EnvVar `bson:"args" json:"args,omitempty" yaml:"args,omitempty"` }
BuildStep ...
type CRUD ¶
type CRUD interface { GetMock() *mock.Mock Create(string, CacaoBase) error Read(string, string) ([]byte, error) Update(string, CacaoBase) error Replace(string, CacaoBase) error Delete(string, string) error ReadFor(string, string, string) ([]map[string]interface{}, error) ReadForUser(string, string) ([]map[string]interface{}, error) }
CRUD is an interface that allows for mocking of the MongoDB
type Cluster ¶
type Cluster struct { ID string `json:"id,omitempty"` Name string `json:"name,omitempty"` DefaultNamespace string `json:"default_namespace,omitempty"` Config string `json:"config,omitempty"` Host string `json:"host,omitempty"` Slug string `json:"slug,omitempty"` Admin bool `json:"admin,omitempty"` }
Cluster ...
func (*Cluster) GetRedacted ¶
GetRedacted will return a new Cluster with the Value set to "REDACTED"
type DatabaseAdapter ¶
DatabaseAdapter implements the CRUD interface to allow for mocking
func GetMongoDBAdapter ¶
func GetMongoDBAdapter(name, address string) (adapter DatabaseAdapter, err error)
GetMongoDBAdapter returns a new connection to MongoDB and wraps it in a CRUD interface
func (DatabaseAdapter) Create ¶
func (d DatabaseAdapter) Create(collectionName string, document CacaoBase) (err error)
Create will insert into the database
func (DatabaseAdapter) Delete ¶
func (d DatabaseAdapter) Delete(collectionName, id string) (err error)
Delete will delete from the database
func (DatabaseAdapter) Read ¶
func (d DatabaseAdapter) Read(collectionName string, id string) (data []byte, err error)
Read will read from the database
func (DatabaseAdapter) ReadFor ¶
func (d DatabaseAdapter) ReadFor(collectionName, key, value string) (results []map[string]interface{}, err error)
ReadFor will return all objects with a key
func (DatabaseAdapter) ReadForUser ¶
func (d DatabaseAdapter) ReadForUser(collectionName, owner string) (results []map[string]interface{}, err error)
ReadForUser will return all objects owned by a user
type Error ¶
Error is used for responding to synchronous requests with an error that is JSON friendly
type MockedAdapter ¶
MockedAdapter for testing
func (MockedAdapter) Create ¶
func (d MockedAdapter) Create(collectionName string, document CacaoBase) error
Create ...
func (MockedAdapter) Delete ¶
func (d MockedAdapter) Delete(collectionName, id string) error
Delete ...
func (MockedAdapter) Read ¶
func (d MockedAdapter) Read(collectionName, id string) ([]byte, error)
Read ...
func (MockedAdapter) ReadFor ¶
func (d MockedAdapter) ReadFor(collectionName, key, value string) ([]map[string]interface{}, error)
ReadFor ...
func (MockedAdapter) ReadForUser ¶
func (d MockedAdapter) ReadForUser(collectionName, owner string) ([]map[string]interface{}, error)
ReadForUser ...
type Repository ¶
type Repository struct { RawURL string `bson:"rawurl" json:"rawurl,omitempty"` URL string `bson:"url" json:"url,omitempty"` Branch string `bson:"branch" json:"branch,omitempty"` }
Repository contains basic information required to interact with git The URL is the RawURL without the leading `https://` in order to use as an ID and the RawURL is saved for cloning
type Request ¶
type Request interface { GetClusterID() string GetRegistrySecretID() string GetGitSecretID() string GetWorkflowID() string GetBuildID() string GetRunID() string GetUser() User GetError() Error SetClusterID(value string) SetRegistrySecretID(value string) SetGitSecretID(value string) SetWorkflowID(value string) SetBuildID(value string) SetRunID(value string) SetUser(value User) }
Request is an interface that allows for reading common HTTP request fields and can be extended by service-specific types for reading additional fields
type Secret ¶
type Secret struct { Username string `json:"username,omitempty"` Value string `json:"value,omitempty"` Type SecretType `json:"type,omitempty"` ID string `json:"id,omitempty"` }
Secret ... Deprecated: Secret is deprecated. Use Service.credentialModel in cacao-common instead
type SecretType ¶
type SecretType string
SecretType associates a type with a Secret
const ( // GCRSecret is used for Google Container Registry GCRSecret SecretType = "gcr" // DockerhubSecret is used for Dockerhub DockerhubSecret SecretType = "dockerhub" // GitSecret is used for Github, GitLab, etc. GitSecret SecretType = "git" )
type User ¶
type User struct { Username string `json:"username,omitempty"` Password string `json:"password,omitempty,omitempty"` Secrets map[string]Secret `json:"secrets,omitempty"` Clusters map[string]Cluster `json:"clusters,omitempty"` IsAdmin bool `json:"is_admin"` }
User defines user attributes, primarily Secrets that are written to Vault. Note that the Password field is only used for creating the User
func (*User) GetRedacted ¶
GetRedacted will return a new User with sensitive fields redacted