mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
lib/promscrape/discovery/kubernetes: use unsupportedFieldError() function instead of errContext string
This improves code readability and maintainability a bit, since the format string is passed as string literal into fmt.Errorf.
This commit is contained in:
parent
68b6ddfb14
commit
b6e3c12811
1 changed files with 10 additions and 6 deletions
|
@ -66,21 +66,20 @@ type AuthInfo struct {
|
|||
}
|
||||
|
||||
func (au *AuthInfo) validate() error {
|
||||
errContext := "field %q is not supported yet; if you feel it is needed please open a feature request at https://github.com/VictoriaMetrics/VictoriaMetrics/issues/new"
|
||||
if au.Exec != nil {
|
||||
return fmt.Errorf(errContext, "exec")
|
||||
return unsupportedFieldError("exec")
|
||||
}
|
||||
if len(au.ImpersonateUID) > 0 {
|
||||
return fmt.Errorf(errContext, "act-as-uid")
|
||||
return unsupportedFieldError("act-as-uid")
|
||||
}
|
||||
if len(au.Impersonate) > 0 {
|
||||
return fmt.Errorf(errContext, "act-as")
|
||||
return unsupportedFieldError("act-as")
|
||||
}
|
||||
if len(au.ImpersonateGroups) > 0 {
|
||||
return fmt.Errorf(errContext, "act-as-groups")
|
||||
return unsupportedFieldError("act-as-groups")
|
||||
}
|
||||
if len(au.ImpersonateUserExtra) > 0 {
|
||||
return fmt.Errorf(errContext, "act-as-user-extra")
|
||||
return unsupportedFieldError("act-as-user-extra")
|
||||
}
|
||||
if len(au.Password) > 0 && len(au.Username) == 0 {
|
||||
return fmt.Errorf("username cannot be empty, if password defined")
|
||||
|
@ -88,6 +87,11 @@ func (au *AuthInfo) validate() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func unsupportedFieldError(fieldName string) error {
|
||||
return fmt.Errorf("field %q is not supported yet; if you feel it is needed please open a feature request "+
|
||||
"at https://github.com/VictoriaMetrics/VictoriaMetrics/issues/new", fieldName)
|
||||
}
|
||||
|
||||
// ExecConfig contains information about os.command, that returns auth token for kubernetes cluster connection
|
||||
type ExecConfig struct {
|
||||
// Command to execute.
|
||||
|
|
Loading…
Reference in a new issue