How to use getConsolidatedConfig method of cmd Package

Best K6 code snippet using cmd.getConsolidatedConfig

handlers.go

Source:handlers.go Github

copy

Full Screen

1/*2Copyright 2019 The Fossul Authors.3Licensed under the Apache License, Version 2.0 (the "License");4you may not use this file except in compliance with the License.5You may obtain a copy of the License at6 http://www.apache.org/licenses/LICENSE-2.07Unless required by applicable law or agreed to in writing, software8distributed under the License is distributed on an "AS IS" BASIS,9WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.10See the License for the specific language governing permissions and11limitations under the License.12*/13package main14import (15 "encoding/json"16 "net/http"17 "os"18 "strings"19 "fmt"20 "github.com/fossul/fossul/src/client"21 "github.com/fossul/fossul/src/client/k8s"22 "github.com/fossul/fossul/src/engine/util"23 "github.com/fossul/fossul/src/plugins/pluginUtil"24 "github.com/gorilla/mux"25)26// GetStatus godoc27// @Description Status and version information for the service28// @Accept json29// @Produce json30// @Success 200 {string} string31// @Header 200 {string} string32// @Failure 400 {string} string33// @Failure 404 {string} string34// @Failure 500 {string} string35// @Router /status [get]36func GetStatus(w http.ResponseWriter, r *http.Request) {37 var status util.Status38 status.Msg = "OK"39 status.Version = version40 json.NewEncoder(w).Encode(status)41}42// SendTrapSuccessCmd godoc43// @Description Execute command after successfull workflow execution44// @Param config body util.Config true "config struct"45// @Accept json46// @Produce json47// @Success 200 {object} util.Result48// @Header 200 {string} string49// @Failure 400 {string} string50// @Failure 404 {string} string51// @Failure 500 {string} string52// @Router /sendTrapSuccessCmd [post]53func SendTrapSuccessCmd(w http.ResponseWriter, r *http.Request) {54 var result util.Result55 var messages []util.Message56 config, err := util.GetConfig(w, r)57 printConfigDebug(config)58 if err != nil {59 message := util.SetMessage("ERROR", "Couldn't read config! "+err.Error())60 messages = append(messages, message)61 result = util.SetResult(1, messages)62 _ = json.NewDecoder(r.Body).Decode(&result)63 json.NewEncoder(w).Encode(result)64 return65 }66 if config.SendTrapSuccessCmd != "" {67 args := strings.Split(config.SendTrapSuccessCmd, ",")68 message := util.SetMessage("INFO", "Performing send trap success command ["+config.SendTrapSuccessCmd+"]")69 result = util.ExecuteCommand(args...)70 result.Messages = util.PrependMessage(message, result.Messages)71 _ = json.NewDecoder(r.Body).Decode(&result)72 json.NewEncoder(w).Encode(result)73 }74}75// SendTrapErrorCmd godoc76// @Description Execute command after failed workflow execution77// @Param config body util.Config true "config struct"78// @Accept json79// @Produce json80// @Success 200 {object} util.Result81// @Header 200 {string} string82// @Failure 400 {string} string83// @Failure 404 {string} string84// @Failure 500 {string} string85// @Router /sendTrapErrorCmd [post]86func SendTrapErrorCmd(w http.ResponseWriter, r *http.Request) {87 var result util.Result88 var messages []util.Message89 config, err := util.GetConfig(w, r)90 printConfigDebug(config)91 if err != nil {92 message := util.SetMessage("ERROR", "Couldn't read config! "+err.Error())93 messages = append(messages, message)94 result = util.SetResult(1, messages)95 _ = json.NewDecoder(r.Body).Decode(&result)96 json.NewEncoder(w).Encode(result)97 return98 }99 if config.SendTrapErrorCmd != "" {100 args := strings.Split(config.SendTrapErrorCmd, ",")101 message := util.SetMessage("INFO", "Performing send trap error command ["+config.SendTrapErrorCmd+"]")102 result = util.ExecuteCommand(args...)103 result.Messages = util.PrependMessage(message, result.Messages)104 _ = json.NewDecoder(r.Body).Decode(&result)105 json.NewEncoder(w).Encode(result)106 }107}108// GetJobs godoc109// @Description Get jobs (workflows) that have executed for a profile/config110// @Param profileName path string true "name of profile"111// @Param configName path string true "name of config"112// @Accept json113// @Produce json114// @Success 200 {object} util.Jobs115// @Header 200 {string} string116// @Failure 400 {string} string117// @Failure 404 {string} string118// @Failure 500 {string} string119// @Router /getJobs/{profileName}/{configName} [get]120func GetJobs(w http.ResponseWriter, r *http.Request) {121 params := mux.Vars(r)122 var profileName string = params["profileName"]123 var configName string = params["configName"]124 jobsDir := dataDir + "/" + profileName + "/" + configName125 var result util.Result126 var messages []util.Message127 var jobs util.Jobs128 var jobList []util.Job129 jobList, err := util.ListJobs(jobsDir)130 if err != nil {131 msg := util.SetMessage("ERROR", "Job list failed! "+err.Error())132 messages = append(messages, msg)133 result = util.SetResult(1, messages)134 jobs.Result = result135 _ = json.NewDecoder(r.Body).Decode(&jobs)136 json.NewEncoder(w).Encode(jobs)137 }138 jobs.Result.Code = 0139 jobs.Jobs = jobList140 _ = json.NewDecoder(r.Body).Decode(&jobs)141 json.NewEncoder(w).Encode(jobs)142}143// DeleteBackup godoc144// @Description Delete a individual backup145// @Param profileName path string true "name of profile"146// @Param configName path string true "name of config"147// @Param policy path string true "name of backup policy"148// @Param workflowId path string true "workflow id"149// @Accept json150// @Produce json151// @Success 200 {object} util.Result152// @Header 200 {string} string153// @Failure 400 {string} string154// @Failure 404 {string} string155// @Failure 500 {string} string156// @Router /deleteBackup/{profileName}/{configName}/{policy}/{workflowId} [get]157func DeleteBackup(w http.ResponseWriter, r *http.Request) {158 auth := SetAuth()159 params := mux.Vars(r)160 var profileName string = params["profileName"]161 var configName string = params["configName"]162 var policyName string = params["policy"]163 var selectedWorkflowId string = params["workflowId"]164 backupFile := dataDir + "/" + profileName + "/" + configName + "/" + selectedWorkflowId + "/backup"165 var result util.Result166 var messages []util.Message167 config, err := util.GetConsolidatedConfig(configDir, profileName, configName, policyName)168 printConfigDebug(config)169 config.SelectedWorkflowId = util.StringToInt(selectedWorkflowId)170 if err != nil {171 message := util.SetMessage("ERROR", "Couldn't read config! "+err.Error())172 messages = append(messages, message)173 result = util.SetResult(1, messages)174 _ = json.NewDecoder(r.Body).Decode(&result)175 json.NewEncoder(w).Encode(result)176 return177 }178 result, err = client.BackupDelete(auth, config)179 if err != nil {180 message := util.SetMessage("ERROR", err.Error())181 messages = append(messages, message)182 result = util.SetResult(1, messages)183 _ = json.NewDecoder(r.Body).Decode(&result)184 json.NewEncoder(w).Encode(result)185 return186 } else {187 err = os.Remove(backupFile)188 if err != nil {189 message := util.SetMessage("ERROR", err.Error())190 messages = append(messages, message)191 result = util.SetResult(1, messages)192 _ = json.NewDecoder(r.Body).Decode(&result)193 json.NewEncoder(w).Encode(result)194 }195 _ = json.NewDecoder(r.Body).Decode(&result)196 json.NewEncoder(w).Encode(result)197 }198}199// GetBackup godoc200// @Description Get a individual backup201// @Param profileName path string true "name of profile"202// @Param configName path string true "name of config"203// @Param workflowId path string true "workflow id"204// @Accept json205// @Produce json206// @Success 200 {object} util.BackupByWorkflow207// @Header 200 {string} string208// @Failure 400 {string} string209// @Failure 404 {string} string210// @Failure 500 {string} string211// @Router /getBackup/{profileName}/{configName}/{workflowId} [get]212func GetBackup(w http.ResponseWriter, r *http.Request) {213 params := mux.Vars(r)214 var profileName string = params["profileName"]215 var configName string = params["configName"]216 var selectedWorkflowId string = params["workflowId"]217 var backupByWorkflow util.BackupByWorkflow218 backup := &util.Backup{}219 var result util.Result220 var messages []util.Message221 backupFile := dataDir + "/" + profileName + "/" + configName + "/" + selectedWorkflowId + "/" + "backup"222 err := util.ReadGob(backupFile, &backup)223 if err != nil {224 message := util.SetMessage("ERROR", "Couldn't read backup! "+err.Error())225 messages = append(messages, message)226 result = util.SetResult(1, messages)227 backupByWorkflow.Result = result228 _ = json.NewDecoder(r.Body).Decode(&backupByWorkflow)229 json.NewEncoder(w).Encode(backupByWorkflow)230 return231 }232 if err != nil {233 message := util.SetMessage("ERROR", "Couldn't read backup! "+err.Error())234 messages = append(messages, message)235 result = util.SetResult(1, messages)236 backupByWorkflow.Result = result237 _ = json.NewDecoder(r.Body).Decode(&backupByWorkflow)238 json.NewEncoder(w).Encode(backupByWorkflow)239 } else {240 backupByWorkflow.Backup = *backup241 message := util.SetMessage("INFO", "Get backup for workflow id ["+selectedWorkflowId+"] completed successfully")242 messages = append(messages, message)243 result = util.SetResult(0, messages)244 backupByWorkflow.Result = result245 _ = json.NewDecoder(r.Body).Decode(&backupByWorkflow)246 json.NewEncoder(w).Encode(backupByWorkflow)247 }248}249// UpdateBackupCustomResource godoc250// @Description Update custom backup resource251// @Param profileName path string true "name of profile"252// @Param configName path string true "name of config"253// @Param policy path string true "name of backup policy"254// @Param crName path string true "name of custom resource"255// @Param op path string true "operation for patching resource"256// @Param specKey path string true "spec key we want to alter"257// @Param specValue path string true "spec key's value we want to alter"258// @Accept json259// @Produce json260// @Success 200 {object} util.Result261// @Header 200 {string} string262// @Failure 400 {string} string263// @Failure 404 {string} string264// @Failure 500 {string} string265// @Router /updateBackupCustomResource/{profileName}/{configName}/{policy}/{crName}/{op}/{specKey}/{specValue} [get]266func UpdateBackupCustomResource(w http.ResponseWriter, r *http.Request) {267 params := mux.Vars(r)268 var profileName string = params["profileName"]269 var configName string = params["configName"]270 var policyName string = params["policy"]271 var crName string = params["crName"]272 var op string = params["op"]273 var specKey string = params["specKey"]274 var specValue string = params["specValue"]275 var result util.Result276 var messages []util.Message277 config, err := util.GetConsolidatedConfig(configDir, profileName, configName, policyName)278 printConfigDebug(config)279 msg := util.SetMessage("INFO", "Updating custom resource ["+crName+"] with workflowId ["+params["specValue"]+"]")280 messages = append(messages, msg)281 err = k8s.UpdateBackupCustomResource(config.AccessWithinCluster, profileName, crName, op, specKey, specValue)282 if err != nil {283 message := util.SetMessage("ERROR", err.Error())284 messages = append(messages, message)285 result = util.SetResult(1, messages)286 _ = json.NewDecoder(r.Body).Decode(&result)287 json.NewEncoder(w).Encode(result)288 return289 } else {290 msg := util.SetMessage("INFO", "Updating custom resource ["+crName+"] with workflowId ["+params["specValue"]+"] completed successfully")291 messages = append(messages, msg)292 result = util.SetResult(0, messages)293 _ = json.NewDecoder(r.Body).Decode(&result)294 json.NewEncoder(w).Encode(result)295 }296}297// CreateBackupCustomResource godoc298// @Description Update custom backup resource299// @Param profileName path string true "name of profile"300// @Param configName path string true "name of config"301// @Param policy path string true "name of backup policy"302// @Param workflowId path string true "workflow id"303// @Param timestamp path string true "timestamp of custom resource creation"304// @Accept json305// @Produce json306// @Success 200 {object} util.Result307// @Header 200 {string} string308// @Failure 400 {string} string309// @Failure 404 {string} string310// @Failure 500 {string} string311// @Router /createBackupCustomResource/{profileName}/{configName}/{policy}/{workflowId}/{timestamp} [get]312func CreateBackupCustomResource(w http.ResponseWriter, r *http.Request) {313 params := mux.Vars(r)314 var profileName string = params["profileName"]315 var configName string = params["configName"]316 var policyName string = params["policy"]317 var workflowId string = params["workflowId"]318 var timestamp string = params["timestamp"]319 var result util.Result320 var messages []util.Message321 config, err := util.GetConsolidatedConfig(configDir, profileName, configName, policyName)322 printConfigDebug(config)323 backupName := util.GetBackupName(config.StoragePluginParameters["BackupName"], config.SelectedBackupPolicy, workflowId, timestamp)324 msg := util.SetMessage("INFO", "Creating backup custom resource ["+backupName+"]")325 messages = append(messages, msg)326 err = k8s.CreateBackupCustomResource(config.AccessWithinCluster, profileName, backupName, profileName, configName, policyName)327 if err != nil {328 message := util.SetMessage("ERROR", err.Error())329 messages = append(messages, message)330 result = util.SetResult(1, messages)331 _ = json.NewDecoder(r.Body).Decode(&result)332 json.NewEncoder(w).Encode(result)333 return334 } else {335 msg := util.SetMessage("INFO", "Creating backup custom resource ["+backupName+"] completed successfully")336 messages = append(messages, msg)337 result = util.SetResult(0, messages)338 _ = json.NewDecoder(r.Body).Decode(&result)339 json.NewEncoder(w).Encode(result)340 }341}342// DeleteBackupCustomResource godoc343// @Description Update custom backup resource344// @Param profileName path string true "name of profile"345// @Param configName path string true "name of config"346// @Param policy path string true "name of backup policy"347// @Param crName path string true "name of custom resource"348// @Accept json349// @Produce json350// @Success 200 {object} util.Result351// @Header 200 {string} string352// @Failure 400 {string} string353// @Failure 404 {string} string354// @Failure 500 {string} string355// @Router /deleteBackupCustomResource/{profileName}/{configName}/{policy}/{crName} [get]356func DeleteBackupCustomResource(w http.ResponseWriter, r *http.Request) {357 params := mux.Vars(r)358 var profileName string = params["profileName"]359 var configName string = params["configName"]360 var policyName string = params["policy"]361 var crName string = params["crName"]362 var result util.Result363 var messages []util.Message364 config, err := util.GetConsolidatedConfig(configDir, profileName, configName, policyName)365 printConfigDebug(config)366 msg := util.SetMessage("INFO", "Deleting backup custom resource ["+crName+"]")367 messages = append(messages, msg)368 err = k8s.DeleteBackupCustomResource(config.AccessWithinCluster, profileName, crName)369 if err != nil {370 message := util.SetMessage("ERROR", err.Error())371 messages = append(messages, message)372 result = util.SetResult(1, messages)373 _ = json.NewDecoder(r.Body).Decode(&result)374 json.NewEncoder(w).Encode(result)375 return376 } else {377 msg := util.SetMessage("INFO", "Deleting backup custom resource ["+crName+"] completed successfully")378 messages = append(messages, msg)379 result = util.SetResult(0, messages)380 _ = json.NewDecoder(r.Body).Decode(&result)381 json.NewEncoder(w).Encode(result)382 }383}384// BackupCustomResourceRetention godoc385// @Description Update custom backup resource386// @Param profileName path string true "name of profile"387// @Param configName path string true "name of config"388// @Param policy path string true "name of backup policy"389// @Accept json390// @Produce json391// @Success 200 {object} util.Result392// @Header 200 {string} string393// @Failure 400 {string} string394// @Failure 404 {string} string395// @Failure 500 {string} string396// @Router /deleteBackupCustomResource/{profileName}/{configName}/{policy} [get]397func BackupCustomResourceRetention(w http.ResponseWriter, r *http.Request) {398 params := mux.Vars(r)399 var profileName string = params["profileName"]400 var configName string = params["configName"]401 var policyName string = params["policy"]402 var result util.Result403 var messages []util.Message404 config, err := util.GetConsolidatedConfig(configDir, profileName, configName, policyName)405 printConfigDebug(config)406 var backupList []string407 backupCustomResourceList, err := k8s.ListBackupCustomResources(config.AccessWithinCluster, profileName)408 for _, backupCustomResource := range backupCustomResourceList.Items {409 backupCustomResourceName := backupCustomResource.GetName()410 backupList = append(backupList, backupCustomResourceName)411 }412 backups, err := pluginUtil.ListCustomResourceBackups(backupList, config.StoragePluginParameters["BackupName"])413 if err != nil {414 msg := util.SetMessage("ERROR", err.Error())415 messages = append(messages, msg)416 result = util.SetResult(1, messages)417 _ = json.NewDecoder(r.Body).Decode(&result)418 json.NewEncoder(w).Encode(result)419 return420 }421 backupsByPolicy := util.GetBackupsByPolicy(config.SelectedBackupPolicy, backups)422 backupCount := len(backupsByPolicy)423 if backupCount > config.SelectedBackupRetention {424 count := 1425 for backup := range pluginUtil.ReverseBackupList(backupsByPolicy) {426 if count > config.SelectedBackupRetention {427 msg := util.SetMessage("INFO", fmt.Sprintf("Number of backups [%d] greater than backup retention [%d]", backupCount, config.SelectedBackupRetention))428 messages = append(messages, msg)429 backupCount = backupCount - 1430 for _, content := range backup.Contents {431 backupName := content.Data432 msg = util.SetMessage("INFO", "Deleting backup "+backupName)433 messages = append(messages, msg)434 err := k8s.DeleteBackupCustomResource(config.AccessWithinCluster, config.ProfileName, backupName)435 if err != nil {436 msg := util.SetMessage("ERROR", err.Error())437 messages = append(messages, msg)438 result = util.SetResult(1, messages)439 _ = json.NewDecoder(r.Body).Decode(&result)440 json.NewEncoder(w).Encode(result)441 return442 }443 msg = util.SetMessage("INFO", "Backup "+backupName+" deleted successfully")444 messages = append(messages, msg)445 }446 }447 count = count + 1448 }449 } else {450 msg := util.SetMessage("INFO", fmt.Sprintf("Backup deletion skipped, there are [%d] backups but backup retention is [%d]", backupCount, config.SelectedBackupRetention))451 messages = append(messages, msg)452 }453 result = util.SetResult(0, messages)454 _ = json.NewDecoder(r.Body).Decode(&result)455 json.NewEncoder(w).Encode(result)456}...

Full Screen

Full Screen

archive.go

Source:archive.go Github

copy

Full Screen

...61 cliOpts, err := getOptions(cmd.Flags())62 if err != nil {63 return err64 }65 conf, err := getConsolidatedConfig(afero.NewOsFs(), Config{Options: cliOpts}, r)66 if err != nil {67 return err68 }69 if _, cerr := deriveAndValidateConfig(conf); cerr != nil {70 return ExitCode{error: cerr, Code: invalidConfigErrorCode}71 }72 err = r.SetOptions(conf.Options)73 if err != nil {74 return err75 }76 // Archive.77 arc := r.MakeArchive()78 f, err := os.Create(archiveOut)79 if err != nil {...

Full Screen

Full Screen

getConsolidatedConfig

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello, playground")4 authorizer, err := auth.NewAuthorizerFromEnvironment()5 if err == nil {6 client := insights.NewDiagnosticSettingsClient(subscriptionId)7 consolidatedConfig, err := client.GetConsolidatedConfig(subscriptionId)8 if err == nil {9 fmt.Println(*consolidatedConfig)10 } else {11 fmt.Println(err)12 }13 } else {14 fmt.Println(err)15 }16}

Full Screen

Full Screen

getConsolidatedConfig

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 cmd := &cmd{}4 fmt.Println(cmd.getConsolidatedConfig())5}6import (7func main() {8 cmd := &cmd{}

Full Screen

Full Screen

getConsolidatedConfig

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 err := shim.Start(new(SampleChaincode))4 if err != nil {5 fmt.Printf("Error starting Sample chaincode: %s", err)6 }7}8type SampleChaincode struct {9}10func (t *SampleChaincode) Init(stub shim.ChaincodeStubInterface, function string, args []string) ([]byte, error) {11}12func (t *SampleChaincode) Invoke(stub shim.ChaincodeStubInterface, function string, args []string) ([]byte, error) {13}14func (t *SampleChaincode) Query(stub shim.ChaincodeStubInterface, function string, args []string) ([]byte, error) {15 if function == "getConsolidatedConfig" {16 return getConsolidatedConfig(stub, args)17 }18}19func getConsolidatedConfig(stub shim.ChaincodeStubInterface, args []string) ([]byte, error) {20 config, err := stub.GetConsolidatedConfig()21 if err != nil {22 }23}24import (25func main() {26 err := shim.Start(new(SampleChaincode))27 if err != nil {28 fmt.Printf("Error starting Sample chaincode: %s", err)29 }30}31type SampleChaincode struct {32}33func (t *SampleChaincode) Init(stub shim.ChaincodeStubInterface, function string, args []string) ([]byte, error) {34}35func (t *SampleChaincode) Invoke(stub shim.ChaincodeStubInterface, function string, args []string) ([]byte, error) {36}37func (t *SampleChaincode) Query(stub shim.ChaincodeStubInterface, function string, args []string) ([]byte, error) {

Full Screen

Full Screen

getConsolidatedConfig

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 config, _ := config.New()4 fmt.Println(config.GetConsolidatedConfig())5}6import (7func main() {8 config, _ := config.New()9 fmt.Println(config.GetConsolidatedConfig())10}11import (12func main() {13 config, _ := config.New()14 fmt.Println(config.GetConsolidatedConfig())15}16import (17func main() {18 config, _ := config.New()19 fmt.Println(config.GetConsolidatedConfig())20}21import (22func main() {23 config, _ := config.New()24 fmt.Println(config.GetConsolidatedConfig())25}26import (27func main() {28 config, _ := config.New()29 fmt.Println(config.GetConsolidatedConfig())30}31import (32func main() {33 config, _ := config.New()34 fmt.Println(config.GetConsolidatedConfig())35}36import (37func main() {38 config, _ := config.New()

Full Screen

Full Screen

getConsolidatedConfig

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 viper.SetConfigName("config")4 viper.AddConfigPath("./")5 viper.SetConfigType("yaml")6 err := viper.ReadInConfig()7 if err != nil {8 fmt.Println("Error reading config file, %s", err)9 }10 fmt.Println(viper.Get("port"))11}12import (13func main() {14 viper.SetConfigName("config")15 viper.AddConfigPath("./")16 viper.SetConfigType("yaml")17 err := viper.ReadInConfig()18 if err != nil {19 fmt.Println("Error reading config file, %s", err)20 }21 fmt.Println(viper.Get("port"))22}23main.main()

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run K6 automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful