Skip to content

feat(instance): add encrypted rdp password method #2078

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 93 additions & 0 deletions api/instance/v1/instance_sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -2122,6 +2122,9 @@ type CreateServerRequest struct {

// PlacementGroup: placement group ID if Instance must be part of a placement group.
PlacementGroup *string `json:"placement_group,omitempty"`

// AdminPasswordEncryptionSSHKeyID: UUID of the SSH RSA key that will be used to encrypt the initial admin password for OS requiring it. Mandatory for Windows OS.
AdminPasswordEncryptionSSHKeyID *string `json:"admin_password_encryption_ssh_key_id,omitempty"`
}

// CreateServerResponse: create server response.
Expand Down Expand Up @@ -2210,6 +2213,15 @@ type CreateVolumeResponse struct {
Volume *Volume `json:"volume"`
}

// DeleteEncryptedRdpPasswordRequest: delete encrypted rdp password request.
type DeleteEncryptedRdpPasswordRequest struct {
// Zone: zone to target. If none is passed will use default zone from the config.
Zone scw.Zone `json:"-"`

// ServerID: UUID of the Instance.
ServerID string `json:"-"`
}

// DeleteIPRequest: delete ip request.
type DeleteIPRequest struct {
// Zone: zone to target. If none is passed will use default zone from the config.
Expand Down Expand Up @@ -2369,6 +2381,27 @@ type GetDashboardResponse struct {
Dashboard *Dashboard `json:"dashboard"`
}

// GetEncryptedRdpPasswordRequest: get encrypted rdp password request.
type GetEncryptedRdpPasswordRequest struct {
// Zone: zone to target. If none is passed will use default zone from the config.
Zone scw.Zone `json:"-"`

// ServerID: UUID of the Instance.
ServerID string `json:"-"`
}

// GetEncryptedRdpPasswordResponse: get encrypted rdp password response.
type GetEncryptedRdpPasswordResponse struct {
// Value: the encrypted RDP password.
Value *string `json:"value"`

// AdminPasswordEncryptionSSHKeyDescription: the description of the SSH key used for ciphering.
AdminPasswordEncryptionSSHKeyDescription *string `json:"admin_password_encryption_ssh_key_description"`

// AdminPasswordEncryptionSSHKeyID: the UUID of the SSH key used for ciphering.
AdminPasswordEncryptionSSHKeyID *string `json:"admin_password_encryption_ssh_key_id"`
}

// GetIPRequest: get ip request.
type GetIPRequest struct {
// Zone: zone to target. If none is passed will use default zone from the config.
Expand Down Expand Up @@ -6501,3 +6534,63 @@ func (s *API) ApplyBlockMigration(req *ApplyBlockMigrationRequest, opts ...scw.R
}
return nil
}

// GetEncryptedRdpPassword: Get the initial administrator password for Windows RDP. This password is encrypted using the SSH RSA key specified at the time of Instance creation.
func (s *API) GetEncryptedRdpPassword(req *GetEncryptedRdpPasswordRequest, opts ...scw.RequestOption) (*GetEncryptedRdpPasswordResponse, error) {
var err error

if req.Zone == "" {
defaultZone, _ := s.client.GetDefaultZone()
req.Zone = defaultZone
}

if fmt.Sprint(req.Zone) == "" {
return nil, errors.New("field Zone cannot be empty in request")
}

if fmt.Sprint(req.ServerID) == "" {
return nil, errors.New("field ServerID cannot be empty in request")
}

scwReq := &scw.ScalewayRequest{
Method: "GET",
Path: "/instance/v1/zones/" + fmt.Sprint(req.Zone) + "/servers/" + fmt.Sprint(req.ServerID) + "/encrypted_rdp_password",
}

var resp GetEncryptedRdpPasswordResponse

err = s.client.Do(scwReq, &resp, opts...)
if err != nil {
return nil, err
}
return &resp, nil
}

// DeleteEncryptedRdpPassword: Delete the initial administrator password for Windows RDP.
func (s *API) DeleteEncryptedRdpPassword(req *DeleteEncryptedRdpPasswordRequest, opts ...scw.RequestOption) error {
var err error

if req.Zone == "" {
defaultZone, _ := s.client.GetDefaultZone()
req.Zone = defaultZone
}

if fmt.Sprint(req.Zone) == "" {
return errors.New("field Zone cannot be empty in request")
}

if fmt.Sprint(req.ServerID) == "" {
return errors.New("field ServerID cannot be empty in request")
}

scwReq := &scw.ScalewayRequest{
Method: "DELETE",
Path: "/instance/v1/zones/" + fmt.Sprint(req.Zone) + "/servers/" + fmt.Sprint(req.ServerID) + "/encrypted_rdp_password",
}

err = s.client.Do(scwReq, nil, opts...)
if err != nil {
return err
}
return nil
}
Loading