MCPcopy Create free account
hub / github.com/devnullvoid/pvetui / EnsureAuthenticated

Method EnsureAuthenticated

pkg/api/auth.go:192–204  ·  view source on GitHub ↗

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

()

Source from the content-addressed store, hash-verified

190//
191// Returns an error if authentication fails or if the configuration is invalid.
192func (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//

Calls 2

GetValidTokenMethod · 0.95
SetAPITokenMethod · 0.80