EnsureAuthenticated ensures the client is properly authenticated and ready for API calls. For API token authentication, this method configures the HTTP client with the token. For password authentication, this method performs the initial authentication if needed. This method should be called before
()
| 190 | // |
| 191 | // Returns an error if authentication fails or if the configuration is invalid. |
| 192 | func (am *AuthManager) EnsureAuthenticated() error { |
| 193 | if am.token != "" { |
| 194 | // Using API token, no need to authenticate |
| 195 | am.httpClient.SetAPIToken(am.token) |
| 196 | |
| 197 | return nil |
| 198 | } |
| 199 | |
| 200 | // Using password authentication, need to get a ticket |
| 201 | _, err := am.GetValidToken(context.Background()) |
| 202 | |
| 203 | return err |
| 204 | } |
| 205 | |
| 206 | // GetValidToken returns a valid authentication token, refreshing if necessary. |
| 207 | // |