You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
decort-golang-sdk/pkg/cloudapi/bservice/create.go

55 lines
1.4 KiB

3 years ago
package bservice
import (
"context"
"net/http"
3 years ago
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
3 years ago
)
2 years ago
// CreateRequest struct for BasicService
3 years ago
type CreateRequest struct {
3 years ago
// Name of the service
// Required: true
Name string `url:"name" json:"name" validate:"required"`
3 years ago
// ID of the Resource Group where this service will be placed
// Required: true
RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
3 years ago
// Name of the user to deploy SSH key for. Pass empty string if no SSH key deployment is required
// Required: false
3 years ago
SSHUser string `url:"sshUser,omitempty" json:"sshUser,omitempty"`
3 years ago
// SSH key to deploy for the specified user. Same key will be deployed to all computes of the service
// Required: false
3 years ago
SSHKey string `url:"sshKey,omitempty" json:"sshKey,omitempty"`
4 months ago
// Zone ID
// Required: false
ZoneID uint64 `url:"zoneId,omitempty" json:"zoneId,omitempty"`
3 years ago
}
3 years ago
// Create creates blank BasicService instance
func (b BService) Create(ctx context.Context, req CreateRequest) (uint64, error) {
err := validators.ValidateRequest(req)
3 years ago
if err != nil {
2 years ago
return 0, validators.ValidationErrors(validators.GetErrors(err))
3 years ago
}
url := "/cloudapi/bservice/create"
3 years ago
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
3 years ago
if err != nil {
return 0, err
}
3 years ago
result, err := strconv.ParseUint(string(res), 10, 64)
if err != nil {
return 0, err
}
return result, nil
3 years ago
}