How to use GetProperty method of config Package

Best Gauge code snippet using config.GetProperty

handler.go

Source:handler.go Github

copy

Full Screen

...60 authURL, err := c.GetRequiredProperty("OS_AUTH_URL")61 if err != nil {62 return nil, err63 }64 applicationCredentialID := c.GetProperty("OS_APPLICATION_CREDENTIAL_ID", "applicationCredentialID")65 applicationCredentialName := c.GetProperty("OS_APPLICATION_CREDENTIAL_NAME", "applicationCredentialName")66 applicationCredentialSecret := c.GetProperty("OS_APPLICATION_CREDENTIAL_SECRET", "applicationCredentialSecret")67 username := c.GetProperty("OS_USERNAME", "username")68 password := c.GetProperty("OS_PASSWORD", "password")69 if applicationCredentialID != "" || applicationCredentialName != "" {70 if applicationCredentialSecret == "" {71 return nil, fmt.Errorf("'OS_APPLICATION_CREDENTIAL_SECRET' (or 'applicationCredentialSecret') is required if 'OS_APPLICATION_CREDENTIAL_ID' or 'OS_APPLICATION_CREDENTIAL_NAME' is given")72 }73 if applicationCredentialID == "" && applicationCredentialName != "" {74 if username == "" {75 return nil, fmt.Errorf("OS_USERNAME' (or 'username') is required if 'OS_APPLICATION_CREDENTIAL_NAME' is given")76 }77 }78 if password != "" {79 return nil, fmt.Errorf("'OS_PASSWORD' (or 'password)' is not allowed if application credentials are used")80 }81 } else {82 if username == "" {83 return nil, fmt.Errorf("'OS_USERNAME' (or 'username') is required if application credentials are not used")84 }85 if password == "" {86 return nil, fmt.Errorf("'OS_PASSWORD' (or 'password') is required if application credentials are not used")87 }88 }89 domainName := c.GetProperty("OS_DOMAIN_NAME", "domainName")90 domainID := c.GetProperty("OS_DOMAIN_ID", "domainID")91 projectName := c.GetProperty("OS_PROJECT_NAME", "tenantName")92 projectID := c.GetProperty("OS_PROJECT_ID", "tenantID")93 userDomainName := c.GetProperty("OS_USER_DOMAIN_NAME", "userDomainName")94 userDomainID := c.GetProperty("OS_USER_DOMAIN_ID", "userDomainID")95 // optional restriction to region96 regionName := c.GetProperty("OS_REGION_NAME")97 // optional CA Certificate for keystone98 caCert := c.GetProperty("CACERT", "caCert")99 // optional Client Certificate100 clientCert := c.GetProperty("CLIENTCERT", "clientCert")101 clientKey := c.GetProperty("CLIENTKEY", "clientKey")102 insecure := strings.ToLower(c.GetProperty("INSECURE", "insecure"))103 authConfig := clientAuthConfig{104 AuthInfo: clientconfig.AuthInfo{105 AuthURL: authURL,106 ApplicationCredentialID: applicationCredentialID,107 ApplicationCredentialName: applicationCredentialName,108 ApplicationCredentialSecret: applicationCredentialSecret,109 Username: username,110 Password: password,111 DomainName: domainName,112 DomainID: domainID,113 ProjectName: projectName,114 ProjectID: projectID,115 UserDomainID: userDomainID,116 UserDomainName: userDomainName,...

Full Screen

Full Screen

config.go

Source:config.go Github

copy

Full Screen

...76////////////////////////////////////////////////////////////////////////////////77func (c *DNSHandlerConfig) GetRequiredProperty(key string, altKeys ...string) (string, error) {78 return c.getProperty(key, true, altKeys...)79}80func (c *DNSHandlerConfig) GetProperty(key string, altKeys ...string) string {81 value, _ := c.getProperty(key, false, altKeys...)82 return value83}84func (c *DNSHandlerConfig) GetRequiredIntProperty(key string, altKeys ...string) (int, error) {85 value, err := c.getProperty(key, true, altKeys...)86 if err != nil {87 return 0, err88 }89 return strconv.Atoi(value)90}91func (c *DNSHandlerConfig) GetRequiredBoolProperty(key string, altKeys ...string) (bool, error) {92 value, err := c.getProperty(key, true, altKeys...)93 if err != nil {94 return false, err95 }96 return strconv.ParseBool(value)97}98func (c *DNSHandlerConfig) GetDefaultedProperty(key string, def string, altKeys ...string) string {99 value, _ := c.getProperty(key, false, altKeys...)100 if value == "" {101 return def102 }103 return value104}105func (c *DNSHandlerConfig) GetDefaultedIntProperty(key string, def int, altKeys ...string) (int, error) {106 value, _ := c.getProperty(key, false, altKeys...)107 if value == "" {108 return def, nil109 }110 return strconv.Atoi(value)111}112func (c *DNSHandlerConfig) GetDefaultedBoolProperty(key string, def bool, altKeys ...string) (bool, error) {113 value, _ := c.getProperty(key, false, altKeys...)114 if value == "" {115 return def, nil116 }117 return strconv.ParseBool(value)118}119func (c *DNSHandlerConfig) getProperty(key string, required bool, altKeys ...string) (string, error) {120 usedKey := key121 value, ok := c.Properties[key]122 if !ok && len(altKeys) > 0 {123 for _, altKey := range altKeys {124 value, ok = c.Properties[altKey]125 if ok {126 usedKey = altKey127 break128 }129 }130 }131 if !ok {132 if !required {133 return "", nil134 }135 keys := append([]string{key}, altKeys...)136 err := fmt.Errorf("'%s' required in secret", strings.Join(keys, "' or '"))137 return "", err138 }139 tvalue := strings.TrimSpace(value)140 if value != tvalue {141 c.Logger.Warnf("value for '%s' in secret contains leading or trailing spaces which have been removed", usedKey)142 }143 if tvalue == "" {144 if !required {145 return "", nil146 }147 err := fmt.Errorf("value for '%s' in secret is empty", usedKey)148 return "", err149 }150 return tvalue, nil151}152func (c *DNSHandlerConfig) FillRequiredProperty(target **string, prop string, alt ...string) error {153 if utils.IsEmptyString(*target) {154 value, err := c.GetRequiredProperty(prop, alt...)155 if err != nil {156 return err157 }158 *target = &value159 return nil160 }161 return c.checkNotDefinedInConfig(prop, alt...)162}163func (c *DNSHandlerConfig) FillRequiredIntProperty(target **int, prop string, alt ...string) error {164 if *target == nil || **target == 0 {165 value, err := c.GetRequiredProperty(prop, alt...)166 if err != nil {167 return err168 }169 i, err := strconv.Atoi(value)170 if err != nil {171 return fmt.Errorf("property %s must be an int value: %s", prop, err)172 }173 *target = &i174 return nil175 }176 return c.checkNotDefinedInConfig(prop, alt...)177}178func (c *DNSHandlerConfig) FillDefaultedIntProperty(target **int, def int, prop string, alt ...string) error {179 if *target == nil || **target == 0 {180 value := c.GetProperty(prop, alt...)181 if value == "" {182 *target = &def183 return nil184 }185 i, err := strconv.Atoi(value)186 if err != nil {187 return fmt.Errorf("property %s must be an int value: %s", prop, err)188 }189 *target = &i190 return nil191 }192 return c.checkNotDefinedInConfig(prop, alt...)193}194func (c *DNSHandlerConfig) FillDefaultedProperty(target **string, def string, prop string, alt ...string) error {195 if *target == nil || **target == "" {196 value := c.GetProperty(prop, alt...)197 if value == "" {198 if def == "" {199 *target = nil200 return nil201 }202 *target = &def203 return nil204 }205 *target = &value206 return nil207 }208 return c.checkNotDefinedInConfig(prop, alt...)209}210func (c *DNSHandlerConfig) FillDefaultedBoolProperty(target **bool, def bool, prop string, alt ...string) error {211 if *target == nil || **target == def {212 value := c.GetProperty(prop, alt...)213 if value == "" {214 *target = &def215 return nil216 }217 b, err := strconv.ParseBool(value)218 if err != nil {219 return err220 }221 *target = &b222 return nil223 }224 return c.checkNotDefinedInConfig(prop, alt...)225}226func (c *DNSHandlerConfig) checkNotDefinedInConfig(prop string, alt ...string) error {227 value := c.GetProperty(prop, alt...)228 if value != "" {229 return fmt.Errorf("property %s defined in secret and provider config", prop)230 }231 return nil232}233func (c *DNSHandlerConfig) Complete() error {234 rateLimiter := AlwaysRateLimiter()235 if c.Options != nil {236 rateLimiterConfig := c.Options.GetRateLimiterConfig()237 var err error238 rateLimiter, err = rateLimiterConfig.NewRateLimiter()239 if err != nil {240 return fmt.Errorf("invalid rate limiter: %w", err)241 }...

Full Screen

Full Screen

template.go

Source:template.go Github

copy

Full Screen

1/*----------------------------------------------------------------2 * Copyright (c) ThoughtWorks, Inc.3 * Licensed under the Apache License, Version 2.04 * See LICENSE in the project root for license information.5 *----------------------------------------------------------------*/6package template7import (8 "fmt"9 "net/url"10 "path/filepath"11 "sort"12 "strings"13 "github.com/getgauge/common"14 "github.com/getgauge/gauge/config"15 "github.com/schollz/closestmatch"16)17const templateProperties = "template.properties"18type templates struct {19 t map[string]*config.Property20 names []string21}22func (t *templates) String() (string, error) {23 var buffer strings.Builder24 for _, k := range t.names {25 v := t.t[k]26 _, err := buffer.WriteString(fmt.Sprintf("\n# %s\n%s = %s\n", v.Description, v.Key, v.Value))27 if err != nil {28 return "", err29 }30 }31 return buffer.String(), nil32}33func (t *templates) update(k, v string, validate bool) error {34 if validate {35 if _, err := url.ParseRequestURI(v); err != nil {36 return fmt.Errorf("Failed to add template '%s'. The template location must be a valid (https) URI", k)37 }38 }39 if _, ok := t.t[k]; ok {40 t.t[k].Value = v41 } else {42 t.t[k] = config.NewProperty(k, v, fmt.Sprintf("Template download information for gauge %s projects", k))43 t.names = append(t.names, k)44 }45 sort.Strings(t.names)46 return nil47}48func (t *templates) get(k string) (string, error) {49 if _, ok := t.t[k]; ok {50 return t.t[k].Value, nil51 }52 matches := t.closestMatch(k)53 if len(matches) > 0 {54 return "", fmt.Errorf("Cannot find Gauge template '%s'.\nThe most similar template names are\n\n\t%s", k, strings.Join(matches, "\n\t"))55 }56 return "", fmt.Errorf("Cannot find Gauge template '%s'", k)57}58func (t *templates) closestMatch(k string) []string {59 matches := []string{}60 cm := closestmatch.New(t.names, []int{2})61 for _, m := range cm.ClosestN(k, 5) {62 if m != "" {63 matches = append(matches, m)64 }65 }66 sort.Strings(matches)67 return matches68}69func (t *templates) write() error {70 s, err := t.String()71 if err != nil {72 return err73 }74 return config.Write(s, templateProperties)75}76func Update(name, value string) error {77 t, err := getTemplates()78 if err != nil {79 return err80 }81 if err := t.update(name, value, true); err != nil {82 return err83 }84 return t.write()85}86func Generate() error {87 cd, err := common.GetConfigurationDir()88 if err != nil {89 return err90 }91 if !common.FileExists(filepath.Join(cd, templateProperties)) {92 return defaults().write()93 }94 return nil95}96func Get(name string) (string, error) {97 mp, err := getTemplates()98 if err != nil {99 return "", err100 }101 return mp.get(name)102}103func All() (string, error) {104 t, err := getTemplates()105 if err != nil {106 return "", err107 }108 return strings.Join(t.names, "\n"), nil109}110func List(machineReadable bool) (string, error) {111 var f config.Formatter112 f = config.TextFormatter{Headers: []string{"Template Name", "Location"}}113 if machineReadable {114 f = config.JsonFormatter{}115 }116 t, err := getTemplates()117 if err != nil {118 return "", err119 }120 var all []config.Property121 for _, v := range t.t {122 all = append(all, *v)123 }124 return f.Format(all)125}126func defaults() *templates {127 prop := map[string]*config.Property{128 "dotnet": getProperty("template-dotnet", "dotnet"),129 "java": getProperty("template-java", "java"),130 "java_gradle": getProperty("template-java-gradle", "java_gradle"),131 "java_maven": getProperty("template-java-maven", "java_maven"),132 "java_maven_selenium": getProperty("template-java-maven-selenium", "java_maven_selenium"),133 "js": getProperty("template-js", "js"),134 "js_simple": getProperty("template-js-simple", "js_simple"),135 "python": getProperty("template-python", "python"),136 "python_selenium": getProperty("template-python-selenium", "python_selenium"),137 "ruby": getProperty("template-ruby", "ruby"),138 "ruby_selenium": getProperty("template-ruby-selenium", "ruby_selenium"),139 "ts": getProperty("template-ts", "ts"),140 }141 return &templates{t: prop, names: getKeys(prop)}142}143func getKeys(prop map[string]*config.Property) []string {144 var keys []string145 for k := range prop {146 keys = append(keys, k)147 }148 sort.Strings(keys)149 return keys150}151func getTemplates() (*templates, error) {152 prop, err := common.GetGaugeConfigurationFor(templateProperties)153 if err != nil {154 return nil, err155 }156 t := &templates{t: make(map[string]*config.Property), names: []string{}}157 for k, v := range prop {158 if err := t.update(k, v, false); err != nil {159 return nil, err160 }161 }162 return t, nil163}164func getProperty(repoName, templateName string) *config.Property {165 f := "https://github.com/getgauge/%s/releases/latest/download/%s.zip"166 templateURL := fmt.Sprintf(f, repoName, templateName)167 desc := fmt.Sprintf("Template for gauge %s projects", templateName)168 return config.NewProperty(templateName, templateURL, desc)169}...

Full Screen

Full Screen

GetProperty

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 conf, err := config.NewConfig("ini", "conf/app.conf")4 if err != nil {5 fmt.Println(err)6 }7 port, err := conf.Int("app::httpport")8 if err != nil {9 fmt.Println(err)10 }11 fmt.Println(port)12}13import (14func main() {15 conf, err := config.NewConfig("ini", "conf/app.conf")16 if err != nil {17 fmt.Println(err)18 }19 conf.Set("app::httpport", "8082")20 port, err := conf.Int("app::httpport")21 if err != nil {22 fmt.Println(err)23 }24 fmt.Println(port)25}26import (27func main() {28 conf, err := config.NewConfig("ini", "conf/app.conf")29 if err != nil {30 fmt.Println(err)31 }32 conf.Set("app::httpport", "8082")33 conf.SaveConfigFile("conf/app.conf")34 port, err := conf.Int("app::httpport")35 if err != nil {36 fmt.Println(err)37 }38 fmt.Println(port)39}40import (41func main() {42 conf, err := config.NewConfig("ini", "conf/app.conf")43 if err != nil {44 fmt.Println(err)45 }46 conf.Set("app::httpport", "8082")47 conf.SaveConfigData("conf/app.conf")48 port, err := conf.Int("app::httpport")

Full Screen

Full Screen

GetProperty

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 config, err := config.NewConfig("ini", "conf/app.conf")4 if err != nil {5 fmt.Println(err)6 }7 fmt.Println(config.String("appname"))8 fmt.Println(config.String("httpport"))9 fmt.Println(config.String("runmode"))10}11import (12func main() {13 config, err := config.NewConfig("ini", "conf/app.conf")14 if err != nil {15 fmt.Println(err)16 }17 fmt.Println(config.String("appname"))18 fmt.Println(config.String("httpport"))19 fmt.Println(config.String("runmode"))20 sections := config.GetSection("mysql")21 fmt.Println(sections)22}

Full Screen

Full Screen

GetProperty

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 conf, err := config.NewConfig("ini", "conf/app.conf")4 if err != nil {5 fmt.Println("new config failed, err:", err)6 }7 port, err := conf.Int("server::port")8 if err != nil {9 fmt.Println("read server::port failed, err:", err)10 }11 fmt.Println("port:", port)12 log_level := conf.String("log::log_level")13 if len(log_level) == 0 {14 fmt.Println("read log::log_level failed")15 }16 fmt.Println("log_level:", log_level)17}18import (19func main() {20 conf, err := config.NewConfig("ini", "conf/app.conf")21 if err != nil {22 fmt.Println("new config failed, err:", err)23 }24 app_conf, err := conf.GetSection("app")25 if err != nil {26 fmt.Println("get section failed, err:", err)27 }28 for k, v := range app_conf {29 fmt.Printf("%s:%s\n", k, v)30 }31}32import (33func main() {34 conf, err := config.NewConfig("ini", "conf/app.conf")35 if err != nil {36 fmt.Println("new config failed, err:", err)37 }38 sections := conf.GetSections()39 for _, v := range sections {40 fmt.Println(v)41 }42}43import (44func main() {45 conf, err := config.NewConfig("ini", "conf/app.conf")46 if err != nil {47 fmt.Println("new config failed, err:", err)

Full Screen

Full Screen

GetProperty

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 conf, err := config.NewConfig("ini", "conf/app.conf")4 if err != nil {5 fmt.Println("new config failed, err:", err)6 }7 appname := conf.String("appname")8 if len(appname) == 0 {9 }10 fmt.Println("appname:", appname)11 fmt.Println("httpport:", conf.String("httpport"))12 fmt.Println("runmode:", conf.String("runmode"))13 fmt.Println("autorender:", conf.String("autorender"))14 fmt.Println("copyrequestbody:", conf.String("copyrequestbody"))15 fmt.Println("sessionon:", conf.String("sessionon"))16}17import (18func main() {19 conf, err := config.NewConfig("ini", "conf/app.conf")20 if err != nil {21 fmt.Println("new config failed, err:", err)22 }23 conf.Set("appname", "beego web app")24 conf.Set("httpport", "8080")25 conf.Set("runmode", "dev")26 conf.Set("autorender", "false")27 conf.Set("copyrequestbody", "true")28 conf.Set("sessionon", "true")29 fmt.Println("appname:", conf.String("appname"))30 fmt.Println("httpport:", conf.String("httpport"))31 fmt.Println("runmode:", conf.String("runmode"))32 fmt.Println("autorender:", conf.String("autorender"))33 fmt.Println("copyrequestbody:", conf.String("copyrequestbody"))34 fmt.Println("sessionon:", conf.String("sessionon"))35}36import (

Full Screen

Full Screen

GetProperty

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(config.GetProperty("dbuser"))4 fmt.Println(config.GetProperty("dbpassword"))5 fmt.Println(config.GetProperty("dburl"))6 fmt.Println(config.GetProperty("dbdriver"))7}

Full Screen

Full Screen

GetProperty

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 conf, err := config.NewConfig("ini", "conf/app.conf")4 if err != nil {5 fmt.Println("new config failed, err:", err)6 }7 port, err := conf.Int("server::port")8 if err != nil {9 fmt.Println("read server::port failed, err:", err)10 }11 fmt.Println("port:", port)12 mysqlAddr := conf.String("mysql::mysql_addr")13 if len(mysqlAddr) == 0 {14 fmt.Println("read mysql::mysql_addr failed")15 }16 fmt.Println("mysqlAddr:", mysqlAddr)17}

Full Screen

Full Screen

GetProperty

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 h := hub.New()4 s := h.Subscribe("my-topic")5 h.Publish("my-topic", "Hello world")6 msg := <-s.Receive()7 fmt.Println(msg.Data)8}9import (10func main() {11 h := hub.New()12 s := h.Subscribe("my-topic")13 h.Publish("my-topic", "Hello world")14 msg := <-s.Receive()15 fmt.Println(msg.Data)16}

Full Screen

Full Screen

GetProperty

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 cfg := config.NewConfig()4 err := cfg.LoadFile("config.json")5 if err != nil {6 fmt.Println(err)7 }8 name := cfg.GetProperty("name")9 fmt.Println(name)10 age := cfg.GetProperty("age")11 fmt.Println(age)12 weight := cfg.GetProperty("weight")13 fmt.Println(weight)14 height := cfg.GetProperty("height")15 fmt.Println(height)16}17{18}

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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful