package awsserversdk import ( "context" "net/http" "net/url" ) type AccessService struct{ client *Client } type LoginInfo struct { Users []LoginUser `json:"users"` } type LoginUser struct { Username string `json:"username"` Methods []LoginMethod `json:"methods"` } type LoginMethod struct { Type string `json:"type"` Protocol string `json:"protocol"` Host string `json:"host"` Port int `json:"port"` Credential LoginCredential `json:"credential"` } type LoginCredential struct { Kind string `json:"kind"` Available bool `json:"available"` Status string `json:"status"` Error string `json:"error"` Password Secret `json:"password"` PrivateKey Secret `json:"private_key"` KeyID string `json:"key_id"` KeyName string `json:"key_name"` Fingerprint string `json:"fingerprint"` Source string `json:"source"` } type Credential struct { Username string `json:"username"` Password Secret `json:"password"` Version int `json:"version"` Warning string `json:"warning"` } type SSHKeyAssignment map[string]any type AddSSHKeyRequest struct { SSHKeyID string `json:"ssh_key_id"` Username string `json:"username"` } func (s *AccessService) GetLoginInfo(ctx context.Context, region, instanceID string) (*LoginInfo, error) { var result LoginInfo err := s.client.do(ctx, http.MethodPost, instancesPath(region, instanceID)+"/login-info", map[string]any{}, &result, newID()) return &result, err } func (s *AccessService) RevealCredential(ctx context.Context, region, instanceID string) (*Credential, error) { var result Credential err := s.client.do(ctx, http.MethodPost, instancesPath(region, instanceID)+"/credentials/reveal", map[string]any{}, &result, newID()) return &result, err } func (s *AccessService) RotateCredential(ctx context.Context, region, instanceID string, options ...RequestOption) (*Operation, error) { return (&InstancesService{client: s.client}).operation(ctx, http.MethodPost, instancesPath(region, instanceID)+"/credentials/rotate", map[string]any{}, options...) } func (s *AccessService) ListSSHKeys(ctx context.Context, region, instanceID string) (*Page[SSHKeyAssignment], error) { var result Page[SSHKeyAssignment] err := s.client.do(ctx, http.MethodGet, instancesPath(region, instanceID)+"/ssh-keys", nil, &result, "") return &result, err } func (s *AccessService) AddSSHKey(ctx context.Context, region, instanceID string, input AddSSHKeyRequest, options ...RequestOption) (*Operation, error) { return (&InstancesService{client: s.client}).operation(ctx, http.MethodPost, instancesPath(region, instanceID)+"/ssh-keys", input, options...) } func (s *AccessService) RemoveSSHKey(ctx context.Context, region, instanceID, keyID, username string, options ...RequestOption) (*Operation, error) { path := instancesPath(region, instanceID) + "/ssh-keys/" + escaped(keyID) if username != "" { path += "?username=" + url.QueryEscape(username) } return (&InstancesService{client: s.client}).operation(ctx, http.MethodDelete, path, nil, options...) }