How to use checkConfigAccessLevel method of main Package

Best Syzkaller code snippet using main.checkConfigAccessLevel

config.go

Source:config.go Github

copy

Full Screen

...211 }212 namespaces := make(map[string]bool)213 clientNames := make(map[string]bool)214 checkClients(clientNames, cfg.Clients)215 checkConfigAccessLevel(&cfg.AccessLevel, AccessPublic, "global")216 checkObsoleting(cfg.Obsoleting)217 if cfg.Namespaces[cfg.DefaultNamespace] == nil {218 panic(fmt.Sprintf("default namespace %q is not found", cfg.DefaultNamespace))219 }220 for ns, cfg := range cfg.Namespaces {221 checkNamespace(ns, cfg, namespaces, clientNames)222 }223}224func checkObsoleting(o ObsoletingConfig) {225 if (o.MinPeriod == 0) != (o.MaxPeriod == 0) {226 panic("obsoleting: both or none of Min/MaxPeriod must be specified")227 }228 if o.MinPeriod > o.MaxPeriod {229 panic(fmt.Sprintf("obsoleting: Min > MaxPeriod (%v > %v)", o.MinPeriod, o.MaxPeriod))230 }231 if o.MinPeriod != 0 && o.MinPeriod < 24*time.Hour {232 panic(fmt.Sprintf("obsoleting: too low MinPeriod: %v, want at least %v", o.MinPeriod, 24*time.Hour))233 }234 if (o.NonFinalMinPeriod == 0) != (o.NonFinalMaxPeriod == 0) {235 panic("obsoleting: both or none of NonFinalMin/MaxPeriod must be specified")236 }237 if o.NonFinalMinPeriod > o.NonFinalMaxPeriod {238 panic(fmt.Sprintf("obsoleting: NonFinalMin > MaxPeriod (%v > %v)", o.NonFinalMinPeriod, o.NonFinalMaxPeriod))239 }240 if o.NonFinalMinPeriod != 0 && o.NonFinalMinPeriod < 24*time.Hour {241 panic(fmt.Sprintf("obsoleting: too low MinPeriod: %v, want at least %v", o.NonFinalMinPeriod, 24*time.Hour))242 }243 if o.MinPeriod == 0 && o.NonFinalMinPeriod != 0 {244 panic("obsoleting: NonFinalMinPeriod without MinPeriod")245 }246}247func checkNamespace(ns string, cfg *Config, namespaces, clientNames map[string]bool) {248 if !namespaceNameRe.MatchString(ns) {249 panic(fmt.Sprintf("bad namespace name: %q", ns))250 }251 if namespaces[ns] {252 panic(fmt.Sprintf("duplicate namespace %q", ns))253 }254 namespaces[ns] = true255 if cfg.DisplayTitle == "" {256 cfg.DisplayTitle = ns257 }258 if cfg.SimilarityDomain == "" {259 cfg.SimilarityDomain = ns260 }261 checkClients(clientNames, cfg.Clients)262 for name, mgr := range cfg.Managers {263 checkManager(ns, name, mgr)264 }265 if !clientKeyRe.MatchString(cfg.Key) {266 panic(fmt.Sprintf("bad namespace %q key: %q", ns, cfg.Key))267 }268 if len(cfg.Reporting) == 0 {269 panic(fmt.Sprintf("no reporting in namespace %q", ns))270 }271 if cfg.TransformCrash == nil {272 cfg.TransformCrash = func(build *Build, crash *dashapi.Crash) bool {273 return true274 }275 }276 if cfg.NeedRepro == nil {277 cfg.NeedRepro = func(bug *Bug) bool {278 return true279 }280 }281 checkKernelRepos(ns, cfg)282 checkNamespaceReporting(ns, cfg)283}284func checkKernelRepos(ns string, cfg *Config) {285 if len(cfg.Repos) == 0 {286 panic(fmt.Sprintf("no repos in namespace %q", ns))287 }288 for _, repo := range cfg.Repos {289 if !vcs.CheckRepoAddress(repo.URL) {290 panic(fmt.Sprintf("%v: bad repo URL %q", ns, repo.URL))291 }292 if !vcs.CheckBranch(repo.Branch) {293 panic(fmt.Sprintf("%v: bad repo branch %q", ns, repo.Branch))294 }295 if repo.Alias == "" {296 panic(fmt.Sprintf("%v: empty repo alias for %q", ns, repo.Alias))297 }298 if prio := repo.ReportingPriority; prio < 0 || prio > 9 {299 panic(fmt.Sprintf("%v: bad kernel repo reporting priority %v for %q", ns, prio, repo.Alias))300 }301 emails := append(append(append([]string{}, repo.CC...), repo.Maintainers...), repo.BuildMaintainers...)302 for _, email := range emails {303 if _, err := mail.ParseAddress(email); err != nil {304 panic(fmt.Sprintf("bad email address %q: %v", email, err))305 }306 }307 }308}309func checkNamespaceReporting(ns string, cfg *Config) {310 checkConfigAccessLevel(&cfg.AccessLevel, cfg.AccessLevel, fmt.Sprintf("namespace %q", ns))311 parentAccessLevel := cfg.AccessLevel312 reportingNames := make(map[string]bool)313 // Go backwards because access levels get stricter backwards.314 for ri := len(cfg.Reporting) - 1; ri >= 0; ri-- {315 reporting := &cfg.Reporting[ri]316 if reporting.Name == "" {317 panic(fmt.Sprintf("empty reporting name in namespace %q", ns))318 }319 if reportingNames[reporting.Name] {320 panic(fmt.Sprintf("duplicate reporting name %q", reporting.Name))321 }322 if reporting.DisplayTitle == "" {323 reporting.DisplayTitle = reporting.Name324 }325 reporting.moderation = ri < len(cfg.Reporting)-1326 if !reporting.moderation && reporting.Embargo != 0 {327 panic(fmt.Sprintf("embargo in the last reporting %v", reporting.Name))328 }329 checkConfigAccessLevel(&reporting.AccessLevel, parentAccessLevel,330 fmt.Sprintf("reporting %q/%q", ns, reporting.Name))331 parentAccessLevel = reporting.AccessLevel332 if reporting.Filter == nil {333 reporting.Filter = ConstFilter(FilterReport)334 }335 reportingNames[reporting.Name] = true336 if reporting.Config.Type() == "" {337 panic(fmt.Sprintf("empty reporting type for %q", reporting.Name))338 }339 if err := reporting.Config.Validate(); err != nil {340 panic(err)341 }342 if _, err := json.Marshal(reporting.Config); err != nil {343 panic(fmt.Sprintf("failed to json marshal %q config: %v",344 reporting.Name, err))345 }346 }347}348func checkManager(ns, name string, mgr ConfigManager) {349 if mgr.Decommissioned && mgr.DelegatedTo == "" {350 panic(fmt.Sprintf("decommissioned manager %v/%v does not have delegate", ns, name))351 }352 if !mgr.Decommissioned && mgr.DelegatedTo != "" {353 panic(fmt.Sprintf("non-decommissioned manager %v/%v has delegate", ns, name))354 }355 if mgr.RestrictedTestingRepo != "" && mgr.RestrictedTestingReason == "" {356 panic(fmt.Sprintf("restricted manager %v/%v does not have restriction reason", ns, name))357 }358 if mgr.RestrictedTestingRepo == "" && mgr.RestrictedTestingReason != "" {359 panic(fmt.Sprintf("unrestricted manager %v/%v has restriction reason", ns, name))360 }361 if (mgr.ObsoletingMinPeriod == 0) != (mgr.ObsoletingMaxPeriod == 0) {362 panic(fmt.Sprintf("manager %v/%v obsoleting: both or none of Min/MaxPeriod must be specified", ns, name))363 }364 if mgr.ObsoletingMinPeriod > mgr.ObsoletingMaxPeriod {365 panic(fmt.Sprintf("manager %v/%v obsoleting: Min > MaxPeriod", ns, name))366 }367 if mgr.ObsoletingMinPeriod != 0 && mgr.ObsoletingMinPeriod < 24*time.Hour {368 panic(fmt.Sprintf("manager %v/%v obsoleting: too low MinPeriod", ns, name))369 }370}371func checkConfigAccessLevel(current *AccessLevel, parent AccessLevel, what string) {372 verifyAccessLevel(parent)373 if *current == 0 {374 *current = parent375 }376 verifyAccessLevel(*current)377 if *current < parent {378 panic(fmt.Sprintf("bad %v access level %v", what, *current))379 }380}381func checkClients(clientNames map[string]bool, clients map[string]string) {382 for name, key := range clients {383 if !clientNameRe.MatchString(name) {384 panic(fmt.Sprintf("bad client name: %v", name))385 }...

Full Screen

Full Screen

checkConfigAccessLevel

Using AI Code Generation

copy

Full Screen

1import (2func main() {3var configAccessLevel bool = checkConfigAccessLevel(configAccessLevel, userAccessLevel)4if configAccessLevel {5fmt.Println("User has access to this configuration")6} else {7fmt.Println("User does not have access to this configuration")8}9}10import (11func checkConfigAccessLevel(configAccessLevel string, userAccessLevel string) bool {12if configAccessLevel == "superadmin" {13} else if configAccessLevel == "admin" && userAccessLevel == "admin" {14} else if configAccessLevel == "user" && userAccessLevel == "user" {15}16}

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 Syzkaller 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