utils

package
v0.0.0-...-88a3487 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2020 License: Apache-2.0 Imports: 34 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ACTIVE             = "active"
	TRIGGER_TEKTON_DEV = "triggers.tekton.dev"
	EVENT_LISTENER     = "EventListener"
)
View Source
const (
	V1                         = "v1"
	V1ALPHA1                   = "v1alpha1"
	KABANEROIO                 = "kabanero.io"
	KABANEROS                  = "kabaneros"
	ANNOTATIONS                = "annotations"
	DATA                       = "data"
	URL                        = "url"
	USERNAME                   = "username"
	PASSWORD                   = "password"
	SECRETS                    = "secrets"
	SPEC                       = "spec"
	COLLECTIONS                = "collections"
	REPOSITORIES               = "repositories"
	ACTIVATEDEFAULTCOLLECTIONS = "activateDefaultCollections"
	METADATA                   = "metadata"
)

Kubernetes and Kabanero yaml constants

View Source
const (
	TRIGGERS = "triggers"
	CHKSUM   = "sha256"
)

constants

Variables

This section is empty.

Functions

func DecompressGzipTar

func DecompressGzipTar(readCloser io.ReadCloser, dir string) error

DecompressGzipTar Decompresses and extracts a tar.gz file.

func DownloadFileFromGithub

func DownloadFileFromGithub(owner, repository, fileName, ref, githubURL, user, token string, isEnterprise bool) ([]byte, bool, error)

DownloadFileFromGithub Downloads a file and returns: bytes of the file, true if file exists, and any error

func DownloadTrigger

func DownloadTrigger(triggerURL, triggerChkSum, dir string, verifyChkSum bool) error

DownloadTrigger Download the trigger.tar.gz and unpack into the directory

triggerURL: URL that serves the trigger gzipped tar
triggerChkSum: the sha256 checksum of the trigger archive
dir: directory to unpack the trigger.tar.gz

func DownloadYAML

func DownloadYAML(kubeClient client.Client, namespace string, secretName string, header map[string][]string, bodyMap map[string]interface{}, fileName string) (map[string]interface{}, bool, error)

DownloadYAML Downloads a YAML file from a git repository.

kubeClient: controller client to API server
namespace: namespace to look for secret to github
secretName name of the secret containing the token to access github
header: HTTP header from webhook
bodyMap: HTTP  message body from webhook

func EventListenerURL

func EventListenerURL(kubeClient client.Client, namespace string, name string) (string, error)

FInd URL for EventListener

func FindEventListenerForStack

func FindEventListenerForStack(kubeClient client.Client, namespace string, repoStackImage string, repoStackVersion string) (string, string, error)
Find the Kabanero Tekton event listener for stack

input:

kubeClient: client to API server
namespace: namespace of stack to search for event listener
repoStackImage:  the name  of image as specified in .appsody-config.yaml. For example, "docker.io/appsody/nodejs:0.3"
repoStackVersion: the semantic version for the stack, as specified in .appsody-config.yaml. For example "0.3"

Return:

name of listener, or "" if no match
exact version found
error : if any error occurred when matching the repository to an event listener

func GetGitHubSecret

func GetGitHubSecret(kubeClient client.Client, namespace string, name string, repoURL string) (string, string, error)

GetGitHubSecret Find the user/token for a GitHub API key. The format of the secret: apiVersion: v1 kind: Secret metadata:

name: gh-https-secret
annotations:
  tekton.dev/git-0: https://github.com

type: kubernetes.io/basic-auth stringData:

username: <username>
password: <token>

This will scan for a secret with either of the following annotations:

  • tekton.dev/git-*
  • kabanero.io/git-*

GetGitHubSecret will return the username and token of a secret whose annotation's value is a prefix match for repoURL. Note that a secret with the `kabanero.io/git-*` annotation is preferred over one with `tekton.dev/git-*`. Return: username, token, error Input:

kubeClient: client to API server
namespace: namespace to look for secret
name: name of the secret, or "" to auto-scan
repoURL: name of the repository

func GetTriggerInfo

func GetTriggerInfo(client rest.Interface, namespace string) (*url.URL, string, error)

GetTriggerInfo Get the URL to trigger gzipped tar and its sha256 checksum.

func GetWebhookSecret

func GetWebhookSecret(kubeClient client.Client, namespace string, name string) (string, error)

Get value of Webhook secret

func IsHeaderGithub

func IsHeaderGithub(header map[string][]string) bool

Return true if header is from Github event

func MergePathWithErrorCheck

func MergePathWithErrorCheck(dir string, toMerge string) (string, error)

MergePathWithErrorCheck Merge a directory path with a relative path. Return error if the rectory not a prefix of the merged path after the merge

func NewDynamicClient

func NewDynamicClient(kubeConfig *rest.Config) (dynamic.Interface, error)

NewDynamicClient Creates a new dynamic client

func NewKubeClient

func NewKubeClient(kubeConfig *rest.Config) (*kubernetes.Clientset, error)

NewKubeClient Creates a new kube client

func NewKubeConfig

func NewKubeConfig(masterURL, kubeconfigPath string) (*rest.Config, error)

NewKubeConfig Creates a new kube config

func ParseGithubURL

func ParseGithubURL(url string) (server, org, repo string, err error)

Parse Github URL into server, org, and repo

Input: url for the github server, e.g., https://github.com/org/repo
OUtput:
   server:  The server, e.g., github.com
   org:  The org portion of the url
   repo: The name of the repo

func ReadFile

func ReadFile(fileName string) ([]byte, error)

ReadFile Reads a file and returns the bytes.

func ReadHTTPURL

func ReadHTTPURL(url string) ([]byte, error)

ReadHTTPURL Read remote file from URL and return bytes

func ReadJSON

func ReadJSON(fileName string) (*unstructured.Unstructured, error)

ReadJSON reads a JSON file and returns it as an unstructured.Unstructured object.

func ToDomainName

func ToDomainName(name string) string

ToDomainName Convert a name to domain name format. The name must:

  • Start with [a-z0-9]. If not, "0" is prepended.
  • lower case. If not, lower case is used.
  • contain only '.', '-', and [a-z0-9]. If not, "." is used insteaad.
  • end with alpha numeric characters. Otherwise, '0' is appended
  • can't have consecutive '.'. Consecutive ".." is substituted with ".".

Returns the empty string if the name is empty after conversion

func ToLabel

func ToLabel(input string) string

ToLabel Convert a string to Kubernetes label format.

func ToLabelName

func ToLabelName(name string) string

ToLabelName Convert the name part of a label. The name must:

  • Start with [a-z0-9A-Z]. If not, "0" is prepended.
  • End with [a-z0-9A-Z]. If not, "0" is appended
  • Intermediate characters can only be: [a-z0-9A-Z] or '_', '-', and '.' If not, '.' is used.
  • be maximum maxLabelLength characters long

func UpdateStatus

func UpdateStatus(ctrlClient client.Client, namespace string, name string, summary []eventsv1alpha1.EventStatusSummary) error

Update status for mediator

func ValidatePayload

func ValidatePayload(sigType, sigHash, secret string, payload []byte) error

ValidatePayload verifies that a payload hashed with some secret matches the expected signature

func YAMLToMap

func YAMLToMap(bytes []byte) (map[string]interface{}, error)

YAMLToMap Converts a YAML byte array to a map.

Types

type HashFunc

type HashFunc func() hash.Hash

Jump to

Keyboard shortcuts

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