How to use Errf method of ui Package

Best Testkube code snippet using ui.Errf

caddyfile.go

Source:caddyfile.go Github

copy

Full Screen

...127 // logger := utils.NewLogger()128 for h.Next() {129 args := h.RemainingArgs()130 if len(args) > 0 {131 return nil, h.Errf("auth backend supports only nested args: %v", args)132 }133 for nesting := h.Nesting(); h.NextBlock(nesting); {134 rootDirective := h.Val()135 switch rootDirective {136 case "transform":137 args := strings.Join(h.RemainingArgs(), " ")138 switch args {139 case "user", "users":140 tc := &transformer.Config{}141 for nesting := h.Nesting(); h.NextBlock(nesting); {142 k := h.Val()143 trArgs := h.RemainingArgs()144 trArgs = append([]string{k}, trArgs...)145 encodedArgs := cfgutils.EncodeArgs(trArgs)146 var matchArgs bool147 for _, arg := range trArgs {148 if arg == "match" {149 matchArgs = true150 break151 }152 }153 if matchArgs {154 if trArgs[0] == "match" {155 trArgs = append([]string{"exact"}, trArgs...)156 encodedArgs = cfgutils.EncodeArgs(trArgs)157 }158 tc.Matchers = append(tc.Matchers, encodedArgs)159 } else {160 tc.Actions = append(tc.Actions, encodedArgs)161 }162 }163 portal.UserTransformerConfigs = append(portal.UserTransformerConfigs, tc)164 default:165 return nil, h.Errf("unsupported directive for %s: %s", rootDirective, args)166 }167 case "cookie":168 args := h.RemainingArgs()169 if len(args) != 2 {170 return nil, h.Errf("%s %s directive is invalid", rootDirective, strings.Join(args, " "))171 }172 switch args[0] {173 case "domain":174 portal.CookieConfig.Domain = args[1]175 case "path":176 portal.CookieConfig.Path = args[1]177 case "lifetime":178 lifetime, err := strconv.Atoi(args[1])179 if err != nil {180 return nil, h.Errf("%s %s value %q conversion failed: %v", rootDirective, args[0], args[1], err)181 }182 if lifetime < 1 {183 return nil, h.Errf("%s %s value must be greater than zero", rootDirective, args[0])184 }185 portal.CookieConfig.Lifetime = lifetime186 case "samesite":187 portal.CookieConfig.SameSite = args[1]188 case "insecure":189 enabled, err := cfgutils.ParseBoolArg(args[1])190 if err != nil {191 return nil, h.Errf("%s %s directive value of %q is invalid: %v", rootDirective, args[0], args[1], err)192 }193 portal.CookieConfig.Insecure = enabled194 default:195 return nil, h.Errf("%s %s directive is unsupported", rootDirective, strings.Join(args, " "))196 }197 case "crypto":198 args := h.RemainingArgs()199 if len(args) < 3 {200 return nil, h.Errf("%s directive %q is too short", rootDirective, strings.Join(args, " "))201 }202 encodedArgs := cfgutils.EncodeArgs(args)203 encodedArgs = repl.ReplaceAll(encodedArgs, badRepl)204 cryptoKeyConfig = append(cryptoKeyConfig, encodedArgs)205 switch args[0] {206 case "key":207 cryptoKeyConfigFound = true208 case "default":209 cryptoKeyStoreConfig = append(cryptoKeyStoreConfig, encodedArgs)210 cryptoKeyStoreConfigFound = true211 default:212 return nil, h.Errf("%s directive value of %q is unsupported", rootDirective, strings.Join(args, " "))213 }214 case "context":215 args := h.RemainingArgs()216 if len(args) == 0 {217 return nil, h.Errf("auth backend %s directive has no value", rootDirective)218 }219 portal.Context = args[0]220 case "backend":221 args := h.RemainingArgs()222 if len(args) == 0 {223 return nil, h.Errf("auth backend %s directive has no value", rootDirective)224 }225 if args[len(args)-1] == "disabled" {226 break227 }228 cfg := make(map[string]interface{})229 switch args[0] {230 case "local":231 if len(args) != 3 {232 return nil, h.Errf("authp directive is invalid: backend %s", cfgutils.EncodeArgs(args))233 }234 cfg["name"] = fmt.Sprintf("local_backend_%d", len(portal.BackendConfigs))235 cfg["method"] = "local"236 cfg["path"] = args[1]237 cfg["realm"] = args[2]238 case "google":239 if len(args) != 3 {240 return nil, h.Errf("authp directive is invalid: backend %s", cfgutils.EncodeArgs(args))241 }242 cfg["name"] = fmt.Sprintf("google_backend_%d", len(portal.BackendConfigs))243 cfg["method"] = "oauth2"244 cfg["realm"] = "google"245 cfg["provider"] = "google"246 cfg["client_id"] = repl.ReplaceAll(args[1], badRepl)247 cfg["client_secret"] = repl.ReplaceAll(args[2], badRepl)248 cfg["scopes"] = []string{"openid", "email", "profile"}249 case "github":250 if len(args) != 3 {251 return nil, h.Errf("authp directive is invalid: backend %s", cfgutils.EncodeArgs(args))252 }253 cfg["name"] = fmt.Sprintf("github_backend_%d", len(portal.BackendConfigs))254 cfg["method"] = "oauth2"255 cfg["realm"] = "github"256 cfg["provider"] = "github"257 cfg["client_id"] = repl.ReplaceAll(args[1], badRepl)258 cfg["client_secret"] = repl.ReplaceAll(args[2], badRepl)259 cfg["scopes"] = []string{"user"}260 case "facebook":261 if len(args) != 3 {262 return nil, h.Errf("authp directive is invalid: backend %s", cfgutils.EncodeArgs(args))263 }264 cfg["name"] = fmt.Sprintf("facebook_backend_%d", len(portal.BackendConfigs))265 cfg["method"] = "oauth2"266 cfg["realm"] = "facebook"267 cfg["provider"] = "facebook"268 cfg["client_id"] = repl.ReplaceAll(args[1], badRepl)269 cfg["client_secret"] = repl.ReplaceAll(args[2], badRepl)270 cfg["scopes"] = []string{"email"}271 default:272 return nil, h.Errf("auth backend directive is invalid: backend %v", args)273 }274 backendConfig, err := backends.NewConfig(cfg)275 if err != nil {276 return nil, h.Errf("auth backend %s directive failed: %v", rootDirective, err.Error())277 }278 portal.BackendConfigs = append(portal.BackendConfigs, *backendConfig)279 case "backends":280 for nesting := h.Nesting(); h.NextBlock(nesting); {281 backendName := h.Val()282 cfg := make(map[string]interface{})283 cfg["name"] = backendName284 backendDisabled := false285 var backendAuthMethod string286 for subNesting := h.Nesting(); h.NextBlock(subNesting); {287 backendArg := h.Val()288 switch backendArg {289 case "method", "type":290 if !h.NextArg() {291 return backendValueErr(h, backendName, backendArg)292 }293 backendAuthMethod = h.Val()294 cfg["method"] = backendAuthMethod295 case "trusted_authority":296 if !h.NextArg() {297 return backendValueErr(h, backendName, backendArg)298 }299 var trustedAuthorities []string300 if v, exists := cfg["trusted_authorities"]; exists {301 trustedAuthorities = v.([]string)302 }303 trustedAuthorities = append(trustedAuthorities, h.Val())304 cfg["trusted_authorities"] = trustedAuthorities305 case "disabled":306 backendDisabled = true307 break308 case "username", "password", "search_base_dn", "search_group_filter", "path", "realm":309 if !h.NextArg() {310 return backendValueErr(h, backendName, backendArg)311 }312 cfg[backendArg] = repl.ReplaceAll(h.Val(), badRepl)313 case "search_filter", "search_user_filter":314 if !h.NextArg() {315 return backendValueErr(h, backendName, backendArg)316 }317 cfg["search_user_filter"] = repl.ReplaceAll(h.Val(), badRepl)318 case "attributes":319 attrMap := make(map[string]interface{})320 for attrNesting := h.Nesting(); h.NextBlock(attrNesting); {321 attrName := h.Val()322 if !h.NextArg() {323 return backendPropErr(h, backendName, backendArg, attrName, "has no value")324 }325 attrMap[attrName] = h.Val()326 }327 cfg[backendArg] = attrMap328 case "servers":329 serverMaps := []map[string]interface{}{}330 for serverNesting := h.Nesting(); h.NextBlock(serverNesting); {331 serverMap := make(map[string]interface{})332 serverMap["addr"] = h.Val()333 serverProps := h.RemainingArgs()334 if len(serverProps) > 0 {335 for _, serverProp := range serverProps {336 switch serverProp {337 case "ignore_cert_errors", "posix_groups":338 serverMap[serverProp] = true339 default:340 return backendPropErr(h, backendName, backendArg, serverProp, "is unsupported")341 }342 }343 }344 serverMaps = append(serverMaps, serverMap)345 }346 cfg[backendArg] = serverMaps347 case "groups":348 groupMaps := []map[string]interface{}{}349 for groupNesting := h.Nesting(); h.NextBlock(groupNesting); {350 groupMap := make(map[string]interface{})351 groupDN := h.Val()352 groupMap["dn"] = groupDN353 groupRoles := h.RemainingArgs()354 if len(groupRoles) == 0 {355 return backendPropErr(h, backendName, backendArg, groupDN, "has no roles")356 }357 groupMap["roles"] = groupRoles358 groupMaps = append(groupMaps, groupMap)359 }360 cfg[backendArg] = groupMaps361 case "provider":362 if !h.NextArg() {363 return backendValueErr(h, backendName, backendArg)364 }365 cfg[backendArg] = h.Val()366 case "idp_metadata_location", "idp_sign_cert_location", "tenant_id",367 "application_id", "application_name", "entity_id", "domain_name",368 "client_id", "client_secret", "server_id", "base_auth_url", "metadata_url",369 "identity_token_name", "authorization_url", "token_url":370 if !h.NextArg() {371 return backendValueErr(h, backendName, backendArg)372 }373 cfg[backendArg] = repl.ReplaceAll(h.Val(), badRepl)374 case "acs_url":375 if !h.NextArg() {376 return backendValueErr(h, backendName, backendArg)377 }378 var acsURLs []string379 if v, exists := cfg["acs_urls"]; exists {380 acsURLs = v.([]string)381 }382 acsURLs = append(acsURLs, h.Val())383 cfg["acs_urls"] = acsURLs384 case "scopes", "user_group_filters", "user_org_filters":385 if _, exists := cfg[backendArg]; exists {386 values := cfg[backendArg].([]string)387 values = append(values, h.RemainingArgs()...)388 cfg[backendArg] = values389 } else {390 cfg[backendArg] = h.RemainingArgs()391 }392 case "delay_start", "retry_attempts", "retry_interval":393 backendVal := strings.Join(h.RemainingArgs(), "|")394 i, err := strconv.Atoi(backendVal)395 if err != nil {396 return backendValueConversionErr(h, backendName, backendArg, backendVal, err)397 }398 cfg[backendArg] = i399 case "disable":400 backendVal := strings.Join(h.RemainingArgs(), "_")401 switch backendVal {402 case "metadata_discovery":403 case "key_verification":404 case "pass_grant_type":405 case "response_type":406 case "nonce":407 default:408 return backendPropErr(h, backendName, backendArg, backendVal, "is unsupported")409 }410 cfg[backendVal+"_disabled"] = true411 case "enable":412 backendVal := strings.Join(h.RemainingArgs(), "_")413 switch backendVal {414 case "accept_header":415 default:416 return backendPropErr(h, backendName, backendArg, backendVal, "is unsupported")417 }418 cfg[backendVal+"_enabled"] = true419 default:420 return backendUnsupportedValueErr(h, backendName, backendArg)421 }422 }423 if !backendDisabled {424 backendConfig, err := backends.NewConfig(cfg)425 if err != nil {426 return nil, h.Errf("auth backend %s directive failed: %v", rootDirective, err.Error())427 }428 portal.BackendConfigs = append(portal.BackendConfigs, *backendConfig)429 }430 }431 case "ui":432 for nesting := h.Nesting(); h.NextBlock(nesting); {433 subDirective := h.Val()434 switch subDirective {435 case "template":436 hargs := h.RemainingArgs()437 switch {438 case len(hargs) == 2:439 portal.UI.Templates[hargs[0]] = hargs[1]440 default:441 args := strings.Join(h.RemainingArgs(), " ")442 return nil, h.Errf("%s directive %q is invalid", rootDirective, args)443 }444 case "theme":445 if !h.NextArg() {446 return nil, h.Errf("%s %s subdirective has no value", rootDirective, subDirective)447 }448 portal.UI.Theme = h.Val()449 case "logo":450 args := strings.Join(h.RemainingArgs(), " ")451 args = strings.TrimSpace(args)452 switch {453 case strings.HasPrefix(args, "url"):454 portal.UI.LogoURL = strings.ReplaceAll(args, "url ", "")455 case strings.HasPrefix(args, "description"):456 portal.UI.LogoDescription = strings.ReplaceAll(args, "description ", "")457 case args == "":458 return nil, h.Errf("%s %s directive has no value", rootDirective, subDirective)459 default:460 return nil, h.Errf("%s directive %q is unsupported", rootDirective, args)461 }462 case "auto_redirect_url":463 if !h.NextArg() {464 return nil, h.Errf("%s %s subdirective has no value", rootDirective, subDirective)465 }466 portal.UI.AutoRedirectURL = h.Val()467 case "password_recovery_enabled":468 if !h.NextArg() {469 return nil, h.Errf("%s %s subdirective has no value", rootDirective, subDirective)470 }471 if h.Val() == "yes" || h.Val() == "true" {472 portal.UI.PasswordRecoveryEnabled = true473 }474 case "links":475 for subNesting := h.Nesting(); h.NextBlock(subNesting); {476 title := h.Val()477 args := h.RemainingArgs()478 if len(args) == 0 {479 return nil, h.Errf("auth backend %s subdirective %s has no value", subDirective, title)480 }481 privateLink := ui.Link{482 Title: title,483 Link: args[0],484 }485 if len(args) == 1 {486 portal.UI.PrivateLinks = append(portal.UI.PrivateLinks, privateLink)487 continue488 }489 argp := 1490 disabledLink := false491 for argp < len(args) {492 switch args[argp] {493 case "target_blank":494 privateLink.Target = "_blank"495 privateLink.TargetEnabled = true496 case "icon":497 argp++498 if argp < len(args) {499 privateLink.IconName = args[argp]500 privateLink.IconEnabled = true501 }502 case "disabled":503 disabledLink = true504 default:505 return nil, h.Errf("auth backend %s subdirective %s has unsupported key %s", subDirective, title, args[argp])506 }507 argp++508 }509 if disabledLink {510 continue511 }512 portal.UI.PrivateLinks = append(portal.UI.PrivateLinks, privateLink)513 }514 case "custom":515 args := strings.Join(h.RemainingArgs(), " ")516 args = strings.TrimSpace(args)517 switch {518 case strings.HasPrefix(args, "css path"):519 portal.UI.CustomCSSPath = strings.ReplaceAll(args, "css path ", "")520 case strings.HasPrefix(args, "css"):521 portal.UI.CustomCSSPath = strings.ReplaceAll(args, "css ", "")522 case strings.HasPrefix(args, "js path"):523 portal.UI.CustomJsPath = strings.ReplaceAll(args, "js path ", "")524 case strings.HasPrefix(args, "js"):525 portal.UI.CustomJsPath = strings.ReplaceAll(args, "js ", "")526 case strings.HasPrefix(args, "html header path"):527 args = strings.ReplaceAll(args, "html header path ", "")528 b, err := ioutil.ReadFile(args)529 if err != nil {530 return nil, h.Errf("%s %s subdirective: %s %v", rootDirective, subDirective, args, err)531 }532 for k, v := range ui.PageTemplates {533 headIndex := strings.Index(v, "<meta name=\"description\"")534 if headIndex < 1 {535 continue536 }537 v = v[:headIndex] + string(b) + v[headIndex:]538 ui.PageTemplates[k] = v539 }540 case args == "":541 return nil, h.Errf("%s %s directive has no value", rootDirective, subDirective)542 default:543 return nil, h.Errf("%s directive %q is unsupported", rootDirective, args)544 }545 case "static_asset":546 args := h.RemainingArgs()547 if len(args) != 3 {548 return nil, h.Errf("auth backend %s subdirective %s is malformed", rootDirective, subDirective)549 }550 prefix := "assets/"551 assetURI := args[0]552 assetContentType := args[1]553 assetPath := args[2]554 if !strings.HasPrefix(assetURI, prefix) {555 return nil, h.Errf("auth backend %s subdirective %s URI must be prefixed with %s, got %s",556 rootDirective, subDirective, prefix, assetURI)557 }558 if err := ui.StaticAssets.AddAsset(assetURI, assetContentType, assetPath); err != nil {559 return nil, h.Errf("auth backend %s subdirective %s failed: %s", rootDirective, subDirective, err)560 }561 default:562 return nil, h.Errf("unsupported subdirective for %s: %s", rootDirective, subDirective)563 }564 }565 case "registration":566 for nesting := h.Nesting(); h.NextBlock(nesting); {567 subDirective := h.Val()568 switch subDirective {569 case "title":570 if !h.NextArg() {571 return nil, h.Errf("%s %s subdirective has no value", rootDirective, subDirective)572 }573 portal.UserRegistrationConfig.Title = h.Val()574 case "disabled":575 if !h.NextArg() {576 return nil, h.Errf("%s %s subdirective has no value", rootDirective, subDirective)577 }578 if h.Val() == "yes" || h.Val() == "on" {579 portal.UserRegistrationConfig.Disabled = true580 }581 case "code":582 if !h.NextArg() {583 return nil, h.Errf("%s %s subdirective has no value", rootDirective, subDirective)584 }585 portal.UserRegistrationConfig.Code = h.Val()586 case "dropbox":587 if !h.NextArg() {588 return nil, h.Errf("%s %s subdirective has no value", rootDirective, subDirective)589 }590 portal.UserRegistrationConfig.Dropbox = h.Val()591 case "require":592 args := strings.Join(h.RemainingArgs(), " ")593 args = strings.TrimSpace(args)594 switch args {595 case "accept terms":596 portal.UserRegistrationConfig.RequireAcceptTerms = true597 case "domain mx":598 portal.UserRegistrationConfig.RequireDomainMailRecord = true599 case "":600 return nil, h.Errf("%s directive has no value", rootDirective)601 default:602 return nil, h.Errf("%s directive %q is unsupported", rootDirective, args)603 }604 }605 }606 case "enable":607 args := strings.Join(h.RemainingArgs(), " ")608 switch args {609 case "source ip tracking":610 portal.TokenGrantorOptions.EnableSourceAddress = true611 default:612 return nil, h.Errf("unsupported directive for %s: %s", rootDirective, args)613 }614 case "validate":615 args := strings.Join(h.RemainingArgs(), " ")616 args = strings.TrimSpace(args)617 switch args {618 case "source address":619 portal.TokenValidatorOptions.ValidateSourceAddress = true620 case "":621 return nil, h.Errf("%s directive has no value", rootDirective)622 default:623 return nil, h.Errf("%s directive %q is unsupported", rootDirective, args)624 }625 default:626 return nil, h.Errf("unsupported root directive: %s", rootDirective)627 }628 }629 }630 if cryptoKeyConfigFound {631 configs, err := kms.ParseCryptoKeyConfigs(strings.Join(cryptoKeyConfig, "\n"))632 if err != nil {633 return nil, h.Errf("crypto key config error: %v", err)634 }635 portal.CryptoKeyConfigs = configs636 }637 if cryptoKeyStoreConfigFound {638 configs, err := kms.ParseCryptoKeyStoreConfig(strings.Join(cryptoKeyStoreConfig, "\n"))639 if err != nil {640 return nil, h.Errf("crypto key store config error: %v", err)641 }642 portal.CryptoKeyStoreConfig = configs643 }644 h.Reset()645 h.Next()646 return &portal, nil647}648func getRouteFromParseCaddyfileAuthenticator(h httpcaddyfile.Helper) ([]httpcaddyfile.ConfigValue, error) {649 portal, err := parseCaddyfileAuthenticator(h)650 if err != nil {651 return nil, err652 }653 pathMatcher := caddy.ModuleMap{654 "path": h.JSON(caddyhttp.MatchPath{"*"}),655 }656 route := caddyhttp.Route{657 HandlersRaw: []json.RawMessage{658 caddyconfig.JSONModuleObject(659 &AuthMiddleware{660 Portal: portal,661 },662 "handler",663 "authp",664 nil,665 ),666 },667 }668 subroute := new(caddyhttp.Subroute)669 subroute.Routes = append([]caddyhttp.Route{route}, subroute.Routes...)670 return h.NewRoute(pathMatcher, subroute), nil671}672func backendValueErr(h httpcaddyfile.Helper, backendName, backendArg string) (*authn.Authenticator, error) {673 return nil, h.Errf("auth backend %s subdirective %s has no value", backendName, backendArg)674}675func backendUnsupportedValueErr(h httpcaddyfile.Helper, backendName, backendArg string) (*authn.Authenticator, error) {676 return nil, h.Errf("auth backend %s subdirective %s is unsupported", backendName, backendArg)677}678func backendPropErr(h httpcaddyfile.Helper, backendName, backendArg, attrName, attrErr string) (*authn.Authenticator, error) {679 return nil, h.Errf("auth backend %q subdirective %q key %q %s", backendName, backendArg, attrName, attrErr)680}681func backendValueConversionErr(h httpcaddyfile.Helper, backendName, k, v string, err error) (*authn.Authenticator, error) {682 return nil, h.Errf("auth backend %s subdirective %s value %q error: %v", backendName, k, v, err)683}...

Full Screen

Full Screen

caddyfile_authn_ui.go

Source:caddyfile_authn_ui.go Github

copy

Full Screen

...31 case len(hargs) == 2:32 portal.UI.Templates[hargs[0]] = hargs[1]33 default:34 args := strings.Join(h.RemainingArgs(), " ")35 return h.Errf("%s directive %q is invalid", rootDirective, args)36 }37 case "theme":38 if !h.NextArg() {39 return h.Errf("%s %s subdirective has no value", rootDirective, subDirective)40 }41 portal.UI.Theme = h.Val()42 case "logo":43 hargs := util.FindReplaceAll(repl, h.RemainingArgs())44 args := strings.Join(hargs, " ")45 args = strings.TrimSpace(args)46 switch {47 case strings.HasPrefix(args, "url"):48 portal.UI.LogoURL = strings.ReplaceAll(args, "url ", "")49 case strings.HasPrefix(args, "description"):50 portal.UI.LogoDescription = strings.ReplaceAll(args, "description ", "")51 case args == "":52 return h.Errf("%s %s directive has no value", rootDirective, subDirective)53 default:54 return h.Errf("%s directive %q is unsupported", rootDirective, args)55 }56 case "meta":57 hargs := util.FindReplaceAll(repl, h.RemainingArgs())58 args := strings.Join(hargs, " ")59 args = strings.TrimSpace(args)60 switch {61 case strings.HasPrefix(args, "title"):62 portal.UI.MetaAuthor = strings.ReplaceAll(args, "title ", "")63 case strings.HasPrefix(args, "author"):64 portal.UI.MetaAuthor = strings.ReplaceAll(args, "author ", "")65 case strings.HasPrefix(args, "description"):66 portal.UI.MetaDescription = strings.ReplaceAll(args, "description ", "")67 case args == "":68 return h.Errf("%s %s directive has no value", rootDirective, subDirective)69 default:70 return h.Errf("%s directive %q is unsupported", rootDirective, args)71 }72 case "auto_redirect_url":73 if !h.NextArg() {74 return h.Errf("%s %s subdirective has no value", rootDirective, subDirective)75 }76 portal.UI.AutoRedirectURL = util.FindReplace(repl, h.Val())77 case "links":78 for subNesting := h.Nesting(); h.NextBlock(subNesting); {79 title := h.Val()80 args := util.FindReplaceAll(repl, h.RemainingArgs())81 if len(args) == 0 {82 return h.Errf("auth backend %s subdirective %s has no value", subDirective, title)83 }84 privateLink := ui.Link{85 Title: title,86 Link: args[0],87 }88 if len(args) == 1 {89 portal.UI.PrivateLinks = append(portal.UI.PrivateLinks, privateLink)90 continue91 }92 argp := 193 disabledLink := false94 for argp < len(args) {95 switch args[argp] {96 case "target_blank":97 privateLink.Target = "_blank"98 privateLink.TargetEnabled = true99 case "icon":100 argp++101 if argp < len(args) {102 privateLink.IconName = args[argp]103 privateLink.IconEnabled = true104 }105 case "disabled":106 disabledLink = true107 default:108 return h.Errf("auth backend %s subdirective %s has unsupported key %s", subDirective, title, args[argp])109 }110 argp++111 }112 if disabledLink {113 continue114 }115 portal.UI.PrivateLinks = append(portal.UI.PrivateLinks, privateLink)116 }117 case "custom":118 args := strings.Join(util.FindReplaceAll(repl, h.RemainingArgs()), " ")119 args = strings.TrimSpace(args)120 switch {121 case strings.HasPrefix(args, "css path"):122 portal.UI.CustomCSSPath = strings.ReplaceAll(args, "css path ", "")123 case strings.HasPrefix(args, "css"):124 portal.UI.CustomCSSPath = strings.ReplaceAll(args, "css ", "")125 case strings.HasPrefix(args, "js path"):126 portal.UI.CustomJsPath = strings.ReplaceAll(args, "js path ", "")127 case strings.HasPrefix(args, "js"):128 portal.UI.CustomJsPath = strings.ReplaceAll(args, "js ", "")129 case strings.HasPrefix(args, "html header path"):130 args = strings.ReplaceAll(args, "html header path ", "")131 b, err := ioutil.ReadFile(args)132 if err != nil {133 return h.Errf("%s %s subdirective: %s %v", rootDirective, subDirective, args, err)134 }135 for k, v := range ui.PageTemplates {136 headIndex := strings.Index(v, "<meta name=\"description\"")137 if headIndex < 1 {138 continue139 }140 v = v[:headIndex] + string(b) + v[headIndex:]141 ui.PageTemplates[k] = v142 }143 case args == "":144 return h.Errf("%s %s directive has no value", rootDirective, subDirective)145 default:146 return h.Errf("%s directive %q is unsupported", rootDirective, args)147 }148 case "static_asset":149 args := util.FindReplaceAll(repl, h.RemainingArgs())150 if len(args) != 3 {151 return h.Errf("auth backend %s subdirective %s is malformed", rootDirective, subDirective)152 }153 prefix := "assets/"154 assetURI := args[0]155 assetContentType := args[1]156 assetPath := args[2]157 if !strings.HasPrefix(assetURI, prefix) {158 return h.Errf("auth backend %s subdirective %s URI must be prefixed with %s, got %s",159 rootDirective, subDirective, prefix, assetURI)160 }161 if err := ui.StaticAssets.AddAsset(assetURI, assetContentType, assetPath); err != nil {162 return h.Errf("auth backend %s subdirective %s failed: %s", rootDirective, subDirective, err)163 }164 case "disable":165 args := util.FindReplaceAll(repl, h.RemainingArgs())166 if err := portal.UI.DisablePage(args); err != nil {167 return h.Errf("auth backend %s subdirective %s is malformed: %v", rootDirective, subDirective, err)168 }169 default:170 return h.Errf("unsupported subdirective for %s: %s", rootDirective, subDirective)171 }172 }173 return nil174}...

Full Screen

Full Screen

setup.go

Source:setup.go Github

copy

Full Screen

...10func Setup(toolname string, securecookies bool) (err error) {11 /* Initialize UI Settings */12 err = UIInit(securecookies, "_"+toolname)13 if err != nil {14 pf.Errf("UI Init failed: %s", err.Error())15 return16 }17 /* Load Templates */18 err = pf.Template_Load()19 if err != nil {20 pf.Errf("Template Loading failed: %s", err.Error())21 return22 }23 /* Start Access Logger */24 if pf.Config.LogFile != "" {25 err = LogAccess_start()26 if err != nil {27 pf.Errf("Could not open log file (%s): %s", pf.Config.LogFile, err.Error())28 return29 }30 defer LogAccess_stop()31 } else {32 pf.Logf("Note: Access LogFile disabled")33 }34 return35}...

Full Screen

Full Screen

Errf

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 err := termui.Init()4 if err != nil {5 panic(err)6 }7 defer termui.Close()8 termui.UseTheme("helloworld")9 par := termui.NewPar("Hello world")10 termui.Render(par)11 termui.Handle("/sys/kbd/q", func(termui.Event) {12 termui.StopLoop()13 })14 termui.Handle("/sys/wnd/resize", func(e termui.Event) {15 termui.Body.Width = termui.TermWidth()16 termui.Body.Align()17 termui.Clear()18 termui.Render(termui.Body)19 })20 termui.Loop()21}22import (23func main() {24 err := termui.Init()25 if err != nil {26 panic(err)27 }28 defer termui.Close()29 termui.UseTheme("helloworld")30 par := termui.NewPar("Hello world")31 termui.Render(par)32 termui.Handle("/sys/kbd/q", func(termui.Event) {33 termui.StopLoop()34 })35 termui.Handle("/sys/wnd/resize", func(e termui.Event) {36 termui.Body.Width = termui.TermWidth()37 termui.Body.Align()38 termui.Clear()39 termui.Render(termui.Body)40 })41 termui.Loop()42}

Full Screen

Full Screen

Errf

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 err := termui.Init()4 if err != nil {5 panic(err)6 }7 defer termui.Close()8 par := termui.NewPar("some text")9 termui.Render(par)10 termui.Errf("some error")11 termui.Handle("/sys/kbd/q", func(termui.Event) {12 termui.StopLoop()13 })14 termui.Handle("/sys/kbd/C-c", func(termui.Event) {15 termui.StopLoop()16 })17 termui.Loop()18}19panic(0x4a0e20, 0xc82000e0d0)20github.com/gizak/termui.(*Par).Buffer(0xc8200a0c00, 0x0, 0x0)21github.com/gizak/termui.(*Par).Buffer(0xc8200a0c00, 0x0, 0x0)22github.com/gizak/termui.(*Par).Buffer(0xc8200a0c00, 0x0, 0x0)23github.com/gizak/termui.(*Par).Buffer(0xc8200a0c00, 0x0, 0x0)

Full Screen

Full Screen

Errf

Using AI Code Generation

copy

Full Screen

1ui.Errf("Error: %v", err)2ui.Errf("Error: %v", err)3ui.Errf("Error: %v", err)4ui.Errf("Error: %v", err)5ui.Errf("Error: %v", err)6ui.Errf("Error: %v", err)7ui.Errf("Error: %v", err)8ui.Errf("Error: %v", err)9ui.Errf("Error: %v", err)10ui.Errf("Error: %v", err)11ui.Errf("Error: %v", err)12ui.Errf("Error: %v", err)13ui.Errf("Error: %v", err)14ui.Errf("Error: %v", err)15ui.Errf("Error: %v", err)16ui.Errf("Error: %v", err)17ui.Errf("Error: %v", err)18ui.Errf("Error

Full Screen

Full Screen

Errf

Using AI Code Generation

copy

Full Screen

1import "ui"2func main() {3 ui.Errf("Hello, %s", "world!")4}5import "ui"6func main() {7 ui.Errf("Hello, %s", "world!")8}9import "ui"10func main() {11 ui.Errf("Hello, %s", "world!")12}13import "ui"14func main() {15 ui.Errf("Hello, %s", "world!")16}17import "ui"18func main() {19 ui.Errf("Hello, %s", "world!")20}21import "ui"22func main() {23 ui.Errf("Hello, %s", "world!")24}25import "ui"26func main() {27 ui.Errf("Hello, %s", "world!")28}29import "ui"30func main() {31 ui.Errf("Hello, %s", "world!")32}33import "ui"34func main() {35 ui.Errf("Hello, %s", "world!")36}37import "ui"38func main() {39 ui.Errf("Hello, %s", "world!")40}41import "ui"42func main() {43 ui.Errf("Hello, %s", "world!")44}45import "ui"46func main() {47 ui.Errf("Hello, %s", "world!")48}

Full Screen

Full Screen

Errf

Using AI Code Generation

copy

Full Screen

1func main() {2 ui := &ui{}3 ui.Errf("Error: %v", errors.New("something went wrong"))4}5func main() {6 ui := &ui{}7 ui.Errf("Error: %v", errors.New("something went wrong"))8}9func main() {10 ui := &ui{}11 ui.Errf("Error: %v", errors.New("something went wrong"))12}13func main() {14 ui := &ui{}15 ui.Errf("Error: %v", errors.New("something went wrong"))16}17func main() {18 ui := &ui{}19 ui.Errf("Error: %v", errors.New("something went wrong"))20}21func main() {22 ui := &ui{}23 ui.Errf("Error: %v", errors.New("something went wrong"))24}25func main() {26 ui := &ui{}27 ui.Errf("Error: %v", errors.New("something went wrong"))28}29func main() {30 ui := &ui{}31 ui.Errf("Error: %v", errors.New("something went wrong"))32}33func main() {34 ui := &ui{}35 ui.Errf("Error: %v", errors.New("something went wrong"))36}37func main() {38 ui := &ui{}39 ui.Errf("Error: %v", errors.New("something went wrong"))40}41func main() {42 ui := &ui{}43 ui.Errf("Error: %v", errors.New("something went wrong"))44}

Full Screen

Full Screen

Errf

Using AI Code Generation

copy

Full Screen

1func main() {2 ui := &ui{}3 ui.Errf("Error: %s", "Invalid input")4}5func main() {6 ui := &ui{}7 ui.Errf("Error: %s", "Invalid input")8}9func main() {10 ui := &ui{}11 ui.Errf("Error: %s", "Invalid input")12}13func main() {14 ui := &ui{}15 ui.Errf("Error: %s", "Invalid input")16}17func main() {18 ui := &ui{}19 ui.Errf("Error: %s", "Invalid input")20}21func main() {22 ui := &ui{}23 ui.Errf("Error: %s", "Invalid input")24}25func main() {26 ui := &ui{}27 ui.Errf("Error: %s", "Invalid input")28}29func main() {30 ui := &ui{}31 ui.Errf("Error: %s", "Invalid input")32}33func main() {34 ui := &ui{}35 ui.Errf("Error: %s", "Invalid input")36}37func main() {38 ui := &ui{}39 ui.Errf("Error: %s", "Invalid input")40}41func main() {42 ui := &ui{}43 ui.Errf("Error: %s", "Invalid input")44}45func main() {46 ui := &ui{}47 ui.Errf("Error: %s", "Invalid input")48}

Full Screen

Full Screen

Errf

Using AI Code Generation

copy

Full Screen

1import (2type args struct {3}4func main() {5 p := arg.MustParse(&args)6 ui := ui.New(os.Stdout)7 if args.Verbose {8 ui.Errf("verbose output enabled")9 }10 fmt.Println(p)11}12import (13type args struct {14}15func main() {16 p := arg.MustParse(&args)17 ui := ui.New(os.Stdout)18 if args.Verbose {19 ui.Errf("verbose output enabled")20 }21 fmt.Println(p)22}23import (24type args struct {25}26func main() {27 p := arg.MustParse(&args)28 ui := ui.New(os.Stdout)29 if args.Verbose {30 ui.Errf("verbose output enabled")31 }32 fmt.Println(p)33}34import (35type args struct {36}37func main() {38 p := arg.MustParse(&args)39 ui := ui.New(os.Stdout)40 if args.Verbose {41 ui.Errf("verbose output enabled")42 }43 fmt.Println(p)44}45import (

Full Screen

Full Screen

Errf

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Enter a string to reverse:")4 fmt.Scanln(&input)5 fmt.Println("Reverse of the string is:", reverse(input))6}7func reverse(input string) string {8 for i := len(input) - 1; i >= 0; i-- {9 reverse += string(input[i])10 }11}12cannot use input (type string) as type *bufio.Reader in argument to bufio.NewReader13import (14func main() {15 fmt.Println("Enter a string to reverse:")16 fmt.Scanln(&input)17 fmt.Println("Reverse of the string is:", reverse(input))18}19func reverse(input string) string {20 for i := len(input) - 1; i >= 0; i-- {21 reverse += string(input[i])22 }23}24cannot use input (type string) as type *bufio.Reader in argument to bufio.NewReader25import (26func main() {27 fmt.Println("Hello, world.")28}29func TestHello(t *testing.T) {30 fmt.Println("Hello, world.")31}

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