Documentation
¶
Overview ¶
Package login provides login functionality for GPUd.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrEmptyMachineID = errors.New("login request failed with empty machine ID")
var ErrEmptyToken = errors.New("token is empty")
Functions ¶
func Login ¶
func Login(ctx context.Context, cfg LoginConfig) error
Login performs the login operation with the control plane. This function extracts the core login logic from the original login command.
It handles the following scenarios based on the Login API Specification:
Success: - HTTP 200 OK: Returns Machine ID and Session Token.
Failures: - Validation Errors (HTTP 400):
- Invalid JSON: "cannot parse json, ..."
- Missing Machine Info: "machine info cannot be nil"
- Missing Token: "token is required"
- Missing ID/NodeGroup: "must specify a machine id or a node group id"
- Token Validation Errors:
- Invalid Token (HTTP 401): "invalid token"
- Token Validation Failed (HTTP 500): "failed to validate token"
- Machine/Node Group Validation Errors:
- Machine Not Found (HTTP 404): "machine not found"
- Node Group Mismatch (HTTP 400): "node group does not match"
- Node Group Not Found (HTTP 404): "node group <name> not found"
- Forbidden Access (HTTP 403): "only allowed to check in machines your owned"
- Forbidden Node Group (HTTP 403): "node group is not owned by the workspace"
- Internal Server Errors (HTTP 500):
- Session Token Error: "failed to find session token"
- Machine Retrieval Error: "failed to get machine"
- Update Status Error: "failed to update machine info"
- Node Group Error: "failed to find node group"
- ID Generation Error: "failed to generate id"
- Machine Creation Error: "failed to add machine"
- Login Finalization Error: "failed to login, please try again"
func SendRequest ¶ added in v0.5.0
func SendRequest(ctx context.Context, endpoint string, req apiv1.LoginRequest) (*apiv1.LoginResponse, error)
SendRequest sends a login request and blocks until the login request is processed. It also validates the response field to ensure the login request is processed successfully.
The server responds with the following status codes and messages:
Success: - 200 OK: Login successful. Returns Machine ID and Token.
Failures: - 400 Bad Request:
- Invalid JSON
- Missing Machine Info
- Missing Token
- Missing ID/NodeGroup
- Node Group Mismatch
- 401 Unauthorized: Invalid Token - 403 Forbidden:
- Forbidden Access (machine not owned by workspace)
- Forbidden Node Group (node group not owned by workspace)
- 404 Not Found:
- Machine Not Found
- Node Group Not Found
- 500 Internal Server Error:
- Token Validation Failed
- Session Token Error
- Machine Retrieval/Creation/Update Errors
- Node Group Error
- ID Generation Error
Types ¶
type LoginConfig ¶ added in v0.9.0
type LoginConfig struct {
Token string
Endpoint string
MachineID string // optional: can be empty
NodeGroup string // optional
DataDir string
// GPUCount is the number of GPUs to be reported to the control plane.
// If not specified, the control plane will use the detected number of GPUs.
GPUCount string
PublicIP string // optional: overrides detected public IP
PrivateIP string // optional: overrides detected private IP
}
LoginConfig contains the configuration for the login operation.