common

package
v0.0.0-...-59b3cb6 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const MonacoBaseFolder = "tmp/monaco/"
View Source
const MonacoConfigFilename = "dynatrace/monaco.conf.yaml"

*

  • Defines the Dynatrace Configuration File structure and supporting Constants
View Source
const MonacoConfigFilenameLOCAL = "dynatrace/_monaco.conf.yaml"
View Source
const MonacoExecutable = "./monaco"
View Source
const MonacoProjectsSubfolder = "projects"

Variables

View Source
var RunLocal = (os.Getenv("ENV") == "local")
View Source
var RunLocalTest = (os.Getenv("ENV") == "localtest")

Functions

func CopyFileContentToDestination

func CopyFileContentToDestination(fileContent string, destination string) error

Copy file contents to a destination

func CopyFileContentsToMonacoProject

func CopyFileContentsToMonacoProject(fileContent string, keptnEvent *BaseKeptnEvent) error

func CreateBaseFolderIfNotExist

func CreateBaseFolderIfNotExist() error

Create base folder for all monaco executions

func CreateTempFolderForKeptnContext

func CreateTempFolderForKeptnContext(keptnEvent *BaseKeptnEvent) (error, string)

Create temp folder for keptn context to store project files

func DeleteTempFolderForKeptnContext

func DeleteTempFolderForKeptnContext(keptnEvent *BaseKeptnEvent) error

Delete temp folder for cleanup

func DownloadAllFilesFromSubfolder

func DownloadAllFilesFromSubfolder(keptnEvent *BaseKeptnEvent, projectsPath string) error

*

  • Tries to download all files under the projectsPaths it into a unique folder based on the keptn context id

func DownloadAndExtractMonacoZip

func DownloadAndExtractMonacoZip(keptnEvent *BaseKeptnEvent, zipFilePath string) error

*

  • Tries to download the zip file and if it exists extracts it into a unique folder based on the keptn context id

func ExecuteMonaco

func ExecuteMonaco(dtCredentials *DTCredentials, keptnEvent *BaseKeptnEvent, projects string, verbose bool, dryrun bool) error

func ExtractMonacoArchive

func ExtractMonacoArchive(keptnEvent *BaseKeptnEvent) error

func ExtractZIPArchive

func ExtractZIPArchive(archiveFileName string, outputFolder string) error

func FileExists

func FileExists(filename string) bool

*

  • just returns whether the file exists

func GenerateMonacoProjectStringFromMonacoConfig

func GenerateMonacoProjectStringFromMonacoConfig(monacoConfigFile *MonacoConfigFile, keptnEvent *BaseKeptnEvent) string

func GetAllKeptnResources

func GetAllKeptnResources(project string, stage string, service string, inheritResources bool, resourceUriFolderOfInterest string, localDirectory string) (int, error)

* This function will download ALL Resources from Keptn's Configuration Repository where the name starts with 'resourceUriFolderOfInterest'. This for instance allows us to download all files in the /dynatrace/projects folders * * Parameters: * project, stage, string: reference the keptn repo * inheritResources: if true it will download all resources from service, stage and project level - otherwise just from service level * resourceUriFolderOfInterest: will only download resources where the resourceUri contains that value, e.g: "/jmeter" and then also stores the downloaded files under that prefix * localDirectory: the local directory to store these downloaded files * * Return: * no of resources: total number of downloaded resources * error: any error that occured

func GetConfigurationServiceURL

func GetConfigurationServiceURL() string

Request URL of configuration service

func GetKeptnResource

func GetKeptnResource(keptnEvent *BaseKeptnEvent, resourceURI string) (string, error)

Downloads a resource from the Keptn Configuration Repo In RunLocal mode it gets it from the local disk In normal mode it first tries to find it on service level, then stage and then project level

func GetKubernetesClient

func GetKubernetesClient() (*kubernetes.Clientset, error)

func GetTempMonacoFolder

func GetTempMonacoFolder(keptnEvent *BaseKeptnEvent) string

returns the tmp folder for this run, e.g: tmp/KEPTNCONTEXT-STAGE

func ParseUnixTimestamp

func ParseUnixTimestamp(timestamp string) (time.Time, error)

ParseUnixTimestamp parses a time stamp into Unix foramt

func PrepareFiles

func PrepareFiles(keptnEvent *BaseKeptnEvent) error

func ReplaceKeptnPlaceholders

func ReplaceKeptnPlaceholders(input string, keptnEvent *BaseKeptnEvent) string

replaces $ placeholders with actual values $CONTEXT, $EVENT, $SOURCE $PROJECT, $STAGE, $SERVICE, $DEPLOYMENT $TESTSTRATEGY $LABEL.XXXX -> will replace that with a label called XXXX $ENV.XXXX -> will replace that with an env variable called XXXX $SECRET.YYYY -> will replace that with the k8s secret called YYYY

func TimestampToString

func TimestampToString(time time.Time) string

TimestampToString converts time stamp into string

func Unzip

func Unzip(src string, dest string) ([]string, error)

func UploadKeptnResource

func UploadKeptnResource(contentToUpload []byte, remoteResourceURI string, keptnEvent *BaseKeptnEvent) error

UploadKeptnResource uploads a file to the Keptn Configuration Service

Types

type BaseKeptnEvent

type BaseKeptnEvent struct {
	Context string
	Source  string
	Event   string

	Project            string
	Stage              string
	Service            string
	Deployment         string
	TestStrategy       string
	DeploymentStrategy string

	Image string
	Tag   string

	Labels map[string]string
}

type DTCredentials

type DTCredentials struct {
	Tenant   string `json:"DT_TENANT" yaml:"DT_TENANT"`
	ApiToken string `json:"DT_API_TOKEN" yaml:"DT_API_TOKEN"`
}

func GetDTCredentials

func GetDTCredentials(dynatraceSecretName string) (*DTCredentials, error)

*

  • Pulls the Dynatrace Credentials from the passed secret

type MonacoConfigFile

type MonacoConfigFile struct {
	SpecVersion string   `json:"spec_version" yaml:"spec_version"`
	DtCreds     string   `json:"dtCreds,omitempty" yaml:"dtCreds,omitempty"`
	Projects    []string `json:"projects,omitempty" yaml:"projects,omitempty"`
}

func GetMonacoConfig

func GetMonacoConfig(keptnEvent *BaseKeptnEvent) (*MonacoConfigFile, error)

GetMonacoConfig loads monaco.conf for the current service

Jump to

Keyboard shortcuts

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