cli

package module
v0.1.124 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2024 License: Apache-2.0 Imports: 50 Imported by: 11

README

stuttgart-things/sthingsCli

providing golang building blocks for the use in command line interface modules

MODULES

GIT
CLONE GIT REPOSITORY, GET FILE LIST + READ FILE
gitRepository         := "https://github.com/stuttgart-things/kaeffken.git"
gitBranch             := "main"
gitCommitID           := "09de9ff7b5c76aff8bb32f68cfb0bbe49cd5a7a8"

repo, cloneStatus := sthingsCli.CloneGitRepository(gitRepository, gitBranch, gitCommitID, nil)

if cloneStatus {
    fileList, directoryList = sthingsCli.GetFileListFromGitRepository("", repo)
    fmt.Println(fileList, directoryList)
}

readMe := sthingsCli.ReadFileContentFromGitRepo(repo, "README.md")
fmt.Println(readMe)

TASKFILE

task: Available tasks for this project:
* lint:       Lint code
* tag:        commit, push & tag the module
* test:       Test code

LICENSE

APACHE 2.0

Copyright 2023 patrick hermann.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Author Information

Patrick Hermann, stuttgart-things 04/2023

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddCommitFileToGitRepository added in v0.1.38

func AddCommitFileToGitRepository(repository, branchName string, auth *http.BasicAuth, add []FilesToAdd, remove []string, commitMsg string) (pushed bool)

func AddValueToRedisSet added in v0.1.7

func AddValueToRedisSet(redisClient *redis.Client, setKey, value string) (isSetValueunique bool)

func AskMultiSelectQuestion

func AskMultiSelectQuestion(questionText string, options []string) []string

func AskSingleInputQuestion

func AskSingleInputQuestion(questionText string, defaultAnswer string) string

func AskSingleSelectQuestion

func AskSingleSelectQuestion(questionText string, options []string) string

func CheckIfRedisSearchIndexExists added in v0.1.117

func CheckIfRedisSearchIndexExists(client *redisearch.Client) (bool, error)

CHECK IF REDISEARCH-INDEX EXISTS

func CheckRedisKV added in v0.1.12

func CheckRedisKV(connectionString, redisPassword, key, expectedValue string) (keyValueExists bool)

func CheckUrlAvailability added in v0.1.41

func CheckUrlAvailability(webURL string) bool

func CheckVaultKVExistenceInSecretPath

func CheckVaultKVExistenceInSecretPath(kvpath, token string) bool

func CloneGitRepository added in v0.1.17

func CloneGitRepository(repository, branchName, commitId string, auth *http.BasicAuth) (fs billy.Filesystem, cloned bool)

func ConvertJSONToYAML added in v0.1.32

func ConvertJSONToYAML(jsonString string) string

func ConvertYAMLToJSON added in v0.1.32

func ConvertYAMLToJSON(yamlString string) string

func CreateGitAuth added in v0.1.18

func CreateGitAuth(gitUser, gitToken string) *http.BasicAuth

func CreateGithubClient added in v0.1.124

func CreateGithubClient(token string) *github.Client

func CreateMinioBucket added in v0.1.84

func CreateMinioBucket(minioClient *minio.Client, bucket, location string) bool

func CreateMinioClient added in v0.1.83

func CreateMinioClient() (bool, *minio.Client)

func CreatePullRequest added in v0.1.100

func CreatePullRequest(client *github.Client, prSubject, prRepoOwner, sourceOwner, commitBranch, prRepo, sourceRepo, repoBranch, baseBranch, prDescription string, prLabels []string) (err error, prId string)

CreatePullRequest CREATES A PULL REQUEST. BASED ON: HTTPS://GODOC.ORG/GITHUB.COM/GOOGLE/GO-GITHUB/GITHUB#EXAMPLE-PULLREQUESTSSERVICE-CREATE

func CreateRedisClient added in v0.1.8

func CreateRedisClient(connectionString, redisPassword string) (client *redis.Client)

func CreateRedisConnectionPool added in v0.1.117

func CreateRedisConnectionPool(redisHost, redisPassword string) (pool *redigo.Pool)

CREATE A REDIS CONNECTION POOL

func CreateRedisSearchIndex added in v0.1.117

func CreateRedisSearchIndex(client *redisearch.Client, schema *redisearch.Schema)

CREATE REDISEARCH INDEX

func CreateRepository added in v0.1.104

func CreateRepository(client *github.Client, name, description, repoOwner string, privateRepo, autoInit bool) (err error, repoName string)

CreateRepository CREATES A GITHUB REPOSITORY

func CreateTableHeader added in v0.1.5

func CreateTableHeader(s interface{}) table.Row

func CreateTableRows added in v0.1.6

func CreateTableRows(s interface{}) table.Row

func DecryptSopsFile added in v0.1.111

func DecryptSopsFile(encryptedSopsFilePath, fileExtension string) (err error, decryptedSopsFile string)

func DeleteBranch added in v0.1.106

func DeleteBranch(client *github.Client, repository, repoOwner, branchName string)

DeleteBranch DELETES A BRANCH

func DeleteRedisSet added in v0.1.80

func DeleteRedisSet(redisClient *redis.Client, setKey string) (isSetDeleted bool)

func DownloadFileWithProgressBar added in v0.1.24

func DownloadFileWithProgressBar(downloadUrl, targetDir string)

func DownloadObjectFromMinioBucket added in v0.1.83

func DownloadObjectFromMinioBucket(minioClient *minio.Client, bucket, objectname, destinationName string) bool

func DropRedisSearchIndex added in v0.1.117

func DropRedisSearchIndex(client *redisearch.Client)

DROP REDISEARCH INDEX

func EncryptStore added in v0.1.89

func EncryptStore(ageKey, rawData string) (encryptedData string)

func EnqueueDataInRedisStreams added in v0.1.13

func EnqueueDataInRedisStreams(connectionString, redisPassword, stream string, values map[string]interface{}) (enqueue bool)

func ExecuteRediSearchQuery added in v0.1.120

func ExecuteRediSearchQuery(client *redisearch.Client, query *redisearch.Query) (docs []redisearch.Document, total int, err error)

EXECUTE REDISEARCH QUERY

func ExtractTarGzArchive added in v0.1.31

func ExtractTarGzArchive(archiveFilePath, extractionFilePath string, extractFileMode int)

func GenerateAgeIdentitdy added in v0.1.89

func GenerateAgeIdentitdy() (identity *age.X25519Identity)

func GetAllValuesFromRedis added in v0.1.7

func GetAllValuesFromRedis(redisClient *redis.Client, ctx context.Context, key string) []string

func GetCommitInformationFromGithubRepo added in v0.1.86

func GetCommitInformationFromGithubRepo(userName, repoName, branchName, option string) (getCommits bool, allCommits []map[string]interface{}, err error)

func GetFileContent added in v0.1.93

func GetFileContent(fileArg string) (targetName string, b []byte, err error)

func GetFileContentFromGithubRepo added in v0.1.116

func GetFileContentFromGithubRepo(client *github.Client, userName, repoName, branchName, filePath string) (content string, err error)

func GetFileListFromGitRepository added in v0.1.17

func GetFileListFromGitRepository(directory string, fs billy.Filesystem) (fileList, directoryList []string)

func GetGitTree added in v0.1.93

func GetGitTree(client *github.Client, ref *github.Reference, sourceFiles []string, sourceOwner, sourceRepo string) (tree *github.Tree, err error)

GetGitTree GENERATES THE TREE TO COMMIT BASED ON THE GIVEN FILES AND THE COMMIT OF THE REF YOU GOT IN GETREF.

func GetObjectsFromMinioBucket added in v0.1.83

func GetObjectsFromMinioBucket(minioClient *minio.Client, bucket string) []string

func GetRandomValueFromRedis added in v0.1.7

func GetRandomValueFromRedis(redisClient *redis.Client, ctx context.Context, key string) string

func GetRedisJSON added in v0.1.33

func GetRedisJSON(redisJSONHandler *rejson.Handler, jsonKey string) (jsonObject []byte, jsonExists bool)

func GetReferenceObject added in v0.1.94

func GetReferenceObject(client *github.Client, sourceOwner, sourceRepo, commitBranch, baseBranch string) (ref *github.Reference, err error)

GetReferenceObject RETURNS THE COMMIT BRANCH REFERENCE OBJECT IF IT EXISTS OR CREATES IT FROM THE BASE BRANCH BEFORE RETURNING IT.

func GetSecretValueFromVaultSecretEngine

func GetSecretValueFromVaultSecretEngine(vaultConnectionInformation map[string]string) (string, string, string, string)

func GetUnderlyingAsValue added in v0.1.6

func GetUnderlyingAsValue(data interface{}) reflect.Value

func GetValueFromRedisByKey added in v0.1.83

func GetValueFromRedisByKey(redisClient *redis.Client, key string) (value string)

func GetValuesFromRedisSet added in v0.1.11

func GetValuesFromRedisSet(redisClient *redis.Client, setKey string) (values []string)

func GetVaultConnectionInformation

func GetVaultConnectionInformation() map[string]string

func GetVaultKvSecretEngines

func GetVaultKvSecretEngines(vaultAddr, vaultToken, vaultNamespace string) []string

func GetVaultKvSecretPaths

func GetVaultKvSecretPaths(vaultAddr, vaultToken, vaultNamespace, kvpath string) []string

func GetVaultSecretValue

func GetVaultSecretValue(kvpath, token string) string

func GetYAMLMapValues added in v0.1.108

func GetYAMLMapValues(content []byte, dictName string) (transformedValues map[string]interface{})

func GetYamlStringKey added in v0.1.47

func GetYamlStringKey(key, pathToConfig, extension string) string

func IndexDocument added in v0.1.119

func IndexDocument(client *redisearch.Client, document redisearch.Document)

INDEX DOCUMENT

func MergePullRequest added in v0.1.105

func MergePullRequest(client *github.Client, repository, repoOwner, message, mergeMethod string, pullRequestID int)

CreateRepository CREATES A GITHUB REPOSITORY

func PushCommit added in v0.1.99

func PushCommit(client *github.Client, ref *github.Reference, tree *github.Tree, sourceOwner, sourceRepo, authorName, authorEmail, commitMessage string) (err error)

PushCommit CREATES THE COMMIT IN THE GIVEN REFERENCE USING THE GIVEN TREE

func ReadFileContentFromGitRepo added in v0.1.21

func ReadFileContentFromGitRepo(repo billy.Filesystem, filePath string) string

func ReadFileToVar added in v0.1.93

func ReadFileToVar(file string) (content []byte, err error)

func ReadInlineYamlToObject added in v0.1.22

func ReadInlineYamlToObject(inlineYAML []byte, yamlObject interface{}) interface{}

func ReadVaultSecretEngines

func ReadVaultSecretEngines(vaultAddr, vaultToken, vaultNamespace, kvpath string) []string

func ReadYamlKeyValuesFromFile added in v0.1.37

func ReadYamlKeyValuesFromFile(yamlFileContent []byte) (yamlStructure map[string]interface{})

func ReadYamlToObject added in v0.1.20

func ReadYamlToObject(pathToYAML, fileExtension string, yamlObject interface{}) interface{}

func RemoveValueFromRedis added in v0.1.7

func RemoveValueFromRedis(redisClient *redis.Client, ctx context.Context, key string, member string) bool

func RenderTemplateSurvey added in v0.1.46

func RenderTemplateSurvey(templateContent string, globalValues map[string]interface{}) (string, map[string]interface{})

func SendWebhookToTeams added in v0.1.10

func SendWebhookToTeams(webhook MsTeamsWebhook) bool

func SetRedisJSON added in v0.1.36

func SetRedisJSON(redisJSONHandler *rejson.Handler, jsonObject interface{}, jsonKey string)

func StoreSecretInSecretEngine

func StoreSecretInSecretEngine(vaultAddr, vaultToken, vaultNamespace, secretEngine, secretName string, secretData map[string]interface{})

func UnZipArchive added in v0.1.30

func UnZipArchive(source, destination string) error

func UploadObjectToMinioBucket added in v0.1.83

func UploadObjectToMinioBucket(minioClient *minio.Client, bucket, sourcePath, objectName string) (bool, int64)

func VerifyEnvVars

func VerifyEnvVars(envVars []string) bool

func VerifyReadKeyValues added in v0.1.122

func VerifyReadKeyValues(templateValues []string, log *sthingsBase.Logger, enableVault bool) map[string]interface{}

func VerifyVaultAuthType added in v0.1.122

func VerifyVaultAuthType(vaultAuthType string, log *sthingsBase.Logger, vaultAuthFound bool)

func VerifyVaultEnvVars added in v0.1.9

func VerifyVaultEnvVars() (string, bool)

Types

type Client

type Client struct {
	Token         string
	Client        *api.Client
	LeaseDuration int
}

func CreateVaultClient

func CreateVaultClient() (*Client, error)

func (*Client) GetVaultTokenFromAppRole

func (vaultClient *Client) GetVaultTokenFromAppRole() (string, error)

type FilesToAdd added in v0.1.107

type FilesToAdd struct {
	Filename    string
	Filecontent []byte
}

type MsTeamsWebhook added in v0.1.10

type MsTeamsWebhook struct {
	Title string `yaml:"title"`
	Text  string `yaml:"text"`
	Color string `yaml:"color"`
	Url   string `yaml:"url"`
}

type RenderSurvey added in v0.1.46

type RenderSurvey struct {
	SingleInputSurvey  func(string) string
	SingleSelectSurvey func(string) string
}

type Token

type Token struct {
	Auth struct {
		ClientToken   string `json:"client_token"`
		LeaseDuration int    `json:"lease_duration"`
	} `json:"auth"`
}

Jump to

Keyboard shortcuts

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