mirror of
https://github.com/bpg/terraform-provider-proxmox.git
synced 2025-07-02 03:22:59 +00:00
* feat(provider): add support for pre(external) auth'd session tokens adds provider config inputs: - env vars: PROXMOX_VE_AUTH_PAYLOAD; PROXMOX_VE_AUTH_TICKET with PROXMOX_VE_CSRF_PREVENTION_TOKEN - provider-config: auth_payload; auth_ticket with csrf_prevention_token Signed-off-by: vanillaSprinkles <vanillaSprinkles@users.noreply.github.com> * add //nolint to "todo" comments/questions and lll for build to pass; add flags to terraform-plugin-docs Signed-off-by: vanillaSprinkles <vanillaSprinkles@users.noreply.github.com> * address first iteration of comments: remove auth-payload, improve index.md Signed-off-by: vanillaSprinkles <vanillaSprinkles@users.noreply.github.com> * refactor credentials using struct composition, other minor cleanups Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com> * fix linter error Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com> * fix make docs, add terraform to handle fmt Signed-off-by: vanillaSprinkles <vanillaSprinkles@users.noreply.github.com> --------- Signed-off-by: vanillaSprinkles <vanillaSprinkles@users.noreply.github.com> Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com> Co-authored-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com>
42 lines
1003 B
Go
42 lines
1003 B
Go
/*
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
*/
|
|
|
|
package api
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"strings"
|
|
)
|
|
|
|
type tokenAuthenticator struct {
|
|
username string
|
|
token string
|
|
}
|
|
|
|
// NewTokenAuthenticator creates a new authenticator that uses a PVE API Token
|
|
// for authentication.
|
|
func NewTokenAuthenticator(toc TokenCredentials) (Authenticator, error) {
|
|
return &tokenAuthenticator{
|
|
username: strings.Split(toc.APIToken, "!")[0],
|
|
token: toc.APIToken,
|
|
}, nil
|
|
}
|
|
|
|
func (t *tokenAuthenticator) IsRoot() bool {
|
|
return t.username == rootUsername
|
|
}
|
|
|
|
func (t *tokenAuthenticator) IsRootTicket() bool {
|
|
// Logged using a token, therefore not a ticket login
|
|
return false
|
|
}
|
|
|
|
func (t *tokenAuthenticator) AuthenticateRequest(_ context.Context, req *http.Request) error {
|
|
req.Header.Set("Authorization", "PVEAPIToken="+t.token)
|
|
return nil
|
|
}
|