sdk

package
Version: v0.0.0-...-f1c27b4 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2020 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	//CloudSignatureHeader header name to pass signed payload secret
	CloudSignatureHeader = "X-Cloud-Signature"
	// FunctionLabelPrefix is a prefix for openfaas labels inside functions
	FunctionLabelPrefix = "com.openfaas.cloud."
)
View Source
const (
	StatusSuccess = "success"
	StatusFailure = "failure"
	StatusPending = "pending"
)

github status constant

View Source
const (
	FunctionContext = "%s"
	StackContext    = "stack-deploy"
	EmptyAuthToken  = ""
)

context constant

View Source
const (
	SystemSubdomain = "system"
)

Variables

This section is empty.

Functions

func AddBasicAuth

func AddBasicAuth(req *http.Request) error

AddBasicAuth to a request by reading secrets when available

func BuildFunctionContext

func BuildFunctionContext(function string) string

BuildFunctionContext build a github context for a function

Example:
  sdk.BuildFunctionContext(functionName)

func CreateServiceURL

func CreateServiceURL(URL, suffix string) string

func FormatDashboardURL

func FormatDashboardURL(gatewayURL string, event *Event) (string, error)

FormatDashboardURL takes the environmental variable gateway_public_url and event object and formats the URL to point to the dashboard

func FormatEndpointURL

func FormatEndpointURL(gatewayURL string, event *Event) (string, error)

FormatEndpointURL takes the gateway_public_url environmental variable along with event object to format URL which points to the function endpoint

func FormatLogsURL

func FormatLogsURL(gatewayURL string, event *Event) (string, error)

FormatLogsURL formats the URL where function logs are stored with the gateway_public_url environmental variable and event object

func FormatServiceName

func FormatServiceName(owner, functionName string) string

func FormatShortSHA

func FormatShortSHA(sha string) string

FormatShortSHA returns a 7-digit SHA

func FormatSystemURL

func FormatSystemURL(gatewayURL string) (string, error)

FormatSystemURL formats the system URL which points to the edge-router with the gateway_public_url environmental variable

func GetPrivateKeyPath

func GetPrivateKeyPath() string

func GetSubdomain

func GetSubdomain(URL string) (string, error)

GetSubdomain gets the subdomain of the URL for example the subdomain of www.o6s.io would be www

func HmacEnabled

func HmacEnabled() bool

HmacEnabled uses validate_hmac env-var to verify if the feature is disabled

func MarshalToken

func MarshalToken(token string) string

MarshalToken marshal a token into json i.e. {"token": "auth_token_value"}

func PostAudit

func PostAudit(auditEvent AuditEvent)

func ReadSecret

func ReadSecret(key string) (string, error)

ReadSecret reads a secret from /var/openfaas/secrets or from env-var 'secret_mount_path' if set.

func UnmarshalToken

func UnmarshalToken(data []byte) (string, error)

UnmarshalToken unmarshal a token and validate

func ValidHMAC

func ValidHMAC(payload *[]byte, secretKey string, digest string) error

ValidHMAC returns an error if HMAC could not be validated or if the signature could not be loaded.

func ValidToken

func ValidToken(token string) bool

ValidToken check if a token is in valid format

func ValidateCustomerList

func ValidateCustomerList(customers []string) bool

ValidateCustomerList validate customer names list

func ValidateCustomers

func ValidateCustomers() bool

ValidateCustomers checks environmental variable validate_customers if customer validation is explicitly disabled

Types

type Audit

type Audit interface {
	Post(AuditEvent) error
}

type AuditEvent

type AuditEvent struct {
	Source  string
	Message string
	Owner   string
	Repo    string
}

type AuditLogger

type AuditLogger struct {
}

func (AuditLogger) Post

func (l AuditLogger) Post(auditEvent AuditEvent) error

type BuildResult

type BuildResult struct {
	Log       []string `json:"log"`
	ImageName string   `json:"imageName"`
	Status    string   `json:"status"`
}

BuildResult represents a successful Docker build and push operation to a remote registry

type CommitStatus

type CommitStatus struct {
	Status      string `json:"status"`
	Description string `json:"description"`
	Context     string `json:"context"`
}

CommitStatus to be written to GitHub/GitLab

type Customer

type Customer struct {
	Sender Sender `json:"sender"`
}

type Customers

type Customers struct {
	Usernames *map[string]string
	Sync      *sync.Mutex
	Expires   time.Time

	CustomersURL  string
	CustomersPath string
}

Customers checks whether users are customers of OpenFaaS Cloud

func NewCustomers

func NewCustomers(customersPath, customersURL string) *Customers

NewCustomers creates a Customers struct to be used to query valid users.

func (*Customers) Fetch

func (c *Customers) Fetch() error

Fetch refreshes cache of customers which is valid for `customerCacheExpiry` duration.

func (*Customers) Get

func (c *Customers) Get(login string) (bool, error)

Get returns whether a customer is found

type Event

type Event struct {
	EventKey       string            `json:"event_key"`
	Service        string            `json:"service"`
	Owner          string            `json:"owner"`
	OwnerID        int               `json:"owner-id"`
	Repository     string            `json:"repository"`
	Image          string            `json:"image"`
	SHA            string            `json:"sha"`
	URL            string            `json:"url"`
	InstallationID int               `json:"installationID"`
	Environment    map[string]string `json:"environment"`
	Secrets        []string          `json:"secrets"`
	Private        bool              `json:"private"`
	SCM            string            `json:"scm"`
	RepoURL        string            `json:"repourl"`
	Labels         map[string]string `json:"labels"`
	Annotations    map[string]string `json:"annotations"`
}

Event info used to pass events between functions

func BuildEventFromPushEvent

func BuildEventFromPushEvent(pushEvent PushEvent) *Event

BuildEventFromPushEvent function to build Event from PushEvent

type Function

type Function struct {
	Name            string            `json:"name"`
	Image           string            `json:"image"`
	InvocationCount float64           `json:"invocationCount"`
	Replicas        uint64            `json:"replicas"`
	Labels          map[string]string `json:"labels"`
	Annotations     map[string]string `json:"annotations"`
}

type GitLabProject

type GitLabProject struct {
	ID                int    `json:"id"`
	Namespace         string `json:"namespace"`
	Name              string `json:"name"`
	PathWithNamespace string `json:"path_with_namespace"` //would be repo full name
	WebURL            string `json:"web_url"`
	VisibilityLevel   int    `json:"visibility_level"`
}

type GitLabPushEvent

type GitLabPushEvent struct {
	Ref              string           `json:"ref"`
	UserUsername     string           `json:"user_username"`
	UserEmail        string           `json:"user_email"`
	GitLabProject    GitLabProject    `json:"project"`
	GitLabRepository GitLabRepository `json:"repository"`
	AfterCommitID    string           `json:"after"`
}

GitLabPushEvent as received from GitLab's system hook event

type GitLabRepository

type GitLabRepository struct {
	CloneURL string `json:"git_http_url"`
}

type Installation

type Installation struct {
	Name     string `json:"name"`
	FullName string `json:"full_name"`
}

type InstallationRepositoriesEvent

type InstallationRepositoriesEvent struct {
	Action       string `json:"action"`
	Installation struct {
		Account struct {
			Login string
		}
	} `json:"installation"`
	RepositoriesRemoved []Installation `json:"repositories_removed"`
	RepositoriesAdded   []Installation `json:"repositories_added"`
	Repositories        []Installation `json:"repositories"`
}

type NilLogger

type NilLogger struct {
}

func (NilLogger) Post

func (l NilLogger) Post(auditEvent AuditEvent) error

type Owner

type Owner struct {
	Login string `json:"login"`
	Email string `json:"email"`
	ID    int64  `json:"id"`
}

Owner is the owner of a GitHub repo

type PipelineLog

type PipelineLog struct {
	RepoPath  string
	CommitSHA string
	Function  string
	Source    string
	Data      string
}

PipelineLog stores a log output from a given stage of a pipeline such as the container builder

type PushEvent

type PushEvent struct {
	Ref           string `json:"ref"`
	Repository    PushEventRepository
	AfterCommitID string `json:"after"`
	Installation  PushEventInstallation
	SCM           string // SCM field is for internal use and not provided by GitHub
}

PushEvent is received from GitHub's push event subscription

type PushEventInstallation

type PushEventInstallation struct {
	ID int `json:"id"`
}

type PushEventRepository

type PushEventRepository struct {
	Name          string `json:"name"`
	FullName      string `json:"full_name"`
	CloneURL      string `json:"clone_url"`
	Private       bool   `json:"private"`
	ID            int64  `json:"id"`
	RepositoryURL string `json:"url"`

	Owner Owner `json:"owner"`
}

PushEventRepository represents the repository from a push event

type Sender

type Sender struct {
	Login string `json:"login"`
}

type Status

type Status struct {
	CommitStatuses map[string]CommitStatus `json:"commit-statuses"`
	EventInfo      Event                   `json:"event"`
	AuthToken      string                  `json:"auth-token"`
}

Status to post status to github-status function

func BuildStatus

func BuildStatus(event *Event, token string) *Status

BuildStatus constructs a status object from event

func UnmarshalStatus

func UnmarshalStatus(data []byte) (*Status, error)

UnmarshalStatus unmarshals a status object from json

func (*Status) AddStatus

func (status *Status) AddStatus(state string, desc string, context string)

AddStatus adds a commit status into a status object a status can contain multiple commit status

func (*Status) Clear

func (status *Status) Clear()

Clear removes any statuses which have been added

func (*Status) Marshal

func (status *Status) Marshal() ([]byte, error)

Marshal marshals a status into json

func (*Status) Report

func (status *Status) Report(gateway string, payloadSecret string) (string, error)

Report send a status update to github-status function

Jump to

Keyboard shortcuts

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