Files
decort-golang-sdk/pkg/cloudapi/bservice/create.go

55 lines
1.4 KiB
Go
Raw Normal View History

2022-08-11 08:09:54 +00:00
package bservice
import (
"context"
2022-10-03 16:56:47 +03:00
"net/http"
2022-08-11 08:09:54 +00:00
"strconv"
2023-03-17 12:54:34 +03:00
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
2022-08-11 08:09:54 +00:00
)
2023-10-25 17:37:18 +03:00
// CreateRequest struct for BasicService
2022-08-11 08:09:54 +00:00
type CreateRequest struct {
2022-12-22 17:56:47 +03:00
// Name of the service
// Required: true
2023-03-17 12:54:34 +03:00
Name string `url:"name" json:"name" validate:"required"`
2022-12-22 17:56:47 +03:00
// ID of the Resource Group where this service will be placed
// Required: true
2023-03-17 12:54:34 +03:00
RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
2022-12-22 17:56:47 +03:00
// Name of the user to deploy SSH key for. Pass empty string if no SSH key deployment is required
// Required: false
2023-03-01 19:05:53 +03:00
SSHUser string `url:"sshUser,omitempty" json:"sshUser,omitempty"`
2022-12-22 17:56:47 +03:00
// SSH key to deploy for the specified user. Same key will be deployed to all computes of the service
// Required: false
2023-03-01 19:05:53 +03:00
SSHKey string `url:"sshKey,omitempty" json:"sshKey,omitempty"`
2025-07-15 17:39:18 +03:00
// Zone ID
// Required: false
ZoneID uint64 `url:"zoneId,omitempty" json:"zoneId,omitempty"`
2022-08-11 08:09:54 +00:00
}
2022-12-22 17:56:47 +03:00
// Create creates blank BasicService instance
2022-10-03 16:56:47 +03:00
func (b BService) Create(ctx context.Context, req CreateRequest) (uint64, error) {
2023-03-17 12:54:34 +03:00
err := validators.ValidateRequest(req)
2022-12-22 17:56:47 +03:00
if err != nil {
2023-10-25 17:37:18 +03:00
return 0, validators.ValidationErrors(validators.GetErrors(err))
2022-08-11 08:09:54 +00:00
}
url := "/cloudapi/bservice/create"
2022-12-22 17:56:47 +03:00
2022-10-03 16:56:47 +03:00
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
2022-08-11 08:09:54 +00:00
if err != nil {
return 0, err
}
2022-12-22 17:56:47 +03:00
result, err := strconv.ParseUint(string(res), 10, 64)
if err != nil {
return 0, err
}
return result, nil
2022-08-11 08:09:54 +00:00
}