mirror of
https://github.com/bpg/terraform-provider-proxmox.git
synced 2025-06-29 18:21:10 +00:00
Token logins using root@pam!sometoken=uuid are not considered by PVE as 'root' logins, and fail to change VM's arch. Make sure the provider does not try to set/change VM's arch. Co-authored-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com>
42 lines
981 B
Go
42 lines
981 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(token string) (Authenticator, error) {
|
|
return &tokenAuthenticator{
|
|
username: strings.Split(token, "!")[0],
|
|
token: token,
|
|
}, 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
|
|
}
|