Validate checks if the authentication configuration is valid.
()
| 128 | |
| 129 | // Validate checks if the authentication configuration is valid. |
| 130 | func (c *AuthConfig) Validate() error { |
| 131 | if //goland:noinspection GoDeprecation |
| 132 | c.PasswordAuth.Method == PasswordAuthMethodDisabled && |
| 133 | c.PublicKeyAuth.Method == PubKeyAuthMethodDisabled && |
| 134 | c.KeyboardInteractiveAuth.Method == KeyboardInteractiveAuthMethodDisabled && |
| 135 | c.GSSAPIAuth.Method == GSSAPIAuthMethodDisabled && |
| 136 | (((c.Password == nil || !*c.Password) && (c.PubKey == nil || !*c.PubKey)) && c.URL == "") { |
| 137 | return fmt.Errorf("no authentication method configured, please configure at least one") |
| 138 | } |
| 139 | if c.PasswordAuth.Method != PasswordAuthMethodDisabled { |
| 140 | //goland:noinspection GoDeprecation |
| 141 | if c.URL != "" && c.Password != nil && *c.Password { |
| 142 | return newError( |
| 143 | "url", |
| 144 | "both the password authentication and the legacy url have been provided, please use the new configuration format", |
| 145 | ) |
| 146 | } |
| 147 | if err := c.PasswordAuth.Validate(); err != nil { |
| 148 | return wrap(err, "password") |
| 149 | } |
| 150 | } |
| 151 | if c.PublicKeyAuth.Method != PubKeyAuthMethodDisabled { |
| 152 | //goland:noinspection GoDeprecation |
| 153 | if c.URL != "" && c.PubKey != nil && *c.PubKey { |
| 154 | return newError( |
| 155 | "url", |
| 156 | "both the pubkey authentication and the legacy url have been provided, please use the new configuration format", |
| 157 | ) |
| 158 | } |
| 159 | if err := c.PublicKeyAuth.Validate(); err != nil { |
| 160 | return wrap(err, "publicKey") |
| 161 | } |
| 162 | } |
| 163 | if c.KeyboardInteractiveAuth.Method != KeyboardInteractiveAuthMethodDisabled { |
| 164 | if err := c.KeyboardInteractiveAuth.Validate(); err != nil { |
| 165 | return wrap(err, "keyboardInteractive") |
| 166 | } |
| 167 | } |
| 168 | if c.GSSAPIAuth.Method != GSSAPIAuthMethodDisabled { |
| 169 | if err := c.GSSAPIAuth.Validate(); err != nil { |
| 170 | return wrap(err, "gssapi") |
| 171 | } |
| 172 | } |
| 173 | if c.Authz.Method != AuthzMethodDisabled { |
| 174 | if err := c.Authz.Validate(); err != nil { |
| 175 | return wrap(err, "authz") |
| 176 | } |
| 177 | } |
| 178 | //goland:noinspection GoDeprecation |
| 179 | if ((c.Password != nil && *c.Password) || (c.PubKey != nil && *c.PubKey)) && c.URL != "" { |
| 180 | //goland:noinspection GoDeprecation |
| 181 | return c.HTTPClientConfiguration.Validate() |
| 182 | } |
| 183 | |
| 184 | return nil |
| 185 | } |
| 186 | |
| 187 | // region AuthMethod |