diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 8860de6..acaaa03 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -2,21 +2,20 @@ name: Go on: push: - branches: [ "master" ] + branches: [ "master", "feature/terraform-endpoints" ] pull_request: - branches: [ "master" ] + branches: [ "master", "feature/terraform-endpoints" ] jobs: - build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Set up Go - uses: actions/setup-go@v3 + uses: actions/setup-go@v4 with: - go-version: 1.18 + go-version: 1.22.2 - name: Build run: go build -v ./... diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..53c207a --- /dev/null +++ b/.gitignore @@ -0,0 +1,48 @@ +### Go template +# If you prefer the allow list template instead of the deny list, see community template: +# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore +# +# Binaries for programs and plugins +*.exe +*.exe~ +*.dll +*.so +*.dylib + +# Test binary, built with `go test -c` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out + +# Dependency directories (remove the comment below to include it) +# vendor/ + +# Go workspace file +go.work + +### Go.AllowList template +# Allowlisting gitignore template for GO projects prevents us +# from adding various unwanted local files, such as generated +# files, developer configurations or IDE-specific files etc. +# +# Recommended: Go.AllowList.gitignore + +# Ignore everything +* + +# But not these files... +!/.gitignore + +!*.go +!go.sum +!go.mod + +!README.md +!LICENSE + +# !Makefile + +# ...even if they are in subdirectories +!*/ + diff --git a/Readme.md b/Readme.md deleted file mode 100644 index 55faf79..0000000 --- a/Readme.md +++ /dev/null @@ -1,31 +0,0 @@ -# Leaseweb Go SDK - -This package provides a golang client for Leaseweb's REST API. - -### Installation - -```bash -go get github.com/LeaseWeb/leaseweb-go-sdk -``` - -### Generate your API Key -You can generate your API key at the [Customer Portal](https://secure.leaseweb.com/) - -### Authenticate and make first call -```golang -import LSW "github.com/LeaseWeb/leaseweb-go-sdk" -import "context" - -func main() { - LSW.InitLeasewebClient("api key here") - ctx := context.Background() - result, err := LSW.DedicatedServerApi{}.List(ctx) - if err == nil { - fmt.Println(result) - } -} -``` - -### Documentation -The full documentation for Leaseweb go SDK is available in the [wiki](https://github.com/LeaseWeb/leaseweb-go-sdk/wiki). - diff --git a/abuse.go b/abuse.go deleted file mode 100644 index 0043ed8..0000000 --- a/abuse.go +++ /dev/null @@ -1,138 +0,0 @@ -package leaseweb - -import ( - "context" - "encoding/json" - "net/http" - - "github.com/LeaseWeb/leaseweb-go-sdk/options" -) - -const ABUSE_API_VERSION = "v1" - -type AbuseApi struct{} - -type AbuseReport struct { - Id string `json:"id"` - Subject string `json:"subject"` - Status string `json:"status"` - Reopened bool `json:"reopened"` - ReportedAt string `json:"reportedAt"` - UpdatedAt string `json:"updatedAt"` - Notifier string `json:"notifier"` - CustomerId string `json:"customerId"` - LegalEntityId string `json:"legalEntityId"` - Deadline string `json:"deadline"` - Body string `json:"body"` - DetectedIpAddresses []string `json:"detectedIpAddresses"` - DetectedDomainNames []AbuseDetectedDomainName `json:"detectedDomainNames"` - Attachments []AbuseAttachment `json:"attachments"` - TotalMessagesCount json.Number `json:"totalMessagesCount"` - LatestMessages []AbuseMessage `json:"latestMessages"` -} - -type AbuseAttachment struct { - Id string `json:"id"` - MimeType string `json:"mimeType"` - Filename string `json:"filename"` -} - -type AbuseDetectedDomainName struct { - Name string `json:"name"` - IpAddresses []string `json:"ipAddresses"` -} - -type AbuseReports struct { - Metadata Metadata `json:"_metadata"` - Reports []AbuseReport `json:"reports"` -} - -type AbuseMessage struct { - PostedBy string `json:"postedBy"` - PostedAt string `json:"postedAt"` - Body string `json:"body"` - Attachment AbuseAttachment `json:"attachment"` -} - -type AbuseMessages struct { - Messages []AbuseMessage `json:"messages"` - Metadata Metadata `json:"_metadata"` -} - -type AbuseResolution struct { - Id string `json:"id"` - Description string `json:"description"` -} - -type AbuseResolutions struct { - Resolutions []AbuseResolution `json:"resolutions"` -} - -type AbuseListOptions struct { - PaginationOptions - Status []string `param:"status"` -} - -func (aba AbuseApi) getPath(endpoint string) string { - return "/abuse/" + ABUSE_API_VERSION + endpoint -} - -func (aba AbuseApi) List(ctx context.Context, opts AbuseListOptions) (*AbuseReports, error) { - path := aba.getPath("/reports") - query := options.Encode(opts) - result := &AbuseReports{} - if err := doRequest(ctx, http.MethodGet, path, query, result); err != nil { - return nil, err - } - return result, nil -} - -func (aba AbuseApi) Get(ctx context.Context, abuseReportId string) (*AbuseReport, error) { - path := aba.getPath("/reports/" + abuseReportId) - result := &AbuseReport{} - if err := doRequest(ctx, http.MethodGet, path, "", result); err != nil { - return nil, err - } - return result, nil -} - -func (aba AbuseApi) ListMessages(ctx context.Context, abuseReportId string, opts PaginationOptions) (*AbuseMessages, error) { - path := aba.getPath("/reports/" + abuseReportId + "/messages") - query := options.Encode(opts) - result := &AbuseMessages{} - if err := doRequest(ctx, http.MethodGet, path, query, result); err != nil { - return nil, err - } - return result, nil -} - -func (aba AbuseApi) CreateMessage(ctx context.Context, abuseReportId string, body string) ([]string, error) { - var result []string - payload := map[string]string{body: body} - path := aba.getPath("/reports/" + abuseReportId + "/messages") - if err := doRequest(ctx, http.MethodPost, path, "", &result, payload); err != nil { - return nil, err - } - return result, nil -} - -func (aba AbuseApi) ListResolutionOptions(ctx context.Context, abuseReportId string) (*AbuseResolutions, error) { - path := aba.getPath("/reports/" + abuseReportId + "/resolutions") - result := &AbuseResolutions{} - if err := doRequest(ctx, http.MethodGet, path, "", result); err != nil { - return nil, err - } - return result, nil -} - -func (aba AbuseApi) Resolve(ctx context.Context, abuseReportId string, resolutions []string) error { - payload := map[string][]string{"resolutions": resolutions} - path := aba.getPath("/reports/" + abuseReportId + "/resolve") - return doRequest(ctx, http.MethodPost, path, "", nil, payload) -} - -// TODO -// func (aba AbuseApi) GetAbuseReportMessageAttachments() {} - -// TODO -// func (aba AbuseApi) GetAbuseReportAttachments() {} diff --git a/abuse_test.go b/abuse_test.go deleted file mode 100644 index f1b5a00..0000000 --- a/abuse_test.go +++ /dev/null @@ -1,814 +0,0 @@ -package leaseweb - -import ( - "context" - "fmt" - "net/http" - "testing" - - "github.com/stretchr/testify/assert" -) - -func TestAbuseList(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{"_metadata":{"limit": 10, "offset": 0, "totalCount": 2}, "reports": [ - { - "id": "000000", - "subject": "Report description 1", - "status": "OPEN", - "reportedAt": "2022-01-01T00:00:00+00:00", - "updatedAt": "2022-02-01T00:00:00+00:00", - "notifier": "notifier1@email.com", - "customerId": "10000001", - "legalEntityId": "2000", - "deadline": "2022-03-01T00:00:00+00:00" - }, - { - "id": "000001", - "subject": "Report description 2", - "status": "CLOSED", - "reportedAt": "2022-03-01T00:00:00+00:00", - "updatedAt": "2022-04-01T00:00:00+00:00", - "notifier": "notifier2@email.com", - "customerId": "10000001", - "legalEntityId": "2600", - "deadline": "2022-05-01T00:00:00+00:00" - } - ]}`) - }) - defer teardown() - - abuseApi := AbuseApi{} - ctx := context.Background() - response, err := abuseApi.List(ctx, AbuseListOptions{}) - - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 2) - assert.Equal(response.Metadata.Offset, 0) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.Reports), 2) - - abuseReport1 := response.Reports[0] - assert.Equal(abuseReport1.Id, "000000") - assert.Equal(abuseReport1.Subject, "Report description 1") - assert.Equal(abuseReport1.Status, "OPEN") - assert.Equal(abuseReport1.ReportedAt, "2022-01-01T00:00:00+00:00") - assert.Equal(abuseReport1.UpdatedAt, "2022-02-01T00:00:00+00:00") - assert.Equal(abuseReport1.Notifier, "notifier1@email.com") - assert.Equal(abuseReport1.CustomerId, "10000001") - assert.Equal(abuseReport1.LegalEntityId, "2000") - assert.Equal(abuseReport1.Deadline, "2022-03-01T00:00:00+00:00") - - abuseReport2 := response.Reports[1] - assert.Equal(abuseReport2.Id, "000001") - assert.Equal(abuseReport2.Subject, "Report description 2") - assert.Equal(abuseReport2.Status, "CLOSED") - assert.Equal(abuseReport2.ReportedAt, "2022-03-01T00:00:00+00:00") - assert.Equal(abuseReport2.UpdatedAt, "2022-04-01T00:00:00+00:00") - assert.Equal(abuseReport2.Notifier, "notifier2@email.com") - assert.Equal(abuseReport2.CustomerId, "10000001") - assert.Equal(abuseReport2.LegalEntityId, "2600") - assert.Equal(abuseReport2.Deadline, "2022-05-01T00:00:00+00:00") -} - -func TestAbuseListPaginateAndPassStatuses(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{"_metadata":{"limit": 10, "offset": 1, "totalCount": 11}, "reports": [ - { - "id": "000000", - "subject": "Report description 1", - "status": "OPEN", - "reportedAt": "2022-01-01T00:00:00+00:00", - "updatedAt": "2022-02-01T00:00:00+00:00", - "notifier": "notifier1@email.com", - "customerId": "10000001", - "legalEntityId": "2000", - "deadline": "2022-03-01T00:00:00+00:00" - } - ]}`) - }) - defer teardown() - - abuseApi := AbuseApi{} - - ctx := context.Background() - opts := AbuseListOptions{ - PaginationOptions: PaginationOptions{ - Limit: Int(1), - }, - Status: []string{"OPEN", "WAITING"}, - } - response, err := abuseApi.List(ctx, opts) - - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 11) - assert.Equal(response.Metadata.Offset, 1) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.Reports), 1) - - abuseReport1 := response.Reports[0] - assert.Equal(abuseReport1.Id, "000000") - assert.Equal(abuseReport1.Subject, "Report description 1") - assert.Equal(abuseReport1.Status, "OPEN") - assert.Equal(abuseReport1.ReportedAt, "2022-01-01T00:00:00+00:00") - assert.Equal(abuseReport1.UpdatedAt, "2022-02-01T00:00:00+00:00") - assert.Equal(abuseReport1.Notifier, "notifier1@email.com") - assert.Equal(abuseReport1.CustomerId, "10000001") - assert.Equal(abuseReport1.LegalEntityId, "2000") - assert.Equal(abuseReport1.Deadline, "2022-03-01T00:00:00+00:00") -} - -func TestAbuseListBeEmpty(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{"_metadata":{"limit": 10, "offset": 0, "totalCount": 0}, "reports": []}`) - }) - defer teardown() - - abuseApi := AbuseApi{} - ctx := context.Background() - response, err := abuseApi.List(ctx, AbuseListOptions{}) - - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 0) - assert.Equal(response.Metadata.Offset, 0) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.Reports), 0) -} - -func TestAbuseListServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"errorCode": "ACCESS_DENIED", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return AbuseApi{}.List(ctx, AbuseListOptions{}) - }, - ExpectedError: ApiError{ - Code: "ACCESS_DENIED", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"errorCode": "SERVER_ERROR", "errorMessage": "The server encountered an unexpected condition that prevented it from fulfilling the request."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return AbuseApi{}.List(ctx, AbuseListOptions{}) - }, - ExpectedError: ApiError{ - Code: "SERVER_ERROR", - Message: "The server encountered an unexpected condition that prevented it from fulfilling the request.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"errorCode": "TEMPORARILY_UNAVAILABLE", "errorMessage": "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return AbuseApi{}.List(ctx, AbuseListOptions{}) - }, - ExpectedError: ApiError{ - Code: "TEMPORARILY_UNAVAILABLE", - Message: "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestAbuseGet(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "id": "000005", - "subject": "Report description", - "status": "CLOSED", - "reopened": false, - "reportedAt": "2015-01-01T00:00:00+0100", - "updatedAt": "2015-02-01T00:00:00+0100", - "notifier": "notifier@email.com", - "customerId": "10000001", - "legalEntityId": "2000", - "body": "string with content", - "deadline": "2015-01-01T00:00:00+0100", - "detectedIpAddresses": [ - "127.0.0.1" - ], - "detectedDomainNames": [ - { - "name": "example.com", - "ipAddresses": [ - "93.184.216.34" - ] - } - ], - "attachments": [ - { - "id": "1abd8e7f-0fdf-453c-b1f5-8fef436acbbe", - "mimeType": "part/xml", - "filename": "000001.xml" - } - ], - "totalMessagesCount": 2, - "latestMessages": [ - { - "postedBy": "CUSTOMER", - "postedAt": "2015-09-30T06:23:40+00:00", - "body": "Hello, this is my first message!" - }, - { - "postedBy": "ABUSE_AGENT", - "postedAt": "2015-10-08T08:25:29+00:00", - "body": "Hi, this is our first reply.", - "attachment": { - "id": "436acbbe-0fdf-453c-b1f5-1abd8e7f8fef", - "mimeType": "image/png", - "filename": "notification.png" - } - } - ] - }`) - }) - defer teardown() - - abuseApi := AbuseApi{} - ctx := context.Background() - response, err := abuseApi.Get(ctx, "000005") - - assert := assert.New(t) - assert.Nil(err) - - assert.Equal(response.Id, "000005") - assert.Equal(response.Subject, "Report description") - assert.Equal(response.Status, "CLOSED") - assert.Equal(response.Reopened, false) - assert.Equal(response.ReportedAt, "2015-01-01T00:00:00+0100") - assert.Equal(response.UpdatedAt, "2015-02-01T00:00:00+0100") - assert.Equal(response.Notifier, "notifier@email.com") - assert.Equal(response.CustomerId, "10000001") - assert.Equal(response.LegalEntityId, "2000") - assert.Equal(response.Body, "string with content") - assert.Equal(response.Deadline, "2015-01-01T00:00:00+0100") - assert.Equal(response.DetectedIpAddresses[0], "127.0.0.1") - assert.Equal(response.DetectedDomainNames[0].Name, "example.com") - assert.Equal(response.DetectedDomainNames[0].IpAddresses[0], "93.184.216.34") - assert.Equal(response.Attachments[0].Id, "1abd8e7f-0fdf-453c-b1f5-8fef436acbbe") - assert.Equal(response.Attachments[0].MimeType, "part/xml") - assert.Equal(response.Attachments[0].Filename, "000001.xml") - assert.Equal(response.TotalMessagesCount.String(), "2") - assert.Equal(len(response.LatestMessages), 2) - - message1 := response.LatestMessages[0] - assert.Equal(message1.PostedBy, "CUSTOMER") - assert.Equal(message1.PostedAt, "2015-09-30T06:23:40+00:00") - assert.Equal(message1.Body, "Hello, this is my first message!") - - message2 := response.LatestMessages[1] - assert.Equal(message2.PostedBy, "ABUSE_AGENT") - assert.Equal(message2.PostedAt, "2015-10-08T08:25:29+00:00") - assert.Equal(message2.Body, "Hi, this is our first reply.") - - assert.Equal(message2.Attachment.Id, "436acbbe-0fdf-453c-b1f5-1abd8e7f8fef") - assert.Equal(message2.Attachment.MimeType, "image/png") - assert.Equal(message2.Attachment.Filename, "notification.png") -} - -func TestAbuseGetServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"errorCode": "ACCESS_DENIED", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return AbuseApi{}.Get(ctx, "wrong-id") - }, - ExpectedError: ApiError{ - Code: "ACCESS_DENIED", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusNotFound) - fmt.Fprintf(w, `{}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return AbuseApi{}.Get(ctx, "123456") - }, - ExpectedError: ApiError{Code: "404", Message: "Not Found"}, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"errorCode": "SERVER_ERROR", "errorMessage": "The server encountered an unexpected condition that prevented it from fulfilling the request."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return AbuseApi{}.Get(ctx, "123456") - }, - ExpectedError: ApiError{ - Code: "SERVER_ERROR", - Message: "The server encountered an unexpected condition that prevented it from fulfilling the request.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"errorCode": "TEMPORARILY_UNAVAILABLE", "errorMessage": "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return AbuseApi{}.Get(ctx, "123456") - }, - ExpectedError: ApiError{ - Code: "TEMPORARILY_UNAVAILABLE", - Message: "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestAbuseListMessages(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{"_metadata":{"limit": 10, "offset": 0, "totalCount": 2}, "messages": [ - { - "postedBy": "CUSTOMER", - "postedAt": "2015-09-30T06:23:40+00:00", - "body": "Hello, this is my first message!" - }, - { - "postedBy": "ABUSE_AGENT", - "postedAt": "2015-10-08T08:25:29+00:00", - "body": "Hi, this is our first reply.", - "attachment": { - "id": "436acbbe-0fdf-453c-b1f5-1abd8e7f8fef", - "mimeType": "image/png", - "filename": "notification.png" - } - } - ]}`) - }) - defer teardown() - - abuseApi := AbuseApi{} - ctx := context.Background() - response, err := abuseApi.ListMessages(ctx, "123456789", PaginationOptions{}) - - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 2) - assert.Equal(response.Metadata.Offset, 0) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.Messages), 2) - - message1 := response.Messages[0] - assert.Equal(message1.PostedBy, "CUSTOMER") - assert.Equal(message1.PostedAt, "2015-09-30T06:23:40+00:00") - assert.Equal(message1.Body, "Hello, this is my first message!") - - message2 := response.Messages[1] - assert.Equal(message2.PostedBy, "ABUSE_AGENT") - assert.Equal(message2.PostedAt, "2015-10-08T08:25:29+00:00") - assert.Equal(message2.Body, "Hi, this is our first reply.") - - assert.Equal(message2.Attachment.Id, "436acbbe-0fdf-453c-b1f5-1abd8e7f8fef") - assert.Equal(message2.Attachment.MimeType, "image/png") - assert.Equal(message2.Attachment.Filename, "notification.png") -} - -func TestAbuseListMessagesPaginate(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{"_metadata":{"limit": 10, "offset": 1, "totalCount": 11}, "messages": [ - { - "postedBy": "ABUSE_AGENT", - "postedAt": "2015-10-08T08:25:29+00:00", - "body": "Hi, this is our first reply.", - "attachment": { - "id": "436acbbe-0fdf-453c-b1f5-1abd8e7f8fef", - "mimeType": "image/png", - "filename": "notification.png" - } - } - ]}`) - }) - defer teardown() - - abuseApi := AbuseApi{} - ctx := context.Background() - opts := PaginationOptions{ - Limit: Int(1), - } - response, err := abuseApi.ListMessages(ctx, "123456789", opts) - - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 11) - assert.Equal(response.Metadata.Offset, 1) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.Messages), 1) - - message1 := response.Messages[0] - assert.Equal(message1.PostedBy, "ABUSE_AGENT") - assert.Equal(message1.PostedAt, "2015-10-08T08:25:29+00:00") - assert.Equal(message1.Body, "Hi, this is our first reply.") - - assert.Equal(message1.Attachment.Id, "436acbbe-0fdf-453c-b1f5-1abd8e7f8fef") - assert.Equal(message1.Attachment.MimeType, "image/png") - assert.Equal(message1.Attachment.Filename, "notification.png") -} - -func TestAbuseListMessagesBeEmpty(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{"_metadata":{"limit": 10, "offset": 0, "totalCount": 0}, "messages": []}`) - }) - defer teardown() - - abuseApi := AbuseApi{} - ctx := context.Background() - response, err := abuseApi.ListMessages(ctx, "123456789", PaginationOptions{}) - - assert := assert.New(t) - assert.Nil(err) - assert.Empty(response.Messages) - assert.Equal(response.Metadata.TotalCount, 0) - assert.Equal(response.Metadata.Offset, 0) - assert.Equal(response.Metadata.Limit, 10) -} - -func TestAbuseListMessagesServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"errorCode": "ACCESS_DENIED", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return AbuseApi{}.ListMessages(ctx, "123456789", PaginationOptions{}) - }, - ExpectedError: ApiError{ - Code: "ACCESS_DENIED", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusNotFound) - fmt.Fprintf(w, `{}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return AbuseApi{}.ListMessages(ctx, "123456789", PaginationOptions{}) - }, - ExpectedError: ApiError{Code: "404", Message: "Not Found"}, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"errorCode": "SERVER_ERROR", "errorMessage": "The server encountered an unexpected condition that prevented it from fulfilling the request."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return AbuseApi{}.ListMessages(ctx, "123456789", PaginationOptions{}) - }, - ExpectedError: ApiError{ - Code: "SERVER_ERROR", - Message: "The server encountered an unexpected condition that prevented it from fulfilling the request.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"errorCode": "TEMPORARILY_UNAVAILABLE", "errorMessage": "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return AbuseApi{}.ListMessages(ctx, "123456789", PaginationOptions{}) - }, - ExpectedError: ApiError{ - Code: "TEMPORARILY_UNAVAILABLE", - Message: "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestAbuseCreateMessage(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusAccepted) - fmt.Fprintf(w, `["To make sure the request has been processed please see if the message is added to the list."]`) - }) - defer teardown() - - abuseApi := AbuseApi{} - ctx := context.Background() - resp, err := abuseApi.CreateMessage(ctx, "123456789", "message body...") - - assert := assert.New(t) - assert.Nil(err) - assert.Equal(resp[0], "To make sure the request has been processed please see if the message is added to the list.") -} - -func TestAbuseCreateMessageServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"errorCode": "ACCESS_DENIED", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return AbuseApi{}.CreateMessage(ctx, "123456789", "message body...") - }, - ExpectedError: ApiError{ - Code: "ACCESS_DENIED", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"errorCode": "SERVER_ERROR", "errorMessage": "The server encountered an unexpected condition that prevented it from fulfilling the request."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return AbuseApi{}.CreateMessage(ctx, "123456789", "message body...") - }, - ExpectedError: ApiError{ - Code: "SERVER_ERROR", - Message: "The server encountered an unexpected condition that prevented it from fulfilling the request.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"errorCode": "TEMPORARILY_UNAVAILABLE", "errorMessage": "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return AbuseApi{}.CreateMessage(ctx, "123456789", "message body...") - }, - ExpectedError: ApiError{ - Code: "TEMPORARILY_UNAVAILABLE", - Message: "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestAbuseListResolutionOptions(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{"resolutions": [ - { - "id": "CONTENT_REMOVED", - "description": "The mentioned content has been removed." - }, - { - "id": "DOMAINS_REMOVED", - "description": "The mentioned domain(s) has/have been removed from the LeaseWeb network." - }, - { - "id": "SUSPENDED", - "description": "The end customer (or responsible user) has been suspended." - }, - { - "id": "DUPLICATE", - "description": "This is either a duplicate or old notification and has already been resolved." - } - ]}`) - }) - defer teardown() - - abuseApi := AbuseApi{} - ctx := context.Background() - response, err := abuseApi.ListResolutionOptions(ctx, "123456789") - - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Resolutions[0].Id, "CONTENT_REMOVED") - assert.Equal(response.Resolutions[1].Id, "DOMAINS_REMOVED") - assert.Equal(response.Resolutions[2].Id, "SUSPENDED") - assert.Equal(response.Resolutions[3].Id, "DUPLICATE") -} - -func TestAbuseListResolutionOptionsBeEmpty(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{"resolutions": []}`) - }) - defer teardown() - - abuseApi := AbuseApi{} - ctx := context.Background() - response, err := abuseApi.ListResolutionOptions(ctx, "123456789") - - assert := assert.New(t) - assert.Nil(err) - assert.Empty(response.Resolutions) -} - -func TestAbuseListResolutionOptionsServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"errorCode": "ACCESS_DENIED", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return AbuseApi{}.ListResolutionOptions(ctx, "123456789") - }, - ExpectedError: ApiError{ - Code: "ACCESS_DENIED", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"errorCode": "SERVER_ERROR", "errorMessage": "The server encountered an unexpected condition that prevented it from fulfilling the request."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return AbuseApi{}.ListResolutionOptions(ctx, "123456789") - }, - ExpectedError: ApiError{ - Code: "SERVER_ERROR", - Message: "The server encountered an unexpected condition that prevented it from fulfilling the request.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"errorCode": "TEMPORARILY_UNAVAILABLE", "errorMessage": "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return AbuseApi{}.ListResolutionOptions(ctx, "123456789") - }, - ExpectedError: ApiError{ - Code: "TEMPORARILY_UNAVAILABLE", - Message: "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestAbuseResolve(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusNoContent) - }) - defer teardown() - - abuseApi := AbuseApi{} - ctx := context.Background() - err := abuseApi.Resolve(ctx, "123456789", []string{"CONTENT_REMOVED", "SUSPENDED"}) - - assert := assert.New(t) - assert.Nil(err) -} - -func TestAbuseResolveServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"errorCode": "ACCESS_DENIED", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, AbuseApi{}.Resolve(ctx, "123456789", []string{"CONTENT_REMOVED", "SUSPENDED"}) - }, - ExpectedError: ApiError{ - Code: "ACCESS_DENIED", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"errorCode": "SERVER_ERROR", "errorMessage": "The server encountered an unexpected condition that prevented it from fulfilling the request."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, AbuseApi{}.Resolve(ctx, "123456789", []string{"CONTENT_REMOVED", "SUSPENDED"}) - }, - ExpectedError: ApiError{ - Code: "SERVER_ERROR", - Message: "The server encountered an unexpected condition that prevented it from fulfilling the request.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"errorCode": "TEMPORARILY_UNAVAILABLE", "errorMessage": "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, AbuseApi{}.Resolve(ctx, "123456789", []string{"CONTENT_REMOVED", "SUSPENDED"}) - }, - ExpectedError: ApiError{ - Code: "TEMPORARILY_UNAVAILABLE", - Message: "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} diff --git a/bmp/README.md b/bmp/README.md new file mode 100644 index 0000000..9149fae --- /dev/null +++ b/bmp/README.md @@ -0,0 +1,245 @@ +# Go API client for bmp + +This documents the rest api bmp api provides. + +## Overview +This API client was generated by the [OpenAPI Generator](https://openapi-generator.tech) project. By using the [OpenAPI-spec](https://www.openapis.org/) from a remote server, you can easily generate an API client. + +- API version: v2 +- Package version: 1.0.0 +- Generator version: 7.4.0 +- Build package: org.openapitools.codegen.languages.GoClientCodegen + +## Installation + +Install the following dependencies: + +```sh +go get github.com/stretchr/testify/assert +go get golang.org/x/oauth2 +go get golang.org/x/net/context +``` + +Put the package under your project folder and add the following in import: + +```go +import bmp "github.com/leaseweb/leaseweb-go-sdk/bmp" +``` + +To use a proxy, set the environment variable `HTTP_PROXY`: + +```go +os.Setenv("HTTP_PROXY", "http://proxy_name:proxy_port") +``` + +## Configuration of Server URL + +Default configuration comes with `Servers` field that contains server objects as defined in the OpenAPI specification. + +### Select Server Configuration + +For using other server than the one defined on index 0 set context value `bmp.ContextServerIndex` of type `int`. + +```go +ctx := context.WithValue(context.Background(), bmp.ContextServerIndex, 1) +``` + +### Templated Server URL + +Templated server URL is formatted using default variables from configuration or from context value `bmp.ContextServerVariables` of type `map[string]string`. + +```go +ctx := context.WithValue(context.Background(), bmp.ContextServerVariables, map[string]string{ + "basePath": "v2", +}) +``` + +Note, enum values are always validated and all unused variables are silently ignored. + +### URLs Configuration per Operation + +Each operation can use different server URL defined using `OperationServers` map in the `Configuration`. +An operation is uniquely identified by `"{classname}Service.{nickname}"` string. +Similar rules for overriding default operation server index and variables applies by using `bmp.ContextOperationServerIndices` and `bmp.ContextOperationServerVariables` context maps. + +```go +ctx := context.WithValue(context.Background(), bmp.ContextOperationServerIndices, map[string]int{ + "{classname}Service.{nickname}": 2, +}) +ctx = context.WithValue(context.Background(), bmp.ContextOperationServerVariables, map[string]map[string]string{ + "{classname}Service.{nickname}": { + "port": "8443", + }, +}) +``` + +## Documentation for API Endpoints + +All URIs are relative to *https://api.leaseweb.com/internal/bmpapi/v2* + +Class | Method | HTTP request | Description +------------ | ------------- | ------------- | ------------- +*BmpAPI* | [**AddServerCredential**](docs/BmpAPI.md#addservercredential) | **Post** /servers/{serverId}/credentials | Create new credentials +*BmpAPI* | [**CancelActiveJob**](docs/BmpAPI.md#cancelactivejob) | **Post** /servers/{serverId}/cancelActiveJob | Cancel active job +*BmpAPI* | [**ConfigureHardwareRaid**](docs/BmpAPI.md#configurehardwareraid) | **Post** /servers/{serverId}/configureHardwareRaid | Configure Hardware Raid +*BmpAPI* | [**CreateServerDhcpReservation**](docs/BmpAPI.md#createserverdhcpreservation) | **Post** /servers/{serverId}/leases | Create a DHCP reservation +*BmpAPI* | [**DeleteNetworkEquipmentCredential**](docs/BmpAPI.md#deletenetworkequipmentcredential) | **Delete** /networkEquipments/{networkEquipmentId}/credentials/{type}/{username} | Delete user credentials +*BmpAPI* | [**DeleteServerCredential**](docs/BmpAPI.md#deleteservercredential) | **Delete** /servers/{serverId}/credentials/{type}/{username} | Delete server credential +*BmpAPI* | [**EnableServerRescueMode**](docs/BmpAPI.md#enableserverrescuemode) | **Post** /servers/{serverId}/rescueMode | Launch rescue mode +*BmpAPI* | [**ExpireActiveJob**](docs/BmpAPI.md#expireactivejob) | **Post** /servers/{serverId}/expireActiveJob | Expire active job +*BmpAPI* | [**GetControlPanelList**](docs/BmpAPI.md#getcontrolpanellist) | **Get** /controlPanels | List control panels +*BmpAPI* | [**GetControlPanelListByOperatingSystem**](docs/BmpAPI.md#getcontrolpanellistbyoperatingsystem) | **Get** /operatingSystems/{operatingSystemId}/controlPanels | List control panels +*BmpAPI* | [**GetNetworkEquipmentCredentialListByType**](docs/BmpAPI.md#getnetworkequipmentcredentiallistbytype) | **Get** /networkEquipments/{networkEquipmentId}/credentials/{type} | List credentials by type +*BmpAPI* | [**GetNetworkEquipmentPowerStatus**](docs/BmpAPI.md#getnetworkequipmentpowerstatus) | **Get** /networkEquipments/{networkEquipmentId}/powerInfo | Show power status +*BmpAPI* | [**GetOperatingSystem**](docs/BmpAPI.md#getoperatingsystem) | **Get** /operatingSystems/{operatingSystemId} | Show an operating system +*BmpAPI* | [**GetOperatingSystemList**](docs/BmpAPI.md#getoperatingsystemlist) | **Get** /operatingSystems | List Operating Systems +*BmpAPI* | [**GetRescueImageList**](docs/BmpAPI.md#getrescueimagelist) | **Get** /rescueImages | Rescue Images +*BmpAPI* | [**GetServerCredentialList**](docs/BmpAPI.md#getservercredentiallist) | **Get** /servers/{serverId}/credentials | List credentials +*BmpAPI* | [**GetServerDhcpReservationList**](docs/BmpAPI.md#getserverdhcpreservationlist) | **Get** /servers/{serverId}/leases | List DHCP reservations +*BmpAPI* | [**GetServerJobList**](docs/BmpAPI.md#getserverjoblist) | **Get** /servers/{serverId}/jobs | List jobs +*BmpAPI* | [**GetServerPowerStatus**](docs/BmpAPI.md#getserverpowerstatus) | **Get** /servers/{serverId}/powerInfo | Show power status +*BmpAPI* | [**InstallOperatingSystem**](docs/BmpAPI.md#installoperatingsystem) | **Post** /servers/{serverId}/install | Launch installation +*BmpAPI* | [**IpmiResetServer**](docs/BmpAPI.md#ipmiresetserver) | **Post** /servers/{serverId}/ipmiReset | Launch IPMI reset +*BmpAPI* | [**NetworkEquipmentsCredentialsGet**](docs/BmpAPI.md#networkequipmentscredentialsget) | **Get** /networkEquipments/{networkEquipmentId}/credentials/{type}/{username} | Show user credentials +*BmpAPI* | [**NetworkEquipmentsCredentialsList**](docs/BmpAPI.md#networkequipmentscredentialslist) | **Get** /networkEquipments/{networkEquipmentId}/credentials | List credentials +*BmpAPI* | [**NetworkEquipmentsCredentialsPost**](docs/BmpAPI.md#networkequipmentscredentialspost) | **Post** /networkEquipments/{networkEquipmentId}/credentials | Create new credentials +*BmpAPI* | [**PowerCycleNetworkEquipment**](docs/BmpAPI.md#powercyclenetworkequipment) | **Post** /networkEquipments/{networkEquipmentId}/powerCycle | Power cycle a network equipment +*BmpAPI* | [**PowerCycleServer**](docs/BmpAPI.md#powercycleserver) | **Post** /servers/{serverId}/powerCycle | Power cycle a server +*BmpAPI* | [**PowerNetworkEquipmentOff**](docs/BmpAPI.md#powernetworkequipmentoff) | **Post** /networkEquipments/{networkEquipmentId}/powerOff | Power off network equipment +*BmpAPI* | [**PowerNetworkEquipmentOn**](docs/BmpAPI.md#powernetworkequipmenton) | **Post** /networkEquipments/{networkEquipmentId}/powerOn | Power on network equipment +*BmpAPI* | [**PowerServerOff**](docs/BmpAPI.md#powerserveroff) | **Post** /servers/{serverId}/powerOff | Power off server +*BmpAPI* | [**PowerServerOn**](docs/BmpAPI.md#powerserveron) | **Post** /servers/{serverId}/powerOn | Power on server +*BmpAPI* | [**RetryServerJob**](docs/BmpAPI.md#retryserverjob) | **Post** /servers/{serverId}/jobs/{jobId}/retry | Retry a job +*BmpAPI* | [**ScanHardware**](docs/BmpAPI.md#scanhardware) | **Post** /servers/{serverId}/hardwareScan | Launch hardware scan +*BmpAPI* | [**ServersCredentialsGet**](docs/BmpAPI.md#serverscredentialsget) | **Get** /servers/{serverId}/credentials/{type}/{username} | Show user credentials +*BmpAPI* | [**ServersCredentialsListType**](docs/BmpAPI.md#serverscredentialslisttype) | **Get** /servers/{serverId}/credentials/{type} | List credentials by type +*BmpAPI* | [**ServersCredentialsPut**](docs/BmpAPI.md#serverscredentialsput) | **Put** /servers/{serverId}/credentials/{type}/{username} | Update user credentials +*BmpAPI* | [**ServersJobsGet**](docs/BmpAPI.md#serversjobsget) | **Get** /servers/{serverId}/jobs/{jobId} | Show a job +*BmpAPI* | [**ServersLeasesDelete**](docs/BmpAPI.md#serversleasesdelete) | **Delete** /servers/{serverId}/leases | Delete a DHCP reservation +*BmpAPI* | [**UpdateNetworkEquipmentCredential**](docs/BmpAPI.md#updatenetworkequipmentcredential) | **Put** /networkEquipments/{networkEquipmentId}/credentials/{type}/{username} | Update user credentials + + +## Documentation For Models + + - [ConfigureHardwareRaidOpts](docs/ConfigureHardwareRaidOpts.md) + - [ControlPanel](docs/ControlPanel.md) + - [ControlPanelList](docs/ControlPanelList.md) + - [CreateNetworkEquipmentCredentialOpts](docs/CreateNetworkEquipmentCredentialOpts.md) + - [CreateServerCredentialOpts](docs/CreateServerCredentialOpts.md) + - [CreateServerDhcpReservationOpts](docs/CreateServerDhcpReservationOpts.md) + - [Credential](docs/Credential.md) + - [CredentialList](docs/CredentialList.md) + - [CredentialType](docs/CredentialType.md) + - [Defaults](docs/Defaults.md) + - [EnableServerRescueModeOpts](docs/EnableServerRescueModeOpts.md) + - [ErrorResult](docs/ErrorResult.md) + - [GetNetworkEquipmentPowerStatusResult](docs/GetNetworkEquipmentPowerStatusResult.md) + - [GetOperatingSystemListResult](docs/GetOperatingSystemListResult.md) + - [GetOperatingSystemResult](docs/GetOperatingSystemResult.md) + - [GetRescueImageListResult](docs/GetRescueImageListResult.md) + - [GetServerDhcpReservationListResult](docs/GetServerDhcpReservationListResult.md) + - [GetServerPowerStatusResult](docs/GetServerPowerStatusResult.md) + - [InstallOperatingSystemOpts](docs/InstallOperatingSystemOpts.md) + - [Ipmi](docs/Ipmi.md) + - [IpmiResetServerOpts](docs/IpmiResetServerOpts.md) + - [LastClientRequest](docs/LastClientRequest.md) + - [Lease](docs/Lease.md) + - [Metadata](docs/Metadata.md) + - [OperatingSystem](docs/OperatingSystem.md) + - [Partition](docs/Partition.md) + - [Pdu](docs/Pdu.md) + - [Raid](docs/Raid.md) + - [RaidType](docs/RaidType.md) + - [RescueImage](docs/RescueImage.md) + - [ScanHardwareOpts](docs/ScanHardwareOpts.md) + - [ServerJob](docs/ServerJob.md) + - [ServerJobList](docs/ServerJobList.md) + - [Task](docs/Task.md) + - [UpdateNetworkEquipmentCredentialOpts](docs/UpdateNetworkEquipmentCredentialOpts.md) + - [UpdateServerCredentialOpts](docs/UpdateServerCredentialOpts.md) + + +## Documentation For Authorization + + +Authentication schemes defined for the API: +### ApiKeyAuth + +- **Type**: API key +- **API key parameter name**: X-LSW-Auth +- **Location**: HTTP header + +Note, each API key must be added to a map of `map[string]APIKey` where the key is: X-LSW-Auth and passed in as the auth context for each request. + +Example + +```go +auth := context.WithValue( + context.Background(), + bmp.ContextAPIKeys, + map[string]bmp.APIKey{ + "X-LSW-Auth": {Key: "API_KEY_STRING"}, + }, + ) +r, err := client.Service.Operation(auth, args) +``` + +### OAuth2 + + +- **Type**: OAuth +- **Flow**: application +- **Authorization URL**: +- **Scopes**: N/A + +Example + +```go +auth := context.WithValue(context.Background(), bmp.ContextAccessToken, "ACCESSTOKENSTRING") +r, err := client.Service.Operation(auth, args) +``` + +Or via OAuth2 module to automatically refresh tokens and perform user authentication. + +```go +import "golang.org/x/oauth2" + +/* Perform OAuth2 round trip request and obtain a token */ + +tokenSource := oauth2cfg.TokenSource(createContext(httpClient), &token) +auth := context.WithValue(oauth2.NoContext, bmp.ContextOAuth2, tokenSource) +r, err := client.Service.Operation(auth, args) +``` + +### BearerAuth + +- **Type**: HTTP Bearer token authentication + +Example + +```go +auth := context.WithValue(context.Background(), bmp.ContextAccessToken, "BEARER_TOKEN_STRING") +r, err := client.Service.Operation(auth, args) +``` + + +## Documentation for Utility Methods + +Due to the fact that model structure members are all pointers, this package contains +a number of utility functions to easily obtain pointers to values of basic types. +Each of these functions takes a value of the given basic type and returns a pointer to it: + +* `PtrBool` +* `PtrInt` +* `PtrInt32` +* `PtrInt64` +* `PtrFloat` +* `PtrFloat32` +* `PtrFloat64` +* `PtrString` +* `PtrTime` + +## Author + +development-networkautomation@leaseweb.com + diff --git a/bmp/api_bmp.go b/bmp/api_bmp.go new file mode 100644 index 0000000..91a6848 --- /dev/null +++ b/bmp/api_bmp.go @@ -0,0 +1,6943 @@ +/* +bmp + +This documents the rest api bmp api provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package bmp + +import ( + "bytes" + "context" + "io" + "net/http" + "net/url" + "strings" +) + + +// BmpAPIService BmpAPI service +type BmpAPIService service + +type ApiAddServerCredentialRequest struct { + ctx context.Context + ApiService *BmpAPIService + serverId string + createServerCredentialOpts *CreateServerCredentialOpts +} + +func (r ApiAddServerCredentialRequest) CreateServerCredentialOpts(createServerCredentialOpts CreateServerCredentialOpts) ApiAddServerCredentialRequest { + r.createServerCredentialOpts = &createServerCredentialOpts + return r +} + +func (r ApiAddServerCredentialRequest) Execute() (*Credential, *http.Response, error) { + return r.ApiService.AddServerCredentialExecute(r) +} + +/* +AddServerCredential Create new credentials + +Password will NOT be updated on the server. The ability to update credentials +is for convenience only. It provides a secure way to communicate passwords +with Leaseweb engineers in case support is required. + + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param serverId The ID of a server + @return ApiAddServerCredentialRequest +*/ +func (a *BmpAPIService) AddServerCredential(ctx context.Context, serverId string) ApiAddServerCredentialRequest { + return ApiAddServerCredentialRequest{ + ApiService: a, + ctx: ctx, + serverId: serverId, + } +} + +// Execute executes the request +// @return Credential +func (a *BmpAPIService) AddServerCredentialExecute(r ApiAddServerCredentialRequest) (*Credential, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodPost + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *Credential + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "BmpAPIService.AddServerCredential") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/servers/{serverId}/credentials" + localVarPath = strings.Replace(localVarPath, "{"+"serverId"+"}", url.PathEscape(parameterValueToString(r.serverId, "serverId")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{"application/json"} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + // body params + localVarPostBody = r.createServerCredentialOpts + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiCancelActiveJobRequest struct { + ctx context.Context + ApiService *BmpAPIService + serverId string +} + +func (r ApiCancelActiveJobRequest) Execute() (*ServerJob, *http.Response, error) { + return r.ApiService.CancelActiveJobExecute(r) +} + +/* +CancelActiveJob Cancel active job + +Canceling an active job will trigger the `onfail` flow of the current job +often resulting in a server reboot. If you do not want the server state to +change `expire` the active job instead. + + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param serverId The ID of a server + @return ApiCancelActiveJobRequest +*/ +func (a *BmpAPIService) CancelActiveJob(ctx context.Context, serverId string) ApiCancelActiveJobRequest { + return ApiCancelActiveJobRequest{ + ApiService: a, + ctx: ctx, + serverId: serverId, + } +} + +// Execute executes the request +// @return ServerJob +func (a *BmpAPIService) CancelActiveJobExecute(r ApiCancelActiveJobRequest) (*ServerJob, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodPost + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *ServerJob + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "BmpAPIService.CancelActiveJob") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/servers/{serverId}/cancelActiveJob" + localVarPath = strings.Replace(localVarPath, "{"+"serverId"+"}", url.PathEscape(parameterValueToString(r.serverId, "serverId")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiConfigureHardwareRaidRequest struct { + ctx context.Context + ApiService *BmpAPIService + serverId string + configureHardwareRaidOpts *ConfigureHardwareRaidOpts +} + +func (r ApiConfigureHardwareRaidRequest) ConfigureHardwareRaidOpts(configureHardwareRaidOpts ConfigureHardwareRaidOpts) ApiConfigureHardwareRaidRequest { + r.configureHardwareRaidOpts = &configureHardwareRaidOpts + return r +} + +func (r ApiConfigureHardwareRaidRequest) Execute() (*ServerJobList, *http.Response, error) { + return r.ApiService.ConfigureHardwareRaidExecute(r) +} + +/* +ConfigureHardwareRaid Configure Hardware Raid + +This is an `internal` only job that can be used to configure Hardware RAID on +servers that are Hardware RAID capable. + +All existing data will be destroyed! + + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param serverId The ID of a server + @return ApiConfigureHardwareRaidRequest +*/ +func (a *BmpAPIService) ConfigureHardwareRaid(ctx context.Context, serverId string) ApiConfigureHardwareRaidRequest { + return ApiConfigureHardwareRaidRequest{ + ApiService: a, + ctx: ctx, + serverId: serverId, + } +} + +// Execute executes the request +// @return ServerJobList +func (a *BmpAPIService) ConfigureHardwareRaidExecute(r ApiConfigureHardwareRaidRequest) (*ServerJobList, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodPost + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *ServerJobList + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "BmpAPIService.ConfigureHardwareRaid") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/servers/{serverId}/configureHardwareRaid" + localVarPath = strings.Replace(localVarPath, "{"+"serverId"+"}", url.PathEscape(parameterValueToString(r.serverId, "serverId")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{"application/json"} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + // body params + localVarPostBody = r.configureHardwareRaidOpts + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiCreateServerDhcpReservationRequest struct { + ctx context.Context + ApiService *BmpAPIService + serverId string + createServerDhcpReservationOpts *CreateServerDhcpReservationOpts +} + +func (r ApiCreateServerDhcpReservationRequest) CreateServerDhcpReservationOpts(createServerDhcpReservationOpts CreateServerDhcpReservationOpts) ApiCreateServerDhcpReservationRequest { + r.createServerDhcpReservationOpts = &createServerDhcpReservationOpts + return r +} + +func (r ApiCreateServerDhcpReservationRequest) Execute() (*http.Response, error) { + return r.ApiService.CreateServerDhcpReservationExecute(r) +} + +/* +CreateServerDhcpReservation Create a DHCP reservation + +After rebooting your server it will acquire this DHCP reservation and boot +from the specified `bootfile` url. + +Please note that this API call will not reboot or power cycle your server. + + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param serverId The ID of a server + @return ApiCreateServerDhcpReservationRequest +*/ +func (a *BmpAPIService) CreateServerDhcpReservation(ctx context.Context, serverId string) ApiCreateServerDhcpReservationRequest { + return ApiCreateServerDhcpReservationRequest{ + ApiService: a, + ctx: ctx, + serverId: serverId, + } +} + +// Execute executes the request +func (a *BmpAPIService) CreateServerDhcpReservationExecute(r ApiCreateServerDhcpReservationRequest) (*http.Response, error) { + var ( + localVarHTTPMethod = http.MethodPost + localVarPostBody interface{} + formFiles []formFile + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "BmpAPIService.CreateServerDhcpReservation") + if err != nil { + return nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/servers/{serverId}/leases" + localVarPath = strings.Replace(localVarPath, "{"+"serverId"+"}", url.PathEscape(parameterValueToString(r.serverId, "serverId")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{"application/json"} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + // body params + localVarPostBody = r.createServerDhcpReservationOpts + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarHTTPResponse, newErr + } + + return localVarHTTPResponse, nil +} + +type ApiDeleteNetworkEquipmentCredentialRequest struct { + ctx context.Context + ApiService *BmpAPIService + networkEquipmentId string + type_ string + username string +} + +func (r ApiDeleteNetworkEquipmentCredentialRequest) Execute() (*http.Response, error) { + return r.ApiService.DeleteNetworkEquipmentCredentialExecute(r) +} + +/* +DeleteNetworkEquipmentCredential Delete user credentials + +This action is purely administrative and will only remove the username and +password associated with this resource from our database. + + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param networkEquipmentId The ID of a dedicated network equipment + @param type_ Credential type + @param username Username + @return ApiDeleteNetworkEquipmentCredentialRequest +*/ +func (a *BmpAPIService) DeleteNetworkEquipmentCredential(ctx context.Context, networkEquipmentId string, type_ string, username string) ApiDeleteNetworkEquipmentCredentialRequest { + return ApiDeleteNetworkEquipmentCredentialRequest{ + ApiService: a, + ctx: ctx, + networkEquipmentId: networkEquipmentId, + type_: type_, + username: username, + } +} + +// Execute executes the request +func (a *BmpAPIService) DeleteNetworkEquipmentCredentialExecute(r ApiDeleteNetworkEquipmentCredentialRequest) (*http.Response, error) { + var ( + localVarHTTPMethod = http.MethodDelete + localVarPostBody interface{} + formFiles []formFile + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "BmpAPIService.DeleteNetworkEquipmentCredential") + if err != nil { + return nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/networkEquipments/{networkEquipmentId}/credentials/{type}/{username}" + localVarPath = strings.Replace(localVarPath, "{"+"networkEquipmentId"+"}", url.PathEscape(parameterValueToString(r.networkEquipmentId, "networkEquipmentId")), -1) + localVarPath = strings.Replace(localVarPath, "{"+"type"+"}", url.PathEscape(parameterValueToString(r.type_, "type_")), -1) + localVarPath = strings.Replace(localVarPath, "{"+"username"+"}", url.PathEscape(parameterValueToString(r.username, "username")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarHTTPResponse, newErr + } + + return localVarHTTPResponse, nil +} + +type ApiDeleteServerCredentialRequest struct { + ctx context.Context + ApiService *BmpAPIService + serverId string + type_ string + username string +} + +func (r ApiDeleteServerCredentialRequest) Execute() (*http.Response, error) { + return r.ApiService.DeleteServerCredentialExecute(r) +} + +/* +DeleteServerCredential Delete server credential + +This action is purely administrative and will only remove the username and +password associated with this resource from our database. + + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param serverId The ID of a server + @param type_ Credential type + @param username Username + @return ApiDeleteServerCredentialRequest +*/ +func (a *BmpAPIService) DeleteServerCredential(ctx context.Context, serverId string, type_ string, username string) ApiDeleteServerCredentialRequest { + return ApiDeleteServerCredentialRequest{ + ApiService: a, + ctx: ctx, + serverId: serverId, + type_: type_, + username: username, + } +} + +// Execute executes the request +func (a *BmpAPIService) DeleteServerCredentialExecute(r ApiDeleteServerCredentialRequest) (*http.Response, error) { + var ( + localVarHTTPMethod = http.MethodDelete + localVarPostBody interface{} + formFiles []formFile + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "BmpAPIService.DeleteServerCredential") + if err != nil { + return nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/servers/{serverId}/credentials/{type}/{username}" + localVarPath = strings.Replace(localVarPath, "{"+"serverId"+"}", url.PathEscape(parameterValueToString(r.serverId, "serverId")), -1) + localVarPath = strings.Replace(localVarPath, "{"+"type"+"}", url.PathEscape(parameterValueToString(r.type_, "type_")), -1) + localVarPath = strings.Replace(localVarPath, "{"+"username"+"}", url.PathEscape(parameterValueToString(r.username, "username")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarHTTPResponse, newErr + } + + return localVarHTTPResponse, nil +} + +type ApiEnableServerRescueModeRequest struct { + ctx context.Context + ApiService *BmpAPIService + serverId string + enableServerRescueModeOpts *EnableServerRescueModeOpts +} + +func (r ApiEnableServerRescueModeRequest) EnableServerRescueModeOpts(enableServerRescueModeOpts EnableServerRescueModeOpts) ApiEnableServerRescueModeRequest { + r.enableServerRescueModeOpts = &enableServerRescueModeOpts + return r +} + +func (r ApiEnableServerRescueModeRequest) Execute() (*ServerJob, *http.Response, error) { + return r.ApiService.EnableServerRescueModeExecute(r) +} + +/* +EnableServerRescueMode Launch rescue mode + +Rescue mode allows you to trouble shoot your server in case your installed +operating system is no longer reachable. + +You can supply a `postInstallScript` key in the body of the request which +should contain a base64 encoded string with a valid script. This script will +be executed as soon as rescue mode is launched and can be used to further +automate the process. A requirement for the post install script is that it +starts with a shebang line like `#!/usr/bin/env bash`. + +After a rescue mode is launched you can manually reboot the server. After this +reboot the server will boot into the existing operating system. + +To get a list of available rescue images, you could do so by sending a `GET` +request to `/bareMetals/v2/rescueImages`. + + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param serverId The ID of a server + @return ApiEnableServerRescueModeRequest +*/ +func (a *BmpAPIService) EnableServerRescueMode(ctx context.Context, serverId string) ApiEnableServerRescueModeRequest { + return ApiEnableServerRescueModeRequest{ + ApiService: a, + ctx: ctx, + serverId: serverId, + } +} + +// Execute executes the request +// @return ServerJob +func (a *BmpAPIService) EnableServerRescueModeExecute(r ApiEnableServerRescueModeRequest) (*ServerJob, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodPost + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *ServerJob + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "BmpAPIService.EnableServerRescueMode") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/servers/{serverId}/rescueMode" + localVarPath = strings.Replace(localVarPath, "{"+"serverId"+"}", url.PathEscape(parameterValueToString(r.serverId, "serverId")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{"application/json"} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + // body params + localVarPostBody = r.enableServerRescueModeOpts + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiExpireActiveJobRequest struct { + ctx context.Context + ApiService *BmpAPIService + serverId string +} + +func (r ApiExpireActiveJobRequest) Execute() (*ServerJob, *http.Response, error) { + return r.ApiService.ExpireActiveJobExecute(r) +} + +/* +ExpireActiveJob Expire active job + +Expiring an active job will not have any influence on the current state of the +server and is merely an administrative action. + +Often you want to `cancel` the job, resulting in a server reboot. In that +case\nuse the `/cancelActiveJob` API call instead. + + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param serverId The ID of a server + @return ApiExpireActiveJobRequest +*/ +func (a *BmpAPIService) ExpireActiveJob(ctx context.Context, serverId string) ApiExpireActiveJobRequest { + return ApiExpireActiveJobRequest{ + ApiService: a, + ctx: ctx, + serverId: serverId, + } +} + +// Execute executes the request +// @return ServerJob +func (a *BmpAPIService) ExpireActiveJobExecute(r ApiExpireActiveJobRequest) (*ServerJob, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodPost + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *ServerJob + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "BmpAPIService.ExpireActiveJob") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/servers/{serverId}/expireActiveJob" + localVarPath = strings.Replace(localVarPath, "{"+"serverId"+"}", url.PathEscape(parameterValueToString(r.serverId, "serverId")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiGetControlPanelListRequest struct { + ctx context.Context + ApiService *BmpAPIService + limit *int32 + offset *int32 +} + +// Limit the number of results returned. +func (r ApiGetControlPanelListRequest) Limit(limit int32) ApiGetControlPanelListRequest { + r.limit = &limit + return r +} + +// Return results starting from the given offset. +func (r ApiGetControlPanelListRequest) Offset(offset int32) ApiGetControlPanelListRequest { + r.offset = &offset + return r +} + +func (r ApiGetControlPanelListRequest) Execute() (*ControlPanelList, *http.Response, error) { + return r.ApiService.GetControlPanelListExecute(r) +} + +/* +GetControlPanelList List control panels + +An `id` of a control panel can be supplied when (re)installing a dedicated +server (for more information on how to install dedicated servers via the API +refer to the API documentation). + + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @return ApiGetControlPanelListRequest +*/ +func (a *BmpAPIService) GetControlPanelList(ctx context.Context) ApiGetControlPanelListRequest { + return ApiGetControlPanelListRequest{ + ApiService: a, + ctx: ctx, + } +} + +// Execute executes the request +// @return ControlPanelList +func (a *BmpAPIService) GetControlPanelListExecute(r ApiGetControlPanelListRequest) (*ControlPanelList, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodGet + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *ControlPanelList + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "BmpAPIService.GetControlPanelList") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/controlPanels" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + if r.limit != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "limit", r.limit, "") + } + if r.offset != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "offset", r.offset, "") + } + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiGetControlPanelListByOperatingSystemRequest struct { + ctx context.Context + ApiService *BmpAPIService + operatingSystemId string + limit *int32 + offset *int32 +} + +// Limit the number of results returned. +func (r ApiGetControlPanelListByOperatingSystemRequest) Limit(limit int32) ApiGetControlPanelListByOperatingSystemRequest { + r.limit = &limit + return r +} + +// Return results starting from the given offset. +func (r ApiGetControlPanelListByOperatingSystemRequest) Offset(offset int32) ApiGetControlPanelListByOperatingSystemRequest { + r.offset = &offset + return r +} + +func (r ApiGetControlPanelListByOperatingSystemRequest) Execute() (*ControlPanelList, *http.Response, error) { + return r.ApiService.GetControlPanelListByOperatingSystemExecute(r) +} + +/* +GetControlPanelListByOperatingSystem List control panels + +An `id` of a control panel can be supplied when (re)installing a dedicated +server (for more information on how to install dedicated servers via the API +refer to the API documentation). + +Not all operating systems support all control panels. Some operating systems +do not allow for installation of a control panel. To filter the list of +control panels which are supported for an operating system use the +`operatingSystemId` query string parameter to filter this list. + + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param operatingSystemId Operating system ID + @return ApiGetControlPanelListByOperatingSystemRequest +*/ +func (a *BmpAPIService) GetControlPanelListByOperatingSystem(ctx context.Context, operatingSystemId string) ApiGetControlPanelListByOperatingSystemRequest { + return ApiGetControlPanelListByOperatingSystemRequest{ + ApiService: a, + ctx: ctx, + operatingSystemId: operatingSystemId, + } +} + +// Execute executes the request +// @return ControlPanelList +func (a *BmpAPIService) GetControlPanelListByOperatingSystemExecute(r ApiGetControlPanelListByOperatingSystemRequest) (*ControlPanelList, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodGet + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *ControlPanelList + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "BmpAPIService.GetControlPanelListByOperatingSystem") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/operatingSystems/{operatingSystemId}/controlPanels" + localVarPath = strings.Replace(localVarPath, "{"+"operatingSystemId"+"}", url.PathEscape(parameterValueToString(r.operatingSystemId, "operatingSystemId")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + if r.limit != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "limit", r.limit, "") + } + if r.offset != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "offset", r.offset, "") + } + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiGetNetworkEquipmentCredentialListByTypeRequest struct { + ctx context.Context + ApiService *BmpAPIService + networkEquipmentId string + type_ string + limit *int32 + offset *int32 +} + +// Limit the number of results returned. +func (r ApiGetNetworkEquipmentCredentialListByTypeRequest) Limit(limit int32) ApiGetNetworkEquipmentCredentialListByTypeRequest { + r.limit = &limit + return r +} + +// Return results starting from the given offset. +func (r ApiGetNetworkEquipmentCredentialListByTypeRequest) Offset(offset int32) ApiGetNetworkEquipmentCredentialListByTypeRequest { + r.offset = &offset + return r +} + +func (r ApiGetNetworkEquipmentCredentialListByTypeRequest) Execute() (*CredentialList, *http.Response, error) { + return r.ApiService.GetNetworkEquipmentCredentialListByTypeExecute(r) +} + +/* +GetNetworkEquipmentCredentialListByType List credentials by type + +List all the credentials filtered by the specified type that are associated +with this network equipment. + + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param networkEquipmentId The ID of a dedicated network equipment + @param type_ Credential type + @return ApiGetNetworkEquipmentCredentialListByTypeRequest +*/ +func (a *BmpAPIService) GetNetworkEquipmentCredentialListByType(ctx context.Context, networkEquipmentId string, type_ string) ApiGetNetworkEquipmentCredentialListByTypeRequest { + return ApiGetNetworkEquipmentCredentialListByTypeRequest{ + ApiService: a, + ctx: ctx, + networkEquipmentId: networkEquipmentId, + type_: type_, + } +} + +// Execute executes the request +// @return CredentialList +func (a *BmpAPIService) GetNetworkEquipmentCredentialListByTypeExecute(r ApiGetNetworkEquipmentCredentialListByTypeRequest) (*CredentialList, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodGet + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *CredentialList + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "BmpAPIService.GetNetworkEquipmentCredentialListByType") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/networkEquipments/{networkEquipmentId}/credentials/{type}" + localVarPath = strings.Replace(localVarPath, "{"+"networkEquipmentId"+"}", url.PathEscape(parameterValueToString(r.networkEquipmentId, "networkEquipmentId")), -1) + localVarPath = strings.Replace(localVarPath, "{"+"type"+"}", url.PathEscape(parameterValueToString(r.type_, "type_")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + if r.limit != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "limit", r.limit, "") + } + if r.offset != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "offset", r.offset, "") + } + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiGetNetworkEquipmentPowerStatusRequest struct { + ctx context.Context + ApiService *BmpAPIService + networkEquipmentId string +} + +func (r ApiGetNetworkEquipmentPowerStatusRequest) Execute() (*GetNetworkEquipmentPowerStatusResult, *http.Response, error) { + return r.ApiService.GetNetworkEquipmentPowerStatusExecute(r) +} + +/* +GetNetworkEquipmentPowerStatus Show power status + +The network equipment can either be `ON` or `OFF`. Network Equipment can be +powered on or off by using the respective `/powerOn` and `/powerOff` API +calls. In addition network equipment can also be rebooted using the +`/powerCycle` API call. + +The `pdu` object describes the power status from the power distribution unit +(PDU) point of view. If your network equipment is connected to multiple PDU +ports the `status` property will report `on` if at least one PDU port has +power. + + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param networkEquipmentId The ID of a dedicated network equipment + @return ApiGetNetworkEquipmentPowerStatusRequest +*/ +func (a *BmpAPIService) GetNetworkEquipmentPowerStatus(ctx context.Context, networkEquipmentId string) ApiGetNetworkEquipmentPowerStatusRequest { + return ApiGetNetworkEquipmentPowerStatusRequest{ + ApiService: a, + ctx: ctx, + networkEquipmentId: networkEquipmentId, + } +} + +// Execute executes the request +// @return GetNetworkEquipmentPowerStatusResult +func (a *BmpAPIService) GetNetworkEquipmentPowerStatusExecute(r ApiGetNetworkEquipmentPowerStatusRequest) (*GetNetworkEquipmentPowerStatusResult, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodGet + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *GetNetworkEquipmentPowerStatusResult + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "BmpAPIService.GetNetworkEquipmentPowerStatus") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/networkEquipments/{networkEquipmentId}/powerInfo" + localVarPath = strings.Replace(localVarPath, "{"+"networkEquipmentId"+"}", url.PathEscape(parameterValueToString(r.networkEquipmentId, "networkEquipmentId")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiGetOperatingSystemRequest struct { + ctx context.Context + ApiService *BmpAPIService + operatingSystemId string + controlPanelId *string +} + +// The Control Panel ID +func (r ApiGetOperatingSystemRequest) ControlPanelId(controlPanelId string) ApiGetOperatingSystemRequest { + r.controlPanelId = &controlPanelId + return r +} + +func (r ApiGetOperatingSystemRequest) Execute() (*GetOperatingSystemResult, *http.Response, error) { + return r.ApiService.GetOperatingSystemExecute(r) +} + +/* +GetOperatingSystem Show an operating system + +This detailed information shows default options when installing the given +operating system on a dedicated server. + +For some operating systems these defaults can be adjusted when making the +`POST` request to `/install`. If the `configurable` parameter is `true` these +defaults can be adjusted by the client. + + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param operatingSystemId Operating system ID + @return ApiGetOperatingSystemRequest +*/ +func (a *BmpAPIService) GetOperatingSystem(ctx context.Context, operatingSystemId string) ApiGetOperatingSystemRequest { + return ApiGetOperatingSystemRequest{ + ApiService: a, + ctx: ctx, + operatingSystemId: operatingSystemId, + } +} + +// Execute executes the request +// @return GetOperatingSystemResult +func (a *BmpAPIService) GetOperatingSystemExecute(r ApiGetOperatingSystemRequest) (*GetOperatingSystemResult, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodGet + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *GetOperatingSystemResult + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "BmpAPIService.GetOperatingSystem") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/operatingSystems/{operatingSystemId}" + localVarPath = strings.Replace(localVarPath, "{"+"operatingSystemId"+"}", url.PathEscape(parameterValueToString(r.operatingSystemId, "operatingSystemId")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + if r.controlPanelId == nil { + return localVarReturnValue, nil, reportError("controlPanelId is required and must be specified") + } + + parameterAddToHeaderOrQuery(localVarQueryParams, "controlPanelId", r.controlPanelId, "") + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiGetOperatingSystemListRequest struct { + ctx context.Context + ApiService *BmpAPIService + limit *int32 + offset *int32 + controlPanelId *string +} + +// Limit the number of results returned. +func (r ApiGetOperatingSystemListRequest) Limit(limit int32) ApiGetOperatingSystemListRequest { + r.limit = &limit + return r +} + +// Return results starting from the given offset. +func (r ApiGetOperatingSystemListRequest) Offset(offset int32) ApiGetOperatingSystemListRequest { + r.offset = &offset + return r +} + +// Filter operating systems by control panel id +func (r ApiGetOperatingSystemListRequest) ControlPanelId(controlPanelId string) ApiGetOperatingSystemListRequest { + r.controlPanelId = &controlPanelId + return r +} + +func (r ApiGetOperatingSystemListRequest) Execute() (*GetOperatingSystemListResult, *http.Response, error) { + return r.ApiService.GetOperatingSystemListExecute(r) +} + +/* +GetOperatingSystemList List Operating Systems + +An `id` of a operating system can be supplied when (re)installing a dedicated +server (for more information on how to install dedicated servers via the API +refer to the API documentation). + + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @return ApiGetOperatingSystemListRequest +*/ +func (a *BmpAPIService) GetOperatingSystemList(ctx context.Context) ApiGetOperatingSystemListRequest { + return ApiGetOperatingSystemListRequest{ + ApiService: a, + ctx: ctx, + } +} + +// Execute executes the request +// @return GetOperatingSystemListResult +func (a *BmpAPIService) GetOperatingSystemListExecute(r ApiGetOperatingSystemListRequest) (*GetOperatingSystemListResult, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodGet + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *GetOperatingSystemListResult + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "BmpAPIService.GetOperatingSystemList") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/operatingSystems" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + if r.limit != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "limit", r.limit, "") + } + if r.offset != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "offset", r.offset, "") + } + if r.controlPanelId != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "controlPanelId", r.controlPanelId, "") + } + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiGetRescueImageListRequest struct { + ctx context.Context + ApiService *BmpAPIService + limit *int32 + offset *int32 +} + +// Limit the number of results returned. +func (r ApiGetRescueImageListRequest) Limit(limit int32) ApiGetRescueImageListRequest { + r.limit = &limit + return r +} + +// Return results starting from the given offset. +func (r ApiGetRescueImageListRequest) Offset(offset int32) ApiGetRescueImageListRequest { + r.offset = &offset + return r +} + +func (r ApiGetRescueImageListRequest) Execute() (*GetRescueImageListResult, *http.Response, error) { + return r.ApiService.GetRescueImageListExecute(r) +} + +/* +GetRescueImageList Rescue Images + +Lists all Rescue Images which are available for launching a dedicated server +into rescue mode. + +A `rescueImageId` can be supplied to the `POST /rescueMode` API call and will +reboot your server into rescue mode. + +Launching rescue mode for a server is often used to troubleshoot an existing +installation. + +Note that launching rescue mode does not modify any data on the disks of your +server. It will require your server to be rebooted. + + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @return ApiGetRescueImageListRequest +*/ +func (a *BmpAPIService) GetRescueImageList(ctx context.Context) ApiGetRescueImageListRequest { + return ApiGetRescueImageListRequest{ + ApiService: a, + ctx: ctx, + } +} + +// Execute executes the request +// @return GetRescueImageListResult +func (a *BmpAPIService) GetRescueImageListExecute(r ApiGetRescueImageListRequest) (*GetRescueImageListResult, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodGet + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *GetRescueImageListResult + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "BmpAPIService.GetRescueImageList") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/rescueImages" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + if r.limit != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "limit", r.limit, "") + } + if r.offset != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "offset", r.offset, "") + } + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiGetServerCredentialListRequest struct { + ctx context.Context + ApiService *BmpAPIService + serverId string + limit *int32 + offset *int32 +} + +// Limit the number of results returned. +func (r ApiGetServerCredentialListRequest) Limit(limit int32) ApiGetServerCredentialListRequest { + r.limit = &limit + return r +} + +// Return results starting from the given offset. +func (r ApiGetServerCredentialListRequest) Offset(offset int32) ApiGetServerCredentialListRequest { + r.offset = &offset + return r +} + +func (r ApiGetServerCredentialListRequest) Execute() (*CredentialList, *http.Response, error) { + return r.ApiService.GetServerCredentialListExecute(r) +} + +/* +GetServerCredentialList List credentials + +The credentials API allows you to store usernames and passwords securely. + +During (re)installations, rescue modes and ipmi resets the newly generated +passwords are stored and can be retrieved using this API. + + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param serverId The ID of a server + @return ApiGetServerCredentialListRequest +*/ +func (a *BmpAPIService) GetServerCredentialList(ctx context.Context, serverId string) ApiGetServerCredentialListRequest { + return ApiGetServerCredentialListRequest{ + ApiService: a, + ctx: ctx, + serverId: serverId, + } +} + +// Execute executes the request +// @return CredentialList +func (a *BmpAPIService) GetServerCredentialListExecute(r ApiGetServerCredentialListRequest) (*CredentialList, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodGet + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *CredentialList + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "BmpAPIService.GetServerCredentialList") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/servers/{serverId}/credentials" + localVarPath = strings.Replace(localVarPath, "{"+"serverId"+"}", url.PathEscape(parameterValueToString(r.serverId, "serverId")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + if r.limit != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "limit", r.limit, "") + } + if r.offset != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "offset", r.offset, "") + } + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiGetServerDhcpReservationListRequest struct { + ctx context.Context + ApiService *BmpAPIService + serverId string +} + +func (r ApiGetServerDhcpReservationListRequest) Execute() (*GetServerDhcpReservationListResult, *http.Response, error) { + return r.ApiService.GetServerDhcpReservationListExecute(r) +} + +/* +GetServerDhcpReservationList List DHCP reservations + +Please note that this will only show reservations for the public network +interface. + + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param serverId The ID of a server + @return ApiGetServerDhcpReservationListRequest +*/ +func (a *BmpAPIService) GetServerDhcpReservationList(ctx context.Context, serverId string) ApiGetServerDhcpReservationListRequest { + return ApiGetServerDhcpReservationListRequest{ + ApiService: a, + ctx: ctx, + serverId: serverId, + } +} + +// Execute executes the request +// @return GetServerDhcpReservationListResult +func (a *BmpAPIService) GetServerDhcpReservationListExecute(r ApiGetServerDhcpReservationListRequest) (*GetServerDhcpReservationListResult, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodGet + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *GetServerDhcpReservationListResult + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "BmpAPIService.GetServerDhcpReservationList") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/servers/{serverId}/leases" + localVarPath = strings.Replace(localVarPath, "{"+"serverId"+"}", url.PathEscape(parameterValueToString(r.serverId, "serverId")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiGetServerJobListRequest struct { + ctx context.Context + ApiService *BmpAPIService + serverId string + limit *int32 + offset *int32 + type_ *string + status *string + isRunning *string +} + +// Limit the number of results returned. +func (r ApiGetServerJobListRequest) Limit(limit int32) ApiGetServerJobListRequest { + r.limit = &limit + return r +} + +// Return results starting from the given offset. +func (r ApiGetServerJobListRequest) Offset(offset int32) ApiGetServerJobListRequest { + r.offset = &offset + return r +} + +// Filter the list of jobs by type. +func (r ApiGetServerJobListRequest) Type_(type_ string) ApiGetServerJobListRequest { + r.type_ = &type_ + return r +} + +// Filter the list of jobs by status. +func (r ApiGetServerJobListRequest) Status(status string) ApiGetServerJobListRequest { + r.status = &status + return r +} + +// Filter the list for running jobs +func (r ApiGetServerJobListRequest) IsRunning(isRunning string) ApiGetServerJobListRequest { + r.isRunning = &isRunning + return r +} + +func (r ApiGetServerJobListRequest) Execute() (*ServerJobList, *http.Response, error) { + return r.ApiService.GetServerJobListExecute(r) +} + +/* +GetServerJobList List jobs + +List all jobs for this server. + + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param serverId The ID of a server + @return ApiGetServerJobListRequest +*/ +func (a *BmpAPIService) GetServerJobList(ctx context.Context, serverId string) ApiGetServerJobListRequest { + return ApiGetServerJobListRequest{ + ApiService: a, + ctx: ctx, + serverId: serverId, + } +} + +// Execute executes the request +// @return ServerJobList +func (a *BmpAPIService) GetServerJobListExecute(r ApiGetServerJobListRequest) (*ServerJobList, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodGet + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *ServerJobList + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "BmpAPIService.GetServerJobList") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/servers/{serverId}/jobs" + localVarPath = strings.Replace(localVarPath, "{"+"serverId"+"}", url.PathEscape(parameterValueToString(r.serverId, "serverId")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + if r.limit != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "limit", r.limit, "") + } + if r.offset != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "offset", r.offset, "") + } + if r.type_ != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "type", r.type_, "") + } + if r.status != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "status", r.status, "") + } + if r.isRunning != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "isRunning", r.isRunning, "") + } + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiGetServerPowerStatusRequest struct { + ctx context.Context + ApiService *BmpAPIService + serverId string +} + +func (r ApiGetServerPowerStatusRequest) Execute() (*GetServerPowerStatusResult, *http.Response, error) { + return r.ApiService.GetServerPowerStatusExecute(r) +} + +/* +GetServerPowerStatus Show power status + +The server can either be `ON` or `OFF`. Servers can be powered on or off by +using the respective `/powerOn` and `/powerOff` API calls. In addition servers +can also be rebooted using the `/powerCycle` API call. + +The `pdu` object describes the power status from the power distribution unit +(PDU) point of view. If your server is connected to multiple PDU ports the +`status` property will report `on` if at least one PDU port has power. + +The `ipmi` object describes the power status by quering the remote management +interface of your server. + +Note that `pdu.status` can report `on` but your server can still be powered +off if it was shutdown via `IPMI` for example. + + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param serverId The ID of a server + @return ApiGetServerPowerStatusRequest +*/ +func (a *BmpAPIService) GetServerPowerStatus(ctx context.Context, serverId string) ApiGetServerPowerStatusRequest { + return ApiGetServerPowerStatusRequest{ + ApiService: a, + ctx: ctx, + serverId: serverId, + } +} + +// Execute executes the request +// @return GetServerPowerStatusResult +func (a *BmpAPIService) GetServerPowerStatusExecute(r ApiGetServerPowerStatusRequest) (*GetServerPowerStatusResult, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodGet + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *GetServerPowerStatusResult + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "BmpAPIService.GetServerPowerStatus") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/servers/{serverId}/powerInfo" + localVarPath = strings.Replace(localVarPath, "{"+"serverId"+"}", url.PathEscape(parameterValueToString(r.serverId, "serverId")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiInstallOperatingSystemRequest struct { + ctx context.Context + ApiService *BmpAPIService + serverId string + installOperatingSystemOpts *InstallOperatingSystemOpts +} + +func (r ApiInstallOperatingSystemRequest) InstallOperatingSystemOpts(installOperatingSystemOpts InstallOperatingSystemOpts) ApiInstallOperatingSystemRequest { + r.installOperatingSystemOpts = &installOperatingSystemOpts + return r +} + +func (r ApiInstallOperatingSystemRequest) Execute() (*ServerJob, *http.Response, error) { + return r.ApiService.InstallOperatingSystemExecute(r) +} + +/* +InstallOperatingSystem Launch installation + +Install your server with an Operating System and optional Control Panel. + +To retrieve a list of available operating systems use the +`/v2/operatingSystems` endpoint. + +To retrieve a list of available control panels use the `/v2/controlPanels` +endpoint. + +The default device / partitions to be used are operating system depended and +can be retrieved via the `/v2/operatingSystems/{operatingSystemId}` endpoint. + +You are now able to target a specific diskset, like SATA1TB, SATA2TB, SSD256GB, +etc. To see which disksets are available in your server check the `/v2/servers/{serverId}` +endpoint and look for the corresponding diskset id from the hdd array. + +For more information about Dedicated Server installation, [click here](https://kb.leaseweb.com/products/dedicated-server/reinstalling-your-dedicated-server) for our related Knowledge Base article. + + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param serverId The ID of a server + @return ApiInstallOperatingSystemRequest +*/ +func (a *BmpAPIService) InstallOperatingSystem(ctx context.Context, serverId string) ApiInstallOperatingSystemRequest { + return ApiInstallOperatingSystemRequest{ + ApiService: a, + ctx: ctx, + serverId: serverId, + } +} + +// Execute executes the request +// @return ServerJob +func (a *BmpAPIService) InstallOperatingSystemExecute(r ApiInstallOperatingSystemRequest) (*ServerJob, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodPost + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *ServerJob + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "BmpAPIService.InstallOperatingSystem") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/servers/{serverId}/install" + localVarPath = strings.Replace(localVarPath, "{"+"serverId"+"}", url.PathEscape(parameterValueToString(r.serverId, "serverId")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{"application/json"} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + // body params + localVarPostBody = r.installOperatingSystemOpts + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiIpmiResetServerRequest struct { + ctx context.Context + ApiService *BmpAPIService + serverId string + ipmiResetServerOpts *IpmiResetServerOpts +} + +func (r ApiIpmiResetServerRequest) IpmiResetServerOpts(ipmiResetServerOpts IpmiResetServerOpts) ApiIpmiResetServerRequest { + r.ipmiResetServerOpts = &ipmiResetServerOpts + return r +} + +func (r ApiIpmiResetServerRequest) Execute() (*ServerJob, *http.Response, error) { + return r.ApiService.IpmiResetServerExecute(r) +} + +/* +IpmiResetServer Launch IPMI reset + +A reset makes sure that your IPMI interface of your server is compatible with +Leaseweb automation. + +An IPMI reset will require a reboot of your server. The contents of your hard +drive won't be altered in any way. After a successful IPMI reset your server +is booted back into the original operating system.", + + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param serverId The ID of a server + @return ApiIpmiResetServerRequest +*/ +func (a *BmpAPIService) IpmiResetServer(ctx context.Context, serverId string) ApiIpmiResetServerRequest { + return ApiIpmiResetServerRequest{ + ApiService: a, + ctx: ctx, + serverId: serverId, + } +} + +// Execute executes the request +// @return ServerJob +func (a *BmpAPIService) IpmiResetServerExecute(r ApiIpmiResetServerRequest) (*ServerJob, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodPost + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *ServerJob + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "BmpAPIService.IpmiResetServer") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/servers/{serverId}/ipmiReset" + localVarPath = strings.Replace(localVarPath, "{"+"serverId"+"}", url.PathEscape(parameterValueToString(r.serverId, "serverId")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{"application/json"} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + // body params + localVarPostBody = r.ipmiResetServerOpts + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiNetworkEquipmentsCredentialsGetRequest struct { + ctx context.Context + ApiService *BmpAPIService + networkEquipmentId string + type_ string + username string +} + +func (r ApiNetworkEquipmentsCredentialsGetRequest) Execute() (*Credential, *http.Response, error) { + return r.ApiService.NetworkEquipmentsCredentialsGetExecute(r) +} + +/* +NetworkEquipmentsCredentialsGet Show user credentials + +View the password for the given credential, identified by `type` and +`username`. + + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param networkEquipmentId The ID of a dedicated network equipment + @param type_ Credential type + @param username Username + @return ApiNetworkEquipmentsCredentialsGetRequest +*/ +func (a *BmpAPIService) NetworkEquipmentsCredentialsGet(ctx context.Context, networkEquipmentId string, type_ string, username string) ApiNetworkEquipmentsCredentialsGetRequest { + return ApiNetworkEquipmentsCredentialsGetRequest{ + ApiService: a, + ctx: ctx, + networkEquipmentId: networkEquipmentId, + type_: type_, + username: username, + } +} + +// Execute executes the request +// @return Credential +func (a *BmpAPIService) NetworkEquipmentsCredentialsGetExecute(r ApiNetworkEquipmentsCredentialsGetRequest) (*Credential, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodGet + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *Credential + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "BmpAPIService.NetworkEquipmentsCredentialsGet") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/networkEquipments/{networkEquipmentId}/credentials/{type}/{username}" + localVarPath = strings.Replace(localVarPath, "{"+"networkEquipmentId"+"}", url.PathEscape(parameterValueToString(r.networkEquipmentId, "networkEquipmentId")), -1) + localVarPath = strings.Replace(localVarPath, "{"+"type"+"}", url.PathEscape(parameterValueToString(r.type_, "type_")), -1) + localVarPath = strings.Replace(localVarPath, "{"+"username"+"}", url.PathEscape(parameterValueToString(r.username, "username")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiNetworkEquipmentsCredentialsListRequest struct { + ctx context.Context + ApiService *BmpAPIService + networkEquipmentId string + limit *int32 + offset *int32 +} + +// Limit the number of results returned. +func (r ApiNetworkEquipmentsCredentialsListRequest) Limit(limit int32) ApiNetworkEquipmentsCredentialsListRequest { + r.limit = &limit + return r +} + +// Return results starting from the given offset. +func (r ApiNetworkEquipmentsCredentialsListRequest) Offset(offset int32) ApiNetworkEquipmentsCredentialsListRequest { + r.offset = &offset + return r +} + +func (r ApiNetworkEquipmentsCredentialsListRequest) Execute() (*CredentialList, *http.Response, error) { + return r.ApiService.NetworkEquipmentsCredentialsListExecute(r) +} + +/* +NetworkEquipmentsCredentialsList List credentials + +The credentials API allows you to store usernames and passwords securely. + + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param networkEquipmentId The ID of a dedicated network equipment + @return ApiNetworkEquipmentsCredentialsListRequest +*/ +func (a *BmpAPIService) NetworkEquipmentsCredentialsList(ctx context.Context, networkEquipmentId string) ApiNetworkEquipmentsCredentialsListRequest { + return ApiNetworkEquipmentsCredentialsListRequest{ + ApiService: a, + ctx: ctx, + networkEquipmentId: networkEquipmentId, + } +} + +// Execute executes the request +// @return CredentialList +func (a *BmpAPIService) NetworkEquipmentsCredentialsListExecute(r ApiNetworkEquipmentsCredentialsListRequest) (*CredentialList, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodGet + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *CredentialList + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "BmpAPIService.NetworkEquipmentsCredentialsList") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/networkEquipments/{networkEquipmentId}/credentials" + localVarPath = strings.Replace(localVarPath, "{"+"networkEquipmentId"+"}", url.PathEscape(parameterValueToString(r.networkEquipmentId, "networkEquipmentId")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + if r.limit != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "limit", r.limit, "") + } + if r.offset != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "offset", r.offset, "") + } + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiNetworkEquipmentsCredentialsPostRequest struct { + ctx context.Context + ApiService *BmpAPIService + networkEquipmentId string + createNetworkEquipmentCredentialOpts *CreateNetworkEquipmentCredentialOpts +} + +func (r ApiNetworkEquipmentsCredentialsPostRequest) CreateNetworkEquipmentCredentialOpts(createNetworkEquipmentCredentialOpts CreateNetworkEquipmentCredentialOpts) ApiNetworkEquipmentsCredentialsPostRequest { + r.createNetworkEquipmentCredentialOpts = &createNetworkEquipmentCredentialOpts + return r +} + +func (r ApiNetworkEquipmentsCredentialsPostRequest) Execute() (*Credential, *http.Response, error) { + return r.ApiService.NetworkEquipmentsCredentialsPostExecute(r) +} + +/* +NetworkEquipmentsCredentialsPost Create new credentials + +Password will NOT be updated on the network equipment. The ability to update +credentials is for convenience only. It provides a secure way to communicate +passwords with Leaseweb engineers in case support is required. + + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param networkEquipmentId The ID of a dedicated network equipment + @return ApiNetworkEquipmentsCredentialsPostRequest +*/ +func (a *BmpAPIService) NetworkEquipmentsCredentialsPost(ctx context.Context, networkEquipmentId string) ApiNetworkEquipmentsCredentialsPostRequest { + return ApiNetworkEquipmentsCredentialsPostRequest{ + ApiService: a, + ctx: ctx, + networkEquipmentId: networkEquipmentId, + } +} + +// Execute executes the request +// @return Credential +func (a *BmpAPIService) NetworkEquipmentsCredentialsPostExecute(r ApiNetworkEquipmentsCredentialsPostRequest) (*Credential, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodPost + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *Credential + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "BmpAPIService.NetworkEquipmentsCredentialsPost") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/networkEquipments/{networkEquipmentId}/credentials" + localVarPath = strings.Replace(localVarPath, "{"+"networkEquipmentId"+"}", url.PathEscape(parameterValueToString(r.networkEquipmentId, "networkEquipmentId")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{"application/json"} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + // body params + localVarPostBody = r.createNetworkEquipmentCredentialOpts + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiPowerCycleNetworkEquipmentRequest struct { + ctx context.Context + ApiService *BmpAPIService + networkEquipmentId string +} + +func (r ApiPowerCycleNetworkEquipmentRequest) Execute() (*http.Response, error) { + return r.ApiService.PowerCycleNetworkEquipmentExecute(r) +} + +/* +PowerCycleNetworkEquipment Power cycle a network equipment + +Powercyle the network equipment. + + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param networkEquipmentId The ID of a dedicated network equipment + @return ApiPowerCycleNetworkEquipmentRequest +*/ +func (a *BmpAPIService) PowerCycleNetworkEquipment(ctx context.Context, networkEquipmentId string) ApiPowerCycleNetworkEquipmentRequest { + return ApiPowerCycleNetworkEquipmentRequest{ + ApiService: a, + ctx: ctx, + networkEquipmentId: networkEquipmentId, + } +} + +// Execute executes the request +func (a *BmpAPIService) PowerCycleNetworkEquipmentExecute(r ApiPowerCycleNetworkEquipmentRequest) (*http.Response, error) { + var ( + localVarHTTPMethod = http.MethodPost + localVarPostBody interface{} + formFiles []formFile + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "BmpAPIService.PowerCycleNetworkEquipment") + if err != nil { + return nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/networkEquipments/{networkEquipmentId}/powerCycle" + localVarPath = strings.Replace(localVarPath, "{"+"networkEquipmentId"+"}", url.PathEscape(parameterValueToString(r.networkEquipmentId, "networkEquipmentId")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarHTTPResponse, newErr + } + + return localVarHTTPResponse, nil +} + +type ApiPowerCycleServerRequest struct { + ctx context.Context + ApiService *BmpAPIService + serverId string +} + +func (r ApiPowerCycleServerRequest) Execute() (*http.Response, error) { + return r.ApiService.PowerCycleServerExecute(r) +} + +/* +PowerCycleServer Power cycle a server + +Powercyle the server. + + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param serverId The ID of a server + @return ApiPowerCycleServerRequest +*/ +func (a *BmpAPIService) PowerCycleServer(ctx context.Context, serverId string) ApiPowerCycleServerRequest { + return ApiPowerCycleServerRequest{ + ApiService: a, + ctx: ctx, + serverId: serverId, + } +} + +// Execute executes the request +func (a *BmpAPIService) PowerCycleServerExecute(r ApiPowerCycleServerRequest) (*http.Response, error) { + var ( + localVarHTTPMethod = http.MethodPost + localVarPostBody interface{} + formFiles []formFile + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "BmpAPIService.PowerCycleServer") + if err != nil { + return nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/servers/{serverId}/powerCycle" + localVarPath = strings.Replace(localVarPath, "{"+"serverId"+"}", url.PathEscape(parameterValueToString(r.serverId, "serverId")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarHTTPResponse, newErr + } + + return localVarHTTPResponse, nil +} + +type ApiPowerNetworkEquipmentOffRequest struct { + ctx context.Context + ApiService *BmpAPIService + networkEquipmentId string +} + +func (r ApiPowerNetworkEquipmentOffRequest) Execute() (*http.Response, error) { + return r.ApiService.PowerNetworkEquipmentOffExecute(r) +} + +/* +PowerNetworkEquipmentOff Power off network equipment + +Power off the given network equipment. + + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param networkEquipmentId The ID of a dedicated network equipment + @return ApiPowerNetworkEquipmentOffRequest +*/ +func (a *BmpAPIService) PowerNetworkEquipmentOff(ctx context.Context, networkEquipmentId string) ApiPowerNetworkEquipmentOffRequest { + return ApiPowerNetworkEquipmentOffRequest{ + ApiService: a, + ctx: ctx, + networkEquipmentId: networkEquipmentId, + } +} + +// Execute executes the request +func (a *BmpAPIService) PowerNetworkEquipmentOffExecute(r ApiPowerNetworkEquipmentOffRequest) (*http.Response, error) { + var ( + localVarHTTPMethod = http.MethodPost + localVarPostBody interface{} + formFiles []formFile + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "BmpAPIService.PowerNetworkEquipmentOff") + if err != nil { + return nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/networkEquipments/{networkEquipmentId}/powerOff" + localVarPath = strings.Replace(localVarPath, "{"+"networkEquipmentId"+"}", url.PathEscape(parameterValueToString(r.networkEquipmentId, "networkEquipmentId")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarHTTPResponse, newErr + } + + return localVarHTTPResponse, nil +} + +type ApiPowerNetworkEquipmentOnRequest struct { + ctx context.Context + ApiService *BmpAPIService + networkEquipmentId string +} + +func (r ApiPowerNetworkEquipmentOnRequest) Execute() (*http.Response, error) { + return r.ApiService.PowerNetworkEquipmentOnExecute(r) +} + +/* +PowerNetworkEquipmentOn Power on network equipment + +Power on the given network equipment. + + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param networkEquipmentId The ID of a dedicated network equipment + @return ApiPowerNetworkEquipmentOnRequest +*/ +func (a *BmpAPIService) PowerNetworkEquipmentOn(ctx context.Context, networkEquipmentId string) ApiPowerNetworkEquipmentOnRequest { + return ApiPowerNetworkEquipmentOnRequest{ + ApiService: a, + ctx: ctx, + networkEquipmentId: networkEquipmentId, + } +} + +// Execute executes the request +func (a *BmpAPIService) PowerNetworkEquipmentOnExecute(r ApiPowerNetworkEquipmentOnRequest) (*http.Response, error) { + var ( + localVarHTTPMethod = http.MethodPost + localVarPostBody interface{} + formFiles []formFile + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "BmpAPIService.PowerNetworkEquipmentOn") + if err != nil { + return nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/networkEquipments/{networkEquipmentId}/powerOn" + localVarPath = strings.Replace(localVarPath, "{"+"networkEquipmentId"+"}", url.PathEscape(parameterValueToString(r.networkEquipmentId, "networkEquipmentId")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarHTTPResponse, newErr + } + + return localVarHTTPResponse, nil +} + +type ApiPowerServerOffRequest struct { + ctx context.Context + ApiService *BmpAPIService + serverId string +} + +func (r ApiPowerServerOffRequest) Execute() (*http.Response, error) { + return r.ApiService.PowerServerOffExecute(r) +} + +/* +PowerServerOff Power off server + +Power off the given server. + + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param serverId The ID of a server + @return ApiPowerServerOffRequest +*/ +func (a *BmpAPIService) PowerServerOff(ctx context.Context, serverId string) ApiPowerServerOffRequest { + return ApiPowerServerOffRequest{ + ApiService: a, + ctx: ctx, + serverId: serverId, + } +} + +// Execute executes the request +func (a *BmpAPIService) PowerServerOffExecute(r ApiPowerServerOffRequest) (*http.Response, error) { + var ( + localVarHTTPMethod = http.MethodPost + localVarPostBody interface{} + formFiles []formFile + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "BmpAPIService.PowerServerOff") + if err != nil { + return nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/servers/{serverId}/powerOff" + localVarPath = strings.Replace(localVarPath, "{"+"serverId"+"}", url.PathEscape(parameterValueToString(r.serverId, "serverId")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarHTTPResponse, newErr + } + + return localVarHTTPResponse, nil +} + +type ApiPowerServerOnRequest struct { + ctx context.Context + ApiService *BmpAPIService + serverId string +} + +func (r ApiPowerServerOnRequest) Execute() (*http.Response, error) { + return r.ApiService.PowerServerOnExecute(r) +} + +/* +PowerServerOn Power on server + +Power on the given server. + + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param serverId The ID of a server + @return ApiPowerServerOnRequest +*/ +func (a *BmpAPIService) PowerServerOn(ctx context.Context, serverId string) ApiPowerServerOnRequest { + return ApiPowerServerOnRequest{ + ApiService: a, + ctx: ctx, + serverId: serverId, + } +} + +// Execute executes the request +func (a *BmpAPIService) PowerServerOnExecute(r ApiPowerServerOnRequest) (*http.Response, error) { + var ( + localVarHTTPMethod = http.MethodPost + localVarPostBody interface{} + formFiles []formFile + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "BmpAPIService.PowerServerOn") + if err != nil { + return nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/servers/{serverId}/powerOn" + localVarPath = strings.Replace(localVarPath, "{"+"serverId"+"}", url.PathEscape(parameterValueToString(r.serverId, "serverId")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarHTTPResponse, newErr + } + + return localVarHTTPResponse, nil +} + +type ApiRetryServerJobRequest struct { + ctx context.Context + ApiService *BmpAPIService + serverId string + jobId string +} + +func (r ApiRetryServerJobRequest) Execute() (*ServerJob, *http.Response, error) { + return r.ApiService.RetryServerJobExecute(r) +} + +/* +RetryServerJob Retry a job + +Retry a job for a specific server. + + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param serverId The ID of a server + @param jobId The ID of a Job + @return ApiRetryServerJobRequest +*/ +func (a *BmpAPIService) RetryServerJob(ctx context.Context, serverId string, jobId string) ApiRetryServerJobRequest { + return ApiRetryServerJobRequest{ + ApiService: a, + ctx: ctx, + serverId: serverId, + jobId: jobId, + } +} + +// Execute executes the request +// @return ServerJob +func (a *BmpAPIService) RetryServerJobExecute(r ApiRetryServerJobRequest) (*ServerJob, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodPost + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *ServerJob + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "BmpAPIService.RetryServerJob") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/servers/{serverId}/jobs/{jobId}/retry" + localVarPath = strings.Replace(localVarPath, "{"+"serverId"+"}", url.PathEscape(parameterValueToString(r.serverId, "serverId")), -1) + localVarPath = strings.Replace(localVarPath, "{"+"jobId"+"}", url.PathEscape(parameterValueToString(r.jobId, "jobId")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 404 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiScanHardwareRequest struct { + ctx context.Context + ApiService *BmpAPIService + serverId string + scanHardwareOpts *ScanHardwareOpts +} + +func (r ApiScanHardwareRequest) ScanHardwareOpts(scanHardwareOpts ScanHardwareOpts) ApiScanHardwareRequest { + r.scanHardwareOpts = &scanHardwareOpts + return r +} + +func (r ApiScanHardwareRequest) Execute() (*ServerJob, *http.Response, error) { + return r.ApiService.ScanHardwareExecute(r) +} + +/* +ScanHardware Launch hardware scan + +A hardware scan collects hardware related information from your server. + +A hardware scan will require a reboot of your server. The contents of your +hard drive won't be altered in any way. After a successful hardware scan your +server is booted back into the original operating system. + + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param serverId The ID of a server + @return ApiScanHardwareRequest +*/ +func (a *BmpAPIService) ScanHardware(ctx context.Context, serverId string) ApiScanHardwareRequest { + return ApiScanHardwareRequest{ + ApiService: a, + ctx: ctx, + serverId: serverId, + } +} + +// Execute executes the request +// @return ServerJob +func (a *BmpAPIService) ScanHardwareExecute(r ApiScanHardwareRequest) (*ServerJob, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodPost + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *ServerJob + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "BmpAPIService.ScanHardware") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/servers/{serverId}/hardwareScan" + localVarPath = strings.Replace(localVarPath, "{"+"serverId"+"}", url.PathEscape(parameterValueToString(r.serverId, "serverId")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{"application/json"} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + // body params + localVarPostBody = r.scanHardwareOpts + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiServersCredentialsGetRequest struct { + ctx context.Context + ApiService *BmpAPIService + serverId string + type_ string + username string +} + +func (r ApiServersCredentialsGetRequest) Execute() (*Credential, *http.Response, error) { + return r.ApiService.ServersCredentialsGetExecute(r) +} + +/* +ServersCredentialsGet Show user credentials + +View the password for the given credential, identified by `type` and +`username`. Auto generated credentials (during a re-install, rescue mode or +ipmi reset can be found here). + + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param serverId The ID of a server + @param type_ Credential type + @param username Username + @return ApiServersCredentialsGetRequest +*/ +func (a *BmpAPIService) ServersCredentialsGet(ctx context.Context, serverId string, type_ string, username string) ApiServersCredentialsGetRequest { + return ApiServersCredentialsGetRequest{ + ApiService: a, + ctx: ctx, + serverId: serverId, + type_: type_, + username: username, + } +} + +// Execute executes the request +// @return Credential +func (a *BmpAPIService) ServersCredentialsGetExecute(r ApiServersCredentialsGetRequest) (*Credential, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodGet + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *Credential + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "BmpAPIService.ServersCredentialsGet") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/servers/{serverId}/credentials/{type}/{username}" + localVarPath = strings.Replace(localVarPath, "{"+"serverId"+"}", url.PathEscape(parameterValueToString(r.serverId, "serverId")), -1) + localVarPath = strings.Replace(localVarPath, "{"+"type"+"}", url.PathEscape(parameterValueToString(r.type_, "type_")), -1) + localVarPath = strings.Replace(localVarPath, "{"+"username"+"}", url.PathEscape(parameterValueToString(r.username, "username")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiServersCredentialsListTypeRequest struct { + ctx context.Context + ApiService *BmpAPIService + serverId string + type_ string + limit *int32 + offset *int32 +} + +// Limit the number of results returned. +func (r ApiServersCredentialsListTypeRequest) Limit(limit int32) ApiServersCredentialsListTypeRequest { + r.limit = &limit + return r +} + +// Return results starting from the given offset. +func (r ApiServersCredentialsListTypeRequest) Offset(offset int32) ApiServersCredentialsListTypeRequest { + r.offset = &offset + return r +} + +func (r ApiServersCredentialsListTypeRequest) Execute() (*CredentialList, *http.Response, error) { + return r.ApiService.ServersCredentialsListTypeExecute(r) +} + +/* +ServersCredentialsListType List credentials by type + +List all the credentials filtered by the specified type that are associated +with this server. + + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param serverId The ID of a server + @param type_ Credential type + @return ApiServersCredentialsListTypeRequest +*/ +func (a *BmpAPIService) ServersCredentialsListType(ctx context.Context, serverId string, type_ string) ApiServersCredentialsListTypeRequest { + return ApiServersCredentialsListTypeRequest{ + ApiService: a, + ctx: ctx, + serverId: serverId, + type_: type_, + } +} + +// Execute executes the request +// @return CredentialList +func (a *BmpAPIService) ServersCredentialsListTypeExecute(r ApiServersCredentialsListTypeRequest) (*CredentialList, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodGet + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *CredentialList + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "BmpAPIService.ServersCredentialsListType") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/servers/{serverId}/credentials/{type}" + localVarPath = strings.Replace(localVarPath, "{"+"serverId"+"}", url.PathEscape(parameterValueToString(r.serverId, "serverId")), -1) + localVarPath = strings.Replace(localVarPath, "{"+"type"+"}", url.PathEscape(parameterValueToString(r.type_, "type_")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + if r.limit != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "limit", r.limit, "") + } + if r.offset != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "offset", r.offset, "") + } + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiServersCredentialsPutRequest struct { + ctx context.Context + ApiService *BmpAPIService + serverId string + type_ string + username string + updateServerCredentialOpts *UpdateServerCredentialOpts +} + +func (r ApiServersCredentialsPutRequest) UpdateServerCredentialOpts(updateServerCredentialOpts UpdateServerCredentialOpts) ApiServersCredentialsPutRequest { + r.updateServerCredentialOpts = &updateServerCredentialOpts + return r +} + +func (r ApiServersCredentialsPutRequest) Execute() (*Credential, *http.Response, error) { + return r.ApiService.ServersCredentialsPutExecute(r) +} + +/* +ServersCredentialsPut Update user credentials + +The usernames or types cannot be changed. In order to change those remove this +credentials and create a new one. + +This action is purely administrative and will only update the password +associated with this resource in our database. + + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param serverId The ID of a server + @param type_ Credential type + @param username Username + @return ApiServersCredentialsPutRequest +*/ +func (a *BmpAPIService) ServersCredentialsPut(ctx context.Context, serverId string, type_ string, username string) ApiServersCredentialsPutRequest { + return ApiServersCredentialsPutRequest{ + ApiService: a, + ctx: ctx, + serverId: serverId, + type_: type_, + username: username, + } +} + +// Execute executes the request +// @return Credential +func (a *BmpAPIService) ServersCredentialsPutExecute(r ApiServersCredentialsPutRequest) (*Credential, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodPut + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *Credential + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "BmpAPIService.ServersCredentialsPut") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/servers/{serverId}/credentials/{type}/{username}" + localVarPath = strings.Replace(localVarPath, "{"+"serverId"+"}", url.PathEscape(parameterValueToString(r.serverId, "serverId")), -1) + localVarPath = strings.Replace(localVarPath, "{"+"type"+"}", url.PathEscape(parameterValueToString(r.type_, "type_")), -1) + localVarPath = strings.Replace(localVarPath, "{"+"username"+"}", url.PathEscape(parameterValueToString(r.username, "username")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{"application/json"} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + // body params + localVarPostBody = r.updateServerCredentialOpts + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiServersJobsGetRequest struct { + ctx context.Context + ApiService *BmpAPIService + serverId string + jobId string +} + +func (r ApiServersJobsGetRequest) Execute() (*ServerJob, *http.Response, error) { + return r.ApiService.ServersJobsGetExecute(r) +} + +/* +ServersJobsGet Show a job + +Get a single job for this server. + + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param serverId The ID of a server + @param jobId The ID of a Job + @return ApiServersJobsGetRequest +*/ +func (a *BmpAPIService) ServersJobsGet(ctx context.Context, serverId string, jobId string) ApiServersJobsGetRequest { + return ApiServersJobsGetRequest{ + ApiService: a, + ctx: ctx, + serverId: serverId, + jobId: jobId, + } +} + +// Execute executes the request +// @return ServerJob +func (a *BmpAPIService) ServersJobsGetExecute(r ApiServersJobsGetRequest) (*ServerJob, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodGet + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *ServerJob + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "BmpAPIService.ServersJobsGet") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/servers/{serverId}/jobs/{jobId}" + localVarPath = strings.Replace(localVarPath, "{"+"serverId"+"}", url.PathEscape(parameterValueToString(r.serverId, "serverId")), -1) + localVarPath = strings.Replace(localVarPath, "{"+"jobId"+"}", url.PathEscape(parameterValueToString(r.jobId, "jobId")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiServersLeasesDeleteRequest struct { + ctx context.Context + ApiService *BmpAPIService + serverId string +} + +func (r ApiServersLeasesDeleteRequest) Execute() (*http.Response, error) { + return r.ApiService.ServersLeasesDeleteExecute(r) +} + +/* +ServersLeasesDelete Delete a DHCP reservation + +Delete a DHCP reservation for this server. + + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param serverId The ID of a server + @return ApiServersLeasesDeleteRequest +*/ +func (a *BmpAPIService) ServersLeasesDelete(ctx context.Context, serverId string) ApiServersLeasesDeleteRequest { + return ApiServersLeasesDeleteRequest{ + ApiService: a, + ctx: ctx, + serverId: serverId, + } +} + +// Execute executes the request +func (a *BmpAPIService) ServersLeasesDeleteExecute(r ApiServersLeasesDeleteRequest) (*http.Response, error) { + var ( + localVarHTTPMethod = http.MethodDelete + localVarPostBody interface{} + formFiles []formFile + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "BmpAPIService.ServersLeasesDelete") + if err != nil { + return nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/servers/{serverId}/leases" + localVarPath = strings.Replace(localVarPath, "{"+"serverId"+"}", url.PathEscape(parameterValueToString(r.serverId, "serverId")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarHTTPResponse, newErr + } + + return localVarHTTPResponse, nil +} + +type ApiUpdateNetworkEquipmentCredentialRequest struct { + ctx context.Context + ApiService *BmpAPIService + networkEquipmentId string + type_ string + username string + updateNetworkEquipmentCredentialOpts *UpdateNetworkEquipmentCredentialOpts +} + +func (r ApiUpdateNetworkEquipmentCredentialRequest) UpdateNetworkEquipmentCredentialOpts(updateNetworkEquipmentCredentialOpts UpdateNetworkEquipmentCredentialOpts) ApiUpdateNetworkEquipmentCredentialRequest { + r.updateNetworkEquipmentCredentialOpts = &updateNetworkEquipmentCredentialOpts + return r +} + +func (r ApiUpdateNetworkEquipmentCredentialRequest) Execute() (*Credential, *http.Response, error) { + return r.ApiService.UpdateNetworkEquipmentCredentialExecute(r) +} + +/* +UpdateNetworkEquipmentCredential Update user credentials + +The usernames or types cannot be changed. In order to change those remove this +credentials and create a new one. + +This action is purely administrative and will only update the password +associated with this resource in our database. + + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param networkEquipmentId The ID of a dedicated network equipment + @param type_ Credential type + @param username Username + @return ApiUpdateNetworkEquipmentCredentialRequest +*/ +func (a *BmpAPIService) UpdateNetworkEquipmentCredential(ctx context.Context, networkEquipmentId string, type_ string, username string) ApiUpdateNetworkEquipmentCredentialRequest { + return ApiUpdateNetworkEquipmentCredentialRequest{ + ApiService: a, + ctx: ctx, + networkEquipmentId: networkEquipmentId, + type_: type_, + username: username, + } +} + +// Execute executes the request +// @return Credential +func (a *BmpAPIService) UpdateNetworkEquipmentCredentialExecute(r ApiUpdateNetworkEquipmentCredentialRequest) (*Credential, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodPut + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *Credential + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "BmpAPIService.UpdateNetworkEquipmentCredential") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/networkEquipments/{networkEquipmentId}/credentials/{type}/{username}" + localVarPath = strings.Replace(localVarPath, "{"+"networkEquipmentId"+"}", url.PathEscape(parameterValueToString(r.networkEquipmentId, "networkEquipmentId")), -1) + localVarPath = strings.Replace(localVarPath, "{"+"type"+"}", url.PathEscape(parameterValueToString(r.type_, "type_")), -1) + localVarPath = strings.Replace(localVarPath, "{"+"username"+"}", url.PathEscape(parameterValueToString(r.username, "username")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{"application/json"} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + // body params + localVarPostBody = r.updateNetworkEquipmentCredentialOpts + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} diff --git a/bmp/client.go b/bmp/client.go new file mode 100644 index 0000000..c42ad60 --- /dev/null +++ b/bmp/client.go @@ -0,0 +1,678 @@ +/* +bmp + +This documents the rest api bmp api provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package bmp + +import ( + "bytes" + "context" + "encoding/json" + "encoding/xml" + "errors" + "fmt" + "io" + "log" + "mime/multipart" + "net/http" + "net/http/httputil" + "net/url" + "os" + "path/filepath" + "reflect" + "regexp" + "strconv" + "strings" + "time" + "unicode/utf8" + + "golang.org/x/oauth2" +) + +var ( + JsonCheck = regexp.MustCompile(`(?i:(?:application|text)/(?:[^;]+\+)?json)`) + XmlCheck = regexp.MustCompile(`(?i:(?:application|text)/(?:[^;]+\+)?xml)`) + queryParamSplit = regexp.MustCompile(`(^|&)([^&]+)`) + queryDescape = strings.NewReplacer( "%5B", "[", "%5D", "]" ) +) + +// APIClient manages communication with the bmp API vv2 +// In most cases there should be only one, shared, APIClient. +type APIClient struct { + cfg *Configuration + common service // Reuse a single struct instead of allocating one for each service on the heap. + + // API Services + + BmpAPI *BmpAPIService +} + +type service struct { + client *APIClient +} + +// NewAPIClient creates a new API client. Requires a userAgent string describing your application. +// optionally a custom http.Client to allow for advanced features such as caching. +func NewAPIClient(cfg *Configuration) *APIClient { + if cfg.HTTPClient == nil { + cfg.HTTPClient = http.DefaultClient + } + + c := &APIClient{} + c.cfg = cfg + c.common.client = c + + // API Services + c.BmpAPI = (*BmpAPIService)(&c.common) + + return c +} + +func atoi(in string) (int, error) { + return strconv.Atoi(in) +} + +// selectHeaderContentType select a content type from the available list. +func selectHeaderContentType(contentTypes []string) string { + if len(contentTypes) == 0 { + return "" + } + if contains(contentTypes, "application/json") { + return "application/json" + } + return contentTypes[0] // use the first content type specified in 'consumes' +} + +// selectHeaderAccept join all accept types and return +func selectHeaderAccept(accepts []string) string { + if len(accepts) == 0 { + return "" + } + + if contains(accepts, "application/json") { + return "application/json" + } + + return strings.Join(accepts, ",") +} + +// contains is a case insensitive match, finding needle in a haystack +func contains(haystack []string, needle string) bool { + for _, a := range haystack { + if strings.EqualFold(a, needle) { + return true + } + } + return false +} + +// Verify optional parameters are of the correct type. +func typeCheckParameter(obj interface{}, expected string, name string) error { + // Make sure there is an object. + if obj == nil { + return nil + } + + // Check the type is as expected. + if reflect.TypeOf(obj).String() != expected { + return fmt.Errorf("expected %s to be of type %s but received %s", name, expected, reflect.TypeOf(obj).String()) + } + return nil +} + +func parameterValueToString( obj interface{}, key string ) string { + if reflect.TypeOf(obj).Kind() != reflect.Ptr { + return fmt.Sprintf("%v", obj) + } + var param,ok = obj.(MappedNullable) + if !ok { + return "" + } + dataMap,err := param.ToMap() + if err != nil { + return "" + } + return fmt.Sprintf("%v", dataMap[key]) +} + +// parameterAddToHeaderOrQuery adds the provided object to the request header or url query +// supporting deep object syntax +func parameterAddToHeaderOrQuery(headerOrQueryParams interface{}, keyPrefix string, obj interface{}, collectionType string) { + var v = reflect.ValueOf(obj) + var value = "" + if v == reflect.ValueOf(nil) { + value = "null" + } else { + switch v.Kind() { + case reflect.Invalid: + value = "invalid" + + case reflect.Struct: + if t,ok := obj.(MappedNullable); ok { + dataMap,err := t.ToMap() + if err != nil { + return + } + parameterAddToHeaderOrQuery(headerOrQueryParams, keyPrefix, dataMap, collectionType) + return + } + if t, ok := obj.(time.Time); ok { + parameterAddToHeaderOrQuery(headerOrQueryParams, keyPrefix, t.Format(time.RFC3339), collectionType) + return + } + value = v.Type().String() + " value" + case reflect.Slice: + var indValue = reflect.ValueOf(obj) + if indValue == reflect.ValueOf(nil) { + return + } + var lenIndValue = indValue.Len() + for i:=0;i 0 || (len(formFiles) > 0) { + if body != nil { + return nil, errors.New("Cannot specify postBody and multipart form at the same time.") + } + body = &bytes.Buffer{} + w := multipart.NewWriter(body) + + for k, v := range formParams { + for _, iv := range v { + if strings.HasPrefix(k, "@") { // file + err = addFile(w, k[1:], iv) + if err != nil { + return nil, err + } + } else { // form value + w.WriteField(k, iv) + } + } + } + for _, formFile := range formFiles { + if len(formFile.fileBytes) > 0 && formFile.fileName != "" { + w.Boundary() + part, err := w.CreateFormFile(formFile.formFileName, filepath.Base(formFile.fileName)) + if err != nil { + return nil, err + } + _, err = part.Write(formFile.fileBytes) + if err != nil { + return nil, err + } + } + } + + // Set the Boundary in the Content-Type + headerParams["Content-Type"] = w.FormDataContentType() + + // Set Content-Length + headerParams["Content-Length"] = fmt.Sprintf("%d", body.Len()) + w.Close() + } + + if strings.HasPrefix(headerParams["Content-Type"], "application/x-www-form-urlencoded") && len(formParams) > 0 { + if body != nil { + return nil, errors.New("Cannot specify postBody and x-www-form-urlencoded form at the same time.") + } + body = &bytes.Buffer{} + body.WriteString(formParams.Encode()) + // Set Content-Length + headerParams["Content-Length"] = fmt.Sprintf("%d", body.Len()) + } + + // Setup path and query parameters + url, err := url.Parse(path) + if err != nil { + return nil, err + } + + // Override request host, if applicable + if c.cfg.Host != "" { + url.Host = c.cfg.Host + } + + // Override request scheme, if applicable + if c.cfg.Scheme != "" { + url.Scheme = c.cfg.Scheme + } + + // Adding Query Param + query := url.Query() + for k, v := range queryParams { + for _, iv := range v { + query.Add(k, iv) + } + } + + // Encode the parameters. + url.RawQuery = queryParamSplit.ReplaceAllStringFunc(query.Encode(), func(s string) string { + pieces := strings.Split(s, "=") + pieces[0] = queryDescape.Replace(pieces[0]) + return strings.Join(pieces, "=") + }) + + // Generate a new request + if body != nil { + localVarRequest, err = http.NewRequest(method, url.String(), body) + } else { + localVarRequest, err = http.NewRequest(method, url.String(), nil) + } + if err != nil { + return nil, err + } + + // add header parameters, if any + if len(headerParams) > 0 { + headers := http.Header{} + for h, v := range headerParams { + headers[h] = []string{v} + } + localVarRequest.Header = headers + } + + // Add the user agent to the request. + localVarRequest.Header.Add("User-Agent", c.cfg.UserAgent) + + if ctx != nil { + // add context to the request + localVarRequest = localVarRequest.WithContext(ctx) + + // Walk through any authentication. + + // OAuth2 authentication + if tok, ok := ctx.Value(ContextOAuth2).(oauth2.TokenSource); ok { + // We were able to grab an oauth2 token from the context + var latestToken *oauth2.Token + if latestToken, err = tok.Token(); err != nil { + return nil, err + } + + latestToken.SetAuthHeader(localVarRequest) + } + + // AccessToken Authentication + if auth, ok := ctx.Value(ContextAccessToken).(string); ok { + localVarRequest.Header.Add("Authorization", "Bearer "+auth) + } + + } + + for header, value := range c.cfg.DefaultHeader { + localVarRequest.Header.Add(header, value) + } + return localVarRequest, nil +} + +func (c *APIClient) decode(v interface{}, b []byte, contentType string) (err error) { + if len(b) == 0 { + return nil + } + if s, ok := v.(*string); ok { + *s = string(b) + return nil + } + if f, ok := v.(*os.File); ok { + f, err = os.CreateTemp("", "HttpClientFile") + if err != nil { + return + } + _, err = f.Write(b) + if err != nil { + return + } + _, err = f.Seek(0, io.SeekStart) + return + } + if f, ok := v.(**os.File); ok { + *f, err = os.CreateTemp("", "HttpClientFile") + if err != nil { + return + } + _, err = (*f).Write(b) + if err != nil { + return + } + _, err = (*f).Seek(0, io.SeekStart) + return + } + if XmlCheck.MatchString(contentType) { + if err = xml.Unmarshal(b, v); err != nil { + return err + } + return nil + } + if JsonCheck.MatchString(contentType) { + if actualObj, ok := v.(interface{ GetActualInstance() interface{} }); ok { // oneOf, anyOf schemas + if unmarshalObj, ok := actualObj.(interface{ UnmarshalJSON([]byte) error }); ok { // make sure it has UnmarshalJSON defined + if err = unmarshalObj.UnmarshalJSON(b); err != nil { + return err + } + } else { + return errors.New("Unknown type with GetActualInstance but no unmarshalObj.UnmarshalJSON defined") + } + } else if err = json.Unmarshal(b, v); err != nil { // simple model + return err + } + return nil + } + return errors.New("undefined response type") +} + +// Add a file to the multipart request +func addFile(w *multipart.Writer, fieldName, path string) error { + file, err := os.Open(filepath.Clean(path)) + if err != nil { + return err + } + err = file.Close() + if err != nil { + return err + } + + part, err := w.CreateFormFile(fieldName, filepath.Base(path)) + if err != nil { + return err + } + _, err = io.Copy(part, file) + + return err +} + +// Prevent trying to import "fmt" +func reportError(format string, a ...interface{}) error { + return fmt.Errorf(format, a...) +} + +// A wrapper for strict JSON decoding +func newStrictDecoder(data []byte) *json.Decoder { + dec := json.NewDecoder(bytes.NewBuffer(data)) + dec.DisallowUnknownFields() + return dec +} + +// Set request body from an interface{} +func setBody(body interface{}, contentType string) (bodyBuf *bytes.Buffer, err error) { + if bodyBuf == nil { + bodyBuf = &bytes.Buffer{} + } + + if reader, ok := body.(io.Reader); ok { + _, err = bodyBuf.ReadFrom(reader) + } else if fp, ok := body.(*os.File); ok { + _, err = bodyBuf.ReadFrom(fp) + } else if b, ok := body.([]byte); ok { + _, err = bodyBuf.Write(b) + } else if s, ok := body.(string); ok { + _, err = bodyBuf.WriteString(s) + } else if s, ok := body.(*string); ok { + _, err = bodyBuf.WriteString(*s) + } else if JsonCheck.MatchString(contentType) { + err = json.NewEncoder(bodyBuf).Encode(body) + } else if XmlCheck.MatchString(contentType) { + var bs []byte + bs, err = xml.Marshal(body) + if err == nil { + bodyBuf.Write(bs) + } + } + + if err != nil { + return nil, err + } + + if bodyBuf.Len() == 0 { + err = fmt.Errorf("invalid body type %s\n", contentType) + return nil, err + } + return bodyBuf, nil +} + +// detectContentType method is used to figure out `Request.Body` content type for request header +func detectContentType(body interface{}) string { + contentType := "text/plain; charset=utf-8" + kind := reflect.TypeOf(body).Kind() + + switch kind { + case reflect.Struct, reflect.Map, reflect.Ptr: + contentType = "application/json; charset=utf-8" + case reflect.String: + contentType = "text/plain; charset=utf-8" + default: + if b, ok := body.([]byte); ok { + contentType = http.DetectContentType(b) + } else if kind == reflect.Slice { + contentType = "application/json; charset=utf-8" + } + } + + return contentType +} + +// Ripped from https://github.com/gregjones/httpcache/blob/master/httpcache.go +type cacheControl map[string]string + +func parseCacheControl(headers http.Header) cacheControl { + cc := cacheControl{} + ccHeader := headers.Get("Cache-Control") + for _, part := range strings.Split(ccHeader, ",") { + part = strings.Trim(part, " ") + if part == "" { + continue + } + if strings.ContainsRune(part, '=') { + keyval := strings.Split(part, "=") + cc[strings.Trim(keyval[0], " ")] = strings.Trim(keyval[1], ",") + } else { + cc[part] = "" + } + } + return cc +} + +// CacheExpires helper function to determine remaining time before repeating a request. +func CacheExpires(r *http.Response) time.Time { + // Figure out when the cache expires. + var expires time.Time + now, err := time.Parse(time.RFC1123, r.Header.Get("date")) + if err != nil { + return time.Now() + } + respCacheControl := parseCacheControl(r.Header) + + if maxAge, ok := respCacheControl["max-age"]; ok { + lifetime, err := time.ParseDuration(maxAge + "s") + if err != nil { + expires = now + } else { + expires = now.Add(lifetime) + } + } else { + expiresHeader := r.Header.Get("Expires") + if expiresHeader != "" { + expires, err = time.Parse(time.RFC1123, expiresHeader) + if err != nil { + expires = now + } + } + } + return expires +} + +func strlen(s string) int { + return utf8.RuneCountInString(s) +} + +// GenericOpenAPIError Provides access to the body, error and model on returned errors. +type GenericOpenAPIError struct { + body []byte + error string + model interface{} +} + +// Error returns non-empty string if there was an error. +func (e GenericOpenAPIError) Error() string { + return e.error +} + +// Body returns the raw bytes of the response +func (e GenericOpenAPIError) Body() []byte { + return e.body +} + +// Model returns the unpacked model of the error +func (e GenericOpenAPIError) Model() interface{} { + return e.model +} + +// format error message using title and detail when model implements rfc7807 +func formatErrorMessage(status string, v interface{}) string { + str := "" + metaValue := reflect.ValueOf(v).Elem() + + if metaValue.Kind() == reflect.Struct { + field := metaValue.FieldByName("Title") + if field != (reflect.Value{}) { + str = fmt.Sprintf("%s", field.Interface()) + } + + field = metaValue.FieldByName("Detail") + if field != (reflect.Value{}) { + str = fmt.Sprintf("%s (%s)", str, field.Interface()) + } + } + + return strings.TrimSpace(fmt.Sprintf("%s %s", status, str)) +} diff --git a/bmp/configuration.go b/bmp/configuration.go new file mode 100644 index 0000000..08edc7f --- /dev/null +++ b/bmp/configuration.go @@ -0,0 +1,225 @@ +/* +bmp + +This documents the rest api bmp api provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package bmp + +import ( + "context" + "fmt" + "net/http" + "strings" +) + +// contextKeys are used to identify the type of value in the context. +// Since these are string, it is possible to get a short description of the +// context key for logging and debugging using key.String(). + +type contextKey string + +func (c contextKey) String() string { + return "auth " + string(c) +} + +var ( + // ContextOAuth2 takes an oauth2.TokenSource as authentication for the request. + ContextOAuth2 = contextKey("token") + + // ContextAccessToken takes a string oauth2 access token as authentication for the request. + ContextAccessToken = contextKey("accesstoken") + + // ContextAPIKeys takes a string apikey as authentication for the request + ContextAPIKeys = contextKey("apiKeys") + + // ContextServerIndex uses a server configuration from the index. + ContextServerIndex = contextKey("serverIndex") + + // ContextOperationServerIndices uses a server configuration from the index mapping. + ContextOperationServerIndices = contextKey("serverOperationIndices") + + // ContextServerVariables overrides a server configuration variables. + ContextServerVariables = contextKey("serverVariables") + + // ContextOperationServerVariables overrides a server configuration variables using operation specific values. + ContextOperationServerVariables = contextKey("serverOperationVariables") +) + +// BasicAuth provides basic http authentication to a request passed via context using ContextBasicAuth +type BasicAuth struct { + UserName string `json:"userName,omitempty"` + Password string `json:"password,omitempty"` +} + +// APIKey provides API key based authentication to a request passed via context using ContextAPIKey +type APIKey struct { + Key string + Prefix string +} + +// ServerVariable stores the information about a server variable +type ServerVariable struct { + Description string + DefaultValue string + EnumValues []string +} + +// ServerConfiguration stores the information about a server +type ServerConfiguration struct { + URL string + Description string + Variables map[string]ServerVariable +} + +// ServerConfigurations stores multiple ServerConfiguration items +type ServerConfigurations []ServerConfiguration + +// Configuration stores the configuration of the API client +type Configuration struct { + Host string `json:"host,omitempty"` + Scheme string `json:"scheme,omitempty"` + DefaultHeader map[string]string `json:"defaultHeader,omitempty"` + UserAgent string `json:"userAgent,omitempty"` + Debug bool `json:"debug,omitempty"` + Servers ServerConfigurations + OperationServers map[string]ServerConfigurations + HTTPClient *http.Client +} + +// NewConfiguration returns a new Configuration object +func NewConfiguration() *Configuration { + cfg := &Configuration{ + DefaultHeader: make(map[string]string), + UserAgent: "OpenAPI-Generator/1.0.0/go", + Debug: false, + Servers: ServerConfigurations{ + { + URL: "https://api.leaseweb.com/internal/bmpapi/v2", + Description: "No description provided", + }, + }, + OperationServers: map[string]ServerConfigurations{ + }, + } + return cfg +} + +// AddDefaultHeader adds a new HTTP header to the default header in the request +func (c *Configuration) AddDefaultHeader(key string, value string) { + c.DefaultHeader[key] = value +} + +// URL formats template on a index using given variables +func (sc ServerConfigurations) URL(index int, variables map[string]string) (string, error) { + if index < 0 || len(sc) <= index { + return "", fmt.Errorf("index %v out of range %v", index, len(sc)-1) + } + server := sc[index] + url := server.URL + + // go through variables and replace placeholders + for name, variable := range server.Variables { + if value, ok := variables[name]; ok { + found := bool(len(variable.EnumValues) == 0) + for _, enumValue := range variable.EnumValues { + if value == enumValue { + found = true + } + } + if !found { + return "", fmt.Errorf("the variable %s in the server URL has invalid value %v. Must be %v", name, value, variable.EnumValues) + } + url = strings.Replace(url, "{"+name+"}", value, -1) + } else { + url = strings.Replace(url, "{"+name+"}", variable.DefaultValue, -1) + } + } + return url, nil +} + +// ServerURL returns URL based on server settings +func (c *Configuration) ServerURL(index int, variables map[string]string) (string, error) { + return c.Servers.URL(index, variables) +} + +func getServerIndex(ctx context.Context) (int, error) { + si := ctx.Value(ContextServerIndex) + if si != nil { + if index, ok := si.(int); ok { + return index, nil + } + return 0, reportError("Invalid type %T should be int", si) + } + return 0, nil +} + +func getServerOperationIndex(ctx context.Context, endpoint string) (int, error) { + osi := ctx.Value(ContextOperationServerIndices) + if osi != nil { + if operationIndices, ok := osi.(map[string]int); !ok { + return 0, reportError("Invalid type %T should be map[string]int", osi) + } else { + index, ok := operationIndices[endpoint] + if ok { + return index, nil + } + } + } + return getServerIndex(ctx) +} + +func getServerVariables(ctx context.Context) (map[string]string, error) { + sv := ctx.Value(ContextServerVariables) + if sv != nil { + if variables, ok := sv.(map[string]string); ok { + return variables, nil + } + return nil, reportError("ctx value of ContextServerVariables has invalid type %T should be map[string]string", sv) + } + return nil, nil +} + +func getServerOperationVariables(ctx context.Context, endpoint string) (map[string]string, error) { + osv := ctx.Value(ContextOperationServerVariables) + if osv != nil { + if operationVariables, ok := osv.(map[string]map[string]string); !ok { + return nil, reportError("ctx value of ContextOperationServerVariables has invalid type %T should be map[string]map[string]string", osv) + } else { + variables, ok := operationVariables[endpoint] + if ok { + return variables, nil + } + } + } + return getServerVariables(ctx) +} + +// ServerURLWithContext returns a new server URL given an endpoint +func (c *Configuration) ServerURLWithContext(ctx context.Context, endpoint string) (string, error) { + sc, ok := c.OperationServers[endpoint] + if !ok { + sc = c.Servers + } + + if ctx == nil { + return sc.URL(0, nil) + } + + index, err := getServerOperationIndex(ctx, endpoint) + if err != nil { + return "", err + } + + variables, err := getServerOperationVariables(ctx, endpoint) + if err != nil { + return "", err + } + + return sc.URL(index, variables) +} diff --git a/bmp/go.mod b/bmp/go.mod new file mode 100644 index 0000000..880be11 --- /dev/null +++ b/bmp/go.mod @@ -0,0 +1,7 @@ +module github.com/leaseweb/leaseweb-go-sdk/bmp + +go 1.18 + +require ( + golang.org/x/oauth2 v0.0.0-20210323180902-22b0adad7558 +) diff --git a/bmp/go.sum b/bmp/go.sum new file mode 100644 index 0000000..3dee6d6 --- /dev/null +++ b/bmp/go.sum @@ -0,0 +1,360 @@ +cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU= +cloud.google.com/go v0.44.1/go.mod h1:iSa0KzasP4Uvy3f1mN/7PiObzGgflwredwwASm/v6AU= +cloud.google.com/go v0.44.2/go.mod h1:60680Gw3Yr4ikxnPRS/oxxkBccT6SA1yMk63TGekxKY= +cloud.google.com/go v0.45.1/go.mod h1:RpBamKRgapWJb87xiFSdk4g1CME7QZg3uwTez+TSTjc= +cloud.google.com/go v0.46.3/go.mod h1:a6bKKbmY7er1mI7TEI4lsAkts/mkhTSZK8w33B4RAg0= +cloud.google.com/go v0.50.0/go.mod h1:r9sluTvynVuxRIOHXQEHMFffphuXHOMZMycpNR5e6To= +cloud.google.com/go v0.52.0/go.mod h1:pXajvRH/6o3+F9jDHZWQ5PbGhn+o8w9qiu/CffaVdO4= +cloud.google.com/go v0.53.0/go.mod h1:fp/UouUEsRkN6ryDKNW/Upv/JBKnv6WDthjR6+vze6M= +cloud.google.com/go v0.54.0/go.mod h1:1rq2OEkV3YMf6n/9ZvGWI3GWw0VoqH/1x2nd8Is/bPc= +cloud.google.com/go v0.56.0/go.mod h1:jr7tqZxxKOVYizybht9+26Z/gUq7tiRzu+ACVAMbKVk= +cloud.google.com/go v0.57.0/go.mod h1:oXiQ6Rzq3RAkkY7N6t3TcE6jE+CIBBbA36lwQ1JyzZs= +cloud.google.com/go v0.62.0/go.mod h1:jmCYTdRCQuc1PHIIJ/maLInMho30T/Y0M4hTdTShOYc= +cloud.google.com/go v0.65.0/go.mod h1:O5N8zS7uWy9vkA9vayVHs65eM1ubvY4h553ofrNHObY= +cloud.google.com/go/bigquery v1.0.1/go.mod h1:i/xbL2UlR5RvWAURpBYZTtm/cXjCha9lbfbpx4poX+o= +cloud.google.com/go/bigquery v1.3.0/go.mod h1:PjpwJnslEMmckchkHFfq+HTD2DmtT67aNFKH1/VBDHE= +cloud.google.com/go/bigquery v1.4.0/go.mod h1:S8dzgnTigyfTmLBfrtrhyYhwRxG72rYxvftPBK2Dvzc= +cloud.google.com/go/bigquery v1.5.0/go.mod h1:snEHRnqQbz117VIFhE8bmtwIDY80NLUZUMb4Nv6dBIg= +cloud.google.com/go/bigquery v1.7.0/go.mod h1://okPTzCYNXSlb24MZs83e2Do+h+VXtc4gLoIoXIAPc= +cloud.google.com/go/bigquery v1.8.0/go.mod h1:J5hqkt3O0uAFnINi6JXValWIb1v0goeZM77hZzJN/fQ= +cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7TKLgZqpHYE= +cloud.google.com/go/datastore v1.1.0/go.mod h1:umbIZjpQpHh4hmRpGhH4tLFup+FVzqBi1b3c64qFpCk= +cloud.google.com/go/pubsub v1.0.1/go.mod h1:R0Gpsv3s54REJCy4fxDixWD93lHJMoZTyQ2kNxGRt3I= +cloud.google.com/go/pubsub v1.1.0/go.mod h1:EwwdRX2sKPjnvnqCa270oGRyludottCI76h+R3AArQw= +cloud.google.com/go/pubsub v1.2.0/go.mod h1:jhfEVHT8odbXTkndysNHCcx0awwzvfOlguIAii9o8iA= +cloud.google.com/go/pubsub v1.3.1/go.mod h1:i+ucay31+CNRpDW4Lu78I4xXG+O1r/MAHgjpRVR+TSU= +cloud.google.com/go/storage v1.0.0/go.mod h1:IhtSnM/ZTZV8YYJWCY8RULGVqBDmpoyjwiyrjsg+URw= +cloud.google.com/go/storage v1.5.0/go.mod h1:tpKbwo567HUNpVclU5sGELwQWBDZ8gh0ZeosJ0Rtdos= +cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohlUTyfDhBk= +cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs= +cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0= +dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= +github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= +github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= +github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= +github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= +github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= +github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= +github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= +github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= +github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y= +github.com/golang/mock v1.4.0/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= +github.com/golang/mock v1.4.1/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= +github.com/golang/mock v1.4.3/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= +github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4= +github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= +github.com/golang/protobuf v1.3.4/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= +github.com/golang/protobuf v1.3.5/go.mod h1:6O5/vntMXwX2lRkT1hjjk0nAC1IDOTvTlVgjlRvqsdk= +github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= +github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= +github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= +github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= +github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= +github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= +github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= +github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= +github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= +github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.4.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= +github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0= +github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= +github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= +github.com/google/pprof v0.0.0-20191218002539-d4f498aebedc/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= +github.com/google/pprof v0.0.0-20200212024743-f11f1df84d12/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= +github.com/google/pprof v0.0.0-20200229191704-1ebb73c60ed3/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= +github.com/google/pprof v0.0.0-20200430221834-fc25d7d30c6d/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= +github.com/google/pprof v0.0.0-20200708004538-1a94d8640e99/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= +github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= +github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= +github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= +github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= +github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= +github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= +github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= +github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk= +github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= +go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= +go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= +go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= +go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= +golang.org/x/exp v0.0.0-20190829153037-c13cbed26979/go.mod h1:86+5VVa7VpoJ4kLfm080zCjGlMRFzhUhsZKEZO7MGek= +golang.org/x/exp v0.0.0-20191030013958-a1ab85dbe136/go.mod h1:JXzH8nQsPlswgeRAPE3MuO9GYsAcnJvJ4vnMwN/5qkY= +golang.org/x/exp v0.0.0-20191129062945-2f5052295587/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= +golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= +golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= +golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM= +golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU= +golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= +golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= +golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= +golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f/go.mod h1:5qLYkcX4OjUUV8bRuDixDT3tpyyb+LUpUlRWLxfhWrs= +golang.org/x/lint v0.0.0-20200130185559-910be7a94367/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= +golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= +golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= +golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o= +golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= +golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY= +golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= +golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= +golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e h1:bRhVy7zSSasaqNksaRZiA5EEI+Ei4I1nO5Jh72wfHlg= +golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190501004415-9ce7a6920f09/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20190628185345-da137c7871d7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200222125558-5a598a2470a0/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200501053045-e0ff5e5a1de5/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200506145744-7e3656a0809f/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200513185701-a91f0712d120/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200520182314-0ba52f642ac2/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= +golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= +golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= +golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= +golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45 h1:SVwTIAaPC2U/AvvLNZ2a7OVsmBpC8L5BlwK1whH3hm0= +golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/oauth2 v0.0.0-20191202225959-858c2ad4c8b6/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/oauth2 v0.0.0-20210323180902-22b0adad7558/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4 h1:YUO/7uOKsKeq9UokNS62b8FYywz3ker1l1vDZRCRefw= +golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200113162924-86b910548bc1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200122134326-e047566fdf82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200331124033-c3d80250170d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200501052902-10377860bb8e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200511232937-7e40ca221e25/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200515095857-1151b9dac4a9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200523222454-059865788121/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200803210538-64077c9b5642/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= +golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20190506145303-2d16b83fe98c/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191113191852-77e3bb0ad9e7/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191115202509-3a792d9c32b2/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191130070609-6e064ea0cf2d/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191216173652-a0e659d51361/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20191227053925-7b8e75db28f4/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200117161641-43d50277825c/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200122220014-bf1340f18c4a/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200204074204-1cc6d1ef6c74/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200207183749-b753a1ba74fa/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200212150539-ea181f53ac56/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200224181240-023911ca70b2/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200227222343-706bc42d1f0d/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200304193943-95d2e580d8eb/go.mod h1:o4KQGtdN14AW+yjsvvwRTJJuXz8XRtIHtEnmAXLyFUw= +golang.org/x/tools v0.0.0-20200312045724-11d5b4c81c7d/go.mod h1:o4KQGtdN14AW+yjsvvwRTJJuXz8XRtIHtEnmAXLyFUw= +golang.org/x/tools v0.0.0-20200331025713-a30bf2db82d4/go.mod h1:Sl4aGygMT6LrqrWclx+PTx3U+LnKx/seiNR+3G19Ar8= +golang.org/x/tools v0.0.0-20200501065659-ab2804fb9c9d/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20200512131952-2bc93b1c0c88/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20200515010526-7d3b6ebf133d/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20200618134242-20370b0cb4b2/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20200729194436-6467de6f59a7/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= +golang.org/x/tools v0.0.0-20200804011535-6c149bb5ef0d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= +golang.org/x/tools v0.0.0-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= +google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M= +google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= +google.golang.org/api v0.9.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= +google.golang.org/api v0.13.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= +google.golang.org/api v0.14.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= +google.golang.org/api v0.15.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= +google.golang.org/api v0.17.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= +google.golang.org/api v0.18.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= +google.golang.org/api v0.19.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= +google.golang.org/api v0.20.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= +google.golang.org/api v0.22.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= +google.golang.org/api v0.24.0/go.mod h1:lIXQywCXRcnZPGlsd8NbLnOjtAoL6em04bJ9+z0MncE= +google.golang.org/api v0.28.0/go.mod h1:lIXQywCXRcnZPGlsd8NbLnOjtAoL6em04bJ9+z0MncE= +google.golang.org/api v0.29.0/go.mod h1:Lcubydp8VUV7KeIHD9z2Bys/sm/vGKnG1UHuDBSrHWM= +google.golang.org/api v0.30.0/go.mod h1:QGmEvQ87FHZNiUVJkT14jQNYJ4ZJjdRF23ZXz5138Fc= +google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= +google.golang.org/appengine v1.4.0 h1:/wp5JvzpHIxhs/dumFmF7BXTf3Z+dd4uXta4kVyO508= +google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0= +google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= +google.golang.org/appengine v1.6.6/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= +google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= +google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190801165951-fa694d86fc64/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= +google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= +google.golang.org/genproto v0.0.0-20190911173649-1774047e7e51/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8= +google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20191115194625-c23dd37a84c9/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20191216164720-4f79533eabd1/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20191230161307-f3c370f40bfb/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20200115191322-ca5a22157cba/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20200122232147-0452cf42e150/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20200204135345-fa8e72b47b90/go.mod h1:GmwEX6Z4W5gMy59cAlVYjN9JhxgbQH6Gn+gFDQe2lzA= +google.golang.org/genproto v0.0.0-20200212174721-66ed5ce911ce/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200224152610-e50cd9704f63/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200228133532-8c2c7df3a383/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200305110556-506484158171/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200312145019-da6875a35672/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200331122359-1ee6d9798940/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200430143042-b979b6f78d84/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200511104702-f5ebc3bea380/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200515170657-fc4c6c6a6587/go.mod h1:YsZOwe1myG/8QRHRsmBRE1LrgQY60beZKjly0O1fX9U= +google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= +google.golang.org/genproto v0.0.0-20200618031413-b414f8b61790/go.mod h1:jDfRM7FcilCzHH/e9qn6dsT145K34l5v+OpcnNgKAAA= +google.golang.org/genproto v0.0.0-20200729003335-053ba62fc06f/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20200804131852-c06518451d9c/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20200825200019-8632dd797987/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= +google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= +google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= +google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= +google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= +google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= +google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= +google.golang.org/grpc v1.27.1/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= +google.golang.org/grpc v1.28.0/go.mod h1:rpkK4SK4GF4Ach/+MFLZUBavHOvF2JJB5uozKKal+60= +google.golang.org/grpc v1.29.1/go.mod h1:itym6AZVZYACWQqET3MqgPpjcuV5QH3BxFS3IjizoKk= +google.golang.org/grpc v1.30.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= +google.golang.org/grpc v1.31.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= +google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= +google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= +google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= +google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= +google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= +google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4= +google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= +honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= +honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= +rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= +rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0= +rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= diff --git a/bmp/model__metadata.go b/bmp/model__metadata.go new file mode 100644 index 0000000..eadb7eb --- /dev/null +++ b/bmp/model__metadata.go @@ -0,0 +1,128 @@ +/* +bmp + +This documents the rest api bmp api provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package bmp + +import ( + "encoding/json" +) + +// checks if the Metadata type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &Metadata{} + +// Metadata The Job Metadata schema +type Metadata struct { + // Batch ID for batch jobs + BATCH_ID *string `json:"BATCH_ID,omitempty"` +} + +// NewMetadata instantiates a new Metadata object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewMetadata() *Metadata { + this := Metadata{} + return &this +} + +// NewMetadataWithDefaults instantiates a new Metadata object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewMetadataWithDefaults() *Metadata { + this := Metadata{} + return &this +} + +// GetBATCH_ID returns the BATCH_ID field value if set, zero value otherwise. +func (o *Metadata) GetBATCH_ID() string { + if o == nil || IsNil(o.BATCH_ID) { + var ret string + return ret + } + return *o.BATCH_ID +} + +// GetBATCH_IDOk returns a tuple with the BATCH_ID field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Metadata) GetBATCH_IDOk() (*string, bool) { + if o == nil || IsNil(o.BATCH_ID) { + return nil, false + } + return o.BATCH_ID, true +} + +// HasBATCH_ID returns a boolean if a field has been set. +func (o *Metadata) HasBATCH_ID() bool { + if o != nil && !IsNil(o.BATCH_ID) { + return true + } + + return false +} + +// SetBATCH_ID gets a reference to the given string and assigns it to the BATCH_ID field. +func (o *Metadata) SetBATCH_ID(v string) { + o.BATCH_ID = &v +} + +func (o Metadata) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o Metadata) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.BATCH_ID) { + toSerialize["BATCH_ID"] = o.BATCH_ID + } + return toSerialize, nil +} + +type NullableMetadata struct { + value *Metadata + isSet bool +} + +func (v NullableMetadata) Get() *Metadata { + return v.value +} + +func (v *NullableMetadata) Set(val *Metadata) { + v.value = val + v.isSet = true +} + +func (v NullableMetadata) IsSet() bool { + return v.isSet +} + +func (v *NullableMetadata) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableMetadata(val *Metadata) *NullableMetadata { + return &NullableMetadata{value: val, isSet: true} +} + +func (v NullableMetadata) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableMetadata) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/bmp/model_configure_hardware_raid_opts.go b/bmp/model_configure_hardware_raid_opts.go new file mode 100644 index 0000000..43ecf93 --- /dev/null +++ b/bmp/model_configure_hardware_raid_opts.go @@ -0,0 +1,311 @@ +/* +bmp + +This documents the rest api bmp api provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package bmp + +import ( + "encoding/json" + "bytes" + "fmt" +) + +// checks if the ConfigureHardwareRaidOpts type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &ConfigureHardwareRaidOpts{} + +// ConfigureHardwareRaidOpts struct for ConfigureHardwareRaidOpts +type ConfigureHardwareRaidOpts struct { + // Url which will receive callbacks + CallbackUrl *string `json:"callbackUrl,omitempty"` + // RAID level to apply, this value is only required if you specify a type HW + Level *int32 `json:"level,omitempty"` + // The number of disks you want to apply RAID on. If not specified all disks are used. + NumberOfDisks *int32 `json:"numberOfDisks,omitempty"` + // If set to `true`, server will be power cycled in order to complete the operation + PowerCycle *bool `json:"powerCycle,omitempty"` + Type RaidType `json:"type"` +} + +type _ConfigureHardwareRaidOpts ConfigureHardwareRaidOpts + +// NewConfigureHardwareRaidOpts instantiates a new ConfigureHardwareRaidOpts object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewConfigureHardwareRaidOpts(type_ RaidType) *ConfigureHardwareRaidOpts { + this := ConfigureHardwareRaidOpts{} + var powerCycle bool = true + this.PowerCycle = &powerCycle + this.Type = type_ + return &this +} + +// NewConfigureHardwareRaidOptsWithDefaults instantiates a new ConfigureHardwareRaidOpts object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewConfigureHardwareRaidOptsWithDefaults() *ConfigureHardwareRaidOpts { + this := ConfigureHardwareRaidOpts{} + var powerCycle bool = true + this.PowerCycle = &powerCycle + return &this +} + +// GetCallbackUrl returns the CallbackUrl field value if set, zero value otherwise. +func (o *ConfigureHardwareRaidOpts) GetCallbackUrl() string { + if o == nil || IsNil(o.CallbackUrl) { + var ret string + return ret + } + return *o.CallbackUrl +} + +// GetCallbackUrlOk returns a tuple with the CallbackUrl field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ConfigureHardwareRaidOpts) GetCallbackUrlOk() (*string, bool) { + if o == nil || IsNil(o.CallbackUrl) { + return nil, false + } + return o.CallbackUrl, true +} + +// HasCallbackUrl returns a boolean if a field has been set. +func (o *ConfigureHardwareRaidOpts) HasCallbackUrl() bool { + if o != nil && !IsNil(o.CallbackUrl) { + return true + } + + return false +} + +// SetCallbackUrl gets a reference to the given string and assigns it to the CallbackUrl field. +func (o *ConfigureHardwareRaidOpts) SetCallbackUrl(v string) { + o.CallbackUrl = &v +} + +// GetLevel returns the Level field value if set, zero value otherwise. +func (o *ConfigureHardwareRaidOpts) GetLevel() int32 { + if o == nil || IsNil(o.Level) { + var ret int32 + return ret + } + return *o.Level +} + +// GetLevelOk returns a tuple with the Level field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ConfigureHardwareRaidOpts) GetLevelOk() (*int32, bool) { + if o == nil || IsNil(o.Level) { + return nil, false + } + return o.Level, true +} + +// HasLevel returns a boolean if a field has been set. +func (o *ConfigureHardwareRaidOpts) HasLevel() bool { + if o != nil && !IsNil(o.Level) { + return true + } + + return false +} + +// SetLevel gets a reference to the given int32 and assigns it to the Level field. +func (o *ConfigureHardwareRaidOpts) SetLevel(v int32) { + o.Level = &v +} + +// GetNumberOfDisks returns the NumberOfDisks field value if set, zero value otherwise. +func (o *ConfigureHardwareRaidOpts) GetNumberOfDisks() int32 { + if o == nil || IsNil(o.NumberOfDisks) { + var ret int32 + return ret + } + return *o.NumberOfDisks +} + +// GetNumberOfDisksOk returns a tuple with the NumberOfDisks field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ConfigureHardwareRaidOpts) GetNumberOfDisksOk() (*int32, bool) { + if o == nil || IsNil(o.NumberOfDisks) { + return nil, false + } + return o.NumberOfDisks, true +} + +// HasNumberOfDisks returns a boolean if a field has been set. +func (o *ConfigureHardwareRaidOpts) HasNumberOfDisks() bool { + if o != nil && !IsNil(o.NumberOfDisks) { + return true + } + + return false +} + +// SetNumberOfDisks gets a reference to the given int32 and assigns it to the NumberOfDisks field. +func (o *ConfigureHardwareRaidOpts) SetNumberOfDisks(v int32) { + o.NumberOfDisks = &v +} + +// GetPowerCycle returns the PowerCycle field value if set, zero value otherwise. +func (o *ConfigureHardwareRaidOpts) GetPowerCycle() bool { + if o == nil || IsNil(o.PowerCycle) { + var ret bool + return ret + } + return *o.PowerCycle +} + +// GetPowerCycleOk returns a tuple with the PowerCycle field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ConfigureHardwareRaidOpts) GetPowerCycleOk() (*bool, bool) { + if o == nil || IsNil(o.PowerCycle) { + return nil, false + } + return o.PowerCycle, true +} + +// HasPowerCycle returns a boolean if a field has been set. +func (o *ConfigureHardwareRaidOpts) HasPowerCycle() bool { + if o != nil && !IsNil(o.PowerCycle) { + return true + } + + return false +} + +// SetPowerCycle gets a reference to the given bool and assigns it to the PowerCycle field. +func (o *ConfigureHardwareRaidOpts) SetPowerCycle(v bool) { + o.PowerCycle = &v +} + +// GetType returns the Type field value +func (o *ConfigureHardwareRaidOpts) GetType() RaidType { + if o == nil { + var ret RaidType + return ret + } + + return o.Type +} + +// GetTypeOk returns a tuple with the Type field value +// and a boolean to check if the value has been set. +func (o *ConfigureHardwareRaidOpts) GetTypeOk() (*RaidType, bool) { + if o == nil { + return nil, false + } + return &o.Type, true +} + +// SetType sets field value +func (o *ConfigureHardwareRaidOpts) SetType(v RaidType) { + o.Type = v +} + +func (o ConfigureHardwareRaidOpts) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o ConfigureHardwareRaidOpts) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.CallbackUrl) { + toSerialize["callbackUrl"] = o.CallbackUrl + } + if !IsNil(o.Level) { + toSerialize["level"] = o.Level + } + if !IsNil(o.NumberOfDisks) { + toSerialize["numberOfDisks"] = o.NumberOfDisks + } + if !IsNil(o.PowerCycle) { + toSerialize["powerCycle"] = o.PowerCycle + } + toSerialize["type"] = o.Type + return toSerialize, nil +} + +func (o *ConfigureHardwareRaidOpts) UnmarshalJSON(data []byte) (err error) { + // This validates that all required properties are included in the JSON object + // by unmarshalling the object into a generic map with string keys and checking + // that every required field exists as a key in the generic map. + requiredProperties := []string{ + "type", + } + + allProperties := make(map[string]interface{}) + + err = json.Unmarshal(data, &allProperties) + + if err != nil { + return err; + } + + for _, requiredProperty := range(requiredProperties) { + if _, exists := allProperties[requiredProperty]; !exists { + return fmt.Errorf("no value given for required property %v", requiredProperty) + } + } + + varConfigureHardwareRaidOpts := _ConfigureHardwareRaidOpts{} + + decoder := json.NewDecoder(bytes.NewReader(data)) + decoder.DisallowUnknownFields() + err = decoder.Decode(&varConfigureHardwareRaidOpts) + + if err != nil { + return err + } + + *o = ConfigureHardwareRaidOpts(varConfigureHardwareRaidOpts) + + return err +} + +type NullableConfigureHardwareRaidOpts struct { + value *ConfigureHardwareRaidOpts + isSet bool +} + +func (v NullableConfigureHardwareRaidOpts) Get() *ConfigureHardwareRaidOpts { + return v.value +} + +func (v *NullableConfigureHardwareRaidOpts) Set(val *ConfigureHardwareRaidOpts) { + v.value = val + v.isSet = true +} + +func (v NullableConfigureHardwareRaidOpts) IsSet() bool { + return v.isSet +} + +func (v *NullableConfigureHardwareRaidOpts) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableConfigureHardwareRaidOpts(val *ConfigureHardwareRaidOpts) *NullableConfigureHardwareRaidOpts { + return &NullableConfigureHardwareRaidOpts{value: val, isSet: true} +} + +func (v NullableConfigureHardwareRaidOpts) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableConfigureHardwareRaidOpts) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/bmp/model_control_panel.go b/bmp/model_control_panel.go new file mode 100644 index 0000000..0a81d7e --- /dev/null +++ b/bmp/model_control_panel.go @@ -0,0 +1,165 @@ +/* +bmp + +This documents the rest api bmp api provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package bmp + +import ( + "encoding/json" +) + +// checks if the ControlPanel type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &ControlPanel{} + +// ControlPanel A single control panel +type ControlPanel struct { + // The unique ID of this control panel + Id *string `json:"id,omitempty"` + // A human readable name describing the control panel + Name *string `json:"name,omitempty"` +} + +// NewControlPanel instantiates a new ControlPanel object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewControlPanel() *ControlPanel { + this := ControlPanel{} + return &this +} + +// NewControlPanelWithDefaults instantiates a new ControlPanel object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewControlPanelWithDefaults() *ControlPanel { + this := ControlPanel{} + return &this +} + +// GetId returns the Id field value if set, zero value otherwise. +func (o *ControlPanel) GetId() string { + if o == nil || IsNil(o.Id) { + var ret string + return ret + } + return *o.Id +} + +// GetIdOk returns a tuple with the Id field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ControlPanel) GetIdOk() (*string, bool) { + if o == nil || IsNil(o.Id) { + return nil, false + } + return o.Id, true +} + +// HasId returns a boolean if a field has been set. +func (o *ControlPanel) HasId() bool { + if o != nil && !IsNil(o.Id) { + return true + } + + return false +} + +// SetId gets a reference to the given string and assigns it to the Id field. +func (o *ControlPanel) SetId(v string) { + o.Id = &v +} + +// GetName returns the Name field value if set, zero value otherwise. +func (o *ControlPanel) GetName() string { + if o == nil || IsNil(o.Name) { + var ret string + return ret + } + return *o.Name +} + +// GetNameOk returns a tuple with the Name field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ControlPanel) GetNameOk() (*string, bool) { + if o == nil || IsNil(o.Name) { + return nil, false + } + return o.Name, true +} + +// HasName returns a boolean if a field has been set. +func (o *ControlPanel) HasName() bool { + if o != nil && !IsNil(o.Name) { + return true + } + + return false +} + +// SetName gets a reference to the given string and assigns it to the Name field. +func (o *ControlPanel) SetName(v string) { + o.Name = &v +} + +func (o ControlPanel) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o ControlPanel) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Id) { + toSerialize["id"] = o.Id + } + if !IsNil(o.Name) { + toSerialize["name"] = o.Name + } + return toSerialize, nil +} + +type NullableControlPanel struct { + value *ControlPanel + isSet bool +} + +func (v NullableControlPanel) Get() *ControlPanel { + return v.value +} + +func (v *NullableControlPanel) Set(val *ControlPanel) { + v.value = val + v.isSet = true +} + +func (v NullableControlPanel) IsSet() bool { + return v.isSet +} + +func (v *NullableControlPanel) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableControlPanel(val *ControlPanel) *NullableControlPanel { + return &NullableControlPanel{value: val, isSet: true} +} + +func (v NullableControlPanel) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableControlPanel) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/bmp/model_control_panel_list.go b/bmp/model_control_panel_list.go new file mode 100644 index 0000000..3123bc6 --- /dev/null +++ b/bmp/model_control_panel_list.go @@ -0,0 +1,164 @@ +/* +bmp + +This documents the rest api bmp api provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package bmp + +import ( + "encoding/json" +) + +// checks if the ControlPanelList type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &ControlPanelList{} + +// ControlPanelList struct for ControlPanelList +type ControlPanelList struct { + Metadata *Metadata `json:"_metadata,omitempty"` + // A list of control panels + ControlPanels []ControlPanel `json:"controlPanels,omitempty"` +} + +// NewControlPanelList instantiates a new ControlPanelList object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewControlPanelList() *ControlPanelList { + this := ControlPanelList{} + return &this +} + +// NewControlPanelListWithDefaults instantiates a new ControlPanelList object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewControlPanelListWithDefaults() *ControlPanelList { + this := ControlPanelList{} + return &this +} + +// GetMetadata returns the Metadata field value if set, zero value otherwise. +func (o *ControlPanelList) GetMetadata() Metadata { + if o == nil || IsNil(o.Metadata) { + var ret Metadata + return ret + } + return *o.Metadata +} + +// GetMetadataOk returns a tuple with the Metadata field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ControlPanelList) GetMetadataOk() (*Metadata, bool) { + if o == nil || IsNil(o.Metadata) { + return nil, false + } + return o.Metadata, true +} + +// HasMetadata returns a boolean if a field has been set. +func (o *ControlPanelList) HasMetadata() bool { + if o != nil && !IsNil(o.Metadata) { + return true + } + + return false +} + +// SetMetadata gets a reference to the given Metadata and assigns it to the Metadata field. +func (o *ControlPanelList) SetMetadata(v Metadata) { + o.Metadata = &v +} + +// GetControlPanels returns the ControlPanels field value if set, zero value otherwise. +func (o *ControlPanelList) GetControlPanels() []ControlPanel { + if o == nil || IsNil(o.ControlPanels) { + var ret []ControlPanel + return ret + } + return o.ControlPanels +} + +// GetControlPanelsOk returns a tuple with the ControlPanels field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ControlPanelList) GetControlPanelsOk() ([]ControlPanel, bool) { + if o == nil || IsNil(o.ControlPanels) { + return nil, false + } + return o.ControlPanels, true +} + +// HasControlPanels returns a boolean if a field has been set. +func (o *ControlPanelList) HasControlPanels() bool { + if o != nil && !IsNil(o.ControlPanels) { + return true + } + + return false +} + +// SetControlPanels gets a reference to the given []ControlPanel and assigns it to the ControlPanels field. +func (o *ControlPanelList) SetControlPanels(v []ControlPanel) { + o.ControlPanels = v +} + +func (o ControlPanelList) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o ControlPanelList) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Metadata) { + toSerialize["_metadata"] = o.Metadata + } + if !IsNil(o.ControlPanels) { + toSerialize["controlPanels"] = o.ControlPanels + } + return toSerialize, nil +} + +type NullableControlPanelList struct { + value *ControlPanelList + isSet bool +} + +func (v NullableControlPanelList) Get() *ControlPanelList { + return v.value +} + +func (v *NullableControlPanelList) Set(val *ControlPanelList) { + v.value = val + v.isSet = true +} + +func (v NullableControlPanelList) IsSet() bool { + return v.isSet +} + +func (v *NullableControlPanelList) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableControlPanelList(val *ControlPanelList) *NullableControlPanelList { + return &NullableControlPanelList{value: val, isSet: true} +} + +func (v NullableControlPanelList) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableControlPanelList) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/bmp/model_create_network_equipment_credential_opts.go b/bmp/model_create_network_equipment_credential_opts.go new file mode 100644 index 0000000..d20d80f --- /dev/null +++ b/bmp/model_create_network_equipment_credential_opts.go @@ -0,0 +1,217 @@ +/* +bmp + +This documents the rest api bmp api provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package bmp + +import ( + "encoding/json" + "bytes" + "fmt" +) + +// checks if the CreateNetworkEquipmentCredentialOpts type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &CreateNetworkEquipmentCredentialOpts{} + +// CreateNetworkEquipmentCredentialOpts struct for CreateNetworkEquipmentCredentialOpts +type CreateNetworkEquipmentCredentialOpts struct { + // The password for the credentials + Password string `json:"password"` + Type CredentialType `json:"type"` + // The username for the credentials + Username string `json:"username"` +} + +type _CreateNetworkEquipmentCredentialOpts CreateNetworkEquipmentCredentialOpts + +// NewCreateNetworkEquipmentCredentialOpts instantiates a new CreateNetworkEquipmentCredentialOpts object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewCreateNetworkEquipmentCredentialOpts(password string, type_ CredentialType, username string) *CreateNetworkEquipmentCredentialOpts { + this := CreateNetworkEquipmentCredentialOpts{} + this.Password = password + this.Type = type_ + this.Username = username + return &this +} + +// NewCreateNetworkEquipmentCredentialOptsWithDefaults instantiates a new CreateNetworkEquipmentCredentialOpts object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewCreateNetworkEquipmentCredentialOptsWithDefaults() *CreateNetworkEquipmentCredentialOpts { + this := CreateNetworkEquipmentCredentialOpts{} + return &this +} + +// GetPassword returns the Password field value +func (o *CreateNetworkEquipmentCredentialOpts) GetPassword() string { + if o == nil { + var ret string + return ret + } + + return o.Password +} + +// GetPasswordOk returns a tuple with the Password field value +// and a boolean to check if the value has been set. +func (o *CreateNetworkEquipmentCredentialOpts) GetPasswordOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.Password, true +} + +// SetPassword sets field value +func (o *CreateNetworkEquipmentCredentialOpts) SetPassword(v string) { + o.Password = v +} + +// GetType returns the Type field value +func (o *CreateNetworkEquipmentCredentialOpts) GetType() CredentialType { + if o == nil { + var ret CredentialType + return ret + } + + return o.Type +} + +// GetTypeOk returns a tuple with the Type field value +// and a boolean to check if the value has been set. +func (o *CreateNetworkEquipmentCredentialOpts) GetTypeOk() (*CredentialType, bool) { + if o == nil { + return nil, false + } + return &o.Type, true +} + +// SetType sets field value +func (o *CreateNetworkEquipmentCredentialOpts) SetType(v CredentialType) { + o.Type = v +} + +// GetUsername returns the Username field value +func (o *CreateNetworkEquipmentCredentialOpts) GetUsername() string { + if o == nil { + var ret string + return ret + } + + return o.Username +} + +// GetUsernameOk returns a tuple with the Username field value +// and a boolean to check if the value has been set. +func (o *CreateNetworkEquipmentCredentialOpts) GetUsernameOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.Username, true +} + +// SetUsername sets field value +func (o *CreateNetworkEquipmentCredentialOpts) SetUsername(v string) { + o.Username = v +} + +func (o CreateNetworkEquipmentCredentialOpts) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o CreateNetworkEquipmentCredentialOpts) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + toSerialize["password"] = o.Password + toSerialize["type"] = o.Type + toSerialize["username"] = o.Username + return toSerialize, nil +} + +func (o *CreateNetworkEquipmentCredentialOpts) UnmarshalJSON(data []byte) (err error) { + // This validates that all required properties are included in the JSON object + // by unmarshalling the object into a generic map with string keys and checking + // that every required field exists as a key in the generic map. + requiredProperties := []string{ + "password", + "type", + "username", + } + + allProperties := make(map[string]interface{}) + + err = json.Unmarshal(data, &allProperties) + + if err != nil { + return err; + } + + for _, requiredProperty := range(requiredProperties) { + if _, exists := allProperties[requiredProperty]; !exists { + return fmt.Errorf("no value given for required property %v", requiredProperty) + } + } + + varCreateNetworkEquipmentCredentialOpts := _CreateNetworkEquipmentCredentialOpts{} + + decoder := json.NewDecoder(bytes.NewReader(data)) + decoder.DisallowUnknownFields() + err = decoder.Decode(&varCreateNetworkEquipmentCredentialOpts) + + if err != nil { + return err + } + + *o = CreateNetworkEquipmentCredentialOpts(varCreateNetworkEquipmentCredentialOpts) + + return err +} + +type NullableCreateNetworkEquipmentCredentialOpts struct { + value *CreateNetworkEquipmentCredentialOpts + isSet bool +} + +func (v NullableCreateNetworkEquipmentCredentialOpts) Get() *CreateNetworkEquipmentCredentialOpts { + return v.value +} + +func (v *NullableCreateNetworkEquipmentCredentialOpts) Set(val *CreateNetworkEquipmentCredentialOpts) { + v.value = val + v.isSet = true +} + +func (v NullableCreateNetworkEquipmentCredentialOpts) IsSet() bool { + return v.isSet +} + +func (v *NullableCreateNetworkEquipmentCredentialOpts) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableCreateNetworkEquipmentCredentialOpts(val *CreateNetworkEquipmentCredentialOpts) *NullableCreateNetworkEquipmentCredentialOpts { + return &NullableCreateNetworkEquipmentCredentialOpts{value: val, isSet: true} +} + +func (v NullableCreateNetworkEquipmentCredentialOpts) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableCreateNetworkEquipmentCredentialOpts) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/bmp/model_create_server_credential_opts.go b/bmp/model_create_server_credential_opts.go new file mode 100644 index 0000000..a4246da --- /dev/null +++ b/bmp/model_create_server_credential_opts.go @@ -0,0 +1,217 @@ +/* +bmp + +This documents the rest api bmp api provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package bmp + +import ( + "encoding/json" + "bytes" + "fmt" +) + +// checks if the CreateServerCredentialOpts type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &CreateServerCredentialOpts{} + +// CreateServerCredentialOpts struct for CreateServerCredentialOpts +type CreateServerCredentialOpts struct { + // The password for the credentials + Password string `json:"password"` + Type CredentialType `json:"type"` + // The username for the credentials + Username string `json:"username"` +} + +type _CreateServerCredentialOpts CreateServerCredentialOpts + +// NewCreateServerCredentialOpts instantiates a new CreateServerCredentialOpts object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewCreateServerCredentialOpts(password string, type_ CredentialType, username string) *CreateServerCredentialOpts { + this := CreateServerCredentialOpts{} + this.Password = password + this.Type = type_ + this.Username = username + return &this +} + +// NewCreateServerCredentialOptsWithDefaults instantiates a new CreateServerCredentialOpts object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewCreateServerCredentialOptsWithDefaults() *CreateServerCredentialOpts { + this := CreateServerCredentialOpts{} + return &this +} + +// GetPassword returns the Password field value +func (o *CreateServerCredentialOpts) GetPassword() string { + if o == nil { + var ret string + return ret + } + + return o.Password +} + +// GetPasswordOk returns a tuple with the Password field value +// and a boolean to check if the value has been set. +func (o *CreateServerCredentialOpts) GetPasswordOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.Password, true +} + +// SetPassword sets field value +func (o *CreateServerCredentialOpts) SetPassword(v string) { + o.Password = v +} + +// GetType returns the Type field value +func (o *CreateServerCredentialOpts) GetType() CredentialType { + if o == nil { + var ret CredentialType + return ret + } + + return o.Type +} + +// GetTypeOk returns a tuple with the Type field value +// and a boolean to check if the value has been set. +func (o *CreateServerCredentialOpts) GetTypeOk() (*CredentialType, bool) { + if o == nil { + return nil, false + } + return &o.Type, true +} + +// SetType sets field value +func (o *CreateServerCredentialOpts) SetType(v CredentialType) { + o.Type = v +} + +// GetUsername returns the Username field value +func (o *CreateServerCredentialOpts) GetUsername() string { + if o == nil { + var ret string + return ret + } + + return o.Username +} + +// GetUsernameOk returns a tuple with the Username field value +// and a boolean to check if the value has been set. +func (o *CreateServerCredentialOpts) GetUsernameOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.Username, true +} + +// SetUsername sets field value +func (o *CreateServerCredentialOpts) SetUsername(v string) { + o.Username = v +} + +func (o CreateServerCredentialOpts) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o CreateServerCredentialOpts) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + toSerialize["password"] = o.Password + toSerialize["type"] = o.Type + toSerialize["username"] = o.Username + return toSerialize, nil +} + +func (o *CreateServerCredentialOpts) UnmarshalJSON(data []byte) (err error) { + // This validates that all required properties are included in the JSON object + // by unmarshalling the object into a generic map with string keys and checking + // that every required field exists as a key in the generic map. + requiredProperties := []string{ + "password", + "type", + "username", + } + + allProperties := make(map[string]interface{}) + + err = json.Unmarshal(data, &allProperties) + + if err != nil { + return err; + } + + for _, requiredProperty := range(requiredProperties) { + if _, exists := allProperties[requiredProperty]; !exists { + return fmt.Errorf("no value given for required property %v", requiredProperty) + } + } + + varCreateServerCredentialOpts := _CreateServerCredentialOpts{} + + decoder := json.NewDecoder(bytes.NewReader(data)) + decoder.DisallowUnknownFields() + err = decoder.Decode(&varCreateServerCredentialOpts) + + if err != nil { + return err + } + + *o = CreateServerCredentialOpts(varCreateServerCredentialOpts) + + return err +} + +type NullableCreateServerCredentialOpts struct { + value *CreateServerCredentialOpts + isSet bool +} + +func (v NullableCreateServerCredentialOpts) Get() *CreateServerCredentialOpts { + return v.value +} + +func (v *NullableCreateServerCredentialOpts) Set(val *CreateServerCredentialOpts) { + v.value = val + v.isSet = true +} + +func (v NullableCreateServerCredentialOpts) IsSet() bool { + return v.isSet +} + +func (v *NullableCreateServerCredentialOpts) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableCreateServerCredentialOpts(val *CreateServerCredentialOpts) *NullableCreateServerCredentialOpts { + return &NullableCreateServerCredentialOpts{value: val, isSet: true} +} + +func (v NullableCreateServerCredentialOpts) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableCreateServerCredentialOpts) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/bmp/model_create_server_dhcp_reservation_opts.go b/bmp/model_create_server_dhcp_reservation_opts.go new file mode 100644 index 0000000..fddbb6e --- /dev/null +++ b/bmp/model_create_server_dhcp_reservation_opts.go @@ -0,0 +1,197 @@ +/* +bmp + +This documents the rest api bmp api provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package bmp + +import ( + "encoding/json" + "bytes" + "fmt" +) + +// checks if the CreateServerDhcpReservationOpts type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &CreateServerDhcpReservationOpts{} + +// CreateServerDhcpReservationOpts struct for CreateServerDhcpReservationOpts +type CreateServerDhcpReservationOpts struct { + // The URL of PXE boot you want your server to boot from + Bootfile string `json:"bootfile"` + // The hostname for the server + Hostname *string `json:"hostname,omitempty"` +} + +type _CreateServerDhcpReservationOpts CreateServerDhcpReservationOpts + +// NewCreateServerDhcpReservationOpts instantiates a new CreateServerDhcpReservationOpts object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewCreateServerDhcpReservationOpts(bootfile string) *CreateServerDhcpReservationOpts { + this := CreateServerDhcpReservationOpts{} + this.Bootfile = bootfile + return &this +} + +// NewCreateServerDhcpReservationOptsWithDefaults instantiates a new CreateServerDhcpReservationOpts object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewCreateServerDhcpReservationOptsWithDefaults() *CreateServerDhcpReservationOpts { + this := CreateServerDhcpReservationOpts{} + return &this +} + +// GetBootfile returns the Bootfile field value +func (o *CreateServerDhcpReservationOpts) GetBootfile() string { + if o == nil { + var ret string + return ret + } + + return o.Bootfile +} + +// GetBootfileOk returns a tuple with the Bootfile field value +// and a boolean to check if the value has been set. +func (o *CreateServerDhcpReservationOpts) GetBootfileOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.Bootfile, true +} + +// SetBootfile sets field value +func (o *CreateServerDhcpReservationOpts) SetBootfile(v string) { + o.Bootfile = v +} + +// GetHostname returns the Hostname field value if set, zero value otherwise. +func (o *CreateServerDhcpReservationOpts) GetHostname() string { + if o == nil || IsNil(o.Hostname) { + var ret string + return ret + } + return *o.Hostname +} + +// GetHostnameOk returns a tuple with the Hostname field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *CreateServerDhcpReservationOpts) GetHostnameOk() (*string, bool) { + if o == nil || IsNil(o.Hostname) { + return nil, false + } + return o.Hostname, true +} + +// HasHostname returns a boolean if a field has been set. +func (o *CreateServerDhcpReservationOpts) HasHostname() bool { + if o != nil && !IsNil(o.Hostname) { + return true + } + + return false +} + +// SetHostname gets a reference to the given string and assigns it to the Hostname field. +func (o *CreateServerDhcpReservationOpts) SetHostname(v string) { + o.Hostname = &v +} + +func (o CreateServerDhcpReservationOpts) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o CreateServerDhcpReservationOpts) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + toSerialize["bootfile"] = o.Bootfile + if !IsNil(o.Hostname) { + toSerialize["hostname"] = o.Hostname + } + return toSerialize, nil +} + +func (o *CreateServerDhcpReservationOpts) UnmarshalJSON(data []byte) (err error) { + // This validates that all required properties are included in the JSON object + // by unmarshalling the object into a generic map with string keys and checking + // that every required field exists as a key in the generic map. + requiredProperties := []string{ + "bootfile", + } + + allProperties := make(map[string]interface{}) + + err = json.Unmarshal(data, &allProperties) + + if err != nil { + return err; + } + + for _, requiredProperty := range(requiredProperties) { + if _, exists := allProperties[requiredProperty]; !exists { + return fmt.Errorf("no value given for required property %v", requiredProperty) + } + } + + varCreateServerDhcpReservationOpts := _CreateServerDhcpReservationOpts{} + + decoder := json.NewDecoder(bytes.NewReader(data)) + decoder.DisallowUnknownFields() + err = decoder.Decode(&varCreateServerDhcpReservationOpts) + + if err != nil { + return err + } + + *o = CreateServerDhcpReservationOpts(varCreateServerDhcpReservationOpts) + + return err +} + +type NullableCreateServerDhcpReservationOpts struct { + value *CreateServerDhcpReservationOpts + isSet bool +} + +func (v NullableCreateServerDhcpReservationOpts) Get() *CreateServerDhcpReservationOpts { + return v.value +} + +func (v *NullableCreateServerDhcpReservationOpts) Set(val *CreateServerDhcpReservationOpts) { + v.value = val + v.isSet = true +} + +func (v NullableCreateServerDhcpReservationOpts) IsSet() bool { + return v.isSet +} + +func (v *NullableCreateServerDhcpReservationOpts) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableCreateServerDhcpReservationOpts(val *CreateServerDhcpReservationOpts) *NullableCreateServerDhcpReservationOpts { + return &NullableCreateServerDhcpReservationOpts{value: val, isSet: true} +} + +func (v NullableCreateServerDhcpReservationOpts) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableCreateServerDhcpReservationOpts) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/bmp/model_credential.go b/bmp/model_credential.go new file mode 100644 index 0000000..e271164 --- /dev/null +++ b/bmp/model_credential.go @@ -0,0 +1,201 @@ +/* +bmp + +This documents the rest api bmp api provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package bmp + +import ( + "encoding/json" +) + +// checks if the Credential type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &Credential{} + +// Credential struct for Credential +type Credential struct { + // The password + Password *string `json:"password,omitempty"` + Type *CredentialType `json:"type,omitempty"` + // The username + Username *string `json:"username,omitempty"` +} + +// NewCredential instantiates a new Credential object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewCredential() *Credential { + this := Credential{} + return &this +} + +// NewCredentialWithDefaults instantiates a new Credential object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewCredentialWithDefaults() *Credential { + this := Credential{} + return &this +} + +// GetPassword returns the Password field value if set, zero value otherwise. +func (o *Credential) GetPassword() string { + if o == nil || IsNil(o.Password) { + var ret string + return ret + } + return *o.Password +} + +// GetPasswordOk returns a tuple with the Password field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Credential) GetPasswordOk() (*string, bool) { + if o == nil || IsNil(o.Password) { + return nil, false + } + return o.Password, true +} + +// HasPassword returns a boolean if a field has been set. +func (o *Credential) HasPassword() bool { + if o != nil && !IsNil(o.Password) { + return true + } + + return false +} + +// SetPassword gets a reference to the given string and assigns it to the Password field. +func (o *Credential) SetPassword(v string) { + o.Password = &v +} + +// GetType returns the Type field value if set, zero value otherwise. +func (o *Credential) GetType() CredentialType { + if o == nil || IsNil(o.Type) { + var ret CredentialType + return ret + } + return *o.Type +} + +// GetTypeOk returns a tuple with the Type field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Credential) GetTypeOk() (*CredentialType, bool) { + if o == nil || IsNil(o.Type) { + return nil, false + } + return o.Type, true +} + +// HasType returns a boolean if a field has been set. +func (o *Credential) HasType() bool { + if o != nil && !IsNil(o.Type) { + return true + } + + return false +} + +// SetType gets a reference to the given CredentialType and assigns it to the Type field. +func (o *Credential) SetType(v CredentialType) { + o.Type = &v +} + +// GetUsername returns the Username field value if set, zero value otherwise. +func (o *Credential) GetUsername() string { + if o == nil || IsNil(o.Username) { + var ret string + return ret + } + return *o.Username +} + +// GetUsernameOk returns a tuple with the Username field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Credential) GetUsernameOk() (*string, bool) { + if o == nil || IsNil(o.Username) { + return nil, false + } + return o.Username, true +} + +// HasUsername returns a boolean if a field has been set. +func (o *Credential) HasUsername() bool { + if o != nil && !IsNil(o.Username) { + return true + } + + return false +} + +// SetUsername gets a reference to the given string and assigns it to the Username field. +func (o *Credential) SetUsername(v string) { + o.Username = &v +} + +func (o Credential) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o Credential) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Password) { + toSerialize["password"] = o.Password + } + if !IsNil(o.Type) { + toSerialize["type"] = o.Type + } + if !IsNil(o.Username) { + toSerialize["username"] = o.Username + } + return toSerialize, nil +} + +type NullableCredential struct { + value *Credential + isSet bool +} + +func (v NullableCredential) Get() *Credential { + return v.value +} + +func (v *NullableCredential) Set(val *Credential) { + v.value = val + v.isSet = true +} + +func (v NullableCredential) IsSet() bool { + return v.isSet +} + +func (v *NullableCredential) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableCredential(val *Credential) *NullableCredential { + return &NullableCredential{value: val, isSet: true} +} + +func (v NullableCredential) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableCredential) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/bmp/model_credential_list.go b/bmp/model_credential_list.go new file mode 100644 index 0000000..9afc34f --- /dev/null +++ b/bmp/model_credential_list.go @@ -0,0 +1,164 @@ +/* +bmp + +This documents the rest api bmp api provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package bmp + +import ( + "encoding/json" +) + +// checks if the CredentialList type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &CredentialList{} + +// CredentialList struct for CredentialList +type CredentialList struct { + Metadata *Metadata `json:"_metadata,omitempty"` + // An array of credentials + Credentials []Credential `json:"credentials,omitempty"` +} + +// NewCredentialList instantiates a new CredentialList object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewCredentialList() *CredentialList { + this := CredentialList{} + return &this +} + +// NewCredentialListWithDefaults instantiates a new CredentialList object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewCredentialListWithDefaults() *CredentialList { + this := CredentialList{} + return &this +} + +// GetMetadata returns the Metadata field value if set, zero value otherwise. +func (o *CredentialList) GetMetadata() Metadata { + if o == nil || IsNil(o.Metadata) { + var ret Metadata + return ret + } + return *o.Metadata +} + +// GetMetadataOk returns a tuple with the Metadata field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *CredentialList) GetMetadataOk() (*Metadata, bool) { + if o == nil || IsNil(o.Metadata) { + return nil, false + } + return o.Metadata, true +} + +// HasMetadata returns a boolean if a field has been set. +func (o *CredentialList) HasMetadata() bool { + if o != nil && !IsNil(o.Metadata) { + return true + } + + return false +} + +// SetMetadata gets a reference to the given Metadata and assigns it to the Metadata field. +func (o *CredentialList) SetMetadata(v Metadata) { + o.Metadata = &v +} + +// GetCredentials returns the Credentials field value if set, zero value otherwise. +func (o *CredentialList) GetCredentials() []Credential { + if o == nil || IsNil(o.Credentials) { + var ret []Credential + return ret + } + return o.Credentials +} + +// GetCredentialsOk returns a tuple with the Credentials field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *CredentialList) GetCredentialsOk() ([]Credential, bool) { + if o == nil || IsNil(o.Credentials) { + return nil, false + } + return o.Credentials, true +} + +// HasCredentials returns a boolean if a field has been set. +func (o *CredentialList) HasCredentials() bool { + if o != nil && !IsNil(o.Credentials) { + return true + } + + return false +} + +// SetCredentials gets a reference to the given []Credential and assigns it to the Credentials field. +func (o *CredentialList) SetCredentials(v []Credential) { + o.Credentials = v +} + +func (o CredentialList) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o CredentialList) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Metadata) { + toSerialize["_metadata"] = o.Metadata + } + if !IsNil(o.Credentials) { + toSerialize["credentials"] = o.Credentials + } + return toSerialize, nil +} + +type NullableCredentialList struct { + value *CredentialList + isSet bool +} + +func (v NullableCredentialList) Get() *CredentialList { + return v.value +} + +func (v *NullableCredentialList) Set(val *CredentialList) { + v.value = val + v.isSet = true +} + +func (v NullableCredentialList) IsSet() bool { + return v.isSet +} + +func (v *NullableCredentialList) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableCredentialList(val *CredentialList) *NullableCredentialList { + return &NullableCredentialList{value: val, isSet: true} +} + +func (v NullableCredentialList) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableCredentialList) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/bmp/model_credential_type.go b/bmp/model_credential_type.go new file mode 100644 index 0000000..937754c --- /dev/null +++ b/bmp/model_credential_type.go @@ -0,0 +1,124 @@ +/* +bmp + +This documents the rest api bmp api provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package bmp + +import ( + "encoding/json" + "fmt" +) + +// CredentialType The type of the credential +type CredentialType string + +// List of credentialType +const ( + OPERATING_SYSTEM CredentialType = "OPERATING_SYSTEM" + CONTROL_PANEL CredentialType = "CONTROL_PANEL" + REMOTE_MANAGEMENT CredentialType = "REMOTE_MANAGEMENT" + RESCUE_MODE CredentialType = "RESCUE_MODE" + SWITCH CredentialType = "SWITCH" + PDU CredentialType = "PDU" + FIREWALL CredentialType = "FIREWALL" + LOAD_BALANCER CredentialType = "LOAD_BALANCER" +) + +// All allowed values of CredentialType enum +var AllowedCredentialTypeEnumValues = []CredentialType{ + "OPERATING_SYSTEM", + "CONTROL_PANEL", + "REMOTE_MANAGEMENT", + "RESCUE_MODE", + "SWITCH", + "PDU", + "FIREWALL", + "LOAD_BALANCER", +} + +func (v *CredentialType) UnmarshalJSON(src []byte) error { + var value string + err := json.Unmarshal(src, &value) + if err != nil { + return err + } + enumTypeValue := CredentialType(value) + for _, existing := range AllowedCredentialTypeEnumValues { + if existing == enumTypeValue { + *v = enumTypeValue + return nil + } + } + + return fmt.Errorf("%+v is not a valid CredentialType", value) +} + +// NewCredentialTypeFromValue returns a pointer to a valid CredentialType +// for the value passed as argument, or an error if the value passed is not allowed by the enum +func NewCredentialTypeFromValue(v string) (*CredentialType, error) { + ev := CredentialType(v) + if ev.IsValid() { + return &ev, nil + } else { + return nil, fmt.Errorf("invalid value '%v' for CredentialType: valid values are %v", v, AllowedCredentialTypeEnumValues) + } +} + +// IsValid return true if the value is valid for the enum, false otherwise +func (v CredentialType) IsValid() bool { + for _, existing := range AllowedCredentialTypeEnumValues { + if existing == v { + return true + } + } + return false +} + +// Ptr returns reference to credentialType value +func (v CredentialType) Ptr() *CredentialType { + return &v +} + +type NullableCredentialType struct { + value *CredentialType + isSet bool +} + +func (v NullableCredentialType) Get() *CredentialType { + return v.value +} + +func (v *NullableCredentialType) Set(val *CredentialType) { + v.value = val + v.isSet = true +} + +func (v NullableCredentialType) IsSet() bool { + return v.isSet +} + +func (v *NullableCredentialType) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableCredentialType(val *CredentialType) *NullableCredentialType { + return &NullableCredentialType{value: val, isSet: true} +} + +func (v NullableCredentialType) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableCredentialType) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + diff --git a/bmp/model_defaults.go b/bmp/model_defaults.go new file mode 100644 index 0000000..bf2b029 --- /dev/null +++ b/bmp/model_defaults.go @@ -0,0 +1,164 @@ +/* +bmp + +This documents the rest api bmp api provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package bmp + +import ( + "encoding/json" +) + +// checks if the Defaults type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &Defaults{} + +// Defaults An object containing defaults for this operating system +type Defaults struct { + // Device name + Device *string `json:"device,omitempty"` + Partitions []Partition `json:"partitions,omitempty"` +} + +// NewDefaults instantiates a new Defaults object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewDefaults() *Defaults { + this := Defaults{} + return &this +} + +// NewDefaultsWithDefaults instantiates a new Defaults object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewDefaultsWithDefaults() *Defaults { + this := Defaults{} + return &this +} + +// GetDevice returns the Device field value if set, zero value otherwise. +func (o *Defaults) GetDevice() string { + if o == nil || IsNil(o.Device) { + var ret string + return ret + } + return *o.Device +} + +// GetDeviceOk returns a tuple with the Device field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Defaults) GetDeviceOk() (*string, bool) { + if o == nil || IsNil(o.Device) { + return nil, false + } + return o.Device, true +} + +// HasDevice returns a boolean if a field has been set. +func (o *Defaults) HasDevice() bool { + if o != nil && !IsNil(o.Device) { + return true + } + + return false +} + +// SetDevice gets a reference to the given string and assigns it to the Device field. +func (o *Defaults) SetDevice(v string) { + o.Device = &v +} + +// GetPartitions returns the Partitions field value if set, zero value otherwise. +func (o *Defaults) GetPartitions() []Partition { + if o == nil || IsNil(o.Partitions) { + var ret []Partition + return ret + } + return o.Partitions +} + +// GetPartitionsOk returns a tuple with the Partitions field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Defaults) GetPartitionsOk() ([]Partition, bool) { + if o == nil || IsNil(o.Partitions) { + return nil, false + } + return o.Partitions, true +} + +// HasPartitions returns a boolean if a field has been set. +func (o *Defaults) HasPartitions() bool { + if o != nil && !IsNil(o.Partitions) { + return true + } + + return false +} + +// SetPartitions gets a reference to the given []Partition and assigns it to the Partitions field. +func (o *Defaults) SetPartitions(v []Partition) { + o.Partitions = v +} + +func (o Defaults) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o Defaults) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Device) { + toSerialize["device"] = o.Device + } + if !IsNil(o.Partitions) { + toSerialize["partitions"] = o.Partitions + } + return toSerialize, nil +} + +type NullableDefaults struct { + value *Defaults + isSet bool +} + +func (v NullableDefaults) Get() *Defaults { + return v.value +} + +func (v *NullableDefaults) Set(val *Defaults) { + v.value = val + v.isSet = true +} + +func (v NullableDefaults) IsSet() bool { + return v.isSet +} + +func (v *NullableDefaults) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableDefaults(val *Defaults) *NullableDefaults { + return &NullableDefaults{value: val, isSet: true} +} + +func (v NullableDefaults) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableDefaults) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/bmp/model_enable_server_rescue_mode_opts.go b/bmp/model_enable_server_rescue_mode_opts.go new file mode 100644 index 0000000..33a7883 --- /dev/null +++ b/bmp/model_enable_server_rescue_mode_opts.go @@ -0,0 +1,351 @@ +/* +bmp + +This documents the rest api bmp api provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package bmp + +import ( + "encoding/json" + "bytes" + "fmt" +) + +// checks if the EnableServerRescueModeOpts type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &EnableServerRescueModeOpts{} + +// EnableServerRescueModeOpts struct for EnableServerRescueModeOpts +type EnableServerRescueModeOpts struct { + // Url which will receive callbacks + CallbackUrl *string `json:"callbackUrl,omitempty"` + // Rescue mode password. If not provided, it would be automatically generated + Password *string `json:"password,omitempty"` + // Base64 Encoded string containing a valid bash script to be run right after rescue mode is launched + PostInstallScript *string `json:"postInstallScript,omitempty"` + // If set to `true`, server will be power cycled in order to complete the operation + PowerCycle *bool `json:"powerCycle,omitempty"` + // Rescue image identifier + RescueImageId string `json:"rescueImageId"` + // User ssh keys + SshKeys *string `json:"sshKeys,omitempty"` +} + +type _EnableServerRescueModeOpts EnableServerRescueModeOpts + +// NewEnableServerRescueModeOpts instantiates a new EnableServerRescueModeOpts object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewEnableServerRescueModeOpts(rescueImageId string) *EnableServerRescueModeOpts { + this := EnableServerRescueModeOpts{} + var powerCycle bool = true + this.PowerCycle = &powerCycle + this.RescueImageId = rescueImageId + return &this +} + +// NewEnableServerRescueModeOptsWithDefaults instantiates a new EnableServerRescueModeOpts object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewEnableServerRescueModeOptsWithDefaults() *EnableServerRescueModeOpts { + this := EnableServerRescueModeOpts{} + var powerCycle bool = true + this.PowerCycle = &powerCycle + var rescueImageId string = "GRML" + this.RescueImageId = rescueImageId + return &this +} + +// GetCallbackUrl returns the CallbackUrl field value if set, zero value otherwise. +func (o *EnableServerRescueModeOpts) GetCallbackUrl() string { + if o == nil || IsNil(o.CallbackUrl) { + var ret string + return ret + } + return *o.CallbackUrl +} + +// GetCallbackUrlOk returns a tuple with the CallbackUrl field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *EnableServerRescueModeOpts) GetCallbackUrlOk() (*string, bool) { + if o == nil || IsNil(o.CallbackUrl) { + return nil, false + } + return o.CallbackUrl, true +} + +// HasCallbackUrl returns a boolean if a field has been set. +func (o *EnableServerRescueModeOpts) HasCallbackUrl() bool { + if o != nil && !IsNil(o.CallbackUrl) { + return true + } + + return false +} + +// SetCallbackUrl gets a reference to the given string and assigns it to the CallbackUrl field. +func (o *EnableServerRescueModeOpts) SetCallbackUrl(v string) { + o.CallbackUrl = &v +} + +// GetPassword returns the Password field value if set, zero value otherwise. +func (o *EnableServerRescueModeOpts) GetPassword() string { + if o == nil || IsNil(o.Password) { + var ret string + return ret + } + return *o.Password +} + +// GetPasswordOk returns a tuple with the Password field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *EnableServerRescueModeOpts) GetPasswordOk() (*string, bool) { + if o == nil || IsNil(o.Password) { + return nil, false + } + return o.Password, true +} + +// HasPassword returns a boolean if a field has been set. +func (o *EnableServerRescueModeOpts) HasPassword() bool { + if o != nil && !IsNil(o.Password) { + return true + } + + return false +} + +// SetPassword gets a reference to the given string and assigns it to the Password field. +func (o *EnableServerRescueModeOpts) SetPassword(v string) { + o.Password = &v +} + +// GetPostInstallScript returns the PostInstallScript field value if set, zero value otherwise. +func (o *EnableServerRescueModeOpts) GetPostInstallScript() string { + if o == nil || IsNil(o.PostInstallScript) { + var ret string + return ret + } + return *o.PostInstallScript +} + +// GetPostInstallScriptOk returns a tuple with the PostInstallScript field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *EnableServerRescueModeOpts) GetPostInstallScriptOk() (*string, bool) { + if o == nil || IsNil(o.PostInstallScript) { + return nil, false + } + return o.PostInstallScript, true +} + +// HasPostInstallScript returns a boolean if a field has been set. +func (o *EnableServerRescueModeOpts) HasPostInstallScript() bool { + if o != nil && !IsNil(o.PostInstallScript) { + return true + } + + return false +} + +// SetPostInstallScript gets a reference to the given string and assigns it to the PostInstallScript field. +func (o *EnableServerRescueModeOpts) SetPostInstallScript(v string) { + o.PostInstallScript = &v +} + +// GetPowerCycle returns the PowerCycle field value if set, zero value otherwise. +func (o *EnableServerRescueModeOpts) GetPowerCycle() bool { + if o == nil || IsNil(o.PowerCycle) { + var ret bool + return ret + } + return *o.PowerCycle +} + +// GetPowerCycleOk returns a tuple with the PowerCycle field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *EnableServerRescueModeOpts) GetPowerCycleOk() (*bool, bool) { + if o == nil || IsNil(o.PowerCycle) { + return nil, false + } + return o.PowerCycle, true +} + +// HasPowerCycle returns a boolean if a field has been set. +func (o *EnableServerRescueModeOpts) HasPowerCycle() bool { + if o != nil && !IsNil(o.PowerCycle) { + return true + } + + return false +} + +// SetPowerCycle gets a reference to the given bool and assigns it to the PowerCycle field. +func (o *EnableServerRescueModeOpts) SetPowerCycle(v bool) { + o.PowerCycle = &v +} + +// GetRescueImageId returns the RescueImageId field value +func (o *EnableServerRescueModeOpts) GetRescueImageId() string { + if o == nil { + var ret string + return ret + } + + return o.RescueImageId +} + +// GetRescueImageIdOk returns a tuple with the RescueImageId field value +// and a boolean to check if the value has been set. +func (o *EnableServerRescueModeOpts) GetRescueImageIdOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.RescueImageId, true +} + +// SetRescueImageId sets field value +func (o *EnableServerRescueModeOpts) SetRescueImageId(v string) { + o.RescueImageId = v +} + +// GetSshKeys returns the SshKeys field value if set, zero value otherwise. +func (o *EnableServerRescueModeOpts) GetSshKeys() string { + if o == nil || IsNil(o.SshKeys) { + var ret string + return ret + } + return *o.SshKeys +} + +// GetSshKeysOk returns a tuple with the SshKeys field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *EnableServerRescueModeOpts) GetSshKeysOk() (*string, bool) { + if o == nil || IsNil(o.SshKeys) { + return nil, false + } + return o.SshKeys, true +} + +// HasSshKeys returns a boolean if a field has been set. +func (o *EnableServerRescueModeOpts) HasSshKeys() bool { + if o != nil && !IsNil(o.SshKeys) { + return true + } + + return false +} + +// SetSshKeys gets a reference to the given string and assigns it to the SshKeys field. +func (o *EnableServerRescueModeOpts) SetSshKeys(v string) { + o.SshKeys = &v +} + +func (o EnableServerRescueModeOpts) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o EnableServerRescueModeOpts) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.CallbackUrl) { + toSerialize["callbackUrl"] = o.CallbackUrl + } + if !IsNil(o.Password) { + toSerialize["password"] = o.Password + } + if !IsNil(o.PostInstallScript) { + toSerialize["postInstallScript"] = o.PostInstallScript + } + if !IsNil(o.PowerCycle) { + toSerialize["powerCycle"] = o.PowerCycle + } + toSerialize["rescueImageId"] = o.RescueImageId + if !IsNil(o.SshKeys) { + toSerialize["sshKeys"] = o.SshKeys + } + return toSerialize, nil +} + +func (o *EnableServerRescueModeOpts) UnmarshalJSON(data []byte) (err error) { + // This validates that all required properties are included in the JSON object + // by unmarshalling the object into a generic map with string keys and checking + // that every required field exists as a key in the generic map. + requiredProperties := []string{ + "rescueImageId", + } + + allProperties := make(map[string]interface{}) + + err = json.Unmarshal(data, &allProperties) + + if err != nil { + return err; + } + + for _, requiredProperty := range(requiredProperties) { + if _, exists := allProperties[requiredProperty]; !exists { + return fmt.Errorf("no value given for required property %v", requiredProperty) + } + } + + varEnableServerRescueModeOpts := _EnableServerRescueModeOpts{} + + decoder := json.NewDecoder(bytes.NewReader(data)) + decoder.DisallowUnknownFields() + err = decoder.Decode(&varEnableServerRescueModeOpts) + + if err != nil { + return err + } + + *o = EnableServerRescueModeOpts(varEnableServerRescueModeOpts) + + return err +} + +type NullableEnableServerRescueModeOpts struct { + value *EnableServerRescueModeOpts + isSet bool +} + +func (v NullableEnableServerRescueModeOpts) Get() *EnableServerRescueModeOpts { + return v.value +} + +func (v *NullableEnableServerRescueModeOpts) Set(val *EnableServerRescueModeOpts) { + v.value = val + v.isSet = true +} + +func (v NullableEnableServerRescueModeOpts) IsSet() bool { + return v.isSet +} + +func (v *NullableEnableServerRescueModeOpts) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableEnableServerRescueModeOpts(val *EnableServerRescueModeOpts) *NullableEnableServerRescueModeOpts { + return &NullableEnableServerRescueModeOpts{value: val, isSet: true} +} + +func (v NullableEnableServerRescueModeOpts) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableEnableServerRescueModeOpts) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/bmp/model_error_result.go b/bmp/model_error_result.go new file mode 100644 index 0000000..bc0cea4 --- /dev/null +++ b/bmp/model_error_result.go @@ -0,0 +1,238 @@ +/* +bmp + +This documents the rest api bmp api provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package bmp + +import ( + "encoding/json" +) + +// checks if the ErrorResult type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &ErrorResult{} + +// ErrorResult struct for ErrorResult +type ErrorResult struct { + // The correlation ID of the current request. + CorrelationId *string `json:"correlationId,omitempty"` + // The error code. + ErrorCode *string `json:"errorCode,omitempty"` + // A human friendly description of the error. + ErrorMessage *string `json:"errorMessage,omitempty"` + ErrorDetails []map[string][]string `json:"errorDetails,omitempty"` +} + +// NewErrorResult instantiates a new ErrorResult object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewErrorResult() *ErrorResult { + this := ErrorResult{} + return &this +} + +// NewErrorResultWithDefaults instantiates a new ErrorResult object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewErrorResultWithDefaults() *ErrorResult { + this := ErrorResult{} + return &this +} + +// GetCorrelationId returns the CorrelationId field value if set, zero value otherwise. +func (o *ErrorResult) GetCorrelationId() string { + if o == nil || IsNil(o.CorrelationId) { + var ret string + return ret + } + return *o.CorrelationId +} + +// GetCorrelationIdOk returns a tuple with the CorrelationId field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ErrorResult) GetCorrelationIdOk() (*string, bool) { + if o == nil || IsNil(o.CorrelationId) { + return nil, false + } + return o.CorrelationId, true +} + +// HasCorrelationId returns a boolean if a field has been set. +func (o *ErrorResult) HasCorrelationId() bool { + if o != nil && !IsNil(o.CorrelationId) { + return true + } + + return false +} + +// SetCorrelationId gets a reference to the given string and assigns it to the CorrelationId field. +func (o *ErrorResult) SetCorrelationId(v string) { + o.CorrelationId = &v +} + +// GetErrorCode returns the ErrorCode field value if set, zero value otherwise. +func (o *ErrorResult) GetErrorCode() string { + if o == nil || IsNil(o.ErrorCode) { + var ret string + return ret + } + return *o.ErrorCode +} + +// GetErrorCodeOk returns a tuple with the ErrorCode field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ErrorResult) GetErrorCodeOk() (*string, bool) { + if o == nil || IsNil(o.ErrorCode) { + return nil, false + } + return o.ErrorCode, true +} + +// HasErrorCode returns a boolean if a field has been set. +func (o *ErrorResult) HasErrorCode() bool { + if o != nil && !IsNil(o.ErrorCode) { + return true + } + + return false +} + +// SetErrorCode gets a reference to the given string and assigns it to the ErrorCode field. +func (o *ErrorResult) SetErrorCode(v string) { + o.ErrorCode = &v +} + +// GetErrorMessage returns the ErrorMessage field value if set, zero value otherwise. +func (o *ErrorResult) GetErrorMessage() string { + if o == nil || IsNil(o.ErrorMessage) { + var ret string + return ret + } + return *o.ErrorMessage +} + +// GetErrorMessageOk returns a tuple with the ErrorMessage field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ErrorResult) GetErrorMessageOk() (*string, bool) { + if o == nil || IsNil(o.ErrorMessage) { + return nil, false + } + return o.ErrorMessage, true +} + +// HasErrorMessage returns a boolean if a field has been set. +func (o *ErrorResult) HasErrorMessage() bool { + if o != nil && !IsNil(o.ErrorMessage) { + return true + } + + return false +} + +// SetErrorMessage gets a reference to the given string and assigns it to the ErrorMessage field. +func (o *ErrorResult) SetErrorMessage(v string) { + o.ErrorMessage = &v +} + +// GetErrorDetails returns the ErrorDetails field value if set, zero value otherwise. +func (o *ErrorResult) GetErrorDetails() []map[string][]string { + if o == nil || IsNil(o.ErrorDetails) { + var ret []map[string][]string + return ret + } + return o.ErrorDetails +} + +// GetErrorDetailsOk returns a tuple with the ErrorDetails field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ErrorResult) GetErrorDetailsOk() ([]map[string][]string, bool) { + if o == nil || IsNil(o.ErrorDetails) { + return nil, false + } + return o.ErrorDetails, true +} + +// HasErrorDetails returns a boolean if a field has been set. +func (o *ErrorResult) HasErrorDetails() bool { + if o != nil && !IsNil(o.ErrorDetails) { + return true + } + + return false +} + +// SetErrorDetails gets a reference to the given []map[string][]string and assigns it to the ErrorDetails field. +func (o *ErrorResult) SetErrorDetails(v []map[string][]string) { + o.ErrorDetails = v +} + +func (o ErrorResult) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o ErrorResult) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.CorrelationId) { + toSerialize["correlationId"] = o.CorrelationId + } + if !IsNil(o.ErrorCode) { + toSerialize["errorCode"] = o.ErrorCode + } + if !IsNil(o.ErrorMessage) { + toSerialize["errorMessage"] = o.ErrorMessage + } + if !IsNil(o.ErrorDetails) { + toSerialize["errorDetails"] = o.ErrorDetails + } + return toSerialize, nil +} + +type NullableErrorResult struct { + value *ErrorResult + isSet bool +} + +func (v NullableErrorResult) Get() *ErrorResult { + return v.value +} + +func (v *NullableErrorResult) Set(val *ErrorResult) { + v.value = val + v.isSet = true +} + +func (v NullableErrorResult) IsSet() bool { + return v.isSet +} + +func (v *NullableErrorResult) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableErrorResult(val *ErrorResult) *NullableErrorResult { + return &NullableErrorResult{value: val, isSet: true} +} + +func (v NullableErrorResult) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableErrorResult) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/bmp/model_get_network_equipment_power_status_result.go b/bmp/model_get_network_equipment_power_status_result.go new file mode 100644 index 0000000..a9a0168 --- /dev/null +++ b/bmp/model_get_network_equipment_power_status_result.go @@ -0,0 +1,127 @@ +/* +bmp + +This documents the rest api bmp api provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package bmp + +import ( + "encoding/json" +) + +// checks if the GetNetworkEquipmentPowerStatusResult type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &GetNetworkEquipmentPowerStatusResult{} + +// GetNetworkEquipmentPowerStatusResult struct for GetNetworkEquipmentPowerStatusResult +type GetNetworkEquipmentPowerStatusResult struct { + Pdu *Pdu `json:"pdu,omitempty"` +} + +// NewGetNetworkEquipmentPowerStatusResult instantiates a new GetNetworkEquipmentPowerStatusResult object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewGetNetworkEquipmentPowerStatusResult() *GetNetworkEquipmentPowerStatusResult { + this := GetNetworkEquipmentPowerStatusResult{} + return &this +} + +// NewGetNetworkEquipmentPowerStatusResultWithDefaults instantiates a new GetNetworkEquipmentPowerStatusResult object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewGetNetworkEquipmentPowerStatusResultWithDefaults() *GetNetworkEquipmentPowerStatusResult { + this := GetNetworkEquipmentPowerStatusResult{} + return &this +} + +// GetPdu returns the Pdu field value if set, zero value otherwise. +func (o *GetNetworkEquipmentPowerStatusResult) GetPdu() Pdu { + if o == nil || IsNil(o.Pdu) { + var ret Pdu + return ret + } + return *o.Pdu +} + +// GetPduOk returns a tuple with the Pdu field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetNetworkEquipmentPowerStatusResult) GetPduOk() (*Pdu, bool) { + if o == nil || IsNil(o.Pdu) { + return nil, false + } + return o.Pdu, true +} + +// HasPdu returns a boolean if a field has been set. +func (o *GetNetworkEquipmentPowerStatusResult) HasPdu() bool { + if o != nil && !IsNil(o.Pdu) { + return true + } + + return false +} + +// SetPdu gets a reference to the given Pdu and assigns it to the Pdu field. +func (o *GetNetworkEquipmentPowerStatusResult) SetPdu(v Pdu) { + o.Pdu = &v +} + +func (o GetNetworkEquipmentPowerStatusResult) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o GetNetworkEquipmentPowerStatusResult) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Pdu) { + toSerialize["pdu"] = o.Pdu + } + return toSerialize, nil +} + +type NullableGetNetworkEquipmentPowerStatusResult struct { + value *GetNetworkEquipmentPowerStatusResult + isSet bool +} + +func (v NullableGetNetworkEquipmentPowerStatusResult) Get() *GetNetworkEquipmentPowerStatusResult { + return v.value +} + +func (v *NullableGetNetworkEquipmentPowerStatusResult) Set(val *GetNetworkEquipmentPowerStatusResult) { + v.value = val + v.isSet = true +} + +func (v NullableGetNetworkEquipmentPowerStatusResult) IsSet() bool { + return v.isSet +} + +func (v *NullableGetNetworkEquipmentPowerStatusResult) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableGetNetworkEquipmentPowerStatusResult(val *GetNetworkEquipmentPowerStatusResult) *NullableGetNetworkEquipmentPowerStatusResult { + return &NullableGetNetworkEquipmentPowerStatusResult{value: val, isSet: true} +} + +func (v NullableGetNetworkEquipmentPowerStatusResult) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableGetNetworkEquipmentPowerStatusResult) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/bmp/model_get_operating_system_list_result.go b/bmp/model_get_operating_system_list_result.go new file mode 100644 index 0000000..f312968 --- /dev/null +++ b/bmp/model_get_operating_system_list_result.go @@ -0,0 +1,164 @@ +/* +bmp + +This documents the rest api bmp api provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package bmp + +import ( + "encoding/json" +) + +// checks if the GetOperatingSystemListResult type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &GetOperatingSystemListResult{} + +// GetOperatingSystemListResult struct for GetOperatingSystemListResult +type GetOperatingSystemListResult struct { + Metadata *Metadata `json:"_metadata,omitempty"` + // A list of operating systems + OperatingSystems []OperatingSystem `json:"operatingSystems,omitempty"` +} + +// NewGetOperatingSystemListResult instantiates a new GetOperatingSystemListResult object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewGetOperatingSystemListResult() *GetOperatingSystemListResult { + this := GetOperatingSystemListResult{} + return &this +} + +// NewGetOperatingSystemListResultWithDefaults instantiates a new GetOperatingSystemListResult object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewGetOperatingSystemListResultWithDefaults() *GetOperatingSystemListResult { + this := GetOperatingSystemListResult{} + return &this +} + +// GetMetadata returns the Metadata field value if set, zero value otherwise. +func (o *GetOperatingSystemListResult) GetMetadata() Metadata { + if o == nil || IsNil(o.Metadata) { + var ret Metadata + return ret + } + return *o.Metadata +} + +// GetMetadataOk returns a tuple with the Metadata field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetOperatingSystemListResult) GetMetadataOk() (*Metadata, bool) { + if o == nil || IsNil(o.Metadata) { + return nil, false + } + return o.Metadata, true +} + +// HasMetadata returns a boolean if a field has been set. +func (o *GetOperatingSystemListResult) HasMetadata() bool { + if o != nil && !IsNil(o.Metadata) { + return true + } + + return false +} + +// SetMetadata gets a reference to the given Metadata and assigns it to the Metadata field. +func (o *GetOperatingSystemListResult) SetMetadata(v Metadata) { + o.Metadata = &v +} + +// GetOperatingSystems returns the OperatingSystems field value if set, zero value otherwise. +func (o *GetOperatingSystemListResult) GetOperatingSystems() []OperatingSystem { + if o == nil || IsNil(o.OperatingSystems) { + var ret []OperatingSystem + return ret + } + return o.OperatingSystems +} + +// GetOperatingSystemsOk returns a tuple with the OperatingSystems field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetOperatingSystemListResult) GetOperatingSystemsOk() ([]OperatingSystem, bool) { + if o == nil || IsNil(o.OperatingSystems) { + return nil, false + } + return o.OperatingSystems, true +} + +// HasOperatingSystems returns a boolean if a field has been set. +func (o *GetOperatingSystemListResult) HasOperatingSystems() bool { + if o != nil && !IsNil(o.OperatingSystems) { + return true + } + + return false +} + +// SetOperatingSystems gets a reference to the given []OperatingSystem and assigns it to the OperatingSystems field. +func (o *GetOperatingSystemListResult) SetOperatingSystems(v []OperatingSystem) { + o.OperatingSystems = v +} + +func (o GetOperatingSystemListResult) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o GetOperatingSystemListResult) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Metadata) { + toSerialize["_metadata"] = o.Metadata + } + if !IsNil(o.OperatingSystems) { + toSerialize["operatingSystems"] = o.OperatingSystems + } + return toSerialize, nil +} + +type NullableGetOperatingSystemListResult struct { + value *GetOperatingSystemListResult + isSet bool +} + +func (v NullableGetOperatingSystemListResult) Get() *GetOperatingSystemListResult { + return v.value +} + +func (v *NullableGetOperatingSystemListResult) Set(val *GetOperatingSystemListResult) { + v.value = val + v.isSet = true +} + +func (v NullableGetOperatingSystemListResult) IsSet() bool { + return v.isSet +} + +func (v *NullableGetOperatingSystemListResult) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableGetOperatingSystemListResult(val *GetOperatingSystemListResult) *NullableGetOperatingSystemListResult { + return &NullableGetOperatingSystemListResult{value: val, isSet: true} +} + +func (v NullableGetOperatingSystemListResult) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableGetOperatingSystemListResult) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/bmp/model_get_operating_system_result.go b/bmp/model_get_operating_system_result.go new file mode 100644 index 0000000..e63842d --- /dev/null +++ b/bmp/model_get_operating_system_result.go @@ -0,0 +1,497 @@ +/* +bmp + +This documents the rest api bmp api provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package bmp + +import ( + "encoding/json" +) + +// checks if the GetOperatingSystemResult type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &GetOperatingSystemResult{} + +// GetOperatingSystemResult struct for GetOperatingSystemResult +type GetOperatingSystemResult struct { + // The architecture of the operating system + Architecture *string `json:"architecture,omitempty"` + // If the default options are configurable or not + Configurable *bool `json:"configurable,omitempty"` + Defaults *Defaults `json:"defaults,omitempty"` + // The operating system family + Family *string `json:"family,omitempty"` + // The operating system ID + Id *string `json:"id,omitempty"` + // A human readable name for the operating system + Name *string `json:"name,omitempty"` + // The type of operating system + Type *string `json:"type,omitempty"` + // The version of the operating system + Version *string `json:"version,omitempty"` + // Operating system features + Features []string `json:"features,omitempty"` + // Operating system supported file systems + SupportedFileSystems []string `json:"supportedFileSystems,omitempty"` + // Operating system supported boot devices + SupportedBootDevices []string `json:"supportedBootDevices,omitempty"` +} + +// NewGetOperatingSystemResult instantiates a new GetOperatingSystemResult object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewGetOperatingSystemResult() *GetOperatingSystemResult { + this := GetOperatingSystemResult{} + return &this +} + +// NewGetOperatingSystemResultWithDefaults instantiates a new GetOperatingSystemResult object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewGetOperatingSystemResultWithDefaults() *GetOperatingSystemResult { + this := GetOperatingSystemResult{} + return &this +} + +// GetArchitecture returns the Architecture field value if set, zero value otherwise. +func (o *GetOperatingSystemResult) GetArchitecture() string { + if o == nil || IsNil(o.Architecture) { + var ret string + return ret + } + return *o.Architecture +} + +// GetArchitectureOk returns a tuple with the Architecture field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetOperatingSystemResult) GetArchitectureOk() (*string, bool) { + if o == nil || IsNil(o.Architecture) { + return nil, false + } + return o.Architecture, true +} + +// HasArchitecture returns a boolean if a field has been set. +func (o *GetOperatingSystemResult) HasArchitecture() bool { + if o != nil && !IsNil(o.Architecture) { + return true + } + + return false +} + +// SetArchitecture gets a reference to the given string and assigns it to the Architecture field. +func (o *GetOperatingSystemResult) SetArchitecture(v string) { + o.Architecture = &v +} + +// GetConfigurable returns the Configurable field value if set, zero value otherwise. +func (o *GetOperatingSystemResult) GetConfigurable() bool { + if o == nil || IsNil(o.Configurable) { + var ret bool + return ret + } + return *o.Configurable +} + +// GetConfigurableOk returns a tuple with the Configurable field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetOperatingSystemResult) GetConfigurableOk() (*bool, bool) { + if o == nil || IsNil(o.Configurable) { + return nil, false + } + return o.Configurable, true +} + +// HasConfigurable returns a boolean if a field has been set. +func (o *GetOperatingSystemResult) HasConfigurable() bool { + if o != nil && !IsNil(o.Configurable) { + return true + } + + return false +} + +// SetConfigurable gets a reference to the given bool and assigns it to the Configurable field. +func (o *GetOperatingSystemResult) SetConfigurable(v bool) { + o.Configurable = &v +} + +// GetDefaults returns the Defaults field value if set, zero value otherwise. +func (o *GetOperatingSystemResult) GetDefaults() Defaults { + if o == nil || IsNil(o.Defaults) { + var ret Defaults + return ret + } + return *o.Defaults +} + +// GetDefaultsOk returns a tuple with the Defaults field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetOperatingSystemResult) GetDefaultsOk() (*Defaults, bool) { + if o == nil || IsNil(o.Defaults) { + return nil, false + } + return o.Defaults, true +} + +// HasDefaults returns a boolean if a field has been set. +func (o *GetOperatingSystemResult) HasDefaults() bool { + if o != nil && !IsNil(o.Defaults) { + return true + } + + return false +} + +// SetDefaults gets a reference to the given Defaults and assigns it to the Defaults field. +func (o *GetOperatingSystemResult) SetDefaults(v Defaults) { + o.Defaults = &v +} + +// GetFamily returns the Family field value if set, zero value otherwise. +func (o *GetOperatingSystemResult) GetFamily() string { + if o == nil || IsNil(o.Family) { + var ret string + return ret + } + return *o.Family +} + +// GetFamilyOk returns a tuple with the Family field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetOperatingSystemResult) GetFamilyOk() (*string, bool) { + if o == nil || IsNil(o.Family) { + return nil, false + } + return o.Family, true +} + +// HasFamily returns a boolean if a field has been set. +func (o *GetOperatingSystemResult) HasFamily() bool { + if o != nil && !IsNil(o.Family) { + return true + } + + return false +} + +// SetFamily gets a reference to the given string and assigns it to the Family field. +func (o *GetOperatingSystemResult) SetFamily(v string) { + o.Family = &v +} + +// GetId returns the Id field value if set, zero value otherwise. +func (o *GetOperatingSystemResult) GetId() string { + if o == nil || IsNil(o.Id) { + var ret string + return ret + } + return *o.Id +} + +// GetIdOk returns a tuple with the Id field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetOperatingSystemResult) GetIdOk() (*string, bool) { + if o == nil || IsNil(o.Id) { + return nil, false + } + return o.Id, true +} + +// HasId returns a boolean if a field has been set. +func (o *GetOperatingSystemResult) HasId() bool { + if o != nil && !IsNil(o.Id) { + return true + } + + return false +} + +// SetId gets a reference to the given string and assigns it to the Id field. +func (o *GetOperatingSystemResult) SetId(v string) { + o.Id = &v +} + +// GetName returns the Name field value if set, zero value otherwise. +func (o *GetOperatingSystemResult) GetName() string { + if o == nil || IsNil(o.Name) { + var ret string + return ret + } + return *o.Name +} + +// GetNameOk returns a tuple with the Name field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetOperatingSystemResult) GetNameOk() (*string, bool) { + if o == nil || IsNil(o.Name) { + return nil, false + } + return o.Name, true +} + +// HasName returns a boolean if a field has been set. +func (o *GetOperatingSystemResult) HasName() bool { + if o != nil && !IsNil(o.Name) { + return true + } + + return false +} + +// SetName gets a reference to the given string and assigns it to the Name field. +func (o *GetOperatingSystemResult) SetName(v string) { + o.Name = &v +} + +// GetType returns the Type field value if set, zero value otherwise. +func (o *GetOperatingSystemResult) GetType() string { + if o == nil || IsNil(o.Type) { + var ret string + return ret + } + return *o.Type +} + +// GetTypeOk returns a tuple with the Type field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetOperatingSystemResult) GetTypeOk() (*string, bool) { + if o == nil || IsNil(o.Type) { + return nil, false + } + return o.Type, true +} + +// HasType returns a boolean if a field has been set. +func (o *GetOperatingSystemResult) HasType() bool { + if o != nil && !IsNil(o.Type) { + return true + } + + return false +} + +// SetType gets a reference to the given string and assigns it to the Type field. +func (o *GetOperatingSystemResult) SetType(v string) { + o.Type = &v +} + +// GetVersion returns the Version field value if set, zero value otherwise. +func (o *GetOperatingSystemResult) GetVersion() string { + if o == nil || IsNil(o.Version) { + var ret string + return ret + } + return *o.Version +} + +// GetVersionOk returns a tuple with the Version field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetOperatingSystemResult) GetVersionOk() (*string, bool) { + if o == nil || IsNil(o.Version) { + return nil, false + } + return o.Version, true +} + +// HasVersion returns a boolean if a field has been set. +func (o *GetOperatingSystemResult) HasVersion() bool { + if o != nil && !IsNil(o.Version) { + return true + } + + return false +} + +// SetVersion gets a reference to the given string and assigns it to the Version field. +func (o *GetOperatingSystemResult) SetVersion(v string) { + o.Version = &v +} + +// GetFeatures returns the Features field value if set, zero value otherwise. +func (o *GetOperatingSystemResult) GetFeatures() []string { + if o == nil || IsNil(o.Features) { + var ret []string + return ret + } + return o.Features +} + +// GetFeaturesOk returns a tuple with the Features field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetOperatingSystemResult) GetFeaturesOk() ([]string, bool) { + if o == nil || IsNil(o.Features) { + return nil, false + } + return o.Features, true +} + +// HasFeatures returns a boolean if a field has been set. +func (o *GetOperatingSystemResult) HasFeatures() bool { + if o != nil && !IsNil(o.Features) { + return true + } + + return false +} + +// SetFeatures gets a reference to the given []string and assigns it to the Features field. +func (o *GetOperatingSystemResult) SetFeatures(v []string) { + o.Features = v +} + +// GetSupportedFileSystems returns the SupportedFileSystems field value if set, zero value otherwise. +func (o *GetOperatingSystemResult) GetSupportedFileSystems() []string { + if o == nil || IsNil(o.SupportedFileSystems) { + var ret []string + return ret + } + return o.SupportedFileSystems +} + +// GetSupportedFileSystemsOk returns a tuple with the SupportedFileSystems field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetOperatingSystemResult) GetSupportedFileSystemsOk() ([]string, bool) { + if o == nil || IsNil(o.SupportedFileSystems) { + return nil, false + } + return o.SupportedFileSystems, true +} + +// HasSupportedFileSystems returns a boolean if a field has been set. +func (o *GetOperatingSystemResult) HasSupportedFileSystems() bool { + if o != nil && !IsNil(o.SupportedFileSystems) { + return true + } + + return false +} + +// SetSupportedFileSystems gets a reference to the given []string and assigns it to the SupportedFileSystems field. +func (o *GetOperatingSystemResult) SetSupportedFileSystems(v []string) { + o.SupportedFileSystems = v +} + +// GetSupportedBootDevices returns the SupportedBootDevices field value if set, zero value otherwise. +func (o *GetOperatingSystemResult) GetSupportedBootDevices() []string { + if o == nil || IsNil(o.SupportedBootDevices) { + var ret []string + return ret + } + return o.SupportedBootDevices +} + +// GetSupportedBootDevicesOk returns a tuple with the SupportedBootDevices field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetOperatingSystemResult) GetSupportedBootDevicesOk() ([]string, bool) { + if o == nil || IsNil(o.SupportedBootDevices) { + return nil, false + } + return o.SupportedBootDevices, true +} + +// HasSupportedBootDevices returns a boolean if a field has been set. +func (o *GetOperatingSystemResult) HasSupportedBootDevices() bool { + if o != nil && !IsNil(o.SupportedBootDevices) { + return true + } + + return false +} + +// SetSupportedBootDevices gets a reference to the given []string and assigns it to the SupportedBootDevices field. +func (o *GetOperatingSystemResult) SetSupportedBootDevices(v []string) { + o.SupportedBootDevices = v +} + +func (o GetOperatingSystemResult) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o GetOperatingSystemResult) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Architecture) { + toSerialize["architecture"] = o.Architecture + } + if !IsNil(o.Configurable) { + toSerialize["configurable"] = o.Configurable + } + if !IsNil(o.Defaults) { + toSerialize["defaults"] = o.Defaults + } + if !IsNil(o.Family) { + toSerialize["family"] = o.Family + } + if !IsNil(o.Id) { + toSerialize["id"] = o.Id + } + if !IsNil(o.Name) { + toSerialize["name"] = o.Name + } + if !IsNil(o.Type) { + toSerialize["type"] = o.Type + } + if !IsNil(o.Version) { + toSerialize["version"] = o.Version + } + if !IsNil(o.Features) { + toSerialize["features"] = o.Features + } + if !IsNil(o.SupportedFileSystems) { + toSerialize["supportedFileSystems"] = o.SupportedFileSystems + } + if !IsNil(o.SupportedBootDevices) { + toSerialize["supportedBootDevices"] = o.SupportedBootDevices + } + return toSerialize, nil +} + +type NullableGetOperatingSystemResult struct { + value *GetOperatingSystemResult + isSet bool +} + +func (v NullableGetOperatingSystemResult) Get() *GetOperatingSystemResult { + return v.value +} + +func (v *NullableGetOperatingSystemResult) Set(val *GetOperatingSystemResult) { + v.value = val + v.isSet = true +} + +func (v NullableGetOperatingSystemResult) IsSet() bool { + return v.isSet +} + +func (v *NullableGetOperatingSystemResult) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableGetOperatingSystemResult(val *GetOperatingSystemResult) *NullableGetOperatingSystemResult { + return &NullableGetOperatingSystemResult{value: val, isSet: true} +} + +func (v NullableGetOperatingSystemResult) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableGetOperatingSystemResult) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/bmp/model_get_rescue_image_list_result.go b/bmp/model_get_rescue_image_list_result.go new file mode 100644 index 0000000..bf07def --- /dev/null +++ b/bmp/model_get_rescue_image_list_result.go @@ -0,0 +1,164 @@ +/* +bmp + +This documents the rest api bmp api provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package bmp + +import ( + "encoding/json" +) + +// checks if the GetRescueImageListResult type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &GetRescueImageListResult{} + +// GetRescueImageListResult struct for GetRescueImageListResult +type GetRescueImageListResult struct { + Metadata *Metadata `json:"_metadata,omitempty"` + // A list of operating systems + RescueImages []RescueImage `json:"rescueImages,omitempty"` +} + +// NewGetRescueImageListResult instantiates a new GetRescueImageListResult object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewGetRescueImageListResult() *GetRescueImageListResult { + this := GetRescueImageListResult{} + return &this +} + +// NewGetRescueImageListResultWithDefaults instantiates a new GetRescueImageListResult object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewGetRescueImageListResultWithDefaults() *GetRescueImageListResult { + this := GetRescueImageListResult{} + return &this +} + +// GetMetadata returns the Metadata field value if set, zero value otherwise. +func (o *GetRescueImageListResult) GetMetadata() Metadata { + if o == nil || IsNil(o.Metadata) { + var ret Metadata + return ret + } + return *o.Metadata +} + +// GetMetadataOk returns a tuple with the Metadata field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetRescueImageListResult) GetMetadataOk() (*Metadata, bool) { + if o == nil || IsNil(o.Metadata) { + return nil, false + } + return o.Metadata, true +} + +// HasMetadata returns a boolean if a field has been set. +func (o *GetRescueImageListResult) HasMetadata() bool { + if o != nil && !IsNil(o.Metadata) { + return true + } + + return false +} + +// SetMetadata gets a reference to the given Metadata and assigns it to the Metadata field. +func (o *GetRescueImageListResult) SetMetadata(v Metadata) { + o.Metadata = &v +} + +// GetRescueImages returns the RescueImages field value if set, zero value otherwise. +func (o *GetRescueImageListResult) GetRescueImages() []RescueImage { + if o == nil || IsNil(o.RescueImages) { + var ret []RescueImage + return ret + } + return o.RescueImages +} + +// GetRescueImagesOk returns a tuple with the RescueImages field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetRescueImageListResult) GetRescueImagesOk() ([]RescueImage, bool) { + if o == nil || IsNil(o.RescueImages) { + return nil, false + } + return o.RescueImages, true +} + +// HasRescueImages returns a boolean if a field has been set. +func (o *GetRescueImageListResult) HasRescueImages() bool { + if o != nil && !IsNil(o.RescueImages) { + return true + } + + return false +} + +// SetRescueImages gets a reference to the given []RescueImage and assigns it to the RescueImages field. +func (o *GetRescueImageListResult) SetRescueImages(v []RescueImage) { + o.RescueImages = v +} + +func (o GetRescueImageListResult) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o GetRescueImageListResult) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Metadata) { + toSerialize["_metadata"] = o.Metadata + } + if !IsNil(o.RescueImages) { + toSerialize["rescueImages"] = o.RescueImages + } + return toSerialize, nil +} + +type NullableGetRescueImageListResult struct { + value *GetRescueImageListResult + isSet bool +} + +func (v NullableGetRescueImageListResult) Get() *GetRescueImageListResult { + return v.value +} + +func (v *NullableGetRescueImageListResult) Set(val *GetRescueImageListResult) { + v.value = val + v.isSet = true +} + +func (v NullableGetRescueImageListResult) IsSet() bool { + return v.isSet +} + +func (v *NullableGetRescueImageListResult) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableGetRescueImageListResult(val *GetRescueImageListResult) *NullableGetRescueImageListResult { + return &NullableGetRescueImageListResult{value: val, isSet: true} +} + +func (v NullableGetRescueImageListResult) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableGetRescueImageListResult) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/bmp/model_get_server_dhcp_reservation_list_result.go b/bmp/model_get_server_dhcp_reservation_list_result.go new file mode 100644 index 0000000..a36864b --- /dev/null +++ b/bmp/model_get_server_dhcp_reservation_list_result.go @@ -0,0 +1,164 @@ +/* +bmp + +This documents the rest api bmp api provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package bmp + +import ( + "encoding/json" +) + +// checks if the GetServerDhcpReservationListResult type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &GetServerDhcpReservationListResult{} + +// GetServerDhcpReservationListResult struct for GetServerDhcpReservationListResult +type GetServerDhcpReservationListResult struct { + Metadata *Metadata `json:"_metadata,omitempty"` + // An array of active DHCP reservations + Leases []Lease `json:"leases,omitempty"` +} + +// NewGetServerDhcpReservationListResult instantiates a new GetServerDhcpReservationListResult object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewGetServerDhcpReservationListResult() *GetServerDhcpReservationListResult { + this := GetServerDhcpReservationListResult{} + return &this +} + +// NewGetServerDhcpReservationListResultWithDefaults instantiates a new GetServerDhcpReservationListResult object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewGetServerDhcpReservationListResultWithDefaults() *GetServerDhcpReservationListResult { + this := GetServerDhcpReservationListResult{} + return &this +} + +// GetMetadata returns the Metadata field value if set, zero value otherwise. +func (o *GetServerDhcpReservationListResult) GetMetadata() Metadata { + if o == nil || IsNil(o.Metadata) { + var ret Metadata + return ret + } + return *o.Metadata +} + +// GetMetadataOk returns a tuple with the Metadata field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetServerDhcpReservationListResult) GetMetadataOk() (*Metadata, bool) { + if o == nil || IsNil(o.Metadata) { + return nil, false + } + return o.Metadata, true +} + +// HasMetadata returns a boolean if a field has been set. +func (o *GetServerDhcpReservationListResult) HasMetadata() bool { + if o != nil && !IsNil(o.Metadata) { + return true + } + + return false +} + +// SetMetadata gets a reference to the given Metadata and assigns it to the Metadata field. +func (o *GetServerDhcpReservationListResult) SetMetadata(v Metadata) { + o.Metadata = &v +} + +// GetLeases returns the Leases field value if set, zero value otherwise. +func (o *GetServerDhcpReservationListResult) GetLeases() []Lease { + if o == nil || IsNil(o.Leases) { + var ret []Lease + return ret + } + return o.Leases +} + +// GetLeasesOk returns a tuple with the Leases field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetServerDhcpReservationListResult) GetLeasesOk() ([]Lease, bool) { + if o == nil || IsNil(o.Leases) { + return nil, false + } + return o.Leases, true +} + +// HasLeases returns a boolean if a field has been set. +func (o *GetServerDhcpReservationListResult) HasLeases() bool { + if o != nil && !IsNil(o.Leases) { + return true + } + + return false +} + +// SetLeases gets a reference to the given []Lease and assigns it to the Leases field. +func (o *GetServerDhcpReservationListResult) SetLeases(v []Lease) { + o.Leases = v +} + +func (o GetServerDhcpReservationListResult) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o GetServerDhcpReservationListResult) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Metadata) { + toSerialize["_metadata"] = o.Metadata + } + if !IsNil(o.Leases) { + toSerialize["leases"] = o.Leases + } + return toSerialize, nil +} + +type NullableGetServerDhcpReservationListResult struct { + value *GetServerDhcpReservationListResult + isSet bool +} + +func (v NullableGetServerDhcpReservationListResult) Get() *GetServerDhcpReservationListResult { + return v.value +} + +func (v *NullableGetServerDhcpReservationListResult) Set(val *GetServerDhcpReservationListResult) { + v.value = val + v.isSet = true +} + +func (v NullableGetServerDhcpReservationListResult) IsSet() bool { + return v.isSet +} + +func (v *NullableGetServerDhcpReservationListResult) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableGetServerDhcpReservationListResult(val *GetServerDhcpReservationListResult) *NullableGetServerDhcpReservationListResult { + return &NullableGetServerDhcpReservationListResult{value: val, isSet: true} +} + +func (v NullableGetServerDhcpReservationListResult) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableGetServerDhcpReservationListResult) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/bmp/model_get_server_power_status_result.go b/bmp/model_get_server_power_status_result.go new file mode 100644 index 0000000..7288074 --- /dev/null +++ b/bmp/model_get_server_power_status_result.go @@ -0,0 +1,163 @@ +/* +bmp + +This documents the rest api bmp api provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package bmp + +import ( + "encoding/json" +) + +// checks if the GetServerPowerStatusResult type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &GetServerPowerStatusResult{} + +// GetServerPowerStatusResult struct for GetServerPowerStatusResult +type GetServerPowerStatusResult struct { + Ipmi *Ipmi `json:"ipmi,omitempty"` + Pdu *Pdu `json:"pdu,omitempty"` +} + +// NewGetServerPowerStatusResult instantiates a new GetServerPowerStatusResult object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewGetServerPowerStatusResult() *GetServerPowerStatusResult { + this := GetServerPowerStatusResult{} + return &this +} + +// NewGetServerPowerStatusResultWithDefaults instantiates a new GetServerPowerStatusResult object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewGetServerPowerStatusResultWithDefaults() *GetServerPowerStatusResult { + this := GetServerPowerStatusResult{} + return &this +} + +// GetIpmi returns the Ipmi field value if set, zero value otherwise. +func (o *GetServerPowerStatusResult) GetIpmi() Ipmi { + if o == nil || IsNil(o.Ipmi) { + var ret Ipmi + return ret + } + return *o.Ipmi +} + +// GetIpmiOk returns a tuple with the Ipmi field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetServerPowerStatusResult) GetIpmiOk() (*Ipmi, bool) { + if o == nil || IsNil(o.Ipmi) { + return nil, false + } + return o.Ipmi, true +} + +// HasIpmi returns a boolean if a field has been set. +func (o *GetServerPowerStatusResult) HasIpmi() bool { + if o != nil && !IsNil(o.Ipmi) { + return true + } + + return false +} + +// SetIpmi gets a reference to the given Ipmi and assigns it to the Ipmi field. +func (o *GetServerPowerStatusResult) SetIpmi(v Ipmi) { + o.Ipmi = &v +} + +// GetPdu returns the Pdu field value if set, zero value otherwise. +func (o *GetServerPowerStatusResult) GetPdu() Pdu { + if o == nil || IsNil(o.Pdu) { + var ret Pdu + return ret + } + return *o.Pdu +} + +// GetPduOk returns a tuple with the Pdu field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetServerPowerStatusResult) GetPduOk() (*Pdu, bool) { + if o == nil || IsNil(o.Pdu) { + return nil, false + } + return o.Pdu, true +} + +// HasPdu returns a boolean if a field has been set. +func (o *GetServerPowerStatusResult) HasPdu() bool { + if o != nil && !IsNil(o.Pdu) { + return true + } + + return false +} + +// SetPdu gets a reference to the given Pdu and assigns it to the Pdu field. +func (o *GetServerPowerStatusResult) SetPdu(v Pdu) { + o.Pdu = &v +} + +func (o GetServerPowerStatusResult) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o GetServerPowerStatusResult) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Ipmi) { + toSerialize["ipmi"] = o.Ipmi + } + if !IsNil(o.Pdu) { + toSerialize["pdu"] = o.Pdu + } + return toSerialize, nil +} + +type NullableGetServerPowerStatusResult struct { + value *GetServerPowerStatusResult + isSet bool +} + +func (v NullableGetServerPowerStatusResult) Get() *GetServerPowerStatusResult { + return v.value +} + +func (v *NullableGetServerPowerStatusResult) Set(val *GetServerPowerStatusResult) { + v.value = val + v.isSet = true +} + +func (v NullableGetServerPowerStatusResult) IsSet() bool { + return v.isSet +} + +func (v *NullableGetServerPowerStatusResult) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableGetServerPowerStatusResult(val *GetServerPowerStatusResult) *NullableGetServerPowerStatusResult { + return &NullableGetServerPowerStatusResult{value: val, isSet: true} +} + +func (v NullableGetServerPowerStatusResult) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableGetServerPowerStatusResult) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/bmp/model_install_operating_system_opts.go b/bmp/model_install_operating_system_opts.go new file mode 100644 index 0000000..9f2716d --- /dev/null +++ b/bmp/model_install_operating_system_opts.go @@ -0,0 +1,566 @@ +/* +bmp + +This documents the rest api bmp api provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package bmp + +import ( + "encoding/json" + "bytes" + "fmt" +) + +// checks if the InstallOperatingSystemOpts type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &InstallOperatingSystemOpts{} + +// InstallOperatingSystemOpts struct for InstallOperatingSystemOpts +type InstallOperatingSystemOpts struct { + // Url which will receive callbacks when the installation is finished or failed + CallbackUrl *string `json:"callbackUrl,omitempty"` + // Control panel identifier + ControlPanelId *string `json:"controlPanelId,omitempty"` + // Block devices in a disk set in which the partitions will be installed. Supported values are any disk set id, SATA_SAS or NVME + Device *string `json:"device,omitempty"` + // Hostname to be used in your installation + Hostname *string `json:"hostname,omitempty"` + // Operating system identifier + OperatingSystemId string `json:"operatingSystemId"` + // Array of partition objects that should be installed per partition + Partitions []Partition `json:"partitions,omitempty"` + // Server root password. If not provided, it would be automatically generated + Password *string `json:"password,omitempty"` + // Base64 Encoded string containing a valid bash script to be run right after the installation + PostInstallScript *string `json:"postInstallScript,omitempty"` + // If true, allows system reboots to happen automatically within the process. Otherwise, you should do them manually + PowerCycle *bool `json:"powerCycle,omitempty"` + Raid *Raid `json:"raid,omitempty"` + // List of public sshKeys to be setup in your installation, separated by new lines + SshKeys *string `json:"sshKeys,omitempty"` + // Timezone represented as Geographical_Area/City + Timezone *string `json:"timezone,omitempty"` +} + +type _InstallOperatingSystemOpts InstallOperatingSystemOpts + +// NewInstallOperatingSystemOpts instantiates a new InstallOperatingSystemOpts object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewInstallOperatingSystemOpts(operatingSystemId string) *InstallOperatingSystemOpts { + this := InstallOperatingSystemOpts{} + this.OperatingSystemId = operatingSystemId + return &this +} + +// NewInstallOperatingSystemOptsWithDefaults instantiates a new InstallOperatingSystemOpts object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewInstallOperatingSystemOptsWithDefaults() *InstallOperatingSystemOpts { + this := InstallOperatingSystemOpts{} + return &this +} + +// GetCallbackUrl returns the CallbackUrl field value if set, zero value otherwise. +func (o *InstallOperatingSystemOpts) GetCallbackUrl() string { + if o == nil || IsNil(o.CallbackUrl) { + var ret string + return ret + } + return *o.CallbackUrl +} + +// GetCallbackUrlOk returns a tuple with the CallbackUrl field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *InstallOperatingSystemOpts) GetCallbackUrlOk() (*string, bool) { + if o == nil || IsNil(o.CallbackUrl) { + return nil, false + } + return o.CallbackUrl, true +} + +// HasCallbackUrl returns a boolean if a field has been set. +func (o *InstallOperatingSystemOpts) HasCallbackUrl() bool { + if o != nil && !IsNil(o.CallbackUrl) { + return true + } + + return false +} + +// SetCallbackUrl gets a reference to the given string and assigns it to the CallbackUrl field. +func (o *InstallOperatingSystemOpts) SetCallbackUrl(v string) { + o.CallbackUrl = &v +} + +// GetControlPanelId returns the ControlPanelId field value if set, zero value otherwise. +func (o *InstallOperatingSystemOpts) GetControlPanelId() string { + if o == nil || IsNil(o.ControlPanelId) { + var ret string + return ret + } + return *o.ControlPanelId +} + +// GetControlPanelIdOk returns a tuple with the ControlPanelId field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *InstallOperatingSystemOpts) GetControlPanelIdOk() (*string, bool) { + if o == nil || IsNil(o.ControlPanelId) { + return nil, false + } + return o.ControlPanelId, true +} + +// HasControlPanelId returns a boolean if a field has been set. +func (o *InstallOperatingSystemOpts) HasControlPanelId() bool { + if o != nil && !IsNil(o.ControlPanelId) { + return true + } + + return false +} + +// SetControlPanelId gets a reference to the given string and assigns it to the ControlPanelId field. +func (o *InstallOperatingSystemOpts) SetControlPanelId(v string) { + o.ControlPanelId = &v +} + +// GetDevice returns the Device field value if set, zero value otherwise. +func (o *InstallOperatingSystemOpts) GetDevice() string { + if o == nil || IsNil(o.Device) { + var ret string + return ret + } + return *o.Device +} + +// GetDeviceOk returns a tuple with the Device field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *InstallOperatingSystemOpts) GetDeviceOk() (*string, bool) { + if o == nil || IsNil(o.Device) { + return nil, false + } + return o.Device, true +} + +// HasDevice returns a boolean if a field has been set. +func (o *InstallOperatingSystemOpts) HasDevice() bool { + if o != nil && !IsNil(o.Device) { + return true + } + + return false +} + +// SetDevice gets a reference to the given string and assigns it to the Device field. +func (o *InstallOperatingSystemOpts) SetDevice(v string) { + o.Device = &v +} + +// GetHostname returns the Hostname field value if set, zero value otherwise. +func (o *InstallOperatingSystemOpts) GetHostname() string { + if o == nil || IsNil(o.Hostname) { + var ret string + return ret + } + return *o.Hostname +} + +// GetHostnameOk returns a tuple with the Hostname field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *InstallOperatingSystemOpts) GetHostnameOk() (*string, bool) { + if o == nil || IsNil(o.Hostname) { + return nil, false + } + return o.Hostname, true +} + +// HasHostname returns a boolean if a field has been set. +func (o *InstallOperatingSystemOpts) HasHostname() bool { + if o != nil && !IsNil(o.Hostname) { + return true + } + + return false +} + +// SetHostname gets a reference to the given string and assigns it to the Hostname field. +func (o *InstallOperatingSystemOpts) SetHostname(v string) { + o.Hostname = &v +} + +// GetOperatingSystemId returns the OperatingSystemId field value +func (o *InstallOperatingSystemOpts) GetOperatingSystemId() string { + if o == nil { + var ret string + return ret + } + + return o.OperatingSystemId +} + +// GetOperatingSystemIdOk returns a tuple with the OperatingSystemId field value +// and a boolean to check if the value has been set. +func (o *InstallOperatingSystemOpts) GetOperatingSystemIdOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.OperatingSystemId, true +} + +// SetOperatingSystemId sets field value +func (o *InstallOperatingSystemOpts) SetOperatingSystemId(v string) { + o.OperatingSystemId = v +} + +// GetPartitions returns the Partitions field value if set, zero value otherwise. +func (o *InstallOperatingSystemOpts) GetPartitions() []Partition { + if o == nil || IsNil(o.Partitions) { + var ret []Partition + return ret + } + return o.Partitions +} + +// GetPartitionsOk returns a tuple with the Partitions field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *InstallOperatingSystemOpts) GetPartitionsOk() ([]Partition, bool) { + if o == nil || IsNil(o.Partitions) { + return nil, false + } + return o.Partitions, true +} + +// HasPartitions returns a boolean if a field has been set. +func (o *InstallOperatingSystemOpts) HasPartitions() bool { + if o != nil && !IsNil(o.Partitions) { + return true + } + + return false +} + +// SetPartitions gets a reference to the given []Partition and assigns it to the Partitions field. +func (o *InstallOperatingSystemOpts) SetPartitions(v []Partition) { + o.Partitions = v +} + +// GetPassword returns the Password field value if set, zero value otherwise. +func (o *InstallOperatingSystemOpts) GetPassword() string { + if o == nil || IsNil(o.Password) { + var ret string + return ret + } + return *o.Password +} + +// GetPasswordOk returns a tuple with the Password field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *InstallOperatingSystemOpts) GetPasswordOk() (*string, bool) { + if o == nil || IsNil(o.Password) { + return nil, false + } + return o.Password, true +} + +// HasPassword returns a boolean if a field has been set. +func (o *InstallOperatingSystemOpts) HasPassword() bool { + if o != nil && !IsNil(o.Password) { + return true + } + + return false +} + +// SetPassword gets a reference to the given string and assigns it to the Password field. +func (o *InstallOperatingSystemOpts) SetPassword(v string) { + o.Password = &v +} + +// GetPostInstallScript returns the PostInstallScript field value if set, zero value otherwise. +func (o *InstallOperatingSystemOpts) GetPostInstallScript() string { + if o == nil || IsNil(o.PostInstallScript) { + var ret string + return ret + } + return *o.PostInstallScript +} + +// GetPostInstallScriptOk returns a tuple with the PostInstallScript field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *InstallOperatingSystemOpts) GetPostInstallScriptOk() (*string, bool) { + if o == nil || IsNil(o.PostInstallScript) { + return nil, false + } + return o.PostInstallScript, true +} + +// HasPostInstallScript returns a boolean if a field has been set. +func (o *InstallOperatingSystemOpts) HasPostInstallScript() bool { + if o != nil && !IsNil(o.PostInstallScript) { + return true + } + + return false +} + +// SetPostInstallScript gets a reference to the given string and assigns it to the PostInstallScript field. +func (o *InstallOperatingSystemOpts) SetPostInstallScript(v string) { + o.PostInstallScript = &v +} + +// GetPowerCycle returns the PowerCycle field value if set, zero value otherwise. +func (o *InstallOperatingSystemOpts) GetPowerCycle() bool { + if o == nil || IsNil(o.PowerCycle) { + var ret bool + return ret + } + return *o.PowerCycle +} + +// GetPowerCycleOk returns a tuple with the PowerCycle field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *InstallOperatingSystemOpts) GetPowerCycleOk() (*bool, bool) { + if o == nil || IsNil(o.PowerCycle) { + return nil, false + } + return o.PowerCycle, true +} + +// HasPowerCycle returns a boolean if a field has been set. +func (o *InstallOperatingSystemOpts) HasPowerCycle() bool { + if o != nil && !IsNil(o.PowerCycle) { + return true + } + + return false +} + +// SetPowerCycle gets a reference to the given bool and assigns it to the PowerCycle field. +func (o *InstallOperatingSystemOpts) SetPowerCycle(v bool) { + o.PowerCycle = &v +} + +// GetRaid returns the Raid field value if set, zero value otherwise. +func (o *InstallOperatingSystemOpts) GetRaid() Raid { + if o == nil || IsNil(o.Raid) { + var ret Raid + return ret + } + return *o.Raid +} + +// GetRaidOk returns a tuple with the Raid field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *InstallOperatingSystemOpts) GetRaidOk() (*Raid, bool) { + if o == nil || IsNil(o.Raid) { + return nil, false + } + return o.Raid, true +} + +// HasRaid returns a boolean if a field has been set. +func (o *InstallOperatingSystemOpts) HasRaid() bool { + if o != nil && !IsNil(o.Raid) { + return true + } + + return false +} + +// SetRaid gets a reference to the given Raid and assigns it to the Raid field. +func (o *InstallOperatingSystemOpts) SetRaid(v Raid) { + o.Raid = &v +} + +// GetSshKeys returns the SshKeys field value if set, zero value otherwise. +func (o *InstallOperatingSystemOpts) GetSshKeys() string { + if o == nil || IsNil(o.SshKeys) { + var ret string + return ret + } + return *o.SshKeys +} + +// GetSshKeysOk returns a tuple with the SshKeys field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *InstallOperatingSystemOpts) GetSshKeysOk() (*string, bool) { + if o == nil || IsNil(o.SshKeys) { + return nil, false + } + return o.SshKeys, true +} + +// HasSshKeys returns a boolean if a field has been set. +func (o *InstallOperatingSystemOpts) HasSshKeys() bool { + if o != nil && !IsNil(o.SshKeys) { + return true + } + + return false +} + +// SetSshKeys gets a reference to the given string and assigns it to the SshKeys field. +func (o *InstallOperatingSystemOpts) SetSshKeys(v string) { + o.SshKeys = &v +} + +// GetTimezone returns the Timezone field value if set, zero value otherwise. +func (o *InstallOperatingSystemOpts) GetTimezone() string { + if o == nil || IsNil(o.Timezone) { + var ret string + return ret + } + return *o.Timezone +} + +// GetTimezoneOk returns a tuple with the Timezone field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *InstallOperatingSystemOpts) GetTimezoneOk() (*string, bool) { + if o == nil || IsNil(o.Timezone) { + return nil, false + } + return o.Timezone, true +} + +// HasTimezone returns a boolean if a field has been set. +func (o *InstallOperatingSystemOpts) HasTimezone() bool { + if o != nil && !IsNil(o.Timezone) { + return true + } + + return false +} + +// SetTimezone gets a reference to the given string and assigns it to the Timezone field. +func (o *InstallOperatingSystemOpts) SetTimezone(v string) { + o.Timezone = &v +} + +func (o InstallOperatingSystemOpts) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o InstallOperatingSystemOpts) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.CallbackUrl) { + toSerialize["callbackUrl"] = o.CallbackUrl + } + if !IsNil(o.ControlPanelId) { + toSerialize["controlPanelId"] = o.ControlPanelId + } + if !IsNil(o.Device) { + toSerialize["device"] = o.Device + } + if !IsNil(o.Hostname) { + toSerialize["hostname"] = o.Hostname + } + toSerialize["operatingSystemId"] = o.OperatingSystemId + if !IsNil(o.Partitions) { + toSerialize["partitions"] = o.Partitions + } + if !IsNil(o.Password) { + toSerialize["password"] = o.Password + } + if !IsNil(o.PostInstallScript) { + toSerialize["postInstallScript"] = o.PostInstallScript + } + if !IsNil(o.PowerCycle) { + toSerialize["powerCycle"] = o.PowerCycle + } + if !IsNil(o.Raid) { + toSerialize["raid"] = o.Raid + } + if !IsNil(o.SshKeys) { + toSerialize["sshKeys"] = o.SshKeys + } + if !IsNil(o.Timezone) { + toSerialize["timezone"] = o.Timezone + } + return toSerialize, nil +} + +func (o *InstallOperatingSystemOpts) UnmarshalJSON(data []byte) (err error) { + // This validates that all required properties are included in the JSON object + // by unmarshalling the object into a generic map with string keys and checking + // that every required field exists as a key in the generic map. + requiredProperties := []string{ + "operatingSystemId", + } + + allProperties := make(map[string]interface{}) + + err = json.Unmarshal(data, &allProperties) + + if err != nil { + return err; + } + + for _, requiredProperty := range(requiredProperties) { + if _, exists := allProperties[requiredProperty]; !exists { + return fmt.Errorf("no value given for required property %v", requiredProperty) + } + } + + varInstallOperatingSystemOpts := _InstallOperatingSystemOpts{} + + decoder := json.NewDecoder(bytes.NewReader(data)) + decoder.DisallowUnknownFields() + err = decoder.Decode(&varInstallOperatingSystemOpts) + + if err != nil { + return err + } + + *o = InstallOperatingSystemOpts(varInstallOperatingSystemOpts) + + return err +} + +type NullableInstallOperatingSystemOpts struct { + value *InstallOperatingSystemOpts + isSet bool +} + +func (v NullableInstallOperatingSystemOpts) Get() *InstallOperatingSystemOpts { + return v.value +} + +func (v *NullableInstallOperatingSystemOpts) Set(val *InstallOperatingSystemOpts) { + v.value = val + v.isSet = true +} + +func (v NullableInstallOperatingSystemOpts) IsSet() bool { + return v.isSet +} + +func (v *NullableInstallOperatingSystemOpts) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableInstallOperatingSystemOpts(val *InstallOperatingSystemOpts) *NullableInstallOperatingSystemOpts { + return &NullableInstallOperatingSystemOpts{value: val, isSet: true} +} + +func (v NullableInstallOperatingSystemOpts) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableInstallOperatingSystemOpts) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/bmp/model_ipmi.go b/bmp/model_ipmi.go new file mode 100644 index 0000000..3059654 --- /dev/null +++ b/bmp/model_ipmi.go @@ -0,0 +1,128 @@ +/* +bmp + +This documents the rest api bmp api provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package bmp + +import ( + "encoding/json" +) + +// checks if the Ipmi type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &Ipmi{} + +// Ipmi Object describing the IPMI power information +type Ipmi struct { + // The current power status of the server. + Status *string `json:"status,omitempty"` +} + +// NewIpmi instantiates a new Ipmi object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewIpmi() *Ipmi { + this := Ipmi{} + return &this +} + +// NewIpmiWithDefaults instantiates a new Ipmi object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewIpmiWithDefaults() *Ipmi { + this := Ipmi{} + return &this +} + +// GetStatus returns the Status field value if set, zero value otherwise. +func (o *Ipmi) GetStatus() string { + if o == nil || IsNil(o.Status) { + var ret string + return ret + } + return *o.Status +} + +// GetStatusOk returns a tuple with the Status field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Ipmi) GetStatusOk() (*string, bool) { + if o == nil || IsNil(o.Status) { + return nil, false + } + return o.Status, true +} + +// HasStatus returns a boolean if a field has been set. +func (o *Ipmi) HasStatus() bool { + if o != nil && !IsNil(o.Status) { + return true + } + + return false +} + +// SetStatus gets a reference to the given string and assigns it to the Status field. +func (o *Ipmi) SetStatus(v string) { + o.Status = &v +} + +func (o Ipmi) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o Ipmi) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Status) { + toSerialize["status"] = o.Status + } + return toSerialize, nil +} + +type NullableIpmi struct { + value *Ipmi + isSet bool +} + +func (v NullableIpmi) Get() *Ipmi { + return v.value +} + +func (v *NullableIpmi) Set(val *Ipmi) { + v.value = val + v.isSet = true +} + +func (v NullableIpmi) IsSet() bool { + return v.isSet +} + +func (v *NullableIpmi) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableIpmi(val *Ipmi) *NullableIpmi { + return &NullableIpmi{value: val, isSet: true} +} + +func (v NullableIpmi) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableIpmi) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/bmp/model_ipmi_reset_server_opts.go b/bmp/model_ipmi_reset_server_opts.go new file mode 100644 index 0000000..f363139 --- /dev/null +++ b/bmp/model_ipmi_reset_server_opts.go @@ -0,0 +1,169 @@ +/* +bmp + +This documents the rest api bmp api provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package bmp + +import ( + "encoding/json" +) + +// checks if the IpmiResetServerOpts type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &IpmiResetServerOpts{} + +// IpmiResetServerOpts struct for IpmiResetServerOpts +type IpmiResetServerOpts struct { + // Url which will receive callbacks + CallbackUrl *string `json:"callbackUrl,omitempty"` + // If set to `true`, server will be power cycled in order to complete the operation + PowerCycle *bool `json:"powerCycle,omitempty"` +} + +// NewIpmiResetServerOpts instantiates a new IpmiResetServerOpts object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewIpmiResetServerOpts() *IpmiResetServerOpts { + this := IpmiResetServerOpts{} + var powerCycle bool = true + this.PowerCycle = &powerCycle + return &this +} + +// NewIpmiResetServerOptsWithDefaults instantiates a new IpmiResetServerOpts object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewIpmiResetServerOptsWithDefaults() *IpmiResetServerOpts { + this := IpmiResetServerOpts{} + var powerCycle bool = true + this.PowerCycle = &powerCycle + return &this +} + +// GetCallbackUrl returns the CallbackUrl field value if set, zero value otherwise. +func (o *IpmiResetServerOpts) GetCallbackUrl() string { + if o == nil || IsNil(o.CallbackUrl) { + var ret string + return ret + } + return *o.CallbackUrl +} + +// GetCallbackUrlOk returns a tuple with the CallbackUrl field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *IpmiResetServerOpts) GetCallbackUrlOk() (*string, bool) { + if o == nil || IsNil(o.CallbackUrl) { + return nil, false + } + return o.CallbackUrl, true +} + +// HasCallbackUrl returns a boolean if a field has been set. +func (o *IpmiResetServerOpts) HasCallbackUrl() bool { + if o != nil && !IsNil(o.CallbackUrl) { + return true + } + + return false +} + +// SetCallbackUrl gets a reference to the given string and assigns it to the CallbackUrl field. +func (o *IpmiResetServerOpts) SetCallbackUrl(v string) { + o.CallbackUrl = &v +} + +// GetPowerCycle returns the PowerCycle field value if set, zero value otherwise. +func (o *IpmiResetServerOpts) GetPowerCycle() bool { + if o == nil || IsNil(o.PowerCycle) { + var ret bool + return ret + } + return *o.PowerCycle +} + +// GetPowerCycleOk returns a tuple with the PowerCycle field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *IpmiResetServerOpts) GetPowerCycleOk() (*bool, bool) { + if o == nil || IsNil(o.PowerCycle) { + return nil, false + } + return o.PowerCycle, true +} + +// HasPowerCycle returns a boolean if a field has been set. +func (o *IpmiResetServerOpts) HasPowerCycle() bool { + if o != nil && !IsNil(o.PowerCycle) { + return true + } + + return false +} + +// SetPowerCycle gets a reference to the given bool and assigns it to the PowerCycle field. +func (o *IpmiResetServerOpts) SetPowerCycle(v bool) { + o.PowerCycle = &v +} + +func (o IpmiResetServerOpts) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o IpmiResetServerOpts) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.CallbackUrl) { + toSerialize["callbackUrl"] = o.CallbackUrl + } + if !IsNil(o.PowerCycle) { + toSerialize["powerCycle"] = o.PowerCycle + } + return toSerialize, nil +} + +type NullableIpmiResetServerOpts struct { + value *IpmiResetServerOpts + isSet bool +} + +func (v NullableIpmiResetServerOpts) Get() *IpmiResetServerOpts { + return v.value +} + +func (v *NullableIpmiResetServerOpts) Set(val *IpmiResetServerOpts) { + v.value = val + v.isSet = true +} + +func (v NullableIpmiResetServerOpts) IsSet() bool { + return v.isSet +} + +func (v *NullableIpmiResetServerOpts) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableIpmiResetServerOpts(val *IpmiResetServerOpts) *NullableIpmiResetServerOpts { + return &NullableIpmiResetServerOpts{value: val, isSet: true} +} + +func (v NullableIpmiResetServerOpts) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableIpmiResetServerOpts) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/bmp/model_last_client_request.go b/bmp/model_last_client_request.go new file mode 100644 index 0000000..943d736 --- /dev/null +++ b/bmp/model_last_client_request.go @@ -0,0 +1,212 @@ +/* +bmp + +This documents the rest api bmp api provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package bmp + +import ( + "encoding/json" +) + +// checks if the LastClientRequest type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &LastClientRequest{} + +// LastClientRequest If the server acquired this DHCP reservation, this object shows information about the client +type LastClientRequest struct { + // The relay agent that forwarded the DHCP traffic + RelayAgent NullableString `json:"relayAgent,omitempty"` + // The type of DHCP packet requested by the client + Type *string `json:"type,omitempty"` + // The user agent of the client making the DHCP request + UserAgent *string `json:"userAgent,omitempty"` +} + +// NewLastClientRequest instantiates a new LastClientRequest object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewLastClientRequest() *LastClientRequest { + this := LastClientRequest{} + return &this +} + +// NewLastClientRequestWithDefaults instantiates a new LastClientRequest object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewLastClientRequestWithDefaults() *LastClientRequest { + this := LastClientRequest{} + return &this +} + +// GetRelayAgent returns the RelayAgent field value if set, zero value otherwise (both if not set or set to explicit null). +func (o *LastClientRequest) GetRelayAgent() string { + if o == nil || IsNil(o.RelayAgent.Get()) { + var ret string + return ret + } + return *o.RelayAgent.Get() +} + +// GetRelayAgentOk returns a tuple with the RelayAgent field value if set, nil otherwise +// and a boolean to check if the value has been set. +// NOTE: If the value is an explicit nil, `nil, true` will be returned +func (o *LastClientRequest) GetRelayAgentOk() (*string, bool) { + if o == nil { + return nil, false + } + return o.RelayAgent.Get(), o.RelayAgent.IsSet() +} + +// HasRelayAgent returns a boolean if a field has been set. +func (o *LastClientRequest) HasRelayAgent() bool { + if o != nil && o.RelayAgent.IsSet() { + return true + } + + return false +} + +// SetRelayAgent gets a reference to the given NullableString and assigns it to the RelayAgent field. +func (o *LastClientRequest) SetRelayAgent(v string) { + o.RelayAgent.Set(&v) +} +// SetRelayAgentNil sets the value for RelayAgent to be an explicit nil +func (o *LastClientRequest) SetRelayAgentNil() { + o.RelayAgent.Set(nil) +} + +// UnsetRelayAgent ensures that no value is present for RelayAgent, not even an explicit nil +func (o *LastClientRequest) UnsetRelayAgent() { + o.RelayAgent.Unset() +} + +// GetType returns the Type field value if set, zero value otherwise. +func (o *LastClientRequest) GetType() string { + if o == nil || IsNil(o.Type) { + var ret string + return ret + } + return *o.Type +} + +// GetTypeOk returns a tuple with the Type field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *LastClientRequest) GetTypeOk() (*string, bool) { + if o == nil || IsNil(o.Type) { + return nil, false + } + return o.Type, true +} + +// HasType returns a boolean if a field has been set. +func (o *LastClientRequest) HasType() bool { + if o != nil && !IsNil(o.Type) { + return true + } + + return false +} + +// SetType gets a reference to the given string and assigns it to the Type field. +func (o *LastClientRequest) SetType(v string) { + o.Type = &v +} + +// GetUserAgent returns the UserAgent field value if set, zero value otherwise. +func (o *LastClientRequest) GetUserAgent() string { + if o == nil || IsNil(o.UserAgent) { + var ret string + return ret + } + return *o.UserAgent +} + +// GetUserAgentOk returns a tuple with the UserAgent field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *LastClientRequest) GetUserAgentOk() (*string, bool) { + if o == nil || IsNil(o.UserAgent) { + return nil, false + } + return o.UserAgent, true +} + +// HasUserAgent returns a boolean if a field has been set. +func (o *LastClientRequest) HasUserAgent() bool { + if o != nil && !IsNil(o.UserAgent) { + return true + } + + return false +} + +// SetUserAgent gets a reference to the given string and assigns it to the UserAgent field. +func (o *LastClientRequest) SetUserAgent(v string) { + o.UserAgent = &v +} + +func (o LastClientRequest) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o LastClientRequest) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if o.RelayAgent.IsSet() { + toSerialize["relayAgent"] = o.RelayAgent.Get() + } + if !IsNil(o.Type) { + toSerialize["type"] = o.Type + } + if !IsNil(o.UserAgent) { + toSerialize["userAgent"] = o.UserAgent + } + return toSerialize, nil +} + +type NullableLastClientRequest struct { + value *LastClientRequest + isSet bool +} + +func (v NullableLastClientRequest) Get() *LastClientRequest { + return v.value +} + +func (v *NullableLastClientRequest) Set(val *LastClientRequest) { + v.value = val + v.isSet = true +} + +func (v NullableLastClientRequest) IsSet() bool { + return v.isSet +} + +func (v *NullableLastClientRequest) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableLastClientRequest(val *LastClientRequest) *NullableLastClientRequest { + return &NullableLastClientRequest{value: val, isSet: true} +} + +func (v NullableLastClientRequest) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableLastClientRequest) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/bmp/model_lease.go b/bmp/model_lease.go new file mode 100644 index 0000000..7d8e8fb --- /dev/null +++ b/bmp/model_lease.go @@ -0,0 +1,460 @@ +/* +bmp + +This documents the rest api bmp api provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package bmp + +import ( + "encoding/json" +) + +// checks if the Lease type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &Lease{} + +// Lease A single DHCP reservation +type Lease struct { + // The PXE bootfile the server will network boot from + Bootfile *string `json:"bootfile,omitempty"` + // The time when the DHCP reservation was created + CreatedAt *string `json:"createdAt,omitempty"` + // The gateway for this DHCP reservation + Gateway *string `json:"gateway,omitempty"` + // The hostname for the server + Hostname *string `json:"hostname,omitempty"` + // The IP address this DHCP reservation is for + Ip *string `json:"ip,omitempty"` + LastClientRequest *LastClientRequest `json:"lastClientRequest,omitempty"` + // The MAC address this DHCP reservation is for + Mac *string `json:"mac,omitempty"` + // The netmask for this DHCP reservation + Netmask *string `json:"netmask,omitempty"` + // The site serving this DHCP reservation + Site *string `json:"site,omitempty"` + // The time when the DHCP reservation was last updated or used by a client + UpdatedAt *string `json:"updatedAt,omitempty"` +} + +// NewLease instantiates a new Lease object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewLease() *Lease { + this := Lease{} + return &this +} + +// NewLeaseWithDefaults instantiates a new Lease object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewLeaseWithDefaults() *Lease { + this := Lease{} + return &this +} + +// GetBootfile returns the Bootfile field value if set, zero value otherwise. +func (o *Lease) GetBootfile() string { + if o == nil || IsNil(o.Bootfile) { + var ret string + return ret + } + return *o.Bootfile +} + +// GetBootfileOk returns a tuple with the Bootfile field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Lease) GetBootfileOk() (*string, bool) { + if o == nil || IsNil(o.Bootfile) { + return nil, false + } + return o.Bootfile, true +} + +// HasBootfile returns a boolean if a field has been set. +func (o *Lease) HasBootfile() bool { + if o != nil && !IsNil(o.Bootfile) { + return true + } + + return false +} + +// SetBootfile gets a reference to the given string and assigns it to the Bootfile field. +func (o *Lease) SetBootfile(v string) { + o.Bootfile = &v +} + +// GetCreatedAt returns the CreatedAt field value if set, zero value otherwise. +func (o *Lease) GetCreatedAt() string { + if o == nil || IsNil(o.CreatedAt) { + var ret string + return ret + } + return *o.CreatedAt +} + +// GetCreatedAtOk returns a tuple with the CreatedAt field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Lease) GetCreatedAtOk() (*string, bool) { + if o == nil || IsNil(o.CreatedAt) { + return nil, false + } + return o.CreatedAt, true +} + +// HasCreatedAt returns a boolean if a field has been set. +func (o *Lease) HasCreatedAt() bool { + if o != nil && !IsNil(o.CreatedAt) { + return true + } + + return false +} + +// SetCreatedAt gets a reference to the given string and assigns it to the CreatedAt field. +func (o *Lease) SetCreatedAt(v string) { + o.CreatedAt = &v +} + +// GetGateway returns the Gateway field value if set, zero value otherwise. +func (o *Lease) GetGateway() string { + if o == nil || IsNil(o.Gateway) { + var ret string + return ret + } + return *o.Gateway +} + +// GetGatewayOk returns a tuple with the Gateway field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Lease) GetGatewayOk() (*string, bool) { + if o == nil || IsNil(o.Gateway) { + return nil, false + } + return o.Gateway, true +} + +// HasGateway returns a boolean if a field has been set. +func (o *Lease) HasGateway() bool { + if o != nil && !IsNil(o.Gateway) { + return true + } + + return false +} + +// SetGateway gets a reference to the given string and assigns it to the Gateway field. +func (o *Lease) SetGateway(v string) { + o.Gateway = &v +} + +// GetHostname returns the Hostname field value if set, zero value otherwise. +func (o *Lease) GetHostname() string { + if o == nil || IsNil(o.Hostname) { + var ret string + return ret + } + return *o.Hostname +} + +// GetHostnameOk returns a tuple with the Hostname field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Lease) GetHostnameOk() (*string, bool) { + if o == nil || IsNil(o.Hostname) { + return nil, false + } + return o.Hostname, true +} + +// HasHostname returns a boolean if a field has been set. +func (o *Lease) HasHostname() bool { + if o != nil && !IsNil(o.Hostname) { + return true + } + + return false +} + +// SetHostname gets a reference to the given string and assigns it to the Hostname field. +func (o *Lease) SetHostname(v string) { + o.Hostname = &v +} + +// GetIp returns the Ip field value if set, zero value otherwise. +func (o *Lease) GetIp() string { + if o == nil || IsNil(o.Ip) { + var ret string + return ret + } + return *o.Ip +} + +// GetIpOk returns a tuple with the Ip field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Lease) GetIpOk() (*string, bool) { + if o == nil || IsNil(o.Ip) { + return nil, false + } + return o.Ip, true +} + +// HasIp returns a boolean if a field has been set. +func (o *Lease) HasIp() bool { + if o != nil && !IsNil(o.Ip) { + return true + } + + return false +} + +// SetIp gets a reference to the given string and assigns it to the Ip field. +func (o *Lease) SetIp(v string) { + o.Ip = &v +} + +// GetLastClientRequest returns the LastClientRequest field value if set, zero value otherwise. +func (o *Lease) GetLastClientRequest() LastClientRequest { + if o == nil || IsNil(o.LastClientRequest) { + var ret LastClientRequest + return ret + } + return *o.LastClientRequest +} + +// GetLastClientRequestOk returns a tuple with the LastClientRequest field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Lease) GetLastClientRequestOk() (*LastClientRequest, bool) { + if o == nil || IsNil(o.LastClientRequest) { + return nil, false + } + return o.LastClientRequest, true +} + +// HasLastClientRequest returns a boolean if a field has been set. +func (o *Lease) HasLastClientRequest() bool { + if o != nil && !IsNil(o.LastClientRequest) { + return true + } + + return false +} + +// SetLastClientRequest gets a reference to the given LastClientRequest and assigns it to the LastClientRequest field. +func (o *Lease) SetLastClientRequest(v LastClientRequest) { + o.LastClientRequest = &v +} + +// GetMac returns the Mac field value if set, zero value otherwise. +func (o *Lease) GetMac() string { + if o == nil || IsNil(o.Mac) { + var ret string + return ret + } + return *o.Mac +} + +// GetMacOk returns a tuple with the Mac field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Lease) GetMacOk() (*string, bool) { + if o == nil || IsNil(o.Mac) { + return nil, false + } + return o.Mac, true +} + +// HasMac returns a boolean if a field has been set. +func (o *Lease) HasMac() bool { + if o != nil && !IsNil(o.Mac) { + return true + } + + return false +} + +// SetMac gets a reference to the given string and assigns it to the Mac field. +func (o *Lease) SetMac(v string) { + o.Mac = &v +} + +// GetNetmask returns the Netmask field value if set, zero value otherwise. +func (o *Lease) GetNetmask() string { + if o == nil || IsNil(o.Netmask) { + var ret string + return ret + } + return *o.Netmask +} + +// GetNetmaskOk returns a tuple with the Netmask field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Lease) GetNetmaskOk() (*string, bool) { + if o == nil || IsNil(o.Netmask) { + return nil, false + } + return o.Netmask, true +} + +// HasNetmask returns a boolean if a field has been set. +func (o *Lease) HasNetmask() bool { + if o != nil && !IsNil(o.Netmask) { + return true + } + + return false +} + +// SetNetmask gets a reference to the given string and assigns it to the Netmask field. +func (o *Lease) SetNetmask(v string) { + o.Netmask = &v +} + +// GetSite returns the Site field value if set, zero value otherwise. +func (o *Lease) GetSite() string { + if o == nil || IsNil(o.Site) { + var ret string + return ret + } + return *o.Site +} + +// GetSiteOk returns a tuple with the Site field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Lease) GetSiteOk() (*string, bool) { + if o == nil || IsNil(o.Site) { + return nil, false + } + return o.Site, true +} + +// HasSite returns a boolean if a field has been set. +func (o *Lease) HasSite() bool { + if o != nil && !IsNil(o.Site) { + return true + } + + return false +} + +// SetSite gets a reference to the given string and assigns it to the Site field. +func (o *Lease) SetSite(v string) { + o.Site = &v +} + +// GetUpdatedAt returns the UpdatedAt field value if set, zero value otherwise. +func (o *Lease) GetUpdatedAt() string { + if o == nil || IsNil(o.UpdatedAt) { + var ret string + return ret + } + return *o.UpdatedAt +} + +// GetUpdatedAtOk returns a tuple with the UpdatedAt field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Lease) GetUpdatedAtOk() (*string, bool) { + if o == nil || IsNil(o.UpdatedAt) { + return nil, false + } + return o.UpdatedAt, true +} + +// HasUpdatedAt returns a boolean if a field has been set. +func (o *Lease) HasUpdatedAt() bool { + if o != nil && !IsNil(o.UpdatedAt) { + return true + } + + return false +} + +// SetUpdatedAt gets a reference to the given string and assigns it to the UpdatedAt field. +func (o *Lease) SetUpdatedAt(v string) { + o.UpdatedAt = &v +} + +func (o Lease) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o Lease) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Bootfile) { + toSerialize["bootfile"] = o.Bootfile + } + if !IsNil(o.CreatedAt) { + toSerialize["createdAt"] = o.CreatedAt + } + if !IsNil(o.Gateway) { + toSerialize["gateway"] = o.Gateway + } + if !IsNil(o.Hostname) { + toSerialize["hostname"] = o.Hostname + } + if !IsNil(o.Ip) { + toSerialize["ip"] = o.Ip + } + if !IsNil(o.LastClientRequest) { + toSerialize["lastClientRequest"] = o.LastClientRequest + } + if !IsNil(o.Mac) { + toSerialize["mac"] = o.Mac + } + if !IsNil(o.Netmask) { + toSerialize["netmask"] = o.Netmask + } + if !IsNil(o.Site) { + toSerialize["site"] = o.Site + } + if !IsNil(o.UpdatedAt) { + toSerialize["updatedAt"] = o.UpdatedAt + } + return toSerialize, nil +} + +type NullableLease struct { + value *Lease + isSet bool +} + +func (v NullableLease) Get() *Lease { + return v.value +} + +func (v *NullableLease) Set(val *Lease) { + v.value = val + v.isSet = true +} + +func (v NullableLease) IsSet() bool { + return v.isSet +} + +func (v *NullableLease) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableLease(val *Lease) *NullableLease { + return &NullableLease{value: val, isSet: true} +} + +func (v NullableLease) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableLease) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/bmp/model_operating_system.go b/bmp/model_operating_system.go new file mode 100644 index 0000000..4cd569c --- /dev/null +++ b/bmp/model_operating_system.go @@ -0,0 +1,165 @@ +/* +bmp + +This documents the rest api bmp api provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package bmp + +import ( + "encoding/json" +) + +// checks if the OperatingSystem type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &OperatingSystem{} + +// OperatingSystem A single operating system +type OperatingSystem struct { + // The unique ID of this operating system + Id *string `json:"id,omitempty"` + // A human readable name describing the operating system + Name *string `json:"name,omitempty"` +} + +// NewOperatingSystem instantiates a new OperatingSystem object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewOperatingSystem() *OperatingSystem { + this := OperatingSystem{} + return &this +} + +// NewOperatingSystemWithDefaults instantiates a new OperatingSystem object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewOperatingSystemWithDefaults() *OperatingSystem { + this := OperatingSystem{} + return &this +} + +// GetId returns the Id field value if set, zero value otherwise. +func (o *OperatingSystem) GetId() string { + if o == nil || IsNil(o.Id) { + var ret string + return ret + } + return *o.Id +} + +// GetIdOk returns a tuple with the Id field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *OperatingSystem) GetIdOk() (*string, bool) { + if o == nil || IsNil(o.Id) { + return nil, false + } + return o.Id, true +} + +// HasId returns a boolean if a field has been set. +func (o *OperatingSystem) HasId() bool { + if o != nil && !IsNil(o.Id) { + return true + } + + return false +} + +// SetId gets a reference to the given string and assigns it to the Id field. +func (o *OperatingSystem) SetId(v string) { + o.Id = &v +} + +// GetName returns the Name field value if set, zero value otherwise. +func (o *OperatingSystem) GetName() string { + if o == nil || IsNil(o.Name) { + var ret string + return ret + } + return *o.Name +} + +// GetNameOk returns a tuple with the Name field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *OperatingSystem) GetNameOk() (*string, bool) { + if o == nil || IsNil(o.Name) { + return nil, false + } + return o.Name, true +} + +// HasName returns a boolean if a field has been set. +func (o *OperatingSystem) HasName() bool { + if o != nil && !IsNil(o.Name) { + return true + } + + return false +} + +// SetName gets a reference to the given string and assigns it to the Name field. +func (o *OperatingSystem) SetName(v string) { + o.Name = &v +} + +func (o OperatingSystem) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o OperatingSystem) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Id) { + toSerialize["id"] = o.Id + } + if !IsNil(o.Name) { + toSerialize["name"] = o.Name + } + return toSerialize, nil +} + +type NullableOperatingSystem struct { + value *OperatingSystem + isSet bool +} + +func (v NullableOperatingSystem) Get() *OperatingSystem { + return v.value +} + +func (v *NullableOperatingSystem) Set(val *OperatingSystem) { + v.value = val + v.isSet = true +} + +func (v NullableOperatingSystem) IsSet() bool { + return v.isSet +} + +func (v *NullableOperatingSystem) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableOperatingSystem(val *OperatingSystem) *NullableOperatingSystem { + return &NullableOperatingSystem{value: val, isSet: true} +} + +func (v NullableOperatingSystem) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableOperatingSystem) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/bmp/model_partition.go b/bmp/model_partition.go new file mode 100644 index 0000000..e4fc2dd --- /dev/null +++ b/bmp/model_partition.go @@ -0,0 +1,202 @@ +/* +bmp + +This documents the rest api bmp api provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package bmp + +import ( + "encoding/json" +) + +// checks if the Partition type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &Partition{} + +// Partition struct for Partition +type Partition struct { + // File system in which partition would be mounted + Filesystem *string `json:"filesystem,omitempty"` + // The partition mount point (eg `/home`). Mandatory for the root partition (`/`) and not intended to be used in swap partition + Mountpoint *string `json:"mountpoint,omitempty"` + // Size of the partition (Normally in MB, but this is OS-specific) + Size *string `json:"size,omitempty"` +} + +// NewPartition instantiates a new Partition object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewPartition() *Partition { + this := Partition{} + return &this +} + +// NewPartitionWithDefaults instantiates a new Partition object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewPartitionWithDefaults() *Partition { + this := Partition{} + return &this +} + +// GetFilesystem returns the Filesystem field value if set, zero value otherwise. +func (o *Partition) GetFilesystem() string { + if o == nil || IsNil(o.Filesystem) { + var ret string + return ret + } + return *o.Filesystem +} + +// GetFilesystemOk returns a tuple with the Filesystem field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Partition) GetFilesystemOk() (*string, bool) { + if o == nil || IsNil(o.Filesystem) { + return nil, false + } + return o.Filesystem, true +} + +// HasFilesystem returns a boolean if a field has been set. +func (o *Partition) HasFilesystem() bool { + if o != nil && !IsNil(o.Filesystem) { + return true + } + + return false +} + +// SetFilesystem gets a reference to the given string and assigns it to the Filesystem field. +func (o *Partition) SetFilesystem(v string) { + o.Filesystem = &v +} + +// GetMountpoint returns the Mountpoint field value if set, zero value otherwise. +func (o *Partition) GetMountpoint() string { + if o == nil || IsNil(o.Mountpoint) { + var ret string + return ret + } + return *o.Mountpoint +} + +// GetMountpointOk returns a tuple with the Mountpoint field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Partition) GetMountpointOk() (*string, bool) { + if o == nil || IsNil(o.Mountpoint) { + return nil, false + } + return o.Mountpoint, true +} + +// HasMountpoint returns a boolean if a field has been set. +func (o *Partition) HasMountpoint() bool { + if o != nil && !IsNil(o.Mountpoint) { + return true + } + + return false +} + +// SetMountpoint gets a reference to the given string and assigns it to the Mountpoint field. +func (o *Partition) SetMountpoint(v string) { + o.Mountpoint = &v +} + +// GetSize returns the Size field value if set, zero value otherwise. +func (o *Partition) GetSize() string { + if o == nil || IsNil(o.Size) { + var ret string + return ret + } + return *o.Size +} + +// GetSizeOk returns a tuple with the Size field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Partition) GetSizeOk() (*string, bool) { + if o == nil || IsNil(o.Size) { + return nil, false + } + return o.Size, true +} + +// HasSize returns a boolean if a field has been set. +func (o *Partition) HasSize() bool { + if o != nil && !IsNil(o.Size) { + return true + } + + return false +} + +// SetSize gets a reference to the given string and assigns it to the Size field. +func (o *Partition) SetSize(v string) { + o.Size = &v +} + +func (o Partition) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o Partition) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Filesystem) { + toSerialize["filesystem"] = o.Filesystem + } + if !IsNil(o.Mountpoint) { + toSerialize["mountpoint"] = o.Mountpoint + } + if !IsNil(o.Size) { + toSerialize["size"] = o.Size + } + return toSerialize, nil +} + +type NullablePartition struct { + value *Partition + isSet bool +} + +func (v NullablePartition) Get() *Partition { + return v.value +} + +func (v *NullablePartition) Set(val *Partition) { + v.value = val + v.isSet = true +} + +func (v NullablePartition) IsSet() bool { + return v.isSet +} + +func (v *NullablePartition) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullablePartition(val *Partition) *NullablePartition { + return &NullablePartition{value: val, isSet: true} +} + +func (v NullablePartition) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullablePartition) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/bmp/model_pdu.go b/bmp/model_pdu.go new file mode 100644 index 0000000..f9743ab --- /dev/null +++ b/bmp/model_pdu.go @@ -0,0 +1,128 @@ +/* +bmp + +This documents the rest api bmp api provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package bmp + +import ( + "encoding/json" +) + +// checks if the Pdu type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &Pdu{} + +// Pdu Object describing the PDU power information +type Pdu struct { + // The current power status of the network equipment. + Status *string `json:"status,omitempty"` +} + +// NewPdu instantiates a new Pdu object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewPdu() *Pdu { + this := Pdu{} + return &this +} + +// NewPduWithDefaults instantiates a new Pdu object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewPduWithDefaults() *Pdu { + this := Pdu{} + return &this +} + +// GetStatus returns the Status field value if set, zero value otherwise. +func (o *Pdu) GetStatus() string { + if o == nil || IsNil(o.Status) { + var ret string + return ret + } + return *o.Status +} + +// GetStatusOk returns a tuple with the Status field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Pdu) GetStatusOk() (*string, bool) { + if o == nil || IsNil(o.Status) { + return nil, false + } + return o.Status, true +} + +// HasStatus returns a boolean if a field has been set. +func (o *Pdu) HasStatus() bool { + if o != nil && !IsNil(o.Status) { + return true + } + + return false +} + +// SetStatus gets a reference to the given string and assigns it to the Status field. +func (o *Pdu) SetStatus(v string) { + o.Status = &v +} + +func (o Pdu) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o Pdu) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Status) { + toSerialize["status"] = o.Status + } + return toSerialize, nil +} + +type NullablePdu struct { + value *Pdu + isSet bool +} + +func (v NullablePdu) Get() *Pdu { + return v.value +} + +func (v *NullablePdu) Set(val *Pdu) { + v.value = val + v.isSet = true +} + +func (v NullablePdu) IsSet() bool { + return v.isSet +} + +func (v *NullablePdu) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullablePdu(val *Pdu) *NullablePdu { + return &NullablePdu{value: val, isSet: true} +} + +func (v NullablePdu) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullablePdu) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/bmp/model_raid.go b/bmp/model_raid.go new file mode 100644 index 0000000..fc7da6b --- /dev/null +++ b/bmp/model_raid.go @@ -0,0 +1,201 @@ +/* +bmp + +This documents the rest api bmp api provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package bmp + +import ( + "encoding/json" +) + +// checks if the Raid type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &Raid{} + +// Raid Contains RAID related information about the installation request +type Raid struct { + // RAID level to apply to your installation, this value is only required if you specify a type HW or SW + Level *int32 `json:"level,omitempty"` + // The number of disks you want to apply RAID on. If not specified all disks are used + NumberOfDisks *int32 `json:"numberOfDisks,omitempty"` + Type *RaidType `json:"type,omitempty"` +} + +// NewRaid instantiates a new Raid object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewRaid() *Raid { + this := Raid{} + return &this +} + +// NewRaidWithDefaults instantiates a new Raid object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewRaidWithDefaults() *Raid { + this := Raid{} + return &this +} + +// GetLevel returns the Level field value if set, zero value otherwise. +func (o *Raid) GetLevel() int32 { + if o == nil || IsNil(o.Level) { + var ret int32 + return ret + } + return *o.Level +} + +// GetLevelOk returns a tuple with the Level field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Raid) GetLevelOk() (*int32, bool) { + if o == nil || IsNil(o.Level) { + return nil, false + } + return o.Level, true +} + +// HasLevel returns a boolean if a field has been set. +func (o *Raid) HasLevel() bool { + if o != nil && !IsNil(o.Level) { + return true + } + + return false +} + +// SetLevel gets a reference to the given int32 and assigns it to the Level field. +func (o *Raid) SetLevel(v int32) { + o.Level = &v +} + +// GetNumberOfDisks returns the NumberOfDisks field value if set, zero value otherwise. +func (o *Raid) GetNumberOfDisks() int32 { + if o == nil || IsNil(o.NumberOfDisks) { + var ret int32 + return ret + } + return *o.NumberOfDisks +} + +// GetNumberOfDisksOk returns a tuple with the NumberOfDisks field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Raid) GetNumberOfDisksOk() (*int32, bool) { + if o == nil || IsNil(o.NumberOfDisks) { + return nil, false + } + return o.NumberOfDisks, true +} + +// HasNumberOfDisks returns a boolean if a field has been set. +func (o *Raid) HasNumberOfDisks() bool { + if o != nil && !IsNil(o.NumberOfDisks) { + return true + } + + return false +} + +// SetNumberOfDisks gets a reference to the given int32 and assigns it to the NumberOfDisks field. +func (o *Raid) SetNumberOfDisks(v int32) { + o.NumberOfDisks = &v +} + +// GetType returns the Type field value if set, zero value otherwise. +func (o *Raid) GetType() RaidType { + if o == nil || IsNil(o.Type) { + var ret RaidType + return ret + } + return *o.Type +} + +// GetTypeOk returns a tuple with the Type field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Raid) GetTypeOk() (*RaidType, bool) { + if o == nil || IsNil(o.Type) { + return nil, false + } + return o.Type, true +} + +// HasType returns a boolean if a field has been set. +func (o *Raid) HasType() bool { + if o != nil && !IsNil(o.Type) { + return true + } + + return false +} + +// SetType gets a reference to the given RaidType and assigns it to the Type field. +func (o *Raid) SetType(v RaidType) { + o.Type = &v +} + +func (o Raid) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o Raid) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Level) { + toSerialize["level"] = o.Level + } + if !IsNil(o.NumberOfDisks) { + toSerialize["numberOfDisks"] = o.NumberOfDisks + } + if !IsNil(o.Type) { + toSerialize["type"] = o.Type + } + return toSerialize, nil +} + +type NullableRaid struct { + value *Raid + isSet bool +} + +func (v NullableRaid) Get() *Raid { + return v.value +} + +func (v *NullableRaid) Set(val *Raid) { + v.value = val + v.isSet = true +} + +func (v NullableRaid) IsSet() bool { + return v.isSet +} + +func (v *NullableRaid) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableRaid(val *Raid) *NullableRaid { + return &NullableRaid{value: val, isSet: true} +} + +func (v NullableRaid) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableRaid) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/bmp/model_raid_type.go b/bmp/model_raid_type.go new file mode 100644 index 0000000..a2918db --- /dev/null +++ b/bmp/model_raid_type.go @@ -0,0 +1,114 @@ +/* +bmp + +This documents the rest api bmp api provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package bmp + +import ( + "encoding/json" + "fmt" +) + +// RaidType RAID type to apply to your installation. NONE is the equivalent of pass-through mode on HW RAID equipped servers +type RaidType string + +// List of raidType +const ( + HW RaidType = "HW" + SW RaidType = "SW" + NONE RaidType = "NONE" +) + +// All allowed values of RaidType enum +var AllowedRaidTypeEnumValues = []RaidType{ + "HW", + "SW", + "NONE", +} + +func (v *RaidType) UnmarshalJSON(src []byte) error { + var value string + err := json.Unmarshal(src, &value) + if err != nil { + return err + } + enumTypeValue := RaidType(value) + for _, existing := range AllowedRaidTypeEnumValues { + if existing == enumTypeValue { + *v = enumTypeValue + return nil + } + } + + return fmt.Errorf("%+v is not a valid RaidType", value) +} + +// NewRaidTypeFromValue returns a pointer to a valid RaidType +// for the value passed as argument, or an error if the value passed is not allowed by the enum +func NewRaidTypeFromValue(v string) (*RaidType, error) { + ev := RaidType(v) + if ev.IsValid() { + return &ev, nil + } else { + return nil, fmt.Errorf("invalid value '%v' for RaidType: valid values are %v", v, AllowedRaidTypeEnumValues) + } +} + +// IsValid return true if the value is valid for the enum, false otherwise +func (v RaidType) IsValid() bool { + for _, existing := range AllowedRaidTypeEnumValues { + if existing == v { + return true + } + } + return false +} + +// Ptr returns reference to raidType value +func (v RaidType) Ptr() *RaidType { + return &v +} + +type NullableRaidType struct { + value *RaidType + isSet bool +} + +func (v NullableRaidType) Get() *RaidType { + return v.value +} + +func (v *NullableRaidType) Set(val *RaidType) { + v.value = val + v.isSet = true +} + +func (v NullableRaidType) IsSet() bool { + return v.isSet +} + +func (v *NullableRaidType) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableRaidType(val *RaidType) *NullableRaidType { + return &NullableRaidType{value: val, isSet: true} +} + +func (v NullableRaidType) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableRaidType) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + diff --git a/bmp/model_rescue_image.go b/bmp/model_rescue_image.go new file mode 100644 index 0000000..817ae7a --- /dev/null +++ b/bmp/model_rescue_image.go @@ -0,0 +1,165 @@ +/* +bmp + +This documents the rest api bmp api provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package bmp + +import ( + "encoding/json" +) + +// checks if the RescueImage type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &RescueImage{} + +// RescueImage A single rescue image +type RescueImage struct { + // The unique ID of this rescue image + Id *string `json:"id,omitempty"` + // A human readable name describing the rescue image + Name *string `json:"name,omitempty"` +} + +// NewRescueImage instantiates a new RescueImage object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewRescueImage() *RescueImage { + this := RescueImage{} + return &this +} + +// NewRescueImageWithDefaults instantiates a new RescueImage object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewRescueImageWithDefaults() *RescueImage { + this := RescueImage{} + return &this +} + +// GetId returns the Id field value if set, zero value otherwise. +func (o *RescueImage) GetId() string { + if o == nil || IsNil(o.Id) { + var ret string + return ret + } + return *o.Id +} + +// GetIdOk returns a tuple with the Id field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *RescueImage) GetIdOk() (*string, bool) { + if o == nil || IsNil(o.Id) { + return nil, false + } + return o.Id, true +} + +// HasId returns a boolean if a field has been set. +func (o *RescueImage) HasId() bool { + if o != nil && !IsNil(o.Id) { + return true + } + + return false +} + +// SetId gets a reference to the given string and assigns it to the Id field. +func (o *RescueImage) SetId(v string) { + o.Id = &v +} + +// GetName returns the Name field value if set, zero value otherwise. +func (o *RescueImage) GetName() string { + if o == nil || IsNil(o.Name) { + var ret string + return ret + } + return *o.Name +} + +// GetNameOk returns a tuple with the Name field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *RescueImage) GetNameOk() (*string, bool) { + if o == nil || IsNil(o.Name) { + return nil, false + } + return o.Name, true +} + +// HasName returns a boolean if a field has been set. +func (o *RescueImage) HasName() bool { + if o != nil && !IsNil(o.Name) { + return true + } + + return false +} + +// SetName gets a reference to the given string and assigns it to the Name field. +func (o *RescueImage) SetName(v string) { + o.Name = &v +} + +func (o RescueImage) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o RescueImage) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Id) { + toSerialize["id"] = o.Id + } + if !IsNil(o.Name) { + toSerialize["name"] = o.Name + } + return toSerialize, nil +} + +type NullableRescueImage struct { + value *RescueImage + isSet bool +} + +func (v NullableRescueImage) Get() *RescueImage { + return v.value +} + +func (v *NullableRescueImage) Set(val *RescueImage) { + v.value = val + v.isSet = true +} + +func (v NullableRescueImage) IsSet() bool { + return v.isSet +} + +func (v *NullableRescueImage) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableRescueImage(val *RescueImage) *NullableRescueImage { + return &NullableRescueImage{value: val, isSet: true} +} + +func (v NullableRescueImage) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableRescueImage) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/bmp/model_scan_hardware_opts.go b/bmp/model_scan_hardware_opts.go new file mode 100644 index 0000000..4fd23a4 --- /dev/null +++ b/bmp/model_scan_hardware_opts.go @@ -0,0 +1,169 @@ +/* +bmp + +This documents the rest api bmp api provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package bmp + +import ( + "encoding/json" +) + +// checks if the ScanHardwareOpts type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &ScanHardwareOpts{} + +// ScanHardwareOpts struct for ScanHardwareOpts +type ScanHardwareOpts struct { + // Url which will receive callbacks + CallbackUrl *string `json:"callbackUrl,omitempty"` + // If set to `true`, server will be power cycled in order to complete the operation + PowerCycle *bool `json:"powerCycle,omitempty"` +} + +// NewScanHardwareOpts instantiates a new ScanHardwareOpts object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewScanHardwareOpts() *ScanHardwareOpts { + this := ScanHardwareOpts{} + var powerCycle bool = true + this.PowerCycle = &powerCycle + return &this +} + +// NewScanHardwareOptsWithDefaults instantiates a new ScanHardwareOpts object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewScanHardwareOptsWithDefaults() *ScanHardwareOpts { + this := ScanHardwareOpts{} + var powerCycle bool = true + this.PowerCycle = &powerCycle + return &this +} + +// GetCallbackUrl returns the CallbackUrl field value if set, zero value otherwise. +func (o *ScanHardwareOpts) GetCallbackUrl() string { + if o == nil || IsNil(o.CallbackUrl) { + var ret string + return ret + } + return *o.CallbackUrl +} + +// GetCallbackUrlOk returns a tuple with the CallbackUrl field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ScanHardwareOpts) GetCallbackUrlOk() (*string, bool) { + if o == nil || IsNil(o.CallbackUrl) { + return nil, false + } + return o.CallbackUrl, true +} + +// HasCallbackUrl returns a boolean if a field has been set. +func (o *ScanHardwareOpts) HasCallbackUrl() bool { + if o != nil && !IsNil(o.CallbackUrl) { + return true + } + + return false +} + +// SetCallbackUrl gets a reference to the given string and assigns it to the CallbackUrl field. +func (o *ScanHardwareOpts) SetCallbackUrl(v string) { + o.CallbackUrl = &v +} + +// GetPowerCycle returns the PowerCycle field value if set, zero value otherwise. +func (o *ScanHardwareOpts) GetPowerCycle() bool { + if o == nil || IsNil(o.PowerCycle) { + var ret bool + return ret + } + return *o.PowerCycle +} + +// GetPowerCycleOk returns a tuple with the PowerCycle field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ScanHardwareOpts) GetPowerCycleOk() (*bool, bool) { + if o == nil || IsNil(o.PowerCycle) { + return nil, false + } + return o.PowerCycle, true +} + +// HasPowerCycle returns a boolean if a field has been set. +func (o *ScanHardwareOpts) HasPowerCycle() bool { + if o != nil && !IsNil(o.PowerCycle) { + return true + } + + return false +} + +// SetPowerCycle gets a reference to the given bool and assigns it to the PowerCycle field. +func (o *ScanHardwareOpts) SetPowerCycle(v bool) { + o.PowerCycle = &v +} + +func (o ScanHardwareOpts) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o ScanHardwareOpts) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.CallbackUrl) { + toSerialize["callbackUrl"] = o.CallbackUrl + } + if !IsNil(o.PowerCycle) { + toSerialize["powerCycle"] = o.PowerCycle + } + return toSerialize, nil +} + +type NullableScanHardwareOpts struct { + value *ScanHardwareOpts + isSet bool +} + +func (v NullableScanHardwareOpts) Get() *ScanHardwareOpts { + return v.value +} + +func (v *NullableScanHardwareOpts) Set(val *ScanHardwareOpts) { + v.value = val + v.isSet = true +} + +func (v NullableScanHardwareOpts) IsSet() bool { + return v.isSet +} + +func (v *NullableScanHardwareOpts) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableScanHardwareOpts(val *ScanHardwareOpts) *NullableScanHardwareOpts { + return &NullableScanHardwareOpts{value: val, isSet: true} +} + +func (v NullableScanHardwareOpts) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableScanHardwareOpts) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/bmp/model_server_job.go b/bmp/model_server_job.go new file mode 100644 index 0000000..3f23bba --- /dev/null +++ b/bmp/model_server_job.go @@ -0,0 +1,617 @@ +/* +bmp + +This documents the rest api bmp api provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package bmp + +import ( + "encoding/json" + "time" +) + +// checks if the ServerJob type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &ServerJob{} + +// ServerJob struct for ServerJob +type ServerJob struct { + // Id of the server (deprecated, use serverId instead) + // Deprecated + BareMetalId *string `json:"bareMetalId,omitempty"` + // Creation timestamp + CreatedAt *time.Time `json:"createdAt,omitempty"` + // Job flow + Flow *string `json:"flow,omitempty"` + // Describes whether the job is running + IsRunning *bool `json:"isRunning,omitempty"` + Metadata *Metadata `json:"metadata,omitempty"` + // Node ID for this server + Node *string `json:"node,omitempty"` + // Payload of the current job + Payload map[string]interface{} `json:"payload,omitempty"` + // Describes progress of the jobs on the server + Progress map[string]interface{} `json:"progress,omitempty"` + // Id of the server + ServerId *string `json:"serverId,omitempty"` + // Status of the job + Status *string `json:"status,omitempty"` + // List of tasks in the job + Tasks []Task `json:"tasks,omitempty"` + // Type of the job + Type *string `json:"type,omitempty"` + // Update timestamp + UpdatedAt *time.Time `json:"updatedAt,omitempty"` + // Unique identifier of the job + Uuid *string `json:"uuid,omitempty"` +} + +// NewServerJob instantiates a new ServerJob object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewServerJob() *ServerJob { + this := ServerJob{} + var metadata Metadata = {} + this.Metadata = &metadata + return &this +} + +// NewServerJobWithDefaults instantiates a new ServerJob object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewServerJobWithDefaults() *ServerJob { + this := ServerJob{} + var metadata Metadata = {} + this.Metadata = &metadata + return &this +} + +// GetBareMetalId returns the BareMetalId field value if set, zero value otherwise. +// Deprecated +func (o *ServerJob) GetBareMetalId() string { + if o == nil || IsNil(o.BareMetalId) { + var ret string + return ret + } + return *o.BareMetalId +} + +// GetBareMetalIdOk returns a tuple with the BareMetalId field value if set, nil otherwise +// and a boolean to check if the value has been set. +// Deprecated +func (o *ServerJob) GetBareMetalIdOk() (*string, bool) { + if o == nil || IsNil(o.BareMetalId) { + return nil, false + } + return o.BareMetalId, true +} + +// HasBareMetalId returns a boolean if a field has been set. +func (o *ServerJob) HasBareMetalId() bool { + if o != nil && !IsNil(o.BareMetalId) { + return true + } + + return false +} + +// SetBareMetalId gets a reference to the given string and assigns it to the BareMetalId field. +// Deprecated +func (o *ServerJob) SetBareMetalId(v string) { + o.BareMetalId = &v +} + +// GetCreatedAt returns the CreatedAt field value if set, zero value otherwise. +func (o *ServerJob) GetCreatedAt() time.Time { + if o == nil || IsNil(o.CreatedAt) { + var ret time.Time + return ret + } + return *o.CreatedAt +} + +// GetCreatedAtOk returns a tuple with the CreatedAt field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ServerJob) GetCreatedAtOk() (*time.Time, bool) { + if o == nil || IsNil(o.CreatedAt) { + return nil, false + } + return o.CreatedAt, true +} + +// HasCreatedAt returns a boolean if a field has been set. +func (o *ServerJob) HasCreatedAt() bool { + if o != nil && !IsNil(o.CreatedAt) { + return true + } + + return false +} + +// SetCreatedAt gets a reference to the given time.Time and assigns it to the CreatedAt field. +func (o *ServerJob) SetCreatedAt(v time.Time) { + o.CreatedAt = &v +} + +// GetFlow returns the Flow field value if set, zero value otherwise. +func (o *ServerJob) GetFlow() string { + if o == nil || IsNil(o.Flow) { + var ret string + return ret + } + return *o.Flow +} + +// GetFlowOk returns a tuple with the Flow field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ServerJob) GetFlowOk() (*string, bool) { + if o == nil || IsNil(o.Flow) { + return nil, false + } + return o.Flow, true +} + +// HasFlow returns a boolean if a field has been set. +func (o *ServerJob) HasFlow() bool { + if o != nil && !IsNil(o.Flow) { + return true + } + + return false +} + +// SetFlow gets a reference to the given string and assigns it to the Flow field. +func (o *ServerJob) SetFlow(v string) { + o.Flow = &v +} + +// GetIsRunning returns the IsRunning field value if set, zero value otherwise. +func (o *ServerJob) GetIsRunning() bool { + if o == nil || IsNil(o.IsRunning) { + var ret bool + return ret + } + return *o.IsRunning +} + +// GetIsRunningOk returns a tuple with the IsRunning field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ServerJob) GetIsRunningOk() (*bool, bool) { + if o == nil || IsNil(o.IsRunning) { + return nil, false + } + return o.IsRunning, true +} + +// HasIsRunning returns a boolean if a field has been set. +func (o *ServerJob) HasIsRunning() bool { + if o != nil && !IsNil(o.IsRunning) { + return true + } + + return false +} + +// SetIsRunning gets a reference to the given bool and assigns it to the IsRunning field. +func (o *ServerJob) SetIsRunning(v bool) { + o.IsRunning = &v +} + +// GetMetadata returns the Metadata field value if set, zero value otherwise. +func (o *ServerJob) GetMetadata() Metadata { + if o == nil || IsNil(o.Metadata) { + var ret Metadata + return ret + } + return *o.Metadata +} + +// GetMetadataOk returns a tuple with the Metadata field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ServerJob) GetMetadataOk() (*Metadata, bool) { + if o == nil || IsNil(o.Metadata) { + return nil, false + } + return o.Metadata, true +} + +// HasMetadata returns a boolean if a field has been set. +func (o *ServerJob) HasMetadata() bool { + if o != nil && !IsNil(o.Metadata) { + return true + } + + return false +} + +// SetMetadata gets a reference to the given Metadata and assigns it to the Metadata field. +func (o *ServerJob) SetMetadata(v Metadata) { + o.Metadata = &v +} + +// GetNode returns the Node field value if set, zero value otherwise. +func (o *ServerJob) GetNode() string { + if o == nil || IsNil(o.Node) { + var ret string + return ret + } + return *o.Node +} + +// GetNodeOk returns a tuple with the Node field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ServerJob) GetNodeOk() (*string, bool) { + if o == nil || IsNil(o.Node) { + return nil, false + } + return o.Node, true +} + +// HasNode returns a boolean if a field has been set. +func (o *ServerJob) HasNode() bool { + if o != nil && !IsNil(o.Node) { + return true + } + + return false +} + +// SetNode gets a reference to the given string and assigns it to the Node field. +func (o *ServerJob) SetNode(v string) { + o.Node = &v +} + +// GetPayload returns the Payload field value if set, zero value otherwise. +func (o *ServerJob) GetPayload() map[string]interface{} { + if o == nil || IsNil(o.Payload) { + var ret map[string]interface{} + return ret + } + return o.Payload +} + +// GetPayloadOk returns a tuple with the Payload field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ServerJob) GetPayloadOk() (map[string]interface{}, bool) { + if o == nil || IsNil(o.Payload) { + return map[string]interface{}{}, false + } + return o.Payload, true +} + +// HasPayload returns a boolean if a field has been set. +func (o *ServerJob) HasPayload() bool { + if o != nil && !IsNil(o.Payload) { + return true + } + + return false +} + +// SetPayload gets a reference to the given map[string]interface{} and assigns it to the Payload field. +func (o *ServerJob) SetPayload(v map[string]interface{}) { + o.Payload = v +} + +// GetProgress returns the Progress field value if set, zero value otherwise. +func (o *ServerJob) GetProgress() map[string]interface{} { + if o == nil || IsNil(o.Progress) { + var ret map[string]interface{} + return ret + } + return o.Progress +} + +// GetProgressOk returns a tuple with the Progress field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ServerJob) GetProgressOk() (map[string]interface{}, bool) { + if o == nil || IsNil(o.Progress) { + return map[string]interface{}{}, false + } + return o.Progress, true +} + +// HasProgress returns a boolean if a field has been set. +func (o *ServerJob) HasProgress() bool { + if o != nil && !IsNil(o.Progress) { + return true + } + + return false +} + +// SetProgress gets a reference to the given map[string]interface{} and assigns it to the Progress field. +func (o *ServerJob) SetProgress(v map[string]interface{}) { + o.Progress = v +} + +// GetServerId returns the ServerId field value if set, zero value otherwise. +func (o *ServerJob) GetServerId() string { + if o == nil || IsNil(o.ServerId) { + var ret string + return ret + } + return *o.ServerId +} + +// GetServerIdOk returns a tuple with the ServerId field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ServerJob) GetServerIdOk() (*string, bool) { + if o == nil || IsNil(o.ServerId) { + return nil, false + } + return o.ServerId, true +} + +// HasServerId returns a boolean if a field has been set. +func (o *ServerJob) HasServerId() bool { + if o != nil && !IsNil(o.ServerId) { + return true + } + + return false +} + +// SetServerId gets a reference to the given string and assigns it to the ServerId field. +func (o *ServerJob) SetServerId(v string) { + o.ServerId = &v +} + +// GetStatus returns the Status field value if set, zero value otherwise. +func (o *ServerJob) GetStatus() string { + if o == nil || IsNil(o.Status) { + var ret string + return ret + } + return *o.Status +} + +// GetStatusOk returns a tuple with the Status field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ServerJob) GetStatusOk() (*string, bool) { + if o == nil || IsNil(o.Status) { + return nil, false + } + return o.Status, true +} + +// HasStatus returns a boolean if a field has been set. +func (o *ServerJob) HasStatus() bool { + if o != nil && !IsNil(o.Status) { + return true + } + + return false +} + +// SetStatus gets a reference to the given string and assigns it to the Status field. +func (o *ServerJob) SetStatus(v string) { + o.Status = &v +} + +// GetTasks returns the Tasks field value if set, zero value otherwise. +func (o *ServerJob) GetTasks() []Task { + if o == nil || IsNil(o.Tasks) { + var ret []Task + return ret + } + return o.Tasks +} + +// GetTasksOk returns a tuple with the Tasks field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ServerJob) GetTasksOk() ([]Task, bool) { + if o == nil || IsNil(o.Tasks) { + return nil, false + } + return o.Tasks, true +} + +// HasTasks returns a boolean if a field has been set. +func (o *ServerJob) HasTasks() bool { + if o != nil && !IsNil(o.Tasks) { + return true + } + + return false +} + +// SetTasks gets a reference to the given []Task and assigns it to the Tasks field. +func (o *ServerJob) SetTasks(v []Task) { + o.Tasks = v +} + +// GetType returns the Type field value if set, zero value otherwise. +func (o *ServerJob) GetType() string { + if o == nil || IsNil(o.Type) { + var ret string + return ret + } + return *o.Type +} + +// GetTypeOk returns a tuple with the Type field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ServerJob) GetTypeOk() (*string, bool) { + if o == nil || IsNil(o.Type) { + return nil, false + } + return o.Type, true +} + +// HasType returns a boolean if a field has been set. +func (o *ServerJob) HasType() bool { + if o != nil && !IsNil(o.Type) { + return true + } + + return false +} + +// SetType gets a reference to the given string and assigns it to the Type field. +func (o *ServerJob) SetType(v string) { + o.Type = &v +} + +// GetUpdatedAt returns the UpdatedAt field value if set, zero value otherwise. +func (o *ServerJob) GetUpdatedAt() time.Time { + if o == nil || IsNil(o.UpdatedAt) { + var ret time.Time + return ret + } + return *o.UpdatedAt +} + +// GetUpdatedAtOk returns a tuple with the UpdatedAt field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ServerJob) GetUpdatedAtOk() (*time.Time, bool) { + if o == nil || IsNil(o.UpdatedAt) { + return nil, false + } + return o.UpdatedAt, true +} + +// HasUpdatedAt returns a boolean if a field has been set. +func (o *ServerJob) HasUpdatedAt() bool { + if o != nil && !IsNil(o.UpdatedAt) { + return true + } + + return false +} + +// SetUpdatedAt gets a reference to the given time.Time and assigns it to the UpdatedAt field. +func (o *ServerJob) SetUpdatedAt(v time.Time) { + o.UpdatedAt = &v +} + +// GetUuid returns the Uuid field value if set, zero value otherwise. +func (o *ServerJob) GetUuid() string { + if o == nil || IsNil(o.Uuid) { + var ret string + return ret + } + return *o.Uuid +} + +// GetUuidOk returns a tuple with the Uuid field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ServerJob) GetUuidOk() (*string, bool) { + if o == nil || IsNil(o.Uuid) { + return nil, false + } + return o.Uuid, true +} + +// HasUuid returns a boolean if a field has been set. +func (o *ServerJob) HasUuid() bool { + if o != nil && !IsNil(o.Uuid) { + return true + } + + return false +} + +// SetUuid gets a reference to the given string and assigns it to the Uuid field. +func (o *ServerJob) SetUuid(v string) { + o.Uuid = &v +} + +func (o ServerJob) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o ServerJob) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.BareMetalId) { + toSerialize["bareMetalId"] = o.BareMetalId + } + if !IsNil(o.CreatedAt) { + toSerialize["createdAt"] = o.CreatedAt + } + if !IsNil(o.Flow) { + toSerialize["flow"] = o.Flow + } + if !IsNil(o.IsRunning) { + toSerialize["isRunning"] = o.IsRunning + } + if !IsNil(o.Metadata) { + toSerialize["metadata"] = o.Metadata + } + if !IsNil(o.Node) { + toSerialize["node"] = o.Node + } + if !IsNil(o.Payload) { + toSerialize["payload"] = o.Payload + } + if !IsNil(o.Progress) { + toSerialize["progress"] = o.Progress + } + if !IsNil(o.ServerId) { + toSerialize["serverId"] = o.ServerId + } + if !IsNil(o.Status) { + toSerialize["status"] = o.Status + } + if !IsNil(o.Tasks) { + toSerialize["tasks"] = o.Tasks + } + if !IsNil(o.Type) { + toSerialize["type"] = o.Type + } + if !IsNil(o.UpdatedAt) { + toSerialize["updatedAt"] = o.UpdatedAt + } + if !IsNil(o.Uuid) { + toSerialize["uuid"] = o.Uuid + } + return toSerialize, nil +} + +type NullableServerJob struct { + value *ServerJob + isSet bool +} + +func (v NullableServerJob) Get() *ServerJob { + return v.value +} + +func (v *NullableServerJob) Set(val *ServerJob) { + v.value = val + v.isSet = true +} + +func (v NullableServerJob) IsSet() bool { + return v.isSet +} + +func (v *NullableServerJob) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableServerJob(val *ServerJob) *NullableServerJob { + return &NullableServerJob{value: val, isSet: true} +} + +func (v NullableServerJob) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableServerJob) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/bmp/model_server_job_list.go b/bmp/model_server_job_list.go new file mode 100644 index 0000000..21e89d6 --- /dev/null +++ b/bmp/model_server_job_list.go @@ -0,0 +1,164 @@ +/* +bmp + +This documents the rest api bmp api provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package bmp + +import ( + "encoding/json" +) + +// checks if the ServerJobList type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &ServerJobList{} + +// ServerJobList struct for ServerJobList +type ServerJobList struct { + Metadata *Metadata `json:"_metadata,omitempty"` + // An array of jobs + Jobs []ServerJob `json:"jobs,omitempty"` +} + +// NewServerJobList instantiates a new ServerJobList object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewServerJobList() *ServerJobList { + this := ServerJobList{} + return &this +} + +// NewServerJobListWithDefaults instantiates a new ServerJobList object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewServerJobListWithDefaults() *ServerJobList { + this := ServerJobList{} + return &this +} + +// GetMetadata returns the Metadata field value if set, zero value otherwise. +func (o *ServerJobList) GetMetadata() Metadata { + if o == nil || IsNil(o.Metadata) { + var ret Metadata + return ret + } + return *o.Metadata +} + +// GetMetadataOk returns a tuple with the Metadata field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ServerJobList) GetMetadataOk() (*Metadata, bool) { + if o == nil || IsNil(o.Metadata) { + return nil, false + } + return o.Metadata, true +} + +// HasMetadata returns a boolean if a field has been set. +func (o *ServerJobList) HasMetadata() bool { + if o != nil && !IsNil(o.Metadata) { + return true + } + + return false +} + +// SetMetadata gets a reference to the given Metadata and assigns it to the Metadata field. +func (o *ServerJobList) SetMetadata(v Metadata) { + o.Metadata = &v +} + +// GetJobs returns the Jobs field value if set, zero value otherwise. +func (o *ServerJobList) GetJobs() []ServerJob { + if o == nil || IsNil(o.Jobs) { + var ret []ServerJob + return ret + } + return o.Jobs +} + +// GetJobsOk returns a tuple with the Jobs field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ServerJobList) GetJobsOk() ([]ServerJob, bool) { + if o == nil || IsNil(o.Jobs) { + return nil, false + } + return o.Jobs, true +} + +// HasJobs returns a boolean if a field has been set. +func (o *ServerJobList) HasJobs() bool { + if o != nil && !IsNil(o.Jobs) { + return true + } + + return false +} + +// SetJobs gets a reference to the given []ServerJob and assigns it to the Jobs field. +func (o *ServerJobList) SetJobs(v []ServerJob) { + o.Jobs = v +} + +func (o ServerJobList) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o ServerJobList) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Metadata) { + toSerialize["_metadata"] = o.Metadata + } + if !IsNil(o.Jobs) { + toSerialize["jobs"] = o.Jobs + } + return toSerialize, nil +} + +type NullableServerJobList struct { + value *ServerJobList + isSet bool +} + +func (v NullableServerJobList) Get() *ServerJobList { + return v.value +} + +func (v *NullableServerJobList) Set(val *ServerJobList) { + v.value = val + v.isSet = true +} + +func (v NullableServerJobList) IsSet() bool { + return v.isSet +} + +func (v *NullableServerJobList) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableServerJobList(val *ServerJobList) *NullableServerJobList { + return &NullableServerJobList{value: val, isSet: true} +} + +func (v NullableServerJobList) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableServerJobList) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/bmp/model_task.go b/bmp/model_task.go new file mode 100644 index 0000000..f7a0ed1 --- /dev/null +++ b/bmp/model_task.go @@ -0,0 +1,360 @@ +/* +bmp + +This documents the rest api bmp api provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package bmp + +import ( + "encoding/json" +) + +// checks if the Task type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &Task{} + +// Task struct for Task +type Task struct { + // Description of the task + Description *string `json:"description,omitempty"` + // An optional error message + ErrorMessage NullableString `json:"errorMessage,omitempty"` + // The flow this task is part of + Flow *string `json:"flow,omitempty"` + // The behaviour if this task fails + OnError *string `json:"onError,omitempty"` + // The status of the task + Status *string `json:"status,omitempty"` + // Timestamp for each state change + StatusTimestamps map[string]interface{} `json:"statusTimestamps,omitempty"` + // Unique ID for this task + Uuid *string `json:"uuid,omitempty"` +} + +// NewTask instantiates a new Task object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewTask() *Task { + this := Task{} + return &this +} + +// NewTaskWithDefaults instantiates a new Task object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewTaskWithDefaults() *Task { + this := Task{} + return &this +} + +// GetDescription returns the Description field value if set, zero value otherwise. +func (o *Task) GetDescription() string { + if o == nil || IsNil(o.Description) { + var ret string + return ret + } + return *o.Description +} + +// GetDescriptionOk returns a tuple with the Description field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Task) GetDescriptionOk() (*string, bool) { + if o == nil || IsNil(o.Description) { + return nil, false + } + return o.Description, true +} + +// HasDescription returns a boolean if a field has been set. +func (o *Task) HasDescription() bool { + if o != nil && !IsNil(o.Description) { + return true + } + + return false +} + +// SetDescription gets a reference to the given string and assigns it to the Description field. +func (o *Task) SetDescription(v string) { + o.Description = &v +} + +// GetErrorMessage returns the ErrorMessage field value if set, zero value otherwise (both if not set or set to explicit null). +func (o *Task) GetErrorMessage() string { + if o == nil || IsNil(o.ErrorMessage.Get()) { + var ret string + return ret + } + return *o.ErrorMessage.Get() +} + +// GetErrorMessageOk returns a tuple with the ErrorMessage field value if set, nil otherwise +// and a boolean to check if the value has been set. +// NOTE: If the value is an explicit nil, `nil, true` will be returned +func (o *Task) GetErrorMessageOk() (*string, bool) { + if o == nil { + return nil, false + } + return o.ErrorMessage.Get(), o.ErrorMessage.IsSet() +} + +// HasErrorMessage returns a boolean if a field has been set. +func (o *Task) HasErrorMessage() bool { + if o != nil && o.ErrorMessage.IsSet() { + return true + } + + return false +} + +// SetErrorMessage gets a reference to the given NullableString and assigns it to the ErrorMessage field. +func (o *Task) SetErrorMessage(v string) { + o.ErrorMessage.Set(&v) +} +// SetErrorMessageNil sets the value for ErrorMessage to be an explicit nil +func (o *Task) SetErrorMessageNil() { + o.ErrorMessage.Set(nil) +} + +// UnsetErrorMessage ensures that no value is present for ErrorMessage, not even an explicit nil +func (o *Task) UnsetErrorMessage() { + o.ErrorMessage.Unset() +} + +// GetFlow returns the Flow field value if set, zero value otherwise. +func (o *Task) GetFlow() string { + if o == nil || IsNil(o.Flow) { + var ret string + return ret + } + return *o.Flow +} + +// GetFlowOk returns a tuple with the Flow field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Task) GetFlowOk() (*string, bool) { + if o == nil || IsNil(o.Flow) { + return nil, false + } + return o.Flow, true +} + +// HasFlow returns a boolean if a field has been set. +func (o *Task) HasFlow() bool { + if o != nil && !IsNil(o.Flow) { + return true + } + + return false +} + +// SetFlow gets a reference to the given string and assigns it to the Flow field. +func (o *Task) SetFlow(v string) { + o.Flow = &v +} + +// GetOnError returns the OnError field value if set, zero value otherwise. +func (o *Task) GetOnError() string { + if o == nil || IsNil(o.OnError) { + var ret string + return ret + } + return *o.OnError +} + +// GetOnErrorOk returns a tuple with the OnError field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Task) GetOnErrorOk() (*string, bool) { + if o == nil || IsNil(o.OnError) { + return nil, false + } + return o.OnError, true +} + +// HasOnError returns a boolean if a field has been set. +func (o *Task) HasOnError() bool { + if o != nil && !IsNil(o.OnError) { + return true + } + + return false +} + +// SetOnError gets a reference to the given string and assigns it to the OnError field. +func (o *Task) SetOnError(v string) { + o.OnError = &v +} + +// GetStatus returns the Status field value if set, zero value otherwise. +func (o *Task) GetStatus() string { + if o == nil || IsNil(o.Status) { + var ret string + return ret + } + return *o.Status +} + +// GetStatusOk returns a tuple with the Status field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Task) GetStatusOk() (*string, bool) { + if o == nil || IsNil(o.Status) { + return nil, false + } + return o.Status, true +} + +// HasStatus returns a boolean if a field has been set. +func (o *Task) HasStatus() bool { + if o != nil && !IsNil(o.Status) { + return true + } + + return false +} + +// SetStatus gets a reference to the given string and assigns it to the Status field. +func (o *Task) SetStatus(v string) { + o.Status = &v +} + +// GetStatusTimestamps returns the StatusTimestamps field value if set, zero value otherwise. +func (o *Task) GetStatusTimestamps() map[string]interface{} { + if o == nil || IsNil(o.StatusTimestamps) { + var ret map[string]interface{} + return ret + } + return o.StatusTimestamps +} + +// GetStatusTimestampsOk returns a tuple with the StatusTimestamps field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Task) GetStatusTimestampsOk() (map[string]interface{}, bool) { + if o == nil || IsNil(o.StatusTimestamps) { + return map[string]interface{}{}, false + } + return o.StatusTimestamps, true +} + +// HasStatusTimestamps returns a boolean if a field has been set. +func (o *Task) HasStatusTimestamps() bool { + if o != nil && !IsNil(o.StatusTimestamps) { + return true + } + + return false +} + +// SetStatusTimestamps gets a reference to the given map[string]interface{} and assigns it to the StatusTimestamps field. +func (o *Task) SetStatusTimestamps(v map[string]interface{}) { + o.StatusTimestamps = v +} + +// GetUuid returns the Uuid field value if set, zero value otherwise. +func (o *Task) GetUuid() string { + if o == nil || IsNil(o.Uuid) { + var ret string + return ret + } + return *o.Uuid +} + +// GetUuidOk returns a tuple with the Uuid field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Task) GetUuidOk() (*string, bool) { + if o == nil || IsNil(o.Uuid) { + return nil, false + } + return o.Uuid, true +} + +// HasUuid returns a boolean if a field has been set. +func (o *Task) HasUuid() bool { + if o != nil && !IsNil(o.Uuid) { + return true + } + + return false +} + +// SetUuid gets a reference to the given string and assigns it to the Uuid field. +func (o *Task) SetUuid(v string) { + o.Uuid = &v +} + +func (o Task) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o Task) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Description) { + toSerialize["description"] = o.Description + } + if o.ErrorMessage.IsSet() { + toSerialize["errorMessage"] = o.ErrorMessage.Get() + } + if !IsNil(o.Flow) { + toSerialize["flow"] = o.Flow + } + if !IsNil(o.OnError) { + toSerialize["onError"] = o.OnError + } + if !IsNil(o.Status) { + toSerialize["status"] = o.Status + } + if !IsNil(o.StatusTimestamps) { + toSerialize["statusTimestamps"] = o.StatusTimestamps + } + if !IsNil(o.Uuid) { + toSerialize["uuid"] = o.Uuid + } + return toSerialize, nil +} + +type NullableTask struct { + value *Task + isSet bool +} + +func (v NullableTask) Get() *Task { + return v.value +} + +func (v *NullableTask) Set(val *Task) { + v.value = val + v.isSet = true +} + +func (v NullableTask) IsSet() bool { + return v.isSet +} + +func (v *NullableTask) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableTask(val *Task) *NullableTask { + return &NullableTask{value: val, isSet: true} +} + +func (v NullableTask) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableTask) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/bmp/model_update_network_equipment_credential_opts.go b/bmp/model_update_network_equipment_credential_opts.go new file mode 100644 index 0000000..74bdf13 --- /dev/null +++ b/bmp/model_update_network_equipment_credential_opts.go @@ -0,0 +1,160 @@ +/* +bmp + +This documents the rest api bmp api provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package bmp + +import ( + "encoding/json" + "bytes" + "fmt" +) + +// checks if the UpdateNetworkEquipmentCredentialOpts type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &UpdateNetworkEquipmentCredentialOpts{} + +// UpdateNetworkEquipmentCredentialOpts struct for UpdateNetworkEquipmentCredentialOpts +type UpdateNetworkEquipmentCredentialOpts struct { + // The password for the credentials + Password string `json:"password"` +} + +type _UpdateNetworkEquipmentCredentialOpts UpdateNetworkEquipmentCredentialOpts + +// NewUpdateNetworkEquipmentCredentialOpts instantiates a new UpdateNetworkEquipmentCredentialOpts object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewUpdateNetworkEquipmentCredentialOpts(password string) *UpdateNetworkEquipmentCredentialOpts { + this := UpdateNetworkEquipmentCredentialOpts{} + this.Password = password + return &this +} + +// NewUpdateNetworkEquipmentCredentialOptsWithDefaults instantiates a new UpdateNetworkEquipmentCredentialOpts object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewUpdateNetworkEquipmentCredentialOptsWithDefaults() *UpdateNetworkEquipmentCredentialOpts { + this := UpdateNetworkEquipmentCredentialOpts{} + return &this +} + +// GetPassword returns the Password field value +func (o *UpdateNetworkEquipmentCredentialOpts) GetPassword() string { + if o == nil { + var ret string + return ret + } + + return o.Password +} + +// GetPasswordOk returns a tuple with the Password field value +// and a boolean to check if the value has been set. +func (o *UpdateNetworkEquipmentCredentialOpts) GetPasswordOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.Password, true +} + +// SetPassword sets field value +func (o *UpdateNetworkEquipmentCredentialOpts) SetPassword(v string) { + o.Password = v +} + +func (o UpdateNetworkEquipmentCredentialOpts) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o UpdateNetworkEquipmentCredentialOpts) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + toSerialize["password"] = o.Password + return toSerialize, nil +} + +func (o *UpdateNetworkEquipmentCredentialOpts) UnmarshalJSON(data []byte) (err error) { + // This validates that all required properties are included in the JSON object + // by unmarshalling the object into a generic map with string keys and checking + // that every required field exists as a key in the generic map. + requiredProperties := []string{ + "password", + } + + allProperties := make(map[string]interface{}) + + err = json.Unmarshal(data, &allProperties) + + if err != nil { + return err; + } + + for _, requiredProperty := range(requiredProperties) { + if _, exists := allProperties[requiredProperty]; !exists { + return fmt.Errorf("no value given for required property %v", requiredProperty) + } + } + + varUpdateNetworkEquipmentCredentialOpts := _UpdateNetworkEquipmentCredentialOpts{} + + decoder := json.NewDecoder(bytes.NewReader(data)) + decoder.DisallowUnknownFields() + err = decoder.Decode(&varUpdateNetworkEquipmentCredentialOpts) + + if err != nil { + return err + } + + *o = UpdateNetworkEquipmentCredentialOpts(varUpdateNetworkEquipmentCredentialOpts) + + return err +} + +type NullableUpdateNetworkEquipmentCredentialOpts struct { + value *UpdateNetworkEquipmentCredentialOpts + isSet bool +} + +func (v NullableUpdateNetworkEquipmentCredentialOpts) Get() *UpdateNetworkEquipmentCredentialOpts { + return v.value +} + +func (v *NullableUpdateNetworkEquipmentCredentialOpts) Set(val *UpdateNetworkEquipmentCredentialOpts) { + v.value = val + v.isSet = true +} + +func (v NullableUpdateNetworkEquipmentCredentialOpts) IsSet() bool { + return v.isSet +} + +func (v *NullableUpdateNetworkEquipmentCredentialOpts) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableUpdateNetworkEquipmentCredentialOpts(val *UpdateNetworkEquipmentCredentialOpts) *NullableUpdateNetworkEquipmentCredentialOpts { + return &NullableUpdateNetworkEquipmentCredentialOpts{value: val, isSet: true} +} + +func (v NullableUpdateNetworkEquipmentCredentialOpts) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableUpdateNetworkEquipmentCredentialOpts) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/bmp/model_update_server_credential_opts.go b/bmp/model_update_server_credential_opts.go new file mode 100644 index 0000000..8b65b88 --- /dev/null +++ b/bmp/model_update_server_credential_opts.go @@ -0,0 +1,160 @@ +/* +bmp + +This documents the rest api bmp api provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package bmp + +import ( + "encoding/json" + "bytes" + "fmt" +) + +// checks if the UpdateServerCredentialOpts type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &UpdateServerCredentialOpts{} + +// UpdateServerCredentialOpts struct for UpdateServerCredentialOpts +type UpdateServerCredentialOpts struct { + // The password for the credentials + Password string `json:"password"` +} + +type _UpdateServerCredentialOpts UpdateServerCredentialOpts + +// NewUpdateServerCredentialOpts instantiates a new UpdateServerCredentialOpts object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewUpdateServerCredentialOpts(password string) *UpdateServerCredentialOpts { + this := UpdateServerCredentialOpts{} + this.Password = password + return &this +} + +// NewUpdateServerCredentialOptsWithDefaults instantiates a new UpdateServerCredentialOpts object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewUpdateServerCredentialOptsWithDefaults() *UpdateServerCredentialOpts { + this := UpdateServerCredentialOpts{} + return &this +} + +// GetPassword returns the Password field value +func (o *UpdateServerCredentialOpts) GetPassword() string { + if o == nil { + var ret string + return ret + } + + return o.Password +} + +// GetPasswordOk returns a tuple with the Password field value +// and a boolean to check if the value has been set. +func (o *UpdateServerCredentialOpts) GetPasswordOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.Password, true +} + +// SetPassword sets field value +func (o *UpdateServerCredentialOpts) SetPassword(v string) { + o.Password = v +} + +func (o UpdateServerCredentialOpts) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o UpdateServerCredentialOpts) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + toSerialize["password"] = o.Password + return toSerialize, nil +} + +func (o *UpdateServerCredentialOpts) UnmarshalJSON(data []byte) (err error) { + // This validates that all required properties are included in the JSON object + // by unmarshalling the object into a generic map with string keys and checking + // that every required field exists as a key in the generic map. + requiredProperties := []string{ + "password", + } + + allProperties := make(map[string]interface{}) + + err = json.Unmarshal(data, &allProperties) + + if err != nil { + return err; + } + + for _, requiredProperty := range(requiredProperties) { + if _, exists := allProperties[requiredProperty]; !exists { + return fmt.Errorf("no value given for required property %v", requiredProperty) + } + } + + varUpdateServerCredentialOpts := _UpdateServerCredentialOpts{} + + decoder := json.NewDecoder(bytes.NewReader(data)) + decoder.DisallowUnknownFields() + err = decoder.Decode(&varUpdateServerCredentialOpts) + + if err != nil { + return err + } + + *o = UpdateServerCredentialOpts(varUpdateServerCredentialOpts) + + return err +} + +type NullableUpdateServerCredentialOpts struct { + value *UpdateServerCredentialOpts + isSet bool +} + +func (v NullableUpdateServerCredentialOpts) Get() *UpdateServerCredentialOpts { + return v.value +} + +func (v *NullableUpdateServerCredentialOpts) Set(val *UpdateServerCredentialOpts) { + v.value = val + v.isSet = true +} + +func (v NullableUpdateServerCredentialOpts) IsSet() bool { + return v.isSet +} + +func (v *NullableUpdateServerCredentialOpts) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableUpdateServerCredentialOpts(val *UpdateServerCredentialOpts) *NullableUpdateServerCredentialOpts { + return &NullableUpdateServerCredentialOpts{value: val, isSet: true} +} + +func (v NullableUpdateServerCredentialOpts) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableUpdateServerCredentialOpts) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/bmp/response.go b/bmp/response.go new file mode 100644 index 0000000..c14e74e --- /dev/null +++ b/bmp/response.go @@ -0,0 +1,48 @@ +/* +bmp + +This documents the rest api bmp api provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package bmp + +import ( + "net/http" +) + +// APIResponse stores the API response returned by the server. +type APIResponse struct { + *http.Response `json:"-"` + Message string `json:"message,omitempty"` + // Operation is the name of the OpenAPI operation. + Operation string `json:"operation,omitempty"` + // RequestURL is the request URL. This value is always available, even if the + // embedded *http.Response is nil. + RequestURL string `json:"url,omitempty"` + // Method is the HTTP method used for the request. This value is always + // available, even if the embedded *http.Response is nil. + Method string `json:"method,omitempty"` + // Payload holds the contents of the response body (which may be nil or empty). + // This is provided here as the raw response.Body() reader will have already + // been drained. + Payload []byte `json:"-"` +} + +// NewAPIResponse returns a new APIResponse object. +func NewAPIResponse(r *http.Response) *APIResponse { + + response := &APIResponse{Response: r} + return response +} + +// NewAPIResponseWithError returns a new APIResponse object with the provided error message. +func NewAPIResponseWithError(errorMessage string) *APIResponse { + + response := &APIResponse{Message: errorMessage} + return response +} diff --git a/bmp/test/api_bmp_test.go b/bmp/test/api_bmp_test.go new file mode 100644 index 0000000..68cf7f1 --- /dev/null +++ b/bmp/test/api_bmp_test.go @@ -0,0 +1,557 @@ +/* +bmp + +Testing BmpAPIService + +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); + +package bmp + +import ( + "context" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "testing" + openapiclient "github.com/leaseweb/leaseweb-go-sdk/bmp" +) + +func Test_bmp_BmpAPIService(t *testing.T) { + + configuration := openapiclient.NewConfiguration() + apiClient := openapiclient.NewAPIClient(configuration) + + t.Run("Test BmpAPIService AddServerCredential", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var serverId string + + resp, httpRes, err := apiClient.BmpAPI.AddServerCredential(context.Background(), serverId).Execute() + + require.Nil(t, err) + require.NotNil(t, resp) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test BmpAPIService CancelActiveJob", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var serverId string + + resp, httpRes, err := apiClient.BmpAPI.CancelActiveJob(context.Background(), serverId).Execute() + + require.Nil(t, err) + require.NotNil(t, resp) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test BmpAPIService ConfigureHardwareRaid", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var serverId string + + resp, httpRes, err := apiClient.BmpAPI.ConfigureHardwareRaid(context.Background(), serverId).Execute() + + require.Nil(t, err) + require.NotNil(t, resp) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test BmpAPIService CreateServerDhcpReservation", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var serverId string + + httpRes, err := apiClient.BmpAPI.CreateServerDhcpReservation(context.Background(), serverId).Execute() + + require.Nil(t, err) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test BmpAPIService DeleteNetworkEquipmentCredential", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var networkEquipmentId string + var type_ string + var username string + + httpRes, err := apiClient.BmpAPI.DeleteNetworkEquipmentCredential(context.Background(), networkEquipmentId, type_, username).Execute() + + require.Nil(t, err) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test BmpAPIService DeleteServerCredential", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var serverId string + var type_ string + var username string + + httpRes, err := apiClient.BmpAPI.DeleteServerCredential(context.Background(), serverId, type_, username).Execute() + + require.Nil(t, err) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test BmpAPIService EnableServerRescueMode", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var serverId string + + resp, httpRes, err := apiClient.BmpAPI.EnableServerRescueMode(context.Background(), serverId).Execute() + + require.Nil(t, err) + require.NotNil(t, resp) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test BmpAPIService ExpireActiveJob", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var serverId string + + resp, httpRes, err := apiClient.BmpAPI.ExpireActiveJob(context.Background(), serverId).Execute() + + require.Nil(t, err) + require.NotNil(t, resp) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test BmpAPIService GetControlPanelList", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + resp, httpRes, err := apiClient.BmpAPI.GetControlPanelList(context.Background()).Execute() + + require.Nil(t, err) + require.NotNil(t, resp) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test BmpAPIService GetControlPanelListByOperatingSystem", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var operatingSystemId string + + resp, httpRes, err := apiClient.BmpAPI.GetControlPanelListByOperatingSystem(context.Background(), operatingSystemId).Execute() + + require.Nil(t, err) + require.NotNil(t, resp) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test BmpAPIService GetNetworkEquipmentCredentialListByType", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var networkEquipmentId string + var type_ string + + resp, httpRes, err := apiClient.BmpAPI.GetNetworkEquipmentCredentialListByType(context.Background(), networkEquipmentId, type_).Execute() + + require.Nil(t, err) + require.NotNil(t, resp) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test BmpAPIService GetNetworkEquipmentPowerStatus", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var networkEquipmentId string + + resp, httpRes, err := apiClient.BmpAPI.GetNetworkEquipmentPowerStatus(context.Background(), networkEquipmentId).Execute() + + require.Nil(t, err) + require.NotNil(t, resp) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test BmpAPIService GetOperatingSystem", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var operatingSystemId string + + resp, httpRes, err := apiClient.BmpAPI.GetOperatingSystem(context.Background(), operatingSystemId).Execute() + + require.Nil(t, err) + require.NotNil(t, resp) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test BmpAPIService GetOperatingSystemList", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + resp, httpRes, err := apiClient.BmpAPI.GetOperatingSystemList(context.Background()).Execute() + + require.Nil(t, err) + require.NotNil(t, resp) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test BmpAPIService GetRescueImageList", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + resp, httpRes, err := apiClient.BmpAPI.GetRescueImageList(context.Background()).Execute() + + require.Nil(t, err) + require.NotNil(t, resp) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test BmpAPIService GetServerCredentialList", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var serverId string + + resp, httpRes, err := apiClient.BmpAPI.GetServerCredentialList(context.Background(), serverId).Execute() + + require.Nil(t, err) + require.NotNil(t, resp) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test BmpAPIService GetServerDhcpReservationList", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var serverId string + + resp, httpRes, err := apiClient.BmpAPI.GetServerDhcpReservationList(context.Background(), serverId).Execute() + + require.Nil(t, err) + require.NotNil(t, resp) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test BmpAPIService GetServerJobList", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var serverId string + + resp, httpRes, err := apiClient.BmpAPI.GetServerJobList(context.Background(), serverId).Execute() + + require.Nil(t, err) + require.NotNil(t, resp) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test BmpAPIService GetServerPowerStatus", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var serverId string + + resp, httpRes, err := apiClient.BmpAPI.GetServerPowerStatus(context.Background(), serverId).Execute() + + require.Nil(t, err) + require.NotNil(t, resp) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test BmpAPIService InstallOperatingSystem", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var serverId string + + resp, httpRes, err := apiClient.BmpAPI.InstallOperatingSystem(context.Background(), serverId).Execute() + + require.Nil(t, err) + require.NotNil(t, resp) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test BmpAPIService IpmiResetServer", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var serverId string + + resp, httpRes, err := apiClient.BmpAPI.IpmiResetServer(context.Background(), serverId).Execute() + + require.Nil(t, err) + require.NotNil(t, resp) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test BmpAPIService NetworkEquipmentsCredentialsGet", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var networkEquipmentId string + var type_ string + var username string + + resp, httpRes, err := apiClient.BmpAPI.NetworkEquipmentsCredentialsGet(context.Background(), networkEquipmentId, type_, username).Execute() + + require.Nil(t, err) + require.NotNil(t, resp) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test BmpAPIService NetworkEquipmentsCredentialsList", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var networkEquipmentId string + + resp, httpRes, err := apiClient.BmpAPI.NetworkEquipmentsCredentialsList(context.Background(), networkEquipmentId).Execute() + + require.Nil(t, err) + require.NotNil(t, resp) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test BmpAPIService NetworkEquipmentsCredentialsPost", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var networkEquipmentId string + + resp, httpRes, err := apiClient.BmpAPI.NetworkEquipmentsCredentialsPost(context.Background(), networkEquipmentId).Execute() + + require.Nil(t, err) + require.NotNil(t, resp) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test BmpAPIService PowerCycleNetworkEquipment", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var networkEquipmentId string + + httpRes, err := apiClient.BmpAPI.PowerCycleNetworkEquipment(context.Background(), networkEquipmentId).Execute() + + require.Nil(t, err) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test BmpAPIService PowerCycleServer", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var serverId string + + httpRes, err := apiClient.BmpAPI.PowerCycleServer(context.Background(), serverId).Execute() + + require.Nil(t, err) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test BmpAPIService PowerNetworkEquipmentOff", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var networkEquipmentId string + + httpRes, err := apiClient.BmpAPI.PowerNetworkEquipmentOff(context.Background(), networkEquipmentId).Execute() + + require.Nil(t, err) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test BmpAPIService PowerNetworkEquipmentOn", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var networkEquipmentId string + + httpRes, err := apiClient.BmpAPI.PowerNetworkEquipmentOn(context.Background(), networkEquipmentId).Execute() + + require.Nil(t, err) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test BmpAPIService PowerServerOff", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var serverId string + + httpRes, err := apiClient.BmpAPI.PowerServerOff(context.Background(), serverId).Execute() + + require.Nil(t, err) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test BmpAPIService PowerServerOn", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var serverId string + + httpRes, err := apiClient.BmpAPI.PowerServerOn(context.Background(), serverId).Execute() + + require.Nil(t, err) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test BmpAPIService RetryServerJob", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var serverId string + var jobId string + + resp, httpRes, err := apiClient.BmpAPI.RetryServerJob(context.Background(), serverId, jobId).Execute() + + require.Nil(t, err) + require.NotNil(t, resp) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test BmpAPIService ScanHardware", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var serverId string + + resp, httpRes, err := apiClient.BmpAPI.ScanHardware(context.Background(), serverId).Execute() + + require.Nil(t, err) + require.NotNil(t, resp) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test BmpAPIService ServersCredentialsGet", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var serverId string + var type_ string + var username string + + resp, httpRes, err := apiClient.BmpAPI.ServersCredentialsGet(context.Background(), serverId, type_, username).Execute() + + require.Nil(t, err) + require.NotNil(t, resp) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test BmpAPIService ServersCredentialsListType", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var serverId string + var type_ string + + resp, httpRes, err := apiClient.BmpAPI.ServersCredentialsListType(context.Background(), serverId, type_).Execute() + + require.Nil(t, err) + require.NotNil(t, resp) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test BmpAPIService ServersCredentialsPut", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var serverId string + var type_ string + var username string + + resp, httpRes, err := apiClient.BmpAPI.ServersCredentialsPut(context.Background(), serverId, type_, username).Execute() + + require.Nil(t, err) + require.NotNil(t, resp) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test BmpAPIService ServersJobsGet", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var serverId string + var jobId string + + resp, httpRes, err := apiClient.BmpAPI.ServersJobsGet(context.Background(), serverId, jobId).Execute() + + require.Nil(t, err) + require.NotNil(t, resp) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test BmpAPIService ServersLeasesDelete", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var serverId string + + httpRes, err := apiClient.BmpAPI.ServersLeasesDelete(context.Background(), serverId).Execute() + + require.Nil(t, err) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test BmpAPIService UpdateNetworkEquipmentCredential", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var networkEquipmentId string + var type_ string + var username string + + resp, httpRes, err := apiClient.BmpAPI.UpdateNetworkEquipmentCredential(context.Background(), networkEquipmentId, type_, username).Execute() + + require.Nil(t, err) + require.NotNil(t, resp) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + +} diff --git a/bmp/utils.go b/bmp/utils.go new file mode 100644 index 0000000..fbfaac5 --- /dev/null +++ b/bmp/utils.go @@ -0,0 +1,348 @@ +/* +bmp + +This documents the rest api bmp api provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package bmp + +import ( + "encoding/json" + "reflect" + "time" +) + +// PtrBool is a helper routine that returns a pointer to given boolean value. +func PtrBool(v bool) *bool { return &v } + +// PtrInt is a helper routine that returns a pointer to given integer value. +func PtrInt(v int) *int { return &v } + +// PtrInt32 is a helper routine that returns a pointer to given integer value. +func PtrInt32(v int32) *int32 { return &v } + +// PtrInt64 is a helper routine that returns a pointer to given integer value. +func PtrInt64(v int64) *int64 { return &v } + +// PtrFloat32 is a helper routine that returns a pointer to given float value. +func PtrFloat32(v float32) *float32 { return &v } + +// PtrFloat64 is a helper routine that returns a pointer to given float value. +func PtrFloat64(v float64) *float64 { return &v } + +// PtrString is a helper routine that returns a pointer to given string value. +func PtrString(v string) *string { return &v } + +// PtrTime is helper routine that returns a pointer to given Time value. +func PtrTime(v time.Time) *time.Time { return &v } + +type NullableBool struct { + value *bool + isSet bool +} + +func (v NullableBool) Get() *bool { + return v.value +} + +func (v *NullableBool) Set(val *bool) { + v.value = val + v.isSet = true +} + +func (v NullableBool) IsSet() bool { + return v.isSet +} + +func (v *NullableBool) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableBool(val *bool) *NullableBool { + return &NullableBool{value: val, isSet: true} +} + +func (v NullableBool) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableBool) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + +type NullableInt struct { + value *int + isSet bool +} + +func (v NullableInt) Get() *int { + return v.value +} + +func (v *NullableInt) Set(val *int) { + v.value = val + v.isSet = true +} + +func (v NullableInt) IsSet() bool { + return v.isSet +} + +func (v *NullableInt) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableInt(val *int) *NullableInt { + return &NullableInt{value: val, isSet: true} +} + +func (v NullableInt) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableInt) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + +type NullableInt32 struct { + value *int32 + isSet bool +} + +func (v NullableInt32) Get() *int32 { + return v.value +} + +func (v *NullableInt32) Set(val *int32) { + v.value = val + v.isSet = true +} + +func (v NullableInt32) IsSet() bool { + return v.isSet +} + +func (v *NullableInt32) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableInt32(val *int32) *NullableInt32 { + return &NullableInt32{value: val, isSet: true} +} + +func (v NullableInt32) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableInt32) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + +type NullableInt64 struct { + value *int64 + isSet bool +} + +func (v NullableInt64) Get() *int64 { + return v.value +} + +func (v *NullableInt64) Set(val *int64) { + v.value = val + v.isSet = true +} + +func (v NullableInt64) IsSet() bool { + return v.isSet +} + +func (v *NullableInt64) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableInt64(val *int64) *NullableInt64 { + return &NullableInt64{value: val, isSet: true} +} + +func (v NullableInt64) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableInt64) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + +type NullableFloat32 struct { + value *float32 + isSet bool +} + +func (v NullableFloat32) Get() *float32 { + return v.value +} + +func (v *NullableFloat32) Set(val *float32) { + v.value = val + v.isSet = true +} + +func (v NullableFloat32) IsSet() bool { + return v.isSet +} + +func (v *NullableFloat32) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableFloat32(val *float32) *NullableFloat32 { + return &NullableFloat32{value: val, isSet: true} +} + +func (v NullableFloat32) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableFloat32) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + +type NullableFloat64 struct { + value *float64 + isSet bool +} + +func (v NullableFloat64) Get() *float64 { + return v.value +} + +func (v *NullableFloat64) Set(val *float64) { + v.value = val + v.isSet = true +} + +func (v NullableFloat64) IsSet() bool { + return v.isSet +} + +func (v *NullableFloat64) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableFloat64(val *float64) *NullableFloat64 { + return &NullableFloat64{value: val, isSet: true} +} + +func (v NullableFloat64) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableFloat64) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + +type NullableString struct { + value *string + isSet bool +} + +func (v NullableString) Get() *string { + return v.value +} + +func (v *NullableString) Set(val *string) { + v.value = val + v.isSet = true +} + +func (v NullableString) IsSet() bool { + return v.isSet +} + +func (v *NullableString) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableString(val *string) *NullableString { + return &NullableString{value: val, isSet: true} +} + +func (v NullableString) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableString) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + +type NullableTime struct { + value *time.Time + isSet bool +} + +func (v NullableTime) Get() *time.Time { + return v.value +} + +func (v *NullableTime) Set(val *time.Time) { + v.value = val + v.isSet = true +} + +func (v NullableTime) IsSet() bool { + return v.isSet +} + +func (v *NullableTime) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableTime(val *time.Time) *NullableTime { + return &NullableTime{value: val, isSet: true} +} + +func (v NullableTime) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableTime) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + +// IsNil checks if an input is nil +func IsNil(i interface{}) bool { + if i == nil { + return true + } + switch reflect.TypeOf(i).Kind() { + case reflect.Chan, reflect.Func, reflect.Map, reflect.Ptr, reflect.UnsafePointer, reflect.Interface, reflect.Slice: + return reflect.ValueOf(i).IsNil() + case reflect.Array: + return reflect.ValueOf(i).IsZero() + } + return false +} + +type MappedNullable interface { + ToMap() (map[string]interface{}, error) +} diff --git a/bmsdb/README.md b/bmsdb/README.md new file mode 100644 index 0000000..02697fd --- /dev/null +++ b/bmsdb/README.md @@ -0,0 +1,181 @@ +# Go API client for bmsdb + +This documents the rest api bmsdb provides. + +## Overview +This API client was generated by the [OpenAPI Generator](https://openapi-generator.tech) project. By using the [OpenAPI-spec](https://www.openapis.org/) from a remote server, you can easily generate an API client. + +- API version: v2 +- Package version: 1.0.0 +- Generator version: 7.4.0 +- Build package: org.openapitools.codegen.languages.GoClientCodegen + +## Installation + +Install the following dependencies: + +```sh +go get github.com/stretchr/testify/assert +go get golang.org/x/oauth2 +go get golang.org/x/net/context +``` + +Put the package under your project folder and add the following in import: + +```go +import bmsdb "github.com/leaseweb/leaseweb-go-sdk/bmsdb" +``` + +To use a proxy, set the environment variable `HTTP_PROXY`: + +```go +os.Setenv("HTTP_PROXY", "http://proxy_name:proxy_port") +``` + +## Configuration of Server URL + +Default configuration comes with `Servers` field that contains server objects as defined in the OpenAPI specification. + +### Select Server Configuration + +For using other server than the one defined on index 0 set context value `bmsdb.ContextServerIndex` of type `int`. + +```go +ctx := context.WithValue(context.Background(), bmsdb.ContextServerIndex, 1) +``` + +### Templated Server URL + +Templated server URL is formatted using default variables from configuration or from context value `bmsdb.ContextServerVariables` of type `map[string]string`. + +```go +ctx := context.WithValue(context.Background(), bmsdb.ContextServerVariables, map[string]string{ + "basePath": "v2", +}) +``` + +Note, enum values are always validated and all unused variables are silently ignored. + +### URLs Configuration per Operation + +Each operation can use different server URL defined using `OperationServers` map in the `Configuration`. +An operation is uniquely identified by `"{classname}Service.{nickname}"` string. +Similar rules for overriding default operation server index and variables applies by using `bmsdb.ContextOperationServerIndices` and `bmsdb.ContextOperationServerVariables` context maps. + +```go +ctx := context.WithValue(context.Background(), bmsdb.ContextOperationServerIndices, map[string]int{ + "{classname}Service.{nickname}": 2, +}) +ctx = context.WithValue(context.Background(), bmsdb.ContextOperationServerVariables, map[string]map[string]string{ + "{classname}Service.{nickname}": { + "port": "8443", + }, +}) +``` + +## Documentation for API Endpoints + +All URIs are relative to *https://api.leaseweb.com/internal/bmsdb/v2* + +Class | Method | HTTP request | Description +------------ | ------------- | ------------- | ------------- +*BmsdbAPI* | [**GetServerHardware**](docs/BmsdbAPI.md#getserverhardware) | **Get** /servers/{serverId}/hardwareInfo | Show hardware information +*BmsdbAPI* | [**GetServerHardwareScan**](docs/BmsdbAPI.md#getserverhardwarescan) | **Get** /servers/{serverId}/hardwareScans/{hardwareScanId} | Show a hardware scan +*BmsdbAPI* | [**ServersHardwarescansList**](docs/BmsdbAPI.md#servershardwarescanslist) | **Get** /servers/{serverId}/hardwareScans | List hardware scans + + +## Documentation For Models + + - [ErrorResult](docs/ErrorResult.md) + - [GetServerHardwareResult](docs/GetServerHardwareResult.md) + - [GetServerHardwareScanListResult](docs/GetServerHardwareScanListResult.md) + - [GetServerHardwareScanResult](docs/GetServerHardwareScanResult.md) + - [HardwareScan](docs/HardwareScan.md) + - [Metadata](docs/Metadata.md) + - [Results](docs/Results.md) + + +## Documentation For Authorization + + +Authentication schemes defined for the API: +### ApiKeyAuth + +- **Type**: API key +- **API key parameter name**: X-LSW-Auth +- **Location**: HTTP header + +Note, each API key must be added to a map of `map[string]APIKey` where the key is: X-LSW-Auth and passed in as the auth context for each request. + +Example + +```go +auth := context.WithValue( + context.Background(), + bmsdb.ContextAPIKeys, + map[string]bmsdb.APIKey{ + "X-LSW-Auth": {Key: "API_KEY_STRING"}, + }, + ) +r, err := client.Service.Operation(auth, args) +``` + +### OAuth2 + + +- **Type**: OAuth +- **Flow**: application +- **Authorization URL**: +- **Scopes**: N/A + +Example + +```go +auth := context.WithValue(context.Background(), bmsdb.ContextAccessToken, "ACCESSTOKENSTRING") +r, err := client.Service.Operation(auth, args) +``` + +Or via OAuth2 module to automatically refresh tokens and perform user authentication. + +```go +import "golang.org/x/oauth2" + +/* Perform OAuth2 round trip request and obtain a token */ + +tokenSource := oauth2cfg.TokenSource(createContext(httpClient), &token) +auth := context.WithValue(oauth2.NoContext, bmsdb.ContextOAuth2, tokenSource) +r, err := client.Service.Operation(auth, args) +``` + +### BearerAuth + +- **Type**: HTTP Bearer token authentication + +Example + +```go +auth := context.WithValue(context.Background(), bmsdb.ContextAccessToken, "BEARER_TOKEN_STRING") +r, err := client.Service.Operation(auth, args) +``` + + +## Documentation for Utility Methods + +Due to the fact that model structure members are all pointers, this package contains +a number of utility functions to easily obtain pointers to values of basic types. +Each of these functions takes a value of the given basic type and returns a pointer to it: + +* `PtrBool` +* `PtrInt` +* `PtrInt32` +* `PtrInt64` +* `PtrFloat` +* `PtrFloat32` +* `PtrFloat64` +* `PtrString` +* `PtrTime` + +## Author + +development-networkautomation@leaseweb.com + diff --git a/bmsdb/api_bmsdb.go b/bmsdb/api_bmsdb.go new file mode 100644 index 0000000..93858fa --- /dev/null +++ b/bmsdb/api_bmsdb.go @@ -0,0 +1,579 @@ +/* +bmsdb + +This documents the rest api bmsdb provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package bmsdb + +import ( + "bytes" + "context" + "io" + "net/http" + "net/url" + "strings" +) + + +// BmsdbAPIService BmsdbAPI service +type BmsdbAPIService service + +type ApiGetServerHardwareRequest struct { + ctx context.Context + ApiService *BmsdbAPIService + serverId string +} + +func (r ApiGetServerHardwareRequest) Execute() (*GetServerHardwareResult, *http.Response, error) { + return r.ApiService.GetServerHardwareExecute(r) +} + +/* +GetServerHardware Show hardware information + +This information is generated when running a hardware scan for your server. A +hardware scan collects hardware information about your system. + + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param serverId The ID of a server + @return ApiGetServerHardwareRequest +*/ +func (a *BmsdbAPIService) GetServerHardware(ctx context.Context, serverId string) ApiGetServerHardwareRequest { + return ApiGetServerHardwareRequest{ + ApiService: a, + ctx: ctx, + serverId: serverId, + } +} + +// Execute executes the request +// @return GetServerHardwareResult +func (a *BmsdbAPIService) GetServerHardwareExecute(r ApiGetServerHardwareRequest) (*GetServerHardwareResult, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodGet + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *GetServerHardwareResult + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "BmsdbAPIService.GetServerHardware") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/servers/{serverId}/hardwareInfo" + localVarPath = strings.Replace(localVarPath, "{"+"serverId"+"}", url.PathEscape(parameterValueToString(r.serverId, "serverId")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiGetServerHardwareScanRequest struct { + ctx context.Context + ApiService *BmsdbAPIService + serverId string + hardwareScanId string + format *string +} + +// Defines the format of the response +func (r ApiGetServerHardwareScanRequest) Format(format string) ApiGetServerHardwareScanRequest { + r.format = &format + return r +} + +func (r ApiGetServerHardwareScanRequest) Execute() (*GetServerHardwareScanResult, *http.Response, error) { + return r.ApiService.GetServerHardwareScanExecute(r) +} + +/* +GetServerHardwareScan Show a hardware scan + +Returns detailed information of a hardware scan. + + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param serverId The ID of a server + @param hardwareScanId The ID that identifies a hardware scan + @return ApiGetServerHardwareScanRequest +*/ +func (a *BmsdbAPIService) GetServerHardwareScan(ctx context.Context, serverId string, hardwareScanId string) ApiGetServerHardwareScanRequest { + return ApiGetServerHardwareScanRequest{ + ApiService: a, + ctx: ctx, + serverId: serverId, + hardwareScanId: hardwareScanId, + } +} + +// Execute executes the request +// @return GetServerHardwareScanResult +func (a *BmsdbAPIService) GetServerHardwareScanExecute(r ApiGetServerHardwareScanRequest) (*GetServerHardwareScanResult, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodGet + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *GetServerHardwareScanResult + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "BmsdbAPIService.GetServerHardwareScan") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/servers/{serverId}/hardwareScans/{hardwareScanId}" + localVarPath = strings.Replace(localVarPath, "{"+"serverId"+"}", url.PathEscape(parameterValueToString(r.serverId, "serverId")), -1) + localVarPath = strings.Replace(localVarPath, "{"+"hardwareScanId"+"}", url.PathEscape(parameterValueToString(r.hardwareScanId, "hardwareScanId")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + if r.format != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "format", r.format, "") + } else { + var defaultValue string = "json" + r.format = &defaultValue + } + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiServersHardwarescansListRequest struct { + ctx context.Context + ApiService *BmsdbAPIService + serverId string + limit *int32 + offset *int32 +} + +// Limit the number of results returned. +func (r ApiServersHardwarescansListRequest) Limit(limit int32) ApiServersHardwarescansListRequest { + r.limit = &limit + return r +} + +// Return results starting from the given offset. +func (r ApiServersHardwarescansListRequest) Offset(offset int32) ApiServersHardwarescansListRequest { + r.offset = &offset + return r +} + +func (r ApiServersHardwarescansListRequest) Execute() (*GetServerHardwareScanListResult, *http.Response, error) { + return r.ApiService.ServersHardwarescansListExecute(r) +} + +/* +ServersHardwarescansList List hardware scans + +List all hardware scans for this server. + + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param serverId The ID of a server + @return ApiServersHardwarescansListRequest +*/ +func (a *BmsdbAPIService) ServersHardwarescansList(ctx context.Context, serverId string) ApiServersHardwarescansListRequest { + return ApiServersHardwarescansListRequest{ + ApiService: a, + ctx: ctx, + serverId: serverId, + } +} + +// Execute executes the request +// @return GetServerHardwareScanListResult +func (a *BmsdbAPIService) ServersHardwarescansListExecute(r ApiServersHardwarescansListRequest) (*GetServerHardwareScanListResult, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodGet + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *GetServerHardwareScanListResult + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "BmsdbAPIService.ServersHardwarescansList") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/servers/{serverId}/hardwareScans" + localVarPath = strings.Replace(localVarPath, "{"+"serverId"+"}", url.PathEscape(parameterValueToString(r.serverId, "serverId")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + if r.limit != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "limit", r.limit, "") + } + if r.offset != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "offset", r.offset, "") + } + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} diff --git a/bmsdb/client.go b/bmsdb/client.go new file mode 100644 index 0000000..d0ec21b --- /dev/null +++ b/bmsdb/client.go @@ -0,0 +1,678 @@ +/* +bmsdb + +This documents the rest api bmsdb provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package bmsdb + +import ( + "bytes" + "context" + "encoding/json" + "encoding/xml" + "errors" + "fmt" + "io" + "log" + "mime/multipart" + "net/http" + "net/http/httputil" + "net/url" + "os" + "path/filepath" + "reflect" + "regexp" + "strconv" + "strings" + "time" + "unicode/utf8" + + "golang.org/x/oauth2" +) + +var ( + JsonCheck = regexp.MustCompile(`(?i:(?:application|text)/(?:[^;]+\+)?json)`) + XmlCheck = regexp.MustCompile(`(?i:(?:application|text)/(?:[^;]+\+)?xml)`) + queryParamSplit = regexp.MustCompile(`(^|&)([^&]+)`) + queryDescape = strings.NewReplacer( "%5B", "[", "%5D", "]" ) +) + +// APIClient manages communication with the bmsdb API vv2 +// In most cases there should be only one, shared, APIClient. +type APIClient struct { + cfg *Configuration + common service // Reuse a single struct instead of allocating one for each service on the heap. + + // API Services + + BmsdbAPI *BmsdbAPIService +} + +type service struct { + client *APIClient +} + +// NewAPIClient creates a new API client. Requires a userAgent string describing your application. +// optionally a custom http.Client to allow for advanced features such as caching. +func NewAPIClient(cfg *Configuration) *APIClient { + if cfg.HTTPClient == nil { + cfg.HTTPClient = http.DefaultClient + } + + c := &APIClient{} + c.cfg = cfg + c.common.client = c + + // API Services + c.BmsdbAPI = (*BmsdbAPIService)(&c.common) + + return c +} + +func atoi(in string) (int, error) { + return strconv.Atoi(in) +} + +// selectHeaderContentType select a content type from the available list. +func selectHeaderContentType(contentTypes []string) string { + if len(contentTypes) == 0 { + return "" + } + if contains(contentTypes, "application/json") { + return "application/json" + } + return contentTypes[0] // use the first content type specified in 'consumes' +} + +// selectHeaderAccept join all accept types and return +func selectHeaderAccept(accepts []string) string { + if len(accepts) == 0 { + return "" + } + + if contains(accepts, "application/json") { + return "application/json" + } + + return strings.Join(accepts, ",") +} + +// contains is a case insensitive match, finding needle in a haystack +func contains(haystack []string, needle string) bool { + for _, a := range haystack { + if strings.EqualFold(a, needle) { + return true + } + } + return false +} + +// Verify optional parameters are of the correct type. +func typeCheckParameter(obj interface{}, expected string, name string) error { + // Make sure there is an object. + if obj == nil { + return nil + } + + // Check the type is as expected. + if reflect.TypeOf(obj).String() != expected { + return fmt.Errorf("expected %s to be of type %s but received %s", name, expected, reflect.TypeOf(obj).String()) + } + return nil +} + +func parameterValueToString( obj interface{}, key string ) string { + if reflect.TypeOf(obj).Kind() != reflect.Ptr { + return fmt.Sprintf("%v", obj) + } + var param,ok = obj.(MappedNullable) + if !ok { + return "" + } + dataMap,err := param.ToMap() + if err != nil { + return "" + } + return fmt.Sprintf("%v", dataMap[key]) +} + +// parameterAddToHeaderOrQuery adds the provided object to the request header or url query +// supporting deep object syntax +func parameterAddToHeaderOrQuery(headerOrQueryParams interface{}, keyPrefix string, obj interface{}, collectionType string) { + var v = reflect.ValueOf(obj) + var value = "" + if v == reflect.ValueOf(nil) { + value = "null" + } else { + switch v.Kind() { + case reflect.Invalid: + value = "invalid" + + case reflect.Struct: + if t,ok := obj.(MappedNullable); ok { + dataMap,err := t.ToMap() + if err != nil { + return + } + parameterAddToHeaderOrQuery(headerOrQueryParams, keyPrefix, dataMap, collectionType) + return + } + if t, ok := obj.(time.Time); ok { + parameterAddToHeaderOrQuery(headerOrQueryParams, keyPrefix, t.Format(time.RFC3339), collectionType) + return + } + value = v.Type().String() + " value" + case reflect.Slice: + var indValue = reflect.ValueOf(obj) + if indValue == reflect.ValueOf(nil) { + return + } + var lenIndValue = indValue.Len() + for i:=0;i 0 || (len(formFiles) > 0) { + if body != nil { + return nil, errors.New("Cannot specify postBody and multipart form at the same time.") + } + body = &bytes.Buffer{} + w := multipart.NewWriter(body) + + for k, v := range formParams { + for _, iv := range v { + if strings.HasPrefix(k, "@") { // file + err = addFile(w, k[1:], iv) + if err != nil { + return nil, err + } + } else { // form value + w.WriteField(k, iv) + } + } + } + for _, formFile := range formFiles { + if len(formFile.fileBytes) > 0 && formFile.fileName != "" { + w.Boundary() + part, err := w.CreateFormFile(formFile.formFileName, filepath.Base(formFile.fileName)) + if err != nil { + return nil, err + } + _, err = part.Write(formFile.fileBytes) + if err != nil { + return nil, err + } + } + } + + // Set the Boundary in the Content-Type + headerParams["Content-Type"] = w.FormDataContentType() + + // Set Content-Length + headerParams["Content-Length"] = fmt.Sprintf("%d", body.Len()) + w.Close() + } + + if strings.HasPrefix(headerParams["Content-Type"], "application/x-www-form-urlencoded") && len(formParams) > 0 { + if body != nil { + return nil, errors.New("Cannot specify postBody and x-www-form-urlencoded form at the same time.") + } + body = &bytes.Buffer{} + body.WriteString(formParams.Encode()) + // Set Content-Length + headerParams["Content-Length"] = fmt.Sprintf("%d", body.Len()) + } + + // Setup path and query parameters + url, err := url.Parse(path) + if err != nil { + return nil, err + } + + // Override request host, if applicable + if c.cfg.Host != "" { + url.Host = c.cfg.Host + } + + // Override request scheme, if applicable + if c.cfg.Scheme != "" { + url.Scheme = c.cfg.Scheme + } + + // Adding Query Param + query := url.Query() + for k, v := range queryParams { + for _, iv := range v { + query.Add(k, iv) + } + } + + // Encode the parameters. + url.RawQuery = queryParamSplit.ReplaceAllStringFunc(query.Encode(), func(s string) string { + pieces := strings.Split(s, "=") + pieces[0] = queryDescape.Replace(pieces[0]) + return strings.Join(pieces, "=") + }) + + // Generate a new request + if body != nil { + localVarRequest, err = http.NewRequest(method, url.String(), body) + } else { + localVarRequest, err = http.NewRequest(method, url.String(), nil) + } + if err != nil { + return nil, err + } + + // add header parameters, if any + if len(headerParams) > 0 { + headers := http.Header{} + for h, v := range headerParams { + headers[h] = []string{v} + } + localVarRequest.Header = headers + } + + // Add the user agent to the request. + localVarRequest.Header.Add("User-Agent", c.cfg.UserAgent) + + if ctx != nil { + // add context to the request + localVarRequest = localVarRequest.WithContext(ctx) + + // Walk through any authentication. + + // OAuth2 authentication + if tok, ok := ctx.Value(ContextOAuth2).(oauth2.TokenSource); ok { + // We were able to grab an oauth2 token from the context + var latestToken *oauth2.Token + if latestToken, err = tok.Token(); err != nil { + return nil, err + } + + latestToken.SetAuthHeader(localVarRequest) + } + + // AccessToken Authentication + if auth, ok := ctx.Value(ContextAccessToken).(string); ok { + localVarRequest.Header.Add("Authorization", "Bearer "+auth) + } + + } + + for header, value := range c.cfg.DefaultHeader { + localVarRequest.Header.Add(header, value) + } + return localVarRequest, nil +} + +func (c *APIClient) decode(v interface{}, b []byte, contentType string) (err error) { + if len(b) == 0 { + return nil + } + if s, ok := v.(*string); ok { + *s = string(b) + return nil + } + if f, ok := v.(*os.File); ok { + f, err = os.CreateTemp("", "HttpClientFile") + if err != nil { + return + } + _, err = f.Write(b) + if err != nil { + return + } + _, err = f.Seek(0, io.SeekStart) + return + } + if f, ok := v.(**os.File); ok { + *f, err = os.CreateTemp("", "HttpClientFile") + if err != nil { + return + } + _, err = (*f).Write(b) + if err != nil { + return + } + _, err = (*f).Seek(0, io.SeekStart) + return + } + if XmlCheck.MatchString(contentType) { + if err = xml.Unmarshal(b, v); err != nil { + return err + } + return nil + } + if JsonCheck.MatchString(contentType) { + if actualObj, ok := v.(interface{ GetActualInstance() interface{} }); ok { // oneOf, anyOf schemas + if unmarshalObj, ok := actualObj.(interface{ UnmarshalJSON([]byte) error }); ok { // make sure it has UnmarshalJSON defined + if err = unmarshalObj.UnmarshalJSON(b); err != nil { + return err + } + } else { + return errors.New("Unknown type with GetActualInstance but no unmarshalObj.UnmarshalJSON defined") + } + } else if err = json.Unmarshal(b, v); err != nil { // simple model + return err + } + return nil + } + return errors.New("undefined response type") +} + +// Add a file to the multipart request +func addFile(w *multipart.Writer, fieldName, path string) error { + file, err := os.Open(filepath.Clean(path)) + if err != nil { + return err + } + err = file.Close() + if err != nil { + return err + } + + part, err := w.CreateFormFile(fieldName, filepath.Base(path)) + if err != nil { + return err + } + _, err = io.Copy(part, file) + + return err +} + +// Prevent trying to import "fmt" +func reportError(format string, a ...interface{}) error { + return fmt.Errorf(format, a...) +} + +// A wrapper for strict JSON decoding +func newStrictDecoder(data []byte) *json.Decoder { + dec := json.NewDecoder(bytes.NewBuffer(data)) + dec.DisallowUnknownFields() + return dec +} + +// Set request body from an interface{} +func setBody(body interface{}, contentType string) (bodyBuf *bytes.Buffer, err error) { + if bodyBuf == nil { + bodyBuf = &bytes.Buffer{} + } + + if reader, ok := body.(io.Reader); ok { + _, err = bodyBuf.ReadFrom(reader) + } else if fp, ok := body.(*os.File); ok { + _, err = bodyBuf.ReadFrom(fp) + } else if b, ok := body.([]byte); ok { + _, err = bodyBuf.Write(b) + } else if s, ok := body.(string); ok { + _, err = bodyBuf.WriteString(s) + } else if s, ok := body.(*string); ok { + _, err = bodyBuf.WriteString(*s) + } else if JsonCheck.MatchString(contentType) { + err = json.NewEncoder(bodyBuf).Encode(body) + } else if XmlCheck.MatchString(contentType) { + var bs []byte + bs, err = xml.Marshal(body) + if err == nil { + bodyBuf.Write(bs) + } + } + + if err != nil { + return nil, err + } + + if bodyBuf.Len() == 0 { + err = fmt.Errorf("invalid body type %s\n", contentType) + return nil, err + } + return bodyBuf, nil +} + +// detectContentType method is used to figure out `Request.Body` content type for request header +func detectContentType(body interface{}) string { + contentType := "text/plain; charset=utf-8" + kind := reflect.TypeOf(body).Kind() + + switch kind { + case reflect.Struct, reflect.Map, reflect.Ptr: + contentType = "application/json; charset=utf-8" + case reflect.String: + contentType = "text/plain; charset=utf-8" + default: + if b, ok := body.([]byte); ok { + contentType = http.DetectContentType(b) + } else if kind == reflect.Slice { + contentType = "application/json; charset=utf-8" + } + } + + return contentType +} + +// Ripped from https://github.com/gregjones/httpcache/blob/master/httpcache.go +type cacheControl map[string]string + +func parseCacheControl(headers http.Header) cacheControl { + cc := cacheControl{} + ccHeader := headers.Get("Cache-Control") + for _, part := range strings.Split(ccHeader, ",") { + part = strings.Trim(part, " ") + if part == "" { + continue + } + if strings.ContainsRune(part, '=') { + keyval := strings.Split(part, "=") + cc[strings.Trim(keyval[0], " ")] = strings.Trim(keyval[1], ",") + } else { + cc[part] = "" + } + } + return cc +} + +// CacheExpires helper function to determine remaining time before repeating a request. +func CacheExpires(r *http.Response) time.Time { + // Figure out when the cache expires. + var expires time.Time + now, err := time.Parse(time.RFC1123, r.Header.Get("date")) + if err != nil { + return time.Now() + } + respCacheControl := parseCacheControl(r.Header) + + if maxAge, ok := respCacheControl["max-age"]; ok { + lifetime, err := time.ParseDuration(maxAge + "s") + if err != nil { + expires = now + } else { + expires = now.Add(lifetime) + } + } else { + expiresHeader := r.Header.Get("Expires") + if expiresHeader != "" { + expires, err = time.Parse(time.RFC1123, expiresHeader) + if err != nil { + expires = now + } + } + } + return expires +} + +func strlen(s string) int { + return utf8.RuneCountInString(s) +} + +// GenericOpenAPIError Provides access to the body, error and model on returned errors. +type GenericOpenAPIError struct { + body []byte + error string + model interface{} +} + +// Error returns non-empty string if there was an error. +func (e GenericOpenAPIError) Error() string { + return e.error +} + +// Body returns the raw bytes of the response +func (e GenericOpenAPIError) Body() []byte { + return e.body +} + +// Model returns the unpacked model of the error +func (e GenericOpenAPIError) Model() interface{} { + return e.model +} + +// format error message using title and detail when model implements rfc7807 +func formatErrorMessage(status string, v interface{}) string { + str := "" + metaValue := reflect.ValueOf(v).Elem() + + if metaValue.Kind() == reflect.Struct { + field := metaValue.FieldByName("Title") + if field != (reflect.Value{}) { + str = fmt.Sprintf("%s", field.Interface()) + } + + field = metaValue.FieldByName("Detail") + if field != (reflect.Value{}) { + str = fmt.Sprintf("%s (%s)", str, field.Interface()) + } + } + + return strings.TrimSpace(fmt.Sprintf("%s %s", status, str)) +} diff --git a/bmsdb/configuration.go b/bmsdb/configuration.go new file mode 100644 index 0000000..6fbad7d --- /dev/null +++ b/bmsdb/configuration.go @@ -0,0 +1,225 @@ +/* +bmsdb + +This documents the rest api bmsdb provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package bmsdb + +import ( + "context" + "fmt" + "net/http" + "strings" +) + +// contextKeys are used to identify the type of value in the context. +// Since these are string, it is possible to get a short description of the +// context key for logging and debugging using key.String(). + +type contextKey string + +func (c contextKey) String() string { + return "auth " + string(c) +} + +var ( + // ContextOAuth2 takes an oauth2.TokenSource as authentication for the request. + ContextOAuth2 = contextKey("token") + + // ContextAccessToken takes a string oauth2 access token as authentication for the request. + ContextAccessToken = contextKey("accesstoken") + + // ContextAPIKeys takes a string apikey as authentication for the request + ContextAPIKeys = contextKey("apiKeys") + + // ContextServerIndex uses a server configuration from the index. + ContextServerIndex = contextKey("serverIndex") + + // ContextOperationServerIndices uses a server configuration from the index mapping. + ContextOperationServerIndices = contextKey("serverOperationIndices") + + // ContextServerVariables overrides a server configuration variables. + ContextServerVariables = contextKey("serverVariables") + + // ContextOperationServerVariables overrides a server configuration variables using operation specific values. + ContextOperationServerVariables = contextKey("serverOperationVariables") +) + +// BasicAuth provides basic http authentication to a request passed via context using ContextBasicAuth +type BasicAuth struct { + UserName string `json:"userName,omitempty"` + Password string `json:"password,omitempty"` +} + +// APIKey provides API key based authentication to a request passed via context using ContextAPIKey +type APIKey struct { + Key string + Prefix string +} + +// ServerVariable stores the information about a server variable +type ServerVariable struct { + Description string + DefaultValue string + EnumValues []string +} + +// ServerConfiguration stores the information about a server +type ServerConfiguration struct { + URL string + Description string + Variables map[string]ServerVariable +} + +// ServerConfigurations stores multiple ServerConfiguration items +type ServerConfigurations []ServerConfiguration + +// Configuration stores the configuration of the API client +type Configuration struct { + Host string `json:"host,omitempty"` + Scheme string `json:"scheme,omitempty"` + DefaultHeader map[string]string `json:"defaultHeader,omitempty"` + UserAgent string `json:"userAgent,omitempty"` + Debug bool `json:"debug,omitempty"` + Servers ServerConfigurations + OperationServers map[string]ServerConfigurations + HTTPClient *http.Client +} + +// NewConfiguration returns a new Configuration object +func NewConfiguration() *Configuration { + cfg := &Configuration{ + DefaultHeader: make(map[string]string), + UserAgent: "OpenAPI-Generator/1.0.0/go", + Debug: false, + Servers: ServerConfigurations{ + { + URL: "https://api.leaseweb.com/internal/bmsdb/v2", + Description: "No description provided", + }, + }, + OperationServers: map[string]ServerConfigurations{ + }, + } + return cfg +} + +// AddDefaultHeader adds a new HTTP header to the default header in the request +func (c *Configuration) AddDefaultHeader(key string, value string) { + c.DefaultHeader[key] = value +} + +// URL formats template on a index using given variables +func (sc ServerConfigurations) URL(index int, variables map[string]string) (string, error) { + if index < 0 || len(sc) <= index { + return "", fmt.Errorf("index %v out of range %v", index, len(sc)-1) + } + server := sc[index] + url := server.URL + + // go through variables and replace placeholders + for name, variable := range server.Variables { + if value, ok := variables[name]; ok { + found := bool(len(variable.EnumValues) == 0) + for _, enumValue := range variable.EnumValues { + if value == enumValue { + found = true + } + } + if !found { + return "", fmt.Errorf("the variable %s in the server URL has invalid value %v. Must be %v", name, value, variable.EnumValues) + } + url = strings.Replace(url, "{"+name+"}", value, -1) + } else { + url = strings.Replace(url, "{"+name+"}", variable.DefaultValue, -1) + } + } + return url, nil +} + +// ServerURL returns URL based on server settings +func (c *Configuration) ServerURL(index int, variables map[string]string) (string, error) { + return c.Servers.URL(index, variables) +} + +func getServerIndex(ctx context.Context) (int, error) { + si := ctx.Value(ContextServerIndex) + if si != nil { + if index, ok := si.(int); ok { + return index, nil + } + return 0, reportError("Invalid type %T should be int", si) + } + return 0, nil +} + +func getServerOperationIndex(ctx context.Context, endpoint string) (int, error) { + osi := ctx.Value(ContextOperationServerIndices) + if osi != nil { + if operationIndices, ok := osi.(map[string]int); !ok { + return 0, reportError("Invalid type %T should be map[string]int", osi) + } else { + index, ok := operationIndices[endpoint] + if ok { + return index, nil + } + } + } + return getServerIndex(ctx) +} + +func getServerVariables(ctx context.Context) (map[string]string, error) { + sv := ctx.Value(ContextServerVariables) + if sv != nil { + if variables, ok := sv.(map[string]string); ok { + return variables, nil + } + return nil, reportError("ctx value of ContextServerVariables has invalid type %T should be map[string]string", sv) + } + return nil, nil +} + +func getServerOperationVariables(ctx context.Context, endpoint string) (map[string]string, error) { + osv := ctx.Value(ContextOperationServerVariables) + if osv != nil { + if operationVariables, ok := osv.(map[string]map[string]string); !ok { + return nil, reportError("ctx value of ContextOperationServerVariables has invalid type %T should be map[string]map[string]string", osv) + } else { + variables, ok := operationVariables[endpoint] + if ok { + return variables, nil + } + } + } + return getServerVariables(ctx) +} + +// ServerURLWithContext returns a new server URL given an endpoint +func (c *Configuration) ServerURLWithContext(ctx context.Context, endpoint string) (string, error) { + sc, ok := c.OperationServers[endpoint] + if !ok { + sc = c.Servers + } + + if ctx == nil { + return sc.URL(0, nil) + } + + index, err := getServerOperationIndex(ctx, endpoint) + if err != nil { + return "", err + } + + variables, err := getServerOperationVariables(ctx, endpoint) + if err != nil { + return "", err + } + + return sc.URL(index, variables) +} diff --git a/bmsdb/go.mod b/bmsdb/go.mod new file mode 100644 index 0000000..74d4603 --- /dev/null +++ b/bmsdb/go.mod @@ -0,0 +1,7 @@ +module github.com/leaseweb/leaseweb-go-sdk/bmsdb + +go 1.18 + +require ( + golang.org/x/oauth2 v0.0.0-20210323180902-22b0adad7558 +) diff --git a/bmsdb/go.sum b/bmsdb/go.sum new file mode 100644 index 0000000..3dee6d6 --- /dev/null +++ b/bmsdb/go.sum @@ -0,0 +1,360 @@ +cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU= +cloud.google.com/go v0.44.1/go.mod h1:iSa0KzasP4Uvy3f1mN/7PiObzGgflwredwwASm/v6AU= +cloud.google.com/go v0.44.2/go.mod h1:60680Gw3Yr4ikxnPRS/oxxkBccT6SA1yMk63TGekxKY= +cloud.google.com/go v0.45.1/go.mod h1:RpBamKRgapWJb87xiFSdk4g1CME7QZg3uwTez+TSTjc= +cloud.google.com/go v0.46.3/go.mod h1:a6bKKbmY7er1mI7TEI4lsAkts/mkhTSZK8w33B4RAg0= +cloud.google.com/go v0.50.0/go.mod h1:r9sluTvynVuxRIOHXQEHMFffphuXHOMZMycpNR5e6To= +cloud.google.com/go v0.52.0/go.mod h1:pXajvRH/6o3+F9jDHZWQ5PbGhn+o8w9qiu/CffaVdO4= +cloud.google.com/go v0.53.0/go.mod h1:fp/UouUEsRkN6ryDKNW/Upv/JBKnv6WDthjR6+vze6M= +cloud.google.com/go v0.54.0/go.mod h1:1rq2OEkV3YMf6n/9ZvGWI3GWw0VoqH/1x2nd8Is/bPc= +cloud.google.com/go v0.56.0/go.mod h1:jr7tqZxxKOVYizybht9+26Z/gUq7tiRzu+ACVAMbKVk= +cloud.google.com/go v0.57.0/go.mod h1:oXiQ6Rzq3RAkkY7N6t3TcE6jE+CIBBbA36lwQ1JyzZs= +cloud.google.com/go v0.62.0/go.mod h1:jmCYTdRCQuc1PHIIJ/maLInMho30T/Y0M4hTdTShOYc= +cloud.google.com/go v0.65.0/go.mod h1:O5N8zS7uWy9vkA9vayVHs65eM1ubvY4h553ofrNHObY= +cloud.google.com/go/bigquery v1.0.1/go.mod h1:i/xbL2UlR5RvWAURpBYZTtm/cXjCha9lbfbpx4poX+o= +cloud.google.com/go/bigquery v1.3.0/go.mod h1:PjpwJnslEMmckchkHFfq+HTD2DmtT67aNFKH1/VBDHE= +cloud.google.com/go/bigquery v1.4.0/go.mod h1:S8dzgnTigyfTmLBfrtrhyYhwRxG72rYxvftPBK2Dvzc= +cloud.google.com/go/bigquery v1.5.0/go.mod h1:snEHRnqQbz117VIFhE8bmtwIDY80NLUZUMb4Nv6dBIg= +cloud.google.com/go/bigquery v1.7.0/go.mod h1://okPTzCYNXSlb24MZs83e2Do+h+VXtc4gLoIoXIAPc= +cloud.google.com/go/bigquery v1.8.0/go.mod h1:J5hqkt3O0uAFnINi6JXValWIb1v0goeZM77hZzJN/fQ= +cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7TKLgZqpHYE= +cloud.google.com/go/datastore v1.1.0/go.mod h1:umbIZjpQpHh4hmRpGhH4tLFup+FVzqBi1b3c64qFpCk= +cloud.google.com/go/pubsub v1.0.1/go.mod h1:R0Gpsv3s54REJCy4fxDixWD93lHJMoZTyQ2kNxGRt3I= +cloud.google.com/go/pubsub v1.1.0/go.mod h1:EwwdRX2sKPjnvnqCa270oGRyludottCI76h+R3AArQw= +cloud.google.com/go/pubsub v1.2.0/go.mod h1:jhfEVHT8odbXTkndysNHCcx0awwzvfOlguIAii9o8iA= +cloud.google.com/go/pubsub v1.3.1/go.mod h1:i+ucay31+CNRpDW4Lu78I4xXG+O1r/MAHgjpRVR+TSU= +cloud.google.com/go/storage v1.0.0/go.mod h1:IhtSnM/ZTZV8YYJWCY8RULGVqBDmpoyjwiyrjsg+URw= +cloud.google.com/go/storage v1.5.0/go.mod h1:tpKbwo567HUNpVclU5sGELwQWBDZ8gh0ZeosJ0Rtdos= +cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohlUTyfDhBk= +cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs= +cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0= +dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= +github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= +github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= +github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= +github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= +github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= +github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= +github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= +github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= +github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y= +github.com/golang/mock v1.4.0/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= +github.com/golang/mock v1.4.1/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= +github.com/golang/mock v1.4.3/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= +github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4= +github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= +github.com/golang/protobuf v1.3.4/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= +github.com/golang/protobuf v1.3.5/go.mod h1:6O5/vntMXwX2lRkT1hjjk0nAC1IDOTvTlVgjlRvqsdk= +github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= +github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= +github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= +github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= +github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= +github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= +github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= +github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= +github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= +github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.4.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= +github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0= +github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= +github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= +github.com/google/pprof v0.0.0-20191218002539-d4f498aebedc/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= +github.com/google/pprof v0.0.0-20200212024743-f11f1df84d12/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= +github.com/google/pprof v0.0.0-20200229191704-1ebb73c60ed3/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= +github.com/google/pprof v0.0.0-20200430221834-fc25d7d30c6d/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= +github.com/google/pprof v0.0.0-20200708004538-1a94d8640e99/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= +github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= +github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= +github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= +github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= +github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= +github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= +github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= +github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk= +github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= +go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= +go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= +go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= +go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= +golang.org/x/exp v0.0.0-20190829153037-c13cbed26979/go.mod h1:86+5VVa7VpoJ4kLfm080zCjGlMRFzhUhsZKEZO7MGek= +golang.org/x/exp v0.0.0-20191030013958-a1ab85dbe136/go.mod h1:JXzH8nQsPlswgeRAPE3MuO9GYsAcnJvJ4vnMwN/5qkY= +golang.org/x/exp v0.0.0-20191129062945-2f5052295587/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= +golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= +golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= +golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM= +golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU= +golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= +golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= +golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= +golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f/go.mod h1:5qLYkcX4OjUUV8bRuDixDT3tpyyb+LUpUlRWLxfhWrs= +golang.org/x/lint v0.0.0-20200130185559-910be7a94367/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= +golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= +golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= +golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o= +golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= +golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY= +golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= +golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= +golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e h1:bRhVy7zSSasaqNksaRZiA5EEI+Ei4I1nO5Jh72wfHlg= +golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190501004415-9ce7a6920f09/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20190628185345-da137c7871d7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200222125558-5a598a2470a0/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200501053045-e0ff5e5a1de5/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200506145744-7e3656a0809f/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200513185701-a91f0712d120/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200520182314-0ba52f642ac2/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= +golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= +golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= +golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= +golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45 h1:SVwTIAaPC2U/AvvLNZ2a7OVsmBpC8L5BlwK1whH3hm0= +golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/oauth2 v0.0.0-20191202225959-858c2ad4c8b6/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/oauth2 v0.0.0-20210323180902-22b0adad7558/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4 h1:YUO/7uOKsKeq9UokNS62b8FYywz3ker1l1vDZRCRefw= +golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200113162924-86b910548bc1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200122134326-e047566fdf82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200331124033-c3d80250170d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200501052902-10377860bb8e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200511232937-7e40ca221e25/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200515095857-1151b9dac4a9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200523222454-059865788121/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200803210538-64077c9b5642/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= +golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20190506145303-2d16b83fe98c/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191113191852-77e3bb0ad9e7/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191115202509-3a792d9c32b2/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191130070609-6e064ea0cf2d/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191216173652-a0e659d51361/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20191227053925-7b8e75db28f4/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200117161641-43d50277825c/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200122220014-bf1340f18c4a/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200204074204-1cc6d1ef6c74/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200207183749-b753a1ba74fa/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200212150539-ea181f53ac56/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200224181240-023911ca70b2/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200227222343-706bc42d1f0d/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200304193943-95d2e580d8eb/go.mod h1:o4KQGtdN14AW+yjsvvwRTJJuXz8XRtIHtEnmAXLyFUw= +golang.org/x/tools v0.0.0-20200312045724-11d5b4c81c7d/go.mod h1:o4KQGtdN14AW+yjsvvwRTJJuXz8XRtIHtEnmAXLyFUw= +golang.org/x/tools v0.0.0-20200331025713-a30bf2db82d4/go.mod h1:Sl4aGygMT6LrqrWclx+PTx3U+LnKx/seiNR+3G19Ar8= +golang.org/x/tools v0.0.0-20200501065659-ab2804fb9c9d/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20200512131952-2bc93b1c0c88/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20200515010526-7d3b6ebf133d/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20200618134242-20370b0cb4b2/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20200729194436-6467de6f59a7/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= +golang.org/x/tools v0.0.0-20200804011535-6c149bb5ef0d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= +golang.org/x/tools v0.0.0-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= +google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M= +google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= +google.golang.org/api v0.9.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= +google.golang.org/api v0.13.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= +google.golang.org/api v0.14.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= +google.golang.org/api v0.15.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= +google.golang.org/api v0.17.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= +google.golang.org/api v0.18.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= +google.golang.org/api v0.19.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= +google.golang.org/api v0.20.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= +google.golang.org/api v0.22.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= +google.golang.org/api v0.24.0/go.mod h1:lIXQywCXRcnZPGlsd8NbLnOjtAoL6em04bJ9+z0MncE= +google.golang.org/api v0.28.0/go.mod h1:lIXQywCXRcnZPGlsd8NbLnOjtAoL6em04bJ9+z0MncE= +google.golang.org/api v0.29.0/go.mod h1:Lcubydp8VUV7KeIHD9z2Bys/sm/vGKnG1UHuDBSrHWM= +google.golang.org/api v0.30.0/go.mod h1:QGmEvQ87FHZNiUVJkT14jQNYJ4ZJjdRF23ZXz5138Fc= +google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= +google.golang.org/appengine v1.4.0 h1:/wp5JvzpHIxhs/dumFmF7BXTf3Z+dd4uXta4kVyO508= +google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0= +google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= +google.golang.org/appengine v1.6.6/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= +google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= +google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190801165951-fa694d86fc64/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= +google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= +google.golang.org/genproto v0.0.0-20190911173649-1774047e7e51/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8= +google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20191115194625-c23dd37a84c9/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20191216164720-4f79533eabd1/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20191230161307-f3c370f40bfb/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20200115191322-ca5a22157cba/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20200122232147-0452cf42e150/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20200204135345-fa8e72b47b90/go.mod h1:GmwEX6Z4W5gMy59cAlVYjN9JhxgbQH6Gn+gFDQe2lzA= +google.golang.org/genproto v0.0.0-20200212174721-66ed5ce911ce/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200224152610-e50cd9704f63/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200228133532-8c2c7df3a383/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200305110556-506484158171/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200312145019-da6875a35672/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200331122359-1ee6d9798940/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200430143042-b979b6f78d84/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200511104702-f5ebc3bea380/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200515170657-fc4c6c6a6587/go.mod h1:YsZOwe1myG/8QRHRsmBRE1LrgQY60beZKjly0O1fX9U= +google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= +google.golang.org/genproto v0.0.0-20200618031413-b414f8b61790/go.mod h1:jDfRM7FcilCzHH/e9qn6dsT145K34l5v+OpcnNgKAAA= +google.golang.org/genproto v0.0.0-20200729003335-053ba62fc06f/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20200804131852-c06518451d9c/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20200825200019-8632dd797987/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= +google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= +google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= +google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= +google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= +google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= +google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= +google.golang.org/grpc v1.27.1/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= +google.golang.org/grpc v1.28.0/go.mod h1:rpkK4SK4GF4Ach/+MFLZUBavHOvF2JJB5uozKKal+60= +google.golang.org/grpc v1.29.1/go.mod h1:itym6AZVZYACWQqET3MqgPpjcuV5QH3BxFS3IjizoKk= +google.golang.org/grpc v1.30.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= +google.golang.org/grpc v1.31.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= +google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= +google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= +google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= +google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= +google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= +google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4= +google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= +honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= +honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= +rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= +rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0= +rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= diff --git a/bmsdb/model__metadata.go b/bmsdb/model__metadata.go new file mode 100644 index 0000000..18624bf --- /dev/null +++ b/bmsdb/model__metadata.go @@ -0,0 +1,210 @@ +/* +bmsdb + +This documents the rest api bmsdb provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package bmsdb + +import ( + "encoding/json" +) + +// checks if the Metadata type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &Metadata{} + +// Metadata Metadata about the collection +type Metadata struct { + // Total amount of orders in this collection + TotalCount *float32 `json:"totalCount,omitempty"` + // The offset used to generate this response + Offset *float32 `json:"offset,omitempty"` + // The limit used to generate this response + Limit *float32 `json:"limit,omitempty"` +} + +// NewMetadata instantiates a new Metadata object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewMetadata() *Metadata { + this := Metadata{} + var offset float32 = 0 + this.Offset = &offset + var limit float32 = 5 + this.Limit = &limit + return &this +} + +// NewMetadataWithDefaults instantiates a new Metadata object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewMetadataWithDefaults() *Metadata { + this := Metadata{} + var offset float32 = 0 + this.Offset = &offset + var limit float32 = 5 + this.Limit = &limit + return &this +} + +// GetTotalCount returns the TotalCount field value if set, zero value otherwise. +func (o *Metadata) GetTotalCount() float32 { + if o == nil || IsNil(o.TotalCount) { + var ret float32 + return ret + } + return *o.TotalCount +} + +// GetTotalCountOk returns a tuple with the TotalCount field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Metadata) GetTotalCountOk() (*float32, bool) { + if o == nil || IsNil(o.TotalCount) { + return nil, false + } + return o.TotalCount, true +} + +// HasTotalCount returns a boolean if a field has been set. +func (o *Metadata) HasTotalCount() bool { + if o != nil && !IsNil(o.TotalCount) { + return true + } + + return false +} + +// SetTotalCount gets a reference to the given float32 and assigns it to the TotalCount field. +func (o *Metadata) SetTotalCount(v float32) { + o.TotalCount = &v +} + +// GetOffset returns the Offset field value if set, zero value otherwise. +func (o *Metadata) GetOffset() float32 { + if o == nil || IsNil(o.Offset) { + var ret float32 + return ret + } + return *o.Offset +} + +// GetOffsetOk returns a tuple with the Offset field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Metadata) GetOffsetOk() (*float32, bool) { + if o == nil || IsNil(o.Offset) { + return nil, false + } + return o.Offset, true +} + +// HasOffset returns a boolean if a field has been set. +func (o *Metadata) HasOffset() bool { + if o != nil && !IsNil(o.Offset) { + return true + } + + return false +} + +// SetOffset gets a reference to the given float32 and assigns it to the Offset field. +func (o *Metadata) SetOffset(v float32) { + o.Offset = &v +} + +// GetLimit returns the Limit field value if set, zero value otherwise. +func (o *Metadata) GetLimit() float32 { + if o == nil || IsNil(o.Limit) { + var ret float32 + return ret + } + return *o.Limit +} + +// GetLimitOk returns a tuple with the Limit field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Metadata) GetLimitOk() (*float32, bool) { + if o == nil || IsNil(o.Limit) { + return nil, false + } + return o.Limit, true +} + +// HasLimit returns a boolean if a field has been set. +func (o *Metadata) HasLimit() bool { + if o != nil && !IsNil(o.Limit) { + return true + } + + return false +} + +// SetLimit gets a reference to the given float32 and assigns it to the Limit field. +func (o *Metadata) SetLimit(v float32) { + o.Limit = &v +} + +func (o Metadata) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o Metadata) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.TotalCount) { + toSerialize["totalCount"] = o.TotalCount + } + if !IsNil(o.Offset) { + toSerialize["offset"] = o.Offset + } + if !IsNil(o.Limit) { + toSerialize["limit"] = o.Limit + } + return toSerialize, nil +} + +type NullableMetadata struct { + value *Metadata + isSet bool +} + +func (v NullableMetadata) Get() *Metadata { + return v.value +} + +func (v *NullableMetadata) Set(val *Metadata) { + v.value = val + v.isSet = true +} + +func (v NullableMetadata) IsSet() bool { + return v.isSet +} + +func (v *NullableMetadata) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableMetadata(val *Metadata) *NullableMetadata { + return &NullableMetadata{value: val, isSet: true} +} + +func (v NullableMetadata) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableMetadata) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/bmsdb/model_error_result.go b/bmsdb/model_error_result.go new file mode 100644 index 0000000..e76a155 --- /dev/null +++ b/bmsdb/model_error_result.go @@ -0,0 +1,238 @@ +/* +bmsdb + +This documents the rest api bmsdb provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package bmsdb + +import ( + "encoding/json" +) + +// checks if the ErrorResult type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &ErrorResult{} + +// ErrorResult struct for ErrorResult +type ErrorResult struct { + // The correlation ID of the current request. + CorrelationId *string `json:"correlationId,omitempty"` + // The error code. + ErrorCode *string `json:"errorCode,omitempty"` + // A human friendly description of the error. + ErrorMessage *string `json:"errorMessage,omitempty"` + ErrorDetails []map[string][]string `json:"errorDetails,omitempty"` +} + +// NewErrorResult instantiates a new ErrorResult object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewErrorResult() *ErrorResult { + this := ErrorResult{} + return &this +} + +// NewErrorResultWithDefaults instantiates a new ErrorResult object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewErrorResultWithDefaults() *ErrorResult { + this := ErrorResult{} + return &this +} + +// GetCorrelationId returns the CorrelationId field value if set, zero value otherwise. +func (o *ErrorResult) GetCorrelationId() string { + if o == nil || IsNil(o.CorrelationId) { + var ret string + return ret + } + return *o.CorrelationId +} + +// GetCorrelationIdOk returns a tuple with the CorrelationId field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ErrorResult) GetCorrelationIdOk() (*string, bool) { + if o == nil || IsNil(o.CorrelationId) { + return nil, false + } + return o.CorrelationId, true +} + +// HasCorrelationId returns a boolean if a field has been set. +func (o *ErrorResult) HasCorrelationId() bool { + if o != nil && !IsNil(o.CorrelationId) { + return true + } + + return false +} + +// SetCorrelationId gets a reference to the given string and assigns it to the CorrelationId field. +func (o *ErrorResult) SetCorrelationId(v string) { + o.CorrelationId = &v +} + +// GetErrorCode returns the ErrorCode field value if set, zero value otherwise. +func (o *ErrorResult) GetErrorCode() string { + if o == nil || IsNil(o.ErrorCode) { + var ret string + return ret + } + return *o.ErrorCode +} + +// GetErrorCodeOk returns a tuple with the ErrorCode field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ErrorResult) GetErrorCodeOk() (*string, bool) { + if o == nil || IsNil(o.ErrorCode) { + return nil, false + } + return o.ErrorCode, true +} + +// HasErrorCode returns a boolean if a field has been set. +func (o *ErrorResult) HasErrorCode() bool { + if o != nil && !IsNil(o.ErrorCode) { + return true + } + + return false +} + +// SetErrorCode gets a reference to the given string and assigns it to the ErrorCode field. +func (o *ErrorResult) SetErrorCode(v string) { + o.ErrorCode = &v +} + +// GetErrorMessage returns the ErrorMessage field value if set, zero value otherwise. +func (o *ErrorResult) GetErrorMessage() string { + if o == nil || IsNil(o.ErrorMessage) { + var ret string + return ret + } + return *o.ErrorMessage +} + +// GetErrorMessageOk returns a tuple with the ErrorMessage field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ErrorResult) GetErrorMessageOk() (*string, bool) { + if o == nil || IsNil(o.ErrorMessage) { + return nil, false + } + return o.ErrorMessage, true +} + +// HasErrorMessage returns a boolean if a field has been set. +func (o *ErrorResult) HasErrorMessage() bool { + if o != nil && !IsNil(o.ErrorMessage) { + return true + } + + return false +} + +// SetErrorMessage gets a reference to the given string and assigns it to the ErrorMessage field. +func (o *ErrorResult) SetErrorMessage(v string) { + o.ErrorMessage = &v +} + +// GetErrorDetails returns the ErrorDetails field value if set, zero value otherwise. +func (o *ErrorResult) GetErrorDetails() []map[string][]string { + if o == nil || IsNil(o.ErrorDetails) { + var ret []map[string][]string + return ret + } + return o.ErrorDetails +} + +// GetErrorDetailsOk returns a tuple with the ErrorDetails field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ErrorResult) GetErrorDetailsOk() ([]map[string][]string, bool) { + if o == nil || IsNil(o.ErrorDetails) { + return nil, false + } + return o.ErrorDetails, true +} + +// HasErrorDetails returns a boolean if a field has been set. +func (o *ErrorResult) HasErrorDetails() bool { + if o != nil && !IsNil(o.ErrorDetails) { + return true + } + + return false +} + +// SetErrorDetails gets a reference to the given []map[string][]string and assigns it to the ErrorDetails field. +func (o *ErrorResult) SetErrorDetails(v []map[string][]string) { + o.ErrorDetails = v +} + +func (o ErrorResult) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o ErrorResult) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.CorrelationId) { + toSerialize["correlationId"] = o.CorrelationId + } + if !IsNil(o.ErrorCode) { + toSerialize["errorCode"] = o.ErrorCode + } + if !IsNil(o.ErrorMessage) { + toSerialize["errorMessage"] = o.ErrorMessage + } + if !IsNil(o.ErrorDetails) { + toSerialize["errorDetails"] = o.ErrorDetails + } + return toSerialize, nil +} + +type NullableErrorResult struct { + value *ErrorResult + isSet bool +} + +func (v NullableErrorResult) Get() *ErrorResult { + return v.value +} + +func (v *NullableErrorResult) Set(val *ErrorResult) { + v.value = val + v.isSet = true +} + +func (v NullableErrorResult) IsSet() bool { + return v.isSet +} + +func (v *NullableErrorResult) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableErrorResult(val *ErrorResult) *NullableErrorResult { + return &NullableErrorResult{value: val, isSet: true} +} + +func (v NullableErrorResult) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableErrorResult) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/bmsdb/model_get_server_hardware_result.go b/bmsdb/model_get_server_hardware_result.go new file mode 100644 index 0000000..c64b1dd --- /dev/null +++ b/bmsdb/model_get_server_hardware_result.go @@ -0,0 +1,277 @@ +/* +bmsdb + +This documents the rest api bmsdb provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package bmsdb + +import ( + "encoding/json" + "time" +) + +// checks if the GetServerHardwareResult type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &GetServerHardwareResult{} + +// GetServerHardwareResult struct for GetServerHardwareResult +type GetServerHardwareResult struct { + // Id of this hardware scan result + Id *string `json:"id,omitempty"` + // Version of the parser used for this hardware info + ParserVersion *string `json:"parserVersion,omitempty"` + // Hardware info e.g. chassis, cpu, memory and etc. + Result map[string]interface{} `json:"result,omitempty"` + // Timestamp of hardware scan + ScannedAt *time.Time `json:"scannedAt,omitempty"` + // The server id + ServerId *string `json:"serverId,omitempty"` +} + +// NewGetServerHardwareResult instantiates a new GetServerHardwareResult object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewGetServerHardwareResult() *GetServerHardwareResult { + this := GetServerHardwareResult{} + return &this +} + +// NewGetServerHardwareResultWithDefaults instantiates a new GetServerHardwareResult object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewGetServerHardwareResultWithDefaults() *GetServerHardwareResult { + this := GetServerHardwareResult{} + return &this +} + +// GetId returns the Id field value if set, zero value otherwise. +func (o *GetServerHardwareResult) GetId() string { + if o == nil || IsNil(o.Id) { + var ret string + return ret + } + return *o.Id +} + +// GetIdOk returns a tuple with the Id field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetServerHardwareResult) GetIdOk() (*string, bool) { + if o == nil || IsNil(o.Id) { + return nil, false + } + return o.Id, true +} + +// HasId returns a boolean if a field has been set. +func (o *GetServerHardwareResult) HasId() bool { + if o != nil && !IsNil(o.Id) { + return true + } + + return false +} + +// SetId gets a reference to the given string and assigns it to the Id field. +func (o *GetServerHardwareResult) SetId(v string) { + o.Id = &v +} + +// GetParserVersion returns the ParserVersion field value if set, zero value otherwise. +func (o *GetServerHardwareResult) GetParserVersion() string { + if o == nil || IsNil(o.ParserVersion) { + var ret string + return ret + } + return *o.ParserVersion +} + +// GetParserVersionOk returns a tuple with the ParserVersion field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetServerHardwareResult) GetParserVersionOk() (*string, bool) { + if o == nil || IsNil(o.ParserVersion) { + return nil, false + } + return o.ParserVersion, true +} + +// HasParserVersion returns a boolean if a field has been set. +func (o *GetServerHardwareResult) HasParserVersion() bool { + if o != nil && !IsNil(o.ParserVersion) { + return true + } + + return false +} + +// SetParserVersion gets a reference to the given string and assigns it to the ParserVersion field. +func (o *GetServerHardwareResult) SetParserVersion(v string) { + o.ParserVersion = &v +} + +// GetResult returns the Result field value if set, zero value otherwise. +func (o *GetServerHardwareResult) GetResult() map[string]interface{} { + if o == nil || IsNil(o.Result) { + var ret map[string]interface{} + return ret + } + return o.Result +} + +// GetResultOk returns a tuple with the Result field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetServerHardwareResult) GetResultOk() (map[string]interface{}, bool) { + if o == nil || IsNil(o.Result) { + return map[string]interface{}{}, false + } + return o.Result, true +} + +// HasResult returns a boolean if a field has been set. +func (o *GetServerHardwareResult) HasResult() bool { + if o != nil && !IsNil(o.Result) { + return true + } + + return false +} + +// SetResult gets a reference to the given map[string]interface{} and assigns it to the Result field. +func (o *GetServerHardwareResult) SetResult(v map[string]interface{}) { + o.Result = v +} + +// GetScannedAt returns the ScannedAt field value if set, zero value otherwise. +func (o *GetServerHardwareResult) GetScannedAt() time.Time { + if o == nil || IsNil(o.ScannedAt) { + var ret time.Time + return ret + } + return *o.ScannedAt +} + +// GetScannedAtOk returns a tuple with the ScannedAt field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetServerHardwareResult) GetScannedAtOk() (*time.Time, bool) { + if o == nil || IsNil(o.ScannedAt) { + return nil, false + } + return o.ScannedAt, true +} + +// HasScannedAt returns a boolean if a field has been set. +func (o *GetServerHardwareResult) HasScannedAt() bool { + if o != nil && !IsNil(o.ScannedAt) { + return true + } + + return false +} + +// SetScannedAt gets a reference to the given time.Time and assigns it to the ScannedAt field. +func (o *GetServerHardwareResult) SetScannedAt(v time.Time) { + o.ScannedAt = &v +} + +// GetServerId returns the ServerId field value if set, zero value otherwise. +func (o *GetServerHardwareResult) GetServerId() string { + if o == nil || IsNil(o.ServerId) { + var ret string + return ret + } + return *o.ServerId +} + +// GetServerIdOk returns a tuple with the ServerId field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetServerHardwareResult) GetServerIdOk() (*string, bool) { + if o == nil || IsNil(o.ServerId) { + return nil, false + } + return o.ServerId, true +} + +// HasServerId returns a boolean if a field has been set. +func (o *GetServerHardwareResult) HasServerId() bool { + if o != nil && !IsNil(o.ServerId) { + return true + } + + return false +} + +// SetServerId gets a reference to the given string and assigns it to the ServerId field. +func (o *GetServerHardwareResult) SetServerId(v string) { + o.ServerId = &v +} + +func (o GetServerHardwareResult) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o GetServerHardwareResult) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Id) { + toSerialize["id"] = o.Id + } + if !IsNil(o.ParserVersion) { + toSerialize["parserVersion"] = o.ParserVersion + } + if !IsNil(o.Result) { + toSerialize["result"] = o.Result + } + if !IsNil(o.ScannedAt) { + toSerialize["scannedAt"] = o.ScannedAt + } + if !IsNil(o.ServerId) { + toSerialize["serverId"] = o.ServerId + } + return toSerialize, nil +} + +type NullableGetServerHardwareResult struct { + value *GetServerHardwareResult + isSet bool +} + +func (v NullableGetServerHardwareResult) Get() *GetServerHardwareResult { + return v.value +} + +func (v *NullableGetServerHardwareResult) Set(val *GetServerHardwareResult) { + v.value = val + v.isSet = true +} + +func (v NullableGetServerHardwareResult) IsSet() bool { + return v.isSet +} + +func (v *NullableGetServerHardwareResult) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableGetServerHardwareResult(val *GetServerHardwareResult) *NullableGetServerHardwareResult { + return &NullableGetServerHardwareResult{value: val, isSet: true} +} + +func (v NullableGetServerHardwareResult) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableGetServerHardwareResult) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/bmsdb/model_get_server_hardware_scan_list_result.go b/bmsdb/model_get_server_hardware_scan_list_result.go new file mode 100644 index 0000000..35e9849 --- /dev/null +++ b/bmsdb/model_get_server_hardware_scan_list_result.go @@ -0,0 +1,164 @@ +/* +bmsdb + +This documents the rest api bmsdb provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package bmsdb + +import ( + "encoding/json" +) + +// checks if the GetServerHardwareScanListResult type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &GetServerHardwareScanListResult{} + +// GetServerHardwareScanListResult List of Hardware Scans executed in a server +type GetServerHardwareScanListResult struct { + Metadata *Metadata `json:"_metadata,omitempty"` + // Simple list of Hardware Scans + HardwareScans []HardwareScan `json:"hardwareScans,omitempty"` +} + +// NewGetServerHardwareScanListResult instantiates a new GetServerHardwareScanListResult object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewGetServerHardwareScanListResult() *GetServerHardwareScanListResult { + this := GetServerHardwareScanListResult{} + return &this +} + +// NewGetServerHardwareScanListResultWithDefaults instantiates a new GetServerHardwareScanListResult object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewGetServerHardwareScanListResultWithDefaults() *GetServerHardwareScanListResult { + this := GetServerHardwareScanListResult{} + return &this +} + +// GetMetadata returns the Metadata field value if set, zero value otherwise. +func (o *GetServerHardwareScanListResult) GetMetadata() Metadata { + if o == nil || IsNil(o.Metadata) { + var ret Metadata + return ret + } + return *o.Metadata +} + +// GetMetadataOk returns a tuple with the Metadata field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetServerHardwareScanListResult) GetMetadataOk() (*Metadata, bool) { + if o == nil || IsNil(o.Metadata) { + return nil, false + } + return o.Metadata, true +} + +// HasMetadata returns a boolean if a field has been set. +func (o *GetServerHardwareScanListResult) HasMetadata() bool { + if o != nil && !IsNil(o.Metadata) { + return true + } + + return false +} + +// SetMetadata gets a reference to the given Metadata and assigns it to the Metadata field. +func (o *GetServerHardwareScanListResult) SetMetadata(v Metadata) { + o.Metadata = &v +} + +// GetHardwareScans returns the HardwareScans field value if set, zero value otherwise. +func (o *GetServerHardwareScanListResult) GetHardwareScans() []HardwareScan { + if o == nil || IsNil(o.HardwareScans) { + var ret []HardwareScan + return ret + } + return o.HardwareScans +} + +// GetHardwareScansOk returns a tuple with the HardwareScans field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetServerHardwareScanListResult) GetHardwareScansOk() ([]HardwareScan, bool) { + if o == nil || IsNil(o.HardwareScans) { + return nil, false + } + return o.HardwareScans, true +} + +// HasHardwareScans returns a boolean if a field has been set. +func (o *GetServerHardwareScanListResult) HasHardwareScans() bool { + if o != nil && !IsNil(o.HardwareScans) { + return true + } + + return false +} + +// SetHardwareScans gets a reference to the given []HardwareScan and assigns it to the HardwareScans field. +func (o *GetServerHardwareScanListResult) SetHardwareScans(v []HardwareScan) { + o.HardwareScans = v +} + +func (o GetServerHardwareScanListResult) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o GetServerHardwareScanListResult) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Metadata) { + toSerialize["_metadata"] = o.Metadata + } + if !IsNil(o.HardwareScans) { + toSerialize["hardwareScans"] = o.HardwareScans + } + return toSerialize, nil +} + +type NullableGetServerHardwareScanListResult struct { + value *GetServerHardwareScanListResult + isSet bool +} + +func (v NullableGetServerHardwareScanListResult) Get() *GetServerHardwareScanListResult { + return v.value +} + +func (v *NullableGetServerHardwareScanListResult) Set(val *GetServerHardwareScanListResult) { + v.value = val + v.isSet = true +} + +func (v NullableGetServerHardwareScanListResult) IsSet() bool { + return v.isSet +} + +func (v *NullableGetServerHardwareScanListResult) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableGetServerHardwareScanListResult(val *GetServerHardwareScanListResult) *NullableGetServerHardwareScanListResult { + return &NullableGetServerHardwareScanListResult{value: val, isSet: true} +} + +func (v NullableGetServerHardwareScanListResult) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableGetServerHardwareScanListResult) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/bmsdb/model_get_server_hardware_scan_result.go b/bmsdb/model_get_server_hardware_scan_result.go new file mode 100644 index 0000000..0b9c50c --- /dev/null +++ b/bmsdb/model_get_server_hardware_scan_result.go @@ -0,0 +1,273 @@ +/* +bmsdb + +This documents the rest api bmsdb provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package bmsdb + +import ( + "encoding/json" +) + +// checks if the GetServerHardwareScanResult type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &GetServerHardwareScanResult{} + +// GetServerHardwareScanResult Hardware Scan information +type GetServerHardwareScanResult struct { + // Hardware Scan ID + Id *string `json:"id,omitempty"` + ParserVersion *string `json:"parserVersion,omitempty"` + Result *Results `json:"result,omitempty"` + // Date time using the ISO-8601 format + ScannedAt *string `json:"scannedAt,omitempty"` + ServerId *string `json:"serverId,omitempty"` +} + +// NewGetServerHardwareScanResult instantiates a new GetServerHardwareScanResult object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewGetServerHardwareScanResult() *GetServerHardwareScanResult { + this := GetServerHardwareScanResult{} + return &this +} + +// NewGetServerHardwareScanResultWithDefaults instantiates a new GetServerHardwareScanResult object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewGetServerHardwareScanResultWithDefaults() *GetServerHardwareScanResult { + this := GetServerHardwareScanResult{} + return &this +} + +// GetId returns the Id field value if set, zero value otherwise. +func (o *GetServerHardwareScanResult) GetId() string { + if o == nil || IsNil(o.Id) { + var ret string + return ret + } + return *o.Id +} + +// GetIdOk returns a tuple with the Id field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetServerHardwareScanResult) GetIdOk() (*string, bool) { + if o == nil || IsNil(o.Id) { + return nil, false + } + return o.Id, true +} + +// HasId returns a boolean if a field has been set. +func (o *GetServerHardwareScanResult) HasId() bool { + if o != nil && !IsNil(o.Id) { + return true + } + + return false +} + +// SetId gets a reference to the given string and assigns it to the Id field. +func (o *GetServerHardwareScanResult) SetId(v string) { + o.Id = &v +} + +// GetParserVersion returns the ParserVersion field value if set, zero value otherwise. +func (o *GetServerHardwareScanResult) GetParserVersion() string { + if o == nil || IsNil(o.ParserVersion) { + var ret string + return ret + } + return *o.ParserVersion +} + +// GetParserVersionOk returns a tuple with the ParserVersion field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetServerHardwareScanResult) GetParserVersionOk() (*string, bool) { + if o == nil || IsNil(o.ParserVersion) { + return nil, false + } + return o.ParserVersion, true +} + +// HasParserVersion returns a boolean if a field has been set. +func (o *GetServerHardwareScanResult) HasParserVersion() bool { + if o != nil && !IsNil(o.ParserVersion) { + return true + } + + return false +} + +// SetParserVersion gets a reference to the given string and assigns it to the ParserVersion field. +func (o *GetServerHardwareScanResult) SetParserVersion(v string) { + o.ParserVersion = &v +} + +// GetResult returns the Result field value if set, zero value otherwise. +func (o *GetServerHardwareScanResult) GetResult() Results { + if o == nil || IsNil(o.Result) { + var ret Results + return ret + } + return *o.Result +} + +// GetResultOk returns a tuple with the Result field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetServerHardwareScanResult) GetResultOk() (*Results, bool) { + if o == nil || IsNil(o.Result) { + return nil, false + } + return o.Result, true +} + +// HasResult returns a boolean if a field has been set. +func (o *GetServerHardwareScanResult) HasResult() bool { + if o != nil && !IsNil(o.Result) { + return true + } + + return false +} + +// SetResult gets a reference to the given Results and assigns it to the Result field. +func (o *GetServerHardwareScanResult) SetResult(v Results) { + o.Result = &v +} + +// GetScannedAt returns the ScannedAt field value if set, zero value otherwise. +func (o *GetServerHardwareScanResult) GetScannedAt() string { + if o == nil || IsNil(o.ScannedAt) { + var ret string + return ret + } + return *o.ScannedAt +} + +// GetScannedAtOk returns a tuple with the ScannedAt field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetServerHardwareScanResult) GetScannedAtOk() (*string, bool) { + if o == nil || IsNil(o.ScannedAt) { + return nil, false + } + return o.ScannedAt, true +} + +// HasScannedAt returns a boolean if a field has been set. +func (o *GetServerHardwareScanResult) HasScannedAt() bool { + if o != nil && !IsNil(o.ScannedAt) { + return true + } + + return false +} + +// SetScannedAt gets a reference to the given string and assigns it to the ScannedAt field. +func (o *GetServerHardwareScanResult) SetScannedAt(v string) { + o.ScannedAt = &v +} + +// GetServerId returns the ServerId field value if set, zero value otherwise. +func (o *GetServerHardwareScanResult) GetServerId() string { + if o == nil || IsNil(o.ServerId) { + var ret string + return ret + } + return *o.ServerId +} + +// GetServerIdOk returns a tuple with the ServerId field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetServerHardwareScanResult) GetServerIdOk() (*string, bool) { + if o == nil || IsNil(o.ServerId) { + return nil, false + } + return o.ServerId, true +} + +// HasServerId returns a boolean if a field has been set. +func (o *GetServerHardwareScanResult) HasServerId() bool { + if o != nil && !IsNil(o.ServerId) { + return true + } + + return false +} + +// SetServerId gets a reference to the given string and assigns it to the ServerId field. +func (o *GetServerHardwareScanResult) SetServerId(v string) { + o.ServerId = &v +} + +func (o GetServerHardwareScanResult) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o GetServerHardwareScanResult) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Id) { + toSerialize["id"] = o.Id + } + if !IsNil(o.ParserVersion) { + toSerialize["parserVersion"] = o.ParserVersion + } + if !IsNil(o.Result) { + toSerialize["result"] = o.Result + } + if !IsNil(o.ScannedAt) { + toSerialize["scannedAt"] = o.ScannedAt + } + if !IsNil(o.ServerId) { + toSerialize["serverId"] = o.ServerId + } + return toSerialize, nil +} + +type NullableGetServerHardwareScanResult struct { + value *GetServerHardwareScanResult + isSet bool +} + +func (v NullableGetServerHardwareScanResult) Get() *GetServerHardwareScanResult { + return v.value +} + +func (v *NullableGetServerHardwareScanResult) Set(val *GetServerHardwareScanResult) { + v.value = val + v.isSet = true +} + +func (v NullableGetServerHardwareScanResult) IsSet() bool { + return v.isSet +} + +func (v *NullableGetServerHardwareScanResult) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableGetServerHardwareScanResult(val *GetServerHardwareScanResult) *NullableGetServerHardwareScanResult { + return &NullableGetServerHardwareScanResult{value: val, isSet: true} +} + +func (v NullableGetServerHardwareScanResult) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableGetServerHardwareScanResult) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/bmsdb/model_hardware_scan.go b/bmsdb/model_hardware_scan.go new file mode 100644 index 0000000..dfd2930 --- /dev/null +++ b/bmsdb/model_hardware_scan.go @@ -0,0 +1,237 @@ +/* +bmsdb + +This documents the rest api bmsdb provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package bmsdb + +import ( + "encoding/json" +) + +// checks if the HardwareScan type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &HardwareScan{} + +// HardwareScan struct for HardwareScan +type HardwareScan struct { + // Hardware Scan id + Id *string `json:"id,omitempty"` + ParserVersion *string `json:"parserVersion,omitempty"` + // Date time using the ISO-8601 format + ScannedAt *string `json:"scannedAt,omitempty"` + ServerId *string `json:"serverId,omitempty"` +} + +// NewHardwareScan instantiates a new HardwareScan object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewHardwareScan() *HardwareScan { + this := HardwareScan{} + return &this +} + +// NewHardwareScanWithDefaults instantiates a new HardwareScan object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewHardwareScanWithDefaults() *HardwareScan { + this := HardwareScan{} + return &this +} + +// GetId returns the Id field value if set, zero value otherwise. +func (o *HardwareScan) GetId() string { + if o == nil || IsNil(o.Id) { + var ret string + return ret + } + return *o.Id +} + +// GetIdOk returns a tuple with the Id field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *HardwareScan) GetIdOk() (*string, bool) { + if o == nil || IsNil(o.Id) { + return nil, false + } + return o.Id, true +} + +// HasId returns a boolean if a field has been set. +func (o *HardwareScan) HasId() bool { + if o != nil && !IsNil(o.Id) { + return true + } + + return false +} + +// SetId gets a reference to the given string and assigns it to the Id field. +func (o *HardwareScan) SetId(v string) { + o.Id = &v +} + +// GetParserVersion returns the ParserVersion field value if set, zero value otherwise. +func (o *HardwareScan) GetParserVersion() string { + if o == nil || IsNil(o.ParserVersion) { + var ret string + return ret + } + return *o.ParserVersion +} + +// GetParserVersionOk returns a tuple with the ParserVersion field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *HardwareScan) GetParserVersionOk() (*string, bool) { + if o == nil || IsNil(o.ParserVersion) { + return nil, false + } + return o.ParserVersion, true +} + +// HasParserVersion returns a boolean if a field has been set. +func (o *HardwareScan) HasParserVersion() bool { + if o != nil && !IsNil(o.ParserVersion) { + return true + } + + return false +} + +// SetParserVersion gets a reference to the given string and assigns it to the ParserVersion field. +func (o *HardwareScan) SetParserVersion(v string) { + o.ParserVersion = &v +} + +// GetScannedAt returns the ScannedAt field value if set, zero value otherwise. +func (o *HardwareScan) GetScannedAt() string { + if o == nil || IsNil(o.ScannedAt) { + var ret string + return ret + } + return *o.ScannedAt +} + +// GetScannedAtOk returns a tuple with the ScannedAt field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *HardwareScan) GetScannedAtOk() (*string, bool) { + if o == nil || IsNil(o.ScannedAt) { + return nil, false + } + return o.ScannedAt, true +} + +// HasScannedAt returns a boolean if a field has been set. +func (o *HardwareScan) HasScannedAt() bool { + if o != nil && !IsNil(o.ScannedAt) { + return true + } + + return false +} + +// SetScannedAt gets a reference to the given string and assigns it to the ScannedAt field. +func (o *HardwareScan) SetScannedAt(v string) { + o.ScannedAt = &v +} + +// GetServerId returns the ServerId field value if set, zero value otherwise. +func (o *HardwareScan) GetServerId() string { + if o == nil || IsNil(o.ServerId) { + var ret string + return ret + } + return *o.ServerId +} + +// GetServerIdOk returns a tuple with the ServerId field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *HardwareScan) GetServerIdOk() (*string, bool) { + if o == nil || IsNil(o.ServerId) { + return nil, false + } + return o.ServerId, true +} + +// HasServerId returns a boolean if a field has been set. +func (o *HardwareScan) HasServerId() bool { + if o != nil && !IsNil(o.ServerId) { + return true + } + + return false +} + +// SetServerId gets a reference to the given string and assigns it to the ServerId field. +func (o *HardwareScan) SetServerId(v string) { + o.ServerId = &v +} + +func (o HardwareScan) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o HardwareScan) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Id) { + toSerialize["id"] = o.Id + } + if !IsNil(o.ParserVersion) { + toSerialize["parserVersion"] = o.ParserVersion + } + if !IsNil(o.ScannedAt) { + toSerialize["scannedAt"] = o.ScannedAt + } + if !IsNil(o.ServerId) { + toSerialize["serverId"] = o.ServerId + } + return toSerialize, nil +} + +type NullableHardwareScan struct { + value *HardwareScan + isSet bool +} + +func (v NullableHardwareScan) Get() *HardwareScan { + return v.value +} + +func (v *NullableHardwareScan) Set(val *HardwareScan) { + v.value = val + v.isSet = true +} + +func (v NullableHardwareScan) IsSet() bool { + return v.isSet +} + +func (v *NullableHardwareScan) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableHardwareScan(val *HardwareScan) *NullableHardwareScan { + return &NullableHardwareScan{value: val, isSet: true} +} + +func (v NullableHardwareScan) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableHardwareScan) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/bmsdb/model_results.go b/bmsdb/model_results.go new file mode 100644 index 0000000..600f047 --- /dev/null +++ b/bmsdb/model_results.go @@ -0,0 +1,307 @@ +/* +bmsdb + +This documents the rest api bmsdb provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package bmsdb + +import ( + "encoding/json" +) + +// checks if the Results type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &Results{} + +// Results Hardware Scan results +type Results struct { + Chassis map[string]interface{} `json:"chassis,omitempty"` + Cpu []map[string]interface{} `json:"cpu,omitempty"` + Disks []map[string]interface{} `json:"disks,omitempty"` + Ipmi map[string]interface{} `json:"ipmi,omitempty"` + Memory []map[string]interface{} `json:"memory,omitempty"` + Network []map[string]interface{} `json:"network,omitempty"` +} + +// NewResults instantiates a new Results object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewResults() *Results { + this := Results{} + return &this +} + +// NewResultsWithDefaults instantiates a new Results object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewResultsWithDefaults() *Results { + this := Results{} + return &this +} + +// GetChassis returns the Chassis field value if set, zero value otherwise. +func (o *Results) GetChassis() map[string]interface{} { + if o == nil || IsNil(o.Chassis) { + var ret map[string]interface{} + return ret + } + return o.Chassis +} + +// GetChassisOk returns a tuple with the Chassis field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Results) GetChassisOk() (map[string]interface{}, bool) { + if o == nil || IsNil(o.Chassis) { + return map[string]interface{}{}, false + } + return o.Chassis, true +} + +// HasChassis returns a boolean if a field has been set. +func (o *Results) HasChassis() bool { + if o != nil && !IsNil(o.Chassis) { + return true + } + + return false +} + +// SetChassis gets a reference to the given map[string]interface{} and assigns it to the Chassis field. +func (o *Results) SetChassis(v map[string]interface{}) { + o.Chassis = v +} + +// GetCpu returns the Cpu field value if set, zero value otherwise. +func (o *Results) GetCpu() []map[string]interface{} { + if o == nil || IsNil(o.Cpu) { + var ret []map[string]interface{} + return ret + } + return o.Cpu +} + +// GetCpuOk returns a tuple with the Cpu field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Results) GetCpuOk() ([]map[string]interface{}, bool) { + if o == nil || IsNil(o.Cpu) { + return nil, false + } + return o.Cpu, true +} + +// HasCpu returns a boolean if a field has been set. +func (o *Results) HasCpu() bool { + if o != nil && !IsNil(o.Cpu) { + return true + } + + return false +} + +// SetCpu gets a reference to the given []map[string]interface{} and assigns it to the Cpu field. +func (o *Results) SetCpu(v []map[string]interface{}) { + o.Cpu = v +} + +// GetDisks returns the Disks field value if set, zero value otherwise. +func (o *Results) GetDisks() []map[string]interface{} { + if o == nil || IsNil(o.Disks) { + var ret []map[string]interface{} + return ret + } + return o.Disks +} + +// GetDisksOk returns a tuple with the Disks field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Results) GetDisksOk() ([]map[string]interface{}, bool) { + if o == nil || IsNil(o.Disks) { + return nil, false + } + return o.Disks, true +} + +// HasDisks returns a boolean if a field has been set. +func (o *Results) HasDisks() bool { + if o != nil && !IsNil(o.Disks) { + return true + } + + return false +} + +// SetDisks gets a reference to the given []map[string]interface{} and assigns it to the Disks field. +func (o *Results) SetDisks(v []map[string]interface{}) { + o.Disks = v +} + +// GetIpmi returns the Ipmi field value if set, zero value otherwise. +func (o *Results) GetIpmi() map[string]interface{} { + if o == nil || IsNil(o.Ipmi) { + var ret map[string]interface{} + return ret + } + return o.Ipmi +} + +// GetIpmiOk returns a tuple with the Ipmi field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Results) GetIpmiOk() (map[string]interface{}, bool) { + if o == nil || IsNil(o.Ipmi) { + return map[string]interface{}{}, false + } + return o.Ipmi, true +} + +// HasIpmi returns a boolean if a field has been set. +func (o *Results) HasIpmi() bool { + if o != nil && !IsNil(o.Ipmi) { + return true + } + + return false +} + +// SetIpmi gets a reference to the given map[string]interface{} and assigns it to the Ipmi field. +func (o *Results) SetIpmi(v map[string]interface{}) { + o.Ipmi = v +} + +// GetMemory returns the Memory field value if set, zero value otherwise. +func (o *Results) GetMemory() []map[string]interface{} { + if o == nil || IsNil(o.Memory) { + var ret []map[string]interface{} + return ret + } + return o.Memory +} + +// GetMemoryOk returns a tuple with the Memory field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Results) GetMemoryOk() ([]map[string]interface{}, bool) { + if o == nil || IsNil(o.Memory) { + return nil, false + } + return o.Memory, true +} + +// HasMemory returns a boolean if a field has been set. +func (o *Results) HasMemory() bool { + if o != nil && !IsNil(o.Memory) { + return true + } + + return false +} + +// SetMemory gets a reference to the given []map[string]interface{} and assigns it to the Memory field. +func (o *Results) SetMemory(v []map[string]interface{}) { + o.Memory = v +} + +// GetNetwork returns the Network field value if set, zero value otherwise. +func (o *Results) GetNetwork() []map[string]interface{} { + if o == nil || IsNil(o.Network) { + var ret []map[string]interface{} + return ret + } + return o.Network +} + +// GetNetworkOk returns a tuple with the Network field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Results) GetNetworkOk() ([]map[string]interface{}, bool) { + if o == nil || IsNil(o.Network) { + return nil, false + } + return o.Network, true +} + +// HasNetwork returns a boolean if a field has been set. +func (o *Results) HasNetwork() bool { + if o != nil && !IsNil(o.Network) { + return true + } + + return false +} + +// SetNetwork gets a reference to the given []map[string]interface{} and assigns it to the Network field. +func (o *Results) SetNetwork(v []map[string]interface{}) { + o.Network = v +} + +func (o Results) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o Results) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Chassis) { + toSerialize["chassis"] = o.Chassis + } + if !IsNil(o.Cpu) { + toSerialize["cpu"] = o.Cpu + } + if !IsNil(o.Disks) { + toSerialize["disks"] = o.Disks + } + if !IsNil(o.Ipmi) { + toSerialize["ipmi"] = o.Ipmi + } + if !IsNil(o.Memory) { + toSerialize["memory"] = o.Memory + } + if !IsNil(o.Network) { + toSerialize["network"] = o.Network + } + return toSerialize, nil +} + +type NullableResults struct { + value *Results + isSet bool +} + +func (v NullableResults) Get() *Results { + return v.value +} + +func (v *NullableResults) Set(val *Results) { + v.value = val + v.isSet = true +} + +func (v NullableResults) IsSet() bool { + return v.isSet +} + +func (v *NullableResults) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableResults(val *Results) *NullableResults { + return &NullableResults{value: val, isSet: true} +} + +func (v NullableResults) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableResults) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/bmsdb/response.go b/bmsdb/response.go new file mode 100644 index 0000000..bd35a79 --- /dev/null +++ b/bmsdb/response.go @@ -0,0 +1,48 @@ +/* +bmsdb + +This documents the rest api bmsdb provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package bmsdb + +import ( + "net/http" +) + +// APIResponse stores the API response returned by the server. +type APIResponse struct { + *http.Response `json:"-"` + Message string `json:"message,omitempty"` + // Operation is the name of the OpenAPI operation. + Operation string `json:"operation,omitempty"` + // RequestURL is the request URL. This value is always available, even if the + // embedded *http.Response is nil. + RequestURL string `json:"url,omitempty"` + // Method is the HTTP method used for the request. This value is always + // available, even if the embedded *http.Response is nil. + Method string `json:"method,omitempty"` + // Payload holds the contents of the response body (which may be nil or empty). + // This is provided here as the raw response.Body() reader will have already + // been drained. + Payload []byte `json:"-"` +} + +// NewAPIResponse returns a new APIResponse object. +func NewAPIResponse(r *http.Response) *APIResponse { + + response := &APIResponse{Response: r} + return response +} + +// NewAPIResponseWithError returns a new APIResponse object with the provided error message. +func NewAPIResponseWithError(errorMessage string) *APIResponse { + + response := &APIResponse{Message: errorMessage} + return response +} diff --git a/bmsdb/test/api_bmsdb_test.go b/bmsdb/test/api_bmsdb_test.go new file mode 100644 index 0000000..fe5ec8f --- /dev/null +++ b/bmsdb/test/api_bmsdb_test.go @@ -0,0 +1,68 @@ +/* +bmsdb + +Testing BmsdbAPIService + +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); + +package bmsdb + +import ( + "context" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "testing" + openapiclient "github.com/leaseweb/leaseweb-go-sdk/bmsdb" +) + +func Test_bmsdb_BmsdbAPIService(t *testing.T) { + + configuration := openapiclient.NewConfiguration() + apiClient := openapiclient.NewAPIClient(configuration) + + t.Run("Test BmsdbAPIService GetServerHardware", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var serverId string + + resp, httpRes, err := apiClient.BmsdbAPI.GetServerHardware(context.Background(), serverId).Execute() + + require.Nil(t, err) + require.NotNil(t, resp) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test BmsdbAPIService GetServerHardwareScan", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var serverId string + var hardwareScanId string + + resp, httpRes, err := apiClient.BmsdbAPI.GetServerHardwareScan(context.Background(), serverId, hardwareScanId).Execute() + + require.Nil(t, err) + require.NotNil(t, resp) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test BmsdbAPIService ServersHardwarescansList", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var serverId string + + resp, httpRes, err := apiClient.BmsdbAPI.ServersHardwarescansList(context.Background(), serverId).Execute() + + require.Nil(t, err) + require.NotNil(t, resp) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + +} diff --git a/bmsdb/utils.go b/bmsdb/utils.go new file mode 100644 index 0000000..fd51566 --- /dev/null +++ b/bmsdb/utils.go @@ -0,0 +1,348 @@ +/* +bmsdb + +This documents the rest api bmsdb provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package bmsdb + +import ( + "encoding/json" + "reflect" + "time" +) + +// PtrBool is a helper routine that returns a pointer to given boolean value. +func PtrBool(v bool) *bool { return &v } + +// PtrInt is a helper routine that returns a pointer to given integer value. +func PtrInt(v int) *int { return &v } + +// PtrInt32 is a helper routine that returns a pointer to given integer value. +func PtrInt32(v int32) *int32 { return &v } + +// PtrInt64 is a helper routine that returns a pointer to given integer value. +func PtrInt64(v int64) *int64 { return &v } + +// PtrFloat32 is a helper routine that returns a pointer to given float value. +func PtrFloat32(v float32) *float32 { return &v } + +// PtrFloat64 is a helper routine that returns a pointer to given float value. +func PtrFloat64(v float64) *float64 { return &v } + +// PtrString is a helper routine that returns a pointer to given string value. +func PtrString(v string) *string { return &v } + +// PtrTime is helper routine that returns a pointer to given Time value. +func PtrTime(v time.Time) *time.Time { return &v } + +type NullableBool struct { + value *bool + isSet bool +} + +func (v NullableBool) Get() *bool { + return v.value +} + +func (v *NullableBool) Set(val *bool) { + v.value = val + v.isSet = true +} + +func (v NullableBool) IsSet() bool { + return v.isSet +} + +func (v *NullableBool) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableBool(val *bool) *NullableBool { + return &NullableBool{value: val, isSet: true} +} + +func (v NullableBool) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableBool) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + +type NullableInt struct { + value *int + isSet bool +} + +func (v NullableInt) Get() *int { + return v.value +} + +func (v *NullableInt) Set(val *int) { + v.value = val + v.isSet = true +} + +func (v NullableInt) IsSet() bool { + return v.isSet +} + +func (v *NullableInt) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableInt(val *int) *NullableInt { + return &NullableInt{value: val, isSet: true} +} + +func (v NullableInt) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableInt) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + +type NullableInt32 struct { + value *int32 + isSet bool +} + +func (v NullableInt32) Get() *int32 { + return v.value +} + +func (v *NullableInt32) Set(val *int32) { + v.value = val + v.isSet = true +} + +func (v NullableInt32) IsSet() bool { + return v.isSet +} + +func (v *NullableInt32) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableInt32(val *int32) *NullableInt32 { + return &NullableInt32{value: val, isSet: true} +} + +func (v NullableInt32) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableInt32) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + +type NullableInt64 struct { + value *int64 + isSet bool +} + +func (v NullableInt64) Get() *int64 { + return v.value +} + +func (v *NullableInt64) Set(val *int64) { + v.value = val + v.isSet = true +} + +func (v NullableInt64) IsSet() bool { + return v.isSet +} + +func (v *NullableInt64) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableInt64(val *int64) *NullableInt64 { + return &NullableInt64{value: val, isSet: true} +} + +func (v NullableInt64) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableInt64) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + +type NullableFloat32 struct { + value *float32 + isSet bool +} + +func (v NullableFloat32) Get() *float32 { + return v.value +} + +func (v *NullableFloat32) Set(val *float32) { + v.value = val + v.isSet = true +} + +func (v NullableFloat32) IsSet() bool { + return v.isSet +} + +func (v *NullableFloat32) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableFloat32(val *float32) *NullableFloat32 { + return &NullableFloat32{value: val, isSet: true} +} + +func (v NullableFloat32) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableFloat32) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + +type NullableFloat64 struct { + value *float64 + isSet bool +} + +func (v NullableFloat64) Get() *float64 { + return v.value +} + +func (v *NullableFloat64) Set(val *float64) { + v.value = val + v.isSet = true +} + +func (v NullableFloat64) IsSet() bool { + return v.isSet +} + +func (v *NullableFloat64) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableFloat64(val *float64) *NullableFloat64 { + return &NullableFloat64{value: val, isSet: true} +} + +func (v NullableFloat64) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableFloat64) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + +type NullableString struct { + value *string + isSet bool +} + +func (v NullableString) Get() *string { + return v.value +} + +func (v *NullableString) Set(val *string) { + v.value = val + v.isSet = true +} + +func (v NullableString) IsSet() bool { + return v.isSet +} + +func (v *NullableString) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableString(val *string) *NullableString { + return &NullableString{value: val, isSet: true} +} + +func (v NullableString) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableString) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + +type NullableTime struct { + value *time.Time + isSet bool +} + +func (v NullableTime) Get() *time.Time { + return v.value +} + +func (v *NullableTime) Set(val *time.Time) { + v.value = val + v.isSet = true +} + +func (v NullableTime) IsSet() bool { + return v.isSet +} + +func (v *NullableTime) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableTime(val *time.Time) *NullableTime { + return &NullableTime{value: val, isSet: true} +} + +func (v NullableTime) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableTime) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + +// IsNil checks if an input is nil +func IsNil(i interface{}) bool { + if i == nil { + return true + } + switch reflect.TypeOf(i).Kind() { + case reflect.Chan, reflect.Func, reflect.Map, reflect.Ptr, reflect.UnsafePointer, reflect.Interface, reflect.Slice: + return reflect.ValueOf(i).IsNil() + case reflect.Array: + return reflect.ValueOf(i).IsZero() + } + return false +} + +type MappedNullable interface { + ToMap() (map[string]interface{}, error) +} diff --git a/bmusage/README.md b/bmusage/README.md new file mode 100644 index 0000000..4172f90 --- /dev/null +++ b/bmusage/README.md @@ -0,0 +1,198 @@ +# Go API client for bmusage + +This documents the rest api bmusage api provides. + +## Overview +This API client was generated by the [OpenAPI Generator](https://openapi-generator.tech) project. By using the [OpenAPI-spec](https://www.openapis.org/) from a remote server, you can easily generate an API client. + +- API version: v2 +- Package version: 1.0.0 +- Generator version: 7.4.0 +- Build package: org.openapitools.codegen.languages.GoClientCodegen + +## Installation + +Install the following dependencies: + +```sh +go get github.com/stretchr/testify/assert +go get golang.org/x/oauth2 +go get golang.org/x/net/context +``` + +Put the package under your project folder and add the following in import: + +```go +import bmusage "github.com/leaseweb/leaseweb-go-sdk/bmusage" +``` + +To use a proxy, set the environment variable `HTTP_PROXY`: + +```go +os.Setenv("HTTP_PROXY", "http://proxy_name:proxy_port") +``` + +## Configuration of Server URL + +Default configuration comes with `Servers` field that contains server objects as defined in the OpenAPI specification. + +### Select Server Configuration + +For using other server than the one defined on index 0 set context value `bmusage.ContextServerIndex` of type `int`. + +```go +ctx := context.WithValue(context.Background(), bmusage.ContextServerIndex, 1) +``` + +### Templated Server URL + +Templated server URL is formatted using default variables from configuration or from context value `bmusage.ContextServerVariables` of type `map[string]string`. + +```go +ctx := context.WithValue(context.Background(), bmusage.ContextServerVariables, map[string]string{ + "basePath": "v2", +}) +``` + +Note, enum values are always validated and all unused variables are silently ignored. + +### URLs Configuration per Operation + +Each operation can use different server URL defined using `OperationServers` map in the `Configuration`. +An operation is uniquely identified by `"{classname}Service.{nickname}"` string. +Similar rules for overriding default operation server index and variables applies by using `bmusage.ContextOperationServerIndices` and `bmusage.ContextOperationServerVariables` context maps. + +```go +ctx := context.WithValue(context.Background(), bmusage.ContextOperationServerIndices, map[string]int{ + "{classname}Service.{nickname}": 2, +}) +ctx = context.WithValue(context.Background(), bmusage.ContextOperationServerVariables, map[string]map[string]string{ + "{classname}Service.{nickname}": { + "port": "8443", + }, +}) +``` + +## Documentation for API Endpoints + +All URIs are relative to *https://api.leaseweb.com/internal/bmusageapi/v2* + +Class | Method | HTTP request | Description +------------ | ------------- | ------------- | ------------- +*BmusageAPI* | [**CreateServerBandwidthNotificationSettingJson**](docs/BmusageAPI.md#createserverbandwidthnotificationsettingjson) | **Post** /servers/{serverId}/notificationSettings/bandwidth | Create a bandwidth notification setting +*BmusageAPI* | [**CreateServerDataTrafficNotificationSetting**](docs/BmusageAPI.md#createserverdatatrafficnotificationsetting) | **Post** /servers/{serverId}/notificationSettings/datatraffic | Create a data traffic notification setting +*BmusageAPI* | [**DeleteServerBandwidthNotificationSetting**](docs/BmusageAPI.md#deleteserverbandwidthnotificationsetting) | **Delete** /servers/{serverId}/notificationSettings/bandwidth/{notificationSettingId} | Delete a bandwidth notification setting +*BmusageAPI* | [**DeleteServerDataTrafficNotificationSetting**](docs/BmusageAPI.md#deleteserverdatatrafficnotificationsetting) | **Delete** /servers/{serverId}/notificationSettings/datatraffic/{notificationSettingId} | Delete a data traffic notification setting +*BmusageAPI* | [**GetServerBandwidthNotificationSetting**](docs/BmusageAPI.md#getserverbandwidthnotificationsetting) | **Get** /servers/{serverId}/notificationSettings/bandwidth/{notificationSettingId} | Show a bandwidth notification setting +*BmusageAPI* | [**GetServerBandwidthNotificationSettingList**](docs/BmusageAPI.md#getserverbandwidthnotificationsettinglist) | **Get** /servers/{serverId}/notificationSettings/bandwidth | List bandwidth notification settings +*BmusageAPI* | [**GetServerDataTrafficMetrics**](docs/BmusageAPI.md#getserverdatatrafficmetrics) | **Get** /servers/{serverId}/metrics/datatraffic | Show datatraffic metrics +*BmusageAPI* | [**GetServerDataTrafficNotificationSetting**](docs/BmusageAPI.md#getserverdatatrafficnotificationsetting) | **Get** /servers/{serverId}/notificationSettings/datatraffic/{notificationSettingId} | Show a data traffic notification setting +*BmusageAPI* | [**GetServerDataTrafficNotificationSettingList**](docs/BmusageAPI.md#getserverdatatrafficnotificationsettinglist) | **Get** /servers/{serverId}/notificationSettings/datatraffic | List data traffic notification settings +*BmusageAPI* | [**ServersMetricsBandwidth**](docs/BmusageAPI.md#serversmetricsbandwidth) | **Get** /servers/{serverId}/metrics/bandwidth | Show bandwidth metrics +*BmusageAPI* | [**UpdateServerBandwidthNotificationSetting**](docs/BmusageAPI.md#updateserverbandwidthnotificationsetting) | **Put** /servers/{serverId}/notificationSettings/bandwidth/{notificationSettingId} | Update a bandwidth notification setting +*BmusageAPI* | [**UpdateServerDataTrafficNotificationSetting**](docs/BmusageAPI.md#updateserverdatatrafficnotificationsetting) | **Put** /servers/{serverId}/notificationSettings/datatraffic/{notificationSettingId} | Update a data traffic notification setting + + +## Documentation For Models + + - [Actions](docs/Actions.md) + - [BandwidthNotificationSetting](docs/BandwidthNotificationSetting.md) + - [BandwidthNotificationSettingOpts](docs/BandwidthNotificationSettingOpts.md) + - [DataTrafficNotificationSetting](docs/DataTrafficNotificationSetting.md) + - [DataTrafficNotificationSettingOpts](docs/DataTrafficNotificationSettingOpts.md) + - [ErrorResult](docs/ErrorResult.md) + - [GetServerBandwidthNotificationSettingListResult](docs/GetServerBandwidthNotificationSettingListResult.md) + - [GetServerDataTrafficNotificationSettingListResult](docs/GetServerDataTrafficNotificationSettingListResult.md) + - [Metadata](docs/Metadata.md) + - [Metric](docs/Metric.md) + - [MetricValue](docs/MetricValue.md) + - [MetricValues](docs/MetricValues.md) + - [Metrics](docs/Metrics.md) + - [MetricsMetadata](docs/MetricsMetadata.md) + - [NotificationSetting](docs/NotificationSetting.md) + + +## Documentation For Authorization + + +Authentication schemes defined for the API: +### ApiKeyAuth + +- **Type**: API key +- **API key parameter name**: X-LSW-Auth +- **Location**: HTTP header + +Note, each API key must be added to a map of `map[string]APIKey` where the key is: X-LSW-Auth and passed in as the auth context for each request. + +Example + +```go +auth := context.WithValue( + context.Background(), + bmusage.ContextAPIKeys, + map[string]bmusage.APIKey{ + "X-LSW-Auth": {Key: "API_KEY_STRING"}, + }, + ) +r, err := client.Service.Operation(auth, args) +``` + +### OAuth2 + + +- **Type**: OAuth +- **Flow**: application +- **Authorization URL**: +- **Scopes**: N/A + +Example + +```go +auth := context.WithValue(context.Background(), bmusage.ContextAccessToken, "ACCESSTOKENSTRING") +r, err := client.Service.Operation(auth, args) +``` + +Or via OAuth2 module to automatically refresh tokens and perform user authentication. + +```go +import "golang.org/x/oauth2" + +/* Perform OAuth2 round trip request and obtain a token */ + +tokenSource := oauth2cfg.TokenSource(createContext(httpClient), &token) +auth := context.WithValue(oauth2.NoContext, bmusage.ContextOAuth2, tokenSource) +r, err := client.Service.Operation(auth, args) +``` + +### BearerAuth + +- **Type**: HTTP Bearer token authentication + +Example + +```go +auth := context.WithValue(context.Background(), bmusage.ContextAccessToken, "BEARER_TOKEN_STRING") +r, err := client.Service.Operation(auth, args) +``` + + +## Documentation for Utility Methods + +Due to the fact that model structure members are all pointers, this package contains +a number of utility functions to easily obtain pointers to values of basic types. +Each of these functions takes a value of the given basic type and returns a pointer to it: + +* `PtrBool` +* `PtrInt` +* `PtrInt32` +* `PtrInt64` +* `PtrFloat` +* `PtrFloat32` +* `PtrFloat64` +* `PtrString` +* `PtrTime` + +## Author + +development-networkautomation@leaseweb.com + diff --git a/bmusage/api_bmusage.go b/bmusage/api_bmusage.go new file mode 100644 index 0000000..4778756 --- /dev/null +++ b/bmusage/api_bmusage.go @@ -0,0 +1,2250 @@ +/* +bmusage + +This documents the rest api bmusage api provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package bmusage + +import ( + "bytes" + "context" + "io" + "net/http" + "net/url" + "strings" + "time" +) + + +// BmusageAPIService BmusageAPI service +type BmusageAPIService service + +type ApiCreateServerBandwidthNotificationSettingJsonRequest struct { + ctx context.Context + ApiService *BmusageAPIService + serverId string + bandwidthNotificationSettingOpts *BandwidthNotificationSettingOpts +} + +func (r ApiCreateServerBandwidthNotificationSettingJsonRequest) BandwidthNotificationSettingOpts(bandwidthNotificationSettingOpts BandwidthNotificationSettingOpts) ApiCreateServerBandwidthNotificationSettingJsonRequest { + r.bandwidthNotificationSettingOpts = &bandwidthNotificationSettingOpts + return r +} + +func (r ApiCreateServerBandwidthNotificationSettingJsonRequest) Execute() (*BandwidthNotificationSetting, *http.Response, error) { + return r.ApiService.CreateServerBandwidthNotificationSettingJsonExecute(r) +} + +/* +CreateServerBandwidthNotificationSettingJson Create a bandwidth notification setting + +Create a new bandwidth notification setting for this server. + + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param serverId The ID of a server + @return ApiCreateServerBandwidthNotificationSettingJsonRequest +*/ +func (a *BmusageAPIService) CreateServerBandwidthNotificationSettingJson(ctx context.Context, serverId string) ApiCreateServerBandwidthNotificationSettingJsonRequest { + return ApiCreateServerBandwidthNotificationSettingJsonRequest{ + ApiService: a, + ctx: ctx, + serverId: serverId, + } +} + +// Execute executes the request +// @return BandwidthNotificationSetting +func (a *BmusageAPIService) CreateServerBandwidthNotificationSettingJsonExecute(r ApiCreateServerBandwidthNotificationSettingJsonRequest) (*BandwidthNotificationSetting, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodPost + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *BandwidthNotificationSetting + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "BmusageAPIService.CreateServerBandwidthNotificationSettingJson") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/servers/{serverId}/notificationSettings/bandwidth" + localVarPath = strings.Replace(localVarPath, "{"+"serverId"+"}", url.PathEscape(parameterValueToString(r.serverId, "serverId")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{"application/json"} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + // body params + localVarPostBody = r.bandwidthNotificationSettingOpts + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiCreateServerDataTrafficNotificationSettingRequest struct { + ctx context.Context + ApiService *BmusageAPIService + serverId string + dataTrafficNotificationSettingOpts *DataTrafficNotificationSettingOpts +} + +func (r ApiCreateServerDataTrafficNotificationSettingRequest) DataTrafficNotificationSettingOpts(dataTrafficNotificationSettingOpts DataTrafficNotificationSettingOpts) ApiCreateServerDataTrafficNotificationSettingRequest { + r.dataTrafficNotificationSettingOpts = &dataTrafficNotificationSettingOpts + return r +} + +func (r ApiCreateServerDataTrafficNotificationSettingRequest) Execute() (*DataTrafficNotificationSetting, *http.Response, error) { + return r.ApiService.CreateServerDataTrafficNotificationSettingExecute(r) +} + +/* +CreateServerDataTrafficNotificationSetting Create a data traffic notification setting + +Create a new data traffic notification setting for this server. + + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param serverId The ID of a server + @return ApiCreateServerDataTrafficNotificationSettingRequest +*/ +func (a *BmusageAPIService) CreateServerDataTrafficNotificationSetting(ctx context.Context, serverId string) ApiCreateServerDataTrafficNotificationSettingRequest { + return ApiCreateServerDataTrafficNotificationSettingRequest{ + ApiService: a, + ctx: ctx, + serverId: serverId, + } +} + +// Execute executes the request +// @return DataTrafficNotificationSetting +func (a *BmusageAPIService) CreateServerDataTrafficNotificationSettingExecute(r ApiCreateServerDataTrafficNotificationSettingRequest) (*DataTrafficNotificationSetting, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodPost + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *DataTrafficNotificationSetting + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "BmusageAPIService.CreateServerDataTrafficNotificationSetting") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/servers/{serverId}/notificationSettings/datatraffic" + localVarPath = strings.Replace(localVarPath, "{"+"serverId"+"}", url.PathEscape(parameterValueToString(r.serverId, "serverId")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{"application/json"} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + // body params + localVarPostBody = r.dataTrafficNotificationSettingOpts + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiDeleteServerBandwidthNotificationSettingRequest struct { + ctx context.Context + ApiService *BmusageAPIService + serverId string + notificationSettingId string +} + +func (r ApiDeleteServerBandwidthNotificationSettingRequest) Execute() (*http.Response, error) { + return r.ApiService.DeleteServerBandwidthNotificationSettingExecute(r) +} + +/* +DeleteServerBandwidthNotificationSetting Delete a bandwidth notification setting + +Remove a Bandwidth Notification setting for this server. + + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param serverId The ID of a server + @param notificationSettingId The ID of a notification setting + @return ApiDeleteServerBandwidthNotificationSettingRequest +*/ +func (a *BmusageAPIService) DeleteServerBandwidthNotificationSetting(ctx context.Context, serverId string, notificationSettingId string) ApiDeleteServerBandwidthNotificationSettingRequest { + return ApiDeleteServerBandwidthNotificationSettingRequest{ + ApiService: a, + ctx: ctx, + serverId: serverId, + notificationSettingId: notificationSettingId, + } +} + +// Execute executes the request +func (a *BmusageAPIService) DeleteServerBandwidthNotificationSettingExecute(r ApiDeleteServerBandwidthNotificationSettingRequest) (*http.Response, error) { + var ( + localVarHTTPMethod = http.MethodDelete + localVarPostBody interface{} + formFiles []formFile + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "BmusageAPIService.DeleteServerBandwidthNotificationSetting") + if err != nil { + return nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/servers/{serverId}/notificationSettings/bandwidth/{notificationSettingId}" + localVarPath = strings.Replace(localVarPath, "{"+"serverId"+"}", url.PathEscape(parameterValueToString(r.serverId, "serverId")), -1) + localVarPath = strings.Replace(localVarPath, "{"+"notificationSettingId"+"}", url.PathEscape(parameterValueToString(r.notificationSettingId, "notificationSettingId")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarHTTPResponse, newErr + } + + return localVarHTTPResponse, nil +} + +type ApiDeleteServerDataTrafficNotificationSettingRequest struct { + ctx context.Context + ApiService *BmusageAPIService + serverId string + notificationSettingId string +} + +func (r ApiDeleteServerDataTrafficNotificationSettingRequest) Execute() (*http.Response, error) { + return r.ApiService.DeleteServerDataTrafficNotificationSettingExecute(r) +} + +/* +DeleteServerDataTrafficNotificationSetting Delete a data traffic notification setting + +Delete the given data traffic notification setting for this server. + + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param serverId The ID of a server + @param notificationSettingId The ID of a notification setting + @return ApiDeleteServerDataTrafficNotificationSettingRequest +*/ +func (a *BmusageAPIService) DeleteServerDataTrafficNotificationSetting(ctx context.Context, serverId string, notificationSettingId string) ApiDeleteServerDataTrafficNotificationSettingRequest { + return ApiDeleteServerDataTrafficNotificationSettingRequest{ + ApiService: a, + ctx: ctx, + serverId: serverId, + notificationSettingId: notificationSettingId, + } +} + +// Execute executes the request +func (a *BmusageAPIService) DeleteServerDataTrafficNotificationSettingExecute(r ApiDeleteServerDataTrafficNotificationSettingRequest) (*http.Response, error) { + var ( + localVarHTTPMethod = http.MethodDelete + localVarPostBody interface{} + formFiles []formFile + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "BmusageAPIService.DeleteServerDataTrafficNotificationSetting") + if err != nil { + return nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/servers/{serverId}/notificationSettings/datatraffic/{notificationSettingId}" + localVarPath = strings.Replace(localVarPath, "{"+"serverId"+"}", url.PathEscape(parameterValueToString(r.serverId, "serverId")), -1) + localVarPath = strings.Replace(localVarPath, "{"+"notificationSettingId"+"}", url.PathEscape(parameterValueToString(r.notificationSettingId, "notificationSettingId")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarHTTPResponse, newErr + } + + return localVarHTTPResponse, nil +} + +type ApiGetServerBandwidthNotificationSettingRequest struct { + ctx context.Context + ApiService *BmusageAPIService + serverId string + notificationSettingId string +} + +func (r ApiGetServerBandwidthNotificationSettingRequest) Execute() (*BandwidthNotificationSetting, *http.Response, error) { + return r.ApiService.GetServerBandwidthNotificationSettingExecute(r) +} + +/* +GetServerBandwidthNotificationSetting Show a bandwidth notification setting + +Get a bandwidth notification setting for this server. + + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param serverId The ID of a server + @param notificationSettingId The ID of a notification setting + @return ApiGetServerBandwidthNotificationSettingRequest +*/ +func (a *BmusageAPIService) GetServerBandwidthNotificationSetting(ctx context.Context, serverId string, notificationSettingId string) ApiGetServerBandwidthNotificationSettingRequest { + return ApiGetServerBandwidthNotificationSettingRequest{ + ApiService: a, + ctx: ctx, + serverId: serverId, + notificationSettingId: notificationSettingId, + } +} + +// Execute executes the request +// @return BandwidthNotificationSetting +func (a *BmusageAPIService) GetServerBandwidthNotificationSettingExecute(r ApiGetServerBandwidthNotificationSettingRequest) (*BandwidthNotificationSetting, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodGet + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *BandwidthNotificationSetting + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "BmusageAPIService.GetServerBandwidthNotificationSetting") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/servers/{serverId}/notificationSettings/bandwidth/{notificationSettingId}" + localVarPath = strings.Replace(localVarPath, "{"+"serverId"+"}", url.PathEscape(parameterValueToString(r.serverId, "serverId")), -1) + localVarPath = strings.Replace(localVarPath, "{"+"notificationSettingId"+"}", url.PathEscape(parameterValueToString(r.notificationSettingId, "notificationSettingId")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiGetServerBandwidthNotificationSettingListRequest struct { + ctx context.Context + ApiService *BmusageAPIService + serverId string + limit *int32 + offset *int32 +} + +// Limit the number of results returned. +func (r ApiGetServerBandwidthNotificationSettingListRequest) Limit(limit int32) ApiGetServerBandwidthNotificationSettingListRequest { + r.limit = &limit + return r +} + +// Return results starting from the given offset. +func (r ApiGetServerBandwidthNotificationSettingListRequest) Offset(offset int32) ApiGetServerBandwidthNotificationSettingListRequest { + r.offset = &offset + return r +} + +func (r ApiGetServerBandwidthNotificationSettingListRequest) Execute() (*GetServerBandwidthNotificationSettingListResult, *http.Response, error) { + return r.ApiService.GetServerBandwidthNotificationSettingListExecute(r) +} + +/* +GetServerBandwidthNotificationSettingList List bandwidth notification settings + +List all bandwidth notification settings for this server. + + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param serverId The ID of a server + @return ApiGetServerBandwidthNotificationSettingListRequest +*/ +func (a *BmusageAPIService) GetServerBandwidthNotificationSettingList(ctx context.Context, serverId string) ApiGetServerBandwidthNotificationSettingListRequest { + return ApiGetServerBandwidthNotificationSettingListRequest{ + ApiService: a, + ctx: ctx, + serverId: serverId, + } +} + +// Execute executes the request +// @return GetServerBandwidthNotificationSettingListResult +func (a *BmusageAPIService) GetServerBandwidthNotificationSettingListExecute(r ApiGetServerBandwidthNotificationSettingListRequest) (*GetServerBandwidthNotificationSettingListResult, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodGet + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *GetServerBandwidthNotificationSettingListResult + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "BmusageAPIService.GetServerBandwidthNotificationSettingList") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/servers/{serverId}/notificationSettings/bandwidth" + localVarPath = strings.Replace(localVarPath, "{"+"serverId"+"}", url.PathEscape(parameterValueToString(r.serverId, "serverId")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + if r.limit != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "limit", r.limit, "") + } + if r.offset != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "offset", r.offset, "") + } + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiGetServerDataTrafficMetricsRequest struct { + ctx context.Context + ApiService *BmusageAPIService + serverId string + from *time.Time + to *time.Time + aggregation *string + granularity *string +} + +// Start of date interval in ISO-8601 format. The returned data will include everything up from - and including - the specified date time. +func (r ApiGetServerDataTrafficMetricsRequest) From(from time.Time) ApiGetServerDataTrafficMetricsRequest { + r.from = &from + return r +} + +// End of date interval in ISO-8601 format. The returned data will include everything up until - but not including - the specified date time. +func (r ApiGetServerDataTrafficMetricsRequest) To(to time.Time) ApiGetServerDataTrafficMetricsRequest { + r.to = &to + return r +} + +// Aggregate each metric using the given aggregation function. +func (r ApiGetServerDataTrafficMetricsRequest) Aggregation(aggregation string) ApiGetServerDataTrafficMetricsRequest { + r.aggregation = &aggregation + return r +} + +// Specify the preferred interval for each metric. If granularity is omitted from the request, only one metric is returned. +func (r ApiGetServerDataTrafficMetricsRequest) Granularity(granularity string) ApiGetServerDataTrafficMetricsRequest { + r.granularity = &granularity + return r +} + +func (r ApiGetServerDataTrafficMetricsRequest) Execute() (*Metrics, *http.Response, error) { + return r.ApiService.GetServerDataTrafficMetricsExecute(r) +} + +/* +GetServerDataTrafficMetrics Show datatraffic metrics + +At this moment only bandwidth information for the public interface is supported. + + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param serverId The ID of a server + @return ApiGetServerDataTrafficMetricsRequest +*/ +func (a *BmusageAPIService) GetServerDataTrafficMetrics(ctx context.Context, serverId string) ApiGetServerDataTrafficMetricsRequest { + return ApiGetServerDataTrafficMetricsRequest{ + ApiService: a, + ctx: ctx, + serverId: serverId, + } +} + +// Execute executes the request +// @return Metrics +func (a *BmusageAPIService) GetServerDataTrafficMetricsExecute(r ApiGetServerDataTrafficMetricsRequest) (*Metrics, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodGet + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *Metrics + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "BmusageAPIService.GetServerDataTrafficMetrics") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/servers/{serverId}/metrics/datatraffic" + localVarPath = strings.Replace(localVarPath, "{"+"serverId"+"}", url.PathEscape(parameterValueToString(r.serverId, "serverId")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + if r.from == nil { + return localVarReturnValue, nil, reportError("from is required and must be specified") + } + if r.to == nil { + return localVarReturnValue, nil, reportError("to is required and must be specified") + } + if r.aggregation == nil { + return localVarReturnValue, nil, reportError("aggregation is required and must be specified") + } + + parameterAddToHeaderOrQuery(localVarQueryParams, "from", r.from, "") + parameterAddToHeaderOrQuery(localVarQueryParams, "to", r.to, "") + if r.granularity != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "granularity", r.granularity, "") + } + parameterAddToHeaderOrQuery(localVarQueryParams, "aggregation", r.aggregation, "") + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiGetServerDataTrafficNotificationSettingRequest struct { + ctx context.Context + ApiService *BmusageAPIService + serverId string + notificationSettingId string +} + +func (r ApiGetServerDataTrafficNotificationSettingRequest) Execute() (*DataTrafficNotificationSetting, *http.Response, error) { + return r.ApiService.GetServerDataTrafficNotificationSettingExecute(r) +} + +/* +GetServerDataTrafficNotificationSetting Show a data traffic notification setting + +Get a datatraffic notification setting for this server. + + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param serverId The ID of a server + @param notificationSettingId The ID of a notification setting + @return ApiGetServerDataTrafficNotificationSettingRequest +*/ +func (a *BmusageAPIService) GetServerDataTrafficNotificationSetting(ctx context.Context, serverId string, notificationSettingId string) ApiGetServerDataTrafficNotificationSettingRequest { + return ApiGetServerDataTrafficNotificationSettingRequest{ + ApiService: a, + ctx: ctx, + serverId: serverId, + notificationSettingId: notificationSettingId, + } +} + +// Execute executes the request +// @return DataTrafficNotificationSetting +func (a *BmusageAPIService) GetServerDataTrafficNotificationSettingExecute(r ApiGetServerDataTrafficNotificationSettingRequest) (*DataTrafficNotificationSetting, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodGet + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *DataTrafficNotificationSetting + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "BmusageAPIService.GetServerDataTrafficNotificationSetting") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/servers/{serverId}/notificationSettings/datatraffic/{notificationSettingId}" + localVarPath = strings.Replace(localVarPath, "{"+"serverId"+"}", url.PathEscape(parameterValueToString(r.serverId, "serverId")), -1) + localVarPath = strings.Replace(localVarPath, "{"+"notificationSettingId"+"}", url.PathEscape(parameterValueToString(r.notificationSettingId, "notificationSettingId")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiGetServerDataTrafficNotificationSettingListRequest struct { + ctx context.Context + ApiService *BmusageAPIService + serverId string + limit *int32 + offset *int32 +} + +// Limit the number of results returned. +func (r ApiGetServerDataTrafficNotificationSettingListRequest) Limit(limit int32) ApiGetServerDataTrafficNotificationSettingListRequest { + r.limit = &limit + return r +} + +// Return results starting from the given offset. +func (r ApiGetServerDataTrafficNotificationSettingListRequest) Offset(offset int32) ApiGetServerDataTrafficNotificationSettingListRequest { + r.offset = &offset + return r +} + +func (r ApiGetServerDataTrafficNotificationSettingListRequest) Execute() (*GetServerDataTrafficNotificationSettingListResult, *http.Response, error) { + return r.ApiService.GetServerDataTrafficNotificationSettingListExecute(r) +} + +/* +GetServerDataTrafficNotificationSettingList List data traffic notification settings + +List all datatraffic notification settings for this server. + + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param serverId The ID of a server + @return ApiGetServerDataTrafficNotificationSettingListRequest +*/ +func (a *BmusageAPIService) GetServerDataTrafficNotificationSettingList(ctx context.Context, serverId string) ApiGetServerDataTrafficNotificationSettingListRequest { + return ApiGetServerDataTrafficNotificationSettingListRequest{ + ApiService: a, + ctx: ctx, + serverId: serverId, + } +} + +// Execute executes the request +// @return GetServerDataTrafficNotificationSettingListResult +func (a *BmusageAPIService) GetServerDataTrafficNotificationSettingListExecute(r ApiGetServerDataTrafficNotificationSettingListRequest) (*GetServerDataTrafficNotificationSettingListResult, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodGet + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *GetServerDataTrafficNotificationSettingListResult + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "BmusageAPIService.GetServerDataTrafficNotificationSettingList") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/servers/{serverId}/notificationSettings/datatraffic" + localVarPath = strings.Replace(localVarPath, "{"+"serverId"+"}", url.PathEscape(parameterValueToString(r.serverId, "serverId")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + if r.limit != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "limit", r.limit, "") + } + if r.offset != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "offset", r.offset, "") + } + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiServersMetricsBandwidthRequest struct { + ctx context.Context + ApiService *BmusageAPIService + serverId string + from *time.Time + to *time.Time + aggregation *string + granularity *string +} + +// Start of date interval in ISO-8601 format. The returned data will include everything up from - and including - the specified date time. +func (r ApiServersMetricsBandwidthRequest) From(from time.Time) ApiServersMetricsBandwidthRequest { + r.from = &from + return r +} + +// End of date interval in ISO-8601 format. The returned data will include everything up until - but not including - the specified date time. +func (r ApiServersMetricsBandwidthRequest) To(to time.Time) ApiServersMetricsBandwidthRequest { + r.to = &to + return r +} + +// Aggregate each metric using the given aggregation function. When the aggregation type `95TH` is specified the granularity parameter should be omitted from the request. +func (r ApiServersMetricsBandwidthRequest) Aggregation(aggregation string) ApiServersMetricsBandwidthRequest { + r.aggregation = &aggregation + return r +} + +// Specify the preferred interval for each metric. If granularity is omitted from the request, only one metric is returned. +func (r ApiServersMetricsBandwidthRequest) Granularity(granularity string) ApiServersMetricsBandwidthRequest { + r.granularity = &granularity + return r +} + +func (r ApiServersMetricsBandwidthRequest) Execute() (*Metrics, *http.Response, error) { + return r.ApiService.ServersMetricsBandwidthExecute(r) +} + +/* +ServersMetricsBandwidth Show bandwidth metrics + +At this moment only bandwidth information for the public interface is supported. + + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param serverId The ID of a server + @return ApiServersMetricsBandwidthRequest +*/ +func (a *BmusageAPIService) ServersMetricsBandwidth(ctx context.Context, serverId string) ApiServersMetricsBandwidthRequest { + return ApiServersMetricsBandwidthRequest{ + ApiService: a, + ctx: ctx, + serverId: serverId, + } +} + +// Execute executes the request +// @return Metrics +func (a *BmusageAPIService) ServersMetricsBandwidthExecute(r ApiServersMetricsBandwidthRequest) (*Metrics, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodGet + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *Metrics + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "BmusageAPIService.ServersMetricsBandwidth") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/servers/{serverId}/metrics/bandwidth" + localVarPath = strings.Replace(localVarPath, "{"+"serverId"+"}", url.PathEscape(parameterValueToString(r.serverId, "serverId")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + if r.from == nil { + return localVarReturnValue, nil, reportError("from is required and must be specified") + } + if r.to == nil { + return localVarReturnValue, nil, reportError("to is required and must be specified") + } + if r.aggregation == nil { + return localVarReturnValue, nil, reportError("aggregation is required and must be specified") + } + + parameterAddToHeaderOrQuery(localVarQueryParams, "from", r.from, "") + parameterAddToHeaderOrQuery(localVarQueryParams, "to", r.to, "") + if r.granularity != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "granularity", r.granularity, "") + } + parameterAddToHeaderOrQuery(localVarQueryParams, "aggregation", r.aggregation, "") + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiUpdateServerBandwidthNotificationSettingRequest struct { + ctx context.Context + ApiService *BmusageAPIService + serverId string + notificationSettingId string + bandwidthNotificationSettingOpts *BandwidthNotificationSettingOpts +} + +func (r ApiUpdateServerBandwidthNotificationSettingRequest) BandwidthNotificationSettingOpts(bandwidthNotificationSettingOpts BandwidthNotificationSettingOpts) ApiUpdateServerBandwidthNotificationSettingRequest { + r.bandwidthNotificationSettingOpts = &bandwidthNotificationSettingOpts + return r +} + +func (r ApiUpdateServerBandwidthNotificationSettingRequest) Execute() (*BandwidthNotificationSetting, *http.Response, error) { + return r.ApiService.UpdateServerBandwidthNotificationSettingExecute(r) +} + +/* +UpdateServerBandwidthNotificationSetting Update a bandwidth notification setting + +Update an existing bandwidth notification setting for this server. + + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param serverId The ID of a server + @param notificationSettingId The ID of a notification setting + @return ApiUpdateServerBandwidthNotificationSettingRequest +*/ +func (a *BmusageAPIService) UpdateServerBandwidthNotificationSetting(ctx context.Context, serverId string, notificationSettingId string) ApiUpdateServerBandwidthNotificationSettingRequest { + return ApiUpdateServerBandwidthNotificationSettingRequest{ + ApiService: a, + ctx: ctx, + serverId: serverId, + notificationSettingId: notificationSettingId, + } +} + +// Execute executes the request +// @return BandwidthNotificationSetting +func (a *BmusageAPIService) UpdateServerBandwidthNotificationSettingExecute(r ApiUpdateServerBandwidthNotificationSettingRequest) (*BandwidthNotificationSetting, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodPut + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *BandwidthNotificationSetting + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "BmusageAPIService.UpdateServerBandwidthNotificationSetting") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/servers/{serverId}/notificationSettings/bandwidth/{notificationSettingId}" + localVarPath = strings.Replace(localVarPath, "{"+"serverId"+"}", url.PathEscape(parameterValueToString(r.serverId, "serverId")), -1) + localVarPath = strings.Replace(localVarPath, "{"+"notificationSettingId"+"}", url.PathEscape(parameterValueToString(r.notificationSettingId, "notificationSettingId")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{"application/json"} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + // body params + localVarPostBody = r.bandwidthNotificationSettingOpts + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiUpdateServerDataTrafficNotificationSettingRequest struct { + ctx context.Context + ApiService *BmusageAPIService + serverId string + notificationSettingId string + dataTrafficNotificationSettingOpts *DataTrafficNotificationSettingOpts +} + +func (r ApiUpdateServerDataTrafficNotificationSettingRequest) DataTrafficNotificationSettingOpts(dataTrafficNotificationSettingOpts DataTrafficNotificationSettingOpts) ApiUpdateServerDataTrafficNotificationSettingRequest { + r.dataTrafficNotificationSettingOpts = &dataTrafficNotificationSettingOpts + return r +} + +func (r ApiUpdateServerDataTrafficNotificationSettingRequest) Execute() (*DataTrafficNotificationSettingOpts, *http.Response, error) { + return r.ApiService.UpdateServerDataTrafficNotificationSettingExecute(r) +} + +/* +UpdateServerDataTrafficNotificationSetting Update a data traffic notification setting + +Update an existing data traffic notification setting for this server. + + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param serverId The ID of a server + @param notificationSettingId The ID of a notification setting + @return ApiUpdateServerDataTrafficNotificationSettingRequest +*/ +func (a *BmusageAPIService) UpdateServerDataTrafficNotificationSetting(ctx context.Context, serverId string, notificationSettingId string) ApiUpdateServerDataTrafficNotificationSettingRequest { + return ApiUpdateServerDataTrafficNotificationSettingRequest{ + ApiService: a, + ctx: ctx, + serverId: serverId, + notificationSettingId: notificationSettingId, + } +} + +// Execute executes the request +// @return DataTrafficNotificationSettingOpts +func (a *BmusageAPIService) UpdateServerDataTrafficNotificationSettingExecute(r ApiUpdateServerDataTrafficNotificationSettingRequest) (*DataTrafficNotificationSettingOpts, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodPut + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *DataTrafficNotificationSettingOpts + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "BmusageAPIService.UpdateServerDataTrafficNotificationSetting") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/servers/{serverId}/notificationSettings/datatraffic/{notificationSettingId}" + localVarPath = strings.Replace(localVarPath, "{"+"serverId"+"}", url.PathEscape(parameterValueToString(r.serverId, "serverId")), -1) + localVarPath = strings.Replace(localVarPath, "{"+"notificationSettingId"+"}", url.PathEscape(parameterValueToString(r.notificationSettingId, "notificationSettingId")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{"application/json"} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + // body params + localVarPostBody = r.dataTrafficNotificationSettingOpts + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} diff --git a/bmusage/client.go b/bmusage/client.go new file mode 100644 index 0000000..4e81699 --- /dev/null +++ b/bmusage/client.go @@ -0,0 +1,678 @@ +/* +bmusage + +This documents the rest api bmusage api provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package bmusage + +import ( + "bytes" + "context" + "encoding/json" + "encoding/xml" + "errors" + "fmt" + "io" + "log" + "mime/multipart" + "net/http" + "net/http/httputil" + "net/url" + "os" + "path/filepath" + "reflect" + "regexp" + "strconv" + "strings" + "time" + "unicode/utf8" + + "golang.org/x/oauth2" +) + +var ( + JsonCheck = regexp.MustCompile(`(?i:(?:application|text)/(?:[^;]+\+)?json)`) + XmlCheck = regexp.MustCompile(`(?i:(?:application|text)/(?:[^;]+\+)?xml)`) + queryParamSplit = regexp.MustCompile(`(^|&)([^&]+)`) + queryDescape = strings.NewReplacer( "%5B", "[", "%5D", "]" ) +) + +// APIClient manages communication with the bmusage API vv2 +// In most cases there should be only one, shared, APIClient. +type APIClient struct { + cfg *Configuration + common service // Reuse a single struct instead of allocating one for each service on the heap. + + // API Services + + BmusageAPI *BmusageAPIService +} + +type service struct { + client *APIClient +} + +// NewAPIClient creates a new API client. Requires a userAgent string describing your application. +// optionally a custom http.Client to allow for advanced features such as caching. +func NewAPIClient(cfg *Configuration) *APIClient { + if cfg.HTTPClient == nil { + cfg.HTTPClient = http.DefaultClient + } + + c := &APIClient{} + c.cfg = cfg + c.common.client = c + + // API Services + c.BmusageAPI = (*BmusageAPIService)(&c.common) + + return c +} + +func atoi(in string) (int, error) { + return strconv.Atoi(in) +} + +// selectHeaderContentType select a content type from the available list. +func selectHeaderContentType(contentTypes []string) string { + if len(contentTypes) == 0 { + return "" + } + if contains(contentTypes, "application/json") { + return "application/json" + } + return contentTypes[0] // use the first content type specified in 'consumes' +} + +// selectHeaderAccept join all accept types and return +func selectHeaderAccept(accepts []string) string { + if len(accepts) == 0 { + return "" + } + + if contains(accepts, "application/json") { + return "application/json" + } + + return strings.Join(accepts, ",") +} + +// contains is a case insensitive match, finding needle in a haystack +func contains(haystack []string, needle string) bool { + for _, a := range haystack { + if strings.EqualFold(a, needle) { + return true + } + } + return false +} + +// Verify optional parameters are of the correct type. +func typeCheckParameter(obj interface{}, expected string, name string) error { + // Make sure there is an object. + if obj == nil { + return nil + } + + // Check the type is as expected. + if reflect.TypeOf(obj).String() != expected { + return fmt.Errorf("expected %s to be of type %s but received %s", name, expected, reflect.TypeOf(obj).String()) + } + return nil +} + +func parameterValueToString( obj interface{}, key string ) string { + if reflect.TypeOf(obj).Kind() != reflect.Ptr { + return fmt.Sprintf("%v", obj) + } + var param,ok = obj.(MappedNullable) + if !ok { + return "" + } + dataMap,err := param.ToMap() + if err != nil { + return "" + } + return fmt.Sprintf("%v", dataMap[key]) +} + +// parameterAddToHeaderOrQuery adds the provided object to the request header or url query +// supporting deep object syntax +func parameterAddToHeaderOrQuery(headerOrQueryParams interface{}, keyPrefix string, obj interface{}, collectionType string) { + var v = reflect.ValueOf(obj) + var value = "" + if v == reflect.ValueOf(nil) { + value = "null" + } else { + switch v.Kind() { + case reflect.Invalid: + value = "invalid" + + case reflect.Struct: + if t,ok := obj.(MappedNullable); ok { + dataMap,err := t.ToMap() + if err != nil { + return + } + parameterAddToHeaderOrQuery(headerOrQueryParams, keyPrefix, dataMap, collectionType) + return + } + if t, ok := obj.(time.Time); ok { + parameterAddToHeaderOrQuery(headerOrQueryParams, keyPrefix, t.Format(time.RFC3339), collectionType) + return + } + value = v.Type().String() + " value" + case reflect.Slice: + var indValue = reflect.ValueOf(obj) + if indValue == reflect.ValueOf(nil) { + return + } + var lenIndValue = indValue.Len() + for i:=0;i 0 || (len(formFiles) > 0) { + if body != nil { + return nil, errors.New("Cannot specify postBody and multipart form at the same time.") + } + body = &bytes.Buffer{} + w := multipart.NewWriter(body) + + for k, v := range formParams { + for _, iv := range v { + if strings.HasPrefix(k, "@") { // file + err = addFile(w, k[1:], iv) + if err != nil { + return nil, err + } + } else { // form value + w.WriteField(k, iv) + } + } + } + for _, formFile := range formFiles { + if len(formFile.fileBytes) > 0 && formFile.fileName != "" { + w.Boundary() + part, err := w.CreateFormFile(formFile.formFileName, filepath.Base(formFile.fileName)) + if err != nil { + return nil, err + } + _, err = part.Write(formFile.fileBytes) + if err != nil { + return nil, err + } + } + } + + // Set the Boundary in the Content-Type + headerParams["Content-Type"] = w.FormDataContentType() + + // Set Content-Length + headerParams["Content-Length"] = fmt.Sprintf("%d", body.Len()) + w.Close() + } + + if strings.HasPrefix(headerParams["Content-Type"], "application/x-www-form-urlencoded") && len(formParams) > 0 { + if body != nil { + return nil, errors.New("Cannot specify postBody and x-www-form-urlencoded form at the same time.") + } + body = &bytes.Buffer{} + body.WriteString(formParams.Encode()) + // Set Content-Length + headerParams["Content-Length"] = fmt.Sprintf("%d", body.Len()) + } + + // Setup path and query parameters + url, err := url.Parse(path) + if err != nil { + return nil, err + } + + // Override request host, if applicable + if c.cfg.Host != "" { + url.Host = c.cfg.Host + } + + // Override request scheme, if applicable + if c.cfg.Scheme != "" { + url.Scheme = c.cfg.Scheme + } + + // Adding Query Param + query := url.Query() + for k, v := range queryParams { + for _, iv := range v { + query.Add(k, iv) + } + } + + // Encode the parameters. + url.RawQuery = queryParamSplit.ReplaceAllStringFunc(query.Encode(), func(s string) string { + pieces := strings.Split(s, "=") + pieces[0] = queryDescape.Replace(pieces[0]) + return strings.Join(pieces, "=") + }) + + // Generate a new request + if body != nil { + localVarRequest, err = http.NewRequest(method, url.String(), body) + } else { + localVarRequest, err = http.NewRequest(method, url.String(), nil) + } + if err != nil { + return nil, err + } + + // add header parameters, if any + if len(headerParams) > 0 { + headers := http.Header{} + for h, v := range headerParams { + headers[h] = []string{v} + } + localVarRequest.Header = headers + } + + // Add the user agent to the request. + localVarRequest.Header.Add("User-Agent", c.cfg.UserAgent) + + if ctx != nil { + // add context to the request + localVarRequest = localVarRequest.WithContext(ctx) + + // Walk through any authentication. + + // OAuth2 authentication + if tok, ok := ctx.Value(ContextOAuth2).(oauth2.TokenSource); ok { + // We were able to grab an oauth2 token from the context + var latestToken *oauth2.Token + if latestToken, err = tok.Token(); err != nil { + return nil, err + } + + latestToken.SetAuthHeader(localVarRequest) + } + + // AccessToken Authentication + if auth, ok := ctx.Value(ContextAccessToken).(string); ok { + localVarRequest.Header.Add("Authorization", "Bearer "+auth) + } + + } + + for header, value := range c.cfg.DefaultHeader { + localVarRequest.Header.Add(header, value) + } + return localVarRequest, nil +} + +func (c *APIClient) decode(v interface{}, b []byte, contentType string) (err error) { + if len(b) == 0 { + return nil + } + if s, ok := v.(*string); ok { + *s = string(b) + return nil + } + if f, ok := v.(*os.File); ok { + f, err = os.CreateTemp("", "HttpClientFile") + if err != nil { + return + } + _, err = f.Write(b) + if err != nil { + return + } + _, err = f.Seek(0, io.SeekStart) + return + } + if f, ok := v.(**os.File); ok { + *f, err = os.CreateTemp("", "HttpClientFile") + if err != nil { + return + } + _, err = (*f).Write(b) + if err != nil { + return + } + _, err = (*f).Seek(0, io.SeekStart) + return + } + if XmlCheck.MatchString(contentType) { + if err = xml.Unmarshal(b, v); err != nil { + return err + } + return nil + } + if JsonCheck.MatchString(contentType) { + if actualObj, ok := v.(interface{ GetActualInstance() interface{} }); ok { // oneOf, anyOf schemas + if unmarshalObj, ok := actualObj.(interface{ UnmarshalJSON([]byte) error }); ok { // make sure it has UnmarshalJSON defined + if err = unmarshalObj.UnmarshalJSON(b); err != nil { + return err + } + } else { + return errors.New("Unknown type with GetActualInstance but no unmarshalObj.UnmarshalJSON defined") + } + } else if err = json.Unmarshal(b, v); err != nil { // simple model + return err + } + return nil + } + return errors.New("undefined response type") +} + +// Add a file to the multipart request +func addFile(w *multipart.Writer, fieldName, path string) error { + file, err := os.Open(filepath.Clean(path)) + if err != nil { + return err + } + err = file.Close() + if err != nil { + return err + } + + part, err := w.CreateFormFile(fieldName, filepath.Base(path)) + if err != nil { + return err + } + _, err = io.Copy(part, file) + + return err +} + +// Prevent trying to import "fmt" +func reportError(format string, a ...interface{}) error { + return fmt.Errorf(format, a...) +} + +// A wrapper for strict JSON decoding +func newStrictDecoder(data []byte) *json.Decoder { + dec := json.NewDecoder(bytes.NewBuffer(data)) + dec.DisallowUnknownFields() + return dec +} + +// Set request body from an interface{} +func setBody(body interface{}, contentType string) (bodyBuf *bytes.Buffer, err error) { + if bodyBuf == nil { + bodyBuf = &bytes.Buffer{} + } + + if reader, ok := body.(io.Reader); ok { + _, err = bodyBuf.ReadFrom(reader) + } else if fp, ok := body.(*os.File); ok { + _, err = bodyBuf.ReadFrom(fp) + } else if b, ok := body.([]byte); ok { + _, err = bodyBuf.Write(b) + } else if s, ok := body.(string); ok { + _, err = bodyBuf.WriteString(s) + } else if s, ok := body.(*string); ok { + _, err = bodyBuf.WriteString(*s) + } else if JsonCheck.MatchString(contentType) { + err = json.NewEncoder(bodyBuf).Encode(body) + } else if XmlCheck.MatchString(contentType) { + var bs []byte + bs, err = xml.Marshal(body) + if err == nil { + bodyBuf.Write(bs) + } + } + + if err != nil { + return nil, err + } + + if bodyBuf.Len() == 0 { + err = fmt.Errorf("invalid body type %s\n", contentType) + return nil, err + } + return bodyBuf, nil +} + +// detectContentType method is used to figure out `Request.Body` content type for request header +func detectContentType(body interface{}) string { + contentType := "text/plain; charset=utf-8" + kind := reflect.TypeOf(body).Kind() + + switch kind { + case reflect.Struct, reflect.Map, reflect.Ptr: + contentType = "application/json; charset=utf-8" + case reflect.String: + contentType = "text/plain; charset=utf-8" + default: + if b, ok := body.([]byte); ok { + contentType = http.DetectContentType(b) + } else if kind == reflect.Slice { + contentType = "application/json; charset=utf-8" + } + } + + return contentType +} + +// Ripped from https://github.com/gregjones/httpcache/blob/master/httpcache.go +type cacheControl map[string]string + +func parseCacheControl(headers http.Header) cacheControl { + cc := cacheControl{} + ccHeader := headers.Get("Cache-Control") + for _, part := range strings.Split(ccHeader, ",") { + part = strings.Trim(part, " ") + if part == "" { + continue + } + if strings.ContainsRune(part, '=') { + keyval := strings.Split(part, "=") + cc[strings.Trim(keyval[0], " ")] = strings.Trim(keyval[1], ",") + } else { + cc[part] = "" + } + } + return cc +} + +// CacheExpires helper function to determine remaining time before repeating a request. +func CacheExpires(r *http.Response) time.Time { + // Figure out when the cache expires. + var expires time.Time + now, err := time.Parse(time.RFC1123, r.Header.Get("date")) + if err != nil { + return time.Now() + } + respCacheControl := parseCacheControl(r.Header) + + if maxAge, ok := respCacheControl["max-age"]; ok { + lifetime, err := time.ParseDuration(maxAge + "s") + if err != nil { + expires = now + } else { + expires = now.Add(lifetime) + } + } else { + expiresHeader := r.Header.Get("Expires") + if expiresHeader != "" { + expires, err = time.Parse(time.RFC1123, expiresHeader) + if err != nil { + expires = now + } + } + } + return expires +} + +func strlen(s string) int { + return utf8.RuneCountInString(s) +} + +// GenericOpenAPIError Provides access to the body, error and model on returned errors. +type GenericOpenAPIError struct { + body []byte + error string + model interface{} +} + +// Error returns non-empty string if there was an error. +func (e GenericOpenAPIError) Error() string { + return e.error +} + +// Body returns the raw bytes of the response +func (e GenericOpenAPIError) Body() []byte { + return e.body +} + +// Model returns the unpacked model of the error +func (e GenericOpenAPIError) Model() interface{} { + return e.model +} + +// format error message using title and detail when model implements rfc7807 +func formatErrorMessage(status string, v interface{}) string { + str := "" + metaValue := reflect.ValueOf(v).Elem() + + if metaValue.Kind() == reflect.Struct { + field := metaValue.FieldByName("Title") + if field != (reflect.Value{}) { + str = fmt.Sprintf("%s", field.Interface()) + } + + field = metaValue.FieldByName("Detail") + if field != (reflect.Value{}) { + str = fmt.Sprintf("%s (%s)", str, field.Interface()) + } + } + + return strings.TrimSpace(fmt.Sprintf("%s %s", status, str)) +} diff --git a/bmusage/configuration.go b/bmusage/configuration.go new file mode 100644 index 0000000..94f15e3 --- /dev/null +++ b/bmusage/configuration.go @@ -0,0 +1,225 @@ +/* +bmusage + +This documents the rest api bmusage api provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package bmusage + +import ( + "context" + "fmt" + "net/http" + "strings" +) + +// contextKeys are used to identify the type of value in the context. +// Since these are string, it is possible to get a short description of the +// context key for logging and debugging using key.String(). + +type contextKey string + +func (c contextKey) String() string { + return "auth " + string(c) +} + +var ( + // ContextOAuth2 takes an oauth2.TokenSource as authentication for the request. + ContextOAuth2 = contextKey("token") + + // ContextAccessToken takes a string oauth2 access token as authentication for the request. + ContextAccessToken = contextKey("accesstoken") + + // ContextAPIKeys takes a string apikey as authentication for the request + ContextAPIKeys = contextKey("apiKeys") + + // ContextServerIndex uses a server configuration from the index. + ContextServerIndex = contextKey("serverIndex") + + // ContextOperationServerIndices uses a server configuration from the index mapping. + ContextOperationServerIndices = contextKey("serverOperationIndices") + + // ContextServerVariables overrides a server configuration variables. + ContextServerVariables = contextKey("serverVariables") + + // ContextOperationServerVariables overrides a server configuration variables using operation specific values. + ContextOperationServerVariables = contextKey("serverOperationVariables") +) + +// BasicAuth provides basic http authentication to a request passed via context using ContextBasicAuth +type BasicAuth struct { + UserName string `json:"userName,omitempty"` + Password string `json:"password,omitempty"` +} + +// APIKey provides API key based authentication to a request passed via context using ContextAPIKey +type APIKey struct { + Key string + Prefix string +} + +// ServerVariable stores the information about a server variable +type ServerVariable struct { + Description string + DefaultValue string + EnumValues []string +} + +// ServerConfiguration stores the information about a server +type ServerConfiguration struct { + URL string + Description string + Variables map[string]ServerVariable +} + +// ServerConfigurations stores multiple ServerConfiguration items +type ServerConfigurations []ServerConfiguration + +// Configuration stores the configuration of the API client +type Configuration struct { + Host string `json:"host,omitempty"` + Scheme string `json:"scheme,omitempty"` + DefaultHeader map[string]string `json:"defaultHeader,omitempty"` + UserAgent string `json:"userAgent,omitempty"` + Debug bool `json:"debug,omitempty"` + Servers ServerConfigurations + OperationServers map[string]ServerConfigurations + HTTPClient *http.Client +} + +// NewConfiguration returns a new Configuration object +func NewConfiguration() *Configuration { + cfg := &Configuration{ + DefaultHeader: make(map[string]string), + UserAgent: "OpenAPI-Generator/1.0.0/go", + Debug: false, + Servers: ServerConfigurations{ + { + URL: "https://api.leaseweb.com/internal/bmusageapi/v2", + Description: "No description provided", + }, + }, + OperationServers: map[string]ServerConfigurations{ + }, + } + return cfg +} + +// AddDefaultHeader adds a new HTTP header to the default header in the request +func (c *Configuration) AddDefaultHeader(key string, value string) { + c.DefaultHeader[key] = value +} + +// URL formats template on a index using given variables +func (sc ServerConfigurations) URL(index int, variables map[string]string) (string, error) { + if index < 0 || len(sc) <= index { + return "", fmt.Errorf("index %v out of range %v", index, len(sc)-1) + } + server := sc[index] + url := server.URL + + // go through variables and replace placeholders + for name, variable := range server.Variables { + if value, ok := variables[name]; ok { + found := bool(len(variable.EnumValues) == 0) + for _, enumValue := range variable.EnumValues { + if value == enumValue { + found = true + } + } + if !found { + return "", fmt.Errorf("the variable %s in the server URL has invalid value %v. Must be %v", name, value, variable.EnumValues) + } + url = strings.Replace(url, "{"+name+"}", value, -1) + } else { + url = strings.Replace(url, "{"+name+"}", variable.DefaultValue, -1) + } + } + return url, nil +} + +// ServerURL returns URL based on server settings +func (c *Configuration) ServerURL(index int, variables map[string]string) (string, error) { + return c.Servers.URL(index, variables) +} + +func getServerIndex(ctx context.Context) (int, error) { + si := ctx.Value(ContextServerIndex) + if si != nil { + if index, ok := si.(int); ok { + return index, nil + } + return 0, reportError("Invalid type %T should be int", si) + } + return 0, nil +} + +func getServerOperationIndex(ctx context.Context, endpoint string) (int, error) { + osi := ctx.Value(ContextOperationServerIndices) + if osi != nil { + if operationIndices, ok := osi.(map[string]int); !ok { + return 0, reportError("Invalid type %T should be map[string]int", osi) + } else { + index, ok := operationIndices[endpoint] + if ok { + return index, nil + } + } + } + return getServerIndex(ctx) +} + +func getServerVariables(ctx context.Context) (map[string]string, error) { + sv := ctx.Value(ContextServerVariables) + if sv != nil { + if variables, ok := sv.(map[string]string); ok { + return variables, nil + } + return nil, reportError("ctx value of ContextServerVariables has invalid type %T should be map[string]string", sv) + } + return nil, nil +} + +func getServerOperationVariables(ctx context.Context, endpoint string) (map[string]string, error) { + osv := ctx.Value(ContextOperationServerVariables) + if osv != nil { + if operationVariables, ok := osv.(map[string]map[string]string); !ok { + return nil, reportError("ctx value of ContextOperationServerVariables has invalid type %T should be map[string]map[string]string", osv) + } else { + variables, ok := operationVariables[endpoint] + if ok { + return variables, nil + } + } + } + return getServerVariables(ctx) +} + +// ServerURLWithContext returns a new server URL given an endpoint +func (c *Configuration) ServerURLWithContext(ctx context.Context, endpoint string) (string, error) { + sc, ok := c.OperationServers[endpoint] + if !ok { + sc = c.Servers + } + + if ctx == nil { + return sc.URL(0, nil) + } + + index, err := getServerOperationIndex(ctx, endpoint) + if err != nil { + return "", err + } + + variables, err := getServerOperationVariables(ctx, endpoint) + if err != nil { + return "", err + } + + return sc.URL(index, variables) +} diff --git a/bmusage/go.mod b/bmusage/go.mod new file mode 100644 index 0000000..3ca8d86 --- /dev/null +++ b/bmusage/go.mod @@ -0,0 +1,7 @@ +module github.com/leaseweb/leaseweb-go-sdk/bmusage + +go 1.18 + +require ( + golang.org/x/oauth2 v0.0.0-20210323180902-22b0adad7558 +) diff --git a/bmusage/go.sum b/bmusage/go.sum new file mode 100644 index 0000000..3dee6d6 --- /dev/null +++ b/bmusage/go.sum @@ -0,0 +1,360 @@ +cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU= +cloud.google.com/go v0.44.1/go.mod h1:iSa0KzasP4Uvy3f1mN/7PiObzGgflwredwwASm/v6AU= +cloud.google.com/go v0.44.2/go.mod h1:60680Gw3Yr4ikxnPRS/oxxkBccT6SA1yMk63TGekxKY= +cloud.google.com/go v0.45.1/go.mod h1:RpBamKRgapWJb87xiFSdk4g1CME7QZg3uwTez+TSTjc= +cloud.google.com/go v0.46.3/go.mod h1:a6bKKbmY7er1mI7TEI4lsAkts/mkhTSZK8w33B4RAg0= +cloud.google.com/go v0.50.0/go.mod h1:r9sluTvynVuxRIOHXQEHMFffphuXHOMZMycpNR5e6To= +cloud.google.com/go v0.52.0/go.mod h1:pXajvRH/6o3+F9jDHZWQ5PbGhn+o8w9qiu/CffaVdO4= +cloud.google.com/go v0.53.0/go.mod h1:fp/UouUEsRkN6ryDKNW/Upv/JBKnv6WDthjR6+vze6M= +cloud.google.com/go v0.54.0/go.mod h1:1rq2OEkV3YMf6n/9ZvGWI3GWw0VoqH/1x2nd8Is/bPc= +cloud.google.com/go v0.56.0/go.mod h1:jr7tqZxxKOVYizybht9+26Z/gUq7tiRzu+ACVAMbKVk= +cloud.google.com/go v0.57.0/go.mod h1:oXiQ6Rzq3RAkkY7N6t3TcE6jE+CIBBbA36lwQ1JyzZs= +cloud.google.com/go v0.62.0/go.mod h1:jmCYTdRCQuc1PHIIJ/maLInMho30T/Y0M4hTdTShOYc= +cloud.google.com/go v0.65.0/go.mod h1:O5N8zS7uWy9vkA9vayVHs65eM1ubvY4h553ofrNHObY= +cloud.google.com/go/bigquery v1.0.1/go.mod h1:i/xbL2UlR5RvWAURpBYZTtm/cXjCha9lbfbpx4poX+o= +cloud.google.com/go/bigquery v1.3.0/go.mod h1:PjpwJnslEMmckchkHFfq+HTD2DmtT67aNFKH1/VBDHE= +cloud.google.com/go/bigquery v1.4.0/go.mod h1:S8dzgnTigyfTmLBfrtrhyYhwRxG72rYxvftPBK2Dvzc= +cloud.google.com/go/bigquery v1.5.0/go.mod h1:snEHRnqQbz117VIFhE8bmtwIDY80NLUZUMb4Nv6dBIg= +cloud.google.com/go/bigquery v1.7.0/go.mod h1://okPTzCYNXSlb24MZs83e2Do+h+VXtc4gLoIoXIAPc= +cloud.google.com/go/bigquery v1.8.0/go.mod h1:J5hqkt3O0uAFnINi6JXValWIb1v0goeZM77hZzJN/fQ= +cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7TKLgZqpHYE= +cloud.google.com/go/datastore v1.1.0/go.mod h1:umbIZjpQpHh4hmRpGhH4tLFup+FVzqBi1b3c64qFpCk= +cloud.google.com/go/pubsub v1.0.1/go.mod h1:R0Gpsv3s54REJCy4fxDixWD93lHJMoZTyQ2kNxGRt3I= +cloud.google.com/go/pubsub v1.1.0/go.mod h1:EwwdRX2sKPjnvnqCa270oGRyludottCI76h+R3AArQw= +cloud.google.com/go/pubsub v1.2.0/go.mod h1:jhfEVHT8odbXTkndysNHCcx0awwzvfOlguIAii9o8iA= +cloud.google.com/go/pubsub v1.3.1/go.mod h1:i+ucay31+CNRpDW4Lu78I4xXG+O1r/MAHgjpRVR+TSU= +cloud.google.com/go/storage v1.0.0/go.mod h1:IhtSnM/ZTZV8YYJWCY8RULGVqBDmpoyjwiyrjsg+URw= +cloud.google.com/go/storage v1.5.0/go.mod h1:tpKbwo567HUNpVclU5sGELwQWBDZ8gh0ZeosJ0Rtdos= +cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohlUTyfDhBk= +cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs= +cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0= +dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= +github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= +github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= +github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= +github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= +github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= +github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= +github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= +github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= +github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y= +github.com/golang/mock v1.4.0/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= +github.com/golang/mock v1.4.1/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= +github.com/golang/mock v1.4.3/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= +github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4= +github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= +github.com/golang/protobuf v1.3.4/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= +github.com/golang/protobuf v1.3.5/go.mod h1:6O5/vntMXwX2lRkT1hjjk0nAC1IDOTvTlVgjlRvqsdk= +github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= +github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= +github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= +github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= +github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= +github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= +github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= +github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= +github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= +github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.4.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= +github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0= +github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= +github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= +github.com/google/pprof v0.0.0-20191218002539-d4f498aebedc/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= +github.com/google/pprof v0.0.0-20200212024743-f11f1df84d12/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= +github.com/google/pprof v0.0.0-20200229191704-1ebb73c60ed3/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= +github.com/google/pprof v0.0.0-20200430221834-fc25d7d30c6d/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= +github.com/google/pprof v0.0.0-20200708004538-1a94d8640e99/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= +github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= +github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= +github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= +github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= +github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= +github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= +github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= +github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk= +github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= +go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= +go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= +go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= +go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= +golang.org/x/exp v0.0.0-20190829153037-c13cbed26979/go.mod h1:86+5VVa7VpoJ4kLfm080zCjGlMRFzhUhsZKEZO7MGek= +golang.org/x/exp v0.0.0-20191030013958-a1ab85dbe136/go.mod h1:JXzH8nQsPlswgeRAPE3MuO9GYsAcnJvJ4vnMwN/5qkY= +golang.org/x/exp v0.0.0-20191129062945-2f5052295587/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= +golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= +golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= +golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM= +golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU= +golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= +golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= +golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= +golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f/go.mod h1:5qLYkcX4OjUUV8bRuDixDT3tpyyb+LUpUlRWLxfhWrs= +golang.org/x/lint v0.0.0-20200130185559-910be7a94367/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= +golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= +golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= +golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o= +golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= +golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY= +golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= +golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= +golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e h1:bRhVy7zSSasaqNksaRZiA5EEI+Ei4I1nO5Jh72wfHlg= +golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190501004415-9ce7a6920f09/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20190628185345-da137c7871d7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200222125558-5a598a2470a0/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200501053045-e0ff5e5a1de5/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200506145744-7e3656a0809f/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200513185701-a91f0712d120/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200520182314-0ba52f642ac2/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= +golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= +golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= +golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= +golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45 h1:SVwTIAaPC2U/AvvLNZ2a7OVsmBpC8L5BlwK1whH3hm0= +golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/oauth2 v0.0.0-20191202225959-858c2ad4c8b6/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/oauth2 v0.0.0-20210323180902-22b0adad7558/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4 h1:YUO/7uOKsKeq9UokNS62b8FYywz3ker1l1vDZRCRefw= +golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200113162924-86b910548bc1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200122134326-e047566fdf82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200331124033-c3d80250170d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200501052902-10377860bb8e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200511232937-7e40ca221e25/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200515095857-1151b9dac4a9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200523222454-059865788121/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200803210538-64077c9b5642/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= +golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20190506145303-2d16b83fe98c/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191113191852-77e3bb0ad9e7/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191115202509-3a792d9c32b2/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191130070609-6e064ea0cf2d/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191216173652-a0e659d51361/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20191227053925-7b8e75db28f4/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200117161641-43d50277825c/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200122220014-bf1340f18c4a/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200204074204-1cc6d1ef6c74/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200207183749-b753a1ba74fa/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200212150539-ea181f53ac56/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200224181240-023911ca70b2/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200227222343-706bc42d1f0d/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200304193943-95d2e580d8eb/go.mod h1:o4KQGtdN14AW+yjsvvwRTJJuXz8XRtIHtEnmAXLyFUw= +golang.org/x/tools v0.0.0-20200312045724-11d5b4c81c7d/go.mod h1:o4KQGtdN14AW+yjsvvwRTJJuXz8XRtIHtEnmAXLyFUw= +golang.org/x/tools v0.0.0-20200331025713-a30bf2db82d4/go.mod h1:Sl4aGygMT6LrqrWclx+PTx3U+LnKx/seiNR+3G19Ar8= +golang.org/x/tools v0.0.0-20200501065659-ab2804fb9c9d/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20200512131952-2bc93b1c0c88/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20200515010526-7d3b6ebf133d/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20200618134242-20370b0cb4b2/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20200729194436-6467de6f59a7/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= +golang.org/x/tools v0.0.0-20200804011535-6c149bb5ef0d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= +golang.org/x/tools v0.0.0-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= +google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M= +google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= +google.golang.org/api v0.9.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= +google.golang.org/api v0.13.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= +google.golang.org/api v0.14.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= +google.golang.org/api v0.15.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= +google.golang.org/api v0.17.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= +google.golang.org/api v0.18.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= +google.golang.org/api v0.19.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= +google.golang.org/api v0.20.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= +google.golang.org/api v0.22.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= +google.golang.org/api v0.24.0/go.mod h1:lIXQywCXRcnZPGlsd8NbLnOjtAoL6em04bJ9+z0MncE= +google.golang.org/api v0.28.0/go.mod h1:lIXQywCXRcnZPGlsd8NbLnOjtAoL6em04bJ9+z0MncE= +google.golang.org/api v0.29.0/go.mod h1:Lcubydp8VUV7KeIHD9z2Bys/sm/vGKnG1UHuDBSrHWM= +google.golang.org/api v0.30.0/go.mod h1:QGmEvQ87FHZNiUVJkT14jQNYJ4ZJjdRF23ZXz5138Fc= +google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= +google.golang.org/appengine v1.4.0 h1:/wp5JvzpHIxhs/dumFmF7BXTf3Z+dd4uXta4kVyO508= +google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0= +google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= +google.golang.org/appengine v1.6.6/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= +google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= +google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190801165951-fa694d86fc64/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= +google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= +google.golang.org/genproto v0.0.0-20190911173649-1774047e7e51/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8= +google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20191115194625-c23dd37a84c9/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20191216164720-4f79533eabd1/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20191230161307-f3c370f40bfb/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20200115191322-ca5a22157cba/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20200122232147-0452cf42e150/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20200204135345-fa8e72b47b90/go.mod h1:GmwEX6Z4W5gMy59cAlVYjN9JhxgbQH6Gn+gFDQe2lzA= +google.golang.org/genproto v0.0.0-20200212174721-66ed5ce911ce/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200224152610-e50cd9704f63/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200228133532-8c2c7df3a383/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200305110556-506484158171/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200312145019-da6875a35672/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200331122359-1ee6d9798940/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200430143042-b979b6f78d84/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200511104702-f5ebc3bea380/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200515170657-fc4c6c6a6587/go.mod h1:YsZOwe1myG/8QRHRsmBRE1LrgQY60beZKjly0O1fX9U= +google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= +google.golang.org/genproto v0.0.0-20200618031413-b414f8b61790/go.mod h1:jDfRM7FcilCzHH/e9qn6dsT145K34l5v+OpcnNgKAAA= +google.golang.org/genproto v0.0.0-20200729003335-053ba62fc06f/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20200804131852-c06518451d9c/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20200825200019-8632dd797987/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= +google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= +google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= +google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= +google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= +google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= +google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= +google.golang.org/grpc v1.27.1/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= +google.golang.org/grpc v1.28.0/go.mod h1:rpkK4SK4GF4Ach/+MFLZUBavHOvF2JJB5uozKKal+60= +google.golang.org/grpc v1.29.1/go.mod h1:itym6AZVZYACWQqET3MqgPpjcuV5QH3BxFS3IjizoKk= +google.golang.org/grpc v1.30.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= +google.golang.org/grpc v1.31.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= +google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= +google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= +google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= +google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= +google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= +google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4= +google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= +honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= +honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= +rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= +rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0= +rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= diff --git a/bmusage/model__metadata.go b/bmusage/model__metadata.go new file mode 100644 index 0000000..40c10d5 --- /dev/null +++ b/bmusage/model__metadata.go @@ -0,0 +1,210 @@ +/* +bmusage + +This documents the rest api bmusage api provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package bmusage + +import ( + "encoding/json" +) + +// checks if the Metadata type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &Metadata{} + +// Metadata Metadata about the collection +type Metadata struct { + // Total amount of orders in this collection + TotalCount *float32 `json:"totalCount,omitempty"` + // The offset used to generate this response + Offset *float32 `json:"offset,omitempty"` + // The limit used to generate this response + Limit *float32 `json:"limit,omitempty"` +} + +// NewMetadata instantiates a new Metadata object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewMetadata() *Metadata { + this := Metadata{} + var offset float32 = 0 + this.Offset = &offset + var limit float32 = 5 + this.Limit = &limit + return &this +} + +// NewMetadataWithDefaults instantiates a new Metadata object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewMetadataWithDefaults() *Metadata { + this := Metadata{} + var offset float32 = 0 + this.Offset = &offset + var limit float32 = 5 + this.Limit = &limit + return &this +} + +// GetTotalCount returns the TotalCount field value if set, zero value otherwise. +func (o *Metadata) GetTotalCount() float32 { + if o == nil || IsNil(o.TotalCount) { + var ret float32 + return ret + } + return *o.TotalCount +} + +// GetTotalCountOk returns a tuple with the TotalCount field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Metadata) GetTotalCountOk() (*float32, bool) { + if o == nil || IsNil(o.TotalCount) { + return nil, false + } + return o.TotalCount, true +} + +// HasTotalCount returns a boolean if a field has been set. +func (o *Metadata) HasTotalCount() bool { + if o != nil && !IsNil(o.TotalCount) { + return true + } + + return false +} + +// SetTotalCount gets a reference to the given float32 and assigns it to the TotalCount field. +func (o *Metadata) SetTotalCount(v float32) { + o.TotalCount = &v +} + +// GetOffset returns the Offset field value if set, zero value otherwise. +func (o *Metadata) GetOffset() float32 { + if o == nil || IsNil(o.Offset) { + var ret float32 + return ret + } + return *o.Offset +} + +// GetOffsetOk returns a tuple with the Offset field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Metadata) GetOffsetOk() (*float32, bool) { + if o == nil || IsNil(o.Offset) { + return nil, false + } + return o.Offset, true +} + +// HasOffset returns a boolean if a field has been set. +func (o *Metadata) HasOffset() bool { + if o != nil && !IsNil(o.Offset) { + return true + } + + return false +} + +// SetOffset gets a reference to the given float32 and assigns it to the Offset field. +func (o *Metadata) SetOffset(v float32) { + o.Offset = &v +} + +// GetLimit returns the Limit field value if set, zero value otherwise. +func (o *Metadata) GetLimit() float32 { + if o == nil || IsNil(o.Limit) { + var ret float32 + return ret + } + return *o.Limit +} + +// GetLimitOk returns a tuple with the Limit field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Metadata) GetLimitOk() (*float32, bool) { + if o == nil || IsNil(o.Limit) { + return nil, false + } + return o.Limit, true +} + +// HasLimit returns a boolean if a field has been set. +func (o *Metadata) HasLimit() bool { + if o != nil && !IsNil(o.Limit) { + return true + } + + return false +} + +// SetLimit gets a reference to the given float32 and assigns it to the Limit field. +func (o *Metadata) SetLimit(v float32) { + o.Limit = &v +} + +func (o Metadata) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o Metadata) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.TotalCount) { + toSerialize["totalCount"] = o.TotalCount + } + if !IsNil(o.Offset) { + toSerialize["offset"] = o.Offset + } + if !IsNil(o.Limit) { + toSerialize["limit"] = o.Limit + } + return toSerialize, nil +} + +type NullableMetadata struct { + value *Metadata + isSet bool +} + +func (v NullableMetadata) Get() *Metadata { + return v.value +} + +func (v *NullableMetadata) Set(val *Metadata) { + v.value = val + v.isSet = true +} + +func (v NullableMetadata) IsSet() bool { + return v.isSet +} + +func (v *NullableMetadata) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableMetadata(val *Metadata) *NullableMetadata { + return &NullableMetadata{value: val, isSet: true} +} + +func (v NullableMetadata) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableMetadata) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/bmusage/model_actions.go b/bmusage/model_actions.go new file mode 100644 index 0000000..e98f4ed --- /dev/null +++ b/bmusage/model_actions.go @@ -0,0 +1,175 @@ +/* +bmusage + +This documents the rest api bmusage api provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package bmusage + +import ( + "encoding/json" +) + +// checks if the Actions type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &Actions{} + +// Actions struct for Actions +type Actions struct { + // Date timestamp when the last notification email triggered + LastTriggeredAt NullableString `json:"lastTriggeredAt,omitempty"` + // Type of action + Type *string `json:"type,omitempty"` +} + +// NewActions instantiates a new Actions object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewActions() *Actions { + this := Actions{} + return &this +} + +// NewActionsWithDefaults instantiates a new Actions object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewActionsWithDefaults() *Actions { + this := Actions{} + return &this +} + +// GetLastTriggeredAt returns the LastTriggeredAt field value if set, zero value otherwise (both if not set or set to explicit null). +func (o *Actions) GetLastTriggeredAt() string { + if o == nil || IsNil(o.LastTriggeredAt.Get()) { + var ret string + return ret + } + return *o.LastTriggeredAt.Get() +} + +// GetLastTriggeredAtOk returns a tuple with the LastTriggeredAt field value if set, nil otherwise +// and a boolean to check if the value has been set. +// NOTE: If the value is an explicit nil, `nil, true` will be returned +func (o *Actions) GetLastTriggeredAtOk() (*string, bool) { + if o == nil { + return nil, false + } + return o.LastTriggeredAt.Get(), o.LastTriggeredAt.IsSet() +} + +// HasLastTriggeredAt returns a boolean if a field has been set. +func (o *Actions) HasLastTriggeredAt() bool { + if o != nil && o.LastTriggeredAt.IsSet() { + return true + } + + return false +} + +// SetLastTriggeredAt gets a reference to the given NullableString and assigns it to the LastTriggeredAt field. +func (o *Actions) SetLastTriggeredAt(v string) { + o.LastTriggeredAt.Set(&v) +} +// SetLastTriggeredAtNil sets the value for LastTriggeredAt to be an explicit nil +func (o *Actions) SetLastTriggeredAtNil() { + o.LastTriggeredAt.Set(nil) +} + +// UnsetLastTriggeredAt ensures that no value is present for LastTriggeredAt, not even an explicit nil +func (o *Actions) UnsetLastTriggeredAt() { + o.LastTriggeredAt.Unset() +} + +// GetType returns the Type field value if set, zero value otherwise. +func (o *Actions) GetType() string { + if o == nil || IsNil(o.Type) { + var ret string + return ret + } + return *o.Type +} + +// GetTypeOk returns a tuple with the Type field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Actions) GetTypeOk() (*string, bool) { + if o == nil || IsNil(o.Type) { + return nil, false + } + return o.Type, true +} + +// HasType returns a boolean if a field has been set. +func (o *Actions) HasType() bool { + if o != nil && !IsNil(o.Type) { + return true + } + + return false +} + +// SetType gets a reference to the given string and assigns it to the Type field. +func (o *Actions) SetType(v string) { + o.Type = &v +} + +func (o Actions) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o Actions) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if o.LastTriggeredAt.IsSet() { + toSerialize["lastTriggeredAt"] = o.LastTriggeredAt.Get() + } + if !IsNil(o.Type) { + toSerialize["type"] = o.Type + } + return toSerialize, nil +} + +type NullableActions struct { + value *Actions + isSet bool +} + +func (v NullableActions) Get() *Actions { + return v.value +} + +func (v *NullableActions) Set(val *Actions) { + v.value = val + v.isSet = true +} + +func (v NullableActions) IsSet() bool { + return v.isSet +} + +func (v *NullableActions) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableActions(val *Actions) *NullableActions { + return &NullableActions{value: val, isSet: true} +} + +func (v NullableActions) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableActions) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/bmusage/model_bandwidth_notification_setting.go b/bmusage/model_bandwidth_notification_setting.go new file mode 100644 index 0000000..e42184e --- /dev/null +++ b/bmusage/model_bandwidth_notification_setting.go @@ -0,0 +1,370 @@ +/* +bmusage + +This documents the rest api bmusage api provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package bmusage + +import ( + "encoding/json" +) + +// checks if the BandwidthNotificationSetting type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &BandwidthNotificationSetting{} + +// BandwidthNotificationSetting struct for BandwidthNotificationSetting +type BandwidthNotificationSetting struct { + // An array of notification setting actions + Actions []Actions `json:"actions,omitempty"` + // Frequency + Frequency *string `json:"frequency,omitempty"` + // Identifier of the notification setting + Id *string `json:"id,omitempty"` + // Date timestamp when the system last checked the server for threshold limit + LastCheckedAt NullableString `json:"lastCheckedAt,omitempty"` + // Threshold Value + Threshold *string `json:"threshold,omitempty"` + // Date timestamp when the threshold exceeded the limit + ThresholdExceededAt NullableString `json:"thresholdExceededAt,omitempty"` + // Unit + Unit *string `json:"unit,omitempty"` +} + +// NewBandwidthNotificationSetting instantiates a new BandwidthNotificationSetting object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewBandwidthNotificationSetting() *BandwidthNotificationSetting { + this := BandwidthNotificationSetting{} + return &this +} + +// NewBandwidthNotificationSettingWithDefaults instantiates a new BandwidthNotificationSetting object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewBandwidthNotificationSettingWithDefaults() *BandwidthNotificationSetting { + this := BandwidthNotificationSetting{} + return &this +} + +// GetActions returns the Actions field value if set, zero value otherwise. +func (o *BandwidthNotificationSetting) GetActions() []Actions { + if o == nil || IsNil(o.Actions) { + var ret []Actions + return ret + } + return o.Actions +} + +// GetActionsOk returns a tuple with the Actions field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *BandwidthNotificationSetting) GetActionsOk() ([]Actions, bool) { + if o == nil || IsNil(o.Actions) { + return nil, false + } + return o.Actions, true +} + +// HasActions returns a boolean if a field has been set. +func (o *BandwidthNotificationSetting) HasActions() bool { + if o != nil && !IsNil(o.Actions) { + return true + } + + return false +} + +// SetActions gets a reference to the given []Actions and assigns it to the Actions field. +func (o *BandwidthNotificationSetting) SetActions(v []Actions) { + o.Actions = v +} + +// GetFrequency returns the Frequency field value if set, zero value otherwise. +func (o *BandwidthNotificationSetting) GetFrequency() string { + if o == nil || IsNil(o.Frequency) { + var ret string + return ret + } + return *o.Frequency +} + +// GetFrequencyOk returns a tuple with the Frequency field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *BandwidthNotificationSetting) GetFrequencyOk() (*string, bool) { + if o == nil || IsNil(o.Frequency) { + return nil, false + } + return o.Frequency, true +} + +// HasFrequency returns a boolean if a field has been set. +func (o *BandwidthNotificationSetting) HasFrequency() bool { + if o != nil && !IsNil(o.Frequency) { + return true + } + + return false +} + +// SetFrequency gets a reference to the given string and assigns it to the Frequency field. +func (o *BandwidthNotificationSetting) SetFrequency(v string) { + o.Frequency = &v +} + +// GetId returns the Id field value if set, zero value otherwise. +func (o *BandwidthNotificationSetting) GetId() string { + if o == nil || IsNil(o.Id) { + var ret string + return ret + } + return *o.Id +} + +// GetIdOk returns a tuple with the Id field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *BandwidthNotificationSetting) GetIdOk() (*string, bool) { + if o == nil || IsNil(o.Id) { + return nil, false + } + return o.Id, true +} + +// HasId returns a boolean if a field has been set. +func (o *BandwidthNotificationSetting) HasId() bool { + if o != nil && !IsNil(o.Id) { + return true + } + + return false +} + +// SetId gets a reference to the given string and assigns it to the Id field. +func (o *BandwidthNotificationSetting) SetId(v string) { + o.Id = &v +} + +// GetLastCheckedAt returns the LastCheckedAt field value if set, zero value otherwise (both if not set or set to explicit null). +func (o *BandwidthNotificationSetting) GetLastCheckedAt() string { + if o == nil || IsNil(o.LastCheckedAt.Get()) { + var ret string + return ret + } + return *o.LastCheckedAt.Get() +} + +// GetLastCheckedAtOk returns a tuple with the LastCheckedAt field value if set, nil otherwise +// and a boolean to check if the value has been set. +// NOTE: If the value is an explicit nil, `nil, true` will be returned +func (o *BandwidthNotificationSetting) GetLastCheckedAtOk() (*string, bool) { + if o == nil { + return nil, false + } + return o.LastCheckedAt.Get(), o.LastCheckedAt.IsSet() +} + +// HasLastCheckedAt returns a boolean if a field has been set. +func (o *BandwidthNotificationSetting) HasLastCheckedAt() bool { + if o != nil && o.LastCheckedAt.IsSet() { + return true + } + + return false +} + +// SetLastCheckedAt gets a reference to the given NullableString and assigns it to the LastCheckedAt field. +func (o *BandwidthNotificationSetting) SetLastCheckedAt(v string) { + o.LastCheckedAt.Set(&v) +} +// SetLastCheckedAtNil sets the value for LastCheckedAt to be an explicit nil +func (o *BandwidthNotificationSetting) SetLastCheckedAtNil() { + o.LastCheckedAt.Set(nil) +} + +// UnsetLastCheckedAt ensures that no value is present for LastCheckedAt, not even an explicit nil +func (o *BandwidthNotificationSetting) UnsetLastCheckedAt() { + o.LastCheckedAt.Unset() +} + +// GetThreshold returns the Threshold field value if set, zero value otherwise. +func (o *BandwidthNotificationSetting) GetThreshold() string { + if o == nil || IsNil(o.Threshold) { + var ret string + return ret + } + return *o.Threshold +} + +// GetThresholdOk returns a tuple with the Threshold field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *BandwidthNotificationSetting) GetThresholdOk() (*string, bool) { + if o == nil || IsNil(o.Threshold) { + return nil, false + } + return o.Threshold, true +} + +// HasThreshold returns a boolean if a field has been set. +func (o *BandwidthNotificationSetting) HasThreshold() bool { + if o != nil && !IsNil(o.Threshold) { + return true + } + + return false +} + +// SetThreshold gets a reference to the given string and assigns it to the Threshold field. +func (o *BandwidthNotificationSetting) SetThreshold(v string) { + o.Threshold = &v +} + +// GetThresholdExceededAt returns the ThresholdExceededAt field value if set, zero value otherwise (both if not set or set to explicit null). +func (o *BandwidthNotificationSetting) GetThresholdExceededAt() string { + if o == nil || IsNil(o.ThresholdExceededAt.Get()) { + var ret string + return ret + } + return *o.ThresholdExceededAt.Get() +} + +// GetThresholdExceededAtOk returns a tuple with the ThresholdExceededAt field value if set, nil otherwise +// and a boolean to check if the value has been set. +// NOTE: If the value is an explicit nil, `nil, true` will be returned +func (o *BandwidthNotificationSetting) GetThresholdExceededAtOk() (*string, bool) { + if o == nil { + return nil, false + } + return o.ThresholdExceededAt.Get(), o.ThresholdExceededAt.IsSet() +} + +// HasThresholdExceededAt returns a boolean if a field has been set. +func (o *BandwidthNotificationSetting) HasThresholdExceededAt() bool { + if o != nil && o.ThresholdExceededAt.IsSet() { + return true + } + + return false +} + +// SetThresholdExceededAt gets a reference to the given NullableString and assigns it to the ThresholdExceededAt field. +func (o *BandwidthNotificationSetting) SetThresholdExceededAt(v string) { + o.ThresholdExceededAt.Set(&v) +} +// SetThresholdExceededAtNil sets the value for ThresholdExceededAt to be an explicit nil +func (o *BandwidthNotificationSetting) SetThresholdExceededAtNil() { + o.ThresholdExceededAt.Set(nil) +} + +// UnsetThresholdExceededAt ensures that no value is present for ThresholdExceededAt, not even an explicit nil +func (o *BandwidthNotificationSetting) UnsetThresholdExceededAt() { + o.ThresholdExceededAt.Unset() +} + +// GetUnit returns the Unit field value if set, zero value otherwise. +func (o *BandwidthNotificationSetting) GetUnit() string { + if o == nil || IsNil(o.Unit) { + var ret string + return ret + } + return *o.Unit +} + +// GetUnitOk returns a tuple with the Unit field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *BandwidthNotificationSetting) GetUnitOk() (*string, bool) { + if o == nil || IsNil(o.Unit) { + return nil, false + } + return o.Unit, true +} + +// HasUnit returns a boolean if a field has been set. +func (o *BandwidthNotificationSetting) HasUnit() bool { + if o != nil && !IsNil(o.Unit) { + return true + } + + return false +} + +// SetUnit gets a reference to the given string and assigns it to the Unit field. +func (o *BandwidthNotificationSetting) SetUnit(v string) { + o.Unit = &v +} + +func (o BandwidthNotificationSetting) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o BandwidthNotificationSetting) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Actions) { + toSerialize["actions"] = o.Actions + } + if !IsNil(o.Frequency) { + toSerialize["frequency"] = o.Frequency + } + if !IsNil(o.Id) { + toSerialize["id"] = o.Id + } + if o.LastCheckedAt.IsSet() { + toSerialize["lastCheckedAt"] = o.LastCheckedAt.Get() + } + if !IsNil(o.Threshold) { + toSerialize["threshold"] = o.Threshold + } + if o.ThresholdExceededAt.IsSet() { + toSerialize["thresholdExceededAt"] = o.ThresholdExceededAt.Get() + } + if !IsNil(o.Unit) { + toSerialize["unit"] = o.Unit + } + return toSerialize, nil +} + +type NullableBandwidthNotificationSetting struct { + value *BandwidthNotificationSetting + isSet bool +} + +func (v NullableBandwidthNotificationSetting) Get() *BandwidthNotificationSetting { + return v.value +} + +func (v *NullableBandwidthNotificationSetting) Set(val *BandwidthNotificationSetting) { + v.value = val + v.isSet = true +} + +func (v NullableBandwidthNotificationSetting) IsSet() bool { + return v.isSet +} + +func (v *NullableBandwidthNotificationSetting) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableBandwidthNotificationSetting(val *BandwidthNotificationSetting) *NullableBandwidthNotificationSetting { + return &NullableBandwidthNotificationSetting{value: val, isSet: true} +} + +func (v NullableBandwidthNotificationSetting) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableBandwidthNotificationSetting) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/bmusage/model_bandwidth_notification_setting_opts.go b/bmusage/model_bandwidth_notification_setting_opts.go new file mode 100644 index 0000000..2d4dd5a --- /dev/null +++ b/bmusage/model_bandwidth_notification_setting_opts.go @@ -0,0 +1,218 @@ +/* +bmusage + +This documents the rest api bmusage api provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package bmusage + +import ( + "encoding/json" + "bytes" + "fmt" +) + +// checks if the BandwidthNotificationSettingOpts type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &BandwidthNotificationSettingOpts{} + +// BandwidthNotificationSettingOpts struct for BandwidthNotificationSettingOpts +type BandwidthNotificationSettingOpts struct { + // Frequency for the Bandwidth Notification + Frequency string `json:"frequency"` + // Threshold Value for the Bandwidth Notification + Threshold string `json:"threshold"` + // Unit for the Bandwidth Notification + Unit string `json:"unit"` +} + +type _BandwidthNotificationSettingOpts BandwidthNotificationSettingOpts + +// NewBandwidthNotificationSettingOpts instantiates a new BandwidthNotificationSettingOpts object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewBandwidthNotificationSettingOpts(frequency string, threshold string, unit string) *BandwidthNotificationSettingOpts { + this := BandwidthNotificationSettingOpts{} + this.Frequency = frequency + this.Threshold = threshold + this.Unit = unit + return &this +} + +// NewBandwidthNotificationSettingOptsWithDefaults instantiates a new BandwidthNotificationSettingOpts object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewBandwidthNotificationSettingOptsWithDefaults() *BandwidthNotificationSettingOpts { + this := BandwidthNotificationSettingOpts{} + return &this +} + +// GetFrequency returns the Frequency field value +func (o *BandwidthNotificationSettingOpts) GetFrequency() string { + if o == nil { + var ret string + return ret + } + + return o.Frequency +} + +// GetFrequencyOk returns a tuple with the Frequency field value +// and a boolean to check if the value has been set. +func (o *BandwidthNotificationSettingOpts) GetFrequencyOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.Frequency, true +} + +// SetFrequency sets field value +func (o *BandwidthNotificationSettingOpts) SetFrequency(v string) { + o.Frequency = v +} + +// GetThreshold returns the Threshold field value +func (o *BandwidthNotificationSettingOpts) GetThreshold() string { + if o == nil { + var ret string + return ret + } + + return o.Threshold +} + +// GetThresholdOk returns a tuple with the Threshold field value +// and a boolean to check if the value has been set. +func (o *BandwidthNotificationSettingOpts) GetThresholdOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.Threshold, true +} + +// SetThreshold sets field value +func (o *BandwidthNotificationSettingOpts) SetThreshold(v string) { + o.Threshold = v +} + +// GetUnit returns the Unit field value +func (o *BandwidthNotificationSettingOpts) GetUnit() string { + if o == nil { + var ret string + return ret + } + + return o.Unit +} + +// GetUnitOk returns a tuple with the Unit field value +// and a boolean to check if the value has been set. +func (o *BandwidthNotificationSettingOpts) GetUnitOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.Unit, true +} + +// SetUnit sets field value +func (o *BandwidthNotificationSettingOpts) SetUnit(v string) { + o.Unit = v +} + +func (o BandwidthNotificationSettingOpts) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o BandwidthNotificationSettingOpts) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + toSerialize["frequency"] = o.Frequency + toSerialize["threshold"] = o.Threshold + toSerialize["unit"] = o.Unit + return toSerialize, nil +} + +func (o *BandwidthNotificationSettingOpts) UnmarshalJSON(data []byte) (err error) { + // This validates that all required properties are included in the JSON object + // by unmarshalling the object into a generic map with string keys and checking + // that every required field exists as a key in the generic map. + requiredProperties := []string{ + "frequency", + "threshold", + "unit", + } + + allProperties := make(map[string]interface{}) + + err = json.Unmarshal(data, &allProperties) + + if err != nil { + return err; + } + + for _, requiredProperty := range(requiredProperties) { + if _, exists := allProperties[requiredProperty]; !exists { + return fmt.Errorf("no value given for required property %v", requiredProperty) + } + } + + varBandwidthNotificationSettingOpts := _BandwidthNotificationSettingOpts{} + + decoder := json.NewDecoder(bytes.NewReader(data)) + decoder.DisallowUnknownFields() + err = decoder.Decode(&varBandwidthNotificationSettingOpts) + + if err != nil { + return err + } + + *o = BandwidthNotificationSettingOpts(varBandwidthNotificationSettingOpts) + + return err +} + +type NullableBandwidthNotificationSettingOpts struct { + value *BandwidthNotificationSettingOpts + isSet bool +} + +func (v NullableBandwidthNotificationSettingOpts) Get() *BandwidthNotificationSettingOpts { + return v.value +} + +func (v *NullableBandwidthNotificationSettingOpts) Set(val *BandwidthNotificationSettingOpts) { + v.value = val + v.isSet = true +} + +func (v NullableBandwidthNotificationSettingOpts) IsSet() bool { + return v.isSet +} + +func (v *NullableBandwidthNotificationSettingOpts) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableBandwidthNotificationSettingOpts(val *BandwidthNotificationSettingOpts) *NullableBandwidthNotificationSettingOpts { + return &NullableBandwidthNotificationSettingOpts{value: val, isSet: true} +} + +func (v NullableBandwidthNotificationSettingOpts) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableBandwidthNotificationSettingOpts) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/bmusage/model_data_traffic_notification_setting.go b/bmusage/model_data_traffic_notification_setting.go new file mode 100644 index 0000000..0d93b57 --- /dev/null +++ b/bmusage/model_data_traffic_notification_setting.go @@ -0,0 +1,370 @@ +/* +bmusage + +This documents the rest api bmusage api provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package bmusage + +import ( + "encoding/json" +) + +// checks if the DataTrafficNotificationSetting type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &DataTrafficNotificationSetting{} + +// DataTrafficNotificationSetting struct for DataTrafficNotificationSetting +type DataTrafficNotificationSetting struct { + // An array of notification setting actions + Actions []Actions `json:"actions,omitempty"` + // Frequency + Frequency *string `json:"frequency,omitempty"` + // Identifier of the notification setting + Id *string `json:"id,omitempty"` + // Date timestamp when the system last checked the server for threshold limit + LastCheckedAt NullableString `json:"lastCheckedAt,omitempty"` + // Threshold Value + Threshold *string `json:"threshold,omitempty"` + // Date timestamp when the threshold exceeded the limit + ThresholdExceededAt NullableString `json:"thresholdExceededAt,omitempty"` + // Unit + Unit *string `json:"unit,omitempty"` +} + +// NewDataTrafficNotificationSetting instantiates a new DataTrafficNotificationSetting object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewDataTrafficNotificationSetting() *DataTrafficNotificationSetting { + this := DataTrafficNotificationSetting{} + return &this +} + +// NewDataTrafficNotificationSettingWithDefaults instantiates a new DataTrafficNotificationSetting object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewDataTrafficNotificationSettingWithDefaults() *DataTrafficNotificationSetting { + this := DataTrafficNotificationSetting{} + return &this +} + +// GetActions returns the Actions field value if set, zero value otherwise. +func (o *DataTrafficNotificationSetting) GetActions() []Actions { + if o == nil || IsNil(o.Actions) { + var ret []Actions + return ret + } + return o.Actions +} + +// GetActionsOk returns a tuple with the Actions field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *DataTrafficNotificationSetting) GetActionsOk() ([]Actions, bool) { + if o == nil || IsNil(o.Actions) { + return nil, false + } + return o.Actions, true +} + +// HasActions returns a boolean if a field has been set. +func (o *DataTrafficNotificationSetting) HasActions() bool { + if o != nil && !IsNil(o.Actions) { + return true + } + + return false +} + +// SetActions gets a reference to the given []Actions and assigns it to the Actions field. +func (o *DataTrafficNotificationSetting) SetActions(v []Actions) { + o.Actions = v +} + +// GetFrequency returns the Frequency field value if set, zero value otherwise. +func (o *DataTrafficNotificationSetting) GetFrequency() string { + if o == nil || IsNil(o.Frequency) { + var ret string + return ret + } + return *o.Frequency +} + +// GetFrequencyOk returns a tuple with the Frequency field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *DataTrafficNotificationSetting) GetFrequencyOk() (*string, bool) { + if o == nil || IsNil(o.Frequency) { + return nil, false + } + return o.Frequency, true +} + +// HasFrequency returns a boolean if a field has been set. +func (o *DataTrafficNotificationSetting) HasFrequency() bool { + if o != nil && !IsNil(o.Frequency) { + return true + } + + return false +} + +// SetFrequency gets a reference to the given string and assigns it to the Frequency field. +func (o *DataTrafficNotificationSetting) SetFrequency(v string) { + o.Frequency = &v +} + +// GetId returns the Id field value if set, zero value otherwise. +func (o *DataTrafficNotificationSetting) GetId() string { + if o == nil || IsNil(o.Id) { + var ret string + return ret + } + return *o.Id +} + +// GetIdOk returns a tuple with the Id field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *DataTrafficNotificationSetting) GetIdOk() (*string, bool) { + if o == nil || IsNil(o.Id) { + return nil, false + } + return o.Id, true +} + +// HasId returns a boolean if a field has been set. +func (o *DataTrafficNotificationSetting) HasId() bool { + if o != nil && !IsNil(o.Id) { + return true + } + + return false +} + +// SetId gets a reference to the given string and assigns it to the Id field. +func (o *DataTrafficNotificationSetting) SetId(v string) { + o.Id = &v +} + +// GetLastCheckedAt returns the LastCheckedAt field value if set, zero value otherwise (both if not set or set to explicit null). +func (o *DataTrafficNotificationSetting) GetLastCheckedAt() string { + if o == nil || IsNil(o.LastCheckedAt.Get()) { + var ret string + return ret + } + return *o.LastCheckedAt.Get() +} + +// GetLastCheckedAtOk returns a tuple with the LastCheckedAt field value if set, nil otherwise +// and a boolean to check if the value has been set. +// NOTE: If the value is an explicit nil, `nil, true` will be returned +func (o *DataTrafficNotificationSetting) GetLastCheckedAtOk() (*string, bool) { + if o == nil { + return nil, false + } + return o.LastCheckedAt.Get(), o.LastCheckedAt.IsSet() +} + +// HasLastCheckedAt returns a boolean if a field has been set. +func (o *DataTrafficNotificationSetting) HasLastCheckedAt() bool { + if o != nil && o.LastCheckedAt.IsSet() { + return true + } + + return false +} + +// SetLastCheckedAt gets a reference to the given NullableString and assigns it to the LastCheckedAt field. +func (o *DataTrafficNotificationSetting) SetLastCheckedAt(v string) { + o.LastCheckedAt.Set(&v) +} +// SetLastCheckedAtNil sets the value for LastCheckedAt to be an explicit nil +func (o *DataTrafficNotificationSetting) SetLastCheckedAtNil() { + o.LastCheckedAt.Set(nil) +} + +// UnsetLastCheckedAt ensures that no value is present for LastCheckedAt, not even an explicit nil +func (o *DataTrafficNotificationSetting) UnsetLastCheckedAt() { + o.LastCheckedAt.Unset() +} + +// GetThreshold returns the Threshold field value if set, zero value otherwise. +func (o *DataTrafficNotificationSetting) GetThreshold() string { + if o == nil || IsNil(o.Threshold) { + var ret string + return ret + } + return *o.Threshold +} + +// GetThresholdOk returns a tuple with the Threshold field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *DataTrafficNotificationSetting) GetThresholdOk() (*string, bool) { + if o == nil || IsNil(o.Threshold) { + return nil, false + } + return o.Threshold, true +} + +// HasThreshold returns a boolean if a field has been set. +func (o *DataTrafficNotificationSetting) HasThreshold() bool { + if o != nil && !IsNil(o.Threshold) { + return true + } + + return false +} + +// SetThreshold gets a reference to the given string and assigns it to the Threshold field. +func (o *DataTrafficNotificationSetting) SetThreshold(v string) { + o.Threshold = &v +} + +// GetThresholdExceededAt returns the ThresholdExceededAt field value if set, zero value otherwise (both if not set or set to explicit null). +func (o *DataTrafficNotificationSetting) GetThresholdExceededAt() string { + if o == nil || IsNil(o.ThresholdExceededAt.Get()) { + var ret string + return ret + } + return *o.ThresholdExceededAt.Get() +} + +// GetThresholdExceededAtOk returns a tuple with the ThresholdExceededAt field value if set, nil otherwise +// and a boolean to check if the value has been set. +// NOTE: If the value is an explicit nil, `nil, true` will be returned +func (o *DataTrafficNotificationSetting) GetThresholdExceededAtOk() (*string, bool) { + if o == nil { + return nil, false + } + return o.ThresholdExceededAt.Get(), o.ThresholdExceededAt.IsSet() +} + +// HasThresholdExceededAt returns a boolean if a field has been set. +func (o *DataTrafficNotificationSetting) HasThresholdExceededAt() bool { + if o != nil && o.ThresholdExceededAt.IsSet() { + return true + } + + return false +} + +// SetThresholdExceededAt gets a reference to the given NullableString and assigns it to the ThresholdExceededAt field. +func (o *DataTrafficNotificationSetting) SetThresholdExceededAt(v string) { + o.ThresholdExceededAt.Set(&v) +} +// SetThresholdExceededAtNil sets the value for ThresholdExceededAt to be an explicit nil +func (o *DataTrafficNotificationSetting) SetThresholdExceededAtNil() { + o.ThresholdExceededAt.Set(nil) +} + +// UnsetThresholdExceededAt ensures that no value is present for ThresholdExceededAt, not even an explicit nil +func (o *DataTrafficNotificationSetting) UnsetThresholdExceededAt() { + o.ThresholdExceededAt.Unset() +} + +// GetUnit returns the Unit field value if set, zero value otherwise. +func (o *DataTrafficNotificationSetting) GetUnit() string { + if o == nil || IsNil(o.Unit) { + var ret string + return ret + } + return *o.Unit +} + +// GetUnitOk returns a tuple with the Unit field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *DataTrafficNotificationSetting) GetUnitOk() (*string, bool) { + if o == nil || IsNil(o.Unit) { + return nil, false + } + return o.Unit, true +} + +// HasUnit returns a boolean if a field has been set. +func (o *DataTrafficNotificationSetting) HasUnit() bool { + if o != nil && !IsNil(o.Unit) { + return true + } + + return false +} + +// SetUnit gets a reference to the given string and assigns it to the Unit field. +func (o *DataTrafficNotificationSetting) SetUnit(v string) { + o.Unit = &v +} + +func (o DataTrafficNotificationSetting) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o DataTrafficNotificationSetting) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Actions) { + toSerialize["actions"] = o.Actions + } + if !IsNil(o.Frequency) { + toSerialize["frequency"] = o.Frequency + } + if !IsNil(o.Id) { + toSerialize["id"] = o.Id + } + if o.LastCheckedAt.IsSet() { + toSerialize["lastCheckedAt"] = o.LastCheckedAt.Get() + } + if !IsNil(o.Threshold) { + toSerialize["threshold"] = o.Threshold + } + if o.ThresholdExceededAt.IsSet() { + toSerialize["thresholdExceededAt"] = o.ThresholdExceededAt.Get() + } + if !IsNil(o.Unit) { + toSerialize["unit"] = o.Unit + } + return toSerialize, nil +} + +type NullableDataTrafficNotificationSetting struct { + value *DataTrafficNotificationSetting + isSet bool +} + +func (v NullableDataTrafficNotificationSetting) Get() *DataTrafficNotificationSetting { + return v.value +} + +func (v *NullableDataTrafficNotificationSetting) Set(val *DataTrafficNotificationSetting) { + v.value = val + v.isSet = true +} + +func (v NullableDataTrafficNotificationSetting) IsSet() bool { + return v.isSet +} + +func (v *NullableDataTrafficNotificationSetting) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableDataTrafficNotificationSetting(val *DataTrafficNotificationSetting) *NullableDataTrafficNotificationSetting { + return &NullableDataTrafficNotificationSetting{value: val, isSet: true} +} + +func (v NullableDataTrafficNotificationSetting) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableDataTrafficNotificationSetting) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/bmusage/model_data_traffic_notification_setting_opts.go b/bmusage/model_data_traffic_notification_setting_opts.go new file mode 100644 index 0000000..7eaca8d --- /dev/null +++ b/bmusage/model_data_traffic_notification_setting_opts.go @@ -0,0 +1,218 @@ +/* +bmusage + +This documents the rest api bmusage api provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package bmusage + +import ( + "encoding/json" + "bytes" + "fmt" +) + +// checks if the DataTrafficNotificationSettingOpts type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &DataTrafficNotificationSettingOpts{} + +// DataTrafficNotificationSettingOpts struct for DataTrafficNotificationSettingOpts +type DataTrafficNotificationSettingOpts struct { + // Frequency for the Data Traffic Notification + Frequency string `json:"frequency"` + // Threshold Value for the Data Traffic Notification + Threshold string `json:"threshold"` + // Unit for the Data Traffic Notification + Unit string `json:"unit"` +} + +type _DataTrafficNotificationSettingOpts DataTrafficNotificationSettingOpts + +// NewDataTrafficNotificationSettingOpts instantiates a new DataTrafficNotificationSettingOpts object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewDataTrafficNotificationSettingOpts(frequency string, threshold string, unit string) *DataTrafficNotificationSettingOpts { + this := DataTrafficNotificationSettingOpts{} + this.Frequency = frequency + this.Threshold = threshold + this.Unit = unit + return &this +} + +// NewDataTrafficNotificationSettingOptsWithDefaults instantiates a new DataTrafficNotificationSettingOpts object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewDataTrafficNotificationSettingOptsWithDefaults() *DataTrafficNotificationSettingOpts { + this := DataTrafficNotificationSettingOpts{} + return &this +} + +// GetFrequency returns the Frequency field value +func (o *DataTrafficNotificationSettingOpts) GetFrequency() string { + if o == nil { + var ret string + return ret + } + + return o.Frequency +} + +// GetFrequencyOk returns a tuple with the Frequency field value +// and a boolean to check if the value has been set. +func (o *DataTrafficNotificationSettingOpts) GetFrequencyOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.Frequency, true +} + +// SetFrequency sets field value +func (o *DataTrafficNotificationSettingOpts) SetFrequency(v string) { + o.Frequency = v +} + +// GetThreshold returns the Threshold field value +func (o *DataTrafficNotificationSettingOpts) GetThreshold() string { + if o == nil { + var ret string + return ret + } + + return o.Threshold +} + +// GetThresholdOk returns a tuple with the Threshold field value +// and a boolean to check if the value has been set. +func (o *DataTrafficNotificationSettingOpts) GetThresholdOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.Threshold, true +} + +// SetThreshold sets field value +func (o *DataTrafficNotificationSettingOpts) SetThreshold(v string) { + o.Threshold = v +} + +// GetUnit returns the Unit field value +func (o *DataTrafficNotificationSettingOpts) GetUnit() string { + if o == nil { + var ret string + return ret + } + + return o.Unit +} + +// GetUnitOk returns a tuple with the Unit field value +// and a boolean to check if the value has been set. +func (o *DataTrafficNotificationSettingOpts) GetUnitOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.Unit, true +} + +// SetUnit sets field value +func (o *DataTrafficNotificationSettingOpts) SetUnit(v string) { + o.Unit = v +} + +func (o DataTrafficNotificationSettingOpts) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o DataTrafficNotificationSettingOpts) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + toSerialize["frequency"] = o.Frequency + toSerialize["threshold"] = o.Threshold + toSerialize["unit"] = o.Unit + return toSerialize, nil +} + +func (o *DataTrafficNotificationSettingOpts) UnmarshalJSON(data []byte) (err error) { + // This validates that all required properties are included in the JSON object + // by unmarshalling the object into a generic map with string keys and checking + // that every required field exists as a key in the generic map. + requiredProperties := []string{ + "frequency", + "threshold", + "unit", + } + + allProperties := make(map[string]interface{}) + + err = json.Unmarshal(data, &allProperties) + + if err != nil { + return err; + } + + for _, requiredProperty := range(requiredProperties) { + if _, exists := allProperties[requiredProperty]; !exists { + return fmt.Errorf("no value given for required property %v", requiredProperty) + } + } + + varDataTrafficNotificationSettingOpts := _DataTrafficNotificationSettingOpts{} + + decoder := json.NewDecoder(bytes.NewReader(data)) + decoder.DisallowUnknownFields() + err = decoder.Decode(&varDataTrafficNotificationSettingOpts) + + if err != nil { + return err + } + + *o = DataTrafficNotificationSettingOpts(varDataTrafficNotificationSettingOpts) + + return err +} + +type NullableDataTrafficNotificationSettingOpts struct { + value *DataTrafficNotificationSettingOpts + isSet bool +} + +func (v NullableDataTrafficNotificationSettingOpts) Get() *DataTrafficNotificationSettingOpts { + return v.value +} + +func (v *NullableDataTrafficNotificationSettingOpts) Set(val *DataTrafficNotificationSettingOpts) { + v.value = val + v.isSet = true +} + +func (v NullableDataTrafficNotificationSettingOpts) IsSet() bool { + return v.isSet +} + +func (v *NullableDataTrafficNotificationSettingOpts) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableDataTrafficNotificationSettingOpts(val *DataTrafficNotificationSettingOpts) *NullableDataTrafficNotificationSettingOpts { + return &NullableDataTrafficNotificationSettingOpts{value: val, isSet: true} +} + +func (v NullableDataTrafficNotificationSettingOpts) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableDataTrafficNotificationSettingOpts) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/bmusage/model_error_result.go b/bmusage/model_error_result.go new file mode 100644 index 0000000..f318e87 --- /dev/null +++ b/bmusage/model_error_result.go @@ -0,0 +1,238 @@ +/* +bmusage + +This documents the rest api bmusage api provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package bmusage + +import ( + "encoding/json" +) + +// checks if the ErrorResult type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &ErrorResult{} + +// ErrorResult struct for ErrorResult +type ErrorResult struct { + // The correlation ID of the current request. + CorrelationId *string `json:"correlationId,omitempty"` + // The error code. + ErrorCode *string `json:"errorCode,omitempty"` + // A human friendly description of the error. + ErrorMessage *string `json:"errorMessage,omitempty"` + ErrorDetails []map[string][]string `json:"errorDetails,omitempty"` +} + +// NewErrorResult instantiates a new ErrorResult object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewErrorResult() *ErrorResult { + this := ErrorResult{} + return &this +} + +// NewErrorResultWithDefaults instantiates a new ErrorResult object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewErrorResultWithDefaults() *ErrorResult { + this := ErrorResult{} + return &this +} + +// GetCorrelationId returns the CorrelationId field value if set, zero value otherwise. +func (o *ErrorResult) GetCorrelationId() string { + if o == nil || IsNil(o.CorrelationId) { + var ret string + return ret + } + return *o.CorrelationId +} + +// GetCorrelationIdOk returns a tuple with the CorrelationId field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ErrorResult) GetCorrelationIdOk() (*string, bool) { + if o == nil || IsNil(o.CorrelationId) { + return nil, false + } + return o.CorrelationId, true +} + +// HasCorrelationId returns a boolean if a field has been set. +func (o *ErrorResult) HasCorrelationId() bool { + if o != nil && !IsNil(o.CorrelationId) { + return true + } + + return false +} + +// SetCorrelationId gets a reference to the given string and assigns it to the CorrelationId field. +func (o *ErrorResult) SetCorrelationId(v string) { + o.CorrelationId = &v +} + +// GetErrorCode returns the ErrorCode field value if set, zero value otherwise. +func (o *ErrorResult) GetErrorCode() string { + if o == nil || IsNil(o.ErrorCode) { + var ret string + return ret + } + return *o.ErrorCode +} + +// GetErrorCodeOk returns a tuple with the ErrorCode field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ErrorResult) GetErrorCodeOk() (*string, bool) { + if o == nil || IsNil(o.ErrorCode) { + return nil, false + } + return o.ErrorCode, true +} + +// HasErrorCode returns a boolean if a field has been set. +func (o *ErrorResult) HasErrorCode() bool { + if o != nil && !IsNil(o.ErrorCode) { + return true + } + + return false +} + +// SetErrorCode gets a reference to the given string and assigns it to the ErrorCode field. +func (o *ErrorResult) SetErrorCode(v string) { + o.ErrorCode = &v +} + +// GetErrorMessage returns the ErrorMessage field value if set, zero value otherwise. +func (o *ErrorResult) GetErrorMessage() string { + if o == nil || IsNil(o.ErrorMessage) { + var ret string + return ret + } + return *o.ErrorMessage +} + +// GetErrorMessageOk returns a tuple with the ErrorMessage field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ErrorResult) GetErrorMessageOk() (*string, bool) { + if o == nil || IsNil(o.ErrorMessage) { + return nil, false + } + return o.ErrorMessage, true +} + +// HasErrorMessage returns a boolean if a field has been set. +func (o *ErrorResult) HasErrorMessage() bool { + if o != nil && !IsNil(o.ErrorMessage) { + return true + } + + return false +} + +// SetErrorMessage gets a reference to the given string and assigns it to the ErrorMessage field. +func (o *ErrorResult) SetErrorMessage(v string) { + o.ErrorMessage = &v +} + +// GetErrorDetails returns the ErrorDetails field value if set, zero value otherwise. +func (o *ErrorResult) GetErrorDetails() []map[string][]string { + if o == nil || IsNil(o.ErrorDetails) { + var ret []map[string][]string + return ret + } + return o.ErrorDetails +} + +// GetErrorDetailsOk returns a tuple with the ErrorDetails field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ErrorResult) GetErrorDetailsOk() ([]map[string][]string, bool) { + if o == nil || IsNil(o.ErrorDetails) { + return nil, false + } + return o.ErrorDetails, true +} + +// HasErrorDetails returns a boolean if a field has been set. +func (o *ErrorResult) HasErrorDetails() bool { + if o != nil && !IsNil(o.ErrorDetails) { + return true + } + + return false +} + +// SetErrorDetails gets a reference to the given []map[string][]string and assigns it to the ErrorDetails field. +func (o *ErrorResult) SetErrorDetails(v []map[string][]string) { + o.ErrorDetails = v +} + +func (o ErrorResult) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o ErrorResult) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.CorrelationId) { + toSerialize["correlationId"] = o.CorrelationId + } + if !IsNil(o.ErrorCode) { + toSerialize["errorCode"] = o.ErrorCode + } + if !IsNil(o.ErrorMessage) { + toSerialize["errorMessage"] = o.ErrorMessage + } + if !IsNil(o.ErrorDetails) { + toSerialize["errorDetails"] = o.ErrorDetails + } + return toSerialize, nil +} + +type NullableErrorResult struct { + value *ErrorResult + isSet bool +} + +func (v NullableErrorResult) Get() *ErrorResult { + return v.value +} + +func (v *NullableErrorResult) Set(val *ErrorResult) { + v.value = val + v.isSet = true +} + +func (v NullableErrorResult) IsSet() bool { + return v.isSet +} + +func (v *NullableErrorResult) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableErrorResult(val *ErrorResult) *NullableErrorResult { + return &NullableErrorResult{value: val, isSet: true} +} + +func (v NullableErrorResult) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableErrorResult) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/bmusage/model_get_server_bandwidth_notification_setting_list_result.go b/bmusage/model_get_server_bandwidth_notification_setting_list_result.go new file mode 100644 index 0000000..a95426e --- /dev/null +++ b/bmusage/model_get_server_bandwidth_notification_setting_list_result.go @@ -0,0 +1,164 @@ +/* +bmusage + +This documents the rest api bmusage api provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package bmusage + +import ( + "encoding/json" +) + +// checks if the GetServerBandwidthNotificationSettingListResult type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &GetServerBandwidthNotificationSettingListResult{} + +// GetServerBandwidthNotificationSettingListResult struct for GetServerBandwidthNotificationSettingListResult +type GetServerBandwidthNotificationSettingListResult struct { + Metadata *Metadata `json:"_metadata,omitempty"` + // An array of Bandwidth Notification Settings + BandwidthNotificationSettings []BandwidthNotificationSetting `json:"bandwidthNotificationSettings,omitempty"` +} + +// NewGetServerBandwidthNotificationSettingListResult instantiates a new GetServerBandwidthNotificationSettingListResult object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewGetServerBandwidthNotificationSettingListResult() *GetServerBandwidthNotificationSettingListResult { + this := GetServerBandwidthNotificationSettingListResult{} + return &this +} + +// NewGetServerBandwidthNotificationSettingListResultWithDefaults instantiates a new GetServerBandwidthNotificationSettingListResult object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewGetServerBandwidthNotificationSettingListResultWithDefaults() *GetServerBandwidthNotificationSettingListResult { + this := GetServerBandwidthNotificationSettingListResult{} + return &this +} + +// GetMetadata returns the Metadata field value if set, zero value otherwise. +func (o *GetServerBandwidthNotificationSettingListResult) GetMetadata() Metadata { + if o == nil || IsNil(o.Metadata) { + var ret Metadata + return ret + } + return *o.Metadata +} + +// GetMetadataOk returns a tuple with the Metadata field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetServerBandwidthNotificationSettingListResult) GetMetadataOk() (*Metadata, bool) { + if o == nil || IsNil(o.Metadata) { + return nil, false + } + return o.Metadata, true +} + +// HasMetadata returns a boolean if a field has been set. +func (o *GetServerBandwidthNotificationSettingListResult) HasMetadata() bool { + if o != nil && !IsNil(o.Metadata) { + return true + } + + return false +} + +// SetMetadata gets a reference to the given Metadata and assigns it to the Metadata field. +func (o *GetServerBandwidthNotificationSettingListResult) SetMetadata(v Metadata) { + o.Metadata = &v +} + +// GetBandwidthNotificationSettings returns the BandwidthNotificationSettings field value if set, zero value otherwise. +func (o *GetServerBandwidthNotificationSettingListResult) GetBandwidthNotificationSettings() []BandwidthNotificationSetting { + if o == nil || IsNil(o.BandwidthNotificationSettings) { + var ret []BandwidthNotificationSetting + return ret + } + return o.BandwidthNotificationSettings +} + +// GetBandwidthNotificationSettingsOk returns a tuple with the BandwidthNotificationSettings field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetServerBandwidthNotificationSettingListResult) GetBandwidthNotificationSettingsOk() ([]BandwidthNotificationSetting, bool) { + if o == nil || IsNil(o.BandwidthNotificationSettings) { + return nil, false + } + return o.BandwidthNotificationSettings, true +} + +// HasBandwidthNotificationSettings returns a boolean if a field has been set. +func (o *GetServerBandwidthNotificationSettingListResult) HasBandwidthNotificationSettings() bool { + if o != nil && !IsNil(o.BandwidthNotificationSettings) { + return true + } + + return false +} + +// SetBandwidthNotificationSettings gets a reference to the given []BandwidthNotificationSetting and assigns it to the BandwidthNotificationSettings field. +func (o *GetServerBandwidthNotificationSettingListResult) SetBandwidthNotificationSettings(v []BandwidthNotificationSetting) { + o.BandwidthNotificationSettings = v +} + +func (o GetServerBandwidthNotificationSettingListResult) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o GetServerBandwidthNotificationSettingListResult) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Metadata) { + toSerialize["_metadata"] = o.Metadata + } + if !IsNil(o.BandwidthNotificationSettings) { + toSerialize["bandwidthNotificationSettings"] = o.BandwidthNotificationSettings + } + return toSerialize, nil +} + +type NullableGetServerBandwidthNotificationSettingListResult struct { + value *GetServerBandwidthNotificationSettingListResult + isSet bool +} + +func (v NullableGetServerBandwidthNotificationSettingListResult) Get() *GetServerBandwidthNotificationSettingListResult { + return v.value +} + +func (v *NullableGetServerBandwidthNotificationSettingListResult) Set(val *GetServerBandwidthNotificationSettingListResult) { + v.value = val + v.isSet = true +} + +func (v NullableGetServerBandwidthNotificationSettingListResult) IsSet() bool { + return v.isSet +} + +func (v *NullableGetServerBandwidthNotificationSettingListResult) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableGetServerBandwidthNotificationSettingListResult(val *GetServerBandwidthNotificationSettingListResult) *NullableGetServerBandwidthNotificationSettingListResult { + return &NullableGetServerBandwidthNotificationSettingListResult{value: val, isSet: true} +} + +func (v NullableGetServerBandwidthNotificationSettingListResult) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableGetServerBandwidthNotificationSettingListResult) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/bmusage/model_get_server_data_traffic_notification_setting_list_result.go b/bmusage/model_get_server_data_traffic_notification_setting_list_result.go new file mode 100644 index 0000000..257afdf --- /dev/null +++ b/bmusage/model_get_server_data_traffic_notification_setting_list_result.go @@ -0,0 +1,164 @@ +/* +bmusage + +This documents the rest api bmusage api provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package bmusage + +import ( + "encoding/json" +) + +// checks if the GetServerDataTrafficNotificationSettingListResult type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &GetServerDataTrafficNotificationSettingListResult{} + +// GetServerDataTrafficNotificationSettingListResult struct for GetServerDataTrafficNotificationSettingListResult +type GetServerDataTrafficNotificationSettingListResult struct { + Metadata *Metadata `json:"_metadata,omitempty"` + // An array of Data traffic Notification Settings + DatatrafficNotificationSettings []DataTrafficNotificationSetting `json:"datatrafficNotificationSettings,omitempty"` +} + +// NewGetServerDataTrafficNotificationSettingListResult instantiates a new GetServerDataTrafficNotificationSettingListResult object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewGetServerDataTrafficNotificationSettingListResult() *GetServerDataTrafficNotificationSettingListResult { + this := GetServerDataTrafficNotificationSettingListResult{} + return &this +} + +// NewGetServerDataTrafficNotificationSettingListResultWithDefaults instantiates a new GetServerDataTrafficNotificationSettingListResult object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewGetServerDataTrafficNotificationSettingListResultWithDefaults() *GetServerDataTrafficNotificationSettingListResult { + this := GetServerDataTrafficNotificationSettingListResult{} + return &this +} + +// GetMetadata returns the Metadata field value if set, zero value otherwise. +func (o *GetServerDataTrafficNotificationSettingListResult) GetMetadata() Metadata { + if o == nil || IsNil(o.Metadata) { + var ret Metadata + return ret + } + return *o.Metadata +} + +// GetMetadataOk returns a tuple with the Metadata field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetServerDataTrafficNotificationSettingListResult) GetMetadataOk() (*Metadata, bool) { + if o == nil || IsNil(o.Metadata) { + return nil, false + } + return o.Metadata, true +} + +// HasMetadata returns a boolean if a field has been set. +func (o *GetServerDataTrafficNotificationSettingListResult) HasMetadata() bool { + if o != nil && !IsNil(o.Metadata) { + return true + } + + return false +} + +// SetMetadata gets a reference to the given Metadata and assigns it to the Metadata field. +func (o *GetServerDataTrafficNotificationSettingListResult) SetMetadata(v Metadata) { + o.Metadata = &v +} + +// GetDatatrafficNotificationSettings returns the DatatrafficNotificationSettings field value if set, zero value otherwise. +func (o *GetServerDataTrafficNotificationSettingListResult) GetDatatrafficNotificationSettings() []DataTrafficNotificationSetting { + if o == nil || IsNil(o.DatatrafficNotificationSettings) { + var ret []DataTrafficNotificationSetting + return ret + } + return o.DatatrafficNotificationSettings +} + +// GetDatatrafficNotificationSettingsOk returns a tuple with the DatatrafficNotificationSettings field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetServerDataTrafficNotificationSettingListResult) GetDatatrafficNotificationSettingsOk() ([]DataTrafficNotificationSetting, bool) { + if o == nil || IsNil(o.DatatrafficNotificationSettings) { + return nil, false + } + return o.DatatrafficNotificationSettings, true +} + +// HasDatatrafficNotificationSettings returns a boolean if a field has been set. +func (o *GetServerDataTrafficNotificationSettingListResult) HasDatatrafficNotificationSettings() bool { + if o != nil && !IsNil(o.DatatrafficNotificationSettings) { + return true + } + + return false +} + +// SetDatatrafficNotificationSettings gets a reference to the given []DataTrafficNotificationSetting and assigns it to the DatatrafficNotificationSettings field. +func (o *GetServerDataTrafficNotificationSettingListResult) SetDatatrafficNotificationSettings(v []DataTrafficNotificationSetting) { + o.DatatrafficNotificationSettings = v +} + +func (o GetServerDataTrafficNotificationSettingListResult) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o GetServerDataTrafficNotificationSettingListResult) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Metadata) { + toSerialize["_metadata"] = o.Metadata + } + if !IsNil(o.DatatrafficNotificationSettings) { + toSerialize["datatrafficNotificationSettings"] = o.DatatrafficNotificationSettings + } + return toSerialize, nil +} + +type NullableGetServerDataTrafficNotificationSettingListResult struct { + value *GetServerDataTrafficNotificationSettingListResult + isSet bool +} + +func (v NullableGetServerDataTrafficNotificationSettingListResult) Get() *GetServerDataTrafficNotificationSettingListResult { + return v.value +} + +func (v *NullableGetServerDataTrafficNotificationSettingListResult) Set(val *GetServerDataTrafficNotificationSettingListResult) { + v.value = val + v.isSet = true +} + +func (v NullableGetServerDataTrafficNotificationSettingListResult) IsSet() bool { + return v.isSet +} + +func (v *NullableGetServerDataTrafficNotificationSettingListResult) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableGetServerDataTrafficNotificationSettingListResult(val *GetServerDataTrafficNotificationSettingListResult) *NullableGetServerDataTrafficNotificationSettingListResult { + return &NullableGetServerDataTrafficNotificationSettingListResult{value: val, isSet: true} +} + +func (v NullableGetServerDataTrafficNotificationSettingListResult) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableGetServerDataTrafficNotificationSettingListResult) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/bmusage/model_metric.go b/bmusage/model_metric.go new file mode 100644 index 0000000..cd5c106 --- /dev/null +++ b/bmusage/model_metric.go @@ -0,0 +1,164 @@ +/* +bmusage + +This documents the rest api bmusage api provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package bmusage + +import ( + "encoding/json" +) + +// checks if the Metric type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &Metric{} + +// Metric struct for Metric +type Metric struct { + // The metric unit that's used + Unit *string `json:"unit,omitempty"` + Values []MetricValue `json:"values,omitempty"` +} + +// NewMetric instantiates a new Metric object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewMetric() *Metric { + this := Metric{} + return &this +} + +// NewMetricWithDefaults instantiates a new Metric object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewMetricWithDefaults() *Metric { + this := Metric{} + return &this +} + +// GetUnit returns the Unit field value if set, zero value otherwise. +func (o *Metric) GetUnit() string { + if o == nil || IsNil(o.Unit) { + var ret string + return ret + } + return *o.Unit +} + +// GetUnitOk returns a tuple with the Unit field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Metric) GetUnitOk() (*string, bool) { + if o == nil || IsNil(o.Unit) { + return nil, false + } + return o.Unit, true +} + +// HasUnit returns a boolean if a field has been set. +func (o *Metric) HasUnit() bool { + if o != nil && !IsNil(o.Unit) { + return true + } + + return false +} + +// SetUnit gets a reference to the given string and assigns it to the Unit field. +func (o *Metric) SetUnit(v string) { + o.Unit = &v +} + +// GetValues returns the Values field value if set, zero value otherwise. +func (o *Metric) GetValues() []MetricValue { + if o == nil || IsNil(o.Values) { + var ret []MetricValue + return ret + } + return o.Values +} + +// GetValuesOk returns a tuple with the Values field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Metric) GetValuesOk() ([]MetricValue, bool) { + if o == nil || IsNil(o.Values) { + return nil, false + } + return o.Values, true +} + +// HasValues returns a boolean if a field has been set. +func (o *Metric) HasValues() bool { + if o != nil && !IsNil(o.Values) { + return true + } + + return false +} + +// SetValues gets a reference to the given []MetricValue and assigns it to the Values field. +func (o *Metric) SetValues(v []MetricValue) { + o.Values = v +} + +func (o Metric) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o Metric) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Unit) { + toSerialize["unit"] = o.Unit + } + if !IsNil(o.Values) { + toSerialize["values"] = o.Values + } + return toSerialize, nil +} + +type NullableMetric struct { + value *Metric + isSet bool +} + +func (v NullableMetric) Get() *Metric { + return v.value +} + +func (v *NullableMetric) Set(val *Metric) { + v.value = val + v.isSet = true +} + +func (v NullableMetric) IsSet() bool { + return v.isSet +} + +func (v *NullableMetric) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableMetric(val *Metric) *NullableMetric { + return &NullableMetric{value: val, isSet: true} +} + +func (v NullableMetric) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableMetric) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/bmusage/model_metric_value.go b/bmusage/model_metric_value.go new file mode 100644 index 0000000..153a0e7 --- /dev/null +++ b/bmusage/model_metric_value.go @@ -0,0 +1,166 @@ +/* +bmusage + +This documents the rest api bmusage api provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package bmusage + +import ( + "encoding/json" + "time" +) + +// checks if the MetricValue type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &MetricValue{} + +// MetricValue An array of metrics grouped by granularity +type MetricValue struct { + // The time of the current metric + Timestamp *time.Time `json:"timestamp,omitempty"` + // The value of the current metric + Value *int32 `json:"value,omitempty"` +} + +// NewMetricValue instantiates a new MetricValue object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewMetricValue() *MetricValue { + this := MetricValue{} + return &this +} + +// NewMetricValueWithDefaults instantiates a new MetricValue object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewMetricValueWithDefaults() *MetricValue { + this := MetricValue{} + return &this +} + +// GetTimestamp returns the Timestamp field value if set, zero value otherwise. +func (o *MetricValue) GetTimestamp() time.Time { + if o == nil || IsNil(o.Timestamp) { + var ret time.Time + return ret + } + return *o.Timestamp +} + +// GetTimestampOk returns a tuple with the Timestamp field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *MetricValue) GetTimestampOk() (*time.Time, bool) { + if o == nil || IsNil(o.Timestamp) { + return nil, false + } + return o.Timestamp, true +} + +// HasTimestamp returns a boolean if a field has been set. +func (o *MetricValue) HasTimestamp() bool { + if o != nil && !IsNil(o.Timestamp) { + return true + } + + return false +} + +// SetTimestamp gets a reference to the given time.Time and assigns it to the Timestamp field. +func (o *MetricValue) SetTimestamp(v time.Time) { + o.Timestamp = &v +} + +// GetValue returns the Value field value if set, zero value otherwise. +func (o *MetricValue) GetValue() int32 { + if o == nil || IsNil(o.Value) { + var ret int32 + return ret + } + return *o.Value +} + +// GetValueOk returns a tuple with the Value field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *MetricValue) GetValueOk() (*int32, bool) { + if o == nil || IsNil(o.Value) { + return nil, false + } + return o.Value, true +} + +// HasValue returns a boolean if a field has been set. +func (o *MetricValue) HasValue() bool { + if o != nil && !IsNil(o.Value) { + return true + } + + return false +} + +// SetValue gets a reference to the given int32 and assigns it to the Value field. +func (o *MetricValue) SetValue(v int32) { + o.Value = &v +} + +func (o MetricValue) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o MetricValue) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Timestamp) { + toSerialize["timestamp"] = o.Timestamp + } + if !IsNil(o.Value) { + toSerialize["value"] = o.Value + } + return toSerialize, nil +} + +type NullableMetricValue struct { + value *MetricValue + isSet bool +} + +func (v NullableMetricValue) Get() *MetricValue { + return v.value +} + +func (v *NullableMetricValue) Set(val *MetricValue) { + v.value = val + v.isSet = true +} + +func (v NullableMetricValue) IsSet() bool { + return v.isSet +} + +func (v *NullableMetricValue) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableMetricValue(val *MetricValue) *NullableMetricValue { + return &NullableMetricValue{value: val, isSet: true} +} + +func (v NullableMetricValue) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableMetricValue) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/bmusage/model_metric_values.go b/bmusage/model_metric_values.go new file mode 100644 index 0000000..df7c57e --- /dev/null +++ b/bmusage/model_metric_values.go @@ -0,0 +1,163 @@ +/* +bmusage + +This documents the rest api bmusage api provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package bmusage + +import ( + "encoding/json" +) + +// checks if the MetricValues type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &MetricValues{} + +// MetricValues Object containing all metrics +type MetricValues struct { + UP_PUBLIC *Metric `json:"UP_PUBLIC,omitempty"` + DOWN_PUBLIC *Metric `json:"DOWN_PUBLIC,omitempty"` +} + +// NewMetricValues instantiates a new MetricValues object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewMetricValues() *MetricValues { + this := MetricValues{} + return &this +} + +// NewMetricValuesWithDefaults instantiates a new MetricValues object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewMetricValuesWithDefaults() *MetricValues { + this := MetricValues{} + return &this +} + +// GetUP_PUBLIC returns the UP_PUBLIC field value if set, zero value otherwise. +func (o *MetricValues) GetUP_PUBLIC() Metric { + if o == nil || IsNil(o.UP_PUBLIC) { + var ret Metric + return ret + } + return *o.UP_PUBLIC +} + +// GetUP_PUBLICOk returns a tuple with the UP_PUBLIC field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *MetricValues) GetUP_PUBLICOk() (*Metric, bool) { + if o == nil || IsNil(o.UP_PUBLIC) { + return nil, false + } + return o.UP_PUBLIC, true +} + +// HasUP_PUBLIC returns a boolean if a field has been set. +func (o *MetricValues) HasUP_PUBLIC() bool { + if o != nil && !IsNil(o.UP_PUBLIC) { + return true + } + + return false +} + +// SetUP_PUBLIC gets a reference to the given Metric and assigns it to the UP_PUBLIC field. +func (o *MetricValues) SetUP_PUBLIC(v Metric) { + o.UP_PUBLIC = &v +} + +// GetDOWN_PUBLIC returns the DOWN_PUBLIC field value if set, zero value otherwise. +func (o *MetricValues) GetDOWN_PUBLIC() Metric { + if o == nil || IsNil(o.DOWN_PUBLIC) { + var ret Metric + return ret + } + return *o.DOWN_PUBLIC +} + +// GetDOWN_PUBLICOk returns a tuple with the DOWN_PUBLIC field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *MetricValues) GetDOWN_PUBLICOk() (*Metric, bool) { + if o == nil || IsNil(o.DOWN_PUBLIC) { + return nil, false + } + return o.DOWN_PUBLIC, true +} + +// HasDOWN_PUBLIC returns a boolean if a field has been set. +func (o *MetricValues) HasDOWN_PUBLIC() bool { + if o != nil && !IsNil(o.DOWN_PUBLIC) { + return true + } + + return false +} + +// SetDOWN_PUBLIC gets a reference to the given Metric and assigns it to the DOWN_PUBLIC field. +func (o *MetricValues) SetDOWN_PUBLIC(v Metric) { + o.DOWN_PUBLIC = &v +} + +func (o MetricValues) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o MetricValues) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.UP_PUBLIC) { + toSerialize["UP_PUBLIC"] = o.UP_PUBLIC + } + if !IsNil(o.DOWN_PUBLIC) { + toSerialize["DOWN_PUBLIC"] = o.DOWN_PUBLIC + } + return toSerialize, nil +} + +type NullableMetricValues struct { + value *MetricValues + isSet bool +} + +func (v NullableMetricValues) Get() *MetricValues { + return v.value +} + +func (v *NullableMetricValues) Set(val *MetricValues) { + v.value = val + v.isSet = true +} + +func (v NullableMetricValues) IsSet() bool { + return v.isSet +} + +func (v *NullableMetricValues) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableMetricValues(val *MetricValues) *NullableMetricValues { + return &NullableMetricValues{value: val, isSet: true} +} + +func (v NullableMetricValues) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableMetricValues) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/bmusage/model_metrics.go b/bmusage/model_metrics.go new file mode 100644 index 0000000..37fb62d --- /dev/null +++ b/bmusage/model_metrics.go @@ -0,0 +1,163 @@ +/* +bmusage + +This documents the rest api bmusage api provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package bmusage + +import ( + "encoding/json" +) + +// checks if the Metrics type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &Metrics{} + +// Metrics struct for Metrics +type Metrics struct { + Metadata *MetricsMetadata `json:"_metadata,omitempty"` + Metrics *MetricValues `json:"metrics,omitempty"` +} + +// NewMetrics instantiates a new Metrics object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewMetrics() *Metrics { + this := Metrics{} + return &this +} + +// NewMetricsWithDefaults instantiates a new Metrics object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewMetricsWithDefaults() *Metrics { + this := Metrics{} + return &this +} + +// GetMetadata returns the Metadata field value if set, zero value otherwise. +func (o *Metrics) GetMetadata() MetricsMetadata { + if o == nil || IsNil(o.Metadata) { + var ret MetricsMetadata + return ret + } + return *o.Metadata +} + +// GetMetadataOk returns a tuple with the Metadata field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Metrics) GetMetadataOk() (*MetricsMetadata, bool) { + if o == nil || IsNil(o.Metadata) { + return nil, false + } + return o.Metadata, true +} + +// HasMetadata returns a boolean if a field has been set. +func (o *Metrics) HasMetadata() bool { + if o != nil && !IsNil(o.Metadata) { + return true + } + + return false +} + +// SetMetadata gets a reference to the given MetricsMetadata and assigns it to the Metadata field. +func (o *Metrics) SetMetadata(v MetricsMetadata) { + o.Metadata = &v +} + +// GetMetrics returns the Metrics field value if set, zero value otherwise. +func (o *Metrics) GetMetrics() MetricValues { + if o == nil || IsNil(o.Metrics) { + var ret MetricValues + return ret + } + return *o.Metrics +} + +// GetMetricsOk returns a tuple with the Metrics field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Metrics) GetMetricsOk() (*MetricValues, bool) { + if o == nil || IsNil(o.Metrics) { + return nil, false + } + return o.Metrics, true +} + +// HasMetrics returns a boolean if a field has been set. +func (o *Metrics) HasMetrics() bool { + if o != nil && !IsNil(o.Metrics) { + return true + } + + return false +} + +// SetMetrics gets a reference to the given MetricValues and assigns it to the Metrics field. +func (o *Metrics) SetMetrics(v MetricValues) { + o.Metrics = &v +} + +func (o Metrics) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o Metrics) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Metadata) { + toSerialize["_metadata"] = o.Metadata + } + if !IsNil(o.Metrics) { + toSerialize["metrics"] = o.Metrics + } + return toSerialize, nil +} + +type NullableMetrics struct { + value *Metrics + isSet bool +} + +func (v NullableMetrics) Get() *Metrics { + return v.value +} + +func (v *NullableMetrics) Set(val *Metrics) { + v.value = val + v.isSet = true +} + +func (v NullableMetrics) IsSet() bool { + return v.isSet +} + +func (v *NullableMetrics) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableMetrics(val *Metrics) *NullableMetrics { + return &NullableMetrics{value: val, isSet: true} +} + +func (v NullableMetrics) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableMetrics) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/bmusage/model_metrics_metadata.go b/bmusage/model_metrics_metadata.go new file mode 100644 index 0000000..0ad10f7 --- /dev/null +++ b/bmusage/model_metrics_metadata.go @@ -0,0 +1,240 @@ +/* +bmusage + +This documents the rest api bmusage api provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package bmusage + +import ( + "encoding/json" + "time" +) + +// checks if the MetricsMetadata type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &MetricsMetadata{} + +// MetricsMetadata Metadata about the collection +type MetricsMetadata struct { + // The aggregation type for this request + Aggregation *string `json:"aggregation,omitempty"` + // Start of date interval in ISO-8601 format + From *time.Time `json:"from,omitempty"` + // The interval for each metric + Granularity *string `json:"granularity,omitempty"` + // End of date interval in ISO-8601 format + To *time.Time `json:"to,omitempty"` +} + +// NewMetricsMetadata instantiates a new MetricsMetadata object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewMetricsMetadata() *MetricsMetadata { + this := MetricsMetadata{} + return &this +} + +// NewMetricsMetadataWithDefaults instantiates a new MetricsMetadata object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewMetricsMetadataWithDefaults() *MetricsMetadata { + this := MetricsMetadata{} + return &this +} + +// GetAggregation returns the Aggregation field value if set, zero value otherwise. +func (o *MetricsMetadata) GetAggregation() string { + if o == nil || IsNil(o.Aggregation) { + var ret string + return ret + } + return *o.Aggregation +} + +// GetAggregationOk returns a tuple with the Aggregation field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *MetricsMetadata) GetAggregationOk() (*string, bool) { + if o == nil || IsNil(o.Aggregation) { + return nil, false + } + return o.Aggregation, true +} + +// HasAggregation returns a boolean if a field has been set. +func (o *MetricsMetadata) HasAggregation() bool { + if o != nil && !IsNil(o.Aggregation) { + return true + } + + return false +} + +// SetAggregation gets a reference to the given string and assigns it to the Aggregation field. +func (o *MetricsMetadata) SetAggregation(v string) { + o.Aggregation = &v +} + +// GetFrom returns the From field value if set, zero value otherwise. +func (o *MetricsMetadata) GetFrom() time.Time { + if o == nil || IsNil(o.From) { + var ret time.Time + return ret + } + return *o.From +} + +// GetFromOk returns a tuple with the From field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *MetricsMetadata) GetFromOk() (*time.Time, bool) { + if o == nil || IsNil(o.From) { + return nil, false + } + return o.From, true +} + +// HasFrom returns a boolean if a field has been set. +func (o *MetricsMetadata) HasFrom() bool { + if o != nil && !IsNil(o.From) { + return true + } + + return false +} + +// SetFrom gets a reference to the given time.Time and assigns it to the From field. +func (o *MetricsMetadata) SetFrom(v time.Time) { + o.From = &v +} + +// GetGranularity returns the Granularity field value if set, zero value otherwise. +func (o *MetricsMetadata) GetGranularity() string { + if o == nil || IsNil(o.Granularity) { + var ret string + return ret + } + return *o.Granularity +} + +// GetGranularityOk returns a tuple with the Granularity field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *MetricsMetadata) GetGranularityOk() (*string, bool) { + if o == nil || IsNil(o.Granularity) { + return nil, false + } + return o.Granularity, true +} + +// HasGranularity returns a boolean if a field has been set. +func (o *MetricsMetadata) HasGranularity() bool { + if o != nil && !IsNil(o.Granularity) { + return true + } + + return false +} + +// SetGranularity gets a reference to the given string and assigns it to the Granularity field. +func (o *MetricsMetadata) SetGranularity(v string) { + o.Granularity = &v +} + +// GetTo returns the To field value if set, zero value otherwise. +func (o *MetricsMetadata) GetTo() time.Time { + if o == nil || IsNil(o.To) { + var ret time.Time + return ret + } + return *o.To +} + +// GetToOk returns a tuple with the To field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *MetricsMetadata) GetToOk() (*time.Time, bool) { + if o == nil || IsNil(o.To) { + return nil, false + } + return o.To, true +} + +// HasTo returns a boolean if a field has been set. +func (o *MetricsMetadata) HasTo() bool { + if o != nil && !IsNil(o.To) { + return true + } + + return false +} + +// SetTo gets a reference to the given time.Time and assigns it to the To field. +func (o *MetricsMetadata) SetTo(v time.Time) { + o.To = &v +} + +func (o MetricsMetadata) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o MetricsMetadata) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Aggregation) { + toSerialize["aggregation"] = o.Aggregation + } + if !IsNil(o.From) { + toSerialize["from"] = o.From + } + if !IsNil(o.Granularity) { + toSerialize["granularity"] = o.Granularity + } + if !IsNil(o.To) { + toSerialize["to"] = o.To + } + return toSerialize, nil +} + +type NullableMetricsMetadata struct { + value *MetricsMetadata + isSet bool +} + +func (v NullableMetricsMetadata) Get() *MetricsMetadata { + return v.value +} + +func (v *NullableMetricsMetadata) Set(val *MetricsMetadata) { + v.value = val + v.isSet = true +} + +func (v NullableMetricsMetadata) IsSet() bool { + return v.isSet +} + +func (v *NullableMetricsMetadata) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableMetricsMetadata(val *MetricsMetadata) *NullableMetricsMetadata { + return &NullableMetricsMetadata{value: val, isSet: true} +} + +func (v NullableMetricsMetadata) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableMetricsMetadata) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/bmusage/model_notification_setting.go b/bmusage/model_notification_setting.go new file mode 100644 index 0000000..27a6539 --- /dev/null +++ b/bmusage/model_notification_setting.go @@ -0,0 +1,333 @@ +/* +bmusage + +This documents the rest api bmusage api provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package bmusage + +import ( + "encoding/json" +) + +// checks if the NotificationSetting type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &NotificationSetting{} + +// NotificationSetting struct for NotificationSetting +type NotificationSetting struct { + // An array of notification setting actions + Actions []Actions `json:"actions,omitempty"` + // Frequency + Frequency *string `json:"frequency,omitempty"` + // Identifier of the notification setting + Id *string `json:"id,omitempty"` + // Date timestamp when the system last checked the server for threshold limit + LastCheckedAt NullableString `json:"lastCheckedAt,omitempty"` + // Threshold Value + Threshold *string `json:"threshold,omitempty"` + // Date timestamp when the threshold exceeded the limit + ThresholdExceededAt NullableString `json:"thresholdExceededAt,omitempty"` +} + +// NewNotificationSetting instantiates a new NotificationSetting object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewNotificationSetting() *NotificationSetting { + this := NotificationSetting{} + return &this +} + +// NewNotificationSettingWithDefaults instantiates a new NotificationSetting object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewNotificationSettingWithDefaults() *NotificationSetting { + this := NotificationSetting{} + return &this +} + +// GetActions returns the Actions field value if set, zero value otherwise. +func (o *NotificationSetting) GetActions() []Actions { + if o == nil || IsNil(o.Actions) { + var ret []Actions + return ret + } + return o.Actions +} + +// GetActionsOk returns a tuple with the Actions field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *NotificationSetting) GetActionsOk() ([]Actions, bool) { + if o == nil || IsNil(o.Actions) { + return nil, false + } + return o.Actions, true +} + +// HasActions returns a boolean if a field has been set. +func (o *NotificationSetting) HasActions() bool { + if o != nil && !IsNil(o.Actions) { + return true + } + + return false +} + +// SetActions gets a reference to the given []Actions and assigns it to the Actions field. +func (o *NotificationSetting) SetActions(v []Actions) { + o.Actions = v +} + +// GetFrequency returns the Frequency field value if set, zero value otherwise. +func (o *NotificationSetting) GetFrequency() string { + if o == nil || IsNil(o.Frequency) { + var ret string + return ret + } + return *o.Frequency +} + +// GetFrequencyOk returns a tuple with the Frequency field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *NotificationSetting) GetFrequencyOk() (*string, bool) { + if o == nil || IsNil(o.Frequency) { + return nil, false + } + return o.Frequency, true +} + +// HasFrequency returns a boolean if a field has been set. +func (o *NotificationSetting) HasFrequency() bool { + if o != nil && !IsNil(o.Frequency) { + return true + } + + return false +} + +// SetFrequency gets a reference to the given string and assigns it to the Frequency field. +func (o *NotificationSetting) SetFrequency(v string) { + o.Frequency = &v +} + +// GetId returns the Id field value if set, zero value otherwise. +func (o *NotificationSetting) GetId() string { + if o == nil || IsNil(o.Id) { + var ret string + return ret + } + return *o.Id +} + +// GetIdOk returns a tuple with the Id field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *NotificationSetting) GetIdOk() (*string, bool) { + if o == nil || IsNil(o.Id) { + return nil, false + } + return o.Id, true +} + +// HasId returns a boolean if a field has been set. +func (o *NotificationSetting) HasId() bool { + if o != nil && !IsNil(o.Id) { + return true + } + + return false +} + +// SetId gets a reference to the given string and assigns it to the Id field. +func (o *NotificationSetting) SetId(v string) { + o.Id = &v +} + +// GetLastCheckedAt returns the LastCheckedAt field value if set, zero value otherwise (both if not set or set to explicit null). +func (o *NotificationSetting) GetLastCheckedAt() string { + if o == nil || IsNil(o.LastCheckedAt.Get()) { + var ret string + return ret + } + return *o.LastCheckedAt.Get() +} + +// GetLastCheckedAtOk returns a tuple with the LastCheckedAt field value if set, nil otherwise +// and a boolean to check if the value has been set. +// NOTE: If the value is an explicit nil, `nil, true` will be returned +func (o *NotificationSetting) GetLastCheckedAtOk() (*string, bool) { + if o == nil { + return nil, false + } + return o.LastCheckedAt.Get(), o.LastCheckedAt.IsSet() +} + +// HasLastCheckedAt returns a boolean if a field has been set. +func (o *NotificationSetting) HasLastCheckedAt() bool { + if o != nil && o.LastCheckedAt.IsSet() { + return true + } + + return false +} + +// SetLastCheckedAt gets a reference to the given NullableString and assigns it to the LastCheckedAt field. +func (o *NotificationSetting) SetLastCheckedAt(v string) { + o.LastCheckedAt.Set(&v) +} +// SetLastCheckedAtNil sets the value for LastCheckedAt to be an explicit nil +func (o *NotificationSetting) SetLastCheckedAtNil() { + o.LastCheckedAt.Set(nil) +} + +// UnsetLastCheckedAt ensures that no value is present for LastCheckedAt, not even an explicit nil +func (o *NotificationSetting) UnsetLastCheckedAt() { + o.LastCheckedAt.Unset() +} + +// GetThreshold returns the Threshold field value if set, zero value otherwise. +func (o *NotificationSetting) GetThreshold() string { + if o == nil || IsNil(o.Threshold) { + var ret string + return ret + } + return *o.Threshold +} + +// GetThresholdOk returns a tuple with the Threshold field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *NotificationSetting) GetThresholdOk() (*string, bool) { + if o == nil || IsNil(o.Threshold) { + return nil, false + } + return o.Threshold, true +} + +// HasThreshold returns a boolean if a field has been set. +func (o *NotificationSetting) HasThreshold() bool { + if o != nil && !IsNil(o.Threshold) { + return true + } + + return false +} + +// SetThreshold gets a reference to the given string and assigns it to the Threshold field. +func (o *NotificationSetting) SetThreshold(v string) { + o.Threshold = &v +} + +// GetThresholdExceededAt returns the ThresholdExceededAt field value if set, zero value otherwise (both if not set or set to explicit null). +func (o *NotificationSetting) GetThresholdExceededAt() string { + if o == nil || IsNil(o.ThresholdExceededAt.Get()) { + var ret string + return ret + } + return *o.ThresholdExceededAt.Get() +} + +// GetThresholdExceededAtOk returns a tuple with the ThresholdExceededAt field value if set, nil otherwise +// and a boolean to check if the value has been set. +// NOTE: If the value is an explicit nil, `nil, true` will be returned +func (o *NotificationSetting) GetThresholdExceededAtOk() (*string, bool) { + if o == nil { + return nil, false + } + return o.ThresholdExceededAt.Get(), o.ThresholdExceededAt.IsSet() +} + +// HasThresholdExceededAt returns a boolean if a field has been set. +func (o *NotificationSetting) HasThresholdExceededAt() bool { + if o != nil && o.ThresholdExceededAt.IsSet() { + return true + } + + return false +} + +// SetThresholdExceededAt gets a reference to the given NullableString and assigns it to the ThresholdExceededAt field. +func (o *NotificationSetting) SetThresholdExceededAt(v string) { + o.ThresholdExceededAt.Set(&v) +} +// SetThresholdExceededAtNil sets the value for ThresholdExceededAt to be an explicit nil +func (o *NotificationSetting) SetThresholdExceededAtNil() { + o.ThresholdExceededAt.Set(nil) +} + +// UnsetThresholdExceededAt ensures that no value is present for ThresholdExceededAt, not even an explicit nil +func (o *NotificationSetting) UnsetThresholdExceededAt() { + o.ThresholdExceededAt.Unset() +} + +func (o NotificationSetting) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o NotificationSetting) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Actions) { + toSerialize["actions"] = o.Actions + } + if !IsNil(o.Frequency) { + toSerialize["frequency"] = o.Frequency + } + if !IsNil(o.Id) { + toSerialize["id"] = o.Id + } + if o.LastCheckedAt.IsSet() { + toSerialize["lastCheckedAt"] = o.LastCheckedAt.Get() + } + if !IsNil(o.Threshold) { + toSerialize["threshold"] = o.Threshold + } + if o.ThresholdExceededAt.IsSet() { + toSerialize["thresholdExceededAt"] = o.ThresholdExceededAt.Get() + } + return toSerialize, nil +} + +type NullableNotificationSetting struct { + value *NotificationSetting + isSet bool +} + +func (v NullableNotificationSetting) Get() *NotificationSetting { + return v.value +} + +func (v *NullableNotificationSetting) Set(val *NotificationSetting) { + v.value = val + v.isSet = true +} + +func (v NullableNotificationSetting) IsSet() bool { + return v.isSet +} + +func (v *NullableNotificationSetting) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableNotificationSetting(val *NotificationSetting) *NullableNotificationSetting { + return &NullableNotificationSetting{value: val, isSet: true} +} + +func (v NullableNotificationSetting) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableNotificationSetting) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/bmusage/response.go b/bmusage/response.go new file mode 100644 index 0000000..06fbd18 --- /dev/null +++ b/bmusage/response.go @@ -0,0 +1,48 @@ +/* +bmusage + +This documents the rest api bmusage api provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package bmusage + +import ( + "net/http" +) + +// APIResponse stores the API response returned by the server. +type APIResponse struct { + *http.Response `json:"-"` + Message string `json:"message,omitempty"` + // Operation is the name of the OpenAPI operation. + Operation string `json:"operation,omitempty"` + // RequestURL is the request URL. This value is always available, even if the + // embedded *http.Response is nil. + RequestURL string `json:"url,omitempty"` + // Method is the HTTP method used for the request. This value is always + // available, even if the embedded *http.Response is nil. + Method string `json:"method,omitempty"` + // Payload holds the contents of the response body (which may be nil or empty). + // This is provided here as the raw response.Body() reader will have already + // been drained. + Payload []byte `json:"-"` +} + +// NewAPIResponse returns a new APIResponse object. +func NewAPIResponse(r *http.Response) *APIResponse { + + response := &APIResponse{Response: r} + return response +} + +// NewAPIResponseWithError returns a new APIResponse object with the provided error message. +func NewAPIResponseWithError(errorMessage string) *APIResponse { + + response := &APIResponse{Message: errorMessage} + return response +} diff --git a/bmusage/test/api_bmusage_test.go b/bmusage/test/api_bmusage_test.go new file mode 100644 index 0000000..043f23d --- /dev/null +++ b/bmusage/test/api_bmusage_test.go @@ -0,0 +1,197 @@ +/* +bmusage + +Testing BmusageAPIService + +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); + +package bmusage + +import ( + "context" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "testing" + openapiclient "github.com/leaseweb/leaseweb-go-sdk/bmusage" +) + +func Test_bmusage_BmusageAPIService(t *testing.T) { + + configuration := openapiclient.NewConfiguration() + apiClient := openapiclient.NewAPIClient(configuration) + + t.Run("Test BmusageAPIService CreateServerBandwidthNotificationSettingJson", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var serverId string + + resp, httpRes, err := apiClient.BmusageAPI.CreateServerBandwidthNotificationSettingJson(context.Background(), serverId).Execute() + + require.Nil(t, err) + require.NotNil(t, resp) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test BmusageAPIService CreateServerDataTrafficNotificationSetting", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var serverId string + + resp, httpRes, err := apiClient.BmusageAPI.CreateServerDataTrafficNotificationSetting(context.Background(), serverId).Execute() + + require.Nil(t, err) + require.NotNil(t, resp) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test BmusageAPIService DeleteServerBandwidthNotificationSetting", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var serverId string + var notificationSettingId string + + httpRes, err := apiClient.BmusageAPI.DeleteServerBandwidthNotificationSetting(context.Background(), serverId, notificationSettingId).Execute() + + require.Nil(t, err) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test BmusageAPIService DeleteServerDataTrafficNotificationSetting", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var serverId string + var notificationSettingId string + + httpRes, err := apiClient.BmusageAPI.DeleteServerDataTrafficNotificationSetting(context.Background(), serverId, notificationSettingId).Execute() + + require.Nil(t, err) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test BmusageAPIService GetServerBandwidthNotificationSetting", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var serverId string + var notificationSettingId string + + resp, httpRes, err := apiClient.BmusageAPI.GetServerBandwidthNotificationSetting(context.Background(), serverId, notificationSettingId).Execute() + + require.Nil(t, err) + require.NotNil(t, resp) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test BmusageAPIService GetServerBandwidthNotificationSettingList", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var serverId string + + resp, httpRes, err := apiClient.BmusageAPI.GetServerBandwidthNotificationSettingList(context.Background(), serverId).Execute() + + require.Nil(t, err) + require.NotNil(t, resp) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test BmusageAPIService GetServerDataTrafficMetrics", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var serverId string + + resp, httpRes, err := apiClient.BmusageAPI.GetServerDataTrafficMetrics(context.Background(), serverId).Execute() + + require.Nil(t, err) + require.NotNil(t, resp) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test BmusageAPIService GetServerDataTrafficNotificationSetting", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var serverId string + var notificationSettingId string + + resp, httpRes, err := apiClient.BmusageAPI.GetServerDataTrafficNotificationSetting(context.Background(), serverId, notificationSettingId).Execute() + + require.Nil(t, err) + require.NotNil(t, resp) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test BmusageAPIService GetServerDataTrafficNotificationSettingList", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var serverId string + + resp, httpRes, err := apiClient.BmusageAPI.GetServerDataTrafficNotificationSettingList(context.Background(), serverId).Execute() + + require.Nil(t, err) + require.NotNil(t, resp) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test BmusageAPIService ServersMetricsBandwidth", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var serverId string + + resp, httpRes, err := apiClient.BmusageAPI.ServersMetricsBandwidth(context.Background(), serverId).Execute() + + require.Nil(t, err) + require.NotNil(t, resp) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test BmusageAPIService UpdateServerBandwidthNotificationSetting", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var serverId string + var notificationSettingId string + + resp, httpRes, err := apiClient.BmusageAPI.UpdateServerBandwidthNotificationSetting(context.Background(), serverId, notificationSettingId).Execute() + + require.Nil(t, err) + require.NotNil(t, resp) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test BmusageAPIService UpdateServerDataTrafficNotificationSetting", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var serverId string + var notificationSettingId string + + resp, httpRes, err := apiClient.BmusageAPI.UpdateServerDataTrafficNotificationSetting(context.Background(), serverId, notificationSettingId).Execute() + + require.Nil(t, err) + require.NotNil(t, resp) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + +} diff --git a/bmusage/utils.go b/bmusage/utils.go new file mode 100644 index 0000000..c978e61 --- /dev/null +++ b/bmusage/utils.go @@ -0,0 +1,348 @@ +/* +bmusage + +This documents the rest api bmusage api provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package bmusage + +import ( + "encoding/json" + "reflect" + "time" +) + +// PtrBool is a helper routine that returns a pointer to given boolean value. +func PtrBool(v bool) *bool { return &v } + +// PtrInt is a helper routine that returns a pointer to given integer value. +func PtrInt(v int) *int { return &v } + +// PtrInt32 is a helper routine that returns a pointer to given integer value. +func PtrInt32(v int32) *int32 { return &v } + +// PtrInt64 is a helper routine that returns a pointer to given integer value. +func PtrInt64(v int64) *int64 { return &v } + +// PtrFloat32 is a helper routine that returns a pointer to given float value. +func PtrFloat32(v float32) *float32 { return &v } + +// PtrFloat64 is a helper routine that returns a pointer to given float value. +func PtrFloat64(v float64) *float64 { return &v } + +// PtrString is a helper routine that returns a pointer to given string value. +func PtrString(v string) *string { return &v } + +// PtrTime is helper routine that returns a pointer to given Time value. +func PtrTime(v time.Time) *time.Time { return &v } + +type NullableBool struct { + value *bool + isSet bool +} + +func (v NullableBool) Get() *bool { + return v.value +} + +func (v *NullableBool) Set(val *bool) { + v.value = val + v.isSet = true +} + +func (v NullableBool) IsSet() bool { + return v.isSet +} + +func (v *NullableBool) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableBool(val *bool) *NullableBool { + return &NullableBool{value: val, isSet: true} +} + +func (v NullableBool) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableBool) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + +type NullableInt struct { + value *int + isSet bool +} + +func (v NullableInt) Get() *int { + return v.value +} + +func (v *NullableInt) Set(val *int) { + v.value = val + v.isSet = true +} + +func (v NullableInt) IsSet() bool { + return v.isSet +} + +func (v *NullableInt) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableInt(val *int) *NullableInt { + return &NullableInt{value: val, isSet: true} +} + +func (v NullableInt) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableInt) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + +type NullableInt32 struct { + value *int32 + isSet bool +} + +func (v NullableInt32) Get() *int32 { + return v.value +} + +func (v *NullableInt32) Set(val *int32) { + v.value = val + v.isSet = true +} + +func (v NullableInt32) IsSet() bool { + return v.isSet +} + +func (v *NullableInt32) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableInt32(val *int32) *NullableInt32 { + return &NullableInt32{value: val, isSet: true} +} + +func (v NullableInt32) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableInt32) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + +type NullableInt64 struct { + value *int64 + isSet bool +} + +func (v NullableInt64) Get() *int64 { + return v.value +} + +func (v *NullableInt64) Set(val *int64) { + v.value = val + v.isSet = true +} + +func (v NullableInt64) IsSet() bool { + return v.isSet +} + +func (v *NullableInt64) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableInt64(val *int64) *NullableInt64 { + return &NullableInt64{value: val, isSet: true} +} + +func (v NullableInt64) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableInt64) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + +type NullableFloat32 struct { + value *float32 + isSet bool +} + +func (v NullableFloat32) Get() *float32 { + return v.value +} + +func (v *NullableFloat32) Set(val *float32) { + v.value = val + v.isSet = true +} + +func (v NullableFloat32) IsSet() bool { + return v.isSet +} + +func (v *NullableFloat32) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableFloat32(val *float32) *NullableFloat32 { + return &NullableFloat32{value: val, isSet: true} +} + +func (v NullableFloat32) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableFloat32) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + +type NullableFloat64 struct { + value *float64 + isSet bool +} + +func (v NullableFloat64) Get() *float64 { + return v.value +} + +func (v *NullableFloat64) Set(val *float64) { + v.value = val + v.isSet = true +} + +func (v NullableFloat64) IsSet() bool { + return v.isSet +} + +func (v *NullableFloat64) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableFloat64(val *float64) *NullableFloat64 { + return &NullableFloat64{value: val, isSet: true} +} + +func (v NullableFloat64) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableFloat64) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + +type NullableString struct { + value *string + isSet bool +} + +func (v NullableString) Get() *string { + return v.value +} + +func (v *NullableString) Set(val *string) { + v.value = val + v.isSet = true +} + +func (v NullableString) IsSet() bool { + return v.isSet +} + +func (v *NullableString) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableString(val *string) *NullableString { + return &NullableString{value: val, isSet: true} +} + +func (v NullableString) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableString) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + +type NullableTime struct { + value *time.Time + isSet bool +} + +func (v NullableTime) Get() *time.Time { + return v.value +} + +func (v *NullableTime) Set(val *time.Time) { + v.value = val + v.isSet = true +} + +func (v NullableTime) IsSet() bool { + return v.isSet +} + +func (v *NullableTime) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableTime(val *time.Time) *NullableTime { + return &NullableTime{value: val, isSet: true} +} + +func (v NullableTime) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableTime) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + +// IsNil checks if an input is nil +func IsNil(i interface{}) bool { + if i == nil { + return true + } + switch reflect.TypeOf(i).Kind() { + case reflect.Chan, reflect.Func, reflect.Map, reflect.Ptr, reflect.UnsafePointer, reflect.Interface, reflect.Slice: + return reflect.ValueOf(i).IsNil() + case reflect.Array: + return reflect.ValueOf(i).IsZero() + } + return false +} + +type MappedNullable interface { + ToMap() (map[string]interface{}, error) +} diff --git a/convert_types.go b/convert_types.go deleted file mode 100644 index 6b11ec3..0000000 --- a/convert_types.go +++ /dev/null @@ -1,13 +0,0 @@ -package leaseweb - -func String(v string) *string { - return &v -} - -func Bool(v bool) *bool { - return &v -} - -func Int(v int) *int { - return &v -} diff --git a/dedicated_network_equipment.go b/dedicated_network_equipment.go deleted file mode 100644 index abcfbe9..0000000 --- a/dedicated_network_equipment.go +++ /dev/null @@ -1,226 +0,0 @@ -package leaseweb - -import ( - "context" - "net/http" - - "github.com/LeaseWeb/leaseweb-go-sdk/options" -) - -const DEDICATED_NETWORK_EQUIPMENT_API_VERSION = "v2" - -type DedicatedNetworkEquipmentApi struct{} - -type DedicatedNetworkEquipments struct { - NetworkEquipments []DedicatedNetworkEquipment `json:"networkEquipments"` - Metadata Metadata `json:"_metadata"` -} - -type DedicatedNetworkEquipment struct { - Contract Contract `json:"contract"` - FeatureAvailability FeatureAvailability `json:"featureAvailability"` - Id string `json:"id"` - Name string `json:"name"` - Location Location `json:"location"` - NetworkInterfaces NetworkInterfaces `json:"networkInterfaces"` - PowerPorts []Port `json:"powerPorts"` - Type string `json:"type"` - SerialNumber string `json:"serialNumber"` - Rack DedicatedNetworkEquipmentRack `json:"rack"` - Specs DedicatedNetworkEquipmentSpec `json:"specs"` -} - -type DedicatedNetworkEquipmentRack struct { - Capacity string `json:"capacity"` - Id string `json:"id"` -} - -type DedicatedNetworkEquipmentSpec struct { - Brand string `json:"brand"` - Model string `json:"model"` -} - -type DedicatedNetworkEquipmentListOptions struct { - PaginationOptions - Reference *string `param:"reference"` - IP *string `param:"ip"` - MacAddress *string `param:"macAddress"` - Site *string `param:"site"` - PrivateRackID *string `param:"privateRackId"` - PrivateNetworkCapable *bool `param:"privateNetworkCapable"` - PrivateNetworkEnabled *bool `param:"privateNetworkEnabled"` -} - -type DedicatedNetworkEquipmentListIpsOptions struct { - PaginationOptions - NetworkType *string `param:"networkType"` - Version *string `param:"version"` - NullRouted *string `param:"nullRouted"` - IPs []string `param:"ips"` -} - -func (dnea DedicatedNetworkEquipmentApi) getPath(endpoint string) string { - return "/bareMetals/" + DEDICATED_NETWORK_EQUIPMENT_API_VERSION + endpoint -} - -func (dnea DedicatedNetworkEquipmentApi) List(ctx context.Context, opts DedicatedNetworkEquipmentListOptions) (*DedicatedNetworkEquipments, error) { - path := dnea.getPath("/networkEquipments") - query := options.Encode(opts) - result := &DedicatedNetworkEquipments{} - if err := doRequest(ctx, http.MethodGet, path, query, result); err != nil { - return nil, err - } - return result, nil -} - -func (dnea DedicatedNetworkEquipmentApi) Get(ctx context.Context, networkEquipmentId string) (*DedicatedNetworkEquipment, error) { - path := dnea.getPath("/networkEquipments/" + networkEquipmentId) - result := &DedicatedNetworkEquipment{} - if err := doRequest(ctx, http.MethodGet, path, "", result); err != nil { - return nil, err - } - return result, nil -} - -func (dnea DedicatedNetworkEquipmentApi) Update(ctx context.Context, networkEquipmentId, reference string) error { - payload := map[string]string{"reference": reference} - path := dnea.getPath("/networkEquipments/" + networkEquipmentId) - return doRequest(ctx, http.MethodPut, path, "", nil, payload) -} - -func (dnea DedicatedNetworkEquipmentApi) ListIps(ctx context.Context, networkEquipmentId string, opts DedicatedNetworkEquipmentListIpsOptions) (*Ips, error) { - path := dnea.getPath("/networkEquipments/" + networkEquipmentId + "/ips") - query := options.Encode(opts) - result := &Ips{} - if err := doRequest(ctx, http.MethodGet, path, query, result); err != nil { - return nil, err - } - return result, nil -} - -func (dnea DedicatedNetworkEquipmentApi) GetIp(ctx context.Context, networkEquipmentId, ip string) (*Ip, error) { - path := dnea.getPath("/networkEquipments/" + networkEquipmentId + "/ips/" + ip) - result := &Ip{} - if err := doRequest(ctx, http.MethodGet, path, "", result); err != nil { - return nil, err - } - return result, nil -} - -func (dnea DedicatedNetworkEquipmentApi) UpdateIp(ctx context.Context, networkEquipmentId, ip string, payload map[string]string) (*Ip, error) { - path := dnea.getPath("/networkEquipments/" + networkEquipmentId + "/ips/" + ip) - result := &Ip{} - if err := doRequest(ctx, http.MethodPut, path, "", result, payload); err != nil { - return nil, err - } - return result, nil -} - -func (dnea DedicatedNetworkEquipmentApi) NullRouteAnIp(ctx context.Context, networkEquipmentId, ip string) (*Ip, error) { - path := dnea.getPath("/networkEquipments/" + networkEquipmentId + "/ips/" + ip + "/null") - result := &Ip{} - if err := doRequest(ctx, http.MethodPost, path, "", result); err != nil { - return nil, err - } - return result, nil -} - -func (dnea DedicatedNetworkEquipmentApi) RemoveNullRouteAnIp(ctx context.Context, networkEquipmentId, ip string) (*Ip, error) { - path := dnea.getPath("/networkEquipments/" + networkEquipmentId + "/ips/" + ip + "/unnull") - result := &Ip{} - if err := doRequest(ctx, http.MethodPost, path, "", result); err != nil { - return nil, err - } - return result, nil -} - -func (dnea DedicatedNetworkEquipmentApi) ListNullRoutes(ctx context.Context, networkEquipmentId string, opts PaginationOptions) (*NullRoutes, error) { - path := dnea.getPath("/networkEquipments/" + networkEquipmentId + "/nullRouteHistory") - query := options.Encode(opts) - result := &NullRoutes{} - if err := doRequest(ctx, http.MethodGet, path, query, result); err != nil { - return nil, err - } - return result, nil -} - -func (dnea DedicatedNetworkEquipmentApi) ListCredentials(ctx context.Context, networkEquipmentId string, opts PaginationOptions) (*Credentials, error) { - result := &Credentials{} - path := dnea.getPath("/networkEquipments/" + networkEquipmentId + "/credentials") - query := options.Encode(opts) - if err := doRequest(ctx, http.MethodGet, path, query, result); err != nil { - return result, err - } - return result, nil -} - -func (dnea DedicatedNetworkEquipmentApi) CreateCredential(ctx context.Context, networkEquipmentId, credentialType, username, password string) (*Credential, error) { - result := &Credential{} - payload := make(map[string]string) - payload["type"] = credentialType - payload["username"] = username - payload["password"] = password - path := dnea.getPath("/networkEquipments/" + networkEquipmentId + "/credentials") - if err := doRequest(ctx, http.MethodPost, path, "", result, payload); err != nil { - return result, err - } - return result, nil -} - -func (dnea DedicatedNetworkEquipmentApi) ListCredentialsByType(ctx context.Context, networkEquipmentId, credentialType string, opts PaginationOptions) (*Credentials, error) { - result := &Credentials{} - path := dnea.getPath("/networkEquipments/" + networkEquipmentId + "/credentials/" + credentialType) - query := options.Encode(opts) - if err := doRequest(ctx, http.MethodGet, path, query, result); err != nil { - return result, err - } - return result, nil -} - -func (dnea DedicatedNetworkEquipmentApi) GetCredential(ctx context.Context, networkEquipmentId, credentialType, username string) (*Credential, error) { - result := &Credential{} - path := dnea.getPath("/networkEquipments/" + networkEquipmentId + "/credentials/" + credentialType + "/" + username) - if err := doRequest(ctx, http.MethodGet, path, "", result); err != nil { - return result, err - } - return result, nil -} - -func (dnea DedicatedNetworkEquipmentApi) DeleteCredential(ctx context.Context, networkEquipmentId, credentialType, username string) error { - path := dnea.getPath("/networkEquipments/" + networkEquipmentId + "/credentials/" + credentialType + "/" + username) - return doRequest(ctx, http.MethodDelete, path, "") -} - -func (dnea DedicatedNetworkEquipmentApi) UpdateCredential(ctx context.Context, networkEquipmentId, credentialType, username, password string) (*Credential, error) { - result := &Credential{} - payload := map[string]string{"password": password} - path := dnea.getPath("/networkEquipments/" + networkEquipmentId + "/credentials/" + credentialType + "/" + username) - if err := doRequest(ctx, http.MethodPut, path, "", result, payload); err != nil { - return result, err - } - return result, nil -} - -func (dnea DedicatedNetworkEquipmentApi) PowerCycleServer(ctx context.Context, networkEquipmentId string) error { - path := dnea.getPath("/networkEquipments/" + networkEquipmentId + "/powerCycle") - return doRequest(ctx, http.MethodPost, path, "") -} - -func (dnea DedicatedNetworkEquipmentApi) GetPowerStatus(ctx context.Context, networkEquipmentId string) (*PowerStatus, error) { - result := &PowerStatus{} - path := dnea.getPath("/networkEquipments/" + networkEquipmentId + "/powerInfo") - if err := doRequest(ctx, http.MethodGet, path, "", result); err != nil { - return result, err - } - return result, nil -} - -func (dnea DedicatedNetworkEquipmentApi) PowerOffServer(ctx context.Context, networkEquipmentId string) error { - path := dnea.getPath("/networkEquipments/" + networkEquipmentId + "/powerOff") - return doRequest(ctx, http.MethodPost, path, "") -} - -func (dnea DedicatedNetworkEquipmentApi) PowerOnServer(ctx context.Context, networkEquipmentId string) error { - path := dnea.getPath("/networkEquipments/" + networkEquipmentId + "/powerOn") - return doRequest(ctx, http.MethodPost, path, "") -} diff --git a/dedicated_network_equipment_test.go b/dedicated_network_equipment_test.go deleted file mode 100644 index 30f3d6b..0000000 --- a/dedicated_network_equipment_test.go +++ /dev/null @@ -1,2945 +0,0 @@ -package leaseweb - -import ( - "context" - "fmt" - "net/http" - "testing" - - "github.com/stretchr/testify/assert" -) - -func TestDedicatedNetworkEquipmentList(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "_metadata": { - "limit": 10, - "offset": 0, - "totalCount": 2 - }, - "networkEquipments": [ - { - "contract": { - "customerId": "10085996", - "deliveryStatus": "ACTIVE", - "id": "49031391001170", - "reference": "My Private Switch", - "salesOrgId": "2000" - }, - "featureAvailability": { - "automation": true, - "ipmiReboot": false, - "powerCycle": true, - "privateNetwork": false, - "remoteManagement": false - }, - "id": "12345", - "location": { - "rack": "YY11", - "site": "AMS-01", - "suite": "HALL3", - "unit": "21" - }, - "networkInterfaces": { - "internal": { - "gateway": null, - "ip": null, - "ports": [] - }, - "public": { - "gateway": "127.0.2.254", - "ip": "127.0.2.1/24", - "locationId": "", - "nullRouted": false, - "ports": [] - }, - "remoteManagement": { - "gateway": null, - "ip": null, - "locationId": null, - "ports": [] - } - }, - "type": "SWITCH" - }, - { - "contract": { - "customerId": "10085996", - "deliveryStatus": "ACTIVE", - "id": "49031513001110", - "reference": "My Other Private Switch", - "salesOrgId": "2000" - }, - "featureAvailability": { - "automation": false, - "ipmiReboot": false, - "powerCycle": false, - "privateNetwork": false, - "remoteManagement": false - }, - "id": "45678", - "location": { - "rack": "XX00", - "site": "AMS-01", - "suite": "HALL3", - "unit": "21" - }, - "networkInterfaces": { - "internal": { - "gateway": null, - "ip": null, - "ports": [] - }, - "public": { - "gateway": "127.1.1.254", - "ip": "127.1.1.68/24", - "locationId": "", - "nullRouted": false, - "ports": [] - }, - "remoteManagement": { - "gateway": null, - "ip": null, - "locationId": null, - "ports": [] - } - }, - "type": "SWITCH" - } - ] - }`) - }) - defer teardown() - - ctx := context.Background() - response, err := DedicatedNetworkEquipmentApi{}.List(ctx, DedicatedNetworkEquipmentListOptions{}) - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 2) - assert.Equal(response.Metadata.Offset, 0) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.NetworkEquipments), 2) - - NetworkEquipment1 := response.NetworkEquipments[0] - assert.Equal(NetworkEquipment1.Id, "12345") - assert.Equal(NetworkEquipment1.Contract.CustomerId, "10085996") - assert.Equal(NetworkEquipment1.Contract.DeliveryStatus, "ACTIVE") - assert.Equal(NetworkEquipment1.Contract.Id, "49031391001170") - assert.Equal(NetworkEquipment1.Contract.Reference, "My Private Switch") - assert.Equal(NetworkEquipment1.Contract.SalesOrgId, "2000") - assert.Equal(NetworkEquipment1.FeatureAvailability.Automation, true) - assert.Equal(NetworkEquipment1.FeatureAvailability.PrivateNetwork, false) - assert.Equal(NetworkEquipment1.FeatureAvailability.IpmiReboot, false) - assert.Equal(NetworkEquipment1.FeatureAvailability.PowerCycle, true) - assert.Equal(NetworkEquipment1.FeatureAvailability.RemoteManagement, false) - assert.Equal(NetworkEquipment1.Location.Rack, "YY11") - assert.Equal(NetworkEquipment1.Location.Site, "AMS-01") - assert.Equal(NetworkEquipment1.Location.Suite, "HALL3") - assert.Equal(NetworkEquipment1.Location.Unit, "21") - assert.Empty(NetworkEquipment1.NetworkInterfaces.Internal.Gateway) - assert.Empty(NetworkEquipment1.NetworkInterfaces.Internal.Ip) - assert.Equal(len(NetworkEquipment1.NetworkInterfaces.Internal.Ports), 0) - assert.Equal(NetworkEquipment1.NetworkInterfaces.Public.Gateway, "127.0.2.254") - assert.Equal(NetworkEquipment1.NetworkInterfaces.Public.Ip, "127.0.2.1/24") - assert.Equal(NetworkEquipment1.NetworkInterfaces.Public.LocationId, "") - assert.Equal(NetworkEquipment1.NetworkInterfaces.Public.NullRouted, false) - assert.Equal(len(NetworkEquipment1.NetworkInterfaces.Public.Ports), 0) - assert.Empty(NetworkEquipment1.NetworkInterfaces.RemoteManagement.Gateway) - assert.Empty(NetworkEquipment1.NetworkInterfaces.RemoteManagement.Ip) - assert.Empty(NetworkEquipment1.NetworkInterfaces.RemoteManagement.LocationId) - assert.Equal(len(NetworkEquipment1.NetworkInterfaces.RemoteManagement.Ports), 0) - assert.Equal(NetworkEquipment1.Type, "SWITCH") - - NetworkEquipment2 := response.NetworkEquipments[1] - assert.Equal(NetworkEquipment2.Id, "45678") - assert.Equal(NetworkEquipment2.Contract.CustomerId, "10085996") - assert.Equal(NetworkEquipment2.Contract.DeliveryStatus, "ACTIVE") - assert.Equal(NetworkEquipment2.Contract.Id, "49031513001110") - assert.Equal(NetworkEquipment2.Contract.Reference, "My Other Private Switch") - assert.Equal(NetworkEquipment2.Contract.SalesOrgId, "2000") - assert.Equal(NetworkEquipment2.FeatureAvailability.Automation, false) - assert.Equal(NetworkEquipment2.FeatureAvailability.PrivateNetwork, false) - assert.Equal(NetworkEquipment2.FeatureAvailability.IpmiReboot, false) - assert.Equal(NetworkEquipment2.FeatureAvailability.PowerCycle, false) - assert.Equal(NetworkEquipment2.FeatureAvailability.RemoteManagement, false) - assert.Equal(NetworkEquipment2.Location.Rack, "XX00") - assert.Equal(NetworkEquipment2.Location.Site, "AMS-01") - assert.Equal(NetworkEquipment2.Location.Suite, "HALL3") - assert.Equal(NetworkEquipment2.Location.Unit, "21") - assert.Empty(NetworkEquipment2.NetworkInterfaces.Internal.Gateway) - assert.Empty(NetworkEquipment2.NetworkInterfaces.Internal.Ip) - assert.Equal(len(NetworkEquipment2.NetworkInterfaces.Internal.Ports), 0) - assert.Equal(NetworkEquipment2.NetworkInterfaces.Public.Gateway, "127.1.1.254") - assert.Equal(NetworkEquipment2.NetworkInterfaces.Public.Ip, "127.1.1.68/24") - assert.Equal(NetworkEquipment2.NetworkInterfaces.Public.LocationId, "") - assert.Equal(NetworkEquipment2.NetworkInterfaces.Public.NullRouted, false) - assert.Equal(len(NetworkEquipment2.NetworkInterfaces.Public.Ports), 0) - assert.Empty(NetworkEquipment2.NetworkInterfaces.RemoteManagement.Gateway) - assert.Empty(NetworkEquipment2.NetworkInterfaces.RemoteManagement.Ip) - assert.Empty(NetworkEquipment2.NetworkInterfaces.RemoteManagement.LocationId) - assert.Equal(len(NetworkEquipment2.NetworkInterfaces.RemoteManagement.Ports), 0) - assert.Equal(NetworkEquipment2.Type, "SWITCH") -} - -func TestDedicatedNetworkEquipmentListBeEmpty(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{"_metadata":{"limit": 10, "offset": 0, "totalCount": 0}, "networkEquipments": []}`) - }) - defer teardown() - ctx := context.Background() - response, err := DedicatedNetworkEquipmentApi{}.List(ctx, DedicatedNetworkEquipmentListOptions{}) - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 0) - assert.Equal(response.Metadata.Offset, 0) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.NetworkEquipments), 0) -} - -func TestDedicatedNetworkEquipmentListPaginateAndFilter(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "_metadata": { - "limit": 10, - "offset": 1, - "totalCount": 11 - }, - "networkEquipments": [ - { - "contract": { - "customerId": "10085996", - "deliveryStatus": "ACTIVE", - "id": "49031391001170", - "reference": "My Private Switch", - "salesOrgId": "2000" - }, - "featureAvailability": { - "automation": true, - "ipmiReboot": false, - "powerCycle": true, - "privateNetwork": false, - "remoteManagement": false - }, - "id": "12345", - "location": { - "rack": "YY11", - "site": "AMS-01", - "suite": "HALL3", - "unit": "21" - }, - "networkInterfaces": { - "internal": { - "gateway": null, - "ip": null, - "ports": [] - }, - "public": { - "gateway": "127.0.2.254", - "ip": "127.0.2.1/24", - "locationId": "", - "nullRouted": false, - "ports": [] - }, - "remoteManagement": { - "gateway": null, - "ip": null, - "locationId": null, - "ports": [] - } - }, - "type": "SWITCH" - } - ] - }`) - }) - defer teardown() - - ctx := context.Background() - opts := DedicatedNetworkEquipmentListOptions{ - PaginationOptions: PaginationOptions{ - Limit: Int(1), - }, - } - response, err := DedicatedNetworkEquipmentApi{}.List(ctx, opts) - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 11) - assert.Equal(response.Metadata.Offset, 1) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.NetworkEquipments), 1) - - NetworkEquipment1 := response.NetworkEquipments[0] - assert.Equal(NetworkEquipment1.Id, "12345") - assert.Equal(NetworkEquipment1.Contract.CustomerId, "10085996") - assert.Equal(NetworkEquipment1.Contract.DeliveryStatus, "ACTIVE") - assert.Equal(NetworkEquipment1.Contract.Id, "49031391001170") - assert.Equal(NetworkEquipment1.Contract.Reference, "My Private Switch") - assert.Equal(NetworkEquipment1.Contract.SalesOrgId, "2000") - assert.Equal(NetworkEquipment1.FeatureAvailability.Automation, true) - assert.Equal(NetworkEquipment1.FeatureAvailability.PrivateNetwork, false) - assert.Equal(NetworkEquipment1.FeatureAvailability.IpmiReboot, false) - assert.Equal(NetworkEquipment1.FeatureAvailability.PowerCycle, true) - assert.Equal(NetworkEquipment1.FeatureAvailability.RemoteManagement, false) - assert.Equal(NetworkEquipment1.Location.Rack, "YY11") - assert.Equal(NetworkEquipment1.Location.Site, "AMS-01") - assert.Equal(NetworkEquipment1.Location.Suite, "HALL3") - assert.Equal(NetworkEquipment1.Location.Unit, "21") - assert.Empty(NetworkEquipment1.NetworkInterfaces.Internal.Gateway) - assert.Empty(NetworkEquipment1.NetworkInterfaces.Internal.Ip) - assert.Equal(len(NetworkEquipment1.NetworkInterfaces.Internal.Ports), 0) - assert.Equal(NetworkEquipment1.NetworkInterfaces.Public.Gateway, "127.0.2.254") - assert.Equal(NetworkEquipment1.NetworkInterfaces.Public.Ip, "127.0.2.1/24") - assert.Equal(NetworkEquipment1.NetworkInterfaces.Public.LocationId, "") - assert.Equal(NetworkEquipment1.NetworkInterfaces.Public.NullRouted, false) - assert.Equal(len(NetworkEquipment1.NetworkInterfaces.Public.Ports), 0) - assert.Empty(NetworkEquipment1.NetworkInterfaces.RemoteManagement.Gateway) - assert.Empty(NetworkEquipment1.NetworkInterfaces.RemoteManagement.Ip) - assert.Empty(NetworkEquipment1.NetworkInterfaces.RemoteManagement.LocationId) - assert.Equal(len(NetworkEquipment1.NetworkInterfaces.RemoteManagement.Ports), 0) - assert.Equal(NetworkEquipment1.Type, "SWITCH") -} - -func TestDedicatedNetworkEquipmentListServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedNetworkEquipmentApi{}.List(ctx, DedicatedNetworkEquipmentListOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "Access to the requested resource is forbidden."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedNetworkEquipmentApi{}.List(ctx, DedicatedNetworkEquipmentListOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "Access to the requested resource is forbidden.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedNetworkEquipmentApi{}.List(ctx, DedicatedNetworkEquipmentListOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedNetworkEquipmentApi{}.List(ctx, DedicatedNetworkEquipmentListOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedNetworkEquipmentGet(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "contract": { - "aggregationPackId": null, - "billingCycle": 1, - "billingFrequency": "MONTH", - "contractTerm": 12, - "contractType": "NORMAL", - "currency": "EUR", - "customerId": "10085996", - "deliveryStatus": "ACTIVE", - "endsAt": null, - "id": "49031391001170", - "networkTraffic": { - "connectivityType": "INTERCONNECTED", - "datatrafficLimit": null, - "datatrafficUnit": null, - "trafficType": null, - "type": null - }, - "pricePerFrequency": 0.00, - "reference": "My Switch", - "salesOrgId": "2000", - "sla": "Platinum", - "startsAt": "2017-08-01T00:00:00Z", - "status": "ACTIVE", - "subnets": [] - }, - "featureAvailability": { - "automation": true, - "ipmiReboot": false, - "powerCycle": true, - "privateNetwork": false, - "remoteManagement": false - }, - "id": "12345", - "location": { - "rack": "YY11", - "site": "AMS-01", - "suite": "HALL3", - "unit": "21" - }, - "name": "ABC-DE-001", - "networkInterfaces": { - "internal": { - "gateway": null, - "ip": null, - "ports": [] - }, - "public": { - "gateway": "127.0.0.254", - "ip": "127.0.0.124/24", - "locationId": "", - "nullRouted": false, - "ports": [] - }, - "remoteManagement": { - "gateway": null, - "ip": null, - "locationId": null, - "ports": [] - } - }, - "powerPorts": [ - { - "name": "AMS-01-HALL3-YY11-PDU01", - "port": "7" - } - ], - "rack": { - "capacity": "", - "id": "11111" - }, - "serialNumber": "XN51FPD0QX", - "specs": { - "brand": "HP", - "model": "PC 2530-48 J9781A" - }, - "type": "SWITCH" - }`) - }) - defer teardown() - - ctx := context.Background() - NetworkEquipment, err := DedicatedNetworkEquipmentApi{}.Get(ctx, "12345") - assert := assert.New(t) - assert.Nil(err) - - assert.Equal(NetworkEquipment.Contract.CustomerId, "10085996") - assert.Equal(NetworkEquipment.Contract.DeliveryStatus, "ACTIVE") - assert.Equal(NetworkEquipment.Contract.Id, "49031391001170") - assert.Equal(NetworkEquipment.Contract.Reference, "My Switch") - assert.Equal(NetworkEquipment.Contract.SalesOrgId, "2000") - assert.Equal(NetworkEquipment.Contract.BillingCycle.String(), "1") - assert.Equal(NetworkEquipment.Contract.BillingFrequency, "MONTH") - assert.Equal(NetworkEquipment.Contract.ContractTerm.String(), "12") - assert.Equal(NetworkEquipment.Contract.Currency, "EUR") - assert.Empty(NetworkEquipment.Contract.EndsAt) - assert.Empty(NetworkEquipment.Contract.NetworkTraffic.DataTrafficLimit) - assert.Empty(NetworkEquipment.Contract.NetworkTraffic.DataTrafficUnit) - assert.Empty(NetworkEquipment.Contract.NetworkTraffic.TrafficType) - assert.Empty(NetworkEquipment.Contract.NetworkTraffic.Type) - assert.Equal(NetworkEquipment.Contract.NetworkTraffic.ConnectivityType, "INTERCONNECTED") - assert.Equal(NetworkEquipment.Contract.PricePerFrequency.String(), "0.00") - assert.Equal(NetworkEquipment.Contract.Sla, "Platinum") - assert.Equal(NetworkEquipment.Contract.StartsAt, "2017-08-01T00:00:00Z") - assert.Empty(NetworkEquipment.Contract.AggregationPackId) - assert.Equal(NetworkEquipment.Contract.ContractType, "NORMAL") - assert.Equal(NetworkEquipment.Contract.Status, "ACTIVE") - assert.Equal(len(NetworkEquipment.Contract.Subnets), 0) - assert.Equal(NetworkEquipment.Id, "12345") - assert.Equal(NetworkEquipment.FeatureAvailability.Automation, true) - assert.Equal(NetworkEquipment.FeatureAvailability.PrivateNetwork, false) - assert.Equal(NetworkEquipment.FeatureAvailability.IpmiReboot, false) - assert.Equal(NetworkEquipment.FeatureAvailability.PowerCycle, true) - assert.Equal(NetworkEquipment.FeatureAvailability.RemoteManagement, false) - assert.Equal(NetworkEquipment.Location.Rack, "YY11") - assert.Equal(NetworkEquipment.Location.Site, "AMS-01") - assert.Equal(NetworkEquipment.Location.Suite, "HALL3") - assert.Equal(NetworkEquipment.Location.Unit, "21") - assert.Empty(NetworkEquipment.NetworkInterfaces.Internal.Gateway) - assert.Empty(NetworkEquipment.NetworkInterfaces.Internal.Ip) - assert.Equal(len(NetworkEquipment.NetworkInterfaces.Internal.Ports), 0) - assert.Equal(NetworkEquipment.NetworkInterfaces.Public.Gateway, "127.0.0.254") - assert.Equal(NetworkEquipment.NetworkInterfaces.Public.Ip, "127.0.0.124/24") - assert.Equal(NetworkEquipment.NetworkInterfaces.Public.LocationId, "") - assert.Equal(NetworkEquipment.NetworkInterfaces.Public.NullRouted, false) - assert.Equal(len(NetworkEquipment.NetworkInterfaces.Public.Ports), 0) - assert.Empty(NetworkEquipment.NetworkInterfaces.RemoteManagement.Gateway) - assert.Empty(NetworkEquipment.NetworkInterfaces.RemoteManagement.Ip) - assert.Empty(NetworkEquipment.NetworkInterfaces.RemoteManagement.LocationId) - assert.Equal(len(NetworkEquipment.NetworkInterfaces.RemoteManagement.Ports), 0) - assert.Equal(NetworkEquipment.PowerPorts[0].Name, "AMS-01-HALL3-YY11-PDU01") - assert.Equal(NetworkEquipment.PowerPorts[0].Port, "7") - assert.Equal(NetworkEquipment.Specs.Brand, "HP") - assert.Equal(NetworkEquipment.Specs.Model, "PC 2530-48 J9781A") - assert.Equal(NetworkEquipment.Rack.Capacity, "") - assert.Equal(NetworkEquipment.Rack.Id, "11111") - assert.Equal(NetworkEquipment.SerialNumber, "XN51FPD0QX") - assert.Equal(NetworkEquipment.Type, "SWITCH") -} - -func TestDedicatedNetworkEquipmentGetServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedNetworkEquipmentApi{}.Get(ctx, "12345") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "Access to the requested resource is forbidden."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedNetworkEquipmentApi{}.Get(ctx, "12345") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "Access to the requested resource is forbidden.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedNetworkEquipmentApi{}.Get(ctx, "12345") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedNetworkEquipmentApi{}.Get(ctx, "12345") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedNetworkEquipmentUpdate(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusNoContent) - }) - defer teardown() - - ctx := context.Background() - err := DedicatedNetworkEquipmentApi{}.Update(ctx, "2893829", "new reference") - assert := assert.New(t) - assert.Nil(err) -} - -func TestDedicatedNetworkEquipmentUpdateServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedNetworkEquipmentApi{}.Update(ctx, "2893829", "new reference") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "Access to the requested resource is forbidden."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedNetworkEquipmentApi{}.Update(ctx, "2893829", "new reference") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "Access to the requested resource is forbidden.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedNetworkEquipmentApi{}.Update(ctx, "2893829", "new reference") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedNetworkEquipmentApi{}.Update(ctx, "2893829", "new reference") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedNetworkEquipmentListIps(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "_metadata": { - "limit": 10, - "offset": 0, - "totalCount": 2 - }, - "ips": [ - { - "ddos": { - "detectionProfile": "ADVANCED_LOW_UDP", - "protectionType": "ADVANCED" - }, - "floatingIp": false, - "gateway": "12.123.123.254", - "ip": "12.123.123.1/24", - "mainIp": true, - "networkType": "PUBLIC", - "nullRouted": true, - "reverseLookup": "domain.example.com", - "version": 4 - }, - { - "ddos": { - "detectionProfile": "STANDARD_DEFAULT", - "protectionType": "STANDARD" - }, - "floatingIp": false, - "gateway": "2001:db8:85a3::8a2e:370:1", - "ip": "2001:db8:85a3::8a2e:370:7334/64", - "mainIp": false, - "networkType": "REMOTE_MANAGEMENT", - "nullRouted": false, - "reverseLookup": "domain.example.com", - "version": 6 - } - ] - }`) - }) - defer teardown() - - ctx := context.Background() - response, err := DedicatedNetworkEquipmentApi{}.ListIps(ctx, "server-id", DedicatedNetworkEquipmentListIpsOptions{}) - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 2) - assert.Equal(response.Metadata.Offset, 0) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.Ips), 2) - - Ip1 := response.Ips[0] - assert.Equal(Ip1.DDOS.DetectionProfile, "ADVANCED_LOW_UDP") - assert.Equal(Ip1.DDOS.ProtectionType, "ADVANCED") - assert.Equal(Ip1.FloatingIp, false) - assert.Equal(Ip1.Gateway, "12.123.123.254") - assert.Equal(Ip1.Ip, "12.123.123.1/24") - assert.Equal(Ip1.MainIp, true) - assert.Equal(Ip1.NetworkType, "PUBLIC") - assert.Equal(Ip1.NullRouted, true) - assert.Equal(Ip1.ReverseLookup, "domain.example.com") - assert.Equal(Ip1.Version.String(), "4") - - Ip2 := response.Ips[1] - assert.Equal(Ip2.DDOS.DetectionProfile, "STANDARD_DEFAULT") - assert.Equal(Ip2.DDOS.ProtectionType, "STANDARD") - assert.Equal(Ip2.FloatingIp, false) - assert.Equal(Ip2.Gateway, "2001:db8:85a3::8a2e:370:1") - assert.Equal(Ip2.Ip, "2001:db8:85a3::8a2e:370:7334/64") - assert.Equal(Ip2.MainIp, false) - assert.Equal(Ip2.NetworkType, "REMOTE_MANAGEMENT") - assert.Equal(Ip2.NullRouted, false) - assert.Equal(Ip2.ReverseLookup, "domain.example.com") - assert.Equal(Ip2.Version.String(), "6") -} - -func TestDedicatedNetworkEquipmentListIpsBeEmpty(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{"_metadata":{"limit": 10, "offset": 0, "totalCount": 0}, "ips": []}`) - }) - defer teardown() - ctx := context.Background() - response, err := DedicatedNetworkEquipmentApi{}.ListIps(ctx, "server-id", DedicatedNetworkEquipmentListIpsOptions{}) - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 0) - assert.Equal(response.Metadata.Offset, 0) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.Ips), 0) -} - -func TestDedicatedNetworkEquipmentListIpsFilterAndPagination(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "_metadata": { - "limit": 10, - "offset": 1, - "totalCount": 11 - }, - "ips": [ - { - "ddos": { - "detectionProfile": "ADVANCED_LOW_UDP", - "protectionType": "ADVANCED" - }, - "floatingIp": false, - "gateway": "12.123.123.254", - "ip": "12.123.123.1/24", - "mainIp": true, - "networkType": "PUBLIC", - "nullRouted": true, - "reverseLookup": "domain.example.com", - "version": 4 - } - ] - }`) - }) - defer teardown() - - ctx := context.Background() - opts := DedicatedNetworkEquipmentListIpsOptions{ - PaginationOptions: PaginationOptions{ - Limit: Int(1), - Offset: Int(10), - }, - } - response, err := DedicatedNetworkEquipmentApi{}.ListIps(ctx, "server-id", opts) - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 11) - assert.Equal(response.Metadata.Offset, 1) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.Ips), 1) - - Ip1 := response.Ips[0] - assert.Equal(Ip1.DDOS.DetectionProfile, "ADVANCED_LOW_UDP") - assert.Equal(Ip1.DDOS.ProtectionType, "ADVANCED") - assert.Equal(Ip1.FloatingIp, false) - assert.Equal(Ip1.Gateway, "12.123.123.254") - assert.Equal(Ip1.Ip, "12.123.123.1/24") - assert.Equal(Ip1.MainIp, true) - assert.Equal(Ip1.NetworkType, "PUBLIC") - assert.Equal(Ip1.NullRouted, true) - assert.Equal(Ip1.ReverseLookup, "domain.example.com") - assert.Equal(Ip1.Version.String(), "4") -} - -func TestDedicatedNetworkEquipmentListIpsServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedNetworkEquipmentApi{}.ListIps(ctx, "server-id", DedicatedNetworkEquipmentListIpsOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "Access to the requested resource is forbidden."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedNetworkEquipmentApi{}.ListIps(ctx, "server-id", DedicatedNetworkEquipmentListIpsOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "Access to the requested resource is forbidden.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedNetworkEquipmentApi{}.ListIps(ctx, "server-id", DedicatedNetworkEquipmentListIpsOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedNetworkEquipmentApi{}.ListIps(ctx, "server-id", DedicatedNetworkEquipmentListIpsOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedNetworkEquipmentGetIp(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "ddos": { - "detectionProfile": "ADVANCED_LOW_UDP", - "protectionType": "ADVANCED" - }, - "floatingIp": false, - "gateway": "12.123.123.254", - "ip": "12.123.123.1/24", - "mainIp": true, - "networkType": "PUBLIC", - "nullRouted": true, - "reverseLookup": "domain.example.com", - "version": 4 - }`) - }) - defer teardown() - - ctx := context.Background() - Ip, err := DedicatedNetworkEquipmentApi{}.GetIp(ctx, "12345", "127.0.0.6") - assert := assert.New(t) - assert.Nil(err) - assert.Equal(Ip.DDOS.DetectionProfile, "ADVANCED_LOW_UDP") - assert.Equal(Ip.DDOS.ProtectionType, "ADVANCED") - assert.Equal(Ip.FloatingIp, false) - assert.Equal(Ip.Gateway, "12.123.123.254") - assert.Equal(Ip.Ip, "12.123.123.1/24") - assert.Equal(Ip.MainIp, true) - assert.Equal(Ip.NetworkType, "PUBLIC") - assert.Equal(Ip.NullRouted, true) - assert.Equal(Ip.ReverseLookup, "domain.example.com") - assert.Equal(Ip.Version.String(), "4") -} - -func TestDedicatedNetworkEquipmentGetIpServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedNetworkEquipmentApi{}.GetIp(ctx, "12345", "127.0.0.6") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedNetworkEquipmentApi{}.GetIp(ctx, "12345", "127.0.0.6") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "404", "errorMessage": "Resource not found"}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedNetworkEquipmentApi{}.GetIp(ctx, "12345", "127.0.0.6") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "404", - Message: "Resource not found", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedNetworkEquipmentApi{}.GetIp(ctx, "12345", "127.0.0.6") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedNetworkEquipmentApi{}.GetIp(ctx, "12345", "127.0.0.6") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedNetworkEquipmentUpdateIp(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "ddos": { - "detectionProfile": "ADVANCED_DEFAULT", - "protectionType": "ADVANCED" - }, - "floatingIp": false, - "gateway": "12.123.123.254", - "ip": "12.123.123.1/24", - "mainIp": true, - "networkType": "PUBLIC", - "nullRouted": true, - "reverseLookup": "domain.example.com", - "version": 4 - }`) - }) - defer teardown() - - payload := map[string]string{"detectionProfile": "ADVANCED_DEFAULT", "reverseLookup": "domain.example.com"} - ctx := context.Background() - Ip, err := DedicatedNetworkEquipmentApi{}.UpdateIp(ctx, "12345", "127.0.0.6", payload) - assert := assert.New(t) - assert.Nil(err) - assert.Equal(Ip.DDOS.DetectionProfile, "ADVANCED_DEFAULT") - assert.Equal(Ip.DDOS.ProtectionType, "ADVANCED") - assert.Equal(Ip.FloatingIp, false) - assert.Equal(Ip.Gateway, "12.123.123.254") - assert.Equal(Ip.Ip, "12.123.123.1/24") - assert.Equal(Ip.MainIp, true) - assert.Equal(Ip.NetworkType, "PUBLIC") - assert.Equal(Ip.NullRouted, true) - assert.Equal(Ip.ReverseLookup, "domain.example.com") - assert.Equal(Ip.Version.String(), "4") -} - -func TestDedicatedNetworkEquipmentUpdateIpServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - payload := map[string]string{"detectionProfile": "ADVANCED_DEFAULT", "reverseLookup": "domain.example.com"} - ctx := context.Background() - return DedicatedNetworkEquipmentApi{}.UpdateIp(ctx, "12345", "127.0.0.6", payload) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - payload := map[string]string{"detectionProfile": "ADVANCED_DEFAULT", "reverseLookup": "domain.example.com"} - ctx := context.Background() - return DedicatedNetworkEquipmentApi{}.UpdateIp(ctx, "12345", "127.0.0.6", payload) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "404", "errorMessage": "Resource not found"}`) - }, - FunctionCall: func() (interface{}, error) { - payload := map[string]string{"detectionProfile": "ADVANCED_DEFAULT", "reverseLookup": "domain.example.com"} - ctx := context.Background() - return DedicatedNetworkEquipmentApi{}.UpdateIp(ctx, "12345", "127.0.0.6", payload) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "404", - Message: "Resource not found", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - payload := map[string]string{"detectionProfile": "ADVANCED_DEFAULT", "reverseLookup": "domain.example.com"} - ctx := context.Background() - return DedicatedNetworkEquipmentApi{}.UpdateIp(ctx, "12345", "127.0.0.6", payload) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - payload := map[string]string{"detectionProfile": "ADVANCED_DEFAULT", "reverseLookup": "domain.example.com"} - ctx := context.Background() - return DedicatedNetworkEquipmentApi{}.UpdateIp(ctx, "12345", "127.0.0.6", payload) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedNetworkEquipmentNullRouteAnIp(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "ddos": { - "detectionProfile": "ADVANCED_DEFAULT", - "protectionType": "ADVANCED" - }, - "floatingIp": false, - "gateway": "12.123.123.254", - "ip": "12.123.123.1/24", - "mainIp": true, - "networkType": "PUBLIC", - "nullRouted": false, - "reverseLookup": "domain.example.com", - "version": 4 - }`) - }) - defer teardown() - - ctx := context.Background() - Ip, err := DedicatedNetworkEquipmentApi{}.NullRouteAnIp(ctx, "12345", "127.0.0.6") - assert := assert.New(t) - assert.Nil(err) - assert.Equal(Ip.DDOS.DetectionProfile, "ADVANCED_DEFAULT") - assert.Equal(Ip.DDOS.ProtectionType, "ADVANCED") - assert.Equal(Ip.FloatingIp, false) - assert.Equal(Ip.Gateway, "12.123.123.254") - assert.Equal(Ip.Ip, "12.123.123.1/24") - assert.Equal(Ip.MainIp, true) - assert.Equal(Ip.NetworkType, "PUBLIC") - assert.Equal(Ip.NullRouted, false) - assert.Equal(Ip.ReverseLookup, "domain.example.com") - assert.Equal(Ip.Version.String(), "4") -} - -func TestDedicatedNetworkEquipmentNullRouteAnIpServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedNetworkEquipmentApi{}.NullRouteAnIp(ctx, "12345", "127.0.0.6") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedNetworkEquipmentApi{}.NullRouteAnIp(ctx, "12345", "127.0.0.6") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "404", "errorMessage": "Resource not found"}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedNetworkEquipmentApi{}.NullRouteAnIp(ctx, "12345", "127.0.0.6") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "404", - Message: "Resource not found", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedNetworkEquipmentApi{}.NullRouteAnIp(ctx, "12345", "127.0.0.6") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedNetworkEquipmentApi{}.NullRouteAnIp(ctx, "12345", "127.0.0.6") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedNetworkEquipmentRemoveNullRouteAnIp(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "ddos": { - "detectionProfile": "ADVANCED_DEFAULT", - "protectionType": "ADVANCED" - }, - "floatingIp": false, - "gateway": "12.123.123.254", - "ip": "12.123.123.1/24", - "mainIp": true, - "networkType": "PUBLIC", - "nullRouted": false, - "reverseLookup": "domain.example.com", - "version": 4 - }`) - }) - defer teardown() - - ctx := context.Background() - Ip, err := DedicatedNetworkEquipmentApi{}.RemoveNullRouteAnIp(ctx, "12345", "127.0.0.6") - assert := assert.New(t) - assert.Nil(err) - assert.Equal(Ip.DDOS.DetectionProfile, "ADVANCED_DEFAULT") - assert.Equal(Ip.DDOS.ProtectionType, "ADVANCED") - assert.Equal(Ip.FloatingIp, false) - assert.Equal(Ip.Gateway, "12.123.123.254") - assert.Equal(Ip.Ip, "12.123.123.1/24") - assert.Equal(Ip.MainIp, true) - assert.Equal(Ip.NetworkType, "PUBLIC") - assert.Equal(Ip.NullRouted, false) - assert.Equal(Ip.ReverseLookup, "domain.example.com") - assert.Equal(Ip.Version.String(), "4") -} - -func TestDedicatedNetworkEquipmentRemoveNullRouteAnIpServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedNetworkEquipmentApi{}.RemoveNullRouteAnIp(ctx, "12345", "127.0.0.6") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedNetworkEquipmentApi{}.RemoveNullRouteAnIp(ctx, "12345", "127.0.0.6") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "404", "errorMessage": "Resource not found"}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedNetworkEquipmentApi{}.RemoveNullRouteAnIp(ctx, "12345", "127.0.0.6") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "404", - Message: "Resource not found", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedNetworkEquipmentApi{}.RemoveNullRouteAnIp(ctx, "12345", "127.0.0.6") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedNetworkEquipmentApi{}.RemoveNullRouteAnIp(ctx, "12345", "127.0.0.6") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedNetworkEquipmentListNullRoutes(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "_metadata": { - "limit": 10, - "offset": 0, - "totalCount": 1 - }, - "nullRoutes": [ - { - "automatedUnnullingAt": "2016-08-12T07:45:33+00:00", - "comment": "Device Null Route related to DDoS Mitigation", - "ip": "1.1.1.1/32", - "nullLevel": 3, - "nulledAt": "2016-08-12T07:40:27+00:00", - "ticketId": "282912" - } - ] - }`) - }) - defer teardown() - - ctx := context.Background() - response, err := DedicatedNetworkEquipmentApi{}.ListNullRoutes(ctx, "server-id", PaginationOptions{}) - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 1) - assert.Equal(response.Metadata.Offset, 0) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.NullRoutes), 1) - - NullRoute := response.NullRoutes[0] - assert.Equal(NullRoute.AutomatedUnnullingAt, "2016-08-12T07:45:33+00:00") - assert.Equal(NullRoute.Comment, "Device Null Route related to DDoS Mitigation") - assert.Equal(NullRoute.Ip, "1.1.1.1/32") - assert.Equal(NullRoute.NullLevel.String(), "3") - assert.Equal(NullRoute.NulledAt, "2016-08-12T07:40:27+00:00") - assert.Equal(NullRoute.TicketId, "282912") -} - -func TestDedicatedNetworkEquipmentListNullRoutesBeEmpty(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{"_metadata":{"limit": 10, "offset": 0, "totalCount": 0}, "nullRoutes": []}`) - }) - defer teardown() - ctx := context.Background() - response, err := DedicatedNetworkEquipmentApi{}.ListNullRoutes(ctx, "server-id", PaginationOptions{}) - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 0) - assert.Equal(response.Metadata.Offset, 0) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.NullRoutes), 0) -} - -func TestDedicatedNetworkEquipmentListNullRoutesFilterAndPagination(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "_metadata": { - "limit": 10, - "offset": 1, - "totalCount": 11 - }, - "nullRoutes": [ - { - "automatedUnnullingAt": "2016-08-12T07:45:33+00:00", - "comment": "Device Null Route related to DDoS Mitigation", - "ip": "1.1.1.1/32", - "nullLevel": 3, - "nulledAt": "2016-08-12T07:40:27+00:00", - "ticketId": "282912" - } - ] - }`) - }) - defer teardown() - - ctx := context.Background() - opts := PaginationOptions{ - Limit: Int(1), - } - response, err := DedicatedNetworkEquipmentApi{}.ListNullRoutes(ctx, "server-id", opts) - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 11) - assert.Equal(response.Metadata.Offset, 1) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.NullRoutes), 1) - - NullRoute := response.NullRoutes[0] - assert.Equal(NullRoute.AutomatedUnnullingAt, "2016-08-12T07:45:33+00:00") - assert.Equal(NullRoute.Comment, "Device Null Route related to DDoS Mitigation") - assert.Equal(NullRoute.Ip, "1.1.1.1/32") - assert.Equal(NullRoute.NullLevel.String(), "3") - assert.Equal(NullRoute.NulledAt, "2016-08-12T07:40:27+00:00") - assert.Equal(NullRoute.TicketId, "282912") -} - -func TestDedicatedNetworkEquipmentListNullRoutesServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedNetworkEquipmentApi{}.ListNullRoutes(ctx, "server-id", PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "Access to the requested resource is forbidden."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedNetworkEquipmentApi{}.ListNullRoutes(ctx, "server-id", PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "Access to the requested resource is forbidden.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedNetworkEquipmentApi{}.ListNullRoutes(ctx, "server-id", PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedNetworkEquipmentApi{}.ListNullRoutes(ctx, "server-id", PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedNetworkEquipmentListCredentials(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "_metadata": { - "limit": 10, - "offset": 0, - "totalCount": 4 - }, - "credentials": [ - { - "type": "REMOTE_MANAGEMENT", - "username": "admin" - }, - { - "type": "REMOTE_MANAGEMENT", - "username": "root" - }, - { - "type": "OPERATING_SYSTEM", - "username": "root" - }, - { - "type": "OPERATING_SYSTEM", - "username": "user" - } - ] - }`) - }) - defer teardown() - - ctx := context.Background() - response, err := DedicatedNetworkEquipmentApi{}.ListCredentials(ctx, "99944", PaginationOptions{}) - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 4) - assert.Equal(response.Metadata.Offset, 0) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.Credentials), 4) - - assert.Equal(response.Credentials[0].Type, "REMOTE_MANAGEMENT") - assert.Equal(response.Credentials[0].Username, "admin") - assert.Equal(response.Credentials[1].Type, "REMOTE_MANAGEMENT") - assert.Equal(response.Credentials[1].Username, "root") - assert.Equal(response.Credentials[2].Type, "OPERATING_SYSTEM") - assert.Equal(response.Credentials[2].Username, "root") - assert.Equal(response.Credentials[3].Type, "OPERATING_SYSTEM") - assert.Equal(response.Credentials[3].Username, "user") -} - -func TestDedicatedNetworkEquipmentListCredentialsBeEmpty(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{"_metadata":{"limit": 10, "offset": 0, "totalCount": 0}, "credentials": []}`) - }) - defer teardown() - ctx := context.Background() - response, err := DedicatedNetworkEquipmentApi{}.ListCredentials(ctx, "99944", PaginationOptions{}) - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 0) - assert.Equal(response.Metadata.Offset, 0) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.Credentials), 0) -} - -func TestDedicatedNetworkEquipmentListCredentialsPaginate(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "_metadata": { - "limit": 10, - "offset": 1, - "totalCount": 11 - }, - "credentials": [ - { - "type": "REMOTE_MANAGEMENT", - "username": "admin" - } - ] - }`) - }) - defer teardown() - - ctx := context.Background() - response, err := DedicatedNetworkEquipmentApi{}.ListCredentials(ctx, "99944", PaginationOptions{}) - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 11) - assert.Equal(response.Metadata.Offset, 1) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.Credentials), 1) - - assert.Equal(response.Credentials[0].Type, "REMOTE_MANAGEMENT") - assert.Equal(response.Credentials[0].Username, "admin") -} - -func TestDedicatedNetworkEquipmentListCredentialsServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedNetworkEquipmentApi{}.ListCredentials(ctx, "99944", PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedNetworkEquipmentApi{}.ListCredentials(ctx, "99944", PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "404", "errorMessage": "Resource not found"}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedNetworkEquipmentApi{}.ListCredentials(ctx, "99944", PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "404", - Message: "Resource not found", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedNetworkEquipmentApi{}.ListCredentials(ctx, "99944", PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedNetworkEquipmentApi{}.ListCredentials(ctx, "99944", PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedNetworkEquipmentCreateCredential(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "password": "mys3cr3tp@ssw0rd", - "type": "OPERATING_SYSTEM", - "username": "root" - }`) - }) - defer teardown() - - ctx := context.Background() - resp, err := DedicatedNetworkEquipmentApi{}.CreateCredential(ctx, "12345", "OPERATING_SYSTEM", "root", "mys3cr3tp@ssw0rd") - assert := assert.New(t) - assert.Nil(err) - - assert.Equal(resp.Type, "OPERATING_SYSTEM") - assert.Equal(resp.Username, "root") - assert.Equal(resp.Password, "mys3cr3tp@ssw0rd") -} - -func TestDedicatedNetworkEquipmentCreateCredentialServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedNetworkEquipmentApi{}.CreateCredential(ctx, "12345", "OPERATING_SYSTEM", "root", "mys3cr3tp@ssw0rd") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedNetworkEquipmentApi{}.CreateCredential(ctx, "12345", "OPERATING_SYSTEM", "root", "mys3cr3tp@ssw0rd") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "404", "errorMessage": "Resource not found"}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedNetworkEquipmentApi{}.CreateCredential(ctx, "12345", "OPERATING_SYSTEM", "root", "mys3cr3tp@ssw0rd") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "404", - Message: "Resource not found", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedNetworkEquipmentApi{}.CreateCredential(ctx, "12345", "OPERATING_SYSTEM", "root", "mys3cr3tp@ssw0rd") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedNetworkEquipmentApi{}.CreateCredential(ctx, "12345", "OPERATING_SYSTEM", "root", "mys3cr3tp@ssw0rd") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedNetworkEquipmentListCredentialsByType(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "_metadata": { - "limit": 10, - "offset": 0, - "totalCount": 2 - }, - "credentials": [ - { - "type": "REMOTE_MANAGEMENT", - "username": "admin" - }, - { - "type": "REMOTE_MANAGEMENT", - "username": "root" - } - ] - }`) - }) - defer teardown() - - ctx := context.Background() - response, err := DedicatedNetworkEquipmentApi{}.ListCredentialsByType(ctx, "99944", "REMOTE_MANAGEMENT", PaginationOptions{}) - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 2) - assert.Equal(response.Metadata.Offset, 0) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.Credentials), 2) - - assert.Equal(response.Credentials[0].Type, "REMOTE_MANAGEMENT") - assert.Equal(response.Credentials[0].Username, "admin") - assert.Equal(response.Credentials[1].Type, "REMOTE_MANAGEMENT") - assert.Equal(response.Credentials[1].Username, "root") -} - -func TestDedicatedNetworkEquipmentListCredentialsByTypeBeEmpty(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{"_metadata":{"limit": 10, "offset": 0, "totalCount": 0}, "credentials": []}`) - }) - defer teardown() - ctx := context.Background() - response, err := DedicatedNetworkEquipmentApi{}.ListCredentialsByType(ctx, "99944", "REMOTE_MANAGEMENT", PaginationOptions{}) - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 0) - assert.Equal(response.Metadata.Offset, 0) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.Credentials), 0) -} - -func TestDedicatedNetworkEquipmentListCredentialsByTypePaginate(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "_metadata": { - "limit": 10, - "offset": 1, - "totalCount": 11 - }, - "credentials": [ - { - "type": "REMOTE_MANAGEMENT", - "username": "admin" - } - ] - }`) - }) - defer teardown() - - ctx := context.Background() - response, err := DedicatedNetworkEquipmentApi{}.ListCredentialsByType(ctx, "99944", "REMOTE_MANAGEMENT", PaginationOptions{}) - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 11) - assert.Equal(response.Metadata.Offset, 1) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.Credentials), 1) - - assert.Equal(response.Credentials[0].Type, "REMOTE_MANAGEMENT") - assert.Equal(response.Credentials[0].Username, "admin") -} - -func TestDedicatedNetworkEquipmentListCredentialsByTypeServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedNetworkEquipmentApi{}.ListCredentialsByType(ctx, "99944", "REMOTE_MANAGEMENT", PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedNetworkEquipmentApi{}.ListCredentialsByType(ctx, "99944", "REMOTE_MANAGEMENT", PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "404", "errorMessage": "Resource not found"}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedNetworkEquipmentApi{}.ListCredentialsByType(ctx, "99944", "REMOTE_MANAGEMENT", PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "404", - Message: "Resource not found", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedNetworkEquipmentApi{}.ListCredentialsByType(ctx, "99944", "REMOTE_MANAGEMENT", PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedNetworkEquipmentApi{}.ListCredentialsByType(ctx, "99944", "REMOTE_MANAGEMENT", PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedNetworkEquipmentGetCredentials(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "password": "mys3cr3tp@ssw0rd", - "type": "OPERATING_SYSTEM", - "username": "root" - }`) - }) - defer teardown() - - ctx := context.Background() - Credential, err := DedicatedNetworkEquipmentApi{}.GetCredential(ctx, "12345", "OPERATING_SYSTEM", "root") - assert := assert.New(t) - assert.Nil(err) - assert.Equal(Credential.Password, "mys3cr3tp@ssw0rd") - assert.Equal(Credential.Username, "root") - assert.Equal(Credential.Type, "OPERATING_SYSTEM") -} - -func TestDedicatedNetworkEquipmentGetCredentialsServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedNetworkEquipmentApi{}.GetCredential(ctx, "12345", "OPERATING_SYSTEM", "root") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedNetworkEquipmentApi{}.GetCredential(ctx, "12345", "OPERATING_SYSTEM", "root") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "404", "errorMessage": "Resource not found"}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedNetworkEquipmentApi{}.GetCredential(ctx, "12345", "OPERATING_SYSTEM", "root") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "404", - Message: "Resource not found", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedNetworkEquipmentApi{}.GetCredential(ctx, "12345", "OPERATING_SYSTEM", "root") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedNetworkEquipmentApi{}.GetCredential(ctx, "12345", "OPERATING_SYSTEM", "root") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedNetworkEquipmentCredentials(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusNoContent) - }) - defer teardown() - - ctx := context.Background() - err := DedicatedNetworkEquipmentApi{}.DeleteCredential(ctx, "12345", "OPERATING_SYSTEM", "admin") - assert := assert.New(t) - assert.Nil(err) -} - -func TestDedicatedNetworkEquipmentCredentialsServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedNetworkEquipmentApi{}.DeleteCredential(ctx, "12345", "OPERATING_SYSTEM", "admin") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedNetworkEquipmentApi{}.DeleteCredential(ctx, "12345", "OPERATING_SYSTEM", "admin") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "404", "errorMessage": "Resource not found"}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedNetworkEquipmentApi{}.DeleteCredential(ctx, "12345", "OPERATING_SYSTEM", "admin") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "404", - Message: "Resource not found", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedNetworkEquipmentApi{}.DeleteCredential(ctx, "12345", "OPERATING_SYSTEM", "admin") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedNetworkEquipmentApi{}.DeleteCredential(ctx, "12345", "OPERATING_SYSTEM", "admin") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedNetworkEquipmentUpdateCredentials(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "password": "new password", - "type": "OPERATING_SYSTEM", - "username": "admin" - }`) - }) - defer teardown() - - ctx := context.Background() - resp, err := DedicatedNetworkEquipmentApi{}.UpdateCredential(ctx, "12345", "OPERATING_SYSTEM", "admin", "new password") - assert := assert.New(t) - assert.Nil(err) - - assert.Equal(resp.Password, "new password") - assert.Equal(resp.Type, "OPERATING_SYSTEM") - assert.Equal(resp.Username, "admin") -} - -func TestDedicatedNetworkEquipmentUpdateCredentialsServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedNetworkEquipmentApi{}.UpdateCredential(ctx, "12345", "OPERATING_SYSTEM", "admin", "new password") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedNetworkEquipmentApi{}.UpdateCredential(ctx, "12345", "OPERATING_SYSTEM", "admin", "new password") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "404", "errorMessage": "Resource not found"}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedNetworkEquipmentApi{}.UpdateCredential(ctx, "12345", "OPERATING_SYSTEM", "admin", "new password") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "404", - Message: "Resource not found", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedNetworkEquipmentApi{}.UpdateCredential(ctx, "12345", "OPERATING_SYSTEM", "admin", "new password") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedNetworkEquipmentApi{}.UpdateCredential(ctx, "12345", "OPERATING_SYSTEM", "admin", "new password") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedNetworkEquipmentPowerCycleServer(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusNoContent) - }) - defer teardown() - - ctx := context.Background() - err := DedicatedNetworkEquipmentApi{}.PowerCycleServer(ctx, "server id") - assert := assert.New(t) - assert.Nil(err) -} - -func TestDedicatedNetworkEquipmentPowerCycleServerServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedNetworkEquipmentApi{}.PowerCycleServer(ctx, "server id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedNetworkEquipmentApi{}.PowerCycleServer(ctx, "server id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "404", "errorMessage": "Resource not found"}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedNetworkEquipmentApi{}.PowerCycleServer(ctx, "server id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "404", - Message: "Resource not found", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedNetworkEquipmentApi{}.PowerCycleServer(ctx, "server id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedNetworkEquipmentApi{}.PowerCycleServer(ctx, "server id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedNetworkEquipmentPowerOffServer(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusNoContent) - }) - defer teardown() - - ctx := context.Background() - err := DedicatedNetworkEquipmentApi{}.PowerOffServer(ctx, "server id") - assert := assert.New(t) - assert.Nil(err) -} - -func TestDedicatedNetworkEquipmentPowerOffServerServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedNetworkEquipmentApi{}.PowerOffServer(ctx, "server id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedNetworkEquipmentApi{}.PowerOffServer(ctx, "server id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "404", "errorMessage": "Resource not found"}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedNetworkEquipmentApi{}.PowerOffServer(ctx, "server id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "404", - Message: "Resource not found", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedNetworkEquipmentApi{}.PowerOffServer(ctx, "server id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedNetworkEquipmentApi{}.PowerOffServer(ctx, "server id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedNetworkEquipmentPowerOnServer(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusNoContent) - }) - defer teardown() - - ctx := context.Background() - err := DedicatedNetworkEquipmentApi{}.PowerOnServer(ctx, "server id") - assert := assert.New(t) - assert.Nil(err) -} - -func TestDedicatedNetworkEquipmentPowerOnServerServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedNetworkEquipmentApi{}.PowerOnServer(ctx, "server id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedNetworkEquipmentApi{}.PowerOnServer(ctx, "server id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "404", "errorMessage": "Resource not found"}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedNetworkEquipmentApi{}.PowerOnServer(ctx, "server id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "404", - Message: "Resource not found", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedNetworkEquipmentApi{}.PowerOnServer(ctx, "server id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedNetworkEquipmentApi{}.PowerOnServer(ctx, "server id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedNetworkEquipmentGetPowerStatus(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "ipmi": { - "status": "off" - }, - "pdu": { - "status": "on" - } - }`) - }) - defer teardown() - - ctx := context.Background() - resp, err := DedicatedNetworkEquipmentApi{}.GetPowerStatus(ctx, "server-id") - assert := assert.New(t) - assert.Nil(err) - - assert.Equal(resp.Ipmi.Status, "off") - assert.Equal(resp.Pdu.Status, "on") -} - -func TestDedicatedNetworkEquipmentGetPowerStatusServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedNetworkEquipmentApi{}.GetPowerStatus(ctx, "server-id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedNetworkEquipmentApi{}.GetPowerStatus(ctx, "server-id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "404", "errorMessage": "Resource not found"}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedNetworkEquipmentApi{}.GetPowerStatus(ctx, "server-id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "404", - Message: "Resource not found", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedNetworkEquipmentApi{}.GetPowerStatus(ctx, "server-id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedNetworkEquipmentApi{}.GetPowerStatus(ctx, "server-id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} diff --git a/dedicated_rack.go b/dedicated_rack.go deleted file mode 100644 index c4fc79b..0000000 --- a/dedicated_rack.go +++ /dev/null @@ -1,321 +0,0 @@ -package leaseweb - -import ( - "context" - "net/http" - - "github.com/LeaseWeb/leaseweb-go-sdk/options" -) - -const DEDICATED_RACK_API_VERSION = "v2" - -type DedicatedRackApi struct{} - -type DedicatedRacks struct { - PrivateRacks []DedicatedRack `json:"privateRacks"` - Metadata Metadata `json:"_metadata"` -} - -type DedicatedRack struct { - Contract Contract `json:"contract"` - FeatureAvailability FeatureAvailability `json:"featureAvailability"` - Id string `json:"id"` - Location Location `json:"location"` - NetworkInterfaces NetworkInterfaces `json:"networkInterfaces"` - PowerPorts []Port `json:"powerPorts"` - Units []DedicatedRackUnit `json:"units"` -} - -type DedicatedRackUnit struct { - Unit string `json:"unit"` - Status string `json:"status"` - ConnectedUnits []string `json:"connectedUnits"` -} - -type DedicatedRackListOptions struct { - PaginationOptions - Reference *string `param:"reference"` - PrivateNetworkCapable *bool `param:"privateNetworkCapable"` - PrivateNetworkEnabled *bool `param:"privateNetworkEnabled"` -} - -type DedicatedRackListIpsOptions struct { - PaginationOptions - NetworkType *string `param:"networkType"` - Version *string `param:"version"` - NullRouted *string `param:"nullRouted"` - IPs []string `param:"ips"` -} - -func (dra DedicatedRackApi) getPath(endpoint string) string { - return "/bareMetals/" + DEDICATED_RACK_API_VERSION + endpoint -} - -func (dra DedicatedRackApi) List(ctx context.Context, opts DedicatedRackListOptions) (*DedicatedRacks, error) { - path := dra.getPath("/privateRacks") - query := options.Encode(opts) - result := &DedicatedRacks{} - if err := doRequest(ctx, http.MethodGet, path, query, result); err != nil { - return nil, err - } - return result, nil -} - -func (dra DedicatedRackApi) Get(ctx context.Context, privateRackId string) (*DedicatedRack, error) { - path := dra.getPath("/privateRacks/" + privateRackId) - result := &DedicatedRack{} - if err := doRequest(ctx, http.MethodGet, path, "", result); err != nil { - return nil, err - } - return result, nil -} - -func (dra DedicatedRackApi) Update(ctx context.Context, privateRackId, reference string) error { - payload := map[string]string{"reference": reference} - path := dra.getPath("/privateRacks/" + privateRackId) - return doRequest(ctx, http.MethodPut, path, "", nil, payload) -} - -func (dra DedicatedRackApi) ListNullRoutes(ctx context.Context, privateRackId string, opts PaginationOptions) (*NullRoutes, error) { - path := dra.getPath("/privateRacks/" + privateRackId + "/nullRouteHistory") - query := options.Encode(opts) - result := &NullRoutes{} - if err := doRequest(ctx, http.MethodGet, path, query, result); err != nil { - return nil, err - } - return result, nil -} - -func (dra DedicatedRackApi) ListIps(ctx context.Context, privateRackId string, opts DedicatedRackListIpsOptions) (*Ips, error) { - path := dra.getPath("/privateRacks/" + privateRackId + "/ips") - query := options.Encode(opts) - result := &Ips{} - if err := doRequest(ctx, http.MethodGet, path, query, result); err != nil { - return nil, err - } - return result, nil -} - -func (dra DedicatedRackApi) GetIp(ctx context.Context, privateRackId, ip string) (*Ip, error) { - path := dra.getPath("/privateRacks/" + privateRackId + "/ips/" + ip) - result := &Ip{} - if err := doRequest(ctx, http.MethodGet, path, "", result); err != nil { - return nil, err - } - return result, nil -} - -func (dra DedicatedRackApi) UpdateIp(ctx context.Context, privateRackId, ip string, payload map[string]string) (*Ip, error) { - path := dra.getPath("/privateRacks/" + privateRackId + "/ips/" + ip) - result := &Ip{} - if err := doRequest(ctx, http.MethodPut, path, "", result, payload); err != nil { - return nil, err - } - return result, nil -} - -func (dra DedicatedRackApi) NullRouteAnIp(ctx context.Context, privateRackId, ip string) (*Ip, error) { - path := dra.getPath("/privateRacks/" + privateRackId + "/ips/" + ip + "/null") - result := &Ip{} - if err := doRequest(ctx, http.MethodPost, path, "", result); err != nil { - return nil, err - } - return result, nil -} - -func (dra DedicatedRackApi) RemoveNullRouteAnIp(ctx context.Context, privateRackId, ip string) (*Ip, error) { - path := dra.getPath("/privateRacks/" + privateRackId + "/ips/" + ip + "/unnull") - result := &Ip{} - if err := doRequest(ctx, http.MethodPost, path, "", result); err != nil { - return nil, err - } - return result, nil -} - -func (dra DedicatedRackApi) ListCredentials(ctx context.Context, privateRackId string, opts PaginationOptions) (*Credentials, error) { - result := &Credentials{} - query := options.Encode(opts) - path := dra.getPath("/privateRacks/" + privateRackId + "/credentials") - if err := doRequest(ctx, http.MethodGet, path, query, result); err != nil { - return result, err - } - return result, nil -} - -func (dra DedicatedRackApi) CreateCredential(ctx context.Context, privateRackId, credentialType, username, password string) (*Credential, error) { - result := &Credential{} - payload := make(map[string]string) - payload["type"] = credentialType - payload["username"] = username - payload["password"] = password - path := dra.getPath("/privateRacks/" + privateRackId + "/credentials") - if err := doRequest(ctx, http.MethodPost, path, "", result, payload); err != nil { - return result, err - } - return result, nil -} - -func (dra DedicatedRackApi) ListCredentialsByType(ctx context.Context, privateRackId, credentialType string, opts PaginationOptions) (*Credentials, error) { - result := &Credentials{} - path := dra.getPath("/privateRacks/" + privateRackId + "/credentials/" + credentialType) - query := options.Encode(opts) - if err := doRequest(ctx, http.MethodGet, path, query, result); err != nil { - return result, err - } - return result, nil -} - -func (dra DedicatedRackApi) GetCredential(ctx context.Context, privateRackId, credentialType, username string) (*Credential, error) { - result := &Credential{} - path := dra.getPath("/privateRacks/" + privateRackId + "/credentials/" + credentialType + "/" + username) - if err := doRequest(ctx, http.MethodGet, path, "", result); err != nil { - return result, err - } - return result, nil -} - -func (dra DedicatedRackApi) DeleteCredential(ctx context.Context, privateRackId, credentialType, username string) error { - path := dra.getPath("/privateRacks/" + privateRackId + "/credentials/" + credentialType + "/" + username) - return doRequest(ctx, http.MethodDelete, path, "") -} - -func (dra DedicatedRackApi) UpdateCredential(ctx context.Context, privateRackId, credentialType, username, password string) (*Credential, error) { - result := &Credential{} - payload := map[string]string{"password": password} - path := dra.getPath("/privateRacks/" + privateRackId + "/credentials/" + credentialType + "/" + username) - if err := doRequest(ctx, http.MethodPut, path, "", result, payload); err != nil { - return result, err - } - return result, nil -} - -func (dra DedicatedRackApi) GetDataTrafficMetrics(ctx context.Context, privateRackId string, opts MetricsOptions) (*DataTrafficMetricsV1, error) { - path := dra.getPath("/privateRacks/" + privateRackId + "/metrics/datatraffic") - query := options.Encode(opts) - result := &DataTrafficMetricsV1{} - if err := doRequest(ctx, http.MethodGet, path, query, result); err != nil { - return nil, err - } - return result, nil -} - -func (dra DedicatedRackApi) GetBandWidthMetrics(ctx context.Context, privateRackId string, opts MetricsOptions) (*BandWidthMetrics, error) { - path := dra.getPath("/privateRacks/" + privateRackId + "/metrics/bandwidth") - query := options.Encode(opts) - result := &BandWidthMetrics{} - if err := doRequest(ctx, http.MethodGet, path, query, result); err != nil { - return nil, err - } - return result, nil -} - -func (dra DedicatedRackApi) GetDdosNotificationSetting(ctx context.Context, privateRackId string) (*DdosNotificationSetting, error) { - result := &DdosNotificationSetting{} - path := dra.getPath("/privateRacks/" + privateRackId + "/notificationSettings/ddos") - if err := doRequest(ctx, http.MethodGet, path, "", result); err != nil { - return result, err - } - return result, nil -} - -func (dra DedicatedRackApi) UpdateDdosNotificationSetting(ctx context.Context, privateRackId string, payload map[string]string) error { - path := dra.getPath("/privateRacks/" + privateRackId + "/notificationSettings/ddos") - if err := doRequest(ctx, http.MethodPut, path, "", nil, payload); err != nil { - return err - } - return nil -} - -func (dra DedicatedRackApi) ListBandWidthNotificationSettings(ctx context.Context, privateRackId string, opts PaginationOptions) (*BandWidthNotificationSettings, error) { - result := &BandWidthNotificationSettings{} - query := options.Encode(opts) - path := dra.getPath("/privateRacks/" + privateRackId + "/notificationSettings/bandwidth") - if err := doRequest(ctx, http.MethodGet, path, query, result); err != nil { - return result, err - } - return result, nil -} - -func (dra DedicatedRackApi) CreateBandWidthNotificationSetting(ctx context.Context, privateRackId, frequency, threshold, unit string) (*NotificationSetting, error) { - payload := map[string]string{ - "frequency": frequency, - "threshold": threshold, - "unit": unit, - } - result := &NotificationSetting{} - path := dra.getPath("/privateRacks/" + privateRackId + "/notificationSettings/bandwidth") - if err := doRequest(ctx, http.MethodPost, path, "", result, payload); err != nil { - return result, err - } - return result, nil -} - -func (dra DedicatedRackApi) DeleteBandWidthNotificationSetting(ctx context.Context, privateRackId, notificationId string) error { - path := dra.getPath("/privateRacks/" + privateRackId + "/notificationSettings/bandwidth/" + notificationId) - return doRequest(ctx, http.MethodDelete, path, "") -} - -func (dra DedicatedRackApi) GetBandWidthNotificationSetting(ctx context.Context, privateRackId, notificationId string) (*NotificationSetting, error) { - result := &NotificationSetting{} - path := dra.getPath("/privateRacks/" + privateRackId + "/notificationSettings/bandwidth/" + notificationId) - if err := doRequest(ctx, http.MethodGet, path, "", result); err != nil { - return result, err - } - return result, nil -} - -func (dra DedicatedRackApi) UpdateBandWidthNotificationSetting(ctx context.Context, privateRackId, notificationSettingId string, payload map[string]string) (*NotificationSetting, error) { - result := &NotificationSetting{} - path := dra.getPath("/privateRacks/" + privateRackId + "/notificationSettings/bandwidth/" + notificationSettingId) - if err := doRequest(ctx, http.MethodPut, path, "", result, payload); err != nil { - return result, err - } - return result, nil -} - -func (dra DedicatedRackApi) ListDataTrafficNotificationSettings(ctx context.Context, privateRackId string, opts PaginationOptions) (*DataTrafficNotificationSettings, error) { - result := &DataTrafficNotificationSettings{} - path := dra.getPath("/privateRacks/" + privateRackId + "/notificationSettings/datatraffic") - query := options.Encode(opts) - if err := doRequest(ctx, http.MethodGet, path, query, result); err != nil { - return result, err - } - return result, nil -} - -func (dra DedicatedRackApi) CreateDataTrafficNotificationSetting(ctx context.Context, privateRackId, frequency, threshold, unit string) (*NotificationSetting, error) { - payload := map[string]string{ - "frequency": frequency, - "threshold": threshold, - "unit": unit, - } - result := &NotificationSetting{} - path := dra.getPath("/privateRacks/" + privateRackId + "/notificationSettings/datatraffic") - if err := doRequest(ctx, http.MethodPost, path, "", result, payload); err != nil { - return result, err - } - return result, nil -} - -func (dra DedicatedRackApi) DeleteDataTrafficNotificationSetting(ctx context.Context, privateRackId, notificationId string) error { - path := dra.getPath("/privateRacks/" + privateRackId + "/notificationSettings/datatraffic/" + notificationId) - return doRequest(ctx, http.MethodDelete, path, "") -} - -func (dra DedicatedRackApi) GetDataTrafficNotificationSetting(ctx context.Context, privateRackId, notificationId string) (*NotificationSetting, error) { - result := &NotificationSetting{} - path := dra.getPath("/privateRacks/" + privateRackId + "/notificationSettings/datatraffic/" + notificationId) - if err := doRequest(ctx, http.MethodGet, path, "", result); err != nil { - return result, err - } - return result, nil -} - -func (dra DedicatedRackApi) UpdateDataTrafficNotificationSetting(ctx context.Context, privateRackId, notificationSettingId string, payload map[string]string) (*NotificationSetting, error) { - result := &NotificationSetting{} - path := dra.getPath("/privateRacks/" + privateRackId + "/notificationSettings/datatraffic/" + notificationSettingId) - if err := doRequest(ctx, http.MethodPut, path, "", result, payload); err != nil { - return result, err - } - return result, nil -} diff --git a/dedicated_rack_test.go b/dedicated_rack_test.go deleted file mode 100644 index 24fd841..0000000 --- a/dedicated_rack_test.go +++ /dev/null @@ -1,4326 +0,0 @@ -package leaseweb - -import ( - "context" - "fmt" - "net/http" - "testing" - - "github.com/stretchr/testify/assert" -) - -func TestDedicatedRackList(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "_metadata": { - "limit": 10, - "offset": 0, - "totalCount": 2 - }, - "privateRacks": [ - { - "contract": { - "customerId": "2738283", - "deliveryStatus": "ACTIVE", - "id": "123456", - "reference": "AAAA - Private rack 001", - "salesOrgId": "2000" - }, - "featureAvailability": { - "powerCycle": false, - "privateNetwork": false - }, - "id": "123456", - "location": { - "rack": "22", - "site": "AMS-01", - "suite": "8.24" - }, - "networkInterfaces": { - "public": { - "ports": [ - { - "name": "EVO-BB99-1", - "port": "0-9" - } - ] - } - } - }, - { - "contract": { - "customerId": "2738283", - "deliveryStatus": "ACTIVE", - "id": "267940", - "reference": "AAAA - Private rack 002", - "salesOrgId": "2000" - }, - "featureAvailability": { - "powerCycle": false, - "privateNetwork": false - }, - "id": "267940", - "location": { - "rack": "MX66", - "site": "AMS-01", - "suite": "Hall3" - }, - "networkInterfaces": { - "public": { - "ports": [ - { - "name": "ce99.ams-01", - "port": "0-1" - } - ] - } - } - } - ] - }`) - }) - defer teardown() - - ctx := context.Background() - response, err := DedicatedRackApi{}.List(ctx, DedicatedRackListOptions{}) - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 2) - assert.Equal(response.Metadata.Offset, 0) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.PrivateRacks), 2) - - Rack1 := response.PrivateRacks[0] - assert.Equal(Rack1.Id, "123456") - assert.Equal(Rack1.Contract.CustomerId, "2738283") - assert.Equal(Rack1.Contract.DeliveryStatus, "ACTIVE") - assert.Equal(Rack1.Contract.Id, "123456") - assert.Equal(Rack1.Contract.Reference, "AAAA - Private rack 001") - assert.Equal(Rack1.Contract.SalesOrgId, "2000") - assert.Equal(Rack1.FeatureAvailability.PowerCycle, false) - assert.Equal(Rack1.FeatureAvailability.PrivateNetwork, false) - assert.Equal(Rack1.Location.Rack, "22") - assert.Equal(Rack1.Location.Site, "AMS-01") - assert.Equal(Rack1.Location.Suite, "8.24") - assert.Equal(Rack1.NetworkInterfaces.Public.Ports[0].Name, "EVO-BB99-1") - assert.Equal(Rack1.NetworkInterfaces.Public.Ports[0].Port, "0-9") - - Rack2 := response.PrivateRacks[1] - assert.Equal(Rack2.Id, "267940") - assert.Equal(Rack2.Contract.CustomerId, "2738283") - assert.Equal(Rack2.Contract.DeliveryStatus, "ACTIVE") - assert.Equal(Rack2.Contract.Id, "267940") - assert.Equal(Rack2.Contract.Reference, "AAAA - Private rack 002") - assert.Equal(Rack2.Contract.SalesOrgId, "2000") - assert.Equal(Rack2.FeatureAvailability.PowerCycle, false) - assert.Equal(Rack2.FeatureAvailability.PrivateNetwork, false) - assert.Equal(Rack2.Location.Rack, "MX66") - assert.Equal(Rack2.Location.Site, "AMS-01") - assert.Equal(Rack2.Location.Suite, "Hall3") - assert.Equal(Rack2.NetworkInterfaces.Public.Ports[0].Name, "ce99.ams-01") - assert.Equal(Rack2.NetworkInterfaces.Public.Ports[0].Port, "0-1") -} - -func TestDedicatedRackListBeEmpty(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{"_metadata":{"limit": 10, "offset": 0, "totalCount": 0}, "privateRacks": []}`) - }) - defer teardown() - ctx := context.Background() - response, err := DedicatedRackApi{}.List(ctx, DedicatedRackListOptions{}) - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 0) - assert.Equal(response.Metadata.Offset, 0) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.PrivateRacks), 0) -} - -func TestDedicatedRackListPaginateAndFilter(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "_metadata": { - "limit": 10, - "offset": 1, - "totalCount": 11 - }, - "privateRacks": [ - { - "contract": { - "customerId": "2738283", - "deliveryStatus": "ACTIVE", - "id": "123456", - "reference": "AAAA - Private rack 001", - "salesOrgId": "2000" - }, - "featureAvailability": { - "powerCycle": false, - "privateNetwork": false - }, - "id": "123456", - "location": { - "rack": "22", - "site": "AMS-01", - "suite": "8.24" - }, - "networkInterfaces": { - "public": { - "ports": [ - { - "name": "EVO-BB99-1", - "port": "0-9" - } - ] - } - } - } - ] - }`) - }) - defer teardown() - - ctx := context.Background() - opts := DedicatedRackListOptions{ - PaginationOptions: PaginationOptions{ - Limit: Int(1), - }, - } - response, err := DedicatedRackApi{}.List(ctx, opts) - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 11) - assert.Equal(response.Metadata.Offset, 1) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.PrivateRacks), 1) - - Rack1 := response.PrivateRacks[0] - assert.Equal(Rack1.Id, "123456") - assert.Equal(Rack1.Contract.CustomerId, "2738283") - assert.Equal(Rack1.Contract.DeliveryStatus, "ACTIVE") - assert.Equal(Rack1.Contract.Id, "123456") - assert.Equal(Rack1.Contract.Reference, "AAAA - Private rack 001") - assert.Equal(Rack1.Contract.SalesOrgId, "2000") - assert.Equal(Rack1.FeatureAvailability.PowerCycle, false) - assert.Equal(Rack1.FeatureAvailability.PrivateNetwork, false) - assert.Equal(Rack1.Location.Rack, "22") - assert.Equal(Rack1.Location.Site, "AMS-01") - assert.Equal(Rack1.Location.Suite, "8.24") - assert.Equal(Rack1.NetworkInterfaces.Public.Ports[0].Name, "EVO-BB99-1") - assert.Equal(Rack1.NetworkInterfaces.Public.Ports[0].Port, "0-9") -} - -func TestDedicatedRackListServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedRackApi{}.List(ctx, DedicatedRackListOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "Access to the requested resource is forbidden."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedRackApi{}.List(ctx, DedicatedRackListOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "Access to the requested resource is forbidden.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedRackApi{}.List(ctx, DedicatedRackListOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedRackApi{}.List(ctx, DedicatedRackListOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedRackGet(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "contract": { - "customerId": "2738283", - "deliveryStatus": "ACTIVE", - "endsAt": null, - "id": "2893829", - "networkTraffic": { - "datatrafficLimit": 0, - "datatrafficUnit": null, - "trafficType": "CUSTOM", - "type": "CONNECTIVITY" - }, - "reference": "AAAA - Private rack 002", - "salesOrgId": "2000", - "sla": "Platinum - 24x7x½", - "startsAt": "2017-08-01T00:00:00" - }, - "featureAvailability": { - "powerCycle": false, - "privateNetwork": false - }, - "id": "2893829", - "location": { - "rack": "MI15", - "site": "AMS-01", - "suite": "Hall3" - }, - "networkInterfaces": { - "public": { - "ports": [ - { - "name": "ce05.ams-01", - "port": "0-26" - } - ] - } - }, - "powerPorts": [], - "units": [ - { - "unit": "1", - "status": "FREE", - "connectedUnits": ["1"] - }, - { - "unit": "13", - "status": "OCCUPIED", - "connectedUnits": ["13", "14"] - } - ] - }`) - }) - defer teardown() - - ctx := context.Background() - Rack, err := DedicatedRackApi{}.Get(ctx, "2893829") - assert := assert.New(t) - assert.Nil(err) - - assert.Equal(Rack.Id, "2893829") - assert.Equal(Rack.Contract.CustomerId, "2738283") - assert.Equal(Rack.Contract.DeliveryStatus, "ACTIVE") - assert.Empty(Rack.Contract.EndsAt) - assert.Equal(Rack.Contract.Id, "2893829") - assert.Equal(Rack.Contract.Reference, "AAAA - Private rack 002") - assert.Equal(Rack.Contract.SalesOrgId, "2000") - assert.Equal(Rack.Contract.NetworkTraffic.DataTrafficLimit.String(), "0") - assert.Empty(Rack.Contract.NetworkTraffic.DataTrafficUnit) - assert.Equal(Rack.Contract.NetworkTraffic.TrafficType, "CUSTOM") - assert.Equal(Rack.Contract.NetworkTraffic.Type, "CONNECTIVITY") - assert.Equal(Rack.Contract.Sla, "Platinum - 24x7x½") - assert.Equal(Rack.Contract.StartsAt, "2017-08-01T00:00:00") - assert.Equal(Rack.FeatureAvailability.PowerCycle, false) - assert.Equal(Rack.FeatureAvailability.PrivateNetwork, false) - assert.Equal(Rack.Location.Rack, "MI15") - assert.Equal(Rack.Location.Site, "AMS-01") - assert.Equal(Rack.Location.Suite, "Hall3") - assert.Equal(Rack.NetworkInterfaces.Public.Ports[0].Name, "ce05.ams-01") - assert.Equal(Rack.NetworkInterfaces.Public.Ports[0].Port, "0-26") - assert.Equal(len(Rack.PowerPorts), 0) - assert.Equal(Rack.Units[0].Unit, "1") - assert.Equal(Rack.Units[0].Status, "FREE") - assert.Equal(Rack.Units[0].ConnectedUnits[0], "1") - assert.Equal(Rack.Units[1].Unit, "13") - assert.Equal(Rack.Units[1].Status, "OCCUPIED") - assert.Equal(Rack.Units[1].ConnectedUnits[0], "13") - assert.Equal(Rack.Units[1].ConnectedUnits[1], "14") -} - -func TestDedicatedRackGetServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedRackApi{}.Get(ctx, "2893829") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "Access to the requested resource is forbidden."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedRackApi{}.Get(ctx, "2893829") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "Access to the requested resource is forbidden.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedRackApi{}.Get(ctx, "2893829") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedRackApi{}.Get(ctx, "2893829") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedRackUpdate(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusNoContent) - }) - defer teardown() - - ctx := context.Background() - err := DedicatedRackApi{}.Update(ctx, "2893829", "new reference") - assert := assert.New(t) - assert.Nil(err) -} - -func TestDedicatedRackUpdateServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedRackApi{}.Update(ctx, "2893829", "new reference") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "Access to the requested resource is forbidden."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedRackApi{}.Update(ctx, "2893829", "new reference") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "Access to the requested resource is forbidden.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedRackApi{}.Update(ctx, "2893829", "new reference") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedRackApi{}.Update(ctx, "2893829", "new reference") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedRackListNullRoutes(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "_metadata": { - "limit": 10, - "offset": 0, - "totalCount": 1 - }, - "nullRoutes": [ - { - "automatedUnnullingAt": "2016-08-12T07:45:33+00:00", - "comment": "Device Null Route related to DDoS Mitigation", - "ip": "1.1.1.1/32", - "nullLevel": 3, - "nulledAt": "2016-08-12T07:40:27+00:00", - "ticketId": "282912" - } - ] - }`) - }) - defer teardown() - - ctx := context.Background() - response, err := DedicatedRackApi{}.ListNullRoutes(ctx, "123456", PaginationOptions{}) - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 1) - assert.Equal(response.Metadata.Offset, 0) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.NullRoutes), 1) - - NullRoute := response.NullRoutes[0] - assert.Equal(NullRoute.AutomatedUnnullingAt, "2016-08-12T07:45:33+00:00") - assert.Equal(NullRoute.Comment, "Device Null Route related to DDoS Mitigation") - assert.Equal(NullRoute.Ip, "1.1.1.1/32") - assert.Equal(NullRoute.NullLevel.String(), "3") - assert.Equal(NullRoute.NulledAt, "2016-08-12T07:40:27+00:00") - assert.Equal(NullRoute.TicketId, "282912") -} - -func TestDedicatedRackListNullRoutesPaginateAndFilter(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "_metadata": { - "limit": 10, - "offset": 1, - "totalCount": 11 - }, - "nullRoutes": [ - { - "automatedUnnullingAt": "2016-08-12T07:45:33+00:00", - "comment": "Device Null Route related to DDoS Mitigation", - "ip": "1.1.1.1/32", - "nullLevel": 3, - "nulledAt": "2016-08-12T07:40:27+00:00", - "ticketId": "282912" - } - ] - }`) - }) - defer teardown() - - ctx := context.Background() - opts := PaginationOptions{ - Limit: Int(1), - } - response, err := DedicatedRackApi{}.ListNullRoutes(ctx, "123456", opts) - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 11) - assert.Equal(response.Metadata.Offset, 1) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.NullRoutes), 1) - - NullRoute := response.NullRoutes[0] - assert.Equal(NullRoute.AutomatedUnnullingAt, "2016-08-12T07:45:33+00:00") - assert.Equal(NullRoute.Comment, "Device Null Route related to DDoS Mitigation") - assert.Equal(NullRoute.Ip, "1.1.1.1/32") - assert.Equal(NullRoute.NullLevel.String(), "3") - assert.Equal(NullRoute.NulledAt, "2016-08-12T07:40:27+00:00") - assert.Equal(NullRoute.TicketId, "282912") -} - -func TestDedicatedRackListNullRoutesServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedRackApi{}.ListNullRoutes(ctx, "123456", PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "Access to the requested resource is forbidden."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedRackApi{}.ListNullRoutes(ctx, "123456", PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "Access to the requested resource is forbidden.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedRackApi{}.ListNullRoutes(ctx, "123456", PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedRackApi{}.ListNullRoutes(ctx, "123456", PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedRackListIps(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "_metadata": { - "limit": 10, - "offset": 0, - "totalCount": 2 - }, - "ips": [ - { - "ip": "12.123.123.1/24", - "gateway": "12.123.123.254", - "floatingIp": false, - "version": 4, - "nullRouted": true, - "reverseLookup": "domain.example.com", - "mainIp": true, - "networkType": "PUBLIC", - "ddos": { - "detectionProfile": "ADVANCED_LOW_UDP", - "protectionType": "ADVANCED" - } - }, - { - "ip": "2001:db8:85a3::8a2e:370:7334/64", - "gateway": "2001:db8:85a3::8a2e:370:1", - "floatingIp": false, - "version": 6, - "nullRouted": false, - "reverseLookup": "domain.example.com", - "mainIp": false, - "networkType": "REMOTE_MANAGEMENT", - "ddos": { - "detectionProfile": "STANDARD_DEFAULT", - "protectionType": "STANDARD" - } - } - ] - }`) - }) - defer teardown() - - ctx := context.Background() - response, err := DedicatedRackApi{}.ListIps(ctx, "123456", DedicatedRackListIpsOptions{}) - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 2) - assert.Equal(response.Metadata.Offset, 0) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.Ips), 2) - - Ip1 := response.Ips[0] - assert.Equal(Ip1.Ip, "12.123.123.1/24") - assert.Equal(Ip1.Gateway, "12.123.123.254") - assert.Equal(Ip1.FloatingIp, false) - assert.Equal(Ip1.Version.String(), "4") - assert.Equal(Ip1.NullRouted, true) - assert.Equal(Ip1.ReverseLookup, "domain.example.com") - assert.Equal(Ip1.MainIp, true) - assert.Equal(Ip1.NetworkType, "PUBLIC") - assert.Equal(Ip1.DDOS.DetectionProfile, "ADVANCED_LOW_UDP") - assert.Equal(Ip1.DDOS.ProtectionType, "ADVANCED") - - Ip2 := response.Ips[1] - assert.Equal(Ip2.Ip, "2001:db8:85a3::8a2e:370:7334/64") - assert.Equal(Ip2.Gateway, "2001:db8:85a3::8a2e:370:1") - assert.Equal(Ip2.FloatingIp, false) - assert.Equal(Ip2.Version.String(), "6") - assert.Equal(Ip2.NullRouted, false) - assert.Equal(Ip2.ReverseLookup, "domain.example.com") - assert.Equal(Ip2.MainIp, false) - assert.Equal(Ip2.NetworkType, "REMOTE_MANAGEMENT") - assert.Equal(Ip2.DDOS.DetectionProfile, "STANDARD_DEFAULT") - assert.Equal(Ip2.DDOS.ProtectionType, "STANDARD") -} - -func TestDedicatedRackListIpsPaginateAndFilter(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "_metadata": { - "limit": 10, - "offset": 1, - "totalCount": 11 - }, - "ips": [ - { - "ip": "12.123.123.1/24", - "gateway": "12.123.123.254", - "floatingIp": false, - "version": 4, - "nullRouted": true, - "reverseLookup": "domain.example.com", - "mainIp": true, - "networkType": "PUBLIC", - "ddos": { - "detectionProfile": "ADVANCED_LOW_UDP", - "protectionType": "ADVANCED" - } - } - ] - }`) - }) - defer teardown() - - ctx := context.Background() - opts := DedicatedRackListIpsOptions{ - PaginationOptions: PaginationOptions{ - Limit: Int(1), - }, - } - response, err := DedicatedRackApi{}.ListIps(ctx, "123456", opts) - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 11) - assert.Equal(response.Metadata.Offset, 1) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.Ips), 1) - - Ip1 := response.Ips[0] - assert.Equal(Ip1.Ip, "12.123.123.1/24") - assert.Equal(Ip1.Gateway, "12.123.123.254") - assert.Equal(Ip1.FloatingIp, false) - assert.Equal(Ip1.Version.String(), "4") - assert.Equal(Ip1.NullRouted, true) - assert.Equal(Ip1.ReverseLookup, "domain.example.com") - assert.Equal(Ip1.MainIp, true) - assert.Equal(Ip1.NetworkType, "PUBLIC") - assert.Equal(Ip1.DDOS.DetectionProfile, "ADVANCED_LOW_UDP") - assert.Equal(Ip1.DDOS.ProtectionType, "ADVANCED") -} - -func TestDedicatedRackListIpsServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedRackApi{}.ListIps(ctx, "123456", DedicatedRackListIpsOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "Access to the requested resource is forbidden."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedRackApi{}.ListIps(ctx, "123456", DedicatedRackListIpsOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "Access to the requested resource is forbidden.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedRackApi{}.ListIps(ctx, "123456", DedicatedRackListIpsOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedRackApi{}.ListIps(ctx, "123456", DedicatedRackListIpsOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedRackGetIps(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "ip": "12.123.123.1/24", - "gateway": "12.123.123.254", - "floatingIp": false, - "version": 4, - "nullRouted": false, - "reverseLookup": "domain.example.com", - "mainIp": true, - "networkType": "PUBLIC", - "ddos": { - "detectionProfile": "ADVANCED_LOW_UDP", - "protectionType": "ADVANCED" - } - }`) - }) - defer teardown() - - ctx := context.Background() - Ip, err := DedicatedRackApi{}.GetIp(ctx, "123456", "12.123.123.1") - assert := assert.New(t) - assert.Nil(err) - - assert.Equal(Ip.Ip, "12.123.123.1/24") - assert.Equal(Ip.Gateway, "12.123.123.254") - assert.Equal(Ip.FloatingIp, false) - assert.Equal(Ip.Version.String(), "4") - assert.Equal(Ip.NullRouted, false) - assert.Equal(Ip.ReverseLookup, "domain.example.com") - assert.Equal(Ip.MainIp, true) - assert.Equal(Ip.NetworkType, "PUBLIC") - assert.Equal(Ip.DDOS.DetectionProfile, "ADVANCED_LOW_UDP") - assert.Equal(Ip.DDOS.ProtectionType, "ADVANCED") -} - -func TestDedicatedRackGetIpsServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedRackApi{}.GetIp(ctx, "123456", "12.123.123.1") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "Access to the requested resource is forbidden."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedRackApi{}.GetIp(ctx, "123456", "12.123.123.1") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "Access to the requested resource is forbidden.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedRackApi{}.GetIp(ctx, "123456", "12.123.123.1") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedRackApi{}.GetIp(ctx, "123456", "12.123.123.1") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedRackUpdateIp(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "ip": "12.123.123.1/24", - "gateway": "12.123.123.254", - "floatingIp": false, - "version": 4, - "nullRouted": false, - "reverseLookup": "domain.example.com", - "mainIp": true, - "networkType": "PUBLIC", - "ddos": { - "detectionProfile": "ADVANCED_LOW_UDP", - "protectionType": "ADVANCED" - } - }`) - }) - defer teardown() - - ctx := context.Background() - Ip, err := DedicatedRackApi{}.UpdateIp(ctx, "123456", "12.123.123.1", map[string]string{"reverseLookup": "domain.example.com", "detectionProfile": "ADVANCED_LOW_UDP"}) - assert := assert.New(t) - assert.Nil(err) - - assert.Equal(Ip.Ip, "12.123.123.1/24") - assert.Equal(Ip.Gateway, "12.123.123.254") - assert.Equal(Ip.FloatingIp, false) - assert.Equal(Ip.Version.String(), "4") - assert.Equal(Ip.NullRouted, false) - assert.Equal(Ip.ReverseLookup, "domain.example.com") - assert.Equal(Ip.MainIp, true) - assert.Equal(Ip.NetworkType, "PUBLIC") - assert.Equal(Ip.DDOS.DetectionProfile, "ADVANCED_LOW_UDP") - assert.Equal(Ip.DDOS.ProtectionType, "ADVANCED") -} - -func TestDedicatedRackUpdateIpServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedRackApi{}.UpdateIp(ctx, "123456", "12.123.123.1", map[string]string{"reverseLookup": "domain.example.com", "detectionProfile": "ADVANCED_LOW_UDP"}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "Access to the requested resource is forbidden."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedRackApi{}.UpdateIp(ctx, "123456", "12.123.123.1", map[string]string{"reverseLookup": "domain.example.com", "detectionProfile": "ADVANCED_LOW_UDP"}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "Access to the requested resource is forbidden.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedRackApi{}.UpdateIp(ctx, "123456", "12.123.123.1", map[string]string{"reverseLookup": "domain.example.com", "detectionProfile": "ADVANCED_LOW_UDP"}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedRackApi{}.UpdateIp(ctx, "123456", "12.123.123.1", map[string]string{"reverseLookup": "domain.example.com", "detectionProfile": "ADVANCED_LOW_UDP"}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedRackNullRouteAnIp(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "ip": "12.123.123.1/24", - "gateway": "12.123.123.254", - "floatingIp": false, - "version": 4, - "nullRouted": false, - "reverseLookup": "domain.example.com", - "mainIp": true, - "networkType": "PUBLIC", - "ddos": { - "detectionProfile": "ADVANCED_LOW_UDP", - "protectionType": "ADVANCED" - } - }`) - }) - defer teardown() - - ctx := context.Background() - Ip, err := DedicatedRackApi{}.NullRouteAnIp(ctx, "123456", "12.123.123.1") - assert := assert.New(t) - assert.Nil(err) - - assert.Equal(Ip.Ip, "12.123.123.1/24") - assert.Equal(Ip.Gateway, "12.123.123.254") - assert.Equal(Ip.FloatingIp, false) - assert.Equal(Ip.Version.String(), "4") - assert.Equal(Ip.NullRouted, false) - assert.Equal(Ip.ReverseLookup, "domain.example.com") - assert.Equal(Ip.MainIp, true) - assert.Equal(Ip.NetworkType, "PUBLIC") - assert.Equal(Ip.DDOS.DetectionProfile, "ADVANCED_LOW_UDP") - assert.Equal(Ip.DDOS.ProtectionType, "ADVANCED") -} - -func TestDedicatedRackNullRouteAnIpServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedRackApi{}.NullRouteAnIp(ctx, "123456", "12.123.123.1") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "Access to the requested resource is forbidden."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedRackApi{}.NullRouteAnIp(ctx, "123456", "12.123.123.1") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "Access to the requested resource is forbidden.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedRackApi{}.NullRouteAnIp(ctx, "123456", "12.123.123.1") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedRackApi{}.NullRouteAnIp(ctx, "123456", "12.123.123.1") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedRackRemoveNullRouteAnIp(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "ip": "12.123.123.1/24", - "gateway": "12.123.123.254", - "floatingIp": false, - "version": 4, - "nullRouted": false, - "reverseLookup": "domain.example.com", - "mainIp": true, - "networkType": "PUBLIC", - "ddos": { - "detectionProfile": "ADVANCED_LOW_UDP", - "protectionType": "ADVANCED" - } - }`) - }) - defer teardown() - - ctx := context.Background() - Ip, err := DedicatedRackApi{}.RemoveNullRouteAnIp(ctx, "123456", "12.123.123.1") - assert := assert.New(t) - assert.Nil(err) - - assert.Equal(Ip.Ip, "12.123.123.1/24") - assert.Equal(Ip.Gateway, "12.123.123.254") - assert.Equal(Ip.FloatingIp, false) - assert.Equal(Ip.Version.String(), "4") - assert.Equal(Ip.NullRouted, false) - assert.Equal(Ip.ReverseLookup, "domain.example.com") - assert.Equal(Ip.MainIp, true) - assert.Equal(Ip.NetworkType, "PUBLIC") - assert.Equal(Ip.DDOS.DetectionProfile, "ADVANCED_LOW_UDP") - assert.Equal(Ip.DDOS.ProtectionType, "ADVANCED") -} - -func TestDedicatedRackRemoveNullRouteAnIpServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedRackApi{}.RemoveNullRouteAnIp(ctx, "123456", "12.123.123.1") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "Access to the requested resource is forbidden."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedRackApi{}.RemoveNullRouteAnIp(ctx, "123456", "12.123.123.1") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "Access to the requested resource is forbidden.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedRackApi{}.RemoveNullRouteAnIp(ctx, "123456", "12.123.123.1") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedRackApi{}.RemoveNullRouteAnIp(ctx, "123456", "12.123.123.1") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedRackListCredentials(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "_metadata": { - "limit": 10, - "offset": 0, - "totalCount": 4 - }, - "credentials": [ - { - "type": "REMOTE_MANAGEMENT", - "username": "admin" - }, - { - "type": "REMOTE_MANAGEMENT", - "username": "root" - }, - { - "type": "OPERATING_SYSTEM", - "username": "root" - }, - { - "type": "OPERATING_SYSTEM", - "username": "user" - } - ] - }`) - }) - defer teardown() - - ctx := context.Background() - response, err := DedicatedRackApi{}.ListCredentials(ctx, "99944", PaginationOptions{}) - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 4) - assert.Equal(response.Metadata.Offset, 0) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.Credentials), 4) - - assert.Equal(response.Credentials[0].Type, "REMOTE_MANAGEMENT") - assert.Equal(response.Credentials[0].Username, "admin") - assert.Equal(response.Credentials[1].Type, "REMOTE_MANAGEMENT") - assert.Equal(response.Credentials[1].Username, "root") - assert.Equal(response.Credentials[2].Type, "OPERATING_SYSTEM") - assert.Equal(response.Credentials[2].Username, "root") - assert.Equal(response.Credentials[3].Type, "OPERATING_SYSTEM") - assert.Equal(response.Credentials[3].Username, "user") -} - -func TestDedicatedRackListCredentialsBeEmpty(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{"_metadata":{"limit": 10, "offset": 0, "totalCount": 0}, "credentials": []}`) - }) - defer teardown() - ctx := context.Background() - response, err := DedicatedRackApi{}.ListCredentials(ctx, "99944", PaginationOptions{}) - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 0) - assert.Equal(response.Metadata.Offset, 0) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.Credentials), 0) -} - -func TestDedicatedRackListCredentialsPaginate(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "_metadata": { - "limit": 10, - "offset": 1, - "totalCount": 11 - }, - "credentials": [ - { - "type": "REMOTE_MANAGEMENT", - "username": "admin" - } - ] - }`) - }) - defer teardown() - - ctx := context.Background() - response, err := DedicatedRackApi{}.ListCredentials(ctx, "99944", PaginationOptions{}) - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 11) - assert.Equal(response.Metadata.Offset, 1) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.Credentials), 1) - - assert.Equal(response.Credentials[0].Type, "REMOTE_MANAGEMENT") - assert.Equal(response.Credentials[0].Username, "admin") -} - -func TestDedicatedRackListCredentialsServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedRackApi{}.ListCredentials(ctx, "99944", PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedRackApi{}.ListCredentials(ctx, "99944", PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "404", "errorMessage": "Resource not found"}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedRackApi{}.ListCredentials(ctx, "99944", PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "404", - Message: "Resource not found", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedRackApi{}.ListCredentials(ctx, "99944", PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedRackApi{}.ListCredentials(ctx, "99944", PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedRackCreateCredential(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "password": "mys3cr3tp@ssw0rd", - "type": "OPERATING_SYSTEM", - "username": "root" - }`) - }) - defer teardown() - - ctx := context.Background() - resp, err := DedicatedRackApi{}.CreateCredential(ctx, "12345", "OPERATING_SYSTEM", "root", "mys3cr3tp@ssw0rd") - assert := assert.New(t) - assert.Nil(err) - - assert.Equal(resp.Type, "OPERATING_SYSTEM") - assert.Equal(resp.Username, "root") - assert.Equal(resp.Password, "mys3cr3tp@ssw0rd") -} - -func TestDedicatedRackCreateCredentialServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedRackApi{}.CreateCredential(ctx, "12345", "OPERATING_SYSTEM", "root", "mys3cr3tp@ssw0rd") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedRackApi{}.CreateCredential(ctx, "12345", "OPERATING_SYSTEM", "root", "mys3cr3tp@ssw0rd") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "404", "errorMessage": "Resource not found"}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedRackApi{}.CreateCredential(ctx, "12345", "OPERATING_SYSTEM", "root", "mys3cr3tp@ssw0rd") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "404", - Message: "Resource not found", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedRackApi{}.CreateCredential(ctx, "12345", "OPERATING_SYSTEM", "root", "mys3cr3tp@ssw0rd") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedRackApi{}.CreateCredential(ctx, "12345", "OPERATING_SYSTEM", "root", "mys3cr3tp@ssw0rd") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedRackListCredentialsByType(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "_metadata": { - "limit": 10, - "offset": 0, - "totalCount": 2 - }, - "credentials": [ - { - "type": "REMOTE_MANAGEMENT", - "username": "admin" - }, - { - "type": "REMOTE_MANAGEMENT", - "username": "root" - } - ] - }`) - }) - defer teardown() - - ctx := context.Background() - response, err := DedicatedRackApi{}.ListCredentialsByType(ctx, "99944", "REMOTE_MANAGEMENT", PaginationOptions{}) - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 2) - assert.Equal(response.Metadata.Offset, 0) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.Credentials), 2) - - assert.Equal(response.Credentials[0].Type, "REMOTE_MANAGEMENT") - assert.Equal(response.Credentials[0].Username, "admin") - assert.Equal(response.Credentials[1].Type, "REMOTE_MANAGEMENT") - assert.Equal(response.Credentials[1].Username, "root") -} - -func TestDedicatedRackListCredentialsByTypeBeEmpty(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{"_metadata":{"limit": 10, "offset": 0, "totalCount": 0}, "credentials": []}`) - }) - defer teardown() - ctx := context.Background() - response, err := DedicatedRackApi{}.ListCredentialsByType(ctx, "99944", "REMOTE_MANAGEMENT", PaginationOptions{}) - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 0) - assert.Equal(response.Metadata.Offset, 0) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.Credentials), 0) -} - -func TestDedicatedRackListCredentialsByTypePaginate(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "_metadata": { - "limit": 10, - "offset": 1, - "totalCount": 11 - }, - "credentials": [ - { - "type": "REMOTE_MANAGEMENT", - "username": "admin" - } - ] - }`) - }) - defer teardown() - - ctx := context.Background() - response, err := DedicatedRackApi{}.ListCredentialsByType(ctx, "99944", "REMOTE_MANAGEMENT", PaginationOptions{}) - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 11) - assert.Equal(response.Metadata.Offset, 1) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.Credentials), 1) - - assert.Equal(response.Credentials[0].Type, "REMOTE_MANAGEMENT") - assert.Equal(response.Credentials[0].Username, "admin") -} - -func TestDedicatedRackListCredentialsByTypeServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedRackApi{}.ListCredentialsByType(ctx, "99944", "REMOTE_MANAGEMENT", PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedRackApi{}.ListCredentialsByType(ctx, "99944", "REMOTE_MANAGEMENT", PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "404", "errorMessage": "Resource not found"}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedRackApi{}.ListCredentialsByType(ctx, "99944", "REMOTE_MANAGEMENT", PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "404", - Message: "Resource not found", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedRackApi{}.ListCredentialsByType(ctx, "99944", "REMOTE_MANAGEMENT", PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedRackApi{}.ListCredentialsByType(ctx, "99944", "REMOTE_MANAGEMENT", PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedRackGetCredentials(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "password": "mys3cr3tp@ssw0rd", - "type": "OPERATING_SYSTEM", - "username": "root" - }`) - }) - defer teardown() - - ctx := context.Background() - Credential, err := DedicatedRackApi{}.GetCredential(ctx, "12345", "OPERATING_SYSTEM", "root") - assert := assert.New(t) - assert.Nil(err) - assert.Equal(Credential.Password, "mys3cr3tp@ssw0rd") - assert.Equal(Credential.Username, "root") - assert.Equal(Credential.Type, "OPERATING_SYSTEM") -} - -func TestDedicatedRackGetCredentialsServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedRackApi{}.GetCredential(ctx, "12345", "OPERATING_SYSTEM", "root") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedRackApi{}.GetCredential(ctx, "12345", "OPERATING_SYSTEM", "root") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "404", "errorMessage": "Resource not found"}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedRackApi{}.GetCredential(ctx, "12345", "OPERATING_SYSTEM", "root") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "404", - Message: "Resource not found", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedRackApi{}.GetCredential(ctx, "12345", "OPERATING_SYSTEM", "root") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedRackApi{}.GetCredential(ctx, "12345", "OPERATING_SYSTEM", "root") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedRackDeleteCredentials(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusNoContent) - }) - defer teardown() - - ctx := context.Background() - err := DedicatedRackApi{}.DeleteCredential(ctx, "12345", "OPERATING_SYSTEM", "admin") - assert := assert.New(t) - assert.Nil(err) -} - -func TestDedicatedRackDeleteCredentialsServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedRackApi{}.DeleteCredential(ctx, "12345", "OPERATING_SYSTEM", "admin") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedRackApi{}.DeleteCredential(ctx, "12345", "OPERATING_SYSTEM", "admin") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "404", "errorMessage": "Resource not found"}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedRackApi{}.DeleteCredential(ctx, "12345", "OPERATING_SYSTEM", "admin") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "404", - Message: "Resource not found", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedRackApi{}.DeleteCredential(ctx, "12345", "OPERATING_SYSTEM", "admin") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedRackApi{}.DeleteCredential(ctx, "12345", "OPERATING_SYSTEM", "admin") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedRackUpdateCredentials(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "password": "new password", - "type": "OPERATING_SYSTEM", - "username": "admin" - }`) - }) - defer teardown() - - ctx := context.Background() - resp, err := DedicatedRackApi{}.UpdateCredential(ctx, "12345", "OPERATING_SYSTEM", "admin", "new password") - assert := assert.New(t) - assert.Nil(err) - - assert.Equal(resp.Password, "new password") - assert.Equal(resp.Type, "OPERATING_SYSTEM") - assert.Equal(resp.Username, "admin") -} - -func TestDedicatedRackUpdateCredentialsServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedRackApi{}.UpdateCredential(ctx, "12345", "OPERATING_SYSTEM", "admin", "new password") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedRackApi{}.UpdateCredential(ctx, "12345", "OPERATING_SYSTEM", "admin", "new password") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "404", "errorMessage": "Resource not found"}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedRackApi{}.UpdateCredential(ctx, "12345", "OPERATING_SYSTEM", "admin", "new password") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "404", - Message: "Resource not found", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedRackApi{}.UpdateCredential(ctx, "12345", "OPERATING_SYSTEM", "admin", "new password") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedRackApi{}.UpdateCredential(ctx, "12345", "OPERATING_SYSTEM", "admin", "new password") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedRackGetBandWidthMetrics(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "_metadata": { - "aggregation": "AVG", - "from": "2016-10-20T09:00:00Z", - "granularity": "HOUR", - "to": "2016-10-20T11:00:00Z" - }, - "metrics": { - "DOWN_PUBLIC": { - "unit": "bps", - "values": [ - { - "timestamp": "2016-10-20T09:00:00Z", - "value": 202499 - }, - { - "timestamp": "2016-10-20T10:00:00Z", - "value": 29900 - } - ] - }, - "UP_PUBLIC": { - "unit": "bps", - "values": [ - { - "timestamp": "2016-10-20T09:00:00Z", - "value": 43212393 - }, - { - "timestamp": "2016-10-20T10:00:00Z", - "value": 12342929 - } - ] - } - } - }`) - }) - defer teardown() - - ctx := context.Background() - opts := MetricsOptions{ - From: String("2016-10-20T09:00:00Z"), - To: String("2016-10-20T11:00:00Z"), - Granularity: String("HOUR"), - Aggregation: String("AVG"), - } - Metric, err := DedicatedRackApi{}.GetBandWidthMetrics(ctx, "99944", opts) - assert := assert.New(t) - assert.Nil(err) - assert.Equal(Metric.Metadata.Aggregation, "AVG") - assert.Equal(Metric.Metadata.From, "2016-10-20T09:00:00Z") - assert.Equal(Metric.Metadata.To, "2016-10-20T11:00:00Z") - assert.Equal(Metric.Metadata.Granularity, "HOUR") - assert.Equal(Metric.Metric.DownPublic.Unit, "bps") - assert.Equal(Metric.Metric.DownPublic.Values[0].Value.String(), "202499") - assert.Equal(Metric.Metric.DownPublic.Values[0].Timestamp, "2016-10-20T09:00:00Z") - assert.Equal(Metric.Metric.DownPublic.Values[1].Value.String(), "29900") - assert.Equal(Metric.Metric.DownPublic.Values[1].Timestamp, "2016-10-20T10:00:00Z") - - assert.Equal(Metric.Metric.UpPublic.Unit, "bps") - assert.Equal(Metric.Metric.UpPublic.Values[0].Value.String(), "43212393") - assert.Equal(Metric.Metric.UpPublic.Values[0].Timestamp, "2016-10-20T09:00:00Z") - assert.Equal(Metric.Metric.UpPublic.Values[1].Value.String(), "12342929") - assert.Equal(Metric.Metric.UpPublic.Values[1].Timestamp, "2016-10-20T10:00:00Z") -} - -func TestDedicatedRackGetBandWidthMetricsServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - opts := MetricsOptions{ - From: String("2016-10-20T09:00:00Z"), - To: String("2016-10-20T11:00:00Z"), - Granularity: String("HOUR"), - Aggregation: String("AVG"), - } - return DedicatedRackApi{}.GetBandWidthMetrics(ctx, "99944", opts) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - opts := MetricsOptions{ - From: String("2016-10-20T09:00:00Z"), - To: String("2016-10-20T11:00:00Z"), - Granularity: String("HOUR"), - Aggregation: String("AVG"), - } - return DedicatedRackApi{}.GetBandWidthMetrics(ctx, "99944", opts) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "404", "errorMessage": "Resource not found"}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - opts := MetricsOptions{ - From: String("2016-10-20T09:00:00Z"), - To: String("2016-10-20T11:00:00Z"), - Granularity: String("HOUR"), - Aggregation: String("AVG"), - } - return DedicatedRackApi{}.GetBandWidthMetrics(ctx, "99944", opts) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "404", - Message: "Resource not found", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - opts := MetricsOptions{ - From: String("2016-10-20T09:00:00Z"), - To: String("2016-10-20T11:00:00Z"), - Granularity: String("HOUR"), - Aggregation: String("AVG"), - } - return DedicatedRackApi{}.GetBandWidthMetrics(ctx, "99944", opts) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - opts := MetricsOptions{ - From: String("2016-10-20T09:00:00Z"), - To: String("2016-10-20T11:00:00Z"), - Granularity: String("HOUR"), - Aggregation: String("AVG"), - } - return DedicatedRackApi{}.GetBandWidthMetrics(ctx, "99944", opts) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedRackGetDataTrafficMetrics(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "_metadata": { - "aggregation": "SUM", - "from": "2016-10-20T09:00:00Z", - "granularity": "HOUR", - "to": "2016-10-20T11:00:00Z" - }, - "metrics": { - "DOWN_PUBLIC": { - "unit": "B", - "values": [ - { - "timestamp": "2016-10-20T09:00:00Z", - "value": 202499 - }, - { - "timestamp": "2016-10-20T10:00:00Z", - "value": 29900 - } - ] - }, - "UP_PUBLIC": { - "unit": "B", - "values": [ - { - "timestamp": "2016-10-20T09:00:00Z", - "value": 43212393 - }, - { - "timestamp": "2016-10-20T10:00:00Z", - "value": 12342929 - } - ] - } - } - }`) - }) - defer teardown() - - ctx := context.Background() - opts := MetricsOptions{ - From: String("2016-10-20T09:00:00Z"), - To: String("2016-10-20T11:00:00Z"), - Granularity: String("HOUR"), - Aggregation: String("SUM"), - } - Metric, err := DedicatedRackApi{}.GetDataTrafficMetrics(ctx, "99944", opts) - assert := assert.New(t) - assert.Nil(err) - assert.Equal(Metric.Metadata.Aggregation, "SUM") - assert.Equal(Metric.Metadata.From, "2016-10-20T09:00:00Z") - assert.Equal(Metric.Metadata.To, "2016-10-20T11:00:00Z") - assert.Equal(Metric.Metadata.Granularity, "HOUR") - assert.Equal(Metric.Metric.DownPublic.Unit, "B") - assert.Equal(Metric.Metric.DownPublic.Values[0].Value.String(), "202499") - assert.Equal(Metric.Metric.DownPublic.Values[0].Timestamp, "2016-10-20T09:00:00Z") - assert.Equal(Metric.Metric.DownPublic.Values[1].Value.String(), "29900") - assert.Equal(Metric.Metric.DownPublic.Values[1].Timestamp, "2016-10-20T10:00:00Z") - - assert.Equal(Metric.Metric.UpPublic.Unit, "B") - assert.Equal(Metric.Metric.UpPublic.Values[0].Value.String(), "43212393") - assert.Equal(Metric.Metric.UpPublic.Values[0].Timestamp, "2016-10-20T09:00:00Z") - assert.Equal(Metric.Metric.UpPublic.Values[1].Value.String(), "12342929") - assert.Equal(Metric.Metric.UpPublic.Values[1].Timestamp, "2016-10-20T10:00:00Z") -} - -func TestDedicatedRackGetDataTrafficMetricsServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - opts := MetricsOptions{ - From: String("2016-10-20T09:00:00Z"), - To: String("2016-10-20T11:00:00Z"), - Granularity: String("HOUR"), - Aggregation: String("SUM"), - } - return DedicatedRackApi{}.GetDataTrafficMetrics(ctx, "99944", opts) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - opts := MetricsOptions{ - From: String("2016-10-20T09:00:00Z"), - To: String("2016-10-20T11:00:00Z"), - Granularity: String("HOUR"), - Aggregation: String("SUM"), - } - return DedicatedRackApi{}.GetDataTrafficMetrics(ctx, "99944", opts) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "404", "errorMessage": "Resource not found"}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - opts := MetricsOptions{ - From: String("2016-10-20T09:00:00Z"), - To: String("2016-10-20T11:00:00Z"), - Granularity: String("HOUR"), - Aggregation: String("SUM"), - } - return DedicatedRackApi{}.GetDataTrafficMetrics(ctx, "99944", opts) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "404", - Message: "Resource not found", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - opts := MetricsOptions{ - From: String("2016-10-20T09:00:00Z"), - To: String("2016-10-20T11:00:00Z"), - Granularity: String("HOUR"), - Aggregation: String("SUM"), - } - return DedicatedRackApi{}.GetDataTrafficMetrics(ctx, "99944", opts) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - opts := MetricsOptions{ - From: String("2016-10-20T09:00:00Z"), - To: String("2016-10-20T11:00:00Z"), - Granularity: String("HOUR"), - Aggregation: String("SUM"), - } - return DedicatedRackApi{}.GetDataTrafficMetrics(ctx, "99944", opts) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedRackGetDdosNotificationSetting(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "nulling": "ENABLED", - "scrubbing": "DISABLED" - }`) - }) - defer teardown() - - ctx := context.Background() - resp, err := DedicatedRackApi{}.GetDdosNotificationSetting(ctx, "server-id") - assert := assert.New(t) - assert.Nil(err) - - assert.Equal(resp.Nulling, "ENABLED") - assert.Equal(resp.Scrubbing, "DISABLED") -} - -func TestDedicatedRackGetDdosNotificationSettingServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedRackApi{}.GetDdosNotificationSetting(ctx, "server-id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedRackApi{}.GetDdosNotificationSetting(ctx, "server-id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "404", "errorMessage": "Resource not found"}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedRackApi{}.GetDdosNotificationSetting(ctx, "server-id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "404", - Message: "Resource not found", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedRackApi{}.GetDdosNotificationSetting(ctx, "server-id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedRackApi{}.GetDdosNotificationSetting(ctx, "server-id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedRackUpdateDdosNotificationSetting(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusNoContent) - }) - defer teardown() - - ctx := context.Background() - err := DedicatedRackApi{}.UpdateDdosNotificationSetting(ctx, "server id", map[string]string{"nulling": "DISABLED", "scrubbing": "ENABLED"}) - assert := assert.New(t) - assert.Nil(err) -} - -func TestDedicatedRackUpdateDdosNotificationSettingServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedRackApi{}.UpdateDdosNotificationSetting(ctx, "server id", map[string]string{"nulling": "DISABLED", "scrubbing": "ENABLED"}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedRackApi{}.UpdateDdosNotificationSetting(ctx, "server id", map[string]string{"nulling": "DISABLED", "scrubbing": "ENABLED"}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "404", "errorMessage": "Resource not found"}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedRackApi{}.UpdateDdosNotificationSetting(ctx, "server id", map[string]string{"nulling": "DISABLED", "scrubbing": "ENABLED"}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "404", - Message: "Resource not found", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedRackApi{}.UpdateDdosNotificationSetting(ctx, "server id", map[string]string{"nulling": "DISABLED", "scrubbing": "ENABLED"}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedRackApi{}.UpdateDdosNotificationSetting(ctx, "server id", map[string]string{"nulling": "DISABLED", "scrubbing": "ENABLED"}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedRackListDataTrafficNotificationSettings(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "_metadata": { - "limit": 10, - "offset": 0, - "totalCount": 2 - }, - "datatrafficNotificationSettings": [ - { - "actions": [ - { - "lastTriggeredAt": null, - "type": "EMAIL" - } - ], - "frequency": "WEEKLY", - "id": "12345", - "lastCheckedAt": null, - "threshold": "1", - "thresholdExceededAt": null, - "unit": "MB" - }, - { - "actions": [ - { - "lastTriggeredAt": null, - "type": "EMAIL" - } - ], - "frequency": "DAILY", - "id": "123456", - "lastCheckedAt": null, - "threshold": "1", - "thresholdExceededAt": null, - "unit": "GB" - } - ] - }`) - }) - defer teardown() - - ctx := context.Background() - resp, err := DedicatedRackApi{}.ListDataTrafficNotificationSettings(ctx, "server-id", PaginationOptions{}) - assert := assert.New(t) - assert.Nil(err) - assert.Equal(resp.Metadata.TotalCount, 2) - assert.Equal(resp.Metadata.Offset, 0) - assert.Equal(resp.Metadata.Limit, 10) - assert.Equal(len(resp.Settings), 2) - - assert.Empty(resp.Settings[0].Actions[0].LastTriggeredAt) - assert.Equal(resp.Settings[0].Actions[0].Type, "EMAIL") - assert.Equal(resp.Settings[0].Frequency, "WEEKLY") - assert.Equal(resp.Settings[0].Id, "12345") - assert.Empty(resp.Settings[0].LastCheckedAt) - assert.Equal(resp.Settings[0].Threshold.String(), "1") - assert.Empty(resp.Settings[0].ThresholdExceededAt) - assert.Equal(resp.Settings[0].Unit, "MB") - - assert.Empty(resp.Settings[1].Actions[0].LastTriggeredAt) - assert.Equal(resp.Settings[1].Actions[0].Type, "EMAIL") - assert.Equal(resp.Settings[1].Frequency, "DAILY") - assert.Equal(resp.Settings[1].Id, "123456") - assert.Empty(resp.Settings[1].LastCheckedAt) - assert.Equal(resp.Settings[1].Threshold.String(), "1") - assert.Empty(resp.Settings[1].ThresholdExceededAt) - assert.Equal(resp.Settings[1].Unit, "GB") -} - -func TestDedicatedRackListDataTrafficNotificationSettingsPaginate(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "_metadata": { - "limit": 10, - "offset": 1, - "totalCount": 11 - }, - "datatrafficNotificationSettings": [ - { - "actions": [ - { - "lastTriggeredAt": null, - "type": "EMAIL" - } - ], - "frequency": "WEEKLY", - "id": "12345", - "lastCheckedAt": null, - "threshold": "1", - "thresholdExceededAt": null, - "unit": "MB" - } - ] - }`) - }) - defer teardown() - - ctx := context.Background() - opts := PaginationOptions{ - Limit: Int(1), - } - resp, err := DedicatedRackApi{}.ListDataTrafficNotificationSettings(ctx, "server-id", opts) - assert := assert.New(t) - assert.Nil(err) - assert.Equal(resp.Metadata.TotalCount, 11) - assert.Equal(resp.Metadata.Offset, 1) - assert.Equal(resp.Metadata.Limit, 10) - assert.Equal(len(resp.Settings), 1) - - assert.Empty(resp.Settings[0].Actions[0].LastTriggeredAt) - assert.Equal(resp.Settings[0].Actions[0].Type, "EMAIL") - assert.Equal(resp.Settings[0].Frequency, "WEEKLY") - assert.Equal(resp.Settings[0].Id, "12345") - assert.Empty(resp.Settings[0].LastCheckedAt) - assert.Equal(resp.Settings[0].Threshold.String(), "1") - assert.Empty(resp.Settings[0].ThresholdExceededAt) - assert.Equal(resp.Settings[0].Unit, "MB") -} - -func TestDedicatedRackListDataTrafficNotificationSettingsServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedRackApi{}.ListDataTrafficNotificationSettings(ctx, "server-id", PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedRackApi{}.ListDataTrafficNotificationSettings(ctx, "server-id", PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "404", "errorMessage": "Resource not found"}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedRackApi{}.ListDataTrafficNotificationSettings(ctx, "server-id", PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "404", - Message: "Resource not found", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedRackApi{}.ListDataTrafficNotificationSettings(ctx, "server-id", PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedRackApi{}.ListDataTrafficNotificationSettings(ctx, "server-id", PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedRackCreateDataTrafficNotificationSetting(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "actions": [ - { - "lastTriggeredAt": "2021-03-16T01:01:44+00:00", - "type": "EMAIL" - } - ], - "frequency": "WEEKLY", - "id": "12345", - "lastCheckedAt": "2021-03-16T01:01:41+00:00", - "threshold": "1", - "thresholdExceededAt": "2021-03-16T01:01:41+00:00", - "unit": "GB" - }`) - }) - defer teardown() - - ctx := context.Background() - resp, err := DedicatedRackApi{}.CreateDataTrafficNotificationSetting(ctx, "server-id", "WEEKLY", "1", "GB") - assert := assert.New(t) - assert.Nil(err) - - assert.Equal(resp.Actions[0].LastTriggeredAt, "2021-03-16T01:01:44+00:00") - assert.Equal(resp.Actions[0].Type, "EMAIL") - assert.Equal(resp.Frequency, "WEEKLY") - assert.Equal(resp.Id, "12345") - assert.Equal(resp.LastCheckedAt, "2021-03-16T01:01:41+00:00") - assert.Equal(resp.Threshold.String(), "1") - assert.Equal(resp.ThresholdExceededAt, "2021-03-16T01:01:41+00:00") - assert.Equal(resp.Unit, "GB") -} - -func TestDedicatedRackCreateDataTrafficNotificationSettingServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedRackApi{}.CreateDataTrafficNotificationSetting(ctx, "server-id", "WEEKLY", "1", "GB") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedRackApi{}.CreateDataTrafficNotificationSetting(ctx, "server-id", "WEEKLY", "1", "GB") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "404", "errorMessage": "Resource not found"}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedRackApi{}.CreateDataTrafficNotificationSetting(ctx, "server-id", "WEEKLY", "1", "GB") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "404", - Message: "Resource not found", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedRackApi{}.CreateDataTrafficNotificationSetting(ctx, "server-id", "WEEKLY", "1", "GB") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedRackApi{}.CreateDataTrafficNotificationSetting(ctx, "server-id", "WEEKLY", "1", "GB") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedRackDeleteDataTrafficNotificationSetting(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusNoContent) - }) - defer teardown() - - ctx := context.Background() - err := DedicatedRackApi{}.DeleteDataTrafficNotificationSetting(ctx, "server id", "notification id") - assert := assert.New(t) - assert.Nil(err) -} - -func TestDedicatedRackDeleteDataTrafficNotificationSettingServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedRackApi{}.DeleteDataTrafficNotificationSetting(ctx, "server id", "notification id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedRackApi{}.DeleteDataTrafficNotificationSetting(ctx, "server id", "notification id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "404", "errorMessage": "Resource not found"}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedRackApi{}.DeleteDataTrafficNotificationSetting(ctx, "server id", "notification id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "404", - Message: "Resource not found", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedRackApi{}.DeleteDataTrafficNotificationSetting(ctx, "server id", "notification id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedRackApi{}.DeleteDataTrafficNotificationSetting(ctx, "server id", "notification id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedRackGetDataTrafficNotificationSetting(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "actions": [ - { - "lastTriggeredAt": "2021-03-16T01:01:44+00:00", - "type": "EMAIL" - } - ], - "frequency": "WEEKLY", - "id": "12345", - "lastCheckedAt": "2021-03-16T01:01:41+00:00", - "threshold": "1", - "thresholdExceededAt": "2021-03-16T01:01:41+00:00", - "unit": "GB" - }`) - }) - defer teardown() - - ctx := context.Background() - resp, err := DedicatedRackApi{}.GetDataTrafficNotificationSetting(ctx, "server-id", "notification id") - assert := assert.New(t) - assert.Nil(err) - - assert.Equal(resp.Actions[0].LastTriggeredAt, "2021-03-16T01:01:44+00:00") - assert.Equal(resp.Actions[0].Type, "EMAIL") - assert.Equal(resp.Frequency, "WEEKLY") - assert.Equal(resp.Id, "12345") - assert.Equal(resp.LastCheckedAt, "2021-03-16T01:01:41+00:00") - assert.Equal(resp.Threshold.String(), "1") - assert.Equal(resp.ThresholdExceededAt, "2021-03-16T01:01:41+00:00") - assert.Equal(resp.Unit, "GB") -} - -func TestDedicatedRackGetDataTrafficNotificationSettingServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedRackApi{}.GetDataTrafficNotificationSetting(ctx, "server-id", "notification id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedRackApi{}.GetDataTrafficNotificationSetting(ctx, "server-id", "notification id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "404", "errorMessage": "Resource not found"}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedRackApi{}.GetDataTrafficNotificationSetting(ctx, "server-id", "notification id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "404", - Message: "Resource not found", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedRackApi{}.GetDataTrafficNotificationSetting(ctx, "server-id", "notification id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedRackApi{}.GetDataTrafficNotificationSetting(ctx, "server-id", "notification id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedRackUpdateDataTrafficNotificationSetting(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "actions": [ - { - "lastTriggeredAt": "2021-03-16T01:01:44+00:00", - "type": "EMAIL" - } - ], - "frequency": "MONTHLY", - "id": "12345", - "lastCheckedAt": "2021-03-16T01:01:41+00:00", - "threshold": "2", - "thresholdExceededAt": "2021-03-16T01:01:41+00:00", - "unit": "GB" - }`) - }) - defer teardown() - - payload := map[string]string{"frequency": "MONTHLY", "threshold": "2", "unit": "GB"} - ctx := context.Background() - resp, err := DedicatedRackApi{}.UpdateDataTrafficNotificationSetting(ctx, "server-id", "notification id", payload) - assert := assert.New(t) - assert.Nil(err) - - assert.Equal(resp.Actions[0].LastTriggeredAt, "2021-03-16T01:01:44+00:00") - assert.Equal(resp.Actions[0].Type, "EMAIL") - assert.Equal(resp.Frequency, "MONTHLY") - assert.Equal(resp.Id, "12345") - assert.Equal(resp.LastCheckedAt, "2021-03-16T01:01:41+00:00") - assert.Equal(resp.Threshold.String(), "2") - assert.Equal(resp.ThresholdExceededAt, "2021-03-16T01:01:41+00:00") - assert.Equal(resp.Unit, "GB") -} - -func TestDedicatedRackUpdateDataTrafficNotificationSettingServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - payload := map[string]string{"frequency": "MONTHLY", "threshold": "2", "unit": "GB"} - ctx := context.Background() - return DedicatedRackApi{}.UpdateDataTrafficNotificationSetting(ctx, "server-id", "notification id", payload) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - payload := map[string]string{"frequency": "MONTHLY", "threshold": "2", "unit": "GB"} - ctx := context.Background() - return DedicatedRackApi{}.UpdateDataTrafficNotificationSetting(ctx, "server-id", "notification id", payload) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "404", "errorMessage": "Resource not found"}`) - }, - FunctionCall: func() (interface{}, error) { - payload := map[string]string{"frequency": "MONTHLY", "threshold": "2", "unit": "GB"} - ctx := context.Background() - return DedicatedRackApi{}.UpdateDataTrafficNotificationSetting(ctx, "server-id", "notification id", payload) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "404", - Message: "Resource not found", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - payload := map[string]string{"frequency": "MONTHLY", "threshold": "2", "unit": "GB"} - ctx := context.Background() - return DedicatedRackApi{}.UpdateDataTrafficNotificationSetting(ctx, "server-id", "notification id", payload) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - payload := map[string]string{"frequency": "MONTHLY", "threshold": "2", "unit": "GB"} - ctx := context.Background() - return DedicatedRackApi{}.UpdateDataTrafficNotificationSetting(ctx, "server-id", "notification id", payload) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedRackListBandWidthNotificationSettings(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "_metadata": { - "limit": 10, - "offset": 0, - "totalCount": 2 - }, - "bandwidthNotificationSettings": [ - { - "actions": [ - { - "lastTriggeredAt": "2021-03-16T01:01:44+00:00", - "type": "EMAIL" - } - ], - "frequency": "WEEKLY", - "id": "12345", - "lastCheckedAt": "2021-03-16T01:01:41+00:00", - "threshold": "1", - "thresholdExceededAt": "2021-03-16T01:01:41+00:00", - "unit": "Gbps" - }, - { - "actions": [ - { - "lastTriggeredAt": "2021-03-16T01:01:44+00:00", - "type": "EMAIL" - } - ], - "frequency": "DAILY", - "id": "123456", - "lastCheckedAt": "2021-03-16T01:01:41+00:00", - "threshold": "1", - "thresholdExceededAt": "2021-03-16T01:01:41+00:00", - "unit": "Mbps" - } - ] - }`) - }) - defer teardown() - - ctx := context.Background() - resp, err := DedicatedRackApi{}.ListBandWidthNotificationSettings(ctx, "server-id", PaginationOptions{}) - assert := assert.New(t) - assert.Nil(err) - assert.Equal(resp.Metadata.TotalCount, 2) - assert.Equal(resp.Metadata.Offset, 0) - assert.Equal(resp.Metadata.Limit, 10) - assert.Equal(len(resp.Settings), 2) - - assert.Equal(resp.Settings[0].Actions[0].LastTriggeredAt, "2021-03-16T01:01:44+00:00") - assert.Equal(resp.Settings[0].Actions[0].Type, "EMAIL") - assert.Equal(resp.Settings[0].Frequency, "WEEKLY") - assert.Equal(resp.Settings[0].Id, "12345") - assert.Equal(resp.Settings[0].LastCheckedAt, "2021-03-16T01:01:41+00:00") - assert.Equal(resp.Settings[0].Threshold.String(), "1") - assert.Equal(resp.Settings[0].ThresholdExceededAt, "2021-03-16T01:01:41+00:00") - assert.Equal(resp.Settings[0].Unit, "Gbps") - - assert.Equal(resp.Settings[1].Actions[0].LastTriggeredAt, "2021-03-16T01:01:44+00:00") - assert.Equal(resp.Settings[1].Actions[0].Type, "EMAIL") - assert.Equal(resp.Settings[1].Frequency, "DAILY") - assert.Equal(resp.Settings[1].Id, "123456") - assert.Equal(resp.Settings[1].LastCheckedAt, "2021-03-16T01:01:41+00:00") - assert.Equal(resp.Settings[1].Threshold.String(), "1") - assert.Equal(resp.Settings[1].ThresholdExceededAt, "2021-03-16T01:01:41+00:00") - assert.Equal(resp.Settings[1].Unit, "Mbps") -} - -func TestDedicatedRackListBandWidthNotificationSettingsPaginate(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "_metadata": { - "limit": 10, - "offset": 1, - "totalCount": 11 - }, - "bandwidthNotificationSettings": [ - { - "actions": [ - { - "lastTriggeredAt": "2021-03-16T01:01:44+00:00", - "type": "EMAIL" - } - ], - "frequency": "WEEKLY", - "id": "12345", - "lastCheckedAt": "2021-03-16T01:01:41+00:00", - "threshold": "1", - "thresholdExceededAt": "2021-03-16T01:01:41+00:00", - "unit": "Gbps" - } - ] - }`) - }) - defer teardown() - - ctx := context.Background() - opts := PaginationOptions{ - Limit: Int(1), - } - resp, err := DedicatedRackApi{}.ListBandWidthNotificationSettings(ctx, "server-id", opts) - assert := assert.New(t) - assert.Nil(err) - assert.Equal(resp.Metadata.TotalCount, 11) - assert.Equal(resp.Metadata.Offset, 1) - assert.Equal(resp.Metadata.Limit, 10) - assert.Equal(len(resp.Settings), 1) - - assert.Equal(resp.Settings[0].Actions[0].LastTriggeredAt, "2021-03-16T01:01:44+00:00") - assert.Equal(resp.Settings[0].Actions[0].Type, "EMAIL") - assert.Equal(resp.Settings[0].Frequency, "WEEKLY") - assert.Equal(resp.Settings[0].Id, "12345") - assert.Equal(resp.Settings[0].LastCheckedAt, "2021-03-16T01:01:41+00:00") - assert.Equal(resp.Settings[0].Threshold.String(), "1") - assert.Equal(resp.Settings[0].ThresholdExceededAt, "2021-03-16T01:01:41+00:00") - assert.Equal(resp.Settings[0].Unit, "Gbps") -} - -func TestDedicatedRackListBandWidthNotificationSettingsServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedRackApi{}.ListBandWidthNotificationSettings(ctx, "server-id", PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedRackApi{}.ListBandWidthNotificationSettings(ctx, "server-id", PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "404", "errorMessage": "Resource not found"}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedRackApi{}.ListBandWidthNotificationSettings(ctx, "server-id", PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "404", - Message: "Resource not found", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedRackApi{}.ListBandWidthNotificationSettings(ctx, "server-id", PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedRackApi{}.ListBandWidthNotificationSettings(ctx, "server-id", PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedRackCreateBandWidthNotificationSetting(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "actions": [ - { - "lastTriggeredAt": "2021-03-16T01:01:44+00:00", - "type": "EMAIL" - } - ], - "frequency": "WEEKLY", - "id": "12345", - "lastCheckedAt": "2021-03-16T01:01:41+00:00", - "threshold": "1", - "thresholdExceededAt": "2021-03-16T01:01:41+00:00", - "unit": "Gbps" - }`) - }) - defer teardown() - - ctx := context.Background() - resp, err := DedicatedRackApi{}.CreateBandWidthNotificationSetting(ctx, "server-id", "WEEKLY", "1", "Gbps") - assert := assert.New(t) - assert.Nil(err) - - assert.Equal(resp.Actions[0].LastTriggeredAt, "2021-03-16T01:01:44+00:00") - assert.Equal(resp.Actions[0].Type, "EMAIL") - assert.Equal(resp.Frequency, "WEEKLY") - assert.Equal(resp.Id, "12345") - assert.Equal(resp.LastCheckedAt, "2021-03-16T01:01:41+00:00") - assert.Equal(resp.Threshold.String(), "1") - assert.Equal(resp.ThresholdExceededAt, "2021-03-16T01:01:41+00:00") - assert.Equal(resp.Unit, "Gbps") -} - -func TestDedicatedRackCreateBandWidthNotificationSettingServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedRackApi{}.CreateBandWidthNotificationSetting(ctx, "server-id", "WEEKLY", "1", "Gbps") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedRackApi{}.CreateBandWidthNotificationSetting(ctx, "server-id", "WEEKLY", "1", "Gbps") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "404", "errorMessage": "Resource not found"}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedRackApi{}.CreateBandWidthNotificationSetting(ctx, "server-id", "WEEKLY", "1", "Gbps") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "404", - Message: "Resource not found", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedRackApi{}.CreateBandWidthNotificationSetting(ctx, "server-id", "WEEKLY", "1", "Gbps") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedRackApi{}.CreateBandWidthNotificationSetting(ctx, "server-id", "WEEKLY", "1", "Gbps") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedRackDeleteBandWidthNotificationSetting(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusNoContent) - }) - defer teardown() - - ctx := context.Background() - err := DedicatedRackApi{}.DeleteBandWidthNotificationSetting(ctx, "server id", "notification id") - assert := assert.New(t) - assert.Nil(err) -} - -func TestDedicatedRackDeleteBandWidthNotificationSettingServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedRackApi{}.DeleteBandWidthNotificationSetting(ctx, "server id", "notification id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedRackApi{}.DeleteBandWidthNotificationSetting(ctx, "server id", "notification id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "404", "errorMessage": "Resource not found"}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedRackApi{}.DeleteBandWidthNotificationSetting(ctx, "server id", "notification id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "404", - Message: "Resource not found", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedRackApi{}.DeleteBandWidthNotificationSetting(ctx, "server id", "notification id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedRackApi{}.DeleteBandWidthNotificationSetting(ctx, "server id", "notification id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedRackGetBandWidthNotificationSetting(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "actions": [ - { - "lastTriggeredAt": "2021-03-16T01:01:44+00:00", - "type": "EMAIL" - } - ], - "frequency": "WEEKLY", - "id": "12345", - "lastCheckedAt": "2021-03-16T01:01:41+00:00", - "threshold": "1", - "thresholdExceededAt": "2021-03-16T01:01:41+00:00", - "unit": "Gbps" - }`) - }) - defer teardown() - - ctx := context.Background() - resp, err := DedicatedRackApi{}.GetBandWidthNotificationSetting(ctx, "server-id", "notification id") - assert := assert.New(t) - assert.Nil(err) - - assert.Equal(resp.Actions[0].LastTriggeredAt, "2021-03-16T01:01:44+00:00") - assert.Equal(resp.Actions[0].Type, "EMAIL") - assert.Equal(resp.Frequency, "WEEKLY") - assert.Equal(resp.Id, "12345") - assert.Equal(resp.LastCheckedAt, "2021-03-16T01:01:41+00:00") - assert.Equal(resp.Threshold.String(), "1") - assert.Equal(resp.ThresholdExceededAt, "2021-03-16T01:01:41+00:00") - assert.Equal(resp.Unit, "Gbps") -} - -func TestDedicatedRackGetBandWidthNotificationSettingServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedRackApi{}.GetBandWidthNotificationSetting(ctx, "server-id", "notification id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedRackApi{}.GetBandWidthNotificationSetting(ctx, "server-id", "notification id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "404", "errorMessage": "Resource not found"}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedRackApi{}.GetBandWidthNotificationSetting(ctx, "server-id", "notification id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "404", - Message: "Resource not found", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedRackApi{}.GetBandWidthNotificationSetting(ctx, "server-id", "notification id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedRackApi{}.GetBandWidthNotificationSetting(ctx, "server-id", "notification id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedRackUpdateBandWidthNotificationSetting(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "actions": [ - { - "lastTriggeredAt": "2021-03-16T01:01:44+00:00", - "type": "EMAIL" - } - ], - "frequency": "MONTHLY", - "id": "12345", - "lastCheckedAt": "2021-03-16T01:01:41+00:00", - "threshold": "2", - "thresholdExceededAt": "2021-03-16T01:01:41+00:00", - "unit": "Mbps" - }`) - }) - defer teardown() - - payload := map[string]string{"frequency": "MONTHLY", "threshold": "2", "unit": "Mbps"} - ctx := context.Background() - resp, err := DedicatedRackApi{}.UpdateBandWidthNotificationSetting(ctx, "server-id", "notification id", payload) - assert := assert.New(t) - assert.Nil(err) - - assert.Equal(resp.Actions[0].LastTriggeredAt, "2021-03-16T01:01:44+00:00") - assert.Equal(resp.Actions[0].Type, "EMAIL") - assert.Equal(resp.Frequency, "MONTHLY") - assert.Equal(resp.Id, "12345") - assert.Equal(resp.LastCheckedAt, "2021-03-16T01:01:41+00:00") - assert.Equal(resp.Threshold.String(), "2") - assert.Equal(resp.ThresholdExceededAt, "2021-03-16T01:01:41+00:00") - assert.Equal(resp.Unit, "Mbps") -} - -func TestDedicatedRackUpdateBandWidthNotificationSettingServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - payload := map[string]string{"frequency": "MONTHLY", "threshold": "2", "unit": "Mbps"} - ctx := context.Background() - return DedicatedRackApi{}.UpdateBandWidthNotificationSetting(ctx, "server-id", "notification id", payload) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - payload := map[string]string{"frequency": "MONTHLY", "threshold": "2", "unit": "Mbps"} - ctx := context.Background() - return DedicatedRackApi{}.UpdateBandWidthNotificationSetting(ctx, "server-id", "notification id", payload) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "404", "errorMessage": "Resource not found"}`) - }, - FunctionCall: func() (interface{}, error) { - payload := map[string]string{"frequency": "MONTHLY", "threshold": "2", "unit": "Mbps"} - ctx := context.Background() - return DedicatedRackApi{}.UpdateBandWidthNotificationSetting(ctx, "server-id", "notification id", payload) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "404", - Message: "Resource not found", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - payload := map[string]string{"frequency": "MONTHLY", "threshold": "2", "unit": "Mbps"} - ctx := context.Background() - return DedicatedRackApi{}.UpdateBandWidthNotificationSetting(ctx, "server-id", "notification id", payload) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - payload := map[string]string{"frequency": "MONTHLY", "threshold": "2", "unit": "Mbps"} - ctx := context.Background() - return DedicatedRackApi{}.UpdateBandWidthNotificationSetting(ctx, "server-id", "notification id", payload) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} diff --git a/dedicated_server.go b/dedicated_server.go deleted file mode 100644 index bc7da0a..0000000 --- a/dedicated_server.go +++ /dev/null @@ -1,980 +0,0 @@ -package leaseweb - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "net/url" - - "github.com/LeaseWeb/leaseweb-go-sdk/options" -) - -const DEDICATED_SERVER_API_VERSION = "v2" - -type DedicatedServerApi struct{} - -type DedicatedServers struct { - Servers []DedicatedServer `json:"servers"` - Metadata Metadata `json:"_metadata"` -} - -type DedicatedServer struct { - AssetId string `json:"assetId"` - Contract Contract `json:"contract"` - FeatureAvailability FeatureAvailability `json:"featureAvailability"` - Id string `json:"id"` - Location Location `json:"location"` - NetworkInterfaces NetworkInterfaces `json:"networkInterfaces"` - PowerPorts []Port `json:"powerPorts"` - PrivateNetworks []PrivateNetwork `json:"privateNetworks"` - Rack DedicatedServerRack `json:"rack"` - SerialNumber string `json:"serialNumber"` - Specs DedicatedServerSpecs `json:"specs"` -} - -type DedicatedServerSpecs struct { - Chassis string `json:"chassis"` - HardwareRaidCapable bool `json:"hardwareRaidCapable"` - Cpu DedicatedServerSpecCpu `json:"cpu"` - Ram DedicatedServerSpecRam `json:"ram"` - Hdd []DedicatedServerSpecHdd `json:"hdd"` - PciCards []DedicatedServerSpecPciCard `json:"pciCards"` -} - -type DedicatedServerSpecCpu struct { - Quantity json.Number `json:"quantity"` - Type string `json:"type"` -} - -type DedicatedServerSpecRam struct { - Size json.Number `json:"size"` - Unit string `json:"unit"` -} - -type DedicatedServerSpecHdd struct { - Amount json.Number `json:"amount"` - Id string `json:"id"` - PerformanceType string `json:"performanceType"` - Size json.Number `json:"size"` - Type string `json:"type"` - Unit string `json:"unit"` -} - -type DedicatedServerSpecPciCard struct { - Description string `json:"description"` -} - -type DedicatedServerRack struct { - Type string `json:"type"` -} - -type DedicatedServerHardware struct { - Id string `json:"id"` - ParserVersion string `json:"parserVersion"` - Result DedicatedServerHardwareInformation `json:"result"` - ScannedAt string `json:"scannedAt"` - ServerId string `json:"serverId"` -} - -type DedicatedServerHardwareInformation struct { - Chassis DedicatedServerChassis `json:"chassis"` - Cpu []DedicatedServerCpu `json:"cpu"` - Ipmi DedicatedServerIpmi `json:"ipmi"` - Disks []DedicatedServerDisks `json:"disks"` - Memories []DedicatedServerMemory `json:"memory"` - Networks []DedicatedServerNetwork `json:"network"` -} - -type DedicatedServerChassis struct { - Description string `json:"description"` - Firmware DedicatedServerChassisFirmware `json:"firmware"` - Motherboard DedicatedServerChassisMotherboard `json:"motherboard"` - Product string `json:"product"` - Serial string `json:"serial"` - Vendor string `json:"vendor"` -} - -type DedicatedServerChassisFirmware struct { - Date string `json:"date"` - Description string `json:"description"` - Vendor string `json:"vendor"` - Version string `json:"version"` -} - -type DedicatedServerChassisMotherboard struct { - Product string `json:"product"` - Serial string `json:"serial"` - Vendor string `json:"vendor"` -} - -type DedicatedServerCpu struct { - Capabilities DedicatedServerCpuCapabilities `json:"capabilities"` - Description string `json:"description"` - HZ string `json:"hz"` - SerialNumber string `json:"serial_number"` - Settings DedicatedServerCpuSettings `json:"settings"` - Slot string `json:"slot"` - Vendor string `json:"vendor"` -} - -type DedicatedServerCpuSettings struct { - Cores string `json:"cores"` - EnabledCores string `json:"enabledcores"` - Threads string `json:"threads"` -} - -type DedicatedServerCpuCapabilities struct { - CpuFreq string `json:"cpufreq"` - HT string `json:"ht"` - VMX bool `json:"vmx"` - X8664 string `json:"x86-64"` -} - -type DedicatedServerIpmi struct { - Defgateway string `json:"defgateway"` - Firmware string `json:"firmware"` - IpAddress string `json:"ipaddress"` - IpSource string `json:"ipsource"` - MacAddress string `json:"macaddress"` - SubnetMask string `json:"subnetmask"` - Vendor string `json:"vendor"` -} - -type DedicatedServerMemory struct { - ClockHZ string `json:"clock_hz"` - Description string `json:"description"` - Id string `json:"id"` - SerialNumber string `json:"serial_number"` - SizeBytes string `json:"size_bytes"` -} - -type DedicatedServerDisks struct { - Description string `json:"description"` - Id string `json:"id"` - Product string `json:"product"` - SerialNumber string `json:"serial_number"` - Size string `json:"size"` - SmartCTL DedicatedServerDisksSmartCTL `json:"smartctl"` - Vendor string `json:"vendor"` -} - -type DedicatedServerDisksSmartCTL struct { - ATAVersion string `json:"ata_version"` - Attributes DedicatedServerDisksSmartCTLAttributes `json:"attributes"` - DeviceModel string `json:"device_model"` - ExecutionStatus string `json:"execution_status"` - FirmwareVersion string `json:"firmware_version"` - ISSAS bool `json:"is_sas"` - OverallHealth string `json:"overall_health"` - RPM string `json:"rpm"` - SATAVersion string `json:"sata_version"` - SectorSize string `json:"sector_size"` - SerialNumber string `json:"serial_number"` - SmartErrorLog string `json:"smart_error_log"` - SmartSupport DedicatedServerDisksSmartCTLSupport `json:"smart_support"` - SmartctlVersion string `json:"smartctl_version"` - UserCapacity string `json:"user_capacity"` -} - -type DedicatedServerDisksSmartCTLSupport struct { - Available bool `json:"available"` - Enabled bool `json:"enabled"` -} - -type DedicatedServerDisksSmartCTLAttributes struct { - PowerOnHours DedicatedServerDisksSmartCTLAttributesType `json:"Power_On_Hours"` - ReallocatedSectorCT DedicatedServerDisksSmartCTLAttributesType `json:"Reallocated_Sector_Ct"` -} - -type DedicatedServerDisksSmartCTLAttributesType struct { - Flag string `json:"flag"` - Id string `json:"id"` - RawValue string `json:"raw_value"` - Thresh string `json:"thresh"` - Type string `json:"type"` - Updated string `json:"updated"` - Value string `json:"value"` - WhenFailed string `json:"when_failed"` - Worst string `json:"worst"` -} - -type DedicatedServerNetwork struct { - Capabilities DedicatedServerNetworkCapabilities `json:"capabilities"` - LLDP DedicatedServerNetworkLLDP `json:"lldp"` - LogicalName string `json:"logical_name"` - MacAddress string `json:"mac_address"` - Product string `json:"product"` - Settings DedicatedServerNetworkSettings `json:"settings"` - Vendor string `json:"vendor"` -} - -type DedicatedServerNetworkSettings struct { - AutoNegotiation string `json:"autonegotiation"` - Broadcast string `json:"broadcast"` - Driver string `json:"driver"` - DriverVersion string `json:"driverversion"` - Duplex string `json:"duplex"` - Firmware string `json:"firmware"` - Ip string `json:"ip"` - Latency string `json:"latency"` - Link string `json:"link"` - Multicast string `json:"multicast"` - Port string `json:"port"` - Speed string `json:"speed"` -} - -type DedicatedServerNetworkLLDP struct { - Chassis DedicatedServerNetworkLLDPChassis `json:"chassis"` - Port DedicatedServerNetworkPort `json:"port"` - Vlan DedicatedServerNetworkLLDPVlan `json:"vlan"` -} - -type DedicatedServerNetworkLLDPVlan struct { - Id string `json:"id"` - Label string `json:"label"` - Name string `json:"name"` -} - -type DedicatedServerNetworkLLDPChassis struct { - Description string `json:"description"` - MacAddress string `json:"mac_address"` - Name string `json:"name"` -} - -type DedicatedServerNetworkPort struct { - Description string `json:"description"` - AutoNegotiation DedicatedServerNetworkPortAutoNegotiation `json:"auto_negotiation"` -} - -type DedicatedServerNetworkPortAutoNegotiation struct { - Enabled string `json:"enabled"` - Supported string `json:"supported"` -} - -type DedicatedServerNetworkCapabilities struct { - AutoNegotiation string `json:"autonegotiation"` - BusMaster string `json:"bus_master"` - CapList string `json:"cap_list"` - Ethernet string `json:"ethernet"` - LinkSpeeds DedicatedServerNetworkCapabilitiesLinkSpeeds `json:"link_speeds"` - MSI string `json:"msi"` - MSIX string `json:"msix"` - PciExpress string `json:"pciexpress"` - Physical string `json:"physical"` - PM string `json:"pm"` - TP string `json:"tp"` -} - -type DedicatedServerNetworkCapabilitiesLinkSpeeds struct { - BTFD1000 string `json:"1000bt-fd"` - BT100 string `json:"100bt"` - BTFD100 string `json:"100bt-fd"` - BT10 string `json:"10bt"` - BTFD10 string `json:"10bt-fd"` -} - -type DedicatedServerNetworkInterfaces struct { - NetworkInterfaces []DedicatedServerNetworkInterface `json:"networkInterfaces"` - Metadata Metadata `json:"_metadata"` -} - -type DedicatedServerNetworkInterface struct { - LinkSpeed string `json:"linkSpeed"` - OperStatus string `json:"operStatus"` - Status string `json:"status"` - SwitchInterface string `json:"switchInterface"` - SwitchName string `json:"switchName"` - Type string `json:"type"` -} - -type DedicatedServerDhcpReservations struct { - Leases []DedicatedServerDhcpReservation `json:"leases"` - Metadata Metadata `json:"_metadata"` -} - -type DedicatedServerDhcpReservation struct { - BootFile string `json:"bootfile"` - CreatedAt string `json:"createdAt"` - Gateway string `json:"gateway"` - Hostname string `json:"hostname"` - Ip string `json:"ip"` - LastClientRequest DedicatedServerDhcpReservationLastClientRequest `json:"lastClientRequest"` - Mac string `json:"mac"` - Netmask string `json:"netmask"` - Site string `json:"site"` - UpdatedAt string `json:"updatedAt"` -} - -type DedicatedServerDhcpReservationLastClientRequest struct { - RelayAgent string `json:"relayAgent"` - Type string `json:"type"` - UserAgent string `json:"userAgent"` -} - -type DedicatedServerJobs struct { - Jobs []DedicatedServerJob `json:"jobs"` - Metadata Metadata `json:"_metadata"` -} - -type DedicatedServerJob struct { - CreatedAt string `json:"createdAt"` - Flow string `json:"flow"` - IsRunning bool `json:"isRunning"` - Node string `json:"node"` - Payload DedicatedServerJobPayload `json:"payload"` - Progress DedicatedServerJobProgress `json:"progress"` - ServerId string `json:"serverId"` - Status string `json:"status"` - Tasks []DedicatedServerJobTask `json:"tasks"` - Type string `json:"type"` - UpdatedAt string `json:"updatedAt"` - Uuid string `json:"uuid"` - Metadata struct { - BatchId string `json:"BATCH_ID"` - } `json:"metadata"` -} - -type DedicatedServerJobPayload map[string]interface{} - -type DedicatedServerJobProgress struct { - Canceled json.Number `json:"canceled"` - Expired json.Number `json:"expired"` - Failed json.Number `json:"failed"` - Finished json.Number `json:"finished"` - InProgress json.Number `json:"inprogress"` - Pending json.Number `json:"pending"` - Percentage json.Number `json:"percentage"` - Total json.Number `json:"total"` - Waiting json.Number `json:"waiting"` -} - -type DedicatedServerJobTask struct { - Description string `json:"description"` - Message string `json:"errorMessage"` - Flow string `json:"flow"` - OnError string `json:"onError"` - Status string `json:"status"` - StatusTimestamps DedicatedServerJobTaskStatusTimeStamp `json:"statusTimestamps"` - Uuid string `json:"uuid"` -} - -type DedicatedServerJobTaskStatusTimeStamp struct { - Canceled string `json:"CANCELED"` - Pending string `json:"PENDING"` - Waiting string `json:"WAITING"` -} - -type DedicatedServerOperatingSystems struct { - Metadata Metadata `json:"_metadata"` - OperatingSystems []DedicatedServerOperatingSystem `json:"operatingSystems"` -} - -type DedicatedServerOperatingSystem struct { - Id string `json:"id"` - Name string `json:"name"` - Architecture string `json:"architecture"` - Configurable bool `json:"configurable"` - Family string `json:"family"` - Type string `json:"type"` - Version string `json:"version"` - Features []string `json:"features"` - SupportedBootDevices []string `json:"supportedBootDevices"` - SupportedFileSystems []string `json:"supportedFileSystems"` - Defaults DedicatedServerOperatingSystemDefaults `json:"defaults"` -} - -type DedicatedServerOperatingSystemDefaults struct { - Device string `json:"device"` - Partitions []DedicatedServerOperatingSystemPartition `json:"partitions"` -} - -type DedicatedServerOperatingSystemPartition struct { - Bootable bool `json:"bootable"` - Filesystem string `json:"filesystem"` - Mountpoint string `json:"mountpoint"` - Primary bool `json:"primary"` - Size string `json:"size"` -} - -type DedicatedServerControlPanels struct { - Metadata Metadata `json:"_metadata"` - ControlPanels []DedicatedServerControlPanel `json:"controlPanels"` -} - -type DedicatedServerControlPanel struct { - Id string `json:"id"` - Name string `json:"name"` -} - -type DedicatedServerRescueImages struct { - Metadata Metadata `json:"_metadata"` - RescueImages []DedicatedServerRescueImage `json:"rescueImages"` -} - -type DedicatedServerRescueImage struct { - Id string `json:"id"` - Name string `json:"name"` -} - -type DedicatedServerListOptions struct { - PaginationOptions - IP *string `param:"ip"` - MacAddress *string `param:"macAddress"` - Site *string `param:"site"` - PrivateRackID *string `param:"privateRackId"` - Reference *string `param:"reference"` - PrivateNetworkCapable *bool `param:"privateNetworkCapable"` - PrivateNetworkEnabled *bool `param:"privateNetworkEnabled"` -} - -type DedicatedServerListIpsOptions struct { - PaginationOptions - NetworkType *string `param:"networkType"` - Version *string `param:"version"` - NullRouted *string `param:"nullRouted"` - IPs []string `param:"ips"` -} - -type DedicatedServerListJobOptions struct { - PaginationOptions - Type *string `param:"type"` - Status *string `param:"status"` - IsRunning *bool `param:"isRunning"` -} - -type DedicatedServerListOperatingSystemsOptions struct { - PaginationOptions - ControlPanelId *string `param:"controlPanelId"` -} - -type DedicatedServerListControlPanelsOptions struct { - PaginationOptions - OperatingSystemId *string `param:"operatingSystemId"` -} - -func (dsa DedicatedServerApi) getPath(endpoint string) string { - return "/bareMetals/" + DEDICATED_SERVER_API_VERSION + endpoint -} - -func (dsa DedicatedServerApi) List(ctx context.Context, opts DedicatedServerListOptions) (*DedicatedServers, error) { - path := dsa.getPath("/servers") - query := options.Encode(opts) - result := &DedicatedServers{} - if err := doRequest(ctx, http.MethodGet, path, query, result); err != nil { - return nil, err - } - return result, nil -} - -// AllWithOpts will return all dedicated servers and allows filtering options be specified as an argument -func (dsa DedicatedServerApi) AllWithOpts(ctx context.Context, opts DedicatedServerListOptions) ([]DedicatedServer, error) { - var allServers []DedicatedServer - - // handle default pagination if Offset or Limit are undefined - if opts.PaginationOptions.Offset == nil || opts.PaginationOptions.Limit == nil { - opts.PaginationOptions = PaginationOptions{Offset: Int(0), Limit: Int(20)} - } - - for { - // List all dedicated servers with defined opts - result, err := DedicatedServerApi{}.List(ctx, opts) - if err != nil { - return nil, err - } - - // Break if no more servers are found - if len(result.Servers) == 0 { - break - } - - // Append servers to list - allServers = append(allServers, result.Servers...) - // Increment Offset with the value of Limit - *opts.PaginationOptions.Offset += *opts.PaginationOptions.Limit - } - - return allServers, nil -} - -// All will return all dedicated servers without optional filters specified -func (dsa DedicatedServerApi) All(ctx context.Context) ([]DedicatedServer, error) { - return dsa.AllWithOpts(ctx, DedicatedServerListOptions{}) -} - -func (dsa DedicatedServerApi) Get(ctx context.Context, serverId string) (*DedicatedServer, error) { - path := dsa.getPath("/servers/" + serverId) - result := &DedicatedServer{} - if err := doRequest(ctx, http.MethodGet, path, "", result); err != nil { - return nil, err - } - return result, nil -} - -func (dsa DedicatedServerApi) Update(ctx context.Context, serverId string, payload map[string]interface{}) error { - path := dsa.getPath("/servers/" + serverId) - return doRequest(ctx, http.MethodPut, path, "", nil, payload) -} - -func (dsa DedicatedServerApi) GetHardwareInformation(ctx context.Context, serverId string) (*DedicatedServerHardware, error) { - path := dsa.getPath("/servers/" + serverId + "/hardwareInfo") - result := &DedicatedServerHardware{} - if err := doRequest(ctx, http.MethodGet, path, "", result); err != nil { - return nil, err - } - return result, nil -} - -func (dsa DedicatedServerApi) ListIps(ctx context.Context, serverId string, opts DedicatedServerListIpsOptions) (*Ips, error) { - path := dsa.getPath("/servers/" + serverId + "/ips") - query := options.Encode(opts) - result := &Ips{} - if err := doRequest(ctx, http.MethodGet, path, query, result); err != nil { - return nil, err - } - return result, nil -} - -func (dsa DedicatedServerApi) GetIp(ctx context.Context, serverId, ip string) (*Ip, error) { - path := dsa.getPath("/servers/" + serverId + "/ips/" + ip) - result := &Ip{} - if err := doRequest(ctx, http.MethodGet, path, "", result); err != nil { - return nil, err - } - return result, nil -} - -func (dsa DedicatedServerApi) UpdateIp(ctx context.Context, serverId, ip string, payload map[string]string) (*Ip, error) { - path := dsa.getPath("/servers/" + serverId + "/ips/" + ip) - result := &Ip{} - if err := doRequest(ctx, http.MethodPut, path, "", result, payload); err != nil { - return nil, err - } - return result, nil -} - -func (dsa DedicatedServerApi) NullRouteAnIp(ctx context.Context, serverId, ip string) (*Ip, error) { - path := dsa.getPath("/servers/" + serverId + "/ips/" + ip + "/null") - result := &Ip{} - if err := doRequest(ctx, http.MethodPost, path, "", result); err != nil { - return nil, err - } - return result, nil -} - -func (dsa DedicatedServerApi) RemoveNullRouteAnIp(ctx context.Context, serverId, ip string) (*Ip, error) { - path := dsa.getPath("/servers/" + serverId + "/ips/" + ip + "/unnull") - result := &Ip{} - if err := doRequest(ctx, http.MethodPost, path, "", result); err != nil { - return nil, err - } - return result, nil -} - -func (dsa DedicatedServerApi) ListNullRoutes(ctx context.Context, serverId string, opts PaginationOptions) (*NullRoutes, error) { - path := dsa.getPath("/servers/" + serverId + "/nullRouteHistory") - query := options.Encode(opts) - result := &NullRoutes{} - if err := doRequest(ctx, http.MethodGet, path, query, result); err != nil { - return nil, err - } - return result, nil -} - -func (dsa DedicatedServerApi) ListNetworkInterfaces(ctx context.Context, serverId string, opts PaginationOptions) (*DedicatedServerNetworkInterfaces, error) { - path := dsa.getPath("/servers/" + serverId + "/networkInterfaces") - result := &DedicatedServerNetworkInterfaces{} - query := options.Encode(opts) - if err := doRequest(ctx, http.MethodGet, path, query, result); err != nil { - return nil, err - } - return result, nil -} - -func (dsa DedicatedServerApi) CloseAllNetworkInterfaces(ctx context.Context, serverId string) error { - path := dsa.getPath("/servers/" + serverId + "/networkInterfaces/close") - return doRequest(ctx, http.MethodPost, path, "") -} - -func (dsa DedicatedServerApi) OpenAllNetworkInterfaces(ctx context.Context, serverId string) error { - path := dsa.getPath("/servers/" + serverId + "/networkInterfaces/open") - return doRequest(ctx, http.MethodPost, path, "") -} - -func (dsa DedicatedServerApi) GetNetworkInterface(ctx context.Context, serverId, networkType string) (*DedicatedServerNetworkInterface, error) { - path := dsa.getPath("/servers/" + serverId + "/networkInterfaces/" + networkType) - result := &DedicatedServerNetworkInterface{} - if err := doRequest(ctx, http.MethodGet, path, "", result); err != nil { - return nil, err - } - return result, nil -} - -func (dsa DedicatedServerApi) CloseNetworkInterface(ctx context.Context, serverId, networkType string) error { - path := dsa.getPath("/servers/" + serverId + "/networkInterfaces/" + networkType + "/close") - return doRequest(ctx, http.MethodPost, path, "") -} - -func (dsa DedicatedServerApi) OpenNetworkInterface(ctx context.Context, serverId, networkType string) error { - path := dsa.getPath("/servers/" + serverId + "/networkInterfaces/" + networkType + "/open") - return doRequest(ctx, http.MethodPost, path, "") -} - -func (dsa DedicatedServerApi) DeleteServerFromPrivateNetwork(ctx context.Context, serverId, privateNetworkId string) error { - path := dsa.getPath("/servers/" + serverId + "/privateNetworks/" + privateNetworkId) - return doRequest(ctx, http.MethodDelete, path, "") -} - -func (dsa DedicatedServerApi) AddServerToPrivateNetwork(ctx context.Context, serverId, privateNetworkId string, linkSpeed int) error { - payload := map[string]int{"linkSpeed": linkSpeed} - path := dsa.getPath("/servers/" + serverId + "/privateNetworks/" + privateNetworkId) - return doRequest(ctx, http.MethodPut, path, "", nil, payload) -} - -func (dsa DedicatedServerApi) DeleteDhcpReservation(ctx context.Context, serverId string) error { - path := dsa.getPath("/servers/" + serverId + "/leases") - return doRequest(ctx, http.MethodDelete, path, "") -} - -func (dsa DedicatedServerApi) ListDhcpReservation(ctx context.Context, serverId string, opts PaginationOptions) (*DedicatedServerDhcpReservations, error) { - path := dsa.getPath("/servers/" + serverId + "/leases") - result := &DedicatedServerDhcpReservations{} - query := options.Encode(opts) - if err := doRequest(ctx, http.MethodGet, path, query, result); err != nil { - return nil, err - } - return result, nil -} - -func (dsa DedicatedServerApi) CreateDhcpReservation(ctx context.Context, serverId string, payload map[string]string) error { - path := dsa.getPath("/servers/" + serverId + "/leases") - return doRequest(ctx, http.MethodPost, path, "", nil, payload) -} - -func (dsa DedicatedServerApi) CancelActiveJob(ctx context.Context, serverId string) (*DedicatedServerJob, error) { - result := &DedicatedServerJob{} - path := dsa.getPath("/servers/" + serverId + "/cancelActiveJob") - if err := doRequest(ctx, http.MethodPost, path, "", result); err != nil { - return result, err - } - return result, nil -} - -func (dsa DedicatedServerApi) ExpireActiveJob(ctx context.Context, serverId string) (*DedicatedServerJob, error) { - result := &DedicatedServerJob{} - path := dsa.getPath("/servers/" + serverId + "/expireActiveJob") - if err := doRequest(ctx, http.MethodPost, path, "", result); err != nil { - return result, err - } - return result, nil -} - -func (dsa DedicatedServerApi) LaunchHardwareScan(ctx context.Context, serverId string, payload map[string]interface{}) (*DedicatedServerJob, error) { - result := &DedicatedServerJob{} - path := dsa.getPath("/servers/" + serverId + "/hardwareScan") - if err := doRequest(ctx, http.MethodPost, path, "", result, payload); err != nil { - return result, err - } - return result, nil -} - -func (dsa DedicatedServerApi) LaunchInstallation(ctx context.Context, serverId string, payload map[string]interface{}) (*DedicatedServerJob, error) { - result := &DedicatedServerJob{} - path := dsa.getPath("/servers/" + serverId + "/install") - if err := doRequest(ctx, http.MethodPost, path, "", result, payload); err != nil { - return result, err - } - return result, nil -} - -func (dsa DedicatedServerApi) LaunchIpmiRest(ctx context.Context, serverId string, payload map[string]interface{}) (*DedicatedServerJob, error) { - result := &DedicatedServerJob{} - path := dsa.getPath("/servers/" + serverId + "/ipmiRest") - if err := doRequest(ctx, http.MethodPost, path, "", result, payload); err != nil { - return result, err - } - return result, nil -} - -func (dsa DedicatedServerApi) ListJobs(ctx context.Context, serverId string, opts DedicatedServerListJobOptions) (*DedicatedServerJobs, error) { - result := &DedicatedServerJobs{} - path := dsa.getPath("/servers/" + serverId + "/jobs") - query := options.Encode(opts) - if err := doRequest(ctx, http.MethodGet, path, query, result); err != nil { - return result, err - } - return result, nil -} - -func (dsa DedicatedServerApi) GetJob(ctx context.Context, serverId, jobId string) (*DedicatedServerJob, error) { - result := &DedicatedServerJob{} - path := dsa.getPath("/servers/" + serverId + "/jobs/" + jobId) - if err := doRequest(ctx, http.MethodGet, path, "", result); err != nil { - return result, err - } - return result, nil -} - -func (dsa DedicatedServerApi) LaunchRescueMode(ctx context.Context, serverId string, payload map[string]interface{}) (*DedicatedServerJob, error) { - result := &DedicatedServerJob{} - path := dsa.getPath("/servers/" + serverId + "/rescueMode") - if err := doRequest(ctx, http.MethodPost, path, "", result, payload); err != nil { - return result, err - } - return result, nil -} - -func (dsa DedicatedServerApi) ListCredentials(ctx context.Context, serverId string, opts PaginationOptions) (*Credentials, error) { - result := &Credentials{} - path := dsa.getPath("/servers/" + serverId + "/credentials") - query := options.Encode(opts) - if err := doRequest(ctx, http.MethodGet, path, query, result); err != nil { - return result, err - } - return result, nil -} - -func (dsa DedicatedServerApi) CreateCredential(ctx context.Context, serverId, credentialType, username, password string) (*Credential, error) { - result := &Credential{} - payload := make(map[string]string) - payload["type"] = credentialType - payload["username"] = username - payload["password"] = password - path := dsa.getPath("/servers/" + serverId + "/credentials") - if err := doRequest(ctx, http.MethodPost, path, "", result, payload); err != nil { - return result, err - } - return result, nil -} - -func (dsa DedicatedServerApi) ListCredentialsByType(ctx context.Context, serverId, credentialType string, opts PaginationOptions) (*Credentials, error) { - result := &Credentials{} - path := dsa.getPath("/servers/" + serverId + "/credentials/" + credentialType) - query := options.Encode(opts) - if err := doRequest(ctx, http.MethodGet, path, query, result); err != nil { - return result, err - } - return result, nil -} - -func (dsa DedicatedServerApi) GetCredential(ctx context.Context, serverId, credentialType, username string) (*Credential, error) { - result := &Credential{} - path := dsa.getPath("/servers/" + serverId + "/credentials/" + credentialType + "/" + username) - if err := doRequest(ctx, http.MethodGet, path, "", result); err != nil { - return result, err - } - return result, nil -} - -func (dsa DedicatedServerApi) DeleteCredential(ctx context.Context, serverId, credentialType, username string) error { - path := dsa.getPath("/servers/" + serverId + "/credentials/" + credentialType + "/" + username) - return doRequest(ctx, http.MethodDelete, path, "") -} - -func (dsa DedicatedServerApi) UpdateCredential(ctx context.Context, serverId, credentialType, username, password string) (*Credential, error) { - result := &Credential{} - payload := map[string]string{"password": password} - path := dsa.getPath("/servers/" + serverId + "/credentials/" + credentialType + "/" + username) - if err := doRequest(ctx, http.MethodPut, path, "", result, payload); err != nil { - return result, err - } - return result, nil -} - -func (dsa DedicatedServerApi) GetDataTrafficMetrics(ctx context.Context, serverId string, opts MetricsOptions) (*DataTrafficMetricsV1, error) { - path := dsa.getPath("/servers/" + serverId + "/metrics/datatraffic") - query := options.Encode(opts) - result := &DataTrafficMetricsV1{} - if err := doRequest(ctx, http.MethodGet, path, query, result); err != nil { - return nil, err - } - return result, nil -} - -func (dsa DedicatedServerApi) GetBandWidthMetrics(ctx context.Context, serverId string, opts MetricsOptions) (*BandWidthMetrics, error) { - path := dsa.getPath("/servers/" + serverId + "/metrics/bandwidth") - query := options.Encode(opts) - result := &BandWidthMetrics{} - if err := doRequest(ctx, http.MethodGet, path, query, result); err != nil { - return nil, err - } - return result, nil -} - -func (dsa DedicatedServerApi) ListBandWidthNotificationSettings(ctx context.Context, serverId string, opts PaginationOptions) (*BandWidthNotificationSettings, error) { - result := &BandWidthNotificationSettings{} - path := dsa.getPath("/servers/" + serverId + "/notificationSettings/bandwidth") - query := options.Encode(opts) - if err := doRequest(ctx, http.MethodGet, path, query, result); err != nil { - return result, err - } - return result, nil -} - -func (dsa DedicatedServerApi) CreateBandWidthNotificationSetting(ctx context.Context, serverId, frequency string, threshold float64, unit string) (*NotificationSetting, error) { - - payload := map[string]string{ - "frequency": frequency, - "threshold": fmt.Sprintf("%g", threshold), - "unit": unit, - } - result := &NotificationSetting{} - path := dsa.getPath("/servers/" + serverId + "/notificationSettings/bandwidth") - if err := doRequest(ctx, http.MethodPost, path, "", result, payload); err != nil { - return result, err - } - return result, nil -} - -func (dsa DedicatedServerApi) DeleteBandWidthNotificationSetting(ctx context.Context, serverId, notificationId string) error { - path := dsa.getPath("/servers/" + serverId + "/notificationSettings/bandwidth/" + notificationId) - return doRequest(ctx, http.MethodDelete, path, "") -} - -func (dsa DedicatedServerApi) GetBandWidthNotificationSetting(ctx context.Context, serverId, notificationId string) (*NotificationSetting, error) { - result := &NotificationSetting{} - path := dsa.getPath("/servers/" + serverId + "/notificationSettings/bandwidth/" + notificationId) - if err := doRequest(ctx, http.MethodGet, path, "", result); err != nil { - return result, err - } - return result, nil -} - -func (dsa DedicatedServerApi) UpdateBandWidthNotificationSetting(ctx context.Context, serverId, notificationSettingId string, payload map[string]string) (*NotificationSetting, error) { - result := &NotificationSetting{} - path := dsa.getPath("/servers/" + serverId + "/notificationSettings/bandwidth/" + notificationSettingId) - if err := doRequest(ctx, http.MethodPut, path, "", result, payload); err != nil { - return result, err - } - return result, nil -} - -func (dsa DedicatedServerApi) ListDataTrafficNotificationSettings(ctx context.Context, serverId string, opts PaginationOptions) (*DataTrafficNotificationSettings, error) { - result := &DataTrafficNotificationSettings{} - path := dsa.getPath("/servers/" + serverId + "/notificationSettings/datatraffic") - query := options.Encode(opts) - if err := doRequest(ctx, http.MethodGet, path, query, result); err != nil { - return result, err - } - return result, nil -} - -func (dsa DedicatedServerApi) CreateDataTrafficNotificationSetting(ctx context.Context, serverId, frequency string, threshold float64, unit string) (*NotificationSetting, error) { - payload := map[string]string{ - "frequency": frequency, - "threshold": fmt.Sprintf("%g", threshold), - "unit": unit, - } - result := &NotificationSetting{} - path := dsa.getPath("/servers/" + serverId + "/notificationSettings/datatraffic") - if err := doRequest(ctx, http.MethodPost, path, "", result, payload); err != nil { - return result, err - } - return result, nil -} - -func (dsa DedicatedServerApi) DeleteDataTrafficNotificationSetting(ctx context.Context, serverId, notificationId string) error { - path := dsa.getPath("/servers/" + serverId + "/notificationSettings/datatraffic/" + notificationId) - return doRequest(ctx, http.MethodDelete, path, "") -} - -func (dsa DedicatedServerApi) GetDataTrafficNotificationSetting(ctx context.Context, serverId, notificationId string) (*NotificationSetting, error) { - result := &NotificationSetting{} - path := dsa.getPath("/servers/" + serverId + "/notificationSettings/datatraffic/" + notificationId) - if err := doRequest(ctx, http.MethodGet, path, "", result); err != nil { - return result, err - } - return result, nil -} - -func (dsa DedicatedServerApi) UpdateDataTrafficNotificationSetting(ctx context.Context, serverId, notificationSettingId string, payload map[string]string) (*NotificationSetting, error) { - result := &NotificationSetting{} - path := dsa.getPath("/servers/" + serverId + "/notificationSettings/datatraffic/" + notificationSettingId) - if err := doRequest(ctx, http.MethodPut, path, "", result, payload); err != nil { - return result, err - } - return result, nil -} - -func (dsa DedicatedServerApi) GetDdosNotificationSetting(ctx context.Context, serverId string) (*DdosNotificationSetting, error) { - result := &DdosNotificationSetting{} - path := dsa.getPath("/servers/" + serverId + "/notificationSettings/ddos") - if err := doRequest(ctx, http.MethodGet, path, "", result); err != nil { - return result, err - } - return result, nil -} - -func (dsa DedicatedServerApi) UpdateDdosNotificationSetting(ctx context.Context, serverId string, payload map[string]string) error { - path := dsa.getPath("/servers/" + serverId + "/notificationSettings/ddos/") - if err := doRequest(ctx, http.MethodPut, path, "", nil, payload); err != nil { - return err - } - return nil -} - -func (dsa DedicatedServerApi) PowerCycleServer(ctx context.Context, serverId string) error { - path := dsa.getPath("/servers/" + serverId + "/powerCycle") - return doRequest(ctx, http.MethodPost, path, "") -} - -func (dsa DedicatedServerApi) GetPowerStatus(ctx context.Context, serverId string) (*PowerStatus, error) { - result := &PowerStatus{} - path := dsa.getPath("/servers/" + serverId + "/powerInfo") - if err := doRequest(ctx, http.MethodGet, path, "", result); err != nil { - return result, err - } - return result, nil -} - -func (dsa DedicatedServerApi) PowerOffServer(ctx context.Context, serverId string) error { - path := dsa.getPath("/servers/" + serverId + "/powerOff") - return doRequest(ctx, http.MethodPost, path, "") -} - -func (dsa DedicatedServerApi) PowerOnServer(ctx context.Context, serverId string) error { - path := dsa.getPath("/servers/" + serverId + "/powerOn") - return doRequest(ctx, http.MethodPost, path, "") -} - -func (dsa DedicatedServerApi) ListOperatingSystems(ctx context.Context, opts DedicatedServerListOperatingSystemsOptions) (*DedicatedServerOperatingSystems, error) { - result := &DedicatedServerOperatingSystems{} - path := dsa.getPath("/operatingSystems") - query := options.Encode(opts) - if err := doRequest(ctx, http.MethodGet, path, query, result); err != nil { - return result, err - } - return result, nil -} - -func (dsa DedicatedServerApi) GetOperatingSystem(ctx context.Context, operatingSystemId, controlPanelId string) (*DedicatedServerOperatingSystem, error) { - v := url.Values{} - v.Add("controlPanelId", fmt.Sprint(controlPanelId)) - result := &DedicatedServerOperatingSystem{} - path := dsa.getPath("/operatingSystems/" + operatingSystemId) - query := v.Encode() - if err := doRequest(ctx, http.MethodGet, path, query, result); err != nil { - return result, err - } - return result, nil -} - -func (dsa DedicatedServerApi) ListControlPanels(ctx context.Context, opts DedicatedServerListControlPanelsOptions) (*DedicatedServerControlPanels, error) { - result := &DedicatedServerControlPanels{} - path := dsa.getPath("/controlPanels") - query := options.Encode(opts) - if err := doRequest(ctx, http.MethodGet, path, query, result); err != nil { - return result, err - } - return result, nil -} - -func (dsa DedicatedServerApi) ListRescueImages(ctx context.Context, opts PaginationOptions) (*DedicatedServerRescueImages, error) { - result := &DedicatedServerRescueImages{} - path := dsa.getPath("/rescueImages") - query := options.Encode(opts) - if err := doRequest(ctx, http.MethodGet, path, query, result); err != nil { - return result, err - } - return result, nil -} diff --git a/dedicated_server_test.go b/dedicated_server_test.go deleted file mode 100644 index f78ec87..0000000 --- a/dedicated_server_test.go +++ /dev/null @@ -1,9590 +0,0 @@ -package leaseweb - -import ( - "context" - "fmt" - "net/http" - "testing" - - "github.com/stretchr/testify/assert" -) - -func TestDedicatedServerList(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{"_metadata":{"limit": 10, "offset": 0, "totalCount": 1}, "servers": [ - { - "assetId": "627293", - "contract": { - "customerId": "32923828192", - "deliveryStatus": "ACTIVE", - "id": "674382", - "reference": "database.server", - "salesOrgId": "2300" - }, - "featureAvailability": { - "automation": true, - "ipmiReboot": false, - "powerCycle": true, - "privateNetwork": true, - "remoteManagement": false - }, - "id": "12345", - "location": { - "rack": "A83", - "site": "AMS-01", - "suite": "99", - "unit": "16-17" - }, - "networkInterfaces": { - "internal": { - "gateway": "10.22.192.12", - "ip": "10.22.192.3", - "mac": "AA:BB:CC:DD:EE:FF", - "ports": [ - { - "name": "EVO-AABB-01", - "port": "30" - } - ] - }, - "public": { - "gateway": "95.211.162.62", - "ip": "95.211.162.0", - "mac": "AA:AC:CC:88:EE:E4", - "ports": [] - }, - "remoteManagement": { - "gateway": "10.22.192.126", - "ip": "10.22.192.1", - "mac": "AA:AC:CC:88:EE:E4", - "ports": [] - } - }, - "powerPorts": [ - { - "name": "EVO-JV12-APC02", - "port": "10" - } - ], - "privateNetworks": [ - { - "id": "1", - "linkSpeed": 1000, - "status": "CONFIGURED", - "subnet": "127.0.0.80/24", - "vlanId": "2120" - } - ], - "rack": { - "type": "SHARED" - } - } - ]}`) - }) - defer teardown() - - ctx := context.Background() - response, err := DedicatedServerApi{}.List(ctx, DedicatedServerListOptions{}) - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 1) - assert.Equal(response.Metadata.Offset, 0) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.Servers), 1) - - Server := response.Servers[0] - assert.Equal(Server.AssetId, "627293") - assert.Equal(Server.Id, "12345") - assert.Equal(Server.Contract.CustomerId, "32923828192") - assert.Equal(Server.Contract.DeliveryStatus, "ACTIVE") - assert.Equal(Server.Contract.Id, "674382") - assert.Equal(Server.Contract.Reference, "database.server") - assert.Equal(Server.Contract.SalesOrgId, "2300") - assert.Equal(Server.FeatureAvailability.Automation, true) - assert.Equal(Server.FeatureAvailability.IpmiReboot, false) - assert.Equal(Server.FeatureAvailability.PowerCycle, true) - assert.Equal(Server.FeatureAvailability.PrivateNetwork, true) - assert.Equal(Server.FeatureAvailability.RemoteManagement, false) - assert.Equal(Server.Location.Rack, "A83") - assert.Equal(Server.Location.Site, "AMS-01") - assert.Equal(Server.Location.Suite, "99") - assert.Equal(Server.Location.Unit, "16-17") - - Internal := Server.NetworkInterfaces.Internal - assert.Equal(Internal.Gateway, "10.22.192.12") - assert.Equal(Internal.Ip, "10.22.192.3") - assert.Equal(Internal.Mac, "AA:BB:CC:DD:EE:FF") - assert.Equal(len(Internal.Ports), 1) - assert.Equal(Internal.Ports[0].Name, "EVO-AABB-01") - assert.Equal(Internal.Ports[0].Port, "30") - - Public := Server.NetworkInterfaces.Public - assert.Equal(Public.Gateway, "95.211.162.62") - assert.Equal(Public.Ip, "95.211.162.0") - assert.Equal(Public.Mac, "AA:AC:CC:88:EE:E4") - assert.Equal(len(Public.Ports), 0) - - RemoteManagement := Server.NetworkInterfaces.RemoteManagement - assert.Equal(RemoteManagement.Gateway, "10.22.192.126") - assert.Equal(RemoteManagement.Ip, "10.22.192.1") - assert.Equal(RemoteManagement.Mac, "AA:AC:CC:88:EE:E4") - - assert.Equal(len(Public.Ports), 0) - assert.Equal(len(Server.PowerPorts), 1) - assert.Equal(Server.PowerPorts[0].Name, "EVO-JV12-APC02") - assert.Equal(Server.PowerPorts[0].Port, "10") - assert.Equal(len(Server.PrivateNetworks), 1) - assert.Equal(Server.PrivateNetworks[0].Id, "1") - assert.Equal(Server.PrivateNetworks[0].LinkSpeed.String(), "1000") - assert.Equal(Server.PrivateNetworks[0].Status, "CONFIGURED") - assert.Equal(Server.PrivateNetworks[0].Subnet, "127.0.0.80/24") - assert.Equal(Server.PrivateNetworks[0].VLanId, "2120") - assert.Equal(Server.Rack.Type, "SHARED") -} - -func TestDedicatedServerListBeEmpty(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{"_metadata":{"limit": 10, "offset": 0, "totalCount": 0}, "servers": []}`) - }) - defer teardown() - ctx := context.Background() - response, err := DedicatedServerApi{}.List(ctx, DedicatedServerListOptions{}) - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 0) - assert.Equal(response.Metadata.Offset, 0) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.Servers), 0) -} - -func TestDedicatedServerListPaginateAndFilter(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{"_metadata":{"limit": 10, "offset": 1, "totalCount": 11}, "servers": [ - { - "assetId": "627293", - "contract": { - "customerId": "32923828192", - "deliveryStatus": "ACTIVE", - "id": "674382", - "reference": "database.server", - "salesOrgId": "2300" - }, - "featureAvailability": { - "automation": true, - "ipmiReboot": false, - "powerCycle": true, - "privateNetwork": true, - "remoteManagement": false - }, - "id": "12345", - "location": { - "rack": "A83", - "site": "AMS-01", - "suite": "99", - "unit": "16-17" - }, - "networkInterfaces": { - "internal": { - "gateway": "10.22.192.12", - "ip": "10.22.192.3", - "mac": "AA:BB:CC:DD:EE:FF", - "ports": [ - { - "name": "EVO-AABB-01", - "port": "30" - } - ] - }, - "public": { - "gateway": "95.211.162.62", - "ip": "95.211.162.0", - "mac": "AA:AC:CC:88:EE:E4", - "ports": [] - }, - "remoteManagement": { - "gateway": "10.22.192.126", - "ip": "10.22.192.1", - "mac": "AA:AC:CC:88:EE:E4", - "ports": [] - } - }, - "powerPorts": [ - { - "name": "EVO-JV12-APC02", - "port": "10" - } - ], - "privateNetworks": [ - { - "id": "1", - "linkSpeed": 1000, - "status": "CONFIGURED", - "subnet": "127.0.0.80/24", - "vlanId": "2120" - } - ], - "rack": { - "type": "SHARED" - } - } - ]}`) - }) - defer teardown() - - ctx := context.Background() - - opts := DedicatedServerListOptions{ - PaginationOptions: PaginationOptions{ - Offset: Int(0), - Limit: Int(10), - }, - Site: String("AMS-01"), - IP: String("10.22.192.3"), - MacAddress: String("AA:BB:CC:DD:EE:FF"), - } - - response, err := DedicatedServerApi{}.List(ctx, opts) - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 11) - assert.Equal(response.Metadata.Offset, 1) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.Servers), 1) - - Server := response.Servers[0] - assert.Equal(Server.AssetId, "627293") - assert.Equal(Server.Id, "12345") - assert.Equal(Server.Contract.CustomerId, "32923828192") - assert.Equal(Server.Contract.DeliveryStatus, "ACTIVE") - assert.Equal(Server.Contract.Id, "674382") - assert.Equal(Server.Contract.Reference, "database.server") - assert.Equal(Server.Contract.SalesOrgId, "2300") - assert.Equal(Server.FeatureAvailability.Automation, true) - assert.Equal(Server.FeatureAvailability.IpmiReboot, false) - assert.Equal(Server.FeatureAvailability.PowerCycle, true) - assert.Equal(Server.FeatureAvailability.PrivateNetwork, true) - assert.Equal(Server.FeatureAvailability.RemoteManagement, false) - assert.Equal(Server.Location.Rack, "A83") - assert.Equal(Server.Location.Site, "AMS-01") - assert.Equal(Server.Location.Suite, "99") - assert.Equal(Server.Location.Unit, "16-17") - - Internal := Server.NetworkInterfaces.Internal - assert.Equal(Internal.Gateway, "10.22.192.12") - assert.Equal(Internal.Ip, "10.22.192.3") - assert.Equal(Internal.Mac, "AA:BB:CC:DD:EE:FF") - assert.Equal(len(Internal.Ports), 1) - assert.Equal(Internal.Ports[0].Name, "EVO-AABB-01") - assert.Equal(Internal.Ports[0].Port, "30") - - Public := Server.NetworkInterfaces.Public - assert.Equal(Public.Gateway, "95.211.162.62") - assert.Equal(Public.Ip, "95.211.162.0") - assert.Equal(Public.Mac, "AA:AC:CC:88:EE:E4") - assert.Equal(len(Public.Ports), 0) - - RemoteManagement := Server.NetworkInterfaces.RemoteManagement - assert.Equal(RemoteManagement.Gateway, "10.22.192.126") - assert.Equal(RemoteManagement.Ip, "10.22.192.1") - assert.Equal(RemoteManagement.Mac, "AA:AC:CC:88:EE:E4") - - assert.Equal(len(Public.Ports), 0) - assert.Equal(len(Server.PowerPorts), 1) - assert.Equal(Server.PowerPorts[0].Name, "EVO-JV12-APC02") - assert.Equal(Server.PowerPorts[0].Port, "10") - assert.Equal(len(Server.PrivateNetworks), 1) - assert.Equal(Server.PrivateNetworks[0].Id, "1") - assert.Equal(Server.PrivateNetworks[0].LinkSpeed.String(), "1000") - assert.Equal(Server.PrivateNetworks[0].Status, "CONFIGURED") - assert.Equal(Server.PrivateNetworks[0].Subnet, "127.0.0.80/24") - assert.Equal(Server.PrivateNetworks[0].VLanId, "2120") - assert.Equal(Server.Rack.Type, "SHARED") -} - -func TestDedicatedServerListServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.List(ctx, DedicatedServerListOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "Access to the requested resource is forbidden."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.List(ctx, DedicatedServerListOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "Access to the requested resource is forbidden.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.List(ctx, DedicatedServerListOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.List(ctx, DedicatedServerListOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedServerGet(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "id": "12345", - "assetId": "627294", - "serialNumber": "JDK18291JK", - "contract": { - "billingCycle": 12, - "billingFrequency": "MONTH", - "contractTerm": 12, - "currency": "EUR", - "customerId": "32923828192", - "deliveryStatus": "ACTIVE", - "endsAt": "2017-10-01T01:00:00+0100", - "id": "674382", - "networkTraffic": { - "datatrafficLimit": 100, - "datatrafficUnit": "TB", - "trafficType": "PREMIUM", - "type": "FLATFEE" - }, - "pricePerFrequency": 49, - "privateNetworks": [ - { - "id": "1", - "linkSpeed": 1000, - "status": "CONFIGURED", - "subnet": "127.0.0.80/24", - "vlanId": "2120" - } - ], - "reference": "database.server", - "salesOrgId": "2300", - "sla": "BRONZE", - "softwareLicenses": [ - { - "currency": "EUR", - "name": "WINDOWS_2012_R2_SERVER", - "price": 12.12 - } - ], - "startsAt": "2014-01-01T01:00:00+0100" - }, - "featureAvailability": { - "automation": true, - "ipmiReboot": false, - "powerCycle": true, - "privateNetwork": true, - "remoteManagement": false - }, - "location": { - "rack": "13", - "site": "AMS-01", - "suite": "A6", - "unit": "16-17" - }, - "networkInterfaces": { - "internal": { - "gateway": "123.123.123.126", - "ip": "123.123.123.123/27", - "mac": "AA:BB:CC:DD:EE:FF", - "ports": [ ] - }, - "public": { - "gateway": "123.123.123.126", - "ip": "123.123.123.123/27", - "mac": "AA:BB:CC:DD:EE:FF", - "ports": [ - { - "name": "EVO-JV12-1", - "port": "33" - } - ] - }, - "remoteManagement": null - }, - "powerPorts": [ - { - "name": "EVO-JV12-APC02", - "port": "10" - } - ], - "rack": { - "type": "PRIVATE" - }, - "specs": { - "chassis": "Dell R210 II", - "cpu": { - "quantity": 4, - "type": "Intel Xeon E3-1220" - }, - "hardwareRaidCapable": true, - "hdd": [ - { - "amount": 2, - "id": "SATA2TB", - "performanceType": null, - "size": 2, - "type": "SATA", - "unit": "TB" - } - ], - "pciCards": [ - { - "description": "2x10GE UTP card" - }, - { - "description": "2x30GE UTP card" - } - ], - "ram": { - "size": 32, - "unit": "GB" - } - } - }`) - }) - defer teardown() - - ctx := context.Background() - Server, err := DedicatedServerApi{}.Get(ctx, "12345") - assert := assert.New(t) - assert.Nil(err) - - assert.Equal(Server.Id, "12345") - assert.Equal(Server.AssetId, "627294") - assert.Equal(Server.SerialNumber, "JDK18291JK") - assert.Equal(Server.Contract.CustomerId, "32923828192") - assert.Equal(Server.Contract.DeliveryStatus, "ACTIVE") - assert.Equal(Server.Contract.Id, "674382") - assert.Equal(Server.Contract.Reference, "database.server") - assert.Equal(Server.Contract.SalesOrgId, "2300") - assert.Equal(Server.Contract.StartsAt, "2014-01-01T01:00:00+0100") - assert.Equal(Server.Contract.Sla, "BRONZE") - - SoftwareLicense := Server.Contract.SoftwareLicenses[0] - assert.Equal(len(Server.Contract.SoftwareLicenses), 1) - assert.Equal(SoftwareLicense.Currency, "EUR") - assert.Equal(SoftwareLicense.Name, "WINDOWS_2012_R2_SERVER") - assert.Equal(SoftwareLicense.Price.String(), "12.12") - assert.Equal(Server.Contract.BillingCycle.String(), "12") - assert.Equal(Server.Contract.BillingFrequency, "MONTH") - assert.Equal(Server.Contract.ContractTerm.String(), "12") - assert.Equal(Server.Contract.Currency, "EUR") - assert.Equal(Server.Contract.EndsAt, "2017-10-01T01:00:00+0100") - assert.Equal(Server.Contract.PricePerFrequency.String(), "49") - assert.Equal(Server.Contract.NetworkTraffic.DataTrafficLimit.String(), "100") - assert.Equal(Server.Contract.NetworkTraffic.DataTrafficUnit, "TB") - assert.Equal(Server.Contract.NetworkTraffic.TrafficType, "PREMIUM") - assert.Equal(Server.Contract.NetworkTraffic.Type, "FLATFEE") - - PrivateNetwork := Server.Contract.PrivateNetworks[0] - assert.Equal(len(Server.Contract.PrivateNetworks), 1) - assert.Equal(PrivateNetwork.Id, "1") - assert.Equal(PrivateNetwork.LinkSpeed.String(), "1000") - assert.Equal(PrivateNetwork.Status, "CONFIGURED") - assert.Equal(PrivateNetwork.Subnet, "127.0.0.80/24") - assert.Equal(PrivateNetwork.VLanId, "2120") - - assert.Equal(Server.FeatureAvailability.Automation, true) - assert.Equal(Server.FeatureAvailability.IpmiReboot, false) - assert.Equal(Server.FeatureAvailability.PowerCycle, true) - assert.Equal(Server.FeatureAvailability.PrivateNetwork, true) - assert.Equal(Server.FeatureAvailability.RemoteManagement, false) - assert.Equal(Server.Location.Rack, "13") - assert.Equal(Server.Location.Site, "AMS-01") - assert.Equal(Server.Location.Suite, "A6") - assert.Equal(Server.Location.Unit, "16-17") - - Internal := Server.NetworkInterfaces.Internal - assert.Equal(Internal.Gateway, "123.123.123.126") - assert.Equal(Internal.Ip, "123.123.123.123/27") - assert.Equal(Internal.Mac, "AA:BB:CC:DD:EE:FF") - assert.Equal(len(Internal.Ports), 0) - - Public := Server.NetworkInterfaces.Public - assert.Equal(Public.Gateway, "123.123.123.126") - assert.Equal(Public.Ip, "123.123.123.123/27") - assert.Equal(Public.Mac, "AA:BB:CC:DD:EE:FF") - assert.Equal(len(Public.Ports), 1) - assert.Equal(Public.Ports[0].Name, "EVO-JV12-1") - assert.Equal(Public.Ports[0].Port, "33") - - assert.Empty(Server.NetworkInterfaces.RemoteManagement) - - assert.Equal(len(Server.PowerPorts), 1) - assert.Equal(Server.PowerPorts[0].Name, "EVO-JV12-APC02") - assert.Equal(Server.PowerPorts[0].Port, "10") - - assert.Equal(Server.Rack.Type, "PRIVATE") - - assert.Equal(Server.Specs.Chassis, "Dell R210 II") - assert.Equal(Server.Specs.HardwareRaidCapable, true) - assert.Equal(Server.Specs.Cpu.Quantity.String(), "4") - assert.Equal(Server.Specs.Cpu.Type, "Intel Xeon E3-1220") - assert.Equal(Server.Specs.Hdd[0].Amount.String(), "2") - assert.Equal(Server.Specs.Hdd[0].Id, "SATA2TB") - assert.Empty(Server.Specs.Hdd[0].PerformanceType) - assert.Equal(Server.Specs.Hdd[0].Size.String(), "2") - assert.Equal(Server.Specs.Hdd[0].Type, "SATA") - assert.Equal(Server.Specs.Hdd[0].Unit, "TB") - assert.Equal(Server.Specs.Ram.Size.String(), "32") - assert.Equal(Server.Specs.Ram.Unit, "GB") - assert.Equal(Server.Specs.PciCards[0].Description, "2x10GE UTP card") - assert.Equal(Server.Specs.PciCards[1].Description, "2x30GE UTP card") -} - -func TestDedicatedServerGetServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.Get(ctx, "12345") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.Get(ctx, "12345") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "404", "errorMessage": "Resource not found"}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.Get(ctx, "12345") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "404", - Message: "Resource not found", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.Get(ctx, "12345") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.Get(ctx, "12345") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedServerUpdate(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusNoContent) - }) - defer teardown() - - payload := map[string]interface{}{"reference": "new reference"} - ctx := context.Background() - err := DedicatedServerApi{}.Update(ctx, "12345", payload) - assert := assert.New(t) - assert.Nil(err) -} - -func TestDedicatedServerUpdateServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - payload := map[string]interface{}{"reference": "new reference"} - ctx := context.Background() - return nil, DedicatedServerApi{}.Update(ctx, "12345", payload) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - payload := map[string]interface{}{"reference": "new reference"} - ctx := context.Background() - return nil, DedicatedServerApi{}.Update(ctx, "12345", payload) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "404", "errorMessage": "Resource not found"}`) - }, - FunctionCall: func() (interface{}, error) { - payload := map[string]interface{}{"reference": "new reference"} - ctx := context.Background() - return nil, DedicatedServerApi{}.Update(ctx, "12345", payload) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "404", - Message: "Resource not found", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - payload := map[string]interface{}{"reference": "new reference"} - ctx := context.Background() - return nil, DedicatedServerApi{}.Update(ctx, "12345", payload) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - payload := map[string]interface{}{"reference": "new reference"} - ctx := context.Background() - return nil, DedicatedServerApi{}.Update(ctx, "12345", payload) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedServerGetHardwareInformation(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "id": "2378237", - "parserVersion": "3.6", - "scannedAt": "2017-09-27T14:21:01Z", - "serverId": "62264", - "result": { - "chassis": { - "description": "Rack Mount Chassis", - "firmware": { - "date": "07/01/2013", - "description": "BIOS", - "vendor": "HP", - "version": "J01" - }, - "motherboard": { - "product": "111", - "serial": "222", - "vendor": "333" - }, - "product": "ProLiant DL120 G7 (647339-B21)", - "serial": "CZ33109CHV", - "vendor": "HP" - }, - "cpu": [ - { - "capabilities": { - "cpufreq": "CPU Frequency scaling", - "ht": "HyperThreading", - "vmx": false, - "x86-64": "64bits extensions (x86-64)" - }, - "description": "Intel(R) Xeon(R) CPU E31230", - "hz": "2792640000", - "serial_number": "123456", - "settings": { - "cores": "4", - "enabledcores": "4", - "threads": "8" - }, - "slot": "Proc 1", - "vendor": "Intel Corp." - } - ], - "disks": [ - { - "description": "ATA Disk", - "id": "disk:0", - "product": "Hitachi HDS72302", - "serial_number": "MS77215W07S6SA", - "size": "2000398934016", - "smartctl": { - "ata_version": "ATA8-ACS T13/1699-D revision 4", - "attributes": { - "Power_On_Hours": { - "flag": "0x0012", - "id": "9", - "raw_value": "39832", - "thresh": "000", - "type": "Old_age", - "updated": "Always", - "value": "095", - "when_failed": "-", - "worst": "095" - }, - "Reallocated_Sector_Ct": { - "flag": "0x0033", - "id": "5", - "raw_value": "0", - "thresh": "005", - "type": "Pre-fail", - "updated": "Always", - "value": "100", - "when_failed": "-", - "worst": "100" - } - }, - "device_model": "Hitachi HDS723020BLE640", - "execution_status": "0", - "firmware_version": "MX4OAAB0", - "is_sas": false, - "overall_health": "PASSED", - "rpm": "7200 rpm", - "sata_version": "SATA 3.0, 6.0 Gb/s (current: 6.0 Gb/s)", - "sector_size": "512 bytes logical, 4096 bytes physical", - "serial_number": "MS77215W07S6SA", - "smart_error_log": "No Errors Logged", - "smart_support": { - "available": true, - "enabled": true - }, - "smartctl_version": "6.2", - "user_capacity": "2,000,398,934,016 bytes [2.00 TB]" - }, - "vendor": "Hitachi" - } - ], - "ipmi": { - "defgateway": "10.19.79.126", - "firmware": "1.88", - "ipaddress": "10.19.79.67", - "ipsource": "DHCP Address", - "macaddress": "28:92:4a:33:48:e8", - "subnetmask": "255.255.255.192", - "vendor": "Hewlett-Packard" - }, - "memory": [ - { - "clock_hz": "1333000000", - "description": "DIMM DDR3 Synchronous 1333 MHz (0.8 ns)", - "id": "memory/bank:0", - "serial_number": "8369AF58", - "size_bytes": "4294967296" - }, - { - "clock_hz": "1333000000", - "description": "DIMM DDR3 Synchronous 1333 MHz (0.8 ns)", - "id": "memory/bank:1", - "serial_number": "8369B174", - "size_bytes": "4294967296" - } - ], - "network": [ - { - "capabilities": { - "autonegotiation": "Auto-negotiation", - "bus_master": "bus mastering", - "cap_list": "PCI capabilities listing", - "ethernet": "123", - "link_speeds": { - "1000bt-fd": "1Gbit/s (full duplex)", - "100bt": "100Mbit/s", - "100bt-fd": "100Mbit/s (full duplex)", - "10bt": "10Mbit/s", - "10bt-fd": "10Mbit/s (full duplex)" - }, - "msi": "Message Signalled Interrupts", - "msix": "MSI-X", - "pciexpress": "PCI Express", - "physical": "Physical interface", - "pm": "Power Management", - "tp": "twisted pair" - }, - "lldp": { - "chassis": { - "description": "Juniper Networks, Inc. ex3300-48t Ethernet Switch, kernel JUNOS 15.1R5.5, Build date: 2016-11-25 16:02:59 UTC Copyright (c) 1996-2016 Juniper Networks, Inc.", - "mac_address": "4c:16:fc:3a:84:c0", - "name": "EVO-NS19-1" - }, - "port": { - "auto_negotiation": { - "enabled": "yes", - "supported": "yes" - }, - "description": "ge-0/0/2.0" - }, - "vlan": { - "id": "0", - "label": "VLAN", - "name": "default" - } - }, - "logical_name": "eth0", - "mac_address": "28:92:4a:33:48:e6", - "product": "82574L Gigabit Network Connection", - "settings": { - "autonegotiation": "on", - "broadcast": "yes", - "driver": "e1000e", - "driverversion": "3.2.6-k", - "duplex": "full", - "firmware": "2.1-2", - "ip": "212.32.230.67", - "latency": "0", - "link": "yes", - "multicast": "yes", - "port": "twisted pair", - "speed": "1Gbit/s" - }, - "vendor": "Intel Corporation" - } - ] - } - }`) - }) - defer teardown() - - ctx := context.Background() - Server, err := DedicatedServerApi{}.GetHardwareInformation(ctx, "2378237") - assert := assert.New(t) - assert.Nil(err) - - assert.Equal(Server.Id, "2378237") - assert.Equal(Server.ParserVersion, "3.6") - assert.Equal(Server.ScannedAt, "2017-09-27T14:21:01Z") - assert.Equal(Server.ServerId, "62264") - - assert.Equal(Server.Result.Chassis.Description, "Rack Mount Chassis") - assert.Equal(Server.Result.Chassis.Product, "ProLiant DL120 G7 (647339-B21)") - assert.Equal(Server.Result.Chassis.Serial, "CZ33109CHV") - assert.Equal(Server.Result.Chassis.Vendor, "HP") - assert.Equal(Server.Result.Chassis.Motherboard.Product, "111") - assert.Equal(Server.Result.Chassis.Motherboard.Serial, "222") - assert.Equal(Server.Result.Chassis.Motherboard.Vendor, "333") - assert.Equal(Server.Result.Chassis.Firmware.Date, "07/01/2013") - assert.Equal(Server.Result.Chassis.Firmware.Description, "BIOS") - assert.Equal(Server.Result.Chassis.Firmware.Vendor, "HP") - assert.Equal(Server.Result.Chassis.Firmware.Version, "J01") - - assert.Equal(len(Server.Result.Cpu), 1) - Cpu := Server.Result.Cpu[0] - assert.Equal(Cpu.Capabilities.CpuFreq, "CPU Frequency scaling") - assert.Equal(Cpu.Capabilities.HT, "HyperThreading") - assert.Equal(Cpu.Capabilities.VMX, false) - assert.Equal(Cpu.Capabilities.X8664, "64bits extensions (x86-64)") - assert.Equal(Cpu.Settings.Cores, "4") - assert.Equal(Cpu.Settings.EnabledCores, "4") - assert.Equal(Cpu.Settings.Threads, "8") - assert.Equal(Cpu.Description, "Intel(R) Xeon(R) CPU E31230") - assert.Equal(Cpu.HZ, "2792640000") - assert.Equal(Cpu.SerialNumber, "123456") - assert.Equal(Cpu.Slot, "Proc 1") - assert.Equal(Cpu.Vendor, "Intel Corp.") - - assert.Equal(len(Server.Result.Disks), 1) - Disk := Server.Result.Disks[0] - assert.Equal(Disk.Description, "ATA Disk") - assert.Equal(Disk.Id, "disk:0") - assert.Equal(Disk.Product, "Hitachi HDS72302") - assert.Equal(Disk.SerialNumber, "MS77215W07S6SA") - assert.Equal(Disk.Size, "2000398934016") - assert.Equal(Disk.SmartCTL.ATAVersion, "ATA8-ACS T13/1699-D revision 4") - assert.Equal(Disk.SmartCTL.DeviceModel, "Hitachi HDS723020BLE640") - assert.Equal(Disk.SmartCTL.ExecutionStatus, "0") - assert.Equal(Disk.SmartCTL.FirmwareVersion, "MX4OAAB0") - assert.Equal(Disk.SmartCTL.ISSAS, false) - assert.Equal(Disk.SmartCTL.OverallHealth, "PASSED") - assert.Equal(Disk.SmartCTL.RPM, "7200 rpm") - assert.Equal(Disk.SmartCTL.SATAVersion, "SATA 3.0, 6.0 Gb/s (current: 6.0 Gb/s)") - assert.Equal(Disk.SmartCTL.SectorSize, "512 bytes logical, 4096 bytes physical") - assert.Equal(Disk.SmartCTL.SerialNumber, "MS77215W07S6SA") - assert.Equal(Disk.SmartCTL.SmartErrorLog, "No Errors Logged") - assert.Equal(Disk.SmartCTL.SmartctlVersion, "6.2") - assert.Equal(Disk.SmartCTL.UserCapacity, "2,000,398,934,016 bytes [2.00 TB]") - assert.Equal(Disk.SmartCTL.SmartSupport.Available, true) - assert.Equal(Disk.SmartCTL.SmartSupport.Enabled, true) - assert.Equal(Disk.SmartCTL.Attributes.ReallocatedSectorCT.Flag, "0x0033") - assert.Equal(Disk.SmartCTL.Attributes.ReallocatedSectorCT.Id, "5") - assert.Equal(Disk.SmartCTL.Attributes.ReallocatedSectorCT.RawValue, "0") - assert.Equal(Disk.SmartCTL.Attributes.ReallocatedSectorCT.Thresh, "005") - assert.Equal(Disk.SmartCTL.Attributes.ReallocatedSectorCT.Type, "Pre-fail") - assert.Equal(Disk.SmartCTL.Attributes.ReallocatedSectorCT.Updated, "Always") - assert.Equal(Disk.SmartCTL.Attributes.ReallocatedSectorCT.Value, "100") - assert.Equal(Disk.SmartCTL.Attributes.ReallocatedSectorCT.WhenFailed, "-") - assert.Equal(Disk.SmartCTL.Attributes.ReallocatedSectorCT.Worst, "100") - assert.Equal(Disk.SmartCTL.Attributes.PowerOnHours.Flag, "0x0012") - assert.Equal(Disk.SmartCTL.Attributes.PowerOnHours.Id, "9") - assert.Equal(Disk.SmartCTL.Attributes.PowerOnHours.RawValue, "39832") - assert.Equal(Disk.SmartCTL.Attributes.PowerOnHours.Thresh, "000") - assert.Equal(Disk.SmartCTL.Attributes.PowerOnHours.Type, "Old_age") - assert.Equal(Disk.SmartCTL.Attributes.PowerOnHours.Updated, "Always") - assert.Equal(Disk.SmartCTL.Attributes.PowerOnHours.Value, "095") - assert.Equal(Disk.SmartCTL.Attributes.PowerOnHours.WhenFailed, "-") - assert.Equal(Disk.SmartCTL.Attributes.PowerOnHours.Worst, "095") - assert.Equal(Disk.Vendor, "Hitachi") - assert.Equal(Server.Result.Ipmi.Defgateway, "10.19.79.126") - assert.Equal(Server.Result.Ipmi.Firmware, "1.88") - assert.Equal(Server.Result.Ipmi.IpAddress, "10.19.79.67") - assert.Equal(Server.Result.Ipmi.IpSource, "DHCP Address") - assert.Equal(Server.Result.Ipmi.MacAddress, "28:92:4a:33:48:e8") - assert.Equal(Server.Result.Ipmi.SubnetMask, "255.255.255.192") - assert.Equal(Server.Result.Ipmi.Vendor, "Hewlett-Packard") - - assert.Equal(len(Server.Result.Memories), 2) - Memory1 := Server.Result.Memories[0] - assert.Equal(Memory1.ClockHZ, "1333000000") - assert.Equal(Memory1.Description, "DIMM DDR3 Synchronous 1333 MHz (0.8 ns)") - assert.Equal(Memory1.Id, "memory/bank:0") - assert.Equal(Memory1.SerialNumber, "8369AF58") - assert.Equal(Memory1.SizeBytes, "4294967296") - - Memory2 := Server.Result.Memories[1] - assert.Equal(Memory2.ClockHZ, "1333000000") - assert.Equal(Memory2.Description, "DIMM DDR3 Synchronous 1333 MHz (0.8 ns)") - assert.Equal(Memory2.Id, "memory/bank:1") - assert.Equal(Memory2.SerialNumber, "8369B174") - assert.Equal(Memory2.SizeBytes, "4294967296") - - assert.Equal(len(Server.Result.Networks), 1) - Network := Server.Result.Networks[0] - assert.Equal(Network.Vendor, "Intel Corporation") - assert.Equal(Network.LogicalName, "eth0") - assert.Equal(Network.MacAddress, "28:92:4a:33:48:e6") - assert.Equal(Network.Product, "82574L Gigabit Network Connection") - - assert.Equal(Network.Capabilities.AutoNegotiation, "Auto-negotiation") - assert.Equal(Network.Capabilities.BusMaster, "bus mastering") - assert.Equal(Network.Capabilities.CapList, "PCI capabilities listing") - assert.Equal(Network.Capabilities.Ethernet, "123") - assert.Equal(Network.Capabilities.LinkSpeeds.BT10, "10Mbit/s") - assert.Equal(Network.Capabilities.LinkSpeeds.BT100, "100Mbit/s") - assert.Equal(Network.Capabilities.LinkSpeeds.BTFD10, "10Mbit/s (full duplex)") - assert.Equal(Network.Capabilities.LinkSpeeds.BTFD100, "100Mbit/s (full duplex)") - assert.Equal(Network.Capabilities.LinkSpeeds.BTFD1000, "1Gbit/s (full duplex)") - assert.Equal(Network.Capabilities.MSI, "Message Signalled Interrupts") - assert.Equal(Network.Capabilities.MSIX, "MSI-X") - assert.Equal(Network.Capabilities.PciExpress, "PCI Express") - assert.Equal(Network.Capabilities.Physical, "Physical interface") - assert.Equal(Network.Capabilities.PM, "Power Management") - assert.Equal(Network.Capabilities.TP, "twisted pair") - - assert.Equal(Network.LLDP.Chassis.Description, "Juniper Networks, Inc. ex3300-48t Ethernet Switch, kernel JUNOS 15.1R5.5, Build date: 2016-11-25 16:02:59 UTC Copyright (c) 1996-2016 Juniper Networks, Inc.") - assert.Equal(Network.LLDP.Chassis.MacAddress, "4c:16:fc:3a:84:c0") - assert.Equal(Network.LLDP.Chassis.Name, "EVO-NS19-1") - assert.Equal(Network.LLDP.Port.AutoNegotiation.Enabled, "yes") - assert.Equal(Network.LLDP.Port.AutoNegotiation.Supported, "yes") - assert.Equal(Network.LLDP.Port.Description, "ge-0/0/2.0") - assert.Equal(Network.LLDP.Vlan.Id, "0") - assert.Equal(Network.LLDP.Vlan.Label, "VLAN") - assert.Equal(Network.LLDP.Vlan.Name, "default") - assert.Equal(Network.Settings.AutoNegotiation, "on") - assert.Equal(Network.Settings.Broadcast, "yes") - assert.Equal(Network.Settings.Driver, "e1000e") - assert.Equal(Network.Settings.DriverVersion, "3.2.6-k") - assert.Equal(Network.Settings.Duplex, "full") - assert.Equal(Network.Settings.Firmware, "2.1-2") - assert.Equal(Network.Settings.Ip, "212.32.230.67") - assert.Equal(Network.Settings.Latency, "0") - assert.Equal(Network.Settings.Link, "yes") - assert.Equal(Network.Settings.Multicast, "yes") - assert.Equal(Network.Settings.Port, "twisted pair") - assert.Equal(Network.Settings.Speed, "1Gbit/s") -} - -func TestDedicatedServerGetHardwareInformationServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.GetHardwareInformation(ctx, "2378237") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.GetHardwareInformation(ctx, "2378237") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "404", "errorMessage": "Resource not found"}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.GetHardwareInformation(ctx, "2378237") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "404", - Message: "Resource not found", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.GetHardwareInformation(ctx, "2378237") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.GetHardwareInformation(ctx, "2378237") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedServerListIps(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "_metadata": { - "limit": 10, - "offset": 0, - "totalCount": 2 - }, - "ips": [ - { - "ddos": { - "detectionProfile": "ADVANCED_LOW_UDP", - "protectionType": "ADVANCED" - }, - "floatingIp": false, - "gateway": "12.123.123.254", - "ip": "12.123.123.1/24", - "mainIp": true, - "networkType": "PUBLIC", - "nullRouted": true, - "reverseLookup": "domain.example.com", - "version": 4 - }, - { - "ddos": { - "detectionProfile": "STANDARD_DEFAULT", - "protectionType": "STANDARD" - }, - "floatingIp": false, - "gateway": "2001:db8:85a3::8a2e:370:1", - "ip": "2001:db8:85a3::8a2e:370:7334/64", - "mainIp": false, - "networkType": "REMOTE_MANAGEMENT", - "nullRouted": false, - "reverseLookup": "domain.example.com", - "version": 6 - } - ] - }`) - }) - defer teardown() - - ctx := context.Background() - response, err := DedicatedServerApi{}.ListIps(ctx, "server-id", DedicatedServerListIpsOptions{}) - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 2) - assert.Equal(response.Metadata.Offset, 0) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.Ips), 2) - - Ip1 := response.Ips[0] - assert.Equal(Ip1.DDOS.DetectionProfile, "ADVANCED_LOW_UDP") - assert.Equal(Ip1.DDOS.ProtectionType, "ADVANCED") - assert.Equal(Ip1.FloatingIp, false) - assert.Equal(Ip1.Gateway, "12.123.123.254") - assert.Equal(Ip1.Ip, "12.123.123.1/24") - assert.Equal(Ip1.MainIp, true) - assert.Equal(Ip1.NetworkType, "PUBLIC") - assert.Equal(Ip1.NullRouted, true) - assert.Equal(Ip1.ReverseLookup, "domain.example.com") - assert.Equal(Ip1.Version.String(), "4") - - Ip2 := response.Ips[1] - assert.Equal(Ip2.DDOS.DetectionProfile, "STANDARD_DEFAULT") - assert.Equal(Ip2.DDOS.ProtectionType, "STANDARD") - assert.Equal(Ip2.FloatingIp, false) - assert.Equal(Ip2.Gateway, "2001:db8:85a3::8a2e:370:1") - assert.Equal(Ip2.Ip, "2001:db8:85a3::8a2e:370:7334/64") - assert.Equal(Ip2.MainIp, false) - assert.Equal(Ip2.NetworkType, "REMOTE_MANAGEMENT") - assert.Equal(Ip2.NullRouted, false) - assert.Equal(Ip2.ReverseLookup, "domain.example.com") - assert.Equal(Ip2.Version.String(), "6") -} - -func TestDedicatedServerListIpsBeEmpty(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{"_metadata":{"limit": 10, "offset": 0, "totalCount": 0}, "ips": []}`) - }) - defer teardown() - ctx := context.Background() - response, err := DedicatedServerApi{}.ListIps(ctx, "server-id", DedicatedServerListIpsOptions{}) - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 0) - assert.Equal(response.Metadata.Offset, 0) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.Ips), 0) -} - -func TestDedicatedServerListIpsFilterAndPagination(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "_metadata": { - "limit": 10, - "offset": 1, - "totalCount": 11 - }, - "ips": [ - { - "ddos": { - "detectionProfile": "ADVANCED_LOW_UDP", - "protectionType": "ADVANCED" - }, - "floatingIp": false, - "gateway": "12.123.123.254", - "ip": "12.123.123.1/24", - "mainIp": true, - "networkType": "PUBLIC", - "nullRouted": true, - "reverseLookup": "domain.example.com", - "version": 4 - } - ] - }`) - }) - defer teardown() - - ctx := context.Background() - opts := DedicatedServerListIpsOptions{ - PaginationOptions: PaginationOptions{ - Offset: Int(0), - Limit: Int(10), - }, - } - response, err := DedicatedServerApi{}.ListIps(ctx, "server-id", opts) - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 11) - assert.Equal(response.Metadata.Offset, 1) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.Ips), 1) - - Ip1 := response.Ips[0] - assert.Equal(Ip1.DDOS.DetectionProfile, "ADVANCED_LOW_UDP") - assert.Equal(Ip1.DDOS.ProtectionType, "ADVANCED") - assert.Equal(Ip1.FloatingIp, false) - assert.Equal(Ip1.Gateway, "12.123.123.254") - assert.Equal(Ip1.Ip, "12.123.123.1/24") - assert.Equal(Ip1.MainIp, true) - assert.Equal(Ip1.NetworkType, "PUBLIC") - assert.Equal(Ip1.NullRouted, true) - assert.Equal(Ip1.ReverseLookup, "domain.example.com") - assert.Equal(Ip1.Version.String(), "4") -} - -func TestDedicatedServerListIpsServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.ListIps(ctx, "server-id", DedicatedServerListIpsOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "Access to the requested resource is forbidden."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.ListIps(ctx, "server-id", DedicatedServerListIpsOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "Access to the requested resource is forbidden.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.ListIps(ctx, "server-id", DedicatedServerListIpsOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.ListIps(ctx, "server-id", DedicatedServerListIpsOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedServerGetIp(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "ddos": { - "detectionProfile": "ADVANCED_LOW_UDP", - "protectionType": "ADVANCED" - }, - "floatingIp": false, - "gateway": "12.123.123.254", - "ip": "12.123.123.1/24", - "mainIp": true, - "networkType": "PUBLIC", - "nullRouted": true, - "reverseLookup": "domain.example.com", - "version": 4 - }`) - }) - defer teardown() - - ctx := context.Background() - Ip, err := DedicatedServerApi{}.GetIp(ctx, "12345", "127.0.0.6") - assert := assert.New(t) - assert.Nil(err) - assert.Equal(Ip.DDOS.DetectionProfile, "ADVANCED_LOW_UDP") - assert.Equal(Ip.DDOS.ProtectionType, "ADVANCED") - assert.Equal(Ip.FloatingIp, false) - assert.Equal(Ip.Gateway, "12.123.123.254") - assert.Equal(Ip.Ip, "12.123.123.1/24") - assert.Equal(Ip.MainIp, true) - assert.Equal(Ip.NetworkType, "PUBLIC") - assert.Equal(Ip.NullRouted, true) - assert.Equal(Ip.ReverseLookup, "domain.example.com") - assert.Equal(Ip.Version.String(), "4") -} - -func TestDedicatedServerGetIpServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.GetIp(ctx, "12345", "127.0.0.6") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.GetIp(ctx, "12345", "127.0.0.6") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "404", "errorMessage": "Resource not found"}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.GetIp(ctx, "12345", "127.0.0.6") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "404", - Message: "Resource not found", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.GetIp(ctx, "12345", "127.0.0.6") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.GetIp(ctx, "12345", "127.0.0.6") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedServerUpdateIp(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "ddos": { - "detectionProfile": "ADVANCED_DEFAULT", - "protectionType": "ADVANCED" - }, - "floatingIp": false, - "gateway": "12.123.123.254", - "ip": "12.123.123.1/24", - "mainIp": true, - "networkType": "PUBLIC", - "nullRouted": true, - "reverseLookup": "domain.example.com", - "version": 4 - }`) - }) - defer teardown() - - payload := map[string]string{"detectionProfile": "ADVANCED_DEFAULT", "reverseLookup": "domain.example.com"} - ctx := context.Background() - Ip, err := DedicatedServerApi{}.UpdateIp(ctx, "12345", "127.0.0.6", payload) - assert := assert.New(t) - assert.Nil(err) - assert.Equal(Ip.DDOS.DetectionProfile, "ADVANCED_DEFAULT") - assert.Equal(Ip.DDOS.ProtectionType, "ADVANCED") - assert.Equal(Ip.FloatingIp, false) - assert.Equal(Ip.Gateway, "12.123.123.254") - assert.Equal(Ip.Ip, "12.123.123.1/24") - assert.Equal(Ip.MainIp, true) - assert.Equal(Ip.NetworkType, "PUBLIC") - assert.Equal(Ip.NullRouted, true) - assert.Equal(Ip.ReverseLookup, "domain.example.com") - assert.Equal(Ip.Version.String(), "4") -} - -func TestDedicatedServerUpdateIpServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - payload := map[string]string{"detectionProfile": "ADVANCED_DEFAULT", "reverseLookup": "domain.example.com"} - ctx := context.Background() - return DedicatedServerApi{}.UpdateIp(ctx, "12345", "127.0.0.6", payload) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - payload := map[string]string{"detectionProfile": "ADVANCED_DEFAULT", "reverseLookup": "domain.example.com"} - ctx := context.Background() - return DedicatedServerApi{}.UpdateIp(ctx, "12345", "127.0.0.6", payload) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "404", "errorMessage": "Resource not found"}`) - }, - FunctionCall: func() (interface{}, error) { - payload := map[string]string{"detectionProfile": "ADVANCED_DEFAULT", "reverseLookup": "domain.example.com"} - ctx := context.Background() - return DedicatedServerApi{}.UpdateIp(ctx, "12345", "127.0.0.6", payload) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "404", - Message: "Resource not found", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - payload := map[string]string{"detectionProfile": "ADVANCED_DEFAULT", "reverseLookup": "domain.example.com"} - ctx := context.Background() - return DedicatedServerApi{}.UpdateIp(ctx, "12345", "127.0.0.6", payload) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - payload := map[string]string{"detectionProfile": "ADVANCED_DEFAULT", "reverseLookup": "domain.example.com"} - ctx := context.Background() - return DedicatedServerApi{}.UpdateIp(ctx, "12345", "127.0.0.6", payload) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedServerNullRouteAnIp(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "ddos": { - "detectionProfile": "ADVANCED_DEFAULT", - "protectionType": "ADVANCED" - }, - "floatingIp": false, - "gateway": "12.123.123.254", - "ip": "12.123.123.1/24", - "mainIp": true, - "networkType": "PUBLIC", - "nullRouted": false, - "reverseLookup": "domain.example.com", - "version": 4 - }`) - }) - defer teardown() - - ctx := context.Background() - Ip, err := DedicatedServerApi{}.NullRouteAnIp(ctx, "12345", "127.0.0.6") - assert := assert.New(t) - assert.Nil(err) - assert.Equal(Ip.DDOS.DetectionProfile, "ADVANCED_DEFAULT") - assert.Equal(Ip.DDOS.ProtectionType, "ADVANCED") - assert.Equal(Ip.FloatingIp, false) - assert.Equal(Ip.Gateway, "12.123.123.254") - assert.Equal(Ip.Ip, "12.123.123.1/24") - assert.Equal(Ip.MainIp, true) - assert.Equal(Ip.NetworkType, "PUBLIC") - assert.Equal(Ip.NullRouted, false) - assert.Equal(Ip.ReverseLookup, "domain.example.com") - assert.Equal(Ip.Version.String(), "4") -} - -func TestDedicatedServerNullRouteAnIpServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.NullRouteAnIp(ctx, "12345", "127.0.0.6") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.NullRouteAnIp(ctx, "12345", "127.0.0.6") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "404", "errorMessage": "Resource not found"}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.NullRouteAnIp(ctx, "12345", "127.0.0.6") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "404", - Message: "Resource not found", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.NullRouteAnIp(ctx, "12345", "127.0.0.6") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.NullRouteAnIp(ctx, "12345", "127.0.0.6") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedServerRemoveNullRouteAnIp(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "ddos": { - "detectionProfile": "ADVANCED_DEFAULT", - "protectionType": "ADVANCED" - }, - "floatingIp": false, - "gateway": "12.123.123.254", - "ip": "12.123.123.1/24", - "mainIp": true, - "networkType": "PUBLIC", - "nullRouted": false, - "reverseLookup": "domain.example.com", - "version": 4 - }`) - }) - defer teardown() - - ctx := context.Background() - Ip, err := DedicatedServerApi{}.RemoveNullRouteAnIp(ctx, "12345", "127.0.0.6") - assert := assert.New(t) - assert.Nil(err) - assert.Equal(Ip.DDOS.DetectionProfile, "ADVANCED_DEFAULT") - assert.Equal(Ip.DDOS.ProtectionType, "ADVANCED") - assert.Equal(Ip.FloatingIp, false) - assert.Equal(Ip.Gateway, "12.123.123.254") - assert.Equal(Ip.Ip, "12.123.123.1/24") - assert.Equal(Ip.MainIp, true) - assert.Equal(Ip.NetworkType, "PUBLIC") - assert.Equal(Ip.NullRouted, false) - assert.Equal(Ip.ReverseLookup, "domain.example.com") - assert.Equal(Ip.Version.String(), "4") -} - -func TestDedicatedServerRemoveNullRouteAnIpServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.RemoveNullRouteAnIp(ctx, "12345", "127.0.0.6") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.RemoveNullRouteAnIp(ctx, "12345", "127.0.0.6") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "404", "errorMessage": "Resource not found"}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.RemoveNullRouteAnIp(ctx, "12345", "127.0.0.6") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "404", - Message: "Resource not found", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.RemoveNullRouteAnIp(ctx, "12345", "127.0.0.6") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.RemoveNullRouteAnIp(ctx, "12345", "127.0.0.6") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedServerListNullRoutes(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "_metadata": { - "limit": 10, - "offset": 0, - "totalCount": 1 - }, - "nullRoutes": [ - { - "automatedUnnullingAt": "2016-08-12T07:45:33+00:00", - "comment": "Device Null Route related to DDoS Mitigation", - "ip": "1.1.1.1/32", - "nullLevel": 3, - "nulledAt": "2016-08-12T07:40:27+00:00", - "ticketId": "282912" - } - ] - }`) - }) - defer teardown() - - ctx := context.Background() - response, err := DedicatedServerApi{}.ListNullRoutes(ctx, "server-id", PaginationOptions{}) - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 1) - assert.Equal(response.Metadata.Offset, 0) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.NullRoutes), 1) - - NullRoute := response.NullRoutes[0] - assert.Equal(NullRoute.AutomatedUnnullingAt, "2016-08-12T07:45:33+00:00") - assert.Equal(NullRoute.Comment, "Device Null Route related to DDoS Mitigation") - assert.Equal(NullRoute.Ip, "1.1.1.1/32") - assert.Equal(NullRoute.NullLevel.String(), "3") - assert.Equal(NullRoute.NulledAt, "2016-08-12T07:40:27+00:00") - assert.Equal(NullRoute.TicketId, "282912") -} - -func TestDedicatedServerListNullRoutesBeEmpty(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{"_metadata":{"limit": 10, "offset": 0, "totalCount": 0}, "nullRoutes": []}`) - }) - defer teardown() - ctx := context.Background() - response, err := DedicatedServerApi{}.ListNullRoutes(ctx, "server-id", PaginationOptions{}) - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 0) - assert.Equal(response.Metadata.Offset, 0) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.NullRoutes), 0) -} - -func TestDedicatedServerListNullRoutesFilterAndPagination(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "_metadata": { - "limit": 10, - "offset": 1, - "totalCount": 11 - }, - "nullRoutes": [ - { - "automatedUnnullingAt": "2016-08-12T07:45:33+00:00", - "comment": "Device Null Route related to DDoS Mitigation", - "ip": "1.1.1.1/32", - "nullLevel": 3, - "nulledAt": "2016-08-12T07:40:27+00:00", - "ticketId": "282912" - } - ] - }`) - }) - defer teardown() - - ctx := context.Background() - opts := PaginationOptions{ - Limit: Int(1), - } - response, err := DedicatedServerApi{}.ListNullRoutes(ctx, "server-id", opts) - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 11) - assert.Equal(response.Metadata.Offset, 1) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.NullRoutes), 1) - - NullRoute := response.NullRoutes[0] - assert.Equal(NullRoute.AutomatedUnnullingAt, "2016-08-12T07:45:33+00:00") - assert.Equal(NullRoute.Comment, "Device Null Route related to DDoS Mitigation") - assert.Equal(NullRoute.Ip, "1.1.1.1/32") - assert.Equal(NullRoute.NullLevel.String(), "3") - assert.Equal(NullRoute.NulledAt, "2016-08-12T07:40:27+00:00") - assert.Equal(NullRoute.TicketId, "282912") -} - -func TestDedicatedServerListNullRoutesServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.ListNullRoutes(ctx, "server-id", PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "Access to the requested resource is forbidden."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.ListNullRoutes(ctx, "server-id", PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "Access to the requested resource is forbidden.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.ListNullRoutes(ctx, "server-id", PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.ListNullRoutes(ctx, "server-id", PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedServerListNetworkInterfaces(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "_metadata": { - "limit": 10, - "offset": 0, - "totalCount": 1 - }, - "networkInterfaces": [ - { - "linkSpeed": "100Mbps", - "operStatus": "OPEN", - "status": "OPEN", - "switchInterface": "33", - "switchName": "EVO-AA11-1", - "type": "PUBLIC" - } - ] - }`) - }) - defer teardown() - - ctx := context.Background() - opts := PaginationOptions{ - Limit: Int(1), - } - response, err := DedicatedServerApi{}.ListNetworkInterfaces(ctx, "server-id", opts) - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 1) - assert.Equal(response.Metadata.Offset, 0) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.NetworkInterfaces), 1) - - NetworkInterface := response.NetworkInterfaces[0] - assert.Equal(NetworkInterface.LinkSpeed, "100Mbps") - assert.Equal(NetworkInterface.OperStatus, "OPEN") - assert.Equal(NetworkInterface.Status, "OPEN") - assert.Equal(NetworkInterface.SwitchInterface, "33") - assert.Equal(NetworkInterface.SwitchName, "EVO-AA11-1") - assert.Equal(NetworkInterface.Type, "PUBLIC") -} - -func TestDedicatedServerListNetworkInterfacesBeEmpty(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{"_metadata":{"limit": 10, "offset": 0, "totalCount": 0}, "networkInterfaces": []}`) - }) - defer teardown() - ctx := context.Background() - opts := PaginationOptions{ - Limit: Int(1), - } - response, err := DedicatedServerApi{}.ListNetworkInterfaces(ctx, "server-id", opts) - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 0) - assert.Equal(response.Metadata.Offset, 0) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.NetworkInterfaces), 0) -} - -func TestDedicatedServerListNetworkInterfacesPagination(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "_metadata": { - "limit": 10, - "offset": 1, - "totalCount": 11 - }, - "networkInterfaces": [ - { - "linkSpeed": "100Mbps", - "operStatus": "OPEN", - "status": "OPEN", - "switchInterface": "33", - "switchName": "EVO-AA11-1", - "type": "PUBLIC" - } - ] - }`) - }) - defer teardown() - - ctx := context.Background() - opts := PaginationOptions{ - Limit: Int(1), - } - response, err := DedicatedServerApi{}.ListNetworkInterfaces(ctx, "server-id", opts) - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 11) - assert.Equal(response.Metadata.Offset, 1) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.NetworkInterfaces), 1) - - NetworkInterface := response.NetworkInterfaces[0] - assert.Equal(NetworkInterface.LinkSpeed, "100Mbps") - assert.Equal(NetworkInterface.OperStatus, "OPEN") - assert.Equal(NetworkInterface.Status, "OPEN") - assert.Equal(NetworkInterface.SwitchInterface, "33") - assert.Equal(NetworkInterface.SwitchName, "EVO-AA11-1") - assert.Equal(NetworkInterface.Type, "PUBLIC") -} - -func TestDedicatedServerListNetworkInterfacesServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - opts := PaginationOptions{ - Limit: Int(1), - } - return DedicatedServerApi{}.ListNetworkInterfaces(ctx, "server-id", opts) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "Access to the requested resource is forbidden."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - opts := PaginationOptions{ - Limit: Int(1), - } - return DedicatedServerApi{}.ListNetworkInterfaces(ctx, "server-id", opts) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "Access to the requested resource is forbidden.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - opts := PaginationOptions{ - Limit: Int(1), - } - return DedicatedServerApi{}.ListNetworkInterfaces(ctx, "server-id", opts) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - opts := PaginationOptions{ - Limit: Int(1), - } - return DedicatedServerApi{}.ListNetworkInterfaces(ctx, "server-id", opts) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedServerCloseAllNetworkInterfaces(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusNoContent) - }) - defer teardown() - - ctx := context.Background() - err := DedicatedServerApi{}.CloseAllNetworkInterfaces(ctx, "12345") - assert := assert.New(t) - assert.Nil(err) -} - -func TestDedicatedServerCloseAllNetworkInterfacesServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedServerApi{}.CloseAllNetworkInterfaces(ctx, "server-id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedServerApi{}.CloseAllNetworkInterfaces(ctx, "server-id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "404", "errorMessage": "Resource not found"}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedServerApi{}.CloseAllNetworkInterfaces(ctx, "server-id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "404", - Message: "Resource not found", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedServerApi{}.CloseAllNetworkInterfaces(ctx, "server-id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedServerApi{}.CloseAllNetworkInterfaces(ctx, "server-id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedServerOpenAllNetworkInterfaces(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusNoContent) - }) - defer teardown() - - ctx := context.Background() - err := DedicatedServerApi{}.OpenAllNetworkInterfaces(ctx, "12345") - assert := assert.New(t) - assert.Nil(err) -} - -func TestDedicatedServerOpenAllNetworkInterfacesServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedServerApi{}.OpenAllNetworkInterfaces(ctx, "server-id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedServerApi{}.OpenAllNetworkInterfaces(ctx, "server-id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "404", "errorMessage": "Resource not found"}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedServerApi{}.OpenAllNetworkInterfaces(ctx, "server-id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "404", - Message: "Resource not found", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedServerApi{}.OpenAllNetworkInterfaces(ctx, "server-id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedServerApi{}.OpenAllNetworkInterfaces(ctx, "server-id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedServerGetNetworkInterface(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "linkSpeed": "100Mbps", - "operStatus": "OPEN", - "status": "OPEN", - "switchInterface": "33", - "switchName": "EVO-AA11-1", - "type": "PUBLIC" - } - `) - }) - defer teardown() - - ctx := context.Background() - NetworkInterface, err := DedicatedServerApi{}.GetNetworkInterface(ctx, "server-id", "public") - assert := assert.New(t) - assert.Nil(err) - assert.Equal(NetworkInterface.LinkSpeed, "100Mbps") - assert.Equal(NetworkInterface.OperStatus, "OPEN") - assert.Equal(NetworkInterface.Status, "OPEN") - assert.Equal(NetworkInterface.SwitchInterface, "33") - assert.Equal(NetworkInterface.SwitchName, "EVO-AA11-1") - assert.Equal(NetworkInterface.Type, "PUBLIC") -} - -func TestDedicatedServerGetNetworkInterfaceServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.GetNetworkInterface(ctx, "server-id", "public") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "Access to the requested resource is forbidden."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.GetNetworkInterface(ctx, "server-id", "public") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "Access to the requested resource is forbidden.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.GetNetworkInterface(ctx, "server-id", "public") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.GetNetworkInterface(ctx, "server-id", "public") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedServerCloseNetworkInterface(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusNoContent) - }) - defer teardown() - - ctx := context.Background() - err := DedicatedServerApi{}.CloseNetworkInterface(ctx, "12345", "PUBLIC") - assert := assert.New(t) - assert.Nil(err) -} - -func TestDedicatedServerCloseNetworkInterfaceServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedServerApi{}.CloseNetworkInterface(ctx, "12345", "PUBLIC") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedServerApi{}.CloseNetworkInterface(ctx, "12345", "PUBLIC") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "404", "errorMessage": "Resource not found"}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedServerApi{}.CloseNetworkInterface(ctx, "12345", "PUBLIC") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "404", - Message: "Resource not found", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedServerApi{}.CloseNetworkInterface(ctx, "12345", "PUBLIC") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedServerApi{}.CloseNetworkInterface(ctx, "12345", "PUBLIC") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedServerOpenNetworkInterface(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusNoContent) - }) - defer teardown() - - ctx := context.Background() - err := DedicatedServerApi{}.OpenNetworkInterface(ctx, "12345", "PUBLIC") - assert := assert.New(t) - assert.Nil(err) -} - -func TestDedicatedServerOpenNetworkInterfaceServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedServerApi{}.OpenNetworkInterface(ctx, "12345", "PUBLIC") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedServerApi{}.OpenNetworkInterface(ctx, "12345", "PUBLIC") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "404", "errorMessage": "Resource not found"}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedServerApi{}.OpenNetworkInterface(ctx, "12345", "PUBLIC") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "404", - Message: "Resource not found", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedServerApi{}.OpenNetworkInterface(ctx, "12345", "PUBLIC") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedServerApi{}.OpenNetworkInterface(ctx, "12345", "PUBLIC") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedServerDeleteServerFromPrivateNetwork(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusNoContent) - }) - defer teardown() - - ctx := context.Background() - err := DedicatedServerApi{}.DeleteServerFromPrivateNetwork(ctx, "12345", "892") - assert := assert.New(t) - assert.Nil(err) -} - -func TestDedicatedServerDeleteServerFromPrivateNetworkServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedServerApi{}.DeleteServerFromPrivateNetwork(ctx, "12345", "892") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedServerApi{}.DeleteServerFromPrivateNetwork(ctx, "12345", "892") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "404", "errorMessage": "Resource not found"}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedServerApi{}.DeleteServerFromPrivateNetwork(ctx, "12345", "892") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "404", - Message: "Resource not found", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedServerApi{}.DeleteServerFromPrivateNetwork(ctx, "12345", "892") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedServerApi{}.DeleteServerFromPrivateNetwork(ctx, "12345", "892") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedServerAddServerToPrivateNetwork(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusNoContent) - }) - defer teardown() - - ctx := context.Background() - err := DedicatedServerApi{}.AddServerToPrivateNetwork(ctx, "12345", "892", 1000) - assert := assert.New(t) - assert.Nil(err) -} - -func TestDedicatedServerAddServerToPrivateNetworkServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedServerApi{}.AddServerToPrivateNetwork(ctx, "12345", "892", 1000) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedServerApi{}.AddServerToPrivateNetwork(ctx, "12345", "892", 1000) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "404", "errorMessage": "Resource not found"}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedServerApi{}.AddServerToPrivateNetwork(ctx, "12345", "892", 1000) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "404", - Message: "Resource not found", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedServerApi{}.AddServerToPrivateNetwork(ctx, "12345", "892", 1000) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedServerApi{}.AddServerToPrivateNetwork(ctx, "12345", "892", 1000) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedServerDeleteDhcpReservation(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusNoContent) - }) - defer teardown() - - ctx := context.Background() - err := DedicatedServerApi{}.DeleteDhcpReservation(ctx, "12345") - assert := assert.New(t) - assert.Nil(err) -} - -func TestDedicatedServerDeleteDhcpReservationServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedServerApi{}.DeleteDhcpReservation(ctx, "12345") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedServerApi{}.DeleteDhcpReservation(ctx, "12345") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "404", "errorMessage": "Resource not found"}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedServerApi{}.DeleteDhcpReservation(ctx, "12345") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "404", - Message: "Resource not found", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedServerApi{}.DeleteDhcpReservation(ctx, "12345") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedServerApi{}.DeleteDhcpReservation(ctx, "12345") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedServerCreateDhcpReservation(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusNoContent) - }) - defer teardown() - - payload := map[string]string{"bootfile": "http://example.com/bootme.ipxe", "hostname": "my-server"} - ctx := context.Background() - err := DedicatedServerApi{}.CreateDhcpReservation(ctx, "12345", payload) - assert := assert.New(t) - assert.Nil(err) -} - -func TestDedicatedServerCreateDhcpReservationServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - payload := map[string]string{"bootfile": "http://example.com/bootme.ipxe", "hostname": "my-server"} - ctx := context.Background() - return nil, DedicatedServerApi{}.CreateDhcpReservation(ctx, "12345", payload) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - payload := map[string]string{"bootfile": "http://example.com/bootme.ipxe", "hostname": "my-server"} - ctx := context.Background() - return nil, DedicatedServerApi{}.CreateDhcpReservation(ctx, "12345", payload) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "404", "errorMessage": "Resource not found"}`) - }, - FunctionCall: func() (interface{}, error) { - payload := map[string]string{"bootfile": "http://example.com/bootme.ipxe", "hostname": "my-server"} - ctx := context.Background() - return nil, DedicatedServerApi{}.CreateDhcpReservation(ctx, "12345", payload) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "404", - Message: "Resource not found", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - payload := map[string]string{"bootfile": "http://example.com/bootme.ipxe", "hostname": "my-server"} - ctx := context.Background() - return nil, DedicatedServerApi{}.CreateDhcpReservation(ctx, "12345", payload) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - payload := map[string]string{"bootfile": "http://example.com/bootme.ipxe", "hostname": "my-server"} - ctx := context.Background() - return nil, DedicatedServerApi{}.CreateDhcpReservation(ctx, "12345", payload) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedServerListDhcpReservation(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "_metadata": { - "limit": 10, - "offset": 0, - "totalCount": 1 - }, - "leases": [ - { - "bootfile": "http://mirror.leaseweb.com/ipxe-files/ubuntu-18.04.ipxe", - "createdAt": "2019-10-18T17:31:01+00:00", - "gateway": "192.168.0.254", - "hostname": "my-server", - "ip": "192.168.0.100", - "lastClientRequest": { - "relayAgent": null, - "type": "DHCP_REQUEST", - "userAgent": "Ubuntu 18.04 dhcpc" - }, - "mac": "AA:BB:CC:DD:EE:FF", - "netmask": "255.255.255.0", - "site": "AMS-01", - "updatedAt": "2019-11-18T19:29:01+00:00" - } - ] - }`) - }) - defer teardown() - - ctx := context.Background() - response, err := DedicatedServerApi{}.ListDhcpReservation(ctx, "server-id", PaginationOptions{}) - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 1) - assert.Equal(response.Metadata.Offset, 0) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.Leases), 1) - - Lease1 := response.Leases[0] - assert.Equal(Lease1.BootFile, "http://mirror.leaseweb.com/ipxe-files/ubuntu-18.04.ipxe") - assert.Equal(Lease1.CreatedAt, "2019-10-18T17:31:01+00:00") - assert.Equal(Lease1.Gateway, "192.168.0.254") - assert.Equal(Lease1.Hostname, "my-server") - assert.Equal(Lease1.Ip, "192.168.0.100") - assert.Empty(Lease1.LastClientRequest.RelayAgent) - assert.Equal(Lease1.LastClientRequest.Type, "DHCP_REQUEST") - assert.Equal(Lease1.LastClientRequest.UserAgent, "Ubuntu 18.04 dhcpc") - assert.Equal(Lease1.Mac, "AA:BB:CC:DD:EE:FF") - assert.Equal(Lease1.Netmask, "255.255.255.0") - assert.Equal(Lease1.Site, "AMS-01") - assert.Equal(Lease1.UpdatedAt, "2019-11-18T19:29:01+00:00") -} - -func TestDedicatedServerListDhcpReservationBeEmpty(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{"_metadata":{"limit": 10, "offset": 0, "totalCount": 0}, "leases": []}`) - }) - defer teardown() - ctx := context.Background() - response, err := DedicatedServerApi{}.ListDhcpReservation(ctx, "server-id", PaginationOptions{}) - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 0) - assert.Equal(response.Metadata.Offset, 0) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.Leases), 0) -} - -func TestDedicatedServerListDhcpReservationPagination(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "_metadata": { - "limit": 10, - "offset": 1, - "totalCount": 11 - }, - "leases": [ - { - "bootfile": "http://mirror.leaseweb.com/ipxe-files/ubuntu-18.04.ipxe", - "createdAt": "2019-10-18T17:31:01+00:00", - "gateway": "192.168.0.254", - "hostname": "my-server", - "ip": "192.168.0.100", - "lastClientRequest": { - "relayAgent": null, - "type": "DHCP_REQUEST", - "userAgent": "Ubuntu 18.04 dhcpc" - }, - "mac": "AA:BB:CC:DD:EE:FF", - "netmask": "255.255.255.0", - "site": "AMS-01", - "updatedAt": "2019-11-18T19:29:01+00:00" - } - ] - }`) - }) - defer teardown() - - ctx := context.Background() - response, err := DedicatedServerApi{}.ListDhcpReservation(ctx, "server-id", PaginationOptions{}) - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 11) - assert.Equal(response.Metadata.Offset, 1) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.Leases), 1) - - Lease1 := response.Leases[0] - assert.Equal(Lease1.BootFile, "http://mirror.leaseweb.com/ipxe-files/ubuntu-18.04.ipxe") - assert.Equal(Lease1.CreatedAt, "2019-10-18T17:31:01+00:00") - assert.Equal(Lease1.Gateway, "192.168.0.254") - assert.Equal(Lease1.Hostname, "my-server") - assert.Equal(Lease1.Ip, "192.168.0.100") - assert.Empty(Lease1.LastClientRequest.RelayAgent) - assert.Equal(Lease1.LastClientRequest.Type, "DHCP_REQUEST") - assert.Equal(Lease1.LastClientRequest.UserAgent, "Ubuntu 18.04 dhcpc") - assert.Equal(Lease1.Mac, "AA:BB:CC:DD:EE:FF") - assert.Equal(Lease1.Netmask, "255.255.255.0") - assert.Equal(Lease1.Site, "AMS-01") - assert.Equal(Lease1.UpdatedAt, "2019-11-18T19:29:01+00:00") -} - -func TestDedicatedServerListDhcpReservationServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.ListDhcpReservation(ctx, "server-id", PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "Access to the requested resource is forbidden."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.ListDhcpReservation(ctx, "server-id", PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "Access to the requested resource is forbidden.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.ListDhcpReservation(ctx, "server-id", PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.ListDhcpReservation(ctx, "server-id", PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedServerCancelActiveJob(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "createdAt": "2021-01-09T08:54:06+0000", - "flow": "#stop", - "isRunning": false, - "node": "80:18:44:E0:AF:C4!JGNTQ92", - "payload": { - "configurable": true, - "device": "SATA2TB", - "fileserverBaseUrl": "http://asd.asd", - "jobType": "install", - "numberOfDisks": null, - "operatingSystemId": "UBUNTU_20_04_64BIT", - "os": { - "architecture": "64bit", - "family": "ubuntu", - "name": "Ubuntu 20.04 LTS (Focal Fossa) (amd64)", - "type": "linux", - "version": "20.04" - }, - "partitions": [ - { - "filesystem": "swap", - "size": "4096" - } - ], - "pop": "AMS-01", - "powerCycle": true, - "raidLevel": null, - "serverId": "99944", - "timezone": "UTC", - "x": 1 - }, - "progress": { - "canceled": 1, - "expired": 0, - "failed": 0, - "finished": 0, - "inprogress": 0, - "pending": 0, - "percentage": 0, - "total": 1, - "waiting": 0 - }, - "serverId": "99944", - "status": "CANCELED", - "tasks": [ - { - "description": "dummy", - "errorMessage": "The job was canceled by the api consumer", - "flow": "tasks", - "onError": "break", - "status": "CANCELED", - "statusTimestamps": { - "CANCELED": "2021-01-09T08:54:15+00:00", - "PENDING": "2021-01-09T08:54:06+00:00", - "WAITING": "2021-01-09T08:54:06+00:00" - }, - "uuid": "085ce145-39bd-4cb3-8e2b-53f17a97a463" - } - ], - "type": "install", - "updatedAt": "2021-01-09T08:54:15+0000", - "uuid": "c77d8a6b-d255-4744-8b95-8bf4af6f8b48" - }`) - }) - defer teardown() - - ctx := context.Background() - Job, err := DedicatedServerApi{}.CancelActiveJob(ctx, "12345") - assert := assert.New(t) - assert.Nil(err) - - assert.Equal(Job.CreatedAt, "2021-01-09T08:54:06+0000") - assert.Equal(Job.Flow, "#stop") - assert.Equal(Job.IsRunning, false) - assert.Equal(Job.Node, "80:18:44:E0:AF:C4!JGNTQ92") - assert.Equal(Job.ServerId, "99944") - assert.Equal(Job.Status, "CANCELED") - assert.Equal(Job.Type, "install") - assert.Equal(Job.UpdatedAt, "2021-01-09T08:54:15+0000") - assert.Equal(Job.Uuid, "c77d8a6b-d255-4744-8b95-8bf4af6f8b48") - - assert.Equal(len(Job.Tasks), 1) - Task := Job.Tasks[0] - assert.Equal(Task.Description, "dummy") - assert.Equal(Task.Message, "The job was canceled by the api consumer") - assert.Equal(Task.Flow, "tasks") - assert.Equal(Task.OnError, "break") - assert.Equal(Task.Status, "CANCELED") - assert.Equal(Task.Uuid, "085ce145-39bd-4cb3-8e2b-53f17a97a463") - assert.Equal(Task.StatusTimestamps.Canceled, "2021-01-09T08:54:15+00:00") - assert.Equal(Task.StatusTimestamps.Pending, "2021-01-09T08:54:06+00:00") - assert.Equal(Task.StatusTimestamps.Waiting, "2021-01-09T08:54:06+00:00") - assert.Equal(Job.Progress.Canceled.String(), "1") - assert.Equal(Job.Progress.Expired.String(), "0") - assert.Equal(Job.Progress.Failed.String(), "0") - assert.Equal(Job.Progress.Finished.String(), "0") - assert.Equal(Job.Progress.InProgress.String(), "0") - assert.Equal(Job.Progress.Pending.String(), "0") - assert.Equal(Job.Progress.Percentage.String(), "0") - assert.Equal(Job.Progress.Total.String(), "1") - assert.Equal(Job.Progress.Waiting.String(), "0") - assert.Equal(Job.Payload["configurable"], true) - assert.Equal(Job.Payload["device"], "SATA2TB") - assert.Equal(Job.Payload["fileserverBaseUrl"], "http://asd.asd") - assert.Equal(Job.Payload["jobType"], "install") - assert.Empty(Job.Payload["numberOfDisks"]) - assert.Equal(Job.Payload["operatingSystemId"], "UBUNTU_20_04_64BIT") - assert.Equal(Job.Payload["os"].(map[string]interface{})["architecture"], "64bit") - assert.Equal(Job.Payload["os"].(map[string]interface{})["family"], "ubuntu") - assert.Equal(Job.Payload["os"].(map[string]interface{})["name"], "Ubuntu 20.04 LTS (Focal Fossa) (amd64)") - assert.Equal(Job.Payload["os"].(map[string]interface{})["type"], "linux") - assert.Equal(Job.Payload["os"].(map[string]interface{})["version"], "20.04") - assert.Equal(Job.Payload["partitions"].([]interface{})[0].(map[string]interface{})["filesystem"], "swap") - assert.Equal(Job.Payload["partitions"].([]interface{})[0].(map[string]interface{})["size"], "4096") - assert.Equal(Job.Payload["pop"], "AMS-01") - assert.Equal(Job.Payload["powerCycle"], true) - assert.Empty(Job.Payload["raidLevel"]) - assert.Equal(Job.Payload["serverId"], "99944") - assert.Equal(Job.Payload["timezone"], "UTC") - assert.Equal(Job.Payload["x"].(float64), float64(1)) -} - -func TestDedicatedServerCancelActiveJobServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.CancelActiveJob(ctx, "12345") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.CancelActiveJob(ctx, "12345") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "404", "errorMessage": "Resource not found"}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.CancelActiveJob(ctx, "12345") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "404", - Message: "Resource not found", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.CancelActiveJob(ctx, "12345") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.CancelActiveJob(ctx, "12345") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedServerExpireActiveJob(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "createdAt": "2021-01-09T08:54:06+0000", - "flow": "#stop", - "isRunning": false, - "node": "80:18:44:E0:AF:C4!JGNTQ92", - "payload": { - "configurable": true, - "device": "SATA2TB", - "fileserverBaseUrl": "http://asd.asd", - "jobType": "install", - "numberOfDisks": null, - "operatingSystemId": "UBUNTU_20_04_64BIT", - "os": { - "architecture": "64bit", - "family": "ubuntu", - "name": "Ubuntu 20.04 LTS (Focal Fossa) (amd64)", - "type": "linux", - "version": "20.04" - }, - "partitions": [ - { - "filesystem": "swap", - "size": "4096" - } - ], - "pop": "AMS-01", - "powerCycle": true, - "raidLevel": null, - "serverId": "99944", - "timezone": "UTC", - "x": 1 - }, - "progress": { - "canceled": 1, - "expired": 0, - "failed": 0, - "finished": 0, - "inprogress": 0, - "pending": 0, - "percentage": 0, - "total": 1, - "waiting": 0 - }, - "serverId": "99944", - "status": "CANCELED", - "tasks": [ - { - "description": "dummy", - "errorMessage": "The job was canceled by the api consumer", - "flow": "tasks", - "onError": "break", - "status": "CANCELED", - "statusTimestamps": { - "CANCELED": "2021-01-09T08:54:15+00:00", - "PENDING": "2021-01-09T08:54:06+00:00", - "WAITING": "2021-01-09T08:54:06+00:00" - }, - "uuid": "085ce145-39bd-4cb3-8e2b-53f17a97a463" - } - ], - "type": "install", - "updatedAt": "2021-01-09T08:54:15+0000", - "uuid": "c77d8a6b-d255-4744-8b95-8bf4af6f8b48" - }`) - }) - defer teardown() - - ctx := context.Background() - Job, err := DedicatedServerApi{}.ExpireActiveJob(ctx, "12345") - assert := assert.New(t) - assert.Nil(err) - - assert.Equal(Job.CreatedAt, "2021-01-09T08:54:06+0000") - assert.Equal(Job.Flow, "#stop") - assert.Equal(Job.IsRunning, false) - assert.Equal(Job.Node, "80:18:44:E0:AF:C4!JGNTQ92") - assert.Equal(Job.ServerId, "99944") - assert.Equal(Job.Status, "CANCELED") - assert.Equal(Job.Type, "install") - assert.Equal(Job.UpdatedAt, "2021-01-09T08:54:15+0000") - assert.Equal(Job.Uuid, "c77d8a6b-d255-4744-8b95-8bf4af6f8b48") - - assert.Equal(len(Job.Tasks), 1) - Task := Job.Tasks[0] - assert.Equal(Task.Description, "dummy") - assert.Equal(Task.Message, "The job was canceled by the api consumer") - assert.Equal(Task.Flow, "tasks") - assert.Equal(Task.OnError, "break") - assert.Equal(Task.Status, "CANCELED") - assert.Equal(Task.Uuid, "085ce145-39bd-4cb3-8e2b-53f17a97a463") - assert.Equal(Task.StatusTimestamps.Canceled, "2021-01-09T08:54:15+00:00") - assert.Equal(Task.StatusTimestamps.Pending, "2021-01-09T08:54:06+00:00") - assert.Equal(Task.StatusTimestamps.Waiting, "2021-01-09T08:54:06+00:00") - assert.Equal(Job.Progress.Canceled.String(), "1") - assert.Equal(Job.Progress.Expired.String(), "0") - assert.Equal(Job.Progress.Failed.String(), "0") - assert.Equal(Job.Progress.Finished.String(), "0") - assert.Equal(Job.Progress.InProgress.String(), "0") - assert.Equal(Job.Progress.Pending.String(), "0") - assert.Equal(Job.Progress.Percentage.String(), "0") - assert.Equal(Job.Progress.Total.String(), "1") - assert.Equal(Job.Progress.Waiting.String(), "0") - assert.Equal(Job.Payload["configurable"], true) - assert.Equal(Job.Payload["device"], "SATA2TB") - assert.Equal(Job.Payload["fileserverBaseUrl"], "http://asd.asd") - assert.Equal(Job.Payload["jobType"], "install") - assert.Empty(Job.Payload["numberOfDisks"]) - assert.Equal(Job.Payload["operatingSystemId"], "UBUNTU_20_04_64BIT") - assert.Equal(Job.Payload["os"].(map[string]interface{})["architecture"], "64bit") - assert.Equal(Job.Payload["os"].(map[string]interface{})["family"], "ubuntu") - assert.Equal(Job.Payload["os"].(map[string]interface{})["name"], "Ubuntu 20.04 LTS (Focal Fossa) (amd64)") - assert.Equal(Job.Payload["os"].(map[string]interface{})["type"], "linux") - assert.Equal(Job.Payload["os"].(map[string]interface{})["version"], "20.04") - assert.Equal(Job.Payload["partitions"].([]interface{})[0].(map[string]interface{})["filesystem"], "swap") - assert.Equal(Job.Payload["partitions"].([]interface{})[0].(map[string]interface{})["size"], "4096") - assert.Equal(Job.Payload["pop"], "AMS-01") - assert.Equal(Job.Payload["powerCycle"], true) - assert.Empty(Job.Payload["raidLevel"]) - assert.Equal(Job.Payload["serverId"], "99944") - assert.Equal(Job.Payload["timezone"], "UTC") - assert.Equal(Job.Payload["x"].(float64), float64(1)) -} - -func TestDedicatedServerExpireActiveJobServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.ExpireActiveJob(ctx, "12345") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.ExpireActiveJob(ctx, "12345") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "404", "errorMessage": "Resource not found"}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.ExpireActiveJob(ctx, "12345") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "404", - Message: "Resource not found", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.ExpireActiveJob(ctx, "12345") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.ExpireActiveJob(ctx, "12345") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedServerLaunchHardwareScan(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "createdAt": "2021-01-09T08:54:06+0000", - "flow": "tasks", - "isRunning": true, - "node": "80:18:44:E0:AF:C4!JGNTQ92", - "payload": { - "fileserverBaseUrl": "http://asd.asd", - "jobType": "hardwareScan", - "pop": "AMS-01", - "powerCycle": true, - "serverId": "99944" - }, - "progress": { - "canceled": 0, - "expired": 0, - "failed": 0, - "finished": 0, - "inprogress": 0, - "pending": 1, - "percentage": 0, - "total": 5, - "waiting": 4 - }, - "serverId": "99944", - "status": "ACTIVE", - "tasks": [ - { - "description": "dummy", - "errorMessage": null, - "flow": "tasks", - "onError": "break", - "status": "PENDING", - "statusTimestamps": { - "PENDING": "2021-01-09T08:54:06+00:00", - "WAITING": "2021-01-09T08:54:06+00:00" - }, - "uuid": "085ce145-39bd-4cb3-8e2b-53f17a97a463" - } - ], - "type": "hardwareScan", - "updatedAt": "2021-01-09T08:54:15+0000", - "uuid": "c77d8a6b-d255-4744-8b95-8bf4af6f8b48" - }`) - }) - defer teardown() - - payload := map[string]interface{}{"callbackUrl": "http://callback.url", "powerCycle": true} - ctx := context.Background() - Job, err := DedicatedServerApi{}.LaunchHardwareScan(ctx, "12345", payload) - assert := assert.New(t) - assert.Nil(err) - - assert.Equal(Job.CreatedAt, "2021-01-09T08:54:06+0000") - assert.Equal(Job.Flow, "tasks") - assert.Equal(Job.IsRunning, true) - assert.Equal(Job.Node, "80:18:44:E0:AF:C4!JGNTQ92") - assert.Equal(Job.ServerId, "99944") - assert.Equal(Job.Status, "ACTIVE") - assert.Equal(Job.Type, "hardwareScan") - assert.Equal(Job.UpdatedAt, "2021-01-09T08:54:15+0000") - assert.Equal(Job.Uuid, "c77d8a6b-d255-4744-8b95-8bf4af6f8b48") - - assert.Equal(len(Job.Tasks), 1) - Task := Job.Tasks[0] - assert.Equal(Task.Description, "dummy") - assert.Empty(Task.Message) - assert.Equal(Task.Flow, "tasks") - assert.Equal(Task.OnError, "break") - assert.Equal(Task.Status, "PENDING") - assert.Equal(Task.Uuid, "085ce145-39bd-4cb3-8e2b-53f17a97a463") - assert.Equal(Task.StatusTimestamps.Pending, "2021-01-09T08:54:06+00:00") - assert.Equal(Task.StatusTimestamps.Waiting, "2021-01-09T08:54:06+00:00") - assert.Equal(Job.Progress.Canceled.String(), "0") - assert.Equal(Job.Progress.Expired.String(), "0") - assert.Equal(Job.Progress.Failed.String(), "0") - assert.Equal(Job.Progress.Finished.String(), "0") - assert.Equal(Job.Progress.InProgress.String(), "0") - assert.Equal(Job.Progress.Pending.String(), "1") - assert.Equal(Job.Progress.Percentage.String(), "0") - assert.Equal(Job.Progress.Total.String(), "5") - assert.Equal(Job.Progress.Waiting.String(), "4") - assert.Equal(Job.Payload["fileserverBaseUrl"], "http://asd.asd") - assert.Equal(Job.Payload["jobType"], "hardwareScan") - assert.Equal(Job.Payload["pop"], "AMS-01") - assert.Equal(Job.Payload["powerCycle"], true) - assert.Equal(Job.Payload["serverId"], "99944") -} - -func TestDedicatedServerLaunchHardwareScanServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - payload := map[string]interface{}{"callbackUrl": "http://callback.url", "powerCycle": true} - ctx := context.Background() - return DedicatedServerApi{}.LaunchHardwareScan(ctx, "12345", payload) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - payload := map[string]interface{}{"callbackUrl": "http://callback.url", "powerCycle": true} - ctx := context.Background() - return DedicatedServerApi{}.LaunchHardwareScan(ctx, "12345", payload) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "404", "errorMessage": "Resource not found"}`) - }, - FunctionCall: func() (interface{}, error) { - payload := map[string]interface{}{"callbackUrl": "http://callback.url", "powerCycle": true} - ctx := context.Background() - return DedicatedServerApi{}.LaunchHardwareScan(ctx, "12345", payload) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "404", - Message: "Resource not found", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - payload := map[string]interface{}{"callbackUrl": "http://callback.url", "powerCycle": true} - ctx := context.Background() - return DedicatedServerApi{}.LaunchHardwareScan(ctx, "12345", payload) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - payload := map[string]interface{}{"callbackUrl": "http://callback.url", "powerCycle": true} - ctx := context.Background() - return DedicatedServerApi{}.LaunchHardwareScan(ctx, "12345", payload) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedServerLaunchInstallation(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "createdAt": "2021-03-06T21:55:32+0000", - "flow": "tasks", - "isRunning": true, - "node": "AA:BB:CC:DD:EE:FF!DKFJKD8989", - "payload": { - "configurable": true, - "device": "SATA2TB", - "fileserverBaseUrl": "10.11.20.2", - "isUnassignedServer": false, - "jobType": "install", - "numberOfDisks": null, - "operatingSystemId": "UBUNTU_20_04_64BIT", - "os": { - "architecture": "64bit", - "family": "ubuntu", - "name": "Ubuntu 20.04 LTS (Focal Fossa) (amd64)", - "type": "linux", - "version": "20.04" - }, - "partitions": [ - { - "bootable": true, - "filesystem": "ext2", - "mountpoint": "/boot", - "primary": true, - "size": "500" - }, - { - "filesystem": "swap", - "size": "4096" - }, - { - "filesystem": "ext4", - "mountpoint": "/tmp", - "size": "4096" - }, - { - "filesystem": "ext4", - "mountpoint": "/", - "primary": true, - "size": "*" - } - ], - "pop": "AMS-01", - "powerCycle": true, - "raidLevel": null, - "serverId": "12345", - "timezone": "UTC" - }, - "progress": { - "canceled": 0, - "expired": 0, - "failed": 0, - "finished": 0, - "inprogress": 0, - "pending": 1, - "percentage": 0, - "total": 26, - "waiting": 25 - }, - "serverId": "12345", - "status": "ACTIVE", - "tasks": [ - { - "description": "dummy", - "errorMessage": null, - "flow": "tasks", - "onError": "break", - "status": "PENDING", - "statusTimestamps": { - "PENDING": "2021-01-09T09:18:06+00:00", - "WAITING": "2021-01-09T09:18:06+00:00" - }, - "uuid": "c1a56a5a-ae38-4b12-acb6-0cba9ceb1016" - } - ], - "type": "install", - "updatedAt": "2021-03-06T21:55:32+0000", - "uuid": "bcf2bedf-8450-4b22-86a8-f30aeb3a38f9" - }`) - }) - defer teardown() - - payload := map[string]interface{}{ - "controlPanelId": "PLESK_12", - "device": "SATA2TB", - "hostname": "ubuntu20.local", - "operatingSystemId": "UBUNTU_20_04_64BIT", - "partitions": []map[string]interface{}{ - { - "bootable": true, - "filesystem": "ext2", - "mountpoint": "/boot", - "primary": true, - "size": "512", - }, - { - "filesystem": "swap", - "size": "4096", - }, - { - "filesystem": "ext4", - "mountpoint": "/tmp", - "size": "2048", - }, - { - "filesystem": "ext4", - "mountpoint": "/", - "primary": true, - "size": "*", - }, - }, - "sshKeys": "ssh-rsa AAAAB3NzaC1y... user@domain.com", - } - ctx := context.Background() - Job, err := DedicatedServerApi{}.LaunchInstallation(ctx, "12345", payload) - assert := assert.New(t) - assert.Nil(err) - - assert.Equal(Job.CreatedAt, "2021-03-06T21:55:32+0000") - assert.Equal(Job.Flow, "tasks") - assert.Equal(Job.IsRunning, true) - assert.Equal(Job.Node, "AA:BB:CC:DD:EE:FF!DKFJKD8989") - assert.Equal(Job.ServerId, "12345") - assert.Equal(Job.Status, "ACTIVE") - assert.Equal(Job.Type, "install") - assert.Equal(Job.UpdatedAt, "2021-03-06T21:55:32+0000") - assert.Equal(Job.Uuid, "bcf2bedf-8450-4b22-86a8-f30aeb3a38f9") - - assert.Equal(len(Job.Tasks), 1) - Task := Job.Tasks[0] - - assert.Equal(Task.Description, "dummy") - assert.Empty(Task.Message) - assert.Equal(Task.Flow, "tasks") - assert.Equal(Task.OnError, "break") - assert.Equal(Task.Status, "PENDING") - assert.Equal(Task.Uuid, "c1a56a5a-ae38-4b12-acb6-0cba9ceb1016") - assert.Equal(Task.StatusTimestamps.Pending, "2021-01-09T09:18:06+00:00") - assert.Equal(Task.StatusTimestamps.Waiting, "2021-01-09T09:18:06+00:00") - assert.Equal(Job.Progress.Canceled.String(), "0") - assert.Equal(Job.Progress.Expired.String(), "0") - assert.Equal(Job.Progress.Failed.String(), "0") - assert.Equal(Job.Progress.Finished.String(), "0") - assert.Equal(Job.Progress.InProgress.String(), "0") - assert.Equal(Job.Progress.Pending.String(), "1") - assert.Equal(Job.Progress.Percentage.String(), "0") - assert.Equal(Job.Progress.Total.String(), "26") - assert.Equal(Job.Progress.Waiting.String(), "25") - assert.Equal(Job.Payload["fileserverBaseUrl"], "10.11.20.2") - assert.Equal(Job.Payload["configurable"], true) - assert.Equal(Job.Payload["pop"], "AMS-01") - assert.Equal(Job.Payload["powerCycle"], true) - assert.Equal(Job.Payload["serverId"], "12345") - assert.Equal(Job.Payload["timezone"], "UTC") - assert.Empty(Job.Payload["raidLevel"]) - assert.Equal(Job.Payload["device"], "SATA2TB") - assert.Equal(Job.Payload["isUnassignedServer"], false) - assert.Equal(Job.Payload["jobType"], "install") - assert.Empty(Job.Payload["numberOfDisks"]) - assert.Equal(Job.Payload["operatingSystemId"], "UBUNTU_20_04_64BIT") - assert.Equal(Job.Payload["os"].(map[string]interface{})["architecture"], "64bit") - assert.Equal(Job.Payload["os"].(map[string]interface{})["family"], "ubuntu") - assert.Equal(Job.Payload["os"].(map[string]interface{})["name"], "Ubuntu 20.04 LTS (Focal Fossa) (amd64)") - assert.Equal(Job.Payload["os"].(map[string]interface{})["type"], "linux") - assert.Equal(Job.Payload["os"].(map[string]interface{})["version"], "20.04") - assert.Equal(Job.Payload["partitions"].([]interface{})[0].(map[string]interface{})["filesystem"], "ext2") - assert.Equal(Job.Payload["partitions"].([]interface{})[0].(map[string]interface{})["size"], "500") - assert.Equal(Job.Payload["partitions"].([]interface{})[0].(map[string]interface{})["bootable"], true) - assert.Equal(Job.Payload["partitions"].([]interface{})[0].(map[string]interface{})["mountpoint"], "/boot") - assert.Equal(Job.Payload["partitions"].([]interface{})[0].(map[string]interface{})["primary"], true) - assert.Equal(Job.Payload["partitions"].([]interface{})[1].(map[string]interface{})["filesystem"], "swap") - assert.Equal(Job.Payload["partitions"].([]interface{})[1].(map[string]interface{})["size"], "4096") - assert.Equal(Job.Payload["partitions"].([]interface{})[2].(map[string]interface{})["filesystem"], "ext4") - assert.Equal(Job.Payload["partitions"].([]interface{})[2].(map[string]interface{})["mountpoint"], "/tmp") - assert.Equal(Job.Payload["partitions"].([]interface{})[2].(map[string]interface{})["size"], "4096") - assert.Equal(Job.Payload["partitions"].([]interface{})[3].(map[string]interface{})["filesystem"], "ext4") - assert.Equal(Job.Payload["partitions"].([]interface{})[3].(map[string]interface{})["size"], "*") - assert.Equal(Job.Payload["partitions"].([]interface{})[3].(map[string]interface{})["mountpoint"], "/") - assert.Equal(Job.Payload["partitions"].([]interface{})[3].(map[string]interface{})["primary"], true) -} - -func TestDedicatedServerLaunchInstallationServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - payload := map[string]interface{}{ - "controlPanelId": "PLESK_12", - "device": "SATA2TB", - "hostname": "ubuntu20.local", - "operatingSystemId": "UBUNTU_20_04_64BIT", - "partitions": []map[string]interface{}{ - { - "bootable": true, - "filesystem": "ext2", - "mountpoint": "/boot", - "primary": true, - "size": "512", - }, - { - "filesystem": "swap", - "size": "4096", - }, - { - "filesystem": "ext4", - "mountpoint": "/tmp", - "size": "2048", - }, - { - "filesystem": "ext4", - "mountpoint": "/", - "primary": true, - "size": "*", - }, - }, - "sshKeys": "ssh-rsa AAAAB3NzaC1y... user@domain.com", - } - ctx := context.Background() - return DedicatedServerApi{}.LaunchInstallation(ctx, "12345", payload) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - payload := map[string]interface{}{ - "controlPanelId": "PLESK_12", - "device": "SATA2TB", - "hostname": "ubuntu20.local", - "operatingSystemId": "UBUNTU_20_04_64BIT", - "partitions": []map[string]interface{}{ - { - "bootable": true, - "filesystem": "ext2", - "mountpoint": "/boot", - "primary": true, - "size": "512", - }, - { - "filesystem": "swap", - "size": "4096", - }, - { - "filesystem": "ext4", - "mountpoint": "/tmp", - "size": "2048", - }, - { - "filesystem": "ext4", - "mountpoint": "/", - "primary": true, - "size": "*", - }, - }, - "sshKeys": "ssh-rsa AAAAB3NzaC1y... user@domain.com", - } - ctx := context.Background() - return DedicatedServerApi{}.LaunchInstallation(ctx, "12345", payload) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "404", "errorMessage": "Resource not found"}`) - }, - FunctionCall: func() (interface{}, error) { - payload := map[string]interface{}{ - "controlPanelId": "PLESK_12", - "device": "SATA2TB", - "hostname": "ubuntu20.local", - "operatingSystemId": "UBUNTU_20_04_64BIT", - "partitions": []map[string]interface{}{ - { - "bootable": true, - "filesystem": "ext2", - "mountpoint": "/boot", - "primary": true, - "size": "512", - }, - { - "filesystem": "swap", - "size": "4096", - }, - { - "filesystem": "ext4", - "mountpoint": "/tmp", - "size": "2048", - }, - { - "filesystem": "ext4", - "mountpoint": "/", - "primary": true, - "size": "*", - }, - }, - "sshKeys": "ssh-rsa AAAAB3NzaC1y... user@domain.com", - } - ctx := context.Background() - return DedicatedServerApi{}.LaunchInstallation(ctx, "12345", payload) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "404", - Message: "Resource not found", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - payload := map[string]interface{}{ - "controlPanelId": "PLESK_12", - "device": "SATA2TB", - "hostname": "ubuntu20.local", - "operatingSystemId": "UBUNTU_20_04_64BIT", - "partitions": []map[string]interface{}{ - { - "bootable": true, - "filesystem": "ext2", - "mountpoint": "/boot", - "primary": true, - "size": "512", - }, - { - "filesystem": "swap", - "size": "4096", - }, - { - "filesystem": "ext4", - "mountpoint": "/tmp", - "size": "2048", - }, - { - "filesystem": "ext4", - "mountpoint": "/", - "primary": true, - "size": "*", - }, - }, - "sshKeys": "ssh-rsa AAAAB3NzaC1y... user@domain.com", - } - ctx := context.Background() - return DedicatedServerApi{}.LaunchInstallation(ctx, "12345", payload) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - payload := map[string]interface{}{ - "controlPanelId": "PLESK_12", - "device": "SATA2TB", - "hostname": "ubuntu20.local", - "operatingSystemId": "UBUNTU_20_04_64BIT", - "partitions": []map[string]interface{}{ - { - "bootable": true, - "filesystem": "ext2", - "mountpoint": "/boot", - "primary": true, - "size": "512", - }, - { - "filesystem": "swap", - "size": "4096", - }, - { - "filesystem": "ext4", - "mountpoint": "/tmp", - "size": "2048", - }, - { - "filesystem": "ext4", - "mountpoint": "/", - "primary": true, - "size": "*", - }, - }, - "sshKeys": "ssh-rsa AAAAB3NzaC1y... user@domain.com", - } - ctx := context.Background() - return DedicatedServerApi{}.LaunchInstallation(ctx, "12345", payload) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedServerLaunchIpmiRest(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "createdAt": "2018-01-09T09:18:06+0000", - "flow": "tasks", - "isRunning": true, - "node": "80:18:44:E0:AF:C4!JGNTQ92", - "payload": { - "fileserverBaseUrl": "", - "hasPublicIpmiIp": false, - "jobType": "ipmiReset", - "pop": "AMS-01", - "powerCycle": true, - "serverId": "99944" - }, - "progress": { - "canceled": 0, - "expired": 0, - "failed": 0, - "finished": 0, - "inprogress": 0, - "pending": 1, - "percentage": 0, - "total": 1, - "waiting": 0 - }, - "serverId": "99944", - "status": "ACTIVE", - "tasks": [ - { - "description": "dummy", - "errorMessage": null, - "flow": "tasks", - "onError": "break", - "status": "PENDING", - "statusTimestamps": { - "PENDING": "2018-01-09T09:18:06+00:00", - "WAITING": "2018-01-09T09:18:06+00:00" - }, - "uuid": "c1a56a5a-ae38-4b12-acb6-0cba9ceb1016" - } - ], - "type": "ipmiReset", - "updatedAt": "2018-01-09T09:18:06+0000", - "uuid": "754154c2-cc7f-4d5f-b8bf-b654084ba4a9" - }`) - }) - defer teardown() - - payload := map[string]interface{}{"callbackUrl": "https://callbacks.example.org"} - ctx := context.Background() - Job, err := DedicatedServerApi{}.LaunchIpmiRest(ctx, "12345", payload) - assert := assert.New(t) - assert.Nil(err) - - assert.Equal(Job.CreatedAt, "2018-01-09T09:18:06+0000") - assert.Equal(Job.Flow, "tasks") - assert.Equal(Job.IsRunning, true) - assert.Equal(Job.Node, "80:18:44:E0:AF:C4!JGNTQ92") - assert.Equal(Job.ServerId, "99944") - assert.Equal(Job.Status, "ACTIVE") - assert.Equal(Job.Type, "ipmiReset") - assert.Equal(Job.UpdatedAt, "2018-01-09T09:18:06+0000") - assert.Equal(Job.Uuid, "754154c2-cc7f-4d5f-b8bf-b654084ba4a9") - - assert.Equal(len(Job.Tasks), 1) - Task := Job.Tasks[0] - - assert.Equal(Task.Description, "dummy") - assert.Empty(Task.Message) - assert.Equal(Task.Flow, "tasks") - assert.Equal(Task.OnError, "break") - assert.Equal(Task.Status, "PENDING") - assert.Equal(Task.Uuid, "c1a56a5a-ae38-4b12-acb6-0cba9ceb1016") - assert.Equal(Task.StatusTimestamps.Pending, "2018-01-09T09:18:06+00:00") - assert.Equal(Task.StatusTimestamps.Waiting, "2018-01-09T09:18:06+00:00") - assert.Equal(Job.Progress.Canceled.String(), "0") - assert.Equal(Job.Progress.Expired.String(), "0") - assert.Equal(Job.Progress.Failed.String(), "0") - assert.Equal(Job.Progress.Finished.String(), "0") - assert.Equal(Job.Progress.InProgress.String(), "0") - assert.Equal(Job.Progress.Pending.String(), "1") - assert.Equal(Job.Progress.Percentage.String(), "0") - assert.Equal(Job.Progress.Total.String(), "1") - assert.Equal(Job.Progress.Waiting.String(), "0") - - assert.Equal(Job.Payload["fileserverBaseUrl"], "") - assert.Equal(Job.Payload["pop"], "AMS-01") - assert.Equal(Job.Payload["powerCycle"], true) - assert.Equal(Job.Payload["serverId"], "99944") - assert.Equal(Job.Payload["jobType"], "ipmiReset") - assert.Equal(Job.Payload["hasPublicIpmiIp"], false) -} - -func TestDedicatedServerLaunchIpmiRestServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - payload := map[string]interface{}{"callbackUrl": "https://callbacks.example.org"} - ctx := context.Background() - return DedicatedServerApi{}.LaunchIpmiRest(ctx, "12345", payload) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - payload := map[string]interface{}{"callbackUrl": "https://callbacks.example.org"} - ctx := context.Background() - return DedicatedServerApi{}.LaunchIpmiRest(ctx, "12345", payload) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "404", "errorMessage": "Resource not found"}`) - }, - FunctionCall: func() (interface{}, error) { - payload := map[string]interface{}{"callbackUrl": "https://callbacks.example.org"} - ctx := context.Background() - return DedicatedServerApi{}.LaunchIpmiRest(ctx, "12345", payload) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "404", - Message: "Resource not found", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - payload := map[string]interface{}{"callbackUrl": "https://callbacks.example.org"} - ctx := context.Background() - return DedicatedServerApi{}.LaunchIpmiRest(ctx, "12345", payload) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - payload := map[string]interface{}{"callbackUrl": "https://callbacks.example.org"} - ctx := context.Background() - return DedicatedServerApi{}.LaunchIpmiRest(ctx, "12345", payload) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedServerListJobs(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "_metadata": { - "limit": 10, - "offset": 0, - "totalCount": 1 - }, - "jobs": [ - { - "createdAt": "2018-01-09T10:38:12+0000", - "flow": "tasks", - "isRunning": true, - "node": "80:18:44:E0:AF:C4!JGNTQ92", - "progress": { - "canceled": 0, - "expired": 0, - "failed": 0, - "finished": 0, - "inprogress": 0, - "pending": 1, - "percentage": 0, - "total": 1, - "waiting": 0 - }, - "serverId": "99944", - "status": "ACTIVE", - "type": "install", - "updatedAt": "2018-01-09T10:38:12+0000", - "uuid": "3a867358-5b4b-44ee-88ac-4274603ef641" - } - ] - }`) - }) - defer teardown() - - ctx := context.Background() - response, err := DedicatedServerApi{}.ListJobs(ctx, "99944", DedicatedServerListJobOptions{}) - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 1) - assert.Equal(response.Metadata.Offset, 0) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.Jobs), 1) - - Job := response.Jobs[0] - assert.Equal(Job.Progress.Canceled.String(), "0") - assert.Equal(Job.Progress.Expired.String(), "0") - assert.Equal(Job.Progress.Failed.String(), "0") - assert.Equal(Job.Progress.Finished.String(), "0") - assert.Equal(Job.Progress.InProgress.String(), "0") - assert.Equal(Job.Progress.Pending.String(), "1") - assert.Equal(Job.Progress.Percentage.String(), "0") - assert.Equal(Job.Progress.Total.String(), "1") - assert.Equal(Job.Progress.Waiting.String(), "0") - assert.Equal(Job.Flow, "tasks") - assert.Equal(Job.IsRunning, true) - assert.Equal(Job.Node, "80:18:44:E0:AF:C4!JGNTQ92") - assert.Equal(Job.CreatedAt, "2018-01-09T10:38:12+0000") - assert.Equal(Job.ServerId, "99944") - assert.Equal(Job.Status, "ACTIVE") - assert.Equal(Job.Type, "install") - assert.Equal(Job.UpdatedAt, "2018-01-09T10:38:12+0000") - assert.Equal(Job.Uuid, "3a867358-5b4b-44ee-88ac-4274603ef641") -} - -func TestDedicatedServerListJobsBeEmpty(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{"_metadata":{"limit": 10, "offset": 0, "totalCount": 0}, "jobs": []}`) - }) - defer teardown() - ctx := context.Background() - response, err := DedicatedServerApi{}.ListJobs(ctx, "99944", DedicatedServerListJobOptions{}) - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 0) - assert.Equal(response.Metadata.Offset, 0) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.Jobs), 0) -} - -func TestDedicatedServerListJobsPaginate(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "_metadata": { - "limit": 10, - "offset": 1, - "totalCount": 11 - }, - "jobs": [ - { - "createdAt": "2018-01-09T10:38:12+0000", - "flow": "tasks", - "isRunning": true, - "node": "80:18:44:E0:AF:C4!JGNTQ92", - "progress": { - "canceled": 0, - "expired": 0, - "failed": 0, - "finished": 0, - "inprogress": 0, - "pending": 1, - "percentage": 0, - "total": 1, - "waiting": 0 - }, - "serverId": "99944", - "status": "ACTIVE", - "type": "install", - "updatedAt": "2018-01-09T10:38:12+0000", - "uuid": "3a867358-5b4b-44ee-88ac-4274603ef641" - } - ] - }`) - }) - defer teardown() - - ctx := context.Background() - opts := DedicatedServerListJobOptions{ - PaginationOptions: PaginationOptions{ - Limit: Int(10), - }, - } - response, err := DedicatedServerApi{}.ListJobs(ctx, "99944", opts) - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 11) - assert.Equal(response.Metadata.Offset, 1) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.Jobs), 1) - - Job := response.Jobs[0] - assert.Equal(Job.Progress.Canceled.String(), "0") - assert.Equal(Job.Progress.Expired.String(), "0") - assert.Equal(Job.Progress.Failed.String(), "0") - assert.Equal(Job.Progress.Finished.String(), "0") - assert.Equal(Job.Progress.InProgress.String(), "0") - assert.Equal(Job.Progress.Pending.String(), "1") - assert.Equal(Job.Progress.Percentage.String(), "0") - assert.Equal(Job.Progress.Total.String(), "1") - assert.Equal(Job.Progress.Waiting.String(), "0") - assert.Equal(Job.Flow, "tasks") - assert.Equal(Job.IsRunning, true) - assert.Equal(Job.Node, "80:18:44:E0:AF:C4!JGNTQ92") - assert.Equal(Job.CreatedAt, "2018-01-09T10:38:12+0000") - assert.Equal(Job.ServerId, "99944") - assert.Equal(Job.Status, "ACTIVE") - assert.Equal(Job.Type, "install") - assert.Equal(Job.UpdatedAt, "2018-01-09T10:38:12+0000") - assert.Equal(Job.Uuid, "3a867358-5b4b-44ee-88ac-4274603ef641") -} - -func TestDedicatedServerListJobsServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.ListJobs(ctx, "99944", DedicatedServerListJobOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "Access to the requested resource is forbidden."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.ListJobs(ctx, "99944", DedicatedServerListJobOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "Access to the requested resource is forbidden.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.ListJobs(ctx, "99944", DedicatedServerListJobOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.ListJobs(ctx, "99944", DedicatedServerListJobOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedServerGetJob(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "createdAt": "2021-01-09T10:38:12+0000", - "flow": "tasks", - "isRunning": true, - "metadata": { - "BATCH_ID": "biannual-os-upgrade-installs" - }, - "node": "80:18:44:E0:AF:C4!JGNTQ92", - "payload": { - "configurable": true, - "device": "SATA2TB", - "fileserverBaseUrl": "", - "jobType": "install", - "numberOfDisks": null, - "operatingSystemId": "UBUNTU_20_04_64BIT", - "os": { - "architecture": "64bit", - "family": "ubuntu", - "name": "Ubuntu 20.04 LTS (Focal Fossa) (amd64)", - "type": "linux", - "version": "20.04" - }, - "partitions": [ - { - "filesystem": "swap", - "size": "4096" - } - ], - "pop": "AMS-01", - "powerCycle": true, - "raidLevel": null, - "serverId": "99944", - "timezone": "UTC", - "x": 1 - }, - "progress": { - "canceled": 0, - "expired": 0, - "failed": 0, - "finished": 0, - "inprogress": 0, - "pending": 1, - "percentage": 0, - "total": 1, - "waiting": 0 - }, - "serverId": "99944", - "status": "ACTIVE", - "tasks": [ - { - "description": "dummy", - "errorMessage": null, - "flow": "tasks", - "onError": "break", - "status": "PENDING", - "statusTimestamps": { - "PENDING": "2021-01-09T10:38:12+00:00", - "WAITING": "2021-01-09T10:38:12+00:00" - }, - "uuid": "8a10b74b-2a94-4a3b-88da-b9c07faa240d" - } - ], - "type": "install", - "updatedAt": "2021-01-09T10:38:12+0000", - "uuid": "3a867358-5b4b-44ee-88ac-4274603ef641" - }`) - }) - defer teardown() - - ctx := context.Background() - Job, err := DedicatedServerApi{}.GetJob(ctx, "99944", "job id") - assert := assert.New(t) - assert.Nil(err) - assert.Equal(Job.Progress.Canceled.String(), "0") - assert.Equal(Job.Progress.Expired.String(), "0") - assert.Equal(Job.Progress.Failed.String(), "0") - assert.Equal(Job.Progress.Finished.String(), "0") - assert.Equal(Job.Progress.InProgress.String(), "0") - assert.Equal(Job.Progress.Pending.String(), "1") - assert.Equal(Job.Progress.Percentage.String(), "0") - assert.Equal(Job.Progress.Total.String(), "1") - assert.Equal(Job.Progress.Waiting.String(), "0") - assert.Equal(Job.Flow, "tasks") - assert.Equal(Job.IsRunning, true) - assert.Equal(Job.Node, "80:18:44:E0:AF:C4!JGNTQ92") - assert.Equal(Job.CreatedAt, "2021-01-09T10:38:12+0000") - assert.Equal(Job.ServerId, "99944") - assert.Equal(Job.Status, "ACTIVE") - assert.Equal(Job.Type, "install") - assert.Equal(Job.UpdatedAt, "2021-01-09T10:38:12+0000") - assert.Equal(Job.Uuid, "3a867358-5b4b-44ee-88ac-4274603ef641") - assert.Equal(Job.Metadata.BatchId, "biannual-os-upgrade-installs") - assert.Equal(len(Job.Tasks), 1) - assert.Equal(Job.Tasks[0].Description, "dummy") - assert.Empty(Job.Tasks[0].Message) - assert.Equal(Job.Tasks[0].Flow, "tasks") - assert.Equal(Job.Tasks[0].OnError, "break") - assert.Equal(Job.Tasks[0].Status, "PENDING") - assert.Equal(Job.Tasks[0].StatusTimestamps.Pending, "2021-01-09T10:38:12+00:00") - assert.Equal(Job.Tasks[0].StatusTimestamps.Waiting, "2021-01-09T10:38:12+00:00") - assert.Equal(Job.Tasks[0].Uuid, "8a10b74b-2a94-4a3b-88da-b9c07faa240d") - - assert.Equal(Job.Payload["configurable"], true) - assert.Equal(Job.Payload["device"], "SATA2TB") - assert.Equal(Job.Payload["fileserverBaseUrl"], "") - assert.Equal(Job.Payload["jobType"], "install") - assert.Empty(Job.Payload["numberOfDisks"]) - assert.Equal(Job.Payload["operatingSystemId"], "UBUNTU_20_04_64BIT") - assert.Equal(Job.Payload["os"].(map[string]interface{})["architecture"], "64bit") - assert.Equal(Job.Payload["os"].(map[string]interface{})["family"], "ubuntu") - assert.Equal(Job.Payload["os"].(map[string]interface{})["name"], "Ubuntu 20.04 LTS (Focal Fossa) (amd64)") - assert.Equal(Job.Payload["os"].(map[string]interface{})["type"], "linux") - assert.Equal(Job.Payload["os"].(map[string]interface{})["version"], "20.04") - assert.Equal(Job.Payload["pop"], "AMS-01") - assert.Equal(Job.Payload["powerCycle"], true) - assert.Empty(Job.Payload["raidLevel"]) - assert.Equal(Job.Payload["serverId"], "99944") - assert.Equal(Job.Payload["timezone"], "UTC") - assert.Equal(Job.Payload["x"].(float64), float64(1)) - assert.Equal(Job.Payload["partitions"].([]interface{})[0].(map[string]interface{})["filesystem"], "swap") - assert.Equal(Job.Payload["partitions"].([]interface{})[0].(map[string]interface{})["size"], "4096") -} - -func TestDedicatedServerGetJobServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.GetJob(ctx, "99944", "job id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.GetJob(ctx, "99944", "job id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "404", "errorMessage": "Resource not found"}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.GetJob(ctx, "99944", "job id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "404", - Message: "Resource not found", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.GetJob(ctx, "99944", "job id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.GetJob(ctx, "99944", "job id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedServerLaunchRescueMode(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "createdAt": "2018-01-09T09:18:06+0000", - "flow": "tasks", - "isRunning": true, - "node": "80:18:44:E0:AF:C4!JGNTQ92", - "payload": { - "fileserverBaseUrl": "10.11.20.2", - "isUnassignedServer": false, - "jobType": "rescueMode", - "pop": "AMS-01", - "powerCycle": true, - "serverId": "2349839" - }, - "progress": { - "canceled": 0, - "expired": 0, - "failed": 0, - "finished": 0, - "inprogress": 0, - "pending": 1, - "percentage": 0, - "total": 12, - "waiting": 11 - }, - "serverId": "2349839", - "status": "ACTIVE", - "tasks": [ - { - "description": "dummy", - "errorMessage": null, - "flow": "tasks", - "onError": "break", - "status": "PENDING", - "statusTimestamps": { - "PENDING": "2018-01-09T09:18:06+00:00", - "WAITING": "2018-01-09T09:18:06+00:00" - }, - "uuid": "c1a56a5a-ae38-4b12-acb6-0cba9ceb1016" - } - ], - "type": "rescueMode", - "updatedAt": "2018-01-09T09:18:06+0000", - "uuid": "754154c2-cc7f-4d5f-b8bf-b654084ba4a9" - }`) - }) - defer teardown() - - payload := map[string]interface{}{ - "callbackUrl": "https://example.com/urlExecutedOnCallback", - "powerCycle": true, - "rescueImageId": "GRML", - "sshKeys": "ssh-rsa AAAAB3NzaC1y... user@domain.com", - } - ctx := context.Background() - Job, err := DedicatedServerApi{}.LaunchRescueMode(ctx, "2349839", payload) - assert := assert.New(t) - assert.Nil(err) - - assert.Equal(Job.CreatedAt, "2018-01-09T09:18:06+0000") - assert.Equal(Job.Flow, "tasks") - assert.Equal(Job.IsRunning, true) - assert.Equal(Job.Node, "80:18:44:E0:AF:C4!JGNTQ92") - assert.Equal(Job.ServerId, "2349839") - assert.Equal(Job.Status, "ACTIVE") - assert.Equal(Job.Type, "rescueMode") - assert.Equal(Job.UpdatedAt, "2018-01-09T09:18:06+0000") - assert.Equal(Job.Uuid, "754154c2-cc7f-4d5f-b8bf-b654084ba4a9") - - assert.Equal(len(Job.Tasks), 1) - Task := Job.Tasks[0] - - assert.Equal(Task.Description, "dummy") - assert.Empty(Task.Message) - assert.Equal(Task.Flow, "tasks") - assert.Equal(Task.OnError, "break") - assert.Equal(Task.Status, "PENDING") - assert.Equal(Task.Uuid, "c1a56a5a-ae38-4b12-acb6-0cba9ceb1016") - assert.Equal(Task.StatusTimestamps.Pending, "2018-01-09T09:18:06+00:00") - assert.Equal(Task.StatusTimestamps.Waiting, "2018-01-09T09:18:06+00:00") - assert.Equal(Job.Progress.Canceled.String(), "0") - assert.Equal(Job.Progress.Expired.String(), "0") - assert.Equal(Job.Progress.Failed.String(), "0") - assert.Equal(Job.Progress.Finished.String(), "0") - assert.Equal(Job.Progress.InProgress.String(), "0") - assert.Equal(Job.Progress.Pending.String(), "1") - assert.Equal(Job.Progress.Percentage.String(), "0") - assert.Equal(Job.Progress.Total.String(), "12") - assert.Equal(Job.Progress.Waiting.String(), "11") - - assert.Equal(Job.Payload["fileserverBaseUrl"], "10.11.20.2") - assert.Equal(Job.Payload["pop"], "AMS-01") - assert.Equal(Job.Payload["powerCycle"], true) - assert.Equal(Job.Payload["serverId"], "2349839") - assert.Equal(Job.Payload["jobType"], "rescueMode") - assert.Equal(Job.Payload["isUnassignedServer"], false) -} - -func TestDedicatedServerLaunchRescueModeServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - payload := map[string]interface{}{ - "callbackUrl": "https://example.com/urlExecutedOnCallback", - "powerCycle": true, - "rescueImageId": "GRML", - "sshKeys": "ssh-rsa AAAAB3NzaC1y... user@domain.com", - } - ctx := context.Background() - return DedicatedServerApi{}.LaunchRescueMode(ctx, "2349839", payload) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - payload := map[string]interface{}{ - "callbackUrl": "https://example.com/urlExecutedOnCallback", - "powerCycle": true, - "rescueImageId": "GRML", - "sshKeys": "ssh-rsa AAAAB3NzaC1y... user@domain.com", - } - ctx := context.Background() - return DedicatedServerApi{}.LaunchRescueMode(ctx, "2349839", payload) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "404", "errorMessage": "Resource not found"}`) - }, - FunctionCall: func() (interface{}, error) { - payload := map[string]interface{}{ - "callbackUrl": "https://example.com/urlExecutedOnCallback", - "powerCycle": true, - "rescueImageId": "GRML", - "sshKeys": "ssh-rsa AAAAB3NzaC1y... user@domain.com", - } - ctx := context.Background() - return DedicatedServerApi{}.LaunchRescueMode(ctx, "2349839", payload) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "404", - Message: "Resource not found", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - payload := map[string]interface{}{ - "callbackUrl": "https://example.com/urlExecutedOnCallback", - "powerCycle": true, - "rescueImageId": "GRML", - "sshKeys": "ssh-rsa AAAAB3NzaC1y... user@domain.com", - } - ctx := context.Background() - return DedicatedServerApi{}.LaunchRescueMode(ctx, "2349839", payload) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - payload := map[string]interface{}{ - "callbackUrl": "https://example.com/urlExecutedOnCallback", - "powerCycle": true, - "rescueImageId": "GRML", - "sshKeys": "ssh-rsa AAAAB3NzaC1y... user@domain.com", - } - ctx := context.Background() - return DedicatedServerApi{}.LaunchRescueMode(ctx, "2349839", payload) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedServerListCredentials(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "_metadata": { - "limit": 10, - "offset": 0, - "totalCount": 4 - }, - "credentials": [ - { - "type": "REMOTE_MANAGEMENT", - "username": "admin" - }, - { - "type": "REMOTE_MANAGEMENT", - "username": "root" - }, - { - "type": "OPERATING_SYSTEM", - "username": "root" - }, - { - "type": "OPERATING_SYSTEM", - "username": "user" - } - ] - }`) - }) - defer teardown() - - ctx := context.Background() - response, err := DedicatedServerApi{}.ListCredentials(ctx, "99944", PaginationOptions{}) - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 4) - assert.Equal(response.Metadata.Offset, 0) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.Credentials), 4) - - assert.Equal(response.Credentials[0].Type, "REMOTE_MANAGEMENT") - assert.Equal(response.Credentials[0].Username, "admin") - assert.Equal(response.Credentials[1].Type, "REMOTE_MANAGEMENT") - assert.Equal(response.Credentials[1].Username, "root") - assert.Equal(response.Credentials[2].Type, "OPERATING_SYSTEM") - assert.Equal(response.Credentials[2].Username, "root") - assert.Equal(response.Credentials[3].Type, "OPERATING_SYSTEM") - assert.Equal(response.Credentials[3].Username, "user") -} - -func TestDedicatedServerListCredentialsBeEmpty(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{"_metadata":{"limit": 10, "offset": 0, "totalCount": 0}, "credentials": []}`) - }) - defer teardown() - ctx := context.Background() - response, err := DedicatedServerApi{}.ListCredentials(ctx, "99944", PaginationOptions{}) - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 0) - assert.Equal(response.Metadata.Offset, 0) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.Credentials), 0) -} - -func TestDedicatedServerListCredentialsPaginate(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "_metadata": { - "limit": 10, - "offset": 1, - "totalCount": 11 - }, - "credentials": [ - { - "type": "REMOTE_MANAGEMENT", - "username": "admin" - } - ] - }`) - }) - defer teardown() - - ctx := context.Background() - response, err := DedicatedServerApi{}.ListCredentials(ctx, "99944", PaginationOptions{}) - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 11) - assert.Equal(response.Metadata.Offset, 1) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.Credentials), 1) - - assert.Equal(response.Credentials[0].Type, "REMOTE_MANAGEMENT") - assert.Equal(response.Credentials[0].Username, "admin") -} - -func TestDedicatedServerListCredentialsServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.ListCredentials(ctx, "99944", PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.ListCredentials(ctx, "99944", PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "404", "errorMessage": "Resource not found"}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.ListCredentials(ctx, "99944", PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "404", - Message: "Resource not found", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.ListCredentials(ctx, "99944", PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.ListCredentials(ctx, "99944", PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedServerCreateCredential(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "password": "mys3cr3tp@ssw0rd", - "type": "OPERATING_SYSTEM", - "username": "root" - }`) - }) - defer teardown() - - ctx := context.Background() - resp, err := DedicatedServerApi{}.CreateCredential(ctx, "12345", "OPERATING_SYSTEM", "root", "mys3cr3tp@ssw0rd") - assert := assert.New(t) - assert.Nil(err) - - assert.Equal(resp.Type, "OPERATING_SYSTEM") - assert.Equal(resp.Username, "root") - assert.Equal(resp.Password, "mys3cr3tp@ssw0rd") -} - -func TestDedicatedServerCreateCredentialServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 400", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"430495b4-c052-451a-a016-30d8f72ac59b","errorCode":"400","errorMessage":"Validation Failed","errorDetails":{"username":["Usernames can only contain alphanumeric values and @.-_ characters"],"password":["This field is missing."]}}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.CreateCredential(ctx, "12345", "OPERATING_SYSTEM", "ro=ot", "") - }, - ExpectedError: ApiError{ - CorrelationId: "430495b4-c052-451a-a016-30d8f72ac59b", - Code: "400", - Message: "Validation Failed", - Details: map[string][]string{ - "username": []string{"Usernames can only contain alphanumeric values and @.-_ characters"}, - "password": []string{"This field is missing."}, - }, - }, - }, - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.CreateCredential(ctx, "12345", "OPERATING_SYSTEM", "root", "mys3cr3tp@ssw0rd") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.CreateCredential(ctx, "12345", "OPERATING_SYSTEM", "root", "mys3cr3tp@ssw0rd") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "404", "errorMessage": "Resource not found"}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.CreateCredential(ctx, "12345", "OPERATING_SYSTEM", "root", "mys3cr3tp@ssw0rd") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "404", - Message: "Resource not found", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.CreateCredential(ctx, "12345", "OPERATING_SYSTEM", "root", "mys3cr3tp@ssw0rd") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.CreateCredential(ctx, "12345", "OPERATING_SYSTEM", "root", "mys3cr3tp@ssw0rd") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedServerListCredentialsByType(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "_metadata": { - "limit": 10, - "offset": 0, - "totalCount": 2 - }, - "credentials": [ - { - "type": "REMOTE_MANAGEMENT", - "username": "admin" - }, - { - "type": "REMOTE_MANAGEMENT", - "username": "root" - } - ] - }`) - }) - defer teardown() - - ctx := context.Background() - response, err := DedicatedServerApi{}.ListCredentialsByType(ctx, "99944", "REMOTE_MANAGEMENT", PaginationOptions{}) - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 2) - assert.Equal(response.Metadata.Offset, 0) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.Credentials), 2) - - assert.Equal(response.Credentials[0].Type, "REMOTE_MANAGEMENT") - assert.Equal(response.Credentials[0].Username, "admin") - assert.Equal(response.Credentials[1].Type, "REMOTE_MANAGEMENT") - assert.Equal(response.Credentials[1].Username, "root") -} - -func TestDedicatedServerListCredentialsByTypeBeEmpty(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{"_metadata":{"limit": 10, "offset": 0, "totalCount": 0}, "credentials": []}`) - }) - defer teardown() - ctx := context.Background() - response, err := DedicatedServerApi{}.ListCredentialsByType(ctx, "99944", "REMOTE_MANAGEMENT", PaginationOptions{}) - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 0) - assert.Equal(response.Metadata.Offset, 0) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.Credentials), 0) -} - -func TestDedicatedServerListCredentialsByTypePaginate(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "_metadata": { - "limit": 10, - "offset": 1, - "totalCount": 11 - }, - "credentials": [ - { - "type": "REMOTE_MANAGEMENT", - "username": "admin" - } - ] - }`) - }) - defer teardown() - - ctx := context.Background() - response, err := DedicatedServerApi{}.ListCredentialsByType(ctx, "99944", "REMOTE_MANAGEMENT", PaginationOptions{}) - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 11) - assert.Equal(response.Metadata.Offset, 1) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.Credentials), 1) - - assert.Equal(response.Credentials[0].Type, "REMOTE_MANAGEMENT") - assert.Equal(response.Credentials[0].Username, "admin") -} - -func TestDedicatedServerListCredentialsByTypeServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.ListCredentialsByType(ctx, "99944", "REMOTE_MANAGEMENT", PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.ListCredentialsByType(ctx, "99944", "REMOTE_MANAGEMENT", PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "404", "errorMessage": "Resource not found"}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.ListCredentialsByType(ctx, "99944", "REMOTE_MANAGEMENT", PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "404", - Message: "Resource not found", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.ListCredentialsByType(ctx, "99944", "REMOTE_MANAGEMENT", PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.ListCredentialsByType(ctx, "99944", "REMOTE_MANAGEMENT", PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedServerGetCredentials(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "password": "mys3cr3tp@ssw0rd", - "type": "OPERATING_SYSTEM", - "username": "root" - }`) - }) - defer teardown() - - ctx := context.Background() - Credential, err := DedicatedServerApi{}.GetCredential(ctx, "12345", "OPERATING_SYSTEM", "root") - assert := assert.New(t) - assert.Nil(err) - assert.Equal(Credential.Password, "mys3cr3tp@ssw0rd") - assert.Equal(Credential.Username, "root") - assert.Equal(Credential.Type, "OPERATING_SYSTEM") -} - -func TestDedicatedServerGetCredentialsServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.GetCredential(ctx, "12345", "OPERATING_SYSTEM", "root") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.GetCredential(ctx, "12345", "OPERATING_SYSTEM", "root") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "404", "errorMessage": "Resource not found"}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.GetCredential(ctx, "12345", "OPERATING_SYSTEM", "root") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "404", - Message: "Resource not found", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.GetCredential(ctx, "12345", "OPERATING_SYSTEM", "root") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.GetCredential(ctx, "12345", "OPERATING_SYSTEM", "root") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedServerDeleteCredentials(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusNoContent) - }) - defer teardown() - - ctx := context.Background() - err := DedicatedServerApi{}.DeleteCredential(ctx, "12345", "OPERATING_SYSTEM", "admin") - assert := assert.New(t) - assert.Nil(err) -} - -func TestDedicatedServerDeleteCredentialsServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedServerApi{}.DeleteCredential(ctx, "12345", "OPERATING_SYSTEM", "admin") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedServerApi{}.DeleteCredential(ctx, "12345", "OPERATING_SYSTEM", "admin") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "404", "errorMessage": "Resource not found"}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedServerApi{}.DeleteCredential(ctx, "12345", "OPERATING_SYSTEM", "admin") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "404", - Message: "Resource not found", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedServerApi{}.DeleteCredential(ctx, "12345", "OPERATING_SYSTEM", "admin") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedServerApi{}.DeleteCredential(ctx, "12345", "OPERATING_SYSTEM", "admin") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedServerUpdateCredentials(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "password": "new password", - "type": "OPERATING_SYSTEM", - "username": "admin" - }`) - }) - defer teardown() - - ctx := context.Background() - resp, err := DedicatedServerApi{}.UpdateCredential(ctx, "12345", "OPERATING_SYSTEM", "admin", "new password") - assert := assert.New(t) - assert.Nil(err) - - assert.Equal(resp.Password, "new password") - assert.Equal(resp.Type, "OPERATING_SYSTEM") - assert.Equal(resp.Username, "admin") -} - -func TestDedicatedServerUpdateCredentialsServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.UpdateCredential(ctx, "12345", "OPERATING_SYSTEM", "admin", "new password") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.UpdateCredential(ctx, "12345", "OPERATING_SYSTEM", "admin", "new password") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "404", "errorMessage": "Resource not found"}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.UpdateCredential(ctx, "12345", "OPERATING_SYSTEM", "admin", "new password") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "404", - Message: "Resource not found", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.UpdateCredential(ctx, "12345", "OPERATING_SYSTEM", "admin", "new password") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.UpdateCredential(ctx, "12345", "OPERATING_SYSTEM", "admin", "new password") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedServerGetBandWidthMetrics(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "_metadata": { - "aggregation": "AVG", - "from": "2016-10-20T09:00:00Z", - "granularity": "HOUR", - "to": "2016-10-20T11:00:00Z" - }, - "metrics": { - "DOWN_PUBLIC": { - "unit": "bps", - "values": [ - { - "timestamp": "2016-10-20T09:00:00Z", - "value": 202499 - }, - { - "timestamp": "2016-10-20T10:00:00Z", - "value": 29900 - } - ] - }, - "UP_PUBLIC": { - "unit": "bps", - "values": [ - { - "timestamp": "2016-10-20T09:00:00Z", - "value": 43212393 - }, - { - "timestamp": "2016-10-20T10:00:00Z", - "value": 12342929 - } - ] - } - } - }`) - }) - defer teardown() - - ctx := context.Background() - opts := MetricsOptions{ - From: String("2016-10-20T09:00:00Z"), - To: String("2016-10-20T11:00:00Z"), - Granularity: String("HOUR"), - Aggregation: String("AVG"), - } - Metric, err := DedicatedServerApi{}.GetBandWidthMetrics(ctx, "99944", opts) - assert := assert.New(t) - assert.Nil(err) - assert.Equal(Metric.Metadata.Aggregation, "AVG") - assert.Equal(Metric.Metadata.From, "2016-10-20T09:00:00Z") - assert.Equal(Metric.Metadata.To, "2016-10-20T11:00:00Z") - assert.Equal(Metric.Metadata.Granularity, "HOUR") - assert.Equal(Metric.Metric.DownPublic.Unit, "bps") - assert.Equal(Metric.Metric.DownPublic.Values[0].Value.String(), "202499") - assert.Equal(Metric.Metric.DownPublic.Values[0].Timestamp, "2016-10-20T09:00:00Z") - assert.Equal(Metric.Metric.DownPublic.Values[1].Value.String(), "29900") - assert.Equal(Metric.Metric.DownPublic.Values[1].Timestamp, "2016-10-20T10:00:00Z") - - assert.Equal(Metric.Metric.UpPublic.Unit, "bps") - assert.Equal(Metric.Metric.UpPublic.Values[0].Value.String(), "43212393") - assert.Equal(Metric.Metric.UpPublic.Values[0].Timestamp, "2016-10-20T09:00:00Z") - assert.Equal(Metric.Metric.UpPublic.Values[1].Value.String(), "12342929") - assert.Equal(Metric.Metric.UpPublic.Values[1].Timestamp, "2016-10-20T10:00:00Z") -} - -func TestDedicatedServerGetBandWidthMetricsServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - opts := MetricsOptions{ - From: String("2016-10-20T09:00:00Z"), - To: String("2016-10-20T11:00:00Z"), - Granularity: String("HOUR"), - Aggregation: String("AVG"), - } - return DedicatedServerApi{}.GetBandWidthMetrics(ctx, "99944", opts) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - opts := MetricsOptions{ - From: String("2016-10-20T09:00:00Z"), - To: String("2016-10-20T11:00:00Z"), - Granularity: String("HOUR"), - Aggregation: String("AVG"), - } - return DedicatedServerApi{}.GetBandWidthMetrics(ctx, "99944", opts) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "404", "errorMessage": "Resource not found"}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - opts := MetricsOptions{ - From: String("2016-10-20T09:00:00Z"), - To: String("2016-10-20T11:00:00Z"), - Granularity: String("HOUR"), - Aggregation: String("AVG"), - } - return DedicatedServerApi{}.GetBandWidthMetrics(ctx, "99944", opts) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "404", - Message: "Resource not found", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - opts := MetricsOptions{ - From: String("2016-10-20T09:00:00Z"), - To: String("2016-10-20T11:00:00Z"), - Granularity: String("HOUR"), - Aggregation: String("AVG"), - } - return DedicatedServerApi{}.GetBandWidthMetrics(ctx, "99944", opts) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - opts := MetricsOptions{ - From: String("2016-10-20T09:00:00Z"), - To: String("2016-10-20T11:00:00Z"), - Granularity: String("HOUR"), - Aggregation: String("AVG"), - } - return DedicatedServerApi{}.GetBandWidthMetrics(ctx, "99944", opts) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedServerGetDataTrafficMetrics(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "_metadata": { - "aggregation": "SUM", - "from": "2016-10-20T09:00:00Z", - "granularity": "HOUR", - "to": "2016-10-20T11:00:00Z" - }, - "metrics": { - "DOWN_PUBLIC": { - "unit": "B", - "values": [ - { - "timestamp": "2016-10-20T09:00:00Z", - "value": 202499 - }, - { - "timestamp": "2016-10-20T10:00:00Z", - "value": 29900 - } - ] - }, - "UP_PUBLIC": { - "unit": "B", - "values": [ - { - "timestamp": "2016-10-20T09:00:00Z", - "value": 43212393 - }, - { - "timestamp": "2016-10-20T10:00:00Z", - "value": 12342929 - } - ] - } - } - }`) - }) - defer teardown() - - ctx := context.Background() - opts := MetricsOptions{ - From: String("2016-10-20T09:00:00Z"), - To: String("2016-10-20T11:00:00Z"), - Granularity: String("HOUR"), - Aggregation: String("SUM"), - } - Metric, err := DedicatedServerApi{}.GetDataTrafficMetrics(ctx, "99944", opts) - assert := assert.New(t) - assert.Nil(err) - assert.Equal(Metric.Metadata.Aggregation, "SUM") - assert.Equal(Metric.Metadata.From, "2016-10-20T09:00:00Z") - assert.Equal(Metric.Metadata.To, "2016-10-20T11:00:00Z") - assert.Equal(Metric.Metadata.Granularity, "HOUR") - assert.Equal(Metric.Metric.DownPublic.Unit, "B") - assert.Equal(Metric.Metric.DownPublic.Values[0].Value.String(), "202499") - assert.Equal(Metric.Metric.DownPublic.Values[0].Timestamp, "2016-10-20T09:00:00Z") - assert.Equal(Metric.Metric.DownPublic.Values[1].Value.String(), "29900") - assert.Equal(Metric.Metric.DownPublic.Values[1].Timestamp, "2016-10-20T10:00:00Z") - - assert.Equal(Metric.Metric.UpPublic.Unit, "B") - assert.Equal(Metric.Metric.UpPublic.Values[0].Value.String(), "43212393") - assert.Equal(Metric.Metric.UpPublic.Values[0].Timestamp, "2016-10-20T09:00:00Z") - assert.Equal(Metric.Metric.UpPublic.Values[1].Value.String(), "12342929") - assert.Equal(Metric.Metric.UpPublic.Values[1].Timestamp, "2016-10-20T10:00:00Z") -} - -func TestDedicatedServerGetDataTrafficMetricsServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - opts := MetricsOptions{ - From: String("2016-10-20T09:00:00Z"), - To: String("2016-10-20T11:00:00Z"), - Granularity: String("HOUR"), - Aggregation: String("SUM"), - } - return DedicatedServerApi{}.GetDataTrafficMetrics(ctx, "99944", opts) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - opts := MetricsOptions{ - From: String("2016-10-20T09:00:00Z"), - To: String("2016-10-20T11:00:00Z"), - Granularity: String("HOUR"), - Aggregation: String("SUM"), - } - return DedicatedServerApi{}.GetDataTrafficMetrics(ctx, "99944", opts) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "404", "errorMessage": "Resource not found"}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - opts := MetricsOptions{ - From: String("2016-10-20T09:00:00Z"), - To: String("2016-10-20T11:00:00Z"), - Granularity: String("HOUR"), - Aggregation: String("SUM"), - } - return DedicatedServerApi{}.GetDataTrafficMetrics(ctx, "99944", opts) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "404", - Message: "Resource not found", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - opts := MetricsOptions{ - From: String("2016-10-20T09:00:00Z"), - To: String("2016-10-20T11:00:00Z"), - Granularity: String("HOUR"), - Aggregation: String("SUM"), - } - return DedicatedServerApi{}.GetDataTrafficMetrics(ctx, "99944", opts) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - opts := MetricsOptions{ - From: String("2016-10-20T09:00:00Z"), - To: String("2016-10-20T11:00:00Z"), - Granularity: String("HOUR"), - Aggregation: String("SUM"), - } - return DedicatedServerApi{}.GetDataTrafficMetrics(ctx, "99944", opts) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedServerListBandWidthNotificationSettings(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "_metadata": { - "limit": 10, - "offset": 0, - "totalCount": 2 - }, - "bandwidthNotificationSettings": [ - { - "actions": [ - { - "lastTriggeredAt": "2021-03-16T01:01:44+00:00", - "type": "EMAIL" - } - ], - "frequency": "WEEKLY", - "id": "12345", - "lastCheckedAt": "2021-03-16T01:01:41+00:00", - "threshold": "1", - "thresholdExceededAt": "2021-03-16T01:01:41+00:00", - "unit": "Gbps" - }, - { - "actions": [ - { - "lastTriggeredAt": "2021-03-16T01:01:44+00:00", - "type": "EMAIL" - } - ], - "frequency": "DAILY", - "id": "123456", - "lastCheckedAt": "2021-03-16T01:01:41+00:00", - "threshold": "1", - "thresholdExceededAt": "2021-03-16T01:01:41+00:00", - "unit": "Mbps" - } - ] - }`) - }) - defer teardown() - - ctx := context.Background() - resp, err := DedicatedServerApi{}.ListBandWidthNotificationSettings(ctx, "server-id", PaginationOptions{}) - assert := assert.New(t) - assert.Nil(err) - assert.Equal(resp.Metadata.TotalCount, 2) - assert.Equal(resp.Metadata.Offset, 0) - assert.Equal(resp.Metadata.Limit, 10) - assert.Equal(len(resp.Settings), 2) - - assert.Equal(resp.Settings[0].Actions[0].LastTriggeredAt, "2021-03-16T01:01:44+00:00") - assert.Equal(resp.Settings[0].Actions[0].Type, "EMAIL") - assert.Equal(resp.Settings[0].Frequency, "WEEKLY") - assert.Equal(resp.Settings[0].Id, "12345") - assert.Equal(resp.Settings[0].LastCheckedAt, "2021-03-16T01:01:41+00:00") - assert.Equal(resp.Settings[0].Threshold.String(), "1") - assert.Equal(resp.Settings[0].ThresholdExceededAt, "2021-03-16T01:01:41+00:00") - assert.Equal(resp.Settings[0].Unit, "Gbps") - - assert.Equal(resp.Settings[1].Actions[0].LastTriggeredAt, "2021-03-16T01:01:44+00:00") - assert.Equal(resp.Settings[1].Actions[0].Type, "EMAIL") - assert.Equal(resp.Settings[1].Frequency, "DAILY") - assert.Equal(resp.Settings[1].Id, "123456") - assert.Equal(resp.Settings[1].LastCheckedAt, "2021-03-16T01:01:41+00:00") - assert.Equal(resp.Settings[1].Threshold.String(), "1") - assert.Equal(resp.Settings[1].ThresholdExceededAt, "2021-03-16T01:01:41+00:00") - assert.Equal(resp.Settings[1].Unit, "Mbps") -} - -func TestDedicatedServerListBandWidthNotificationSettingsPaginate(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "_metadata": { - "limit": 10, - "offset": 1, - "totalCount": 11 - }, - "bandwidthNotificationSettings": [ - { - "actions": [ - { - "lastTriggeredAt": "2021-03-16T01:01:44+00:00", - "type": "EMAIL" - } - ], - "frequency": "WEEKLY", - "id": "12345", - "lastCheckedAt": "2021-03-16T01:01:41+00:00", - "threshold": "1", - "thresholdExceededAt": "2021-03-16T01:01:41+00:00", - "unit": "Gbps" - } - ] - }`) - }) - defer teardown() - - ctx := context.Background() - opts := PaginationOptions{ - Limit: Int(1), - } - resp, err := DedicatedServerApi{}.ListBandWidthNotificationSettings(ctx, "server-id", opts) - assert := assert.New(t) - assert.Nil(err) - assert.Equal(resp.Metadata.TotalCount, 11) - assert.Equal(resp.Metadata.Offset, 1) - assert.Equal(resp.Metadata.Limit, 10) - assert.Equal(len(resp.Settings), 1) - - assert.Equal(resp.Settings[0].Actions[0].LastTriggeredAt, "2021-03-16T01:01:44+00:00") - assert.Equal(resp.Settings[0].Actions[0].Type, "EMAIL") - assert.Equal(resp.Settings[0].Frequency, "WEEKLY") - assert.Equal(resp.Settings[0].Id, "12345") - assert.Equal(resp.Settings[0].LastCheckedAt, "2021-03-16T01:01:41+00:00") - assert.Equal(resp.Settings[0].Threshold.String(), "1") - assert.Equal(resp.Settings[0].ThresholdExceededAt, "2021-03-16T01:01:41+00:00") - assert.Equal(resp.Settings[0].Unit, "Gbps") -} - -func TestDedicatedServerListBandWidthNotificationSettingsServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.ListBandWidthNotificationSettings(ctx, "server-id", PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.ListBandWidthNotificationSettings(ctx, "server-id", PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "404", "errorMessage": "Resource not found"}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.ListBandWidthNotificationSettings(ctx, "server-id", PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "404", - Message: "Resource not found", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.ListBandWidthNotificationSettings(ctx, "server-id", PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.ListBandWidthNotificationSettings(ctx, "server-id", PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedServerCreateBandWidthNotificationSetting(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "actions": [ - { - "lastTriggeredAt": "2021-03-16T01:01:44+00:00", - "type": "EMAIL" - } - ], - "frequency": "WEEKLY", - "id": "12345", - "lastCheckedAt": "2021-03-16T01:01:41+00:00", - "threshold": "1", - "thresholdExceededAt": "2021-03-16T01:01:41+00:00", - "unit": "Gbps" - }`) - }) - defer teardown() - - ctx := context.Background() - resp, err := DedicatedServerApi{}.CreateBandWidthNotificationSetting(ctx, "server-id", "WEEKLY", 1, "Gbps") - assert := assert.New(t) - assert.Nil(err) - - assert.Equal(resp.Actions[0].LastTriggeredAt, "2021-03-16T01:01:44+00:00") - assert.Equal(resp.Actions[0].Type, "EMAIL") - assert.Equal(resp.Frequency, "WEEKLY") - assert.Equal(resp.Id, "12345") - assert.Equal(resp.LastCheckedAt, "2021-03-16T01:01:41+00:00") - assert.Equal(resp.Threshold.String(), "1") - assert.Equal(resp.ThresholdExceededAt, "2021-03-16T01:01:41+00:00") - assert.Equal(resp.Unit, "Gbps") -} - -func TestDedicatedServerCreateBandWidthNotificationSettingServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.CreateBandWidthNotificationSetting(ctx, "server-id", "WEEKLY", 1, "Gbps") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.CreateBandWidthNotificationSetting(ctx, "server-id", "WEEKLY", 1, "Gbps") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "404", "errorMessage": "Resource not found"}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.CreateBandWidthNotificationSetting(ctx, "server-id", "WEEKLY", 1, "Gbps") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "404", - Message: "Resource not found", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.CreateBandWidthNotificationSetting(ctx, "server-id", "WEEKLY", 1, "Gbps") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.CreateBandWidthNotificationSetting(ctx, "server-id", "WEEKLY", 1, "Gbps") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedServerDeleteBandWidthNotificationSetting(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusNoContent) - }) - defer teardown() - - ctx := context.Background() - err := DedicatedServerApi{}.DeleteBandWidthNotificationSetting(ctx, "server id", "notification id") - assert := assert.New(t) - assert.Nil(err) -} - -func TestDedicatedServerDeleteBandWidthNotificationSettingServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedServerApi{}.DeleteBandWidthNotificationSetting(ctx, "server id", "notification id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedServerApi{}.DeleteBandWidthNotificationSetting(ctx, "server id", "notification id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "404", "errorMessage": "Resource not found"}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedServerApi{}.DeleteBandWidthNotificationSetting(ctx, "server id", "notification id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "404", - Message: "Resource not found", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedServerApi{}.DeleteBandWidthNotificationSetting(ctx, "server id", "notification id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedServerApi{}.DeleteBandWidthNotificationSetting(ctx, "server id", "notification id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedServerGetBandWidthNotificationSetting(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "actions": [ - { - "lastTriggeredAt": "2021-03-16T01:01:44+00:00", - "type": "EMAIL" - } - ], - "frequency": "WEEKLY", - "id": "12345", - "lastCheckedAt": "2021-03-16T01:01:41+00:00", - "threshold": "1", - "thresholdExceededAt": "2021-03-16T01:01:41+00:00", - "unit": "Gbps" - }`) - }) - defer teardown() - - ctx := context.Background() - resp, err := DedicatedServerApi{}.GetBandWidthNotificationSetting(ctx, "server-id", "notification id") - assert := assert.New(t) - assert.Nil(err) - - assert.Equal(resp.Actions[0].LastTriggeredAt, "2021-03-16T01:01:44+00:00") - assert.Equal(resp.Actions[0].Type, "EMAIL") - assert.Equal(resp.Frequency, "WEEKLY") - assert.Equal(resp.Id, "12345") - assert.Equal(resp.LastCheckedAt, "2021-03-16T01:01:41+00:00") - assert.Equal(resp.Threshold.String(), "1") - assert.Equal(resp.ThresholdExceededAt, "2021-03-16T01:01:41+00:00") - assert.Equal(resp.Unit, "Gbps") -} - -func TestDedicatedServerGetBandWidthNotificationSettingServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.GetBandWidthNotificationSetting(ctx, "server-id", "notification id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.GetBandWidthNotificationSetting(ctx, "server-id", "notification id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "404", "errorMessage": "Resource not found"}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.GetBandWidthNotificationSetting(ctx, "server-id", "notification id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "404", - Message: "Resource not found", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.GetBandWidthNotificationSetting(ctx, "server-id", "notification id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.GetBandWidthNotificationSetting(ctx, "server-id", "notification id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedServerUpdateBandWidthNotificationSetting(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "actions": [ - { - "lastTriggeredAt": "2021-03-16T01:01:44+00:00", - "type": "EMAIL" - } - ], - "frequency": "MONTHLY", - "id": "12345", - "lastCheckedAt": "2021-03-16T01:01:41+00:00", - "threshold": "2", - "thresholdExceededAt": "2021-03-16T01:01:41+00:00", - "unit": "Mbps" - }`) - }) - defer teardown() - - payload := map[string]string{"frequency": "MONTHLY", "threshold": "2", "unit": "Mbps"} - ctx := context.Background() - resp, err := DedicatedServerApi{}.UpdateBandWidthNotificationSetting(ctx, "server-id", "notification id", payload) - assert := assert.New(t) - assert.Nil(err) - - assert.Equal(resp.Actions[0].LastTriggeredAt, "2021-03-16T01:01:44+00:00") - assert.Equal(resp.Actions[0].Type, "EMAIL") - assert.Equal(resp.Frequency, "MONTHLY") - assert.Equal(resp.Id, "12345") - assert.Equal(resp.LastCheckedAt, "2021-03-16T01:01:41+00:00") - assert.Equal(resp.Threshold.String(), "2") - assert.Equal(resp.ThresholdExceededAt, "2021-03-16T01:01:41+00:00") - assert.Equal(resp.Unit, "Mbps") -} - -func TestDedicatedServerUpdateBandWidthNotificationSettingServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - payload := map[string]string{"frequency": "MONTHLY", "threshold": "2", "unit": "Mbps"} - ctx := context.Background() - return DedicatedServerApi{}.UpdateBandWidthNotificationSetting(ctx, "server-id", "notification id", payload) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - payload := map[string]string{"frequency": "MONTHLY", "threshold": "2", "unit": "Mbps"} - ctx := context.Background() - return DedicatedServerApi{}.UpdateBandWidthNotificationSetting(ctx, "server-id", "notification id", payload) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "404", "errorMessage": "Resource not found"}`) - }, - FunctionCall: func() (interface{}, error) { - payload := map[string]string{"frequency": "MONTHLY", "threshold": "2", "unit": "Mbps"} - ctx := context.Background() - return DedicatedServerApi{}.UpdateBandWidthNotificationSetting(ctx, "server-id", "notification id", payload) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "404", - Message: "Resource not found", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - payload := map[string]string{"frequency": "MONTHLY", "threshold": "2", "unit": "Mbps"} - ctx := context.Background() - return DedicatedServerApi{}.UpdateBandWidthNotificationSetting(ctx, "server-id", "notification id", payload) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - payload := map[string]string{"frequency": "MONTHLY", "threshold": "2", "unit": "Mbps"} - ctx := context.Background() - return DedicatedServerApi{}.UpdateBandWidthNotificationSetting(ctx, "server-id", "notification id", payload) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedServerListDataTrafficNotificationSettings(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "_metadata": { - "limit": 10, - "offset": 0, - "totalCount": 2 - }, - "datatrafficNotificationSettings": [ - { - "actions": [ - { - "lastTriggeredAt": null, - "type": "EMAIL" - } - ], - "frequency": "WEEKLY", - "id": "12345", - "lastCheckedAt": null, - "threshold": "1", - "thresholdExceededAt": null, - "unit": "MB" - }, - { - "actions": [ - { - "lastTriggeredAt": null, - "type": "EMAIL" - } - ], - "frequency": "DAILY", - "id": "123456", - "lastCheckedAt": null, - "threshold": "1", - "thresholdExceededAt": null, - "unit": "GB" - } - ] - }`) - }) - defer teardown() - - ctx := context.Background() - resp, err := DedicatedServerApi{}.ListDataTrafficNotificationSettings(ctx, "server-id", PaginationOptions{}) - assert := assert.New(t) - assert.Nil(err) - assert.Equal(resp.Metadata.TotalCount, 2) - assert.Equal(resp.Metadata.Offset, 0) - assert.Equal(resp.Metadata.Limit, 10) - assert.Equal(len(resp.Settings), 2) - - assert.Empty(resp.Settings[0].Actions[0].LastTriggeredAt) - assert.Equal(resp.Settings[0].Actions[0].Type, "EMAIL") - assert.Equal(resp.Settings[0].Frequency, "WEEKLY") - assert.Equal(resp.Settings[0].Id, "12345") - assert.Empty(resp.Settings[0].LastCheckedAt) - assert.Equal(resp.Settings[0].Threshold.String(), "1") - assert.Empty(resp.Settings[0].ThresholdExceededAt) - assert.Equal(resp.Settings[0].Unit, "MB") - - assert.Empty(resp.Settings[1].Actions[0].LastTriggeredAt) - assert.Equal(resp.Settings[1].Actions[0].Type, "EMAIL") - assert.Equal(resp.Settings[1].Frequency, "DAILY") - assert.Equal(resp.Settings[1].Id, "123456") - assert.Empty(resp.Settings[1].LastCheckedAt) - assert.Equal(resp.Settings[1].Threshold.String(), "1") - assert.Empty(resp.Settings[1].ThresholdExceededAt) - assert.Equal(resp.Settings[1].Unit, "GB") -} - -func TestDedicatedServerListDataTrafficNotificationSettingsPaginate(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "_metadata": { - "limit": 10, - "offset": 1, - "totalCount": 11 - }, - "datatrafficNotificationSettings": [ - { - "actions": [ - { - "lastTriggeredAt": null, - "type": "EMAIL" - } - ], - "frequency": "WEEKLY", - "id": "12345", - "lastCheckedAt": null, - "threshold": "1", - "thresholdExceededAt": null, - "unit": "MB" - } - ] - }`) - }) - defer teardown() - - ctx := context.Background() - opts := PaginationOptions{ - Limit: Int(1), - } - resp, err := DedicatedServerApi{}.ListDataTrafficNotificationSettings(ctx, "server-id", opts) - assert := assert.New(t) - assert.Nil(err) - assert.Equal(resp.Metadata.TotalCount, 11) - assert.Equal(resp.Metadata.Offset, 1) - assert.Equal(resp.Metadata.Limit, 10) - assert.Equal(len(resp.Settings), 1) - - assert.Empty(resp.Settings[0].Actions[0].LastTriggeredAt) - assert.Equal(resp.Settings[0].Actions[0].Type, "EMAIL") - assert.Equal(resp.Settings[0].Frequency, "WEEKLY") - assert.Equal(resp.Settings[0].Id, "12345") - assert.Empty(resp.Settings[0].LastCheckedAt) - assert.Equal(resp.Settings[0].Threshold.String(), "1") - assert.Empty(resp.Settings[0].ThresholdExceededAt) - assert.Equal(resp.Settings[0].Unit, "MB") -} - -func TestDedicatedServerListDataTrafficNotificationSettingsServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.ListDataTrafficNotificationSettings(ctx, "server-id", PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.ListDataTrafficNotificationSettings(ctx, "server-id", PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "404", "errorMessage": "Resource not found"}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.ListDataTrafficNotificationSettings(ctx, "server-id", PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "404", - Message: "Resource not found", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.ListDataTrafficNotificationSettings(ctx, "server-id", PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.ListDataTrafficNotificationSettings(ctx, "server-id", PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedServerCreateDataTrafficNotificationSetting(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "actions": [ - { - "lastTriggeredAt": "2021-03-16T01:01:44+00:00", - "type": "EMAIL" - } - ], - "frequency": "WEEKLY", - "id": "12345", - "lastCheckedAt": "2021-03-16T01:01:41+00:00", - "threshold": "1", - "thresholdExceededAt": "2021-03-16T01:01:41+00:00", - "unit": "GB" - }`) - }) - defer teardown() - - ctx := context.Background() - resp, err := DedicatedServerApi{}.CreateDataTrafficNotificationSetting(ctx, "server-id", "WEEKLY", 1, "GB") - assert := assert.New(t) - assert.Nil(err) - - assert.Equal(resp.Actions[0].LastTriggeredAt, "2021-03-16T01:01:44+00:00") - assert.Equal(resp.Actions[0].Type, "EMAIL") - assert.Equal(resp.Frequency, "WEEKLY") - assert.Equal(resp.Id, "12345") - assert.Equal(resp.LastCheckedAt, "2021-03-16T01:01:41+00:00") - assert.Equal(resp.Threshold.String(), "1") - assert.Equal(resp.ThresholdExceededAt, "2021-03-16T01:01:41+00:00") - assert.Equal(resp.Unit, "GB") -} - -func TestDedicatedServerCreateDataTrafficNotificationSettingServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.CreateDataTrafficNotificationSetting(ctx, "server-id", "WEEKLY", 1, "GB") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.CreateDataTrafficNotificationSetting(ctx, "server-id", "WEEKLY", 1, "GB") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "404", "errorMessage": "Resource not found"}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.CreateDataTrafficNotificationSetting(ctx, "server-id", "WEEKLY", 1, "GB") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "404", - Message: "Resource not found", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.CreateDataTrafficNotificationSetting(ctx, "server-id", "WEEKLY", 1, "GB") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.CreateDataTrafficNotificationSetting(ctx, "server-id", "WEEKLY", 1, "GB") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedServerDeleteDataTrafficNotificationSetting(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusNoContent) - }) - defer teardown() - - ctx := context.Background() - err := DedicatedServerApi{}.DeleteDataTrafficNotificationSetting(ctx, "server id", "notification id") - assert := assert.New(t) - assert.Nil(err) -} - -func TestDedicatedServerDeleteDataTrafficNotificationSettingServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedServerApi{}.DeleteDataTrafficNotificationSetting(ctx, "server id", "notification id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedServerApi{}.DeleteDataTrafficNotificationSetting(ctx, "server id", "notification id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "404", "errorMessage": "Resource not found"}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedServerApi{}.DeleteDataTrafficNotificationSetting(ctx, "server id", "notification id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "404", - Message: "Resource not found", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedServerApi{}.DeleteDataTrafficNotificationSetting(ctx, "server id", "notification id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedServerApi{}.DeleteDataTrafficNotificationSetting(ctx, "server id", "notification id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedServerGetDataTrafficNotificationSetting(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "actions": [ - { - "lastTriggeredAt": "2021-03-16T01:01:44+00:00", - "type": "EMAIL" - } - ], - "frequency": "WEEKLY", - "id": "12345", - "lastCheckedAt": "2021-03-16T01:01:41+00:00", - "threshold": "1", - "thresholdExceededAt": "2021-03-16T01:01:41+00:00", - "unit": "GB" - }`) - }) - defer teardown() - - ctx := context.Background() - resp, err := DedicatedServerApi{}.GetDataTrafficNotificationSetting(ctx, "server-id", "notification id") - assert := assert.New(t) - assert.Nil(err) - - assert.Equal(resp.Actions[0].LastTriggeredAt, "2021-03-16T01:01:44+00:00") - assert.Equal(resp.Actions[0].Type, "EMAIL") - assert.Equal(resp.Frequency, "WEEKLY") - assert.Equal(resp.Id, "12345") - assert.Equal(resp.LastCheckedAt, "2021-03-16T01:01:41+00:00") - assert.Equal(resp.Threshold.String(), "1") - assert.Equal(resp.ThresholdExceededAt, "2021-03-16T01:01:41+00:00") - assert.Equal(resp.Unit, "GB") -} - -func TestDedicatedServerGetDataTrafficNotificationSettingServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.GetDataTrafficNotificationSetting(ctx, "server-id", "notification id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.GetDataTrafficNotificationSetting(ctx, "server-id", "notification id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "404", "errorMessage": "Resource not found"}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.GetDataTrafficNotificationSetting(ctx, "server-id", "notification id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "404", - Message: "Resource not found", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.GetDataTrafficNotificationSetting(ctx, "server-id", "notification id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.GetDataTrafficNotificationSetting(ctx, "server-id", "notification id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedServerUpdateDataTrafficNotificationSetting(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "actions": [ - { - "lastTriggeredAt": "2021-03-16T01:01:44+00:00", - "type": "EMAIL" - } - ], - "frequency": "MONTHLY", - "id": "12345", - "lastCheckedAt": "2021-03-16T01:01:41+00:00", - "threshold": "2", - "thresholdExceededAt": "2021-03-16T01:01:41+00:00", - "unit": "GB" - }`) - }) - defer teardown() - - payload := map[string]string{"frequency": "MONTHLY", "threshold": "2", "unit": "GB"} - ctx := context.Background() - resp, err := DedicatedServerApi{}.UpdateDataTrafficNotificationSetting(ctx, "server-id", "notification id", payload) - assert := assert.New(t) - assert.Nil(err) - - assert.Equal(resp.Actions[0].LastTriggeredAt, "2021-03-16T01:01:44+00:00") - assert.Equal(resp.Actions[0].Type, "EMAIL") - assert.Equal(resp.Frequency, "MONTHLY") - assert.Equal(resp.Id, "12345") - assert.Equal(resp.LastCheckedAt, "2021-03-16T01:01:41+00:00") - assert.Equal(resp.Threshold.String(), "2") - assert.Equal(resp.ThresholdExceededAt, "2021-03-16T01:01:41+00:00") - assert.Equal(resp.Unit, "GB") -} - -func TestDedicatedServerUpdateDataTrafficNotificationSettingServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - payload := map[string]string{"frequency": "MONTHLY", "threshold": "2", "unit": "GB"} - ctx := context.Background() - return DedicatedServerApi{}.UpdateDataTrafficNotificationSetting(ctx, "server-id", "notification id", payload) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - payload := map[string]string{"frequency": "MONTHLY", "threshold": "2", "unit": "GB"} - ctx := context.Background() - return DedicatedServerApi{}.UpdateDataTrafficNotificationSetting(ctx, "server-id", "notification id", payload) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "404", "errorMessage": "Resource not found"}`) - }, - FunctionCall: func() (interface{}, error) { - payload := map[string]string{"frequency": "MONTHLY", "threshold": "2", "unit": "GB"} - ctx := context.Background() - return DedicatedServerApi{}.UpdateDataTrafficNotificationSetting(ctx, "server-id", "notification id", payload) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "404", - Message: "Resource not found", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - payload := map[string]string{"frequency": "MONTHLY", "threshold": "2", "unit": "GB"} - ctx := context.Background() - return DedicatedServerApi{}.UpdateDataTrafficNotificationSetting(ctx, "server-id", "notification id", payload) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - payload := map[string]string{"frequency": "MONTHLY", "threshold": "2", "unit": "GB"} - ctx := context.Background() - return DedicatedServerApi{}.UpdateDataTrafficNotificationSetting(ctx, "server-id", "notification id", payload) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedServerGetDdosNotificationSetting(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "nulling": "ENABLED", - "scrubbing": "DISABLED" - }`) - }) - defer teardown() - - ctx := context.Background() - resp, err := DedicatedServerApi{}.GetDdosNotificationSetting(ctx, "server-id") - assert := assert.New(t) - assert.Nil(err) - - assert.Equal(resp.Nulling, "ENABLED") - assert.Equal(resp.Scrubbing, "DISABLED") -} - -func TestDedicatedServerGetDdosNotificationSettingServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.GetDdosNotificationSetting(ctx, "server-id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.GetDdosNotificationSetting(ctx, "server-id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "404", "errorMessage": "Resource not found"}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.GetDdosNotificationSetting(ctx, "server-id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "404", - Message: "Resource not found", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.GetDdosNotificationSetting(ctx, "server-id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.GetDdosNotificationSetting(ctx, "server-id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedServerUpdateDdosNotificationSetting(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusNoContent) - }) - defer teardown() - - ctx := context.Background() - err := DedicatedServerApi{}.UpdateDdosNotificationSetting(ctx, "server id", map[string]string{"nulling": "DISABLED", "scrubbing": "ENABLED"}) - assert := assert.New(t) - assert.Nil(err) -} - -func TestDedicatedServerUpdateDdosNotificationSettingServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedServerApi{}.UpdateDdosNotificationSetting(ctx, "server id", map[string]string{"nulling": "DISABLED", "scrubbing": "ENABLED"}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedServerApi{}.UpdateDdosNotificationSetting(ctx, "server id", map[string]string{"nulling": "DISABLED", "scrubbing": "ENABLED"}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "404", "errorMessage": "Resource not found"}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedServerApi{}.UpdateDdosNotificationSetting(ctx, "server id", map[string]string{"nulling": "DISABLED", "scrubbing": "ENABLED"}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "404", - Message: "Resource not found", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedServerApi{}.UpdateDdosNotificationSetting(ctx, "server id", map[string]string{"nulling": "DISABLED", "scrubbing": "ENABLED"}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedServerApi{}.UpdateDdosNotificationSetting(ctx, "server id", map[string]string{"nulling": "DISABLED", "scrubbing": "ENABLED"}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedServerPowerCycleServer(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusNoContent) - }) - defer teardown() - - ctx := context.Background() - err := DedicatedServerApi{}.PowerCycleServer(ctx, "server id") - assert := assert.New(t) - assert.Nil(err) -} - -func TestDedicatedServerPowerCycleServerServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedServerApi{}.PowerCycleServer(ctx, "server id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedServerApi{}.PowerCycleServer(ctx, "server id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "404", "errorMessage": "Resource not found"}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedServerApi{}.PowerCycleServer(ctx, "server id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "404", - Message: "Resource not found", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedServerApi{}.PowerCycleServer(ctx, "server id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedServerApi{}.PowerCycleServer(ctx, "server id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedServerPowerOffServer(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusNoContent) - }) - defer teardown() - - ctx := context.Background() - err := DedicatedServerApi{}.PowerOffServer(ctx, "server id") - assert := assert.New(t) - assert.Nil(err) -} - -func TestDedicatedServerPowerOffServerServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedServerApi{}.PowerOffServer(ctx, "server id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedServerApi{}.PowerOffServer(ctx, "server id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "404", "errorMessage": "Resource not found"}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedServerApi{}.PowerOffServer(ctx, "server id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "404", - Message: "Resource not found", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedServerApi{}.PowerOffServer(ctx, "server id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedServerApi{}.PowerOffServer(ctx, "server id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedServerPowerOnServer(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusNoContent) - }) - defer teardown() - - ctx := context.Background() - err := DedicatedServerApi{}.PowerOnServer(ctx, "server id") - assert := assert.New(t) - assert.Nil(err) -} - -func TestDedicatedServerPowerOnServerServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedServerApi{}.PowerOnServer(ctx, "server id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedServerApi{}.PowerOnServer(ctx, "server id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "404", "errorMessage": "Resource not found"}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedServerApi{}.PowerOnServer(ctx, "server id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "404", - Message: "Resource not found", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedServerApi{}.PowerOnServer(ctx, "server id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, DedicatedServerApi{}.PowerOnServer(ctx, "server id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedServerGetPowerStatus(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "ipmi": { - "status": "off" - }, - "pdu": { - "status": "on" - } - }`) - }) - defer teardown() - - ctx := context.Background() - resp, err := DedicatedServerApi{}.GetPowerStatus(ctx, "server-id") - assert := assert.New(t) - assert.Nil(err) - - assert.Equal(resp.Ipmi.Status, "off") - assert.Equal(resp.Pdu.Status, "on") -} - -func TestDedicatedServerGetPowerStatusServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.GetPowerStatus(ctx, "server-id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.GetPowerStatus(ctx, "server-id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "404", "errorMessage": "Resource not found"}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.GetPowerStatus(ctx, "server-id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "404", - Message: "Resource not found", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.GetPowerStatus(ctx, "server-id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.GetPowerStatus(ctx, "server-id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedServerListOperatingSystems(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "_metadata": { - "limit": 10, - "offset": 0, - "totalCount": 2 - }, - "operatingSystems": [ - { - "id": "ALMALINUX_8_64BIT", - "name": "AlmaLinux 8 (x86_64)" - }, - { - "id": "CENTOS_7_64BIT", - "name": "CentOS 7 (x86_64)" - } - ] - }`) - }) - defer teardown() - - ctx := context.Background() - response, err := DedicatedServerApi{}.ListOperatingSystems(ctx, DedicatedServerListOperatingSystemsOptions{}) - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 2) - assert.Equal(response.Metadata.Offset, 0) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.OperatingSystems), 2) - - assert.Equal(response.OperatingSystems[0].Id, "ALMALINUX_8_64BIT") - assert.Equal(response.OperatingSystems[0].Name, "AlmaLinux 8 (x86_64)") - assert.Equal(response.OperatingSystems[1].Id, "CENTOS_7_64BIT") - assert.Equal(response.OperatingSystems[1].Name, "CentOS 7 (x86_64)") -} - -func TestDedicatedServerListOperatingSystemsPagination(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "_metadata": { - "limit": 10, - "offset": 1, - "totalCount": 11 - }, - "operatingSystems": [ - { - "id": "ALMALINUX_8_64BIT", - "name": "AlmaLinux 8 (x86_64)" - } - ] - }`) - }) - defer teardown() - - ctx := context.Background() - response, err := DedicatedServerApi{}.ListOperatingSystems(ctx, DedicatedServerListOperatingSystemsOptions{}) - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 11) - assert.Equal(response.Metadata.Offset, 1) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.OperatingSystems), 1) - - assert.Equal(response.OperatingSystems[0].Id, "ALMALINUX_8_64BIT") - assert.Equal(response.OperatingSystems[0].Name, "AlmaLinux 8 (x86_64)") -} - -func TestDedicatedServerListOperatingSystemsServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.ListOperatingSystems(ctx, DedicatedServerListOperatingSystemsOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "Access to the requested resource is forbidden."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.ListOperatingSystems(ctx, DedicatedServerListOperatingSystemsOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "Access to the requested resource is forbidden.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.ListOperatingSystems(ctx, DedicatedServerListOperatingSystemsOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.ListOperatingSystems(ctx, DedicatedServerListOperatingSystemsOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedServerGetOperatingSystem(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "architecture": "64bit", - "configurable": true, - "defaults": { - "device": "SATA_SAS", - "partitions": [ - { - "bootable": true, - "filesystem": "ext2", - "mountpoint": "/boot", - "primary": true, - "size": "1024" - }, - { - "filesystem": "swap", - "size": "4096" - }, - { - "filesystem": "ext4", - "mountpoint": "/tmp", - "size": "4096" - }, - { - "filesystem": "ext4", - "mountpoint": "/", - "primary": true, - "size": "*" - } - ] - }, - "family": "ubuntu", - "features": [ - "PARTITIONING", - "SW_RAID", - "TIMEZONE", - "HOSTNAME", - "SSH_KEYS", - "POST_INSTALL_SCRIPTS" - ], - "id": "UBUNTU_20_04_64BIT", - "name": "Ubuntu 20.04 LTS (Focal Fossa) (amd64)", - "supportedBootDevices": [ - "SATA_SAS", - "NVME" - ], - "supportedFileSystems": [ - "ext2", - "ext3", - "ext4", - "xfs", - "swap" - ], - "type": "linux", - "version": "20.04" - }`) - }) - defer teardown() - - ctx := context.Background() - OperatingSystem, err := DedicatedServerApi{}.GetOperatingSystem(ctx, "UBUNTU_20_04_64BIT", "controll panel id") - assert := assert.New(t) - assert.Nil(err) - - assert.Equal(OperatingSystem.Architecture, "64bit") - assert.Equal(OperatingSystem.Configurable, true) - assert.Equal(OperatingSystem.Defaults.Device, "SATA_SAS") - - assert.Equal(OperatingSystem.Defaults.Partitions[0].Bootable, true) - assert.Equal(OperatingSystem.Defaults.Partitions[0].Filesystem, "ext2") - assert.Equal(OperatingSystem.Defaults.Partitions[0].Mountpoint, "/boot") - assert.Equal(OperatingSystem.Defaults.Partitions[0].Primary, true) - assert.Equal(OperatingSystem.Defaults.Partitions[0].Size, "1024") - assert.Equal(OperatingSystem.Defaults.Partitions[1].Filesystem, "swap") - assert.Equal(OperatingSystem.Defaults.Partitions[1].Size, "4096") - assert.Equal(OperatingSystem.Defaults.Partitions[2].Filesystem, "ext4") - assert.Equal(OperatingSystem.Defaults.Partitions[2].Mountpoint, "/tmp") - assert.Equal(OperatingSystem.Defaults.Partitions[2].Size, "4096") - assert.Equal(OperatingSystem.Defaults.Partitions[3].Filesystem, "ext4") - assert.Equal(OperatingSystem.Defaults.Partitions[3].Mountpoint, "/") - assert.Equal(OperatingSystem.Defaults.Partitions[3].Primary, true) - assert.Equal(OperatingSystem.Defaults.Partitions[3].Size, "*") - assert.Equal(OperatingSystem.Family, "ubuntu") - assert.Equal(OperatingSystem.Features[0], "PARTITIONING") - assert.Equal(OperatingSystem.Features[1], "SW_RAID") - assert.Equal(OperatingSystem.Features[2], "TIMEZONE") - assert.Equal(OperatingSystem.Features[3], "HOSTNAME") - assert.Equal(OperatingSystem.Features[4], "SSH_KEYS") - assert.Equal(OperatingSystem.Features[5], "POST_INSTALL_SCRIPTS") - assert.Equal(OperatingSystem.Id, "UBUNTU_20_04_64BIT") - assert.Equal(OperatingSystem.Name, "Ubuntu 20.04 LTS (Focal Fossa) (amd64)") - assert.Equal(OperatingSystem.SupportedBootDevices[0], "SATA_SAS") - assert.Equal(OperatingSystem.SupportedBootDevices[1], "NVME") - assert.Equal(OperatingSystem.SupportedFileSystems[0], "ext2") - assert.Equal(OperatingSystem.SupportedFileSystems[1], "ext3") - assert.Equal(OperatingSystem.SupportedFileSystems[2], "ext4") - assert.Equal(OperatingSystem.SupportedFileSystems[3], "xfs") - assert.Equal(OperatingSystem.SupportedFileSystems[4], "swap") - assert.Equal(OperatingSystem.Type, "linux") - assert.Equal(OperatingSystem.Version, "20.04") -} - -func TestDedicatedServerGetOperatingSystemServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.GetOperatingSystem(ctx, "UBUNTU_20_04_64BIT", "controll panel id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "Access to the requested resource is forbidden."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.GetOperatingSystem(ctx, "UBUNTU_20_04_64BIT", "controll panel id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "Access to the requested resource is forbidden.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.GetOperatingSystem(ctx, "UBUNTU_20_04_64BIT", "controll panel id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.GetOperatingSystem(ctx, "UBUNTU_20_04_64BIT", "controll panel id") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedServerListControlPanels(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "_metadata": { - "limit": 10, - "offset": 0, - "totalCount": 2 - }, - "controlPanels": [ - { - "id": "CPANEL_PREMIER_100", - "name": "cPanel Premier 100" - }, - { - "id": "CPANEL_PREMIER_150", - "name": "cPanel Premier 150" - } - ] - }`) - }) - defer teardown() - - ctx := context.Background() - response, err := DedicatedServerApi{}.ListControlPanels(ctx, DedicatedServerListControlPanelsOptions{}) - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 2) - assert.Equal(response.Metadata.Offset, 0) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.ControlPanels), 2) - - assert.Equal(response.ControlPanels[0].Id, "CPANEL_PREMIER_100") - assert.Equal(response.ControlPanels[0].Name, "cPanel Premier 100") - assert.Equal(response.ControlPanels[1].Id, "CPANEL_PREMIER_150") - assert.Equal(response.ControlPanels[1].Name, "cPanel Premier 150") -} - -func TestDedicatedServerListControlPanelsPagination(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "_metadata": { - "limit": 10, - "offset": 1, - "totalCount": 11 - }, - "controlPanels": [ - { - "id": "CPANEL_PREMIER_100", - "name": "cPanel Premier 100" - } - ] - }`) - }) - defer teardown() - - ctx := context.Background() - opts := DedicatedServerListControlPanelsOptions{ - PaginationOptions: PaginationOptions{ - Limit: Int(10), - }, - } - response, err := DedicatedServerApi{}.ListControlPanels(ctx, opts) - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 11) - assert.Equal(response.Metadata.Offset, 1) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.ControlPanels), 1) - - assert.Equal(response.ControlPanels[0].Id, "CPANEL_PREMIER_100") - assert.Equal(response.ControlPanels[0].Name, "cPanel Premier 100") -} - -func TestDedicatedServerListControlPanelsServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.ListControlPanels(ctx, DedicatedServerListControlPanelsOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "Access to the requested resource is forbidden."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.ListControlPanels(ctx, DedicatedServerListControlPanelsOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "Access to the requested resource is forbidden.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.ListControlPanels(ctx, DedicatedServerListControlPanelsOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.ListControlPanels(ctx, DedicatedServerListControlPanelsOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestDedicatedServerListRescueImages(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "_metadata": { - "limit": 10, - "offset": 0, - "totalCount": 2 - }, - "rescueImages": [ - { - "id": "GRML", - "name": "GRML Linux Rescue Image (amd64)" - }, - { - "id": "CENTOS_7", - "name": "CentOS 7 Linux Rescue Image (amd64)" - } - ] - }`) - }) - defer teardown() - - ctx := context.Background() - response, err := DedicatedServerApi{}.ListRescueImages(ctx, PaginationOptions{}) - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 2) - assert.Equal(response.Metadata.Offset, 0) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.RescueImages), 2) - - assert.Equal(response.RescueImages[0].Id, "GRML") - assert.Equal(response.RescueImages[0].Name, "GRML Linux Rescue Image (amd64)") - assert.Equal(response.RescueImages[1].Id, "CENTOS_7") - assert.Equal(response.RescueImages[1].Name, "CentOS 7 Linux Rescue Image (amd64)") -} - -func TestDedicatedServerListRescueImagesPagination(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "_metadata": { - "limit": 10, - "offset": 1, - "totalCount": 11 - }, - "rescueImages": [ - { - "id": "GRML", - "name": "GRML Linux Rescue Image (amd64)" - } - ] - }`) - }) - defer teardown() - - ctx := context.Background() - opts := PaginationOptions{ - Limit: Int(1), - } - response, err := DedicatedServerApi{}.ListRescueImages(ctx, opts) - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 11) - assert.Equal(response.Metadata.Offset, 1) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.RescueImages), 1) - - assert.Equal(response.RescueImages[0].Id, "GRML") - assert.Equal(response.RescueImages[0].Name, "GRML Linux Rescue Image (amd64)") -} - -func TestDedicatedServerListRescueImagesServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.ListRescueImages(ctx, PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "Access to the requested resource is forbidden."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.ListRescueImages(ctx, PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "Access to the requested resource is forbidden.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.ListRescueImages(ctx, PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return DedicatedServerApi{}.ListRescueImages(ctx, PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} diff --git a/dedicatedserver/README.md b/dedicatedserver/README.md new file mode 100644 index 0000000..7f5af11 --- /dev/null +++ b/dedicatedserver/README.md @@ -0,0 +1,218 @@ +# Go API client for dedicatedserver + +This documents the rest api dedicatedserver provides. + +## Overview +This API client was generated by the [OpenAPI Generator](https://openapi-generator.tech) project. By using the [OpenAPI-spec](https://www.openapis.org/) from a remote server, you can easily generate an API client. + +- API version: v2 +- Package version: 1.0.0 +- Generator version: 7.4.0 +- Build package: org.openapitools.codegen.languages.GoClientCodegen + +## Installation + +Install the following dependencies: + +```sh +go get github.com/stretchr/testify/assert +go get golang.org/x/oauth2 +go get golang.org/x/net/context +``` + +Put the package under your project folder and add the following in import: + +```go +import dedicatedserver "github.com/leaseweb/leaseweb-go-sdk/dedicatedserver" +``` + +To use a proxy, set the environment variable `HTTP_PROXY`: + +```go +os.Setenv("HTTP_PROXY", "http://proxy_name:proxy_port") +``` + +## Configuration of Server URL + +Default configuration comes with `Servers` field that contains server objects as defined in the OpenAPI specification. + +### Select Server Configuration + +For using other server than the one defined on index 0 set context value `dedicatedserver.ContextServerIndex` of type `int`. + +```go +ctx := context.WithValue(context.Background(), dedicatedserver.ContextServerIndex, 1) +``` + +### Templated Server URL + +Templated server URL is formatted using default variables from configuration or from context value `dedicatedserver.ContextServerVariables` of type `map[string]string`. + +```go +ctx := context.WithValue(context.Background(), dedicatedserver.ContextServerVariables, map[string]string{ + "basePath": "v2", +}) +``` + +Note, enum values are always validated and all unused variables are silently ignored. + +### URLs Configuration per Operation + +Each operation can use different server URL defined using `OperationServers` map in the `Configuration`. +An operation is uniquely identified by `"{classname}Service.{nickname}"` string. +Similar rules for overriding default operation server index and variables applies by using `dedicatedserver.ContextOperationServerIndices` and `dedicatedserver.ContextOperationServerVariables` context maps. + +```go +ctx := context.WithValue(context.Background(), dedicatedserver.ContextOperationServerIndices, map[string]int{ + "{classname}Service.{nickname}": 2, +}) +ctx = context.WithValue(context.Background(), dedicatedserver.ContextOperationServerVariables, map[string]map[string]string{ + "{classname}Service.{nickname}": { + "port": "8443", + }, +}) +``` + +## Documentation for API Endpoints + +All URIs are relative to *https://api.leaseweb.com/internal/dedicatedserverapi/v2* + +Class | Method | HTTP request | Description +------------ | ------------- | ------------- | ------------- +*DedicatedserverAPI* | [**AddServerToPrivateNetwork**](docs/DedicatedserverAPI.md#addservertoprivatenetwork) | **Put** /servers/{serverId}/privateNetworks/{privateNetworkId} | Add a server to private network +*DedicatedserverAPI* | [**DeleteServerFromPrivateNetwork**](docs/DedicatedserverAPI.md#deleteserverfromprivatenetwork) | **Delete** /servers/{serverId}/privateNetworks/{privateNetworkId} | Delete a server from a private network +*DedicatedserverAPI* | [**GetNetworkEquipment**](docs/DedicatedserverAPI.md#getnetworkequipment) | **Get** /networkEquipments/{networkEquipmentId} | Get network equipment +*DedicatedserverAPI* | [**GetNetworkEquipmentIp**](docs/DedicatedserverAPI.md#getnetworkequipmentip) | **Get** /networkEquipments/{networkEquipmentId}/ips/{ip} | Show an IP +*DedicatedserverAPI* | [**GetNetworkEquipmentIpList**](docs/DedicatedserverAPI.md#getnetworkequipmentiplist) | **Get** /networkEquipments/{networkEquipmentId}/ips | List IPs +*DedicatedserverAPI* | [**GetNetworkEquipmentList**](docs/DedicatedserverAPI.md#getnetworkequipmentlist) | **Get** /networkEquipments | List network equipment +*DedicatedserverAPI* | [**GetNetworkEquipmentNullRouteHistory**](docs/DedicatedserverAPI.md#getnetworkequipmentnullroutehistory) | **Get** /networkEquipments/{networkEquipmentId}/nullRouteHistory | Show null route history +*DedicatedserverAPI* | [**GetServer**](docs/DedicatedserverAPI.md#getserver) | **Get** /servers/{serverId} | Get server +*DedicatedserverAPI* | [**GetServerIp**](docs/DedicatedserverAPI.md#getserverip) | **Get** /servers/{serverId}/ips/{ip} | Show an IP +*DedicatedserverAPI* | [**GetServerIpList**](docs/DedicatedserverAPI.md#getserveriplist) | **Get** /servers/{serverId}/ips | List IPs +*DedicatedserverAPI* | [**GetServerList**](docs/DedicatedserverAPI.md#getserverlist) | **Get** /servers | List servers +*DedicatedserverAPI* | [**GetServerNullRouteHistory**](docs/DedicatedserverAPI.md#getservernullroutehistory) | **Get** /servers/{serverId}/nullRouteHistory | Show null route history +*DedicatedserverAPI* | [**NetworkEquipmentsIpsNull**](docs/DedicatedserverAPI.md#networkequipmentsipsnull) | **Post** /networkEquipments/{networkEquipmentId}/ips/{ip}/null | Null route an IP +*DedicatedserverAPI* | [**NullIpRoute**](docs/DedicatedserverAPI.md#nulliproute) | **Post** /servers/{serverId}/ips/{ip}/null | Null route an IP +*DedicatedserverAPI* | [**PutServerIp**](docs/DedicatedserverAPI.md#putserverip) | **Put** /servers/{serverId}/ips/{ip} | Update an IP +*DedicatedserverAPI* | [**RemoveNullIpRoute**](docs/DedicatedserverAPI.md#removenulliproute) | **Post** /servers/{serverId}/ips/{ip}/unnull | Remove a null route +*DedicatedserverAPI* | [**UnNullNetworkEquipmentIpRoute**](docs/DedicatedserverAPI.md#unnullnetworkequipmentiproute) | **Post** /networkEquipments/{networkEquipmentId}/ips/{ip}/unnull | Remove a null route +*DedicatedserverAPI* | [**UpdateNetworkEquipmentIp**](docs/DedicatedserverAPI.md#updatenetworkequipmentip) | **Put** /networkEquipments/{networkEquipmentId}/ips/{ip} | Update an IP +*DedicatedserverAPI* | [**UpdateNetworkEquipmentReference**](docs/DedicatedserverAPI.md#updatenetworkequipmentreference) | **Put** /networkEquipments/{networkEquipmentId} | Update network equipment +*DedicatedserverAPI* | [**UpdateServerReference**](docs/DedicatedserverAPI.md#updateserverreference) | **Put** /servers/{serverId} | Update server + + +## Documentation For Models + + - [AddServerToPrivateNetworkOpts](docs/AddServerToPrivateNetworkOpts.md) + - [Cpu](docs/Cpu.md) + - [DDos](docs/DDos.md) + - [ErrorResult](docs/ErrorResult.md) + - [GetNetworkEquipmentIpListResult](docs/GetNetworkEquipmentIpListResult.md) + - [GetNetworkEquipmentListResult](docs/GetNetworkEquipmentListResult.md) + - [GetNetworkEquipmentNullRouteHistoryResult](docs/GetNetworkEquipmentNullRouteHistoryResult.md) + - [GetServerListResult](docs/GetServerListResult.md) + - [GetServerNullRouteHistoryResult](docs/GetServerNullRouteHistoryResult.md) + - [Hdd](docs/Hdd.md) + - [Ip](docs/Ip.md) + - [LinkSpeed](docs/LinkSpeed.md) + - [Metadata](docs/Metadata.md) + - [NetworkEquipment](docs/NetworkEquipment.md) + - [NetworkEquipmentSpecs](docs/NetworkEquipmentSpecs.md) + - [NullRoute](docs/NullRoute.md) + - [PciCard](docs/PciCard.md) + - [Powerport](docs/Powerport.md) + - [PrivateNetwork](docs/PrivateNetwork.md) + - [Rack](docs/Rack.md) + - [Ram](docs/Ram.md) + - [Server](docs/Server.md) + - [ServerSpecs](docs/ServerSpecs.md) + - [UpdateIpProfileOpts](docs/UpdateIpProfileOpts.md) + - [UpdateNetworkEquipmentIpOpts](docs/UpdateNetworkEquipmentIpOpts.md) + - [UpdateNetworkEquipmentReferenceOpts](docs/UpdateNetworkEquipmentReferenceOpts.md) + - [UpdateServerReferenceOpts](docs/UpdateServerReferenceOpts.md) + + +## Documentation For Authorization + + +Authentication schemes defined for the API: +### ApiKeyAuth + +- **Type**: API key +- **API key parameter name**: X-LSW-Auth +- **Location**: HTTP header + +Note, each API key must be added to a map of `map[string]APIKey` where the key is: X-LSW-Auth and passed in as the auth context for each request. + +Example + +```go +auth := context.WithValue( + context.Background(), + dedicatedserver.ContextAPIKeys, + map[string]dedicatedserver.APIKey{ + "X-LSW-Auth": {Key: "API_KEY_STRING"}, + }, + ) +r, err := client.Service.Operation(auth, args) +``` + +### OAuth2 + + +- **Type**: OAuth +- **Flow**: application +- **Authorization URL**: +- **Scopes**: N/A + +Example + +```go +auth := context.WithValue(context.Background(), dedicatedserver.ContextAccessToken, "ACCESSTOKENSTRING") +r, err := client.Service.Operation(auth, args) +``` + +Or via OAuth2 module to automatically refresh tokens and perform user authentication. + +```go +import "golang.org/x/oauth2" + +/* Perform OAuth2 round trip request and obtain a token */ + +tokenSource := oauth2cfg.TokenSource(createContext(httpClient), &token) +auth := context.WithValue(oauth2.NoContext, dedicatedserver.ContextOAuth2, tokenSource) +r, err := client.Service.Operation(auth, args) +``` + +### BearerAuth + +- **Type**: HTTP Bearer token authentication + +Example + +```go +auth := context.WithValue(context.Background(), dedicatedserver.ContextAccessToken, "BEARER_TOKEN_STRING") +r, err := client.Service.Operation(auth, args) +``` + + +## Documentation for Utility Methods + +Due to the fact that model structure members are all pointers, this package contains +a number of utility functions to easily obtain pointers to values of basic types. +Each of these functions takes a value of the given basic type and returns a pointer to it: + +* `PtrBool` +* `PtrInt` +* `PtrInt32` +* `PtrInt64` +* `PtrFloat` +* `PtrFloat32` +* `PtrFloat64` +* `PtrString` +* `PtrTime` + +## Author + +development-networkautomation@leaseweb.com + diff --git a/dedicatedserver/api_dedicatedserver.go b/dedicatedserver/api_dedicatedserver.go new file mode 100644 index 0000000..4797623 --- /dev/null +++ b/dedicatedserver/api_dedicatedserver.go @@ -0,0 +1,3935 @@ +/* +Leaseweb API for dedicated servers + +This documents the rest api dedicatedserver provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package dedicatedserver + +import ( + "bytes" + "context" + "io" + "net/http" + "net/url" + "strings" +) + + +// DedicatedserverAPIService DedicatedserverAPI service +type DedicatedserverAPIService service + +type ApiAddServerToPrivateNetworkRequest struct { + ctx context.Context + ApiService *DedicatedserverAPIService + serverId string + privateNetworkId string + addServerToPrivateNetworkOpts *AddServerToPrivateNetworkOpts +} + +func (r ApiAddServerToPrivateNetworkRequest) AddServerToPrivateNetworkOpts(addServerToPrivateNetworkOpts AddServerToPrivateNetworkOpts) ApiAddServerToPrivateNetworkRequest { + r.addServerToPrivateNetworkOpts = &addServerToPrivateNetworkOpts + return r +} + +func (r ApiAddServerToPrivateNetworkRequest) Execute() (*http.Response, error) { + return r.ApiService.AddServerToPrivateNetworkExecute(r) +} + +/* +AddServerToPrivateNetwork Add a server to private network + +It takes a few minutes before the server has access to the private network. + +To get the current status of the server you can call +`/bareMetals/v2/servers/{serverId}`. + +Once the server is added to the private network the status changes from +`CONFIGURING` to `CONFIGURED`. + + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param serverId The ID of a server + @param privateNetworkId The ID of a Private Network + @return ApiAddServerToPrivateNetworkRequest +*/ +func (a *DedicatedserverAPIService) AddServerToPrivateNetwork(ctx context.Context, serverId string, privateNetworkId string) ApiAddServerToPrivateNetworkRequest { + return ApiAddServerToPrivateNetworkRequest{ + ApiService: a, + ctx: ctx, + serverId: serverId, + privateNetworkId: privateNetworkId, + } +} + +// Execute executes the request +func (a *DedicatedserverAPIService) AddServerToPrivateNetworkExecute(r ApiAddServerToPrivateNetworkRequest) (*http.Response, error) { + var ( + localVarHTTPMethod = http.MethodPut + localVarPostBody interface{} + formFiles []formFile + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "DedicatedserverAPIService.AddServerToPrivateNetwork") + if err != nil { + return nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/servers/{serverId}/privateNetworks/{privateNetworkId}" + localVarPath = strings.Replace(localVarPath, "{"+"serverId"+"}", url.PathEscape(parameterValueToString(r.serverId, "serverId")), -1) + localVarPath = strings.Replace(localVarPath, "{"+"privateNetworkId"+"}", url.PathEscape(parameterValueToString(r.privateNetworkId, "privateNetworkId")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{"application/json"} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + // body params + localVarPostBody = r.addServerToPrivateNetworkOpts + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 404 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarHTTPResponse, newErr + } + + return localVarHTTPResponse, nil +} + +type ApiDeleteServerFromPrivateNetworkRequest struct { + ctx context.Context + ApiService *DedicatedserverAPIService + serverId string + privateNetworkId string +} + +func (r ApiDeleteServerFromPrivateNetworkRequest) Execute() (*http.Response, error) { + return r.ApiService.DeleteServerFromPrivateNetworkExecute(r) +} + +/* +DeleteServerFromPrivateNetwork Delete a server from a private network + +This API call will remove the dedicated server from the private network. + +It takes a few minutes before the server has been removed from the private +network. + +To get the current status of the server you can call +`/bareMetals/v2/servers/{serverId}`. + +While the server is being removed the status changes to `REMOVING`. + + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param serverId The ID of a server + @param privateNetworkId The ID of a Private Network + @return ApiDeleteServerFromPrivateNetworkRequest +*/ +func (a *DedicatedserverAPIService) DeleteServerFromPrivateNetwork(ctx context.Context, serverId string, privateNetworkId string) ApiDeleteServerFromPrivateNetworkRequest { + return ApiDeleteServerFromPrivateNetworkRequest{ + ApiService: a, + ctx: ctx, + serverId: serverId, + privateNetworkId: privateNetworkId, + } +} + +// Execute executes the request +func (a *DedicatedserverAPIService) DeleteServerFromPrivateNetworkExecute(r ApiDeleteServerFromPrivateNetworkRequest) (*http.Response, error) { + var ( + localVarHTTPMethod = http.MethodDelete + localVarPostBody interface{} + formFiles []formFile + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "DedicatedserverAPIService.DeleteServerFromPrivateNetwork") + if err != nil { + return nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/servers/{serverId}/privateNetworks/{privateNetworkId}" + localVarPath = strings.Replace(localVarPath, "{"+"serverId"+"}", url.PathEscape(parameterValueToString(r.serverId, "serverId")), -1) + localVarPath = strings.Replace(localVarPath, "{"+"privateNetworkId"+"}", url.PathEscape(parameterValueToString(r.privateNetworkId, "privateNetworkId")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 404 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarHTTPResponse, newErr + } + + return localVarHTTPResponse, nil +} + +type ApiGetNetworkEquipmentRequest struct { + ctx context.Context + ApiService *DedicatedserverAPIService + networkEquipmentId string +} + +func (r ApiGetNetworkEquipmentRequest) Execute() (*NetworkEquipment, *http.Response, error) { + return r.ApiService.GetNetworkEquipmentExecute(r) +} + +/* +GetNetworkEquipment Get network equipment + +Use this API to get information about a single network equipment. + + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param networkEquipmentId The ID of a dedicated network equipment + @return ApiGetNetworkEquipmentRequest +*/ +func (a *DedicatedserverAPIService) GetNetworkEquipment(ctx context.Context, networkEquipmentId string) ApiGetNetworkEquipmentRequest { + return ApiGetNetworkEquipmentRequest{ + ApiService: a, + ctx: ctx, + networkEquipmentId: networkEquipmentId, + } +} + +// Execute executes the request +// @return NetworkEquipment +func (a *DedicatedserverAPIService) GetNetworkEquipmentExecute(r ApiGetNetworkEquipmentRequest) (*NetworkEquipment, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodGet + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *NetworkEquipment + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "DedicatedserverAPIService.GetNetworkEquipment") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/networkEquipments/{networkEquipmentId}" + localVarPath = strings.Replace(localVarPath, "{"+"networkEquipmentId"+"}", url.PathEscape(parameterValueToString(r.networkEquipmentId, "networkEquipmentId")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 404 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiGetNetworkEquipmentIpRequest struct { + ctx context.Context + ApiService *DedicatedserverAPIService + networkEquipmentId string + ip string +} + +func (r ApiGetNetworkEquipmentIpRequest) Execute() (*Ip, *http.Response, error) { + return r.ApiService.GetNetworkEquipmentIpExecute(r) +} + +/* +GetNetworkEquipmentIp Show an IP + +Get a single IP address associated with this network equipment. + + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param networkEquipmentId The ID of a dedicated network equipment + @param ip The IP Address + @return ApiGetNetworkEquipmentIpRequest +*/ +func (a *DedicatedserverAPIService) GetNetworkEquipmentIp(ctx context.Context, networkEquipmentId string, ip string) ApiGetNetworkEquipmentIpRequest { + return ApiGetNetworkEquipmentIpRequest{ + ApiService: a, + ctx: ctx, + networkEquipmentId: networkEquipmentId, + ip: ip, + } +} + +// Execute executes the request +// @return Ip +func (a *DedicatedserverAPIService) GetNetworkEquipmentIpExecute(r ApiGetNetworkEquipmentIpRequest) (*Ip, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodGet + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *Ip + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "DedicatedserverAPIService.GetNetworkEquipmentIp") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/networkEquipments/{networkEquipmentId}/ips/{ip}" + localVarPath = strings.Replace(localVarPath, "{"+"networkEquipmentId"+"}", url.PathEscape(parameterValueToString(r.networkEquipmentId, "networkEquipmentId")), -1) + localVarPath = strings.Replace(localVarPath, "{"+"ip"+"}", url.PathEscape(parameterValueToString(r.ip, "ip")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiGetNetworkEquipmentIpListRequest struct { + ctx context.Context + ApiService *DedicatedserverAPIService + networkEquipmentId string + networkType *string + version *string + nullRouted *string + ips *string + limit *int32 + offset *int32 +} + +// Filter the collection of ip addresses by network type +func (r ApiGetNetworkEquipmentIpListRequest) NetworkType(networkType string) ApiGetNetworkEquipmentIpListRequest { + r.networkType = &networkType + return r +} + +// Filter the collection by ip version +func (r ApiGetNetworkEquipmentIpListRequest) Version(version string) ApiGetNetworkEquipmentIpListRequest { + r.version = &version + return r +} + +// Filter Ips by Nulled-Status +func (r ApiGetNetworkEquipmentIpListRequest) NullRouted(nullRouted string) ApiGetNetworkEquipmentIpListRequest { + r.nullRouted = &nullRouted + return r +} + +// Filter the collection of Ips for the comma separated list of Ips +func (r ApiGetNetworkEquipmentIpListRequest) Ips(ips string) ApiGetNetworkEquipmentIpListRequest { + r.ips = &ips + return r +} + +// Limit the number of results returned. +func (r ApiGetNetworkEquipmentIpListRequest) Limit(limit int32) ApiGetNetworkEquipmentIpListRequest { + r.limit = &limit + return r +} + +// Return results starting from the given offset. +func (r ApiGetNetworkEquipmentIpListRequest) Offset(offset int32) ApiGetNetworkEquipmentIpListRequest { + r.offset = &offset + return r +} + +func (r ApiGetNetworkEquipmentIpListRequest) Execute() (*GetNetworkEquipmentIpListResult, *http.Response, error) { + return r.ApiService.GetNetworkEquipmentIpListExecute(r) +} + +/* +GetNetworkEquipmentIpList List IPs + +List all IP Addresses associated with this network equipment. Optionally +filtered. + + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param networkEquipmentId The ID of a dedicated network equipment + @return ApiGetNetworkEquipmentIpListRequest +*/ +func (a *DedicatedserverAPIService) GetNetworkEquipmentIpList(ctx context.Context, networkEquipmentId string) ApiGetNetworkEquipmentIpListRequest { + return ApiGetNetworkEquipmentIpListRequest{ + ApiService: a, + ctx: ctx, + networkEquipmentId: networkEquipmentId, + } +} + +// Execute executes the request +// @return GetNetworkEquipmentIpListResult +func (a *DedicatedserverAPIService) GetNetworkEquipmentIpListExecute(r ApiGetNetworkEquipmentIpListRequest) (*GetNetworkEquipmentIpListResult, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodGet + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *GetNetworkEquipmentIpListResult + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "DedicatedserverAPIService.GetNetworkEquipmentIpList") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/networkEquipments/{networkEquipmentId}/ips" + localVarPath = strings.Replace(localVarPath, "{"+"networkEquipmentId"+"}", url.PathEscape(parameterValueToString(r.networkEquipmentId, "networkEquipmentId")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + if r.networkType != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "networkType", r.networkType, "") + } + if r.version != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "version", r.version, "") + } + if r.nullRouted != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "nullRouted", r.nullRouted, "") + } + if r.ips != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "ips", r.ips, "") + } + if r.limit != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "limit", r.limit, "") + } + if r.offset != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "offset", r.offset, "") + } + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiGetNetworkEquipmentListRequest struct { + ctx context.Context + ApiService *DedicatedserverAPIService + limit *int32 + offset *int32 + reference *string + ip *string + macAddress *string + site *string + privateRackId *string + privateNetworkCapable *string + privateNetworkEnabled *string +} + +// Limit the number of results returned. +func (r ApiGetNetworkEquipmentListRequest) Limit(limit int32) ApiGetNetworkEquipmentListRequest { + r.limit = &limit + return r +} + +// Return results starting from the given offset. +func (r ApiGetNetworkEquipmentListRequest) Offset(offset int32) ApiGetNetworkEquipmentListRequest { + r.offset = &offset + return r +} + +// Filter the list of network equipment by reference. +func (r ApiGetNetworkEquipmentListRequest) Reference(reference string) ApiGetNetworkEquipmentListRequest { + r.reference = &reference + return r +} + +// Filter the list of network equipment by ip address. +func (r ApiGetNetworkEquipmentListRequest) Ip(ip string) ApiGetNetworkEquipmentListRequest { + r.ip = &ip + return r +} + +// Filter the list of network equipment by mac address. +func (r ApiGetNetworkEquipmentListRequest) MacAddress(macAddress string) ApiGetNetworkEquipmentListRequest { + r.macAddress = &macAddress + return r +} + +// Filter the list of network equipment by site (location). +func (r ApiGetNetworkEquipmentListRequest) Site(site string) ApiGetNetworkEquipmentListRequest { + r.site = &site + return r +} + +// Filter the list of network equipment by dedicated rack id. +func (r ApiGetNetworkEquipmentListRequest) PrivateRackId(privateRackId string) ApiGetNetworkEquipmentListRequest { + r.privateRackId = &privateRackId + return r +} + +// Filter the list for private network capable network equipment +func (r ApiGetNetworkEquipmentListRequest) PrivateNetworkCapable(privateNetworkCapable string) ApiGetNetworkEquipmentListRequest { + r.privateNetworkCapable = &privateNetworkCapable + return r +} + +// Filter the list for private network enabled network equipment +func (r ApiGetNetworkEquipmentListRequest) PrivateNetworkEnabled(privateNetworkEnabled string) ApiGetNetworkEquipmentListRequest { + r.privateNetworkEnabled = &privateNetworkEnabled + return r +} + +func (r ApiGetNetworkEquipmentListRequest) Execute() (*GetNetworkEquipmentListResult, *http.Response, error) { + return r.ApiService.GetNetworkEquipmentListExecute(r) +} + +/* +GetNetworkEquipmentList List network equipment + +List your Dedicated Network Equipment. This api call supports pagination. Use +the `limit` and `offset` query string parameters to paginate through all your +dedicated network equipment. + +Every `network equipment` object in the json response lists a few properties +of a network equipment. Use the single resource api call to get more details +for a single network equipment. + + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @return ApiGetNetworkEquipmentListRequest +*/ +func (a *DedicatedserverAPIService) GetNetworkEquipmentList(ctx context.Context) ApiGetNetworkEquipmentListRequest { + return ApiGetNetworkEquipmentListRequest{ + ApiService: a, + ctx: ctx, + } +} + +// Execute executes the request +// @return GetNetworkEquipmentListResult +func (a *DedicatedserverAPIService) GetNetworkEquipmentListExecute(r ApiGetNetworkEquipmentListRequest) (*GetNetworkEquipmentListResult, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodGet + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *GetNetworkEquipmentListResult + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "DedicatedserverAPIService.GetNetworkEquipmentList") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/networkEquipments" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + if r.limit != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "limit", r.limit, "") + } + if r.offset != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "offset", r.offset, "") + } + if r.reference != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "reference", r.reference, "") + } + if r.ip != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "ip", r.ip, "") + } + if r.macAddress != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "macAddress", r.macAddress, "") + } + if r.site != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "site", r.site, "") + } + if r.privateRackId != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "privateRackId", r.privateRackId, "") + } + if r.privateNetworkCapable != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "privateNetworkCapable", r.privateNetworkCapable, "") + } + if r.privateNetworkEnabled != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "privateNetworkEnabled", r.privateNetworkEnabled, "") + } + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiGetNetworkEquipmentNullRouteHistoryRequest struct { + ctx context.Context + ApiService *DedicatedserverAPIService + networkEquipmentId string + limit *int32 + offset *int32 +} + +// Limit the number of results returned. +func (r ApiGetNetworkEquipmentNullRouteHistoryRequest) Limit(limit int32) ApiGetNetworkEquipmentNullRouteHistoryRequest { + r.limit = &limit + return r +} + +// Return results starting from the given offset. +func (r ApiGetNetworkEquipmentNullRouteHistoryRequest) Offset(offset int32) ApiGetNetworkEquipmentNullRouteHistoryRequest { + r.offset = &offset + return r +} + +func (r ApiGetNetworkEquipmentNullRouteHistoryRequest) Execute() (*GetNetworkEquipmentNullRouteHistoryResult, *http.Response, error) { + return r.ApiService.GetNetworkEquipmentNullRouteHistoryExecute(r) +} + +/* +GetNetworkEquipmentNullRouteHistory Show null route history + +Show all null route history for any ips associated with this a network +equipment. + + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param networkEquipmentId The ID of a dedicated network equipment + @return ApiGetNetworkEquipmentNullRouteHistoryRequest +*/ +func (a *DedicatedserverAPIService) GetNetworkEquipmentNullRouteHistory(ctx context.Context, networkEquipmentId string) ApiGetNetworkEquipmentNullRouteHistoryRequest { + return ApiGetNetworkEquipmentNullRouteHistoryRequest{ + ApiService: a, + ctx: ctx, + networkEquipmentId: networkEquipmentId, + } +} + +// Execute executes the request +// @return GetNetworkEquipmentNullRouteHistoryResult +func (a *DedicatedserverAPIService) GetNetworkEquipmentNullRouteHistoryExecute(r ApiGetNetworkEquipmentNullRouteHistoryRequest) (*GetNetworkEquipmentNullRouteHistoryResult, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodGet + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *GetNetworkEquipmentNullRouteHistoryResult + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "DedicatedserverAPIService.GetNetworkEquipmentNullRouteHistory") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/networkEquipments/{networkEquipmentId}/nullRouteHistory" + localVarPath = strings.Replace(localVarPath, "{"+"networkEquipmentId"+"}", url.PathEscape(parameterValueToString(r.networkEquipmentId, "networkEquipmentId")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + if r.limit != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "limit", r.limit, "") + } + if r.offset != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "offset", r.offset, "") + } + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiGetServerRequest struct { + ctx context.Context + ApiService *DedicatedserverAPIService + serverId string +} + +func (r ApiGetServerRequest) Execute() (*Server, *http.Response, error) { + return r.ApiService.GetServerExecute(r) +} + +/* +GetServer Get server + +Use this API to get information about a single server. + + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param serverId The ID of a server + @return ApiGetServerRequest +*/ +func (a *DedicatedserverAPIService) GetServer(ctx context.Context, serverId string) ApiGetServerRequest { + return ApiGetServerRequest{ + ApiService: a, + ctx: ctx, + serverId: serverId, + } +} + +// Execute executes the request +// @return Server +func (a *DedicatedserverAPIService) GetServerExecute(r ApiGetServerRequest) (*Server, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodGet + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *Server + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "DedicatedserverAPIService.GetServer") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/servers/{serverId}" + localVarPath = strings.Replace(localVarPath, "{"+"serverId"+"}", url.PathEscape(parameterValueToString(r.serverId, "serverId")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 404 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiGetServerIpRequest struct { + ctx context.Context + ApiService *DedicatedserverAPIService + serverId string + ip string +} + +func (r ApiGetServerIpRequest) Execute() (*Ip, *http.Response, error) { + return r.ApiService.GetServerIpExecute(r) +} + +/* +GetServerIp Show an IP + +Get a single IP address associated with this server. + + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param serverId The ID of a server + @param ip The IP Address + @return ApiGetServerIpRequest +*/ +func (a *DedicatedserverAPIService) GetServerIp(ctx context.Context, serverId string, ip string) ApiGetServerIpRequest { + return ApiGetServerIpRequest{ + ApiService: a, + ctx: ctx, + serverId: serverId, + ip: ip, + } +} + +// Execute executes the request +// @return Ip +func (a *DedicatedserverAPIService) GetServerIpExecute(r ApiGetServerIpRequest) (*Ip, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodGet + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *Ip + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "DedicatedserverAPIService.GetServerIp") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/servers/{serverId}/ips/{ip}" + localVarPath = strings.Replace(localVarPath, "{"+"serverId"+"}", url.PathEscape(parameterValueToString(r.serverId, "serverId")), -1) + localVarPath = strings.Replace(localVarPath, "{"+"ip"+"}", url.PathEscape(parameterValueToString(r.ip, "ip")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiGetServerIpListRequest struct { + ctx context.Context + ApiService *DedicatedserverAPIService + serverId string + networkType *string + version *string + nullRouted *string + ips *string + limit *int32 + offset *int32 +} + +// Filter the collection of ip addresses by network type +func (r ApiGetServerIpListRequest) NetworkType(networkType string) ApiGetServerIpListRequest { + r.networkType = &networkType + return r +} + +// Filter the collection by ip version +func (r ApiGetServerIpListRequest) Version(version string) ApiGetServerIpListRequest { + r.version = &version + return r +} + +// Filter Ips by Nulled-Status +func (r ApiGetServerIpListRequest) NullRouted(nullRouted string) ApiGetServerIpListRequest { + r.nullRouted = &nullRouted + return r +} + +// Filter the collection of Ips for the comma separated list of Ips +func (r ApiGetServerIpListRequest) Ips(ips string) ApiGetServerIpListRequest { + r.ips = &ips + return r +} + +// Limit the number of results returned. +func (r ApiGetServerIpListRequest) Limit(limit int32) ApiGetServerIpListRequest { + r.limit = &limit + return r +} + +// Return results starting from the given offset. +func (r ApiGetServerIpListRequest) Offset(offset int32) ApiGetServerIpListRequest { + r.offset = &offset + return r +} + +func (r ApiGetServerIpListRequest) Execute() (*Ip, *http.Response, error) { + return r.ApiService.GetServerIpListExecute(r) +} + +/* +GetServerIpList List IPs + +List all IP Addresses associated with this server. Optionally filtered. + + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param serverId The ID of a server + @return ApiGetServerIpListRequest +*/ +func (a *DedicatedserverAPIService) GetServerIpList(ctx context.Context, serverId string) ApiGetServerIpListRequest { + return ApiGetServerIpListRequest{ + ApiService: a, + ctx: ctx, + serverId: serverId, + } +} + +// Execute executes the request +// @return Ip +func (a *DedicatedserverAPIService) GetServerIpListExecute(r ApiGetServerIpListRequest) (*Ip, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodGet + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *Ip + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "DedicatedserverAPIService.GetServerIpList") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/servers/{serverId}/ips" + localVarPath = strings.Replace(localVarPath, "{"+"serverId"+"}", url.PathEscape(parameterValueToString(r.serverId, "serverId")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + if r.networkType != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "networkType", r.networkType, "") + } + if r.version != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "version", r.version, "") + } + if r.nullRouted != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "nullRouted", r.nullRouted, "") + } + if r.ips != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "ips", r.ips, "") + } + if r.limit != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "limit", r.limit, "") + } + if r.offset != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "offset", r.offset, "") + } + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiGetServerListRequest struct { + ctx context.Context + ApiService *DedicatedserverAPIService + limit *int32 + offset *int32 + reference *string + ip *string + macAddress *string + site *string + privateRackId *string + privateNetworkCapable *string + privateNetworkEnabled *string +} + +// Limit the number of results returned. +func (r ApiGetServerListRequest) Limit(limit int32) ApiGetServerListRequest { + r.limit = &limit + return r +} + +// Return results starting from the given offset. +func (r ApiGetServerListRequest) Offset(offset int32) ApiGetServerListRequest { + r.offset = &offset + return r +} + +// Filter the list of servers by reference. +func (r ApiGetServerListRequest) Reference(reference string) ApiGetServerListRequest { + r.reference = &reference + return r +} + +// Filter the list of servers by ip address. +func (r ApiGetServerListRequest) Ip(ip string) ApiGetServerListRequest { + r.ip = &ip + return r +} + +// Filter the list of servers by mac address. +func (r ApiGetServerListRequest) MacAddress(macAddress string) ApiGetServerListRequest { + r.macAddress = &macAddress + return r +} + +// Filter the list of servers by site (location). +func (r ApiGetServerListRequest) Site(site string) ApiGetServerListRequest { + r.site = &site + return r +} + +// Filter the list of servers by dedicated rack id. +func (r ApiGetServerListRequest) PrivateRackId(privateRackId string) ApiGetServerListRequest { + r.privateRackId = &privateRackId + return r +} + +// Filter the list for private network capable servers +func (r ApiGetServerListRequest) PrivateNetworkCapable(privateNetworkCapable string) ApiGetServerListRequest { + r.privateNetworkCapable = &privateNetworkCapable + return r +} + +// Filter the list for private network enabled servers +func (r ApiGetServerListRequest) PrivateNetworkEnabled(privateNetworkEnabled string) ApiGetServerListRequest { + r.privateNetworkEnabled = &privateNetworkEnabled + return r +} + +func (r ApiGetServerListRequest) Execute() (*GetServerListResult, *http.Response, error) { + return r.ApiService.GetServerListExecute(r) +} + +/* +GetServerList List servers + +List your Dedicated Servers. This api call supports pagination. Use the +`limit` and `offset` query string parameters to paginate through all your +dedicated servers. + +Every `server` object in the json response lists a few properties of a server. +Use the single resource api call to get more details for a single server. + + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @return ApiGetServerListRequest +*/ +func (a *DedicatedserverAPIService) GetServerList(ctx context.Context) ApiGetServerListRequest { + return ApiGetServerListRequest{ + ApiService: a, + ctx: ctx, + } +} + +// Execute executes the request +// @return GetServerListResult +func (a *DedicatedserverAPIService) GetServerListExecute(r ApiGetServerListRequest) (*GetServerListResult, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodGet + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *GetServerListResult + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "DedicatedserverAPIService.GetServerList") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/servers" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + if r.limit != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "limit", r.limit, "") + } + if r.offset != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "offset", r.offset, "") + } + if r.reference != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "reference", r.reference, "") + } + if r.ip != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "ip", r.ip, "") + } + if r.macAddress != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "macAddress", r.macAddress, "") + } + if r.site != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "site", r.site, "") + } + if r.privateRackId != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "privateRackId", r.privateRackId, "") + } + if r.privateNetworkCapable != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "privateNetworkCapable", r.privateNetworkCapable, "") + } + if r.privateNetworkEnabled != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "privateNetworkEnabled", r.privateNetworkEnabled, "") + } + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiGetServerNullRouteHistoryRequest struct { + ctx context.Context + ApiService *DedicatedserverAPIService + serverId string + limit *int32 + offset *int32 +} + +// Limit the number of results returned. +func (r ApiGetServerNullRouteHistoryRequest) Limit(limit int32) ApiGetServerNullRouteHistoryRequest { + r.limit = &limit + return r +} + +// Return results starting from the given offset. +func (r ApiGetServerNullRouteHistoryRequest) Offset(offset int32) ApiGetServerNullRouteHistoryRequest { + r.offset = &offset + return r +} + +func (r ApiGetServerNullRouteHistoryRequest) Execute() (*GetServerNullRouteHistoryResult, *http.Response, error) { + return r.ApiService.GetServerNullRouteHistoryExecute(r) +} + +/* +GetServerNullRouteHistory Show null route history + +Show all null route history for any ips associated with this server. + + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param serverId The ID of a server + @return ApiGetServerNullRouteHistoryRequest +*/ +func (a *DedicatedserverAPIService) GetServerNullRouteHistory(ctx context.Context, serverId string) ApiGetServerNullRouteHistoryRequest { + return ApiGetServerNullRouteHistoryRequest{ + ApiService: a, + ctx: ctx, + serverId: serverId, + } +} + +// Execute executes the request +// @return GetServerNullRouteHistoryResult +func (a *DedicatedserverAPIService) GetServerNullRouteHistoryExecute(r ApiGetServerNullRouteHistoryRequest) (*GetServerNullRouteHistoryResult, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodGet + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *GetServerNullRouteHistoryResult + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "DedicatedserverAPIService.GetServerNullRouteHistory") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/servers/{serverId}/nullRouteHistory" + localVarPath = strings.Replace(localVarPath, "{"+"serverId"+"}", url.PathEscape(parameterValueToString(r.serverId, "serverId")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + if r.limit != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "limit", r.limit, "") + } + if r.offset != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "offset", r.offset, "") + } + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiNetworkEquipmentsIpsNullRequest struct { + ctx context.Context + ApiService *DedicatedserverAPIService + networkEquipmentId string + ip string +} + +func (r ApiNetworkEquipmentsIpsNullRequest) Execute() (*Ip, *http.Response, error) { + return r.ApiService.NetworkEquipmentsIpsNullExecute(r) +} + +/* +NetworkEquipmentsIpsNull Null route an IP + +Null the given IP address. It might take a few minutes before the change is +propagated across the network. + + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param networkEquipmentId The ID of a dedicated network equipment + @param ip The IP Address + @return ApiNetworkEquipmentsIpsNullRequest +*/ +func (a *DedicatedserverAPIService) NetworkEquipmentsIpsNull(ctx context.Context, networkEquipmentId string, ip string) ApiNetworkEquipmentsIpsNullRequest { + return ApiNetworkEquipmentsIpsNullRequest{ + ApiService: a, + ctx: ctx, + networkEquipmentId: networkEquipmentId, + ip: ip, + } +} + +// Execute executes the request +// @return Ip +func (a *DedicatedserverAPIService) NetworkEquipmentsIpsNullExecute(r ApiNetworkEquipmentsIpsNullRequest) (*Ip, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodPost + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *Ip + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "DedicatedserverAPIService.NetworkEquipmentsIpsNull") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/networkEquipments/{networkEquipmentId}/ips/{ip}/null" + localVarPath = strings.Replace(localVarPath, "{"+"networkEquipmentId"+"}", url.PathEscape(parameterValueToString(r.networkEquipmentId, "networkEquipmentId")), -1) + localVarPath = strings.Replace(localVarPath, "{"+"ip"+"}", url.PathEscape(parameterValueToString(r.ip, "ip")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiNullIpRouteRequest struct { + ctx context.Context + ApiService *DedicatedserverAPIService + serverId string + ip string +} + +func (r ApiNullIpRouteRequest) Execute() (*Ip, *http.Response, error) { + return r.ApiService.NullIpRouteExecute(r) +} + +/* +NullIpRoute Null route an IP + +Null the given IP address. It might take a few minutes before the change is +propagated across the network. + + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param serverId The ID of a server + @param ip The IP Address + @return ApiNullIpRouteRequest +*/ +func (a *DedicatedserverAPIService) NullIpRoute(ctx context.Context, serverId string, ip string) ApiNullIpRouteRequest { + return ApiNullIpRouteRequest{ + ApiService: a, + ctx: ctx, + serverId: serverId, + ip: ip, + } +} + +// Execute executes the request +// @return Ip +func (a *DedicatedserverAPIService) NullIpRouteExecute(r ApiNullIpRouteRequest) (*Ip, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodPost + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *Ip + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "DedicatedserverAPIService.NullIpRoute") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/servers/{serverId}/ips/{ip}/null" + localVarPath = strings.Replace(localVarPath, "{"+"serverId"+"}", url.PathEscape(parameterValueToString(r.serverId, "serverId")), -1) + localVarPath = strings.Replace(localVarPath, "{"+"ip"+"}", url.PathEscape(parameterValueToString(r.ip, "ip")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiPutServerIpRequest struct { + ctx context.Context + ApiService *DedicatedserverAPIService + serverId string + ip string + updateIpProfileOpts *UpdateIpProfileOpts +} + +func (r ApiPutServerIpRequest) UpdateIpProfileOpts(updateIpProfileOpts UpdateIpProfileOpts) ApiPutServerIpRequest { + r.updateIpProfileOpts = &updateIpProfileOpts + return r +} + +func (r ApiPutServerIpRequest) Execute() (*Ip, *http.Response, error) { + return r.ApiService.PutServerIpExecute(r) +} + +/* +PutServerIp Update an IP + +Update the reverse lookup or DDoS detection profile for the ip address. + +DDoS detection profiles can only be changed if the IP address is protected +using Advanced DDoS protection. + +For more information about DDoS detection profiles [click here](https://kb.leaseweb.com/products/cyber-security/ddos-ip-protection#DDOSIPProtection-DDoSIPProtectionAdvancedDetectionprofiles) for our KB related article. + + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param serverId The ID of a server + @param ip The IP Address + @return ApiPutServerIpRequest +*/ +func (a *DedicatedserverAPIService) PutServerIp(ctx context.Context, serverId string, ip string) ApiPutServerIpRequest { + return ApiPutServerIpRequest{ + ApiService: a, + ctx: ctx, + serverId: serverId, + ip: ip, + } +} + +// Execute executes the request +// @return Ip +func (a *DedicatedserverAPIService) PutServerIpExecute(r ApiPutServerIpRequest) (*Ip, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodPut + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *Ip + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "DedicatedserverAPIService.PutServerIp") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/servers/{serverId}/ips/{ip}" + localVarPath = strings.Replace(localVarPath, "{"+"serverId"+"}", url.PathEscape(parameterValueToString(r.serverId, "serverId")), -1) + localVarPath = strings.Replace(localVarPath, "{"+"ip"+"}", url.PathEscape(parameterValueToString(r.ip, "ip")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{"application/json"} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + // body params + localVarPostBody = r.updateIpProfileOpts + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiRemoveNullIpRouteRequest struct { + ctx context.Context + ApiService *DedicatedserverAPIService + serverId string + ip string +} + +func (r ApiRemoveNullIpRouteRequest) Execute() (*Ip, *http.Response, error) { + return r.ApiService.RemoveNullIpRouteExecute(r) +} + +/* +RemoveNullIpRoute Remove a null route + +Remove an existing null route for the given IP address. It might take a few +minutes before the change is propagated across the network. + + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param serverId The ID of a server + @param ip The IP Address + @return ApiRemoveNullIpRouteRequest +*/ +func (a *DedicatedserverAPIService) RemoveNullIpRoute(ctx context.Context, serverId string, ip string) ApiRemoveNullIpRouteRequest { + return ApiRemoveNullIpRouteRequest{ + ApiService: a, + ctx: ctx, + serverId: serverId, + ip: ip, + } +} + +// Execute executes the request +// @return Ip +func (a *DedicatedserverAPIService) RemoveNullIpRouteExecute(r ApiRemoveNullIpRouteRequest) (*Ip, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodPost + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *Ip + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "DedicatedserverAPIService.RemoveNullIpRoute") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/servers/{serverId}/ips/{ip}/unnull" + localVarPath = strings.Replace(localVarPath, "{"+"serverId"+"}", url.PathEscape(parameterValueToString(r.serverId, "serverId")), -1) + localVarPath = strings.Replace(localVarPath, "{"+"ip"+"}", url.PathEscape(parameterValueToString(r.ip, "ip")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiUnNullNetworkEquipmentIpRouteRequest struct { + ctx context.Context + ApiService *DedicatedserverAPIService + networkEquipmentId string + ip string +} + +func (r ApiUnNullNetworkEquipmentIpRouteRequest) Execute() (*Ip, *http.Response, error) { + return r.ApiService.UnNullNetworkEquipmentIpRouteExecute(r) +} + +/* +UnNullNetworkEquipmentIpRoute Remove a null route + +Remove an existing null route for the given IP address. It might take a few +minutes before the change is propagated across the network. + + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param networkEquipmentId The ID of a dedicated network equipment + @param ip The IP Address + @return ApiUnNullNetworkEquipmentIpRouteRequest +*/ +func (a *DedicatedserverAPIService) UnNullNetworkEquipmentIpRoute(ctx context.Context, networkEquipmentId string, ip string) ApiUnNullNetworkEquipmentIpRouteRequest { + return ApiUnNullNetworkEquipmentIpRouteRequest{ + ApiService: a, + ctx: ctx, + networkEquipmentId: networkEquipmentId, + ip: ip, + } +} + +// Execute executes the request +// @return Ip +func (a *DedicatedserverAPIService) UnNullNetworkEquipmentIpRouteExecute(r ApiUnNullNetworkEquipmentIpRouteRequest) (*Ip, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodPost + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *Ip + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "DedicatedserverAPIService.UnNullNetworkEquipmentIpRoute") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/networkEquipments/{networkEquipmentId}/ips/{ip}/unnull" + localVarPath = strings.Replace(localVarPath, "{"+"networkEquipmentId"+"}", url.PathEscape(parameterValueToString(r.networkEquipmentId, "networkEquipmentId")), -1) + localVarPath = strings.Replace(localVarPath, "{"+"ip"+"}", url.PathEscape(parameterValueToString(r.ip, "ip")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiUpdateNetworkEquipmentIpRequest struct { + ctx context.Context + ApiService *DedicatedserverAPIService + networkEquipmentId string + ip string + updateNetworkEquipmentIpOpts *UpdateNetworkEquipmentIpOpts +} + +func (r ApiUpdateNetworkEquipmentIpRequest) UpdateNetworkEquipmentIpOpts(updateNetworkEquipmentIpOpts UpdateNetworkEquipmentIpOpts) ApiUpdateNetworkEquipmentIpRequest { + r.updateNetworkEquipmentIpOpts = &updateNetworkEquipmentIpOpts + return r +} + +func (r ApiUpdateNetworkEquipmentIpRequest) Execute() (*Ip, *http.Response, error) { + return r.ApiService.UpdateNetworkEquipmentIpExecute(r) +} + +/* +UpdateNetworkEquipmentIp Update an IP + +Update the reverse lookup or DDoS detection profile for the ip address. + +DDoS detection profiles can only be changed if the IP address is protected +using Advanced DDoS protection. + +For more information about DDoS detection profiles [click here](https://kb.leaseweb.com/products/cyber-security/ddos-ip-protection#DDOSIPProtection-DDoSIPProtectionAdvancedDetectionprofiles) for our KB related article. + + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param networkEquipmentId The ID of a dedicated network equipment + @param ip The IP Address + @return ApiUpdateNetworkEquipmentIpRequest +*/ +func (a *DedicatedserverAPIService) UpdateNetworkEquipmentIp(ctx context.Context, networkEquipmentId string, ip string) ApiUpdateNetworkEquipmentIpRequest { + return ApiUpdateNetworkEquipmentIpRequest{ + ApiService: a, + ctx: ctx, + networkEquipmentId: networkEquipmentId, + ip: ip, + } +} + +// Execute executes the request +// @return Ip +func (a *DedicatedserverAPIService) UpdateNetworkEquipmentIpExecute(r ApiUpdateNetworkEquipmentIpRequest) (*Ip, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodPut + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *Ip + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "DedicatedserverAPIService.UpdateNetworkEquipmentIp") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/networkEquipments/{networkEquipmentId}/ips/{ip}" + localVarPath = strings.Replace(localVarPath, "{"+"networkEquipmentId"+"}", url.PathEscape(parameterValueToString(r.networkEquipmentId, "networkEquipmentId")), -1) + localVarPath = strings.Replace(localVarPath, "{"+"ip"+"}", url.PathEscape(parameterValueToString(r.ip, "ip")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{"application/json"} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + // body params + localVarPostBody = r.updateNetworkEquipmentIpOpts + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiUpdateNetworkEquipmentReferenceRequest struct { + ctx context.Context + ApiService *DedicatedserverAPIService + networkEquipmentId string + updateNetworkEquipmentReferenceOpts *UpdateNetworkEquipmentReferenceOpts +} + +func (r ApiUpdateNetworkEquipmentReferenceRequest) UpdateNetworkEquipmentReferenceOpts(updateNetworkEquipmentReferenceOpts UpdateNetworkEquipmentReferenceOpts) ApiUpdateNetworkEquipmentReferenceRequest { + r.updateNetworkEquipmentReferenceOpts = &updateNetworkEquipmentReferenceOpts + return r +} + +func (r ApiUpdateNetworkEquipmentReferenceRequest) Execute() (*http.Response, error) { + return r.ApiService.UpdateNetworkEquipmentReferenceExecute(r) +} + +/* +UpdateNetworkEquipmentReference Update network equipment + +Update the reference for a network equipment. + + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param networkEquipmentId The ID of a dedicated network equipment + @return ApiUpdateNetworkEquipmentReferenceRequest +*/ +func (a *DedicatedserverAPIService) UpdateNetworkEquipmentReference(ctx context.Context, networkEquipmentId string) ApiUpdateNetworkEquipmentReferenceRequest { + return ApiUpdateNetworkEquipmentReferenceRequest{ + ApiService: a, + ctx: ctx, + networkEquipmentId: networkEquipmentId, + } +} + +// Execute executes the request +func (a *DedicatedserverAPIService) UpdateNetworkEquipmentReferenceExecute(r ApiUpdateNetworkEquipmentReferenceRequest) (*http.Response, error) { + var ( + localVarHTTPMethod = http.MethodPut + localVarPostBody interface{} + formFiles []formFile + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "DedicatedserverAPIService.UpdateNetworkEquipmentReference") + if err != nil { + return nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/networkEquipments/{networkEquipmentId}" + localVarPath = strings.Replace(localVarPath, "{"+"networkEquipmentId"+"}", url.PathEscape(parameterValueToString(r.networkEquipmentId, "networkEquipmentId")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + if r.updateNetworkEquipmentReferenceOpts == nil { + return nil, reportError("updateNetworkEquipmentReferenceOpts is required and must be specified") + } + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{"application/json"} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + // body params + localVarPostBody = r.updateNetworkEquipmentReferenceOpts + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarHTTPResponse, newErr + } + + return localVarHTTPResponse, nil +} + +type ApiUpdateServerReferenceRequest struct { + ctx context.Context + ApiService *DedicatedserverAPIService + serverId string + updateServerReferenceOpts *UpdateServerReferenceOpts +} + +func (r ApiUpdateServerReferenceRequest) UpdateServerReferenceOpts(updateServerReferenceOpts UpdateServerReferenceOpts) ApiUpdateServerReferenceRequest { + r.updateServerReferenceOpts = &updateServerReferenceOpts + return r +} + +func (r ApiUpdateServerReferenceRequest) Execute() (*http.Response, error) { + return r.ApiService.UpdateServerReferenceExecute(r) +} + +/* +UpdateServerReference Update server + +Update the reference for a server. + + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param serverId The ID of a server + @return ApiUpdateServerReferenceRequest +*/ +func (a *DedicatedserverAPIService) UpdateServerReference(ctx context.Context, serverId string) ApiUpdateServerReferenceRequest { + return ApiUpdateServerReferenceRequest{ + ApiService: a, + ctx: ctx, + serverId: serverId, + } +} + +// Execute executes the request +func (a *DedicatedserverAPIService) UpdateServerReferenceExecute(r ApiUpdateServerReferenceRequest) (*http.Response, error) { + var ( + localVarHTTPMethod = http.MethodPut + localVarPostBody interface{} + formFiles []formFile + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "DedicatedserverAPIService.UpdateServerReference") + if err != nil { + return nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/servers/{serverId}" + localVarPath = strings.Replace(localVarPath, "{"+"serverId"+"}", url.PathEscape(parameterValueToString(r.serverId, "serverId")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + if r.updateServerReferenceOpts == nil { + return nil, reportError("updateServerReferenceOpts is required and must be specified") + } + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{"application/json"} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + // body params + localVarPostBody = r.updateServerReferenceOpts + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 404 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarHTTPResponse, newErr + } + + return localVarHTTPResponse, nil +} diff --git a/dedicatedserver/client.go b/dedicatedserver/client.go new file mode 100644 index 0000000..d85a6aa --- /dev/null +++ b/dedicatedserver/client.go @@ -0,0 +1,678 @@ +/* +Leaseweb API for dedicated servers + +This documents the rest api dedicatedserver provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package dedicatedserver + +import ( + "bytes" + "context" + "encoding/json" + "encoding/xml" + "errors" + "fmt" + "io" + "log" + "mime/multipart" + "net/http" + "net/http/httputil" + "net/url" + "os" + "path/filepath" + "reflect" + "regexp" + "strconv" + "strings" + "time" + "unicode/utf8" + + "golang.org/x/oauth2" +) + +var ( + JsonCheck = regexp.MustCompile(`(?i:(?:application|text)/(?:[^;]+\+)?json)`) + XmlCheck = regexp.MustCompile(`(?i:(?:application|text)/(?:[^;]+\+)?xml)`) + queryParamSplit = regexp.MustCompile(`(^|&)([^&]+)`) + queryDescape = strings.NewReplacer( "%5B", "[", "%5D", "]" ) +) + +// APIClient manages communication with the Leaseweb API for dedicated servers API vv2 +// In most cases there should be only one, shared, APIClient. +type APIClient struct { + cfg *Configuration + common service // Reuse a single struct instead of allocating one for each service on the heap. + + // API Services + + DedicatedserverAPI *DedicatedserverAPIService +} + +type service struct { + client *APIClient +} + +// NewAPIClient creates a new API client. Requires a userAgent string describing your application. +// optionally a custom http.Client to allow for advanced features such as caching. +func NewAPIClient(cfg *Configuration) *APIClient { + if cfg.HTTPClient == nil { + cfg.HTTPClient = http.DefaultClient + } + + c := &APIClient{} + c.cfg = cfg + c.common.client = c + + // API Services + c.DedicatedserverAPI = (*DedicatedserverAPIService)(&c.common) + + return c +} + +func atoi(in string) (int, error) { + return strconv.Atoi(in) +} + +// selectHeaderContentType select a content type from the available list. +func selectHeaderContentType(contentTypes []string) string { + if len(contentTypes) == 0 { + return "" + } + if contains(contentTypes, "application/json") { + return "application/json" + } + return contentTypes[0] // use the first content type specified in 'consumes' +} + +// selectHeaderAccept join all accept types and return +func selectHeaderAccept(accepts []string) string { + if len(accepts) == 0 { + return "" + } + + if contains(accepts, "application/json") { + return "application/json" + } + + return strings.Join(accepts, ",") +} + +// contains is a case insensitive match, finding needle in a haystack +func contains(haystack []string, needle string) bool { + for _, a := range haystack { + if strings.EqualFold(a, needle) { + return true + } + } + return false +} + +// Verify optional parameters are of the correct type. +func typeCheckParameter(obj interface{}, expected string, name string) error { + // Make sure there is an object. + if obj == nil { + return nil + } + + // Check the type is as expected. + if reflect.TypeOf(obj).String() != expected { + return fmt.Errorf("expected %s to be of type %s but received %s", name, expected, reflect.TypeOf(obj).String()) + } + return nil +} + +func parameterValueToString( obj interface{}, key string ) string { + if reflect.TypeOf(obj).Kind() != reflect.Ptr { + return fmt.Sprintf("%v", obj) + } + var param,ok = obj.(MappedNullable) + if !ok { + return "" + } + dataMap,err := param.ToMap() + if err != nil { + return "" + } + return fmt.Sprintf("%v", dataMap[key]) +} + +// parameterAddToHeaderOrQuery adds the provided object to the request header or url query +// supporting deep object syntax +func parameterAddToHeaderOrQuery(headerOrQueryParams interface{}, keyPrefix string, obj interface{}, collectionType string) { + var v = reflect.ValueOf(obj) + var value = "" + if v == reflect.ValueOf(nil) { + value = "null" + } else { + switch v.Kind() { + case reflect.Invalid: + value = "invalid" + + case reflect.Struct: + if t,ok := obj.(MappedNullable); ok { + dataMap,err := t.ToMap() + if err != nil { + return + } + parameterAddToHeaderOrQuery(headerOrQueryParams, keyPrefix, dataMap, collectionType) + return + } + if t, ok := obj.(time.Time); ok { + parameterAddToHeaderOrQuery(headerOrQueryParams, keyPrefix, t.Format(time.RFC3339), collectionType) + return + } + value = v.Type().String() + " value" + case reflect.Slice: + var indValue = reflect.ValueOf(obj) + if indValue == reflect.ValueOf(nil) { + return + } + var lenIndValue = indValue.Len() + for i:=0;i 0 || (len(formFiles) > 0) { + if body != nil { + return nil, errors.New("Cannot specify postBody and multipart form at the same time.") + } + body = &bytes.Buffer{} + w := multipart.NewWriter(body) + + for k, v := range formParams { + for _, iv := range v { + if strings.HasPrefix(k, "@") { // file + err = addFile(w, k[1:], iv) + if err != nil { + return nil, err + } + } else { // form value + w.WriteField(k, iv) + } + } + } + for _, formFile := range formFiles { + if len(formFile.fileBytes) > 0 && formFile.fileName != "" { + w.Boundary() + part, err := w.CreateFormFile(formFile.formFileName, filepath.Base(formFile.fileName)) + if err != nil { + return nil, err + } + _, err = part.Write(formFile.fileBytes) + if err != nil { + return nil, err + } + } + } + + // Set the Boundary in the Content-Type + headerParams["Content-Type"] = w.FormDataContentType() + + // Set Content-Length + headerParams["Content-Length"] = fmt.Sprintf("%d", body.Len()) + w.Close() + } + + if strings.HasPrefix(headerParams["Content-Type"], "application/x-www-form-urlencoded") && len(formParams) > 0 { + if body != nil { + return nil, errors.New("Cannot specify postBody and x-www-form-urlencoded form at the same time.") + } + body = &bytes.Buffer{} + body.WriteString(formParams.Encode()) + // Set Content-Length + headerParams["Content-Length"] = fmt.Sprintf("%d", body.Len()) + } + + // Setup path and query parameters + url, err := url.Parse(path) + if err != nil { + return nil, err + } + + // Override request host, if applicable + if c.cfg.Host != "" { + url.Host = c.cfg.Host + } + + // Override request scheme, if applicable + if c.cfg.Scheme != "" { + url.Scheme = c.cfg.Scheme + } + + // Adding Query Param + query := url.Query() + for k, v := range queryParams { + for _, iv := range v { + query.Add(k, iv) + } + } + + // Encode the parameters. + url.RawQuery = queryParamSplit.ReplaceAllStringFunc(query.Encode(), func(s string) string { + pieces := strings.Split(s, "=") + pieces[0] = queryDescape.Replace(pieces[0]) + return strings.Join(pieces, "=") + }) + + // Generate a new request + if body != nil { + localVarRequest, err = http.NewRequest(method, url.String(), body) + } else { + localVarRequest, err = http.NewRequest(method, url.String(), nil) + } + if err != nil { + return nil, err + } + + // add header parameters, if any + if len(headerParams) > 0 { + headers := http.Header{} + for h, v := range headerParams { + headers[h] = []string{v} + } + localVarRequest.Header = headers + } + + // Add the user agent to the request. + localVarRequest.Header.Add("User-Agent", c.cfg.UserAgent) + + if ctx != nil { + // add context to the request + localVarRequest = localVarRequest.WithContext(ctx) + + // Walk through any authentication. + + // OAuth2 authentication + if tok, ok := ctx.Value(ContextOAuth2).(oauth2.TokenSource); ok { + // We were able to grab an oauth2 token from the context + var latestToken *oauth2.Token + if latestToken, err = tok.Token(); err != nil { + return nil, err + } + + latestToken.SetAuthHeader(localVarRequest) + } + + // AccessToken Authentication + if auth, ok := ctx.Value(ContextAccessToken).(string); ok { + localVarRequest.Header.Add("Authorization", "Bearer "+auth) + } + + } + + for header, value := range c.cfg.DefaultHeader { + localVarRequest.Header.Add(header, value) + } + return localVarRequest, nil +} + +func (c *APIClient) decode(v interface{}, b []byte, contentType string) (err error) { + if len(b) == 0 { + return nil + } + if s, ok := v.(*string); ok { + *s = string(b) + return nil + } + if f, ok := v.(*os.File); ok { + f, err = os.CreateTemp("", "HttpClientFile") + if err != nil { + return + } + _, err = f.Write(b) + if err != nil { + return + } + _, err = f.Seek(0, io.SeekStart) + return + } + if f, ok := v.(**os.File); ok { + *f, err = os.CreateTemp("", "HttpClientFile") + if err != nil { + return + } + _, err = (*f).Write(b) + if err != nil { + return + } + _, err = (*f).Seek(0, io.SeekStart) + return + } + if XmlCheck.MatchString(contentType) { + if err = xml.Unmarshal(b, v); err != nil { + return err + } + return nil + } + if JsonCheck.MatchString(contentType) { + if actualObj, ok := v.(interface{ GetActualInstance() interface{} }); ok { // oneOf, anyOf schemas + if unmarshalObj, ok := actualObj.(interface{ UnmarshalJSON([]byte) error }); ok { // make sure it has UnmarshalJSON defined + if err = unmarshalObj.UnmarshalJSON(b); err != nil { + return err + } + } else { + return errors.New("Unknown type with GetActualInstance but no unmarshalObj.UnmarshalJSON defined") + } + } else if err = json.Unmarshal(b, v); err != nil { // simple model + return err + } + return nil + } + return errors.New("undefined response type") +} + +// Add a file to the multipart request +func addFile(w *multipart.Writer, fieldName, path string) error { + file, err := os.Open(filepath.Clean(path)) + if err != nil { + return err + } + err = file.Close() + if err != nil { + return err + } + + part, err := w.CreateFormFile(fieldName, filepath.Base(path)) + if err != nil { + return err + } + _, err = io.Copy(part, file) + + return err +} + +// Prevent trying to import "fmt" +func reportError(format string, a ...interface{}) error { + return fmt.Errorf(format, a...) +} + +// A wrapper for strict JSON decoding +func newStrictDecoder(data []byte) *json.Decoder { + dec := json.NewDecoder(bytes.NewBuffer(data)) + dec.DisallowUnknownFields() + return dec +} + +// Set request body from an interface{} +func setBody(body interface{}, contentType string) (bodyBuf *bytes.Buffer, err error) { + if bodyBuf == nil { + bodyBuf = &bytes.Buffer{} + } + + if reader, ok := body.(io.Reader); ok { + _, err = bodyBuf.ReadFrom(reader) + } else if fp, ok := body.(*os.File); ok { + _, err = bodyBuf.ReadFrom(fp) + } else if b, ok := body.([]byte); ok { + _, err = bodyBuf.Write(b) + } else if s, ok := body.(string); ok { + _, err = bodyBuf.WriteString(s) + } else if s, ok := body.(*string); ok { + _, err = bodyBuf.WriteString(*s) + } else if JsonCheck.MatchString(contentType) { + err = json.NewEncoder(bodyBuf).Encode(body) + } else if XmlCheck.MatchString(contentType) { + var bs []byte + bs, err = xml.Marshal(body) + if err == nil { + bodyBuf.Write(bs) + } + } + + if err != nil { + return nil, err + } + + if bodyBuf.Len() == 0 { + err = fmt.Errorf("invalid body type %s\n", contentType) + return nil, err + } + return bodyBuf, nil +} + +// detectContentType method is used to figure out `Request.Body` content type for request header +func detectContentType(body interface{}) string { + contentType := "text/plain; charset=utf-8" + kind := reflect.TypeOf(body).Kind() + + switch kind { + case reflect.Struct, reflect.Map, reflect.Ptr: + contentType = "application/json; charset=utf-8" + case reflect.String: + contentType = "text/plain; charset=utf-8" + default: + if b, ok := body.([]byte); ok { + contentType = http.DetectContentType(b) + } else if kind == reflect.Slice { + contentType = "application/json; charset=utf-8" + } + } + + return contentType +} + +// Ripped from https://github.com/gregjones/httpcache/blob/master/httpcache.go +type cacheControl map[string]string + +func parseCacheControl(headers http.Header) cacheControl { + cc := cacheControl{} + ccHeader := headers.Get("Cache-Control") + for _, part := range strings.Split(ccHeader, ",") { + part = strings.Trim(part, " ") + if part == "" { + continue + } + if strings.ContainsRune(part, '=') { + keyval := strings.Split(part, "=") + cc[strings.Trim(keyval[0], " ")] = strings.Trim(keyval[1], ",") + } else { + cc[part] = "" + } + } + return cc +} + +// CacheExpires helper function to determine remaining time before repeating a request. +func CacheExpires(r *http.Response) time.Time { + // Figure out when the cache expires. + var expires time.Time + now, err := time.Parse(time.RFC1123, r.Header.Get("date")) + if err != nil { + return time.Now() + } + respCacheControl := parseCacheControl(r.Header) + + if maxAge, ok := respCacheControl["max-age"]; ok { + lifetime, err := time.ParseDuration(maxAge + "s") + if err != nil { + expires = now + } else { + expires = now.Add(lifetime) + } + } else { + expiresHeader := r.Header.Get("Expires") + if expiresHeader != "" { + expires, err = time.Parse(time.RFC1123, expiresHeader) + if err != nil { + expires = now + } + } + } + return expires +} + +func strlen(s string) int { + return utf8.RuneCountInString(s) +} + +// GenericOpenAPIError Provides access to the body, error and model on returned errors. +type GenericOpenAPIError struct { + body []byte + error string + model interface{} +} + +// Error returns non-empty string if there was an error. +func (e GenericOpenAPIError) Error() string { + return e.error +} + +// Body returns the raw bytes of the response +func (e GenericOpenAPIError) Body() []byte { + return e.body +} + +// Model returns the unpacked model of the error +func (e GenericOpenAPIError) Model() interface{} { + return e.model +} + +// format error message using title and detail when model implements rfc7807 +func formatErrorMessage(status string, v interface{}) string { + str := "" + metaValue := reflect.ValueOf(v).Elem() + + if metaValue.Kind() == reflect.Struct { + field := metaValue.FieldByName("Title") + if field != (reflect.Value{}) { + str = fmt.Sprintf("%s", field.Interface()) + } + + field = metaValue.FieldByName("Detail") + if field != (reflect.Value{}) { + str = fmt.Sprintf("%s (%s)", str, field.Interface()) + } + } + + return strings.TrimSpace(fmt.Sprintf("%s %s", status, str)) +} diff --git a/dedicatedserver/configuration.go b/dedicatedserver/configuration.go new file mode 100644 index 0000000..7cd3454 --- /dev/null +++ b/dedicatedserver/configuration.go @@ -0,0 +1,225 @@ +/* +Leaseweb API for dedicated servers + +This documents the rest api dedicatedserver provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package dedicatedserver + +import ( + "context" + "fmt" + "net/http" + "strings" +) + +// contextKeys are used to identify the type of value in the context. +// Since these are string, it is possible to get a short description of the +// context key for logging and debugging using key.String(). + +type contextKey string + +func (c contextKey) String() string { + return "auth " + string(c) +} + +var ( + // ContextOAuth2 takes an oauth2.TokenSource as authentication for the request. + ContextOAuth2 = contextKey("token") + + // ContextAccessToken takes a string oauth2 access token as authentication for the request. + ContextAccessToken = contextKey("accesstoken") + + // ContextAPIKeys takes a string apikey as authentication for the request + ContextAPIKeys = contextKey("apiKeys") + + // ContextServerIndex uses a server configuration from the index. + ContextServerIndex = contextKey("serverIndex") + + // ContextOperationServerIndices uses a server configuration from the index mapping. + ContextOperationServerIndices = contextKey("serverOperationIndices") + + // ContextServerVariables overrides a server configuration variables. + ContextServerVariables = contextKey("serverVariables") + + // ContextOperationServerVariables overrides a server configuration variables using operation specific values. + ContextOperationServerVariables = contextKey("serverOperationVariables") +) + +// BasicAuth provides basic http authentication to a request passed via context using ContextBasicAuth +type BasicAuth struct { + UserName string `json:"userName,omitempty"` + Password string `json:"password,omitempty"` +} + +// APIKey provides API key based authentication to a request passed via context using ContextAPIKey +type APIKey struct { + Key string + Prefix string +} + +// ServerVariable stores the information about a server variable +type ServerVariable struct { + Description string + DefaultValue string + EnumValues []string +} + +// ServerConfiguration stores the information about a server +type ServerConfiguration struct { + URL string + Description string + Variables map[string]ServerVariable +} + +// ServerConfigurations stores multiple ServerConfiguration items +type ServerConfigurations []ServerConfiguration + +// Configuration stores the configuration of the API client +type Configuration struct { + Host string `json:"host,omitempty"` + Scheme string `json:"scheme,omitempty"` + DefaultHeader map[string]string `json:"defaultHeader,omitempty"` + UserAgent string `json:"userAgent,omitempty"` + Debug bool `json:"debug,omitempty"` + Servers ServerConfigurations + OperationServers map[string]ServerConfigurations + HTTPClient *http.Client +} + +// NewConfiguration returns a new Configuration object +func NewConfiguration() *Configuration { + cfg := &Configuration{ + DefaultHeader: make(map[string]string), + UserAgent: "OpenAPI-Generator/1.0.0/go", + Debug: false, + Servers: ServerConfigurations{ + { + URL: "https://api.leaseweb.com/internal/dedicatedserverapi/v2", + Description: "No description provided", + }, + }, + OperationServers: map[string]ServerConfigurations{ + }, + } + return cfg +} + +// AddDefaultHeader adds a new HTTP header to the default header in the request +func (c *Configuration) AddDefaultHeader(key string, value string) { + c.DefaultHeader[key] = value +} + +// URL formats template on a index using given variables +func (sc ServerConfigurations) URL(index int, variables map[string]string) (string, error) { + if index < 0 || len(sc) <= index { + return "", fmt.Errorf("index %v out of range %v", index, len(sc)-1) + } + server := sc[index] + url := server.URL + + // go through variables and replace placeholders + for name, variable := range server.Variables { + if value, ok := variables[name]; ok { + found := bool(len(variable.EnumValues) == 0) + for _, enumValue := range variable.EnumValues { + if value == enumValue { + found = true + } + } + if !found { + return "", fmt.Errorf("the variable %s in the server URL has invalid value %v. Must be %v", name, value, variable.EnumValues) + } + url = strings.Replace(url, "{"+name+"}", value, -1) + } else { + url = strings.Replace(url, "{"+name+"}", variable.DefaultValue, -1) + } + } + return url, nil +} + +// ServerURL returns URL based on server settings +func (c *Configuration) ServerURL(index int, variables map[string]string) (string, error) { + return c.Servers.URL(index, variables) +} + +func getServerIndex(ctx context.Context) (int, error) { + si := ctx.Value(ContextServerIndex) + if si != nil { + if index, ok := si.(int); ok { + return index, nil + } + return 0, reportError("Invalid type %T should be int", si) + } + return 0, nil +} + +func getServerOperationIndex(ctx context.Context, endpoint string) (int, error) { + osi := ctx.Value(ContextOperationServerIndices) + if osi != nil { + if operationIndices, ok := osi.(map[string]int); !ok { + return 0, reportError("Invalid type %T should be map[string]int", osi) + } else { + index, ok := operationIndices[endpoint] + if ok { + return index, nil + } + } + } + return getServerIndex(ctx) +} + +func getServerVariables(ctx context.Context) (map[string]string, error) { + sv := ctx.Value(ContextServerVariables) + if sv != nil { + if variables, ok := sv.(map[string]string); ok { + return variables, nil + } + return nil, reportError("ctx value of ContextServerVariables has invalid type %T should be map[string]string", sv) + } + return nil, nil +} + +func getServerOperationVariables(ctx context.Context, endpoint string) (map[string]string, error) { + osv := ctx.Value(ContextOperationServerVariables) + if osv != nil { + if operationVariables, ok := osv.(map[string]map[string]string); !ok { + return nil, reportError("ctx value of ContextOperationServerVariables has invalid type %T should be map[string]map[string]string", osv) + } else { + variables, ok := operationVariables[endpoint] + if ok { + return variables, nil + } + } + } + return getServerVariables(ctx) +} + +// ServerURLWithContext returns a new server URL given an endpoint +func (c *Configuration) ServerURLWithContext(ctx context.Context, endpoint string) (string, error) { + sc, ok := c.OperationServers[endpoint] + if !ok { + sc = c.Servers + } + + if ctx == nil { + return sc.URL(0, nil) + } + + index, err := getServerOperationIndex(ctx, endpoint) + if err != nil { + return "", err + } + + variables, err := getServerOperationVariables(ctx, endpoint) + if err != nil { + return "", err + } + + return sc.URL(index, variables) +} diff --git a/dedicatedserver/go.mod b/dedicatedserver/go.mod new file mode 100644 index 0000000..aa579bb --- /dev/null +++ b/dedicatedserver/go.mod @@ -0,0 +1,7 @@ +module github.com/leaseweb/leaseweb-go-sdk/dedicatedserver + +go 1.18 + +require ( + golang.org/x/oauth2 v0.0.0-20210323180902-22b0adad7558 +) diff --git a/dedicatedserver/go.sum b/dedicatedserver/go.sum new file mode 100644 index 0000000..3dee6d6 --- /dev/null +++ b/dedicatedserver/go.sum @@ -0,0 +1,360 @@ +cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU= +cloud.google.com/go v0.44.1/go.mod h1:iSa0KzasP4Uvy3f1mN/7PiObzGgflwredwwASm/v6AU= +cloud.google.com/go v0.44.2/go.mod h1:60680Gw3Yr4ikxnPRS/oxxkBccT6SA1yMk63TGekxKY= +cloud.google.com/go v0.45.1/go.mod h1:RpBamKRgapWJb87xiFSdk4g1CME7QZg3uwTez+TSTjc= +cloud.google.com/go v0.46.3/go.mod h1:a6bKKbmY7er1mI7TEI4lsAkts/mkhTSZK8w33B4RAg0= +cloud.google.com/go v0.50.0/go.mod h1:r9sluTvynVuxRIOHXQEHMFffphuXHOMZMycpNR5e6To= +cloud.google.com/go v0.52.0/go.mod h1:pXajvRH/6o3+F9jDHZWQ5PbGhn+o8w9qiu/CffaVdO4= +cloud.google.com/go v0.53.0/go.mod h1:fp/UouUEsRkN6ryDKNW/Upv/JBKnv6WDthjR6+vze6M= +cloud.google.com/go v0.54.0/go.mod h1:1rq2OEkV3YMf6n/9ZvGWI3GWw0VoqH/1x2nd8Is/bPc= +cloud.google.com/go v0.56.0/go.mod h1:jr7tqZxxKOVYizybht9+26Z/gUq7tiRzu+ACVAMbKVk= +cloud.google.com/go v0.57.0/go.mod h1:oXiQ6Rzq3RAkkY7N6t3TcE6jE+CIBBbA36lwQ1JyzZs= +cloud.google.com/go v0.62.0/go.mod h1:jmCYTdRCQuc1PHIIJ/maLInMho30T/Y0M4hTdTShOYc= +cloud.google.com/go v0.65.0/go.mod h1:O5N8zS7uWy9vkA9vayVHs65eM1ubvY4h553ofrNHObY= +cloud.google.com/go/bigquery v1.0.1/go.mod h1:i/xbL2UlR5RvWAURpBYZTtm/cXjCha9lbfbpx4poX+o= +cloud.google.com/go/bigquery v1.3.0/go.mod h1:PjpwJnslEMmckchkHFfq+HTD2DmtT67aNFKH1/VBDHE= +cloud.google.com/go/bigquery v1.4.0/go.mod h1:S8dzgnTigyfTmLBfrtrhyYhwRxG72rYxvftPBK2Dvzc= +cloud.google.com/go/bigquery v1.5.0/go.mod h1:snEHRnqQbz117VIFhE8bmtwIDY80NLUZUMb4Nv6dBIg= +cloud.google.com/go/bigquery v1.7.0/go.mod h1://okPTzCYNXSlb24MZs83e2Do+h+VXtc4gLoIoXIAPc= +cloud.google.com/go/bigquery v1.8.0/go.mod h1:J5hqkt3O0uAFnINi6JXValWIb1v0goeZM77hZzJN/fQ= +cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7TKLgZqpHYE= +cloud.google.com/go/datastore v1.1.0/go.mod h1:umbIZjpQpHh4hmRpGhH4tLFup+FVzqBi1b3c64qFpCk= +cloud.google.com/go/pubsub v1.0.1/go.mod h1:R0Gpsv3s54REJCy4fxDixWD93lHJMoZTyQ2kNxGRt3I= +cloud.google.com/go/pubsub v1.1.0/go.mod h1:EwwdRX2sKPjnvnqCa270oGRyludottCI76h+R3AArQw= +cloud.google.com/go/pubsub v1.2.0/go.mod h1:jhfEVHT8odbXTkndysNHCcx0awwzvfOlguIAii9o8iA= +cloud.google.com/go/pubsub v1.3.1/go.mod h1:i+ucay31+CNRpDW4Lu78I4xXG+O1r/MAHgjpRVR+TSU= +cloud.google.com/go/storage v1.0.0/go.mod h1:IhtSnM/ZTZV8YYJWCY8RULGVqBDmpoyjwiyrjsg+URw= +cloud.google.com/go/storage v1.5.0/go.mod h1:tpKbwo567HUNpVclU5sGELwQWBDZ8gh0ZeosJ0Rtdos= +cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohlUTyfDhBk= +cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs= +cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0= +dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= +github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= +github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= +github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= +github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= +github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= +github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= +github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= +github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= +github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y= +github.com/golang/mock v1.4.0/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= +github.com/golang/mock v1.4.1/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= +github.com/golang/mock v1.4.3/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= +github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4= +github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= +github.com/golang/protobuf v1.3.4/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= +github.com/golang/protobuf v1.3.5/go.mod h1:6O5/vntMXwX2lRkT1hjjk0nAC1IDOTvTlVgjlRvqsdk= +github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= +github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= +github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= +github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= +github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= +github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= +github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= +github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= +github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= +github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.4.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= +github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0= +github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= +github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= +github.com/google/pprof v0.0.0-20191218002539-d4f498aebedc/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= +github.com/google/pprof v0.0.0-20200212024743-f11f1df84d12/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= +github.com/google/pprof v0.0.0-20200229191704-1ebb73c60ed3/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= +github.com/google/pprof v0.0.0-20200430221834-fc25d7d30c6d/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= +github.com/google/pprof v0.0.0-20200708004538-1a94d8640e99/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= +github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= +github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= +github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= +github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= +github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= +github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= +github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= +github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk= +github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= +go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= +go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= +go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= +go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= +golang.org/x/exp v0.0.0-20190829153037-c13cbed26979/go.mod h1:86+5VVa7VpoJ4kLfm080zCjGlMRFzhUhsZKEZO7MGek= +golang.org/x/exp v0.0.0-20191030013958-a1ab85dbe136/go.mod h1:JXzH8nQsPlswgeRAPE3MuO9GYsAcnJvJ4vnMwN/5qkY= +golang.org/x/exp v0.0.0-20191129062945-2f5052295587/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= +golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= +golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= +golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM= +golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU= +golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= +golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= +golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= +golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f/go.mod h1:5qLYkcX4OjUUV8bRuDixDT3tpyyb+LUpUlRWLxfhWrs= +golang.org/x/lint v0.0.0-20200130185559-910be7a94367/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= +golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= +golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= +golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o= +golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= +golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY= +golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= +golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= +golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e h1:bRhVy7zSSasaqNksaRZiA5EEI+Ei4I1nO5Jh72wfHlg= +golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190501004415-9ce7a6920f09/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20190628185345-da137c7871d7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200222125558-5a598a2470a0/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200501053045-e0ff5e5a1de5/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200506145744-7e3656a0809f/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200513185701-a91f0712d120/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200520182314-0ba52f642ac2/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= +golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= +golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= +golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= +golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45 h1:SVwTIAaPC2U/AvvLNZ2a7OVsmBpC8L5BlwK1whH3hm0= +golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/oauth2 v0.0.0-20191202225959-858c2ad4c8b6/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/oauth2 v0.0.0-20210323180902-22b0adad7558/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4 h1:YUO/7uOKsKeq9UokNS62b8FYywz3ker1l1vDZRCRefw= +golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200113162924-86b910548bc1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200122134326-e047566fdf82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200331124033-c3d80250170d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200501052902-10377860bb8e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200511232937-7e40ca221e25/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200515095857-1151b9dac4a9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200523222454-059865788121/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200803210538-64077c9b5642/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= +golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20190506145303-2d16b83fe98c/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191113191852-77e3bb0ad9e7/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191115202509-3a792d9c32b2/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191130070609-6e064ea0cf2d/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191216173652-a0e659d51361/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20191227053925-7b8e75db28f4/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200117161641-43d50277825c/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200122220014-bf1340f18c4a/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200204074204-1cc6d1ef6c74/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200207183749-b753a1ba74fa/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200212150539-ea181f53ac56/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200224181240-023911ca70b2/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200227222343-706bc42d1f0d/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200304193943-95d2e580d8eb/go.mod h1:o4KQGtdN14AW+yjsvvwRTJJuXz8XRtIHtEnmAXLyFUw= +golang.org/x/tools v0.0.0-20200312045724-11d5b4c81c7d/go.mod h1:o4KQGtdN14AW+yjsvvwRTJJuXz8XRtIHtEnmAXLyFUw= +golang.org/x/tools v0.0.0-20200331025713-a30bf2db82d4/go.mod h1:Sl4aGygMT6LrqrWclx+PTx3U+LnKx/seiNR+3G19Ar8= +golang.org/x/tools v0.0.0-20200501065659-ab2804fb9c9d/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20200512131952-2bc93b1c0c88/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20200515010526-7d3b6ebf133d/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20200618134242-20370b0cb4b2/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20200729194436-6467de6f59a7/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= +golang.org/x/tools v0.0.0-20200804011535-6c149bb5ef0d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= +golang.org/x/tools v0.0.0-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= +google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M= +google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= +google.golang.org/api v0.9.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= +google.golang.org/api v0.13.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= +google.golang.org/api v0.14.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= +google.golang.org/api v0.15.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= +google.golang.org/api v0.17.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= +google.golang.org/api v0.18.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= +google.golang.org/api v0.19.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= +google.golang.org/api v0.20.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= +google.golang.org/api v0.22.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= +google.golang.org/api v0.24.0/go.mod h1:lIXQywCXRcnZPGlsd8NbLnOjtAoL6em04bJ9+z0MncE= +google.golang.org/api v0.28.0/go.mod h1:lIXQywCXRcnZPGlsd8NbLnOjtAoL6em04bJ9+z0MncE= +google.golang.org/api v0.29.0/go.mod h1:Lcubydp8VUV7KeIHD9z2Bys/sm/vGKnG1UHuDBSrHWM= +google.golang.org/api v0.30.0/go.mod h1:QGmEvQ87FHZNiUVJkT14jQNYJ4ZJjdRF23ZXz5138Fc= +google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= +google.golang.org/appengine v1.4.0 h1:/wp5JvzpHIxhs/dumFmF7BXTf3Z+dd4uXta4kVyO508= +google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0= +google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= +google.golang.org/appengine v1.6.6/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= +google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= +google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190801165951-fa694d86fc64/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= +google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= +google.golang.org/genproto v0.0.0-20190911173649-1774047e7e51/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8= +google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20191115194625-c23dd37a84c9/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20191216164720-4f79533eabd1/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20191230161307-f3c370f40bfb/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20200115191322-ca5a22157cba/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20200122232147-0452cf42e150/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20200204135345-fa8e72b47b90/go.mod h1:GmwEX6Z4W5gMy59cAlVYjN9JhxgbQH6Gn+gFDQe2lzA= +google.golang.org/genproto v0.0.0-20200212174721-66ed5ce911ce/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200224152610-e50cd9704f63/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200228133532-8c2c7df3a383/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200305110556-506484158171/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200312145019-da6875a35672/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200331122359-1ee6d9798940/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200430143042-b979b6f78d84/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200511104702-f5ebc3bea380/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200515170657-fc4c6c6a6587/go.mod h1:YsZOwe1myG/8QRHRsmBRE1LrgQY60beZKjly0O1fX9U= +google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= +google.golang.org/genproto v0.0.0-20200618031413-b414f8b61790/go.mod h1:jDfRM7FcilCzHH/e9qn6dsT145K34l5v+OpcnNgKAAA= +google.golang.org/genproto v0.0.0-20200729003335-053ba62fc06f/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20200804131852-c06518451d9c/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20200825200019-8632dd797987/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= +google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= +google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= +google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= +google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= +google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= +google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= +google.golang.org/grpc v1.27.1/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= +google.golang.org/grpc v1.28.0/go.mod h1:rpkK4SK4GF4Ach/+MFLZUBavHOvF2JJB5uozKKal+60= +google.golang.org/grpc v1.29.1/go.mod h1:itym6AZVZYACWQqET3MqgPpjcuV5QH3BxFS3IjizoKk= +google.golang.org/grpc v1.30.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= +google.golang.org/grpc v1.31.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= +google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= +google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= +google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= +google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= +google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= +google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4= +google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= +honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= +honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= +rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= +rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0= +rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= diff --git a/dedicatedserver/model__metadata.go b/dedicatedserver/model__metadata.go new file mode 100644 index 0000000..4ff9030 --- /dev/null +++ b/dedicatedserver/model__metadata.go @@ -0,0 +1,210 @@ +/* +Leaseweb API for dedicated servers + +This documents the rest api dedicatedserver provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package dedicatedserver + +import ( + "encoding/json" +) + +// checks if the Metadata type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &Metadata{} + +// Metadata Metadata about the collection +type Metadata struct { + // Total amount of orders in this collection + TotalCount *float32 `json:"totalCount,omitempty"` + // The offset used to generate this response + Offset *float32 `json:"offset,omitempty"` + // The limit used to generate this response + Limit *float32 `json:"limit,omitempty"` +} + +// NewMetadata instantiates a new Metadata object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewMetadata() *Metadata { + this := Metadata{} + var offset float32 = 0 + this.Offset = &offset + var limit float32 = 5 + this.Limit = &limit + return &this +} + +// NewMetadataWithDefaults instantiates a new Metadata object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewMetadataWithDefaults() *Metadata { + this := Metadata{} + var offset float32 = 0 + this.Offset = &offset + var limit float32 = 5 + this.Limit = &limit + return &this +} + +// GetTotalCount returns the TotalCount field value if set, zero value otherwise. +func (o *Metadata) GetTotalCount() float32 { + if o == nil || IsNil(o.TotalCount) { + var ret float32 + return ret + } + return *o.TotalCount +} + +// GetTotalCountOk returns a tuple with the TotalCount field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Metadata) GetTotalCountOk() (*float32, bool) { + if o == nil || IsNil(o.TotalCount) { + return nil, false + } + return o.TotalCount, true +} + +// HasTotalCount returns a boolean if a field has been set. +func (o *Metadata) HasTotalCount() bool { + if o != nil && !IsNil(o.TotalCount) { + return true + } + + return false +} + +// SetTotalCount gets a reference to the given float32 and assigns it to the TotalCount field. +func (o *Metadata) SetTotalCount(v float32) { + o.TotalCount = &v +} + +// GetOffset returns the Offset field value if set, zero value otherwise. +func (o *Metadata) GetOffset() float32 { + if o == nil || IsNil(o.Offset) { + var ret float32 + return ret + } + return *o.Offset +} + +// GetOffsetOk returns a tuple with the Offset field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Metadata) GetOffsetOk() (*float32, bool) { + if o == nil || IsNil(o.Offset) { + return nil, false + } + return o.Offset, true +} + +// HasOffset returns a boolean if a field has been set. +func (o *Metadata) HasOffset() bool { + if o != nil && !IsNil(o.Offset) { + return true + } + + return false +} + +// SetOffset gets a reference to the given float32 and assigns it to the Offset field. +func (o *Metadata) SetOffset(v float32) { + o.Offset = &v +} + +// GetLimit returns the Limit field value if set, zero value otherwise. +func (o *Metadata) GetLimit() float32 { + if o == nil || IsNil(o.Limit) { + var ret float32 + return ret + } + return *o.Limit +} + +// GetLimitOk returns a tuple with the Limit field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Metadata) GetLimitOk() (*float32, bool) { + if o == nil || IsNil(o.Limit) { + return nil, false + } + return o.Limit, true +} + +// HasLimit returns a boolean if a field has been set. +func (o *Metadata) HasLimit() bool { + if o != nil && !IsNil(o.Limit) { + return true + } + + return false +} + +// SetLimit gets a reference to the given float32 and assigns it to the Limit field. +func (o *Metadata) SetLimit(v float32) { + o.Limit = &v +} + +func (o Metadata) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o Metadata) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.TotalCount) { + toSerialize["totalCount"] = o.TotalCount + } + if !IsNil(o.Offset) { + toSerialize["offset"] = o.Offset + } + if !IsNil(o.Limit) { + toSerialize["limit"] = o.Limit + } + return toSerialize, nil +} + +type NullableMetadata struct { + value *Metadata + isSet bool +} + +func (v NullableMetadata) Get() *Metadata { + return v.value +} + +func (v *NullableMetadata) Set(val *Metadata) { + v.value = val + v.isSet = true +} + +func (v NullableMetadata) IsSet() bool { + return v.isSet +} + +func (v *NullableMetadata) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableMetadata(val *Metadata) *NullableMetadata { + return &NullableMetadata{value: val, isSet: true} +} + +func (v NullableMetadata) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableMetadata) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/dedicatedserver/model_add_server_to_private_network_opts.go b/dedicatedserver/model_add_server_to_private_network_opts.go new file mode 100644 index 0000000..3fc1611 --- /dev/null +++ b/dedicatedserver/model_add_server_to_private_network_opts.go @@ -0,0 +1,159 @@ +/* +Leaseweb API for dedicated servers + +This documents the rest api dedicatedserver provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package dedicatedserver + +import ( + "encoding/json" + "bytes" + "fmt" +) + +// checks if the AddServerToPrivateNetworkOpts type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &AddServerToPrivateNetworkOpts{} + +// AddServerToPrivateNetworkOpts struct for AddServerToPrivateNetworkOpts +type AddServerToPrivateNetworkOpts struct { + LinkSpeed LinkSpeed `json:"linkSpeed"` +} + +type _AddServerToPrivateNetworkOpts AddServerToPrivateNetworkOpts + +// NewAddServerToPrivateNetworkOpts instantiates a new AddServerToPrivateNetworkOpts object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewAddServerToPrivateNetworkOpts(linkSpeed LinkSpeed) *AddServerToPrivateNetworkOpts { + this := AddServerToPrivateNetworkOpts{} + this.LinkSpeed = linkSpeed + return &this +} + +// NewAddServerToPrivateNetworkOptsWithDefaults instantiates a new AddServerToPrivateNetworkOpts object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewAddServerToPrivateNetworkOptsWithDefaults() *AddServerToPrivateNetworkOpts { + this := AddServerToPrivateNetworkOpts{} + return &this +} + +// GetLinkSpeed returns the LinkSpeed field value +func (o *AddServerToPrivateNetworkOpts) GetLinkSpeed() LinkSpeed { + if o == nil { + var ret LinkSpeed + return ret + } + + return o.LinkSpeed +} + +// GetLinkSpeedOk returns a tuple with the LinkSpeed field value +// and a boolean to check if the value has been set. +func (o *AddServerToPrivateNetworkOpts) GetLinkSpeedOk() (*LinkSpeed, bool) { + if o == nil { + return nil, false + } + return &o.LinkSpeed, true +} + +// SetLinkSpeed sets field value +func (o *AddServerToPrivateNetworkOpts) SetLinkSpeed(v LinkSpeed) { + o.LinkSpeed = v +} + +func (o AddServerToPrivateNetworkOpts) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o AddServerToPrivateNetworkOpts) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + toSerialize["linkSpeed"] = o.LinkSpeed + return toSerialize, nil +} + +func (o *AddServerToPrivateNetworkOpts) UnmarshalJSON(data []byte) (err error) { + // This validates that all required properties are included in the JSON object + // by unmarshalling the object into a generic map with string keys and checking + // that every required field exists as a key in the generic map. + requiredProperties := []string{ + "linkSpeed", + } + + allProperties := make(map[string]interface{}) + + err = json.Unmarshal(data, &allProperties) + + if err != nil { + return err; + } + + for _, requiredProperty := range(requiredProperties) { + if _, exists := allProperties[requiredProperty]; !exists { + return fmt.Errorf("no value given for required property %v", requiredProperty) + } + } + + varAddServerToPrivateNetworkOpts := _AddServerToPrivateNetworkOpts{} + + decoder := json.NewDecoder(bytes.NewReader(data)) + decoder.DisallowUnknownFields() + err = decoder.Decode(&varAddServerToPrivateNetworkOpts) + + if err != nil { + return err + } + + *o = AddServerToPrivateNetworkOpts(varAddServerToPrivateNetworkOpts) + + return err +} + +type NullableAddServerToPrivateNetworkOpts struct { + value *AddServerToPrivateNetworkOpts + isSet bool +} + +func (v NullableAddServerToPrivateNetworkOpts) Get() *AddServerToPrivateNetworkOpts { + return v.value +} + +func (v *NullableAddServerToPrivateNetworkOpts) Set(val *AddServerToPrivateNetworkOpts) { + v.value = val + v.isSet = true +} + +func (v NullableAddServerToPrivateNetworkOpts) IsSet() bool { + return v.isSet +} + +func (v *NullableAddServerToPrivateNetworkOpts) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableAddServerToPrivateNetworkOpts(val *AddServerToPrivateNetworkOpts) *NullableAddServerToPrivateNetworkOpts { + return &NullableAddServerToPrivateNetworkOpts{value: val, isSet: true} +} + +func (v NullableAddServerToPrivateNetworkOpts) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableAddServerToPrivateNetworkOpts) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/dedicatedserver/model_cpu.go b/dedicatedserver/model_cpu.go new file mode 100644 index 0000000..60c6d0a --- /dev/null +++ b/dedicatedserver/model_cpu.go @@ -0,0 +1,165 @@ +/* +Leaseweb API for dedicated servers + +This documents the rest api dedicatedserver provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package dedicatedserver + +import ( + "encoding/json" +) + +// checks if the Cpu type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &Cpu{} + +// Cpu CPU of the server +type Cpu struct { + // The quantity of CPUs in the server + Quantity *int32 `json:"quantity,omitempty"` + // The type of CPUs in the server + Type *string `json:"type,omitempty"` +} + +// NewCpu instantiates a new Cpu object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewCpu() *Cpu { + this := Cpu{} + return &this +} + +// NewCpuWithDefaults instantiates a new Cpu object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewCpuWithDefaults() *Cpu { + this := Cpu{} + return &this +} + +// GetQuantity returns the Quantity field value if set, zero value otherwise. +func (o *Cpu) GetQuantity() int32 { + if o == nil || IsNil(o.Quantity) { + var ret int32 + return ret + } + return *o.Quantity +} + +// GetQuantityOk returns a tuple with the Quantity field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Cpu) GetQuantityOk() (*int32, bool) { + if o == nil || IsNil(o.Quantity) { + return nil, false + } + return o.Quantity, true +} + +// HasQuantity returns a boolean if a field has been set. +func (o *Cpu) HasQuantity() bool { + if o != nil && !IsNil(o.Quantity) { + return true + } + + return false +} + +// SetQuantity gets a reference to the given int32 and assigns it to the Quantity field. +func (o *Cpu) SetQuantity(v int32) { + o.Quantity = &v +} + +// GetType returns the Type field value if set, zero value otherwise. +func (o *Cpu) GetType() string { + if o == nil || IsNil(o.Type) { + var ret string + return ret + } + return *o.Type +} + +// GetTypeOk returns a tuple with the Type field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Cpu) GetTypeOk() (*string, bool) { + if o == nil || IsNil(o.Type) { + return nil, false + } + return o.Type, true +} + +// HasType returns a boolean if a field has been set. +func (o *Cpu) HasType() bool { + if o != nil && !IsNil(o.Type) { + return true + } + + return false +} + +// SetType gets a reference to the given string and assigns it to the Type field. +func (o *Cpu) SetType(v string) { + o.Type = &v +} + +func (o Cpu) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o Cpu) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Quantity) { + toSerialize["quantity"] = o.Quantity + } + if !IsNil(o.Type) { + toSerialize["type"] = o.Type + } + return toSerialize, nil +} + +type NullableCpu struct { + value *Cpu + isSet bool +} + +func (v NullableCpu) Get() *Cpu { + return v.value +} + +func (v *NullableCpu) Set(val *Cpu) { + v.value = val + v.isSet = true +} + +func (v NullableCpu) IsSet() bool { + return v.isSet +} + +func (v *NullableCpu) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableCpu(val *Cpu) *NullableCpu { + return &NullableCpu{value: val, isSet: true} +} + +func (v NullableCpu) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableCpu) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/dedicatedserver/model_d_dos.go b/dedicatedserver/model_d_dos.go new file mode 100644 index 0000000..c811a97 --- /dev/null +++ b/dedicatedserver/model_d_dos.go @@ -0,0 +1,165 @@ +/* +Leaseweb API for dedicated servers + +This documents the rest api dedicatedserver provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package dedicatedserver + +import ( + "encoding/json" +) + +// checks if the DDos type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &DDos{} + +// DDos DDoS IP Protection Details +type DDos struct { + // The applied detection profile + DetectionProfile *string `json:"detectionProfile,omitempty"` + // The type of DDoS protection + ProtectionType *string `json:"protectionType,omitempty"` +} + +// NewDDos instantiates a new DDos object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewDDos() *DDos { + this := DDos{} + return &this +} + +// NewDDosWithDefaults instantiates a new DDos object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewDDosWithDefaults() *DDos { + this := DDos{} + return &this +} + +// GetDetectionProfile returns the DetectionProfile field value if set, zero value otherwise. +func (o *DDos) GetDetectionProfile() string { + if o == nil || IsNil(o.DetectionProfile) { + var ret string + return ret + } + return *o.DetectionProfile +} + +// GetDetectionProfileOk returns a tuple with the DetectionProfile field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *DDos) GetDetectionProfileOk() (*string, bool) { + if o == nil || IsNil(o.DetectionProfile) { + return nil, false + } + return o.DetectionProfile, true +} + +// HasDetectionProfile returns a boolean if a field has been set. +func (o *DDos) HasDetectionProfile() bool { + if o != nil && !IsNil(o.DetectionProfile) { + return true + } + + return false +} + +// SetDetectionProfile gets a reference to the given string and assigns it to the DetectionProfile field. +func (o *DDos) SetDetectionProfile(v string) { + o.DetectionProfile = &v +} + +// GetProtectionType returns the ProtectionType field value if set, zero value otherwise. +func (o *DDos) GetProtectionType() string { + if o == nil || IsNil(o.ProtectionType) { + var ret string + return ret + } + return *o.ProtectionType +} + +// GetProtectionTypeOk returns a tuple with the ProtectionType field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *DDos) GetProtectionTypeOk() (*string, bool) { + if o == nil || IsNil(o.ProtectionType) { + return nil, false + } + return o.ProtectionType, true +} + +// HasProtectionType returns a boolean if a field has been set. +func (o *DDos) HasProtectionType() bool { + if o != nil && !IsNil(o.ProtectionType) { + return true + } + + return false +} + +// SetProtectionType gets a reference to the given string and assigns it to the ProtectionType field. +func (o *DDos) SetProtectionType(v string) { + o.ProtectionType = &v +} + +func (o DDos) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o DDos) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.DetectionProfile) { + toSerialize["detectionProfile"] = o.DetectionProfile + } + if !IsNil(o.ProtectionType) { + toSerialize["protectionType"] = o.ProtectionType + } + return toSerialize, nil +} + +type NullableDDos struct { + value *DDos + isSet bool +} + +func (v NullableDDos) Get() *DDos { + return v.value +} + +func (v *NullableDDos) Set(val *DDos) { + v.value = val + v.isSet = true +} + +func (v NullableDDos) IsSet() bool { + return v.isSet +} + +func (v *NullableDDos) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableDDos(val *DDos) *NullableDDos { + return &NullableDDos{value: val, isSet: true} +} + +func (v NullableDDos) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableDDos) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/dedicatedserver/model_error_result.go b/dedicatedserver/model_error_result.go new file mode 100644 index 0000000..917e39e --- /dev/null +++ b/dedicatedserver/model_error_result.go @@ -0,0 +1,238 @@ +/* +Leaseweb API for dedicated servers + +This documents the rest api dedicatedserver provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package dedicatedserver + +import ( + "encoding/json" +) + +// checks if the ErrorResult type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &ErrorResult{} + +// ErrorResult struct for ErrorResult +type ErrorResult struct { + // The correlation ID of the current request. + CorrelationId *string `json:"correlationId,omitempty"` + // The error code. + ErrorCode *string `json:"errorCode,omitempty"` + // A human friendly description of the error. + ErrorMessage *string `json:"errorMessage,omitempty"` + ErrorDetails []map[string][]string `json:"errorDetails,omitempty"` +} + +// NewErrorResult instantiates a new ErrorResult object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewErrorResult() *ErrorResult { + this := ErrorResult{} + return &this +} + +// NewErrorResultWithDefaults instantiates a new ErrorResult object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewErrorResultWithDefaults() *ErrorResult { + this := ErrorResult{} + return &this +} + +// GetCorrelationId returns the CorrelationId field value if set, zero value otherwise. +func (o *ErrorResult) GetCorrelationId() string { + if o == nil || IsNil(o.CorrelationId) { + var ret string + return ret + } + return *o.CorrelationId +} + +// GetCorrelationIdOk returns a tuple with the CorrelationId field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ErrorResult) GetCorrelationIdOk() (*string, bool) { + if o == nil || IsNil(o.CorrelationId) { + return nil, false + } + return o.CorrelationId, true +} + +// HasCorrelationId returns a boolean if a field has been set. +func (o *ErrorResult) HasCorrelationId() bool { + if o != nil && !IsNil(o.CorrelationId) { + return true + } + + return false +} + +// SetCorrelationId gets a reference to the given string and assigns it to the CorrelationId field. +func (o *ErrorResult) SetCorrelationId(v string) { + o.CorrelationId = &v +} + +// GetErrorCode returns the ErrorCode field value if set, zero value otherwise. +func (o *ErrorResult) GetErrorCode() string { + if o == nil || IsNil(o.ErrorCode) { + var ret string + return ret + } + return *o.ErrorCode +} + +// GetErrorCodeOk returns a tuple with the ErrorCode field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ErrorResult) GetErrorCodeOk() (*string, bool) { + if o == nil || IsNil(o.ErrorCode) { + return nil, false + } + return o.ErrorCode, true +} + +// HasErrorCode returns a boolean if a field has been set. +func (o *ErrorResult) HasErrorCode() bool { + if o != nil && !IsNil(o.ErrorCode) { + return true + } + + return false +} + +// SetErrorCode gets a reference to the given string and assigns it to the ErrorCode field. +func (o *ErrorResult) SetErrorCode(v string) { + o.ErrorCode = &v +} + +// GetErrorMessage returns the ErrorMessage field value if set, zero value otherwise. +func (o *ErrorResult) GetErrorMessage() string { + if o == nil || IsNil(o.ErrorMessage) { + var ret string + return ret + } + return *o.ErrorMessage +} + +// GetErrorMessageOk returns a tuple with the ErrorMessage field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ErrorResult) GetErrorMessageOk() (*string, bool) { + if o == nil || IsNil(o.ErrorMessage) { + return nil, false + } + return o.ErrorMessage, true +} + +// HasErrorMessage returns a boolean if a field has been set. +func (o *ErrorResult) HasErrorMessage() bool { + if o != nil && !IsNil(o.ErrorMessage) { + return true + } + + return false +} + +// SetErrorMessage gets a reference to the given string and assigns it to the ErrorMessage field. +func (o *ErrorResult) SetErrorMessage(v string) { + o.ErrorMessage = &v +} + +// GetErrorDetails returns the ErrorDetails field value if set, zero value otherwise. +func (o *ErrorResult) GetErrorDetails() []map[string][]string { + if o == nil || IsNil(o.ErrorDetails) { + var ret []map[string][]string + return ret + } + return o.ErrorDetails +} + +// GetErrorDetailsOk returns a tuple with the ErrorDetails field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ErrorResult) GetErrorDetailsOk() ([]map[string][]string, bool) { + if o == nil || IsNil(o.ErrorDetails) { + return nil, false + } + return o.ErrorDetails, true +} + +// HasErrorDetails returns a boolean if a field has been set. +func (o *ErrorResult) HasErrorDetails() bool { + if o != nil && !IsNil(o.ErrorDetails) { + return true + } + + return false +} + +// SetErrorDetails gets a reference to the given []map[string][]string and assigns it to the ErrorDetails field. +func (o *ErrorResult) SetErrorDetails(v []map[string][]string) { + o.ErrorDetails = v +} + +func (o ErrorResult) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o ErrorResult) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.CorrelationId) { + toSerialize["correlationId"] = o.CorrelationId + } + if !IsNil(o.ErrorCode) { + toSerialize["errorCode"] = o.ErrorCode + } + if !IsNil(o.ErrorMessage) { + toSerialize["errorMessage"] = o.ErrorMessage + } + if !IsNil(o.ErrorDetails) { + toSerialize["errorDetails"] = o.ErrorDetails + } + return toSerialize, nil +} + +type NullableErrorResult struct { + value *ErrorResult + isSet bool +} + +func (v NullableErrorResult) Get() *ErrorResult { + return v.value +} + +func (v *NullableErrorResult) Set(val *ErrorResult) { + v.value = val + v.isSet = true +} + +func (v NullableErrorResult) IsSet() bool { + return v.isSet +} + +func (v *NullableErrorResult) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableErrorResult(val *ErrorResult) *NullableErrorResult { + return &NullableErrorResult{value: val, isSet: true} +} + +func (v NullableErrorResult) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableErrorResult) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/dedicatedserver/model_get_network_equipment_ip_list_result.go b/dedicatedserver/model_get_network_equipment_ip_list_result.go new file mode 100644 index 0000000..32049fa --- /dev/null +++ b/dedicatedserver/model_get_network_equipment_ip_list_result.go @@ -0,0 +1,164 @@ +/* +Leaseweb API for dedicated servers + +This documents the rest api dedicatedserver provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package dedicatedserver + +import ( + "encoding/json" +) + +// checks if the GetNetworkEquipmentIpListResult type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &GetNetworkEquipmentIpListResult{} + +// GetNetworkEquipmentIpListResult struct for GetNetworkEquipmentIpListResult +type GetNetworkEquipmentIpListResult struct { + Metadata *Metadata `json:"_metadata,omitempty"` + // An array of IP addresses + Ips []Ip `json:"ips,omitempty"` +} + +// NewGetNetworkEquipmentIpListResult instantiates a new GetNetworkEquipmentIpListResult object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewGetNetworkEquipmentIpListResult() *GetNetworkEquipmentIpListResult { + this := GetNetworkEquipmentIpListResult{} + return &this +} + +// NewGetNetworkEquipmentIpListResultWithDefaults instantiates a new GetNetworkEquipmentIpListResult object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewGetNetworkEquipmentIpListResultWithDefaults() *GetNetworkEquipmentIpListResult { + this := GetNetworkEquipmentIpListResult{} + return &this +} + +// GetMetadata returns the Metadata field value if set, zero value otherwise. +func (o *GetNetworkEquipmentIpListResult) GetMetadata() Metadata { + if o == nil || IsNil(o.Metadata) { + var ret Metadata + return ret + } + return *o.Metadata +} + +// GetMetadataOk returns a tuple with the Metadata field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetNetworkEquipmentIpListResult) GetMetadataOk() (*Metadata, bool) { + if o == nil || IsNil(o.Metadata) { + return nil, false + } + return o.Metadata, true +} + +// HasMetadata returns a boolean if a field has been set. +func (o *GetNetworkEquipmentIpListResult) HasMetadata() bool { + if o != nil && !IsNil(o.Metadata) { + return true + } + + return false +} + +// SetMetadata gets a reference to the given Metadata and assigns it to the Metadata field. +func (o *GetNetworkEquipmentIpListResult) SetMetadata(v Metadata) { + o.Metadata = &v +} + +// GetIps returns the Ips field value if set, zero value otherwise. +func (o *GetNetworkEquipmentIpListResult) GetIps() []Ip { + if o == nil || IsNil(o.Ips) { + var ret []Ip + return ret + } + return o.Ips +} + +// GetIpsOk returns a tuple with the Ips field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetNetworkEquipmentIpListResult) GetIpsOk() ([]Ip, bool) { + if o == nil || IsNil(o.Ips) { + return nil, false + } + return o.Ips, true +} + +// HasIps returns a boolean if a field has been set. +func (o *GetNetworkEquipmentIpListResult) HasIps() bool { + if o != nil && !IsNil(o.Ips) { + return true + } + + return false +} + +// SetIps gets a reference to the given []Ip and assigns it to the Ips field. +func (o *GetNetworkEquipmentIpListResult) SetIps(v []Ip) { + o.Ips = v +} + +func (o GetNetworkEquipmentIpListResult) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o GetNetworkEquipmentIpListResult) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Metadata) { + toSerialize["_metadata"] = o.Metadata + } + if !IsNil(o.Ips) { + toSerialize["ips"] = o.Ips + } + return toSerialize, nil +} + +type NullableGetNetworkEquipmentIpListResult struct { + value *GetNetworkEquipmentIpListResult + isSet bool +} + +func (v NullableGetNetworkEquipmentIpListResult) Get() *GetNetworkEquipmentIpListResult { + return v.value +} + +func (v *NullableGetNetworkEquipmentIpListResult) Set(val *GetNetworkEquipmentIpListResult) { + v.value = val + v.isSet = true +} + +func (v NullableGetNetworkEquipmentIpListResult) IsSet() bool { + return v.isSet +} + +func (v *NullableGetNetworkEquipmentIpListResult) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableGetNetworkEquipmentIpListResult(val *GetNetworkEquipmentIpListResult) *NullableGetNetworkEquipmentIpListResult { + return &NullableGetNetworkEquipmentIpListResult{value: val, isSet: true} +} + +func (v NullableGetNetworkEquipmentIpListResult) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableGetNetworkEquipmentIpListResult) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/dedicatedserver/model_get_network_equipment_list_result.go b/dedicatedserver/model_get_network_equipment_list_result.go new file mode 100644 index 0000000..d882646 --- /dev/null +++ b/dedicatedserver/model_get_network_equipment_list_result.go @@ -0,0 +1,164 @@ +/* +Leaseweb API for dedicated servers + +This documents the rest api dedicatedserver provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package dedicatedserver + +import ( + "encoding/json" +) + +// checks if the GetNetworkEquipmentListResult type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &GetNetworkEquipmentListResult{} + +// GetNetworkEquipmentListResult struct for GetNetworkEquipmentListResult +type GetNetworkEquipmentListResult struct { + Metadata *Metadata `json:"_metadata,omitempty"` + // An array of network equipment + NetworkEquipments []NetworkEquipment `json:"networkEquipments,omitempty"` +} + +// NewGetNetworkEquipmentListResult instantiates a new GetNetworkEquipmentListResult object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewGetNetworkEquipmentListResult() *GetNetworkEquipmentListResult { + this := GetNetworkEquipmentListResult{} + return &this +} + +// NewGetNetworkEquipmentListResultWithDefaults instantiates a new GetNetworkEquipmentListResult object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewGetNetworkEquipmentListResultWithDefaults() *GetNetworkEquipmentListResult { + this := GetNetworkEquipmentListResult{} + return &this +} + +// GetMetadata returns the Metadata field value if set, zero value otherwise. +func (o *GetNetworkEquipmentListResult) GetMetadata() Metadata { + if o == nil || IsNil(o.Metadata) { + var ret Metadata + return ret + } + return *o.Metadata +} + +// GetMetadataOk returns a tuple with the Metadata field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetNetworkEquipmentListResult) GetMetadataOk() (*Metadata, bool) { + if o == nil || IsNil(o.Metadata) { + return nil, false + } + return o.Metadata, true +} + +// HasMetadata returns a boolean if a field has been set. +func (o *GetNetworkEquipmentListResult) HasMetadata() bool { + if o != nil && !IsNil(o.Metadata) { + return true + } + + return false +} + +// SetMetadata gets a reference to the given Metadata and assigns it to the Metadata field. +func (o *GetNetworkEquipmentListResult) SetMetadata(v Metadata) { + o.Metadata = &v +} + +// GetNetworkEquipments returns the NetworkEquipments field value if set, zero value otherwise. +func (o *GetNetworkEquipmentListResult) GetNetworkEquipments() []NetworkEquipment { + if o == nil || IsNil(o.NetworkEquipments) { + var ret []NetworkEquipment + return ret + } + return o.NetworkEquipments +} + +// GetNetworkEquipmentsOk returns a tuple with the NetworkEquipments field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetNetworkEquipmentListResult) GetNetworkEquipmentsOk() ([]NetworkEquipment, bool) { + if o == nil || IsNil(o.NetworkEquipments) { + return nil, false + } + return o.NetworkEquipments, true +} + +// HasNetworkEquipments returns a boolean if a field has been set. +func (o *GetNetworkEquipmentListResult) HasNetworkEquipments() bool { + if o != nil && !IsNil(o.NetworkEquipments) { + return true + } + + return false +} + +// SetNetworkEquipments gets a reference to the given []NetworkEquipment and assigns it to the NetworkEquipments field. +func (o *GetNetworkEquipmentListResult) SetNetworkEquipments(v []NetworkEquipment) { + o.NetworkEquipments = v +} + +func (o GetNetworkEquipmentListResult) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o GetNetworkEquipmentListResult) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Metadata) { + toSerialize["_metadata"] = o.Metadata + } + if !IsNil(o.NetworkEquipments) { + toSerialize["networkEquipments"] = o.NetworkEquipments + } + return toSerialize, nil +} + +type NullableGetNetworkEquipmentListResult struct { + value *GetNetworkEquipmentListResult + isSet bool +} + +func (v NullableGetNetworkEquipmentListResult) Get() *GetNetworkEquipmentListResult { + return v.value +} + +func (v *NullableGetNetworkEquipmentListResult) Set(val *GetNetworkEquipmentListResult) { + v.value = val + v.isSet = true +} + +func (v NullableGetNetworkEquipmentListResult) IsSet() bool { + return v.isSet +} + +func (v *NullableGetNetworkEquipmentListResult) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableGetNetworkEquipmentListResult(val *GetNetworkEquipmentListResult) *NullableGetNetworkEquipmentListResult { + return &NullableGetNetworkEquipmentListResult{value: val, isSet: true} +} + +func (v NullableGetNetworkEquipmentListResult) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableGetNetworkEquipmentListResult) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/dedicatedserver/model_get_network_equipment_null_route_history_result.go b/dedicatedserver/model_get_network_equipment_null_route_history_result.go new file mode 100644 index 0000000..07bd849 --- /dev/null +++ b/dedicatedserver/model_get_network_equipment_null_route_history_result.go @@ -0,0 +1,164 @@ +/* +Leaseweb API for dedicated servers + +This documents the rest api dedicatedserver provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package dedicatedserver + +import ( + "encoding/json" +) + +// checks if the GetNetworkEquipmentNullRouteHistoryResult type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &GetNetworkEquipmentNullRouteHistoryResult{} + +// GetNetworkEquipmentNullRouteHistoryResult struct for GetNetworkEquipmentNullRouteHistoryResult +type GetNetworkEquipmentNullRouteHistoryResult struct { + Metadata *Metadata `json:"_metadata,omitempty"` + // An array of network equipment null route events + NullRoutes []NullRoute `json:"nullRoutes,omitempty"` +} + +// NewGetNetworkEquipmentNullRouteHistoryResult instantiates a new GetNetworkEquipmentNullRouteHistoryResult object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewGetNetworkEquipmentNullRouteHistoryResult() *GetNetworkEquipmentNullRouteHistoryResult { + this := GetNetworkEquipmentNullRouteHistoryResult{} + return &this +} + +// NewGetNetworkEquipmentNullRouteHistoryResultWithDefaults instantiates a new GetNetworkEquipmentNullRouteHistoryResult object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewGetNetworkEquipmentNullRouteHistoryResultWithDefaults() *GetNetworkEquipmentNullRouteHistoryResult { + this := GetNetworkEquipmentNullRouteHistoryResult{} + return &this +} + +// GetMetadata returns the Metadata field value if set, zero value otherwise. +func (o *GetNetworkEquipmentNullRouteHistoryResult) GetMetadata() Metadata { + if o == nil || IsNil(o.Metadata) { + var ret Metadata + return ret + } + return *o.Metadata +} + +// GetMetadataOk returns a tuple with the Metadata field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetNetworkEquipmentNullRouteHistoryResult) GetMetadataOk() (*Metadata, bool) { + if o == nil || IsNil(o.Metadata) { + return nil, false + } + return o.Metadata, true +} + +// HasMetadata returns a boolean if a field has been set. +func (o *GetNetworkEquipmentNullRouteHistoryResult) HasMetadata() bool { + if o != nil && !IsNil(o.Metadata) { + return true + } + + return false +} + +// SetMetadata gets a reference to the given Metadata and assigns it to the Metadata field. +func (o *GetNetworkEquipmentNullRouteHistoryResult) SetMetadata(v Metadata) { + o.Metadata = &v +} + +// GetNullRoutes returns the NullRoutes field value if set, zero value otherwise. +func (o *GetNetworkEquipmentNullRouteHistoryResult) GetNullRoutes() []NullRoute { + if o == nil || IsNil(o.NullRoutes) { + var ret []NullRoute + return ret + } + return o.NullRoutes +} + +// GetNullRoutesOk returns a tuple with the NullRoutes field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetNetworkEquipmentNullRouteHistoryResult) GetNullRoutesOk() ([]NullRoute, bool) { + if o == nil || IsNil(o.NullRoutes) { + return nil, false + } + return o.NullRoutes, true +} + +// HasNullRoutes returns a boolean if a field has been set. +func (o *GetNetworkEquipmentNullRouteHistoryResult) HasNullRoutes() bool { + if o != nil && !IsNil(o.NullRoutes) { + return true + } + + return false +} + +// SetNullRoutes gets a reference to the given []NullRoute and assigns it to the NullRoutes field. +func (o *GetNetworkEquipmentNullRouteHistoryResult) SetNullRoutes(v []NullRoute) { + o.NullRoutes = v +} + +func (o GetNetworkEquipmentNullRouteHistoryResult) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o GetNetworkEquipmentNullRouteHistoryResult) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Metadata) { + toSerialize["_metadata"] = o.Metadata + } + if !IsNil(o.NullRoutes) { + toSerialize["nullRoutes"] = o.NullRoutes + } + return toSerialize, nil +} + +type NullableGetNetworkEquipmentNullRouteHistoryResult struct { + value *GetNetworkEquipmentNullRouteHistoryResult + isSet bool +} + +func (v NullableGetNetworkEquipmentNullRouteHistoryResult) Get() *GetNetworkEquipmentNullRouteHistoryResult { + return v.value +} + +func (v *NullableGetNetworkEquipmentNullRouteHistoryResult) Set(val *GetNetworkEquipmentNullRouteHistoryResult) { + v.value = val + v.isSet = true +} + +func (v NullableGetNetworkEquipmentNullRouteHistoryResult) IsSet() bool { + return v.isSet +} + +func (v *NullableGetNetworkEquipmentNullRouteHistoryResult) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableGetNetworkEquipmentNullRouteHistoryResult(val *GetNetworkEquipmentNullRouteHistoryResult) *NullableGetNetworkEquipmentNullRouteHistoryResult { + return &NullableGetNetworkEquipmentNullRouteHistoryResult{value: val, isSet: true} +} + +func (v NullableGetNetworkEquipmentNullRouteHistoryResult) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableGetNetworkEquipmentNullRouteHistoryResult) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/dedicatedserver/model_get_server_list_result.go b/dedicatedserver/model_get_server_list_result.go new file mode 100644 index 0000000..4e3403f --- /dev/null +++ b/dedicatedserver/model_get_server_list_result.go @@ -0,0 +1,164 @@ +/* +Leaseweb API for dedicated servers + +This documents the rest api dedicatedserver provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package dedicatedserver + +import ( + "encoding/json" +) + +// checks if the GetServerListResult type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &GetServerListResult{} + +// GetServerListResult struct for GetServerListResult +type GetServerListResult struct { + Metadata *Metadata `json:"_metadata,omitempty"` + // An array of servers + Servers []Server `json:"servers,omitempty"` +} + +// NewGetServerListResult instantiates a new GetServerListResult object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewGetServerListResult() *GetServerListResult { + this := GetServerListResult{} + return &this +} + +// NewGetServerListResultWithDefaults instantiates a new GetServerListResult object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewGetServerListResultWithDefaults() *GetServerListResult { + this := GetServerListResult{} + return &this +} + +// GetMetadata returns the Metadata field value if set, zero value otherwise. +func (o *GetServerListResult) GetMetadata() Metadata { + if o == nil || IsNil(o.Metadata) { + var ret Metadata + return ret + } + return *o.Metadata +} + +// GetMetadataOk returns a tuple with the Metadata field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetServerListResult) GetMetadataOk() (*Metadata, bool) { + if o == nil || IsNil(o.Metadata) { + return nil, false + } + return o.Metadata, true +} + +// HasMetadata returns a boolean if a field has been set. +func (o *GetServerListResult) HasMetadata() bool { + if o != nil && !IsNil(o.Metadata) { + return true + } + + return false +} + +// SetMetadata gets a reference to the given Metadata and assigns it to the Metadata field. +func (o *GetServerListResult) SetMetadata(v Metadata) { + o.Metadata = &v +} + +// GetServers returns the Servers field value if set, zero value otherwise. +func (o *GetServerListResult) GetServers() []Server { + if o == nil || IsNil(o.Servers) { + var ret []Server + return ret + } + return o.Servers +} + +// GetServersOk returns a tuple with the Servers field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetServerListResult) GetServersOk() ([]Server, bool) { + if o == nil || IsNil(o.Servers) { + return nil, false + } + return o.Servers, true +} + +// HasServers returns a boolean if a field has been set. +func (o *GetServerListResult) HasServers() bool { + if o != nil && !IsNil(o.Servers) { + return true + } + + return false +} + +// SetServers gets a reference to the given []Server and assigns it to the Servers field. +func (o *GetServerListResult) SetServers(v []Server) { + o.Servers = v +} + +func (o GetServerListResult) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o GetServerListResult) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Metadata) { + toSerialize["_metadata"] = o.Metadata + } + if !IsNil(o.Servers) { + toSerialize["servers"] = o.Servers + } + return toSerialize, nil +} + +type NullableGetServerListResult struct { + value *GetServerListResult + isSet bool +} + +func (v NullableGetServerListResult) Get() *GetServerListResult { + return v.value +} + +func (v *NullableGetServerListResult) Set(val *GetServerListResult) { + v.value = val + v.isSet = true +} + +func (v NullableGetServerListResult) IsSet() bool { + return v.isSet +} + +func (v *NullableGetServerListResult) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableGetServerListResult(val *GetServerListResult) *NullableGetServerListResult { + return &NullableGetServerListResult{value: val, isSet: true} +} + +func (v NullableGetServerListResult) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableGetServerListResult) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/dedicatedserver/model_get_server_null_route_history_result.go b/dedicatedserver/model_get_server_null_route_history_result.go new file mode 100644 index 0000000..9f2fc60 --- /dev/null +++ b/dedicatedserver/model_get_server_null_route_history_result.go @@ -0,0 +1,164 @@ +/* +Leaseweb API for dedicated servers + +This documents the rest api dedicatedserver provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package dedicatedserver + +import ( + "encoding/json" +) + +// checks if the GetServerNullRouteHistoryResult type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &GetServerNullRouteHistoryResult{} + +// GetServerNullRouteHistoryResult struct for GetServerNullRouteHistoryResult +type GetServerNullRouteHistoryResult struct { + Metadata *Metadata `json:"_metadata,omitempty"` + // An array of server null route events + NullRoutes []NullRoute `json:"nullRoutes,omitempty"` +} + +// NewGetServerNullRouteHistoryResult instantiates a new GetServerNullRouteHistoryResult object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewGetServerNullRouteHistoryResult() *GetServerNullRouteHistoryResult { + this := GetServerNullRouteHistoryResult{} + return &this +} + +// NewGetServerNullRouteHistoryResultWithDefaults instantiates a new GetServerNullRouteHistoryResult object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewGetServerNullRouteHistoryResultWithDefaults() *GetServerNullRouteHistoryResult { + this := GetServerNullRouteHistoryResult{} + return &this +} + +// GetMetadata returns the Metadata field value if set, zero value otherwise. +func (o *GetServerNullRouteHistoryResult) GetMetadata() Metadata { + if o == nil || IsNil(o.Metadata) { + var ret Metadata + return ret + } + return *o.Metadata +} + +// GetMetadataOk returns a tuple with the Metadata field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetServerNullRouteHistoryResult) GetMetadataOk() (*Metadata, bool) { + if o == nil || IsNil(o.Metadata) { + return nil, false + } + return o.Metadata, true +} + +// HasMetadata returns a boolean if a field has been set. +func (o *GetServerNullRouteHistoryResult) HasMetadata() bool { + if o != nil && !IsNil(o.Metadata) { + return true + } + + return false +} + +// SetMetadata gets a reference to the given Metadata and assigns it to the Metadata field. +func (o *GetServerNullRouteHistoryResult) SetMetadata(v Metadata) { + o.Metadata = &v +} + +// GetNullRoutes returns the NullRoutes field value if set, zero value otherwise. +func (o *GetServerNullRouteHistoryResult) GetNullRoutes() []NullRoute { + if o == nil || IsNil(o.NullRoutes) { + var ret []NullRoute + return ret + } + return o.NullRoutes +} + +// GetNullRoutesOk returns a tuple with the NullRoutes field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetServerNullRouteHistoryResult) GetNullRoutesOk() ([]NullRoute, bool) { + if o == nil || IsNil(o.NullRoutes) { + return nil, false + } + return o.NullRoutes, true +} + +// HasNullRoutes returns a boolean if a field has been set. +func (o *GetServerNullRouteHistoryResult) HasNullRoutes() bool { + if o != nil && !IsNil(o.NullRoutes) { + return true + } + + return false +} + +// SetNullRoutes gets a reference to the given []NullRoute and assigns it to the NullRoutes field. +func (o *GetServerNullRouteHistoryResult) SetNullRoutes(v []NullRoute) { + o.NullRoutes = v +} + +func (o GetServerNullRouteHistoryResult) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o GetServerNullRouteHistoryResult) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Metadata) { + toSerialize["_metadata"] = o.Metadata + } + if !IsNil(o.NullRoutes) { + toSerialize["nullRoutes"] = o.NullRoutes + } + return toSerialize, nil +} + +type NullableGetServerNullRouteHistoryResult struct { + value *GetServerNullRouteHistoryResult + isSet bool +} + +func (v NullableGetServerNullRouteHistoryResult) Get() *GetServerNullRouteHistoryResult { + return v.value +} + +func (v *NullableGetServerNullRouteHistoryResult) Set(val *GetServerNullRouteHistoryResult) { + v.value = val + v.isSet = true +} + +func (v NullableGetServerNullRouteHistoryResult) IsSet() bool { + return v.isSet +} + +func (v *NullableGetServerNullRouteHistoryResult) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableGetServerNullRouteHistoryResult(val *GetServerNullRouteHistoryResult) *NullableGetServerNullRouteHistoryResult { + return &NullableGetServerNullRouteHistoryResult{value: val, isSet: true} +} + +func (v NullableGetServerNullRouteHistoryResult) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableGetServerNullRouteHistoryResult) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/dedicatedserver/model_hdd.go b/dedicatedserver/model_hdd.go new file mode 100644 index 0000000..cdbd121 --- /dev/null +++ b/dedicatedserver/model_hdd.go @@ -0,0 +1,323 @@ +/* +Leaseweb API for dedicated servers + +This documents the rest api dedicatedserver provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package dedicatedserver + +import ( + "encoding/json" +) + +// checks if the Hdd type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &Hdd{} + +// Hdd A single object of the hard disk drive +type Hdd struct { + // Id of the hard disk drive + Id *string `json:"id,omitempty"` + // The total amount of hard disk drives + Amount *int32 `json:"amount,omitempty"` + // The size number of the hard disk drive + Size *int32 `json:"size,omitempty"` + // The type of the hard disk drive + Type *string `json:"type,omitempty"` + // The unit of the hard disk drive + Unit *string `json:"unit,omitempty"` + // Hard disk drive performance type + PerformanceType NullableString `json:"performanceType,omitempty"` +} + +// NewHdd instantiates a new Hdd object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewHdd() *Hdd { + this := Hdd{} + return &this +} + +// NewHddWithDefaults instantiates a new Hdd object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewHddWithDefaults() *Hdd { + this := Hdd{} + return &this +} + +// GetId returns the Id field value if set, zero value otherwise. +func (o *Hdd) GetId() string { + if o == nil || IsNil(o.Id) { + var ret string + return ret + } + return *o.Id +} + +// GetIdOk returns a tuple with the Id field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Hdd) GetIdOk() (*string, bool) { + if o == nil || IsNil(o.Id) { + return nil, false + } + return o.Id, true +} + +// HasId returns a boolean if a field has been set. +func (o *Hdd) HasId() bool { + if o != nil && !IsNil(o.Id) { + return true + } + + return false +} + +// SetId gets a reference to the given string and assigns it to the Id field. +func (o *Hdd) SetId(v string) { + o.Id = &v +} + +// GetAmount returns the Amount field value if set, zero value otherwise. +func (o *Hdd) GetAmount() int32 { + if o == nil || IsNil(o.Amount) { + var ret int32 + return ret + } + return *o.Amount +} + +// GetAmountOk returns a tuple with the Amount field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Hdd) GetAmountOk() (*int32, bool) { + if o == nil || IsNil(o.Amount) { + return nil, false + } + return o.Amount, true +} + +// HasAmount returns a boolean if a field has been set. +func (o *Hdd) HasAmount() bool { + if o != nil && !IsNil(o.Amount) { + return true + } + + return false +} + +// SetAmount gets a reference to the given int32 and assigns it to the Amount field. +func (o *Hdd) SetAmount(v int32) { + o.Amount = &v +} + +// GetSize returns the Size field value if set, zero value otherwise. +func (o *Hdd) GetSize() int32 { + if o == nil || IsNil(o.Size) { + var ret int32 + return ret + } + return *o.Size +} + +// GetSizeOk returns a tuple with the Size field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Hdd) GetSizeOk() (*int32, bool) { + if o == nil || IsNil(o.Size) { + return nil, false + } + return o.Size, true +} + +// HasSize returns a boolean if a field has been set. +func (o *Hdd) HasSize() bool { + if o != nil && !IsNil(o.Size) { + return true + } + + return false +} + +// SetSize gets a reference to the given int32 and assigns it to the Size field. +func (o *Hdd) SetSize(v int32) { + o.Size = &v +} + +// GetType returns the Type field value if set, zero value otherwise. +func (o *Hdd) GetType() string { + if o == nil || IsNil(o.Type) { + var ret string + return ret + } + return *o.Type +} + +// GetTypeOk returns a tuple with the Type field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Hdd) GetTypeOk() (*string, bool) { + if o == nil || IsNil(o.Type) { + return nil, false + } + return o.Type, true +} + +// HasType returns a boolean if a field has been set. +func (o *Hdd) HasType() bool { + if o != nil && !IsNil(o.Type) { + return true + } + + return false +} + +// SetType gets a reference to the given string and assigns it to the Type field. +func (o *Hdd) SetType(v string) { + o.Type = &v +} + +// GetUnit returns the Unit field value if set, zero value otherwise. +func (o *Hdd) GetUnit() string { + if o == nil || IsNil(o.Unit) { + var ret string + return ret + } + return *o.Unit +} + +// GetUnitOk returns a tuple with the Unit field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Hdd) GetUnitOk() (*string, bool) { + if o == nil || IsNil(o.Unit) { + return nil, false + } + return o.Unit, true +} + +// HasUnit returns a boolean if a field has been set. +func (o *Hdd) HasUnit() bool { + if o != nil && !IsNil(o.Unit) { + return true + } + + return false +} + +// SetUnit gets a reference to the given string and assigns it to the Unit field. +func (o *Hdd) SetUnit(v string) { + o.Unit = &v +} + +// GetPerformanceType returns the PerformanceType field value if set, zero value otherwise (both if not set or set to explicit null). +func (o *Hdd) GetPerformanceType() string { + if o == nil || IsNil(o.PerformanceType.Get()) { + var ret string + return ret + } + return *o.PerformanceType.Get() +} + +// GetPerformanceTypeOk returns a tuple with the PerformanceType field value if set, nil otherwise +// and a boolean to check if the value has been set. +// NOTE: If the value is an explicit nil, `nil, true` will be returned +func (o *Hdd) GetPerformanceTypeOk() (*string, bool) { + if o == nil { + return nil, false + } + return o.PerformanceType.Get(), o.PerformanceType.IsSet() +} + +// HasPerformanceType returns a boolean if a field has been set. +func (o *Hdd) HasPerformanceType() bool { + if o != nil && o.PerformanceType.IsSet() { + return true + } + + return false +} + +// SetPerformanceType gets a reference to the given NullableString and assigns it to the PerformanceType field. +func (o *Hdd) SetPerformanceType(v string) { + o.PerformanceType.Set(&v) +} +// SetPerformanceTypeNil sets the value for PerformanceType to be an explicit nil +func (o *Hdd) SetPerformanceTypeNil() { + o.PerformanceType.Set(nil) +} + +// UnsetPerformanceType ensures that no value is present for PerformanceType, not even an explicit nil +func (o *Hdd) UnsetPerformanceType() { + o.PerformanceType.Unset() +} + +func (o Hdd) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o Hdd) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Id) { + toSerialize["id"] = o.Id + } + if !IsNil(o.Amount) { + toSerialize["amount"] = o.Amount + } + if !IsNil(o.Size) { + toSerialize["size"] = o.Size + } + if !IsNil(o.Type) { + toSerialize["type"] = o.Type + } + if !IsNil(o.Unit) { + toSerialize["unit"] = o.Unit + } + if o.PerformanceType.IsSet() { + toSerialize["performanceType"] = o.PerformanceType.Get() + } + return toSerialize, nil +} + +type NullableHdd struct { + value *Hdd + isSet bool +} + +func (v NullableHdd) Get() *Hdd { + return v.value +} + +func (v *NullableHdd) Set(val *Hdd) { + v.value = val + v.isSet = true +} + +func (v NullableHdd) IsSet() bool { + return v.isSet +} + +func (v *NullableHdd) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableHdd(val *Hdd) *NullableHdd { + return &NullableHdd{value: val, isSet: true} +} + +func (v NullableHdd) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableHdd) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/dedicatedserver/model_ip.go b/dedicatedserver/model_ip.go new file mode 100644 index 0000000..8507598 --- /dev/null +++ b/dedicatedserver/model_ip.go @@ -0,0 +1,423 @@ +/* +Leaseweb API for dedicated servers + +This documents the rest api dedicatedserver provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package dedicatedserver + +import ( + "encoding/json" +) + +// checks if the Ip type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &Ip{} + +// Ip struct for Ip +type Ip struct { + Ddos *DDos `json:"ddos,omitempty"` + // Indicates if the IP is a Floating IP + FloatingIp *bool `json:"floatingIp,omitempty"` + // Gateway + Gateway *string `json:"gateway,omitempty"` + // IP address in CIDR notation + Ip *string `json:"ip,omitempty"` + // IP address is main + MainIp *bool `json:"mainIp,omitempty"` + // Type of network + NetworkType *string `json:"networkType,omitempty"` + // IP address null routed + NullRouted *bool `json:"nullRouted,omitempty"` + // The reverse lookup value + ReverseLookup *string `json:"reverseLookup,omitempty"` + // IP version + Version *int32 `json:"version,omitempty"` +} + +// NewIp instantiates a new Ip object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewIp() *Ip { + this := Ip{} + return &this +} + +// NewIpWithDefaults instantiates a new Ip object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewIpWithDefaults() *Ip { + this := Ip{} + return &this +} + +// GetDdos returns the Ddos field value if set, zero value otherwise. +func (o *Ip) GetDdos() DDos { + if o == nil || IsNil(o.Ddos) { + var ret DDos + return ret + } + return *o.Ddos +} + +// GetDdosOk returns a tuple with the Ddos field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Ip) GetDdosOk() (*DDos, bool) { + if o == nil || IsNil(o.Ddos) { + return nil, false + } + return o.Ddos, true +} + +// HasDdos returns a boolean if a field has been set. +func (o *Ip) HasDdos() bool { + if o != nil && !IsNil(o.Ddos) { + return true + } + + return false +} + +// SetDdos gets a reference to the given DDos and assigns it to the Ddos field. +func (o *Ip) SetDdos(v DDos) { + o.Ddos = &v +} + +// GetFloatingIp returns the FloatingIp field value if set, zero value otherwise. +func (o *Ip) GetFloatingIp() bool { + if o == nil || IsNil(o.FloatingIp) { + var ret bool + return ret + } + return *o.FloatingIp +} + +// GetFloatingIpOk returns a tuple with the FloatingIp field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Ip) GetFloatingIpOk() (*bool, bool) { + if o == nil || IsNil(o.FloatingIp) { + return nil, false + } + return o.FloatingIp, true +} + +// HasFloatingIp returns a boolean if a field has been set. +func (o *Ip) HasFloatingIp() bool { + if o != nil && !IsNil(o.FloatingIp) { + return true + } + + return false +} + +// SetFloatingIp gets a reference to the given bool and assigns it to the FloatingIp field. +func (o *Ip) SetFloatingIp(v bool) { + o.FloatingIp = &v +} + +// GetGateway returns the Gateway field value if set, zero value otherwise. +func (o *Ip) GetGateway() string { + if o == nil || IsNil(o.Gateway) { + var ret string + return ret + } + return *o.Gateway +} + +// GetGatewayOk returns a tuple with the Gateway field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Ip) GetGatewayOk() (*string, bool) { + if o == nil || IsNil(o.Gateway) { + return nil, false + } + return o.Gateway, true +} + +// HasGateway returns a boolean if a field has been set. +func (o *Ip) HasGateway() bool { + if o != nil && !IsNil(o.Gateway) { + return true + } + + return false +} + +// SetGateway gets a reference to the given string and assigns it to the Gateway field. +func (o *Ip) SetGateway(v string) { + o.Gateway = &v +} + +// GetIp returns the Ip field value if set, zero value otherwise. +func (o *Ip) GetIp() string { + if o == nil || IsNil(o.Ip) { + var ret string + return ret + } + return *o.Ip +} + +// GetIpOk returns a tuple with the Ip field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Ip) GetIpOk() (*string, bool) { + if o == nil || IsNil(o.Ip) { + return nil, false + } + return o.Ip, true +} + +// HasIp returns a boolean if a field has been set. +func (o *Ip) HasIp() bool { + if o != nil && !IsNil(o.Ip) { + return true + } + + return false +} + +// SetIp gets a reference to the given string and assigns it to the Ip field. +func (o *Ip) SetIp(v string) { + o.Ip = &v +} + +// GetMainIp returns the MainIp field value if set, zero value otherwise. +func (o *Ip) GetMainIp() bool { + if o == nil || IsNil(o.MainIp) { + var ret bool + return ret + } + return *o.MainIp +} + +// GetMainIpOk returns a tuple with the MainIp field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Ip) GetMainIpOk() (*bool, bool) { + if o == nil || IsNil(o.MainIp) { + return nil, false + } + return o.MainIp, true +} + +// HasMainIp returns a boolean if a field has been set. +func (o *Ip) HasMainIp() bool { + if o != nil && !IsNil(o.MainIp) { + return true + } + + return false +} + +// SetMainIp gets a reference to the given bool and assigns it to the MainIp field. +func (o *Ip) SetMainIp(v bool) { + o.MainIp = &v +} + +// GetNetworkType returns the NetworkType field value if set, zero value otherwise. +func (o *Ip) GetNetworkType() string { + if o == nil || IsNil(o.NetworkType) { + var ret string + return ret + } + return *o.NetworkType +} + +// GetNetworkTypeOk returns a tuple with the NetworkType field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Ip) GetNetworkTypeOk() (*string, bool) { + if o == nil || IsNil(o.NetworkType) { + return nil, false + } + return o.NetworkType, true +} + +// HasNetworkType returns a boolean if a field has been set. +func (o *Ip) HasNetworkType() bool { + if o != nil && !IsNil(o.NetworkType) { + return true + } + + return false +} + +// SetNetworkType gets a reference to the given string and assigns it to the NetworkType field. +func (o *Ip) SetNetworkType(v string) { + o.NetworkType = &v +} + +// GetNullRouted returns the NullRouted field value if set, zero value otherwise. +func (o *Ip) GetNullRouted() bool { + if o == nil || IsNil(o.NullRouted) { + var ret bool + return ret + } + return *o.NullRouted +} + +// GetNullRoutedOk returns a tuple with the NullRouted field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Ip) GetNullRoutedOk() (*bool, bool) { + if o == nil || IsNil(o.NullRouted) { + return nil, false + } + return o.NullRouted, true +} + +// HasNullRouted returns a boolean if a field has been set. +func (o *Ip) HasNullRouted() bool { + if o != nil && !IsNil(o.NullRouted) { + return true + } + + return false +} + +// SetNullRouted gets a reference to the given bool and assigns it to the NullRouted field. +func (o *Ip) SetNullRouted(v bool) { + o.NullRouted = &v +} + +// GetReverseLookup returns the ReverseLookup field value if set, zero value otherwise. +func (o *Ip) GetReverseLookup() string { + if o == nil || IsNil(o.ReverseLookup) { + var ret string + return ret + } + return *o.ReverseLookup +} + +// GetReverseLookupOk returns a tuple with the ReverseLookup field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Ip) GetReverseLookupOk() (*string, bool) { + if o == nil || IsNil(o.ReverseLookup) { + return nil, false + } + return o.ReverseLookup, true +} + +// HasReverseLookup returns a boolean if a field has been set. +func (o *Ip) HasReverseLookup() bool { + if o != nil && !IsNil(o.ReverseLookup) { + return true + } + + return false +} + +// SetReverseLookup gets a reference to the given string and assigns it to the ReverseLookup field. +func (o *Ip) SetReverseLookup(v string) { + o.ReverseLookup = &v +} + +// GetVersion returns the Version field value if set, zero value otherwise. +func (o *Ip) GetVersion() int32 { + if o == nil || IsNil(o.Version) { + var ret int32 + return ret + } + return *o.Version +} + +// GetVersionOk returns a tuple with the Version field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Ip) GetVersionOk() (*int32, bool) { + if o == nil || IsNil(o.Version) { + return nil, false + } + return o.Version, true +} + +// HasVersion returns a boolean if a field has been set. +func (o *Ip) HasVersion() bool { + if o != nil && !IsNil(o.Version) { + return true + } + + return false +} + +// SetVersion gets a reference to the given int32 and assigns it to the Version field. +func (o *Ip) SetVersion(v int32) { + o.Version = &v +} + +func (o Ip) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o Ip) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Ddos) { + toSerialize["ddos"] = o.Ddos + } + if !IsNil(o.FloatingIp) { + toSerialize["floatingIp"] = o.FloatingIp + } + if !IsNil(o.Gateway) { + toSerialize["gateway"] = o.Gateway + } + if !IsNil(o.Ip) { + toSerialize["ip"] = o.Ip + } + if !IsNil(o.MainIp) { + toSerialize["mainIp"] = o.MainIp + } + if !IsNil(o.NetworkType) { + toSerialize["networkType"] = o.NetworkType + } + if !IsNil(o.NullRouted) { + toSerialize["nullRouted"] = o.NullRouted + } + if !IsNil(o.ReverseLookup) { + toSerialize["reverseLookup"] = o.ReverseLookup + } + if !IsNil(o.Version) { + toSerialize["version"] = o.Version + } + return toSerialize, nil +} + +type NullableIp struct { + value *Ip + isSet bool +} + +func (v NullableIp) Get() *Ip { + return v.value +} + +func (v *NullableIp) Set(val *Ip) { + v.value = val + v.isSet = true +} + +func (v NullableIp) IsSet() bool { + return v.isSet +} + +func (v *NullableIp) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableIp(val *Ip) *NullableIp { + return &NullableIp{value: val, isSet: true} +} + +func (v NullableIp) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableIp) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/dedicatedserver/model_link_speed.go b/dedicatedserver/model_link_speed.go new file mode 100644 index 0000000..e247cce --- /dev/null +++ b/dedicatedserver/model_link_speed.go @@ -0,0 +1,114 @@ +/* +Leaseweb API for dedicated servers + +This documents the rest api dedicatedserver provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package dedicatedserver + +import ( + "encoding/json" + "fmt" +) + +// LinkSpeed The port speed in Mbps +type LinkSpeed int32 + +// List of linkSpeed +const ( + _100 LinkSpeed = 100 + _1000 LinkSpeed = 1000 + _10000 LinkSpeed = 10000 +) + +// All allowed values of LinkSpeed enum +var AllowedLinkSpeedEnumValues = []LinkSpeed{ + 100, + 1000, + 10000, +} + +func (v *LinkSpeed) UnmarshalJSON(src []byte) error { + var value int32 + err := json.Unmarshal(src, &value) + if err != nil { + return err + } + enumTypeValue := LinkSpeed(value) + for _, existing := range AllowedLinkSpeedEnumValues { + if existing == enumTypeValue { + *v = enumTypeValue + return nil + } + } + + return fmt.Errorf("%+v is not a valid LinkSpeed", value) +} + +// NewLinkSpeedFromValue returns a pointer to a valid LinkSpeed +// for the value passed as argument, or an error if the value passed is not allowed by the enum +func NewLinkSpeedFromValue(v int32) (*LinkSpeed, error) { + ev := LinkSpeed(v) + if ev.IsValid() { + return &ev, nil + } else { + return nil, fmt.Errorf("invalid value '%v' for LinkSpeed: valid values are %v", v, AllowedLinkSpeedEnumValues) + } +} + +// IsValid return true if the value is valid for the enum, false otherwise +func (v LinkSpeed) IsValid() bool { + for _, existing := range AllowedLinkSpeedEnumValues { + if existing == v { + return true + } + } + return false +} + +// Ptr returns reference to linkSpeed value +func (v LinkSpeed) Ptr() *LinkSpeed { + return &v +} + +type NullableLinkSpeed struct { + value *LinkSpeed + isSet bool +} + +func (v NullableLinkSpeed) Get() *LinkSpeed { + return v.value +} + +func (v *NullableLinkSpeed) Set(val *LinkSpeed) { + v.value = val + v.isSet = true +} + +func (v NullableLinkSpeed) IsSet() bool { + return v.isSet +} + +func (v *NullableLinkSpeed) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableLinkSpeed(val *LinkSpeed) *NullableLinkSpeed { + return &NullableLinkSpeed{value: val, isSet: true} +} + +func (v NullableLinkSpeed) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableLinkSpeed) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + diff --git a/dedicatedserver/model_network_equipment.go b/dedicatedserver/model_network_equipment.go new file mode 100644 index 0000000..8362ce3 --- /dev/null +++ b/dedicatedserver/model_network_equipment.go @@ -0,0 +1,496 @@ +/* +Leaseweb API for dedicated servers + +This documents the rest api dedicatedserver provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package dedicatedserver + +import ( + "encoding/json" +) + +// checks if the NetworkEquipment type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &NetworkEquipment{} + +// NetworkEquipment struct for NetworkEquipment +type NetworkEquipment struct { + // Contract information + Contract map[string]interface{} `json:"contract,omitempty"` + // List of features that are available for this network equipment + FeatureAvailability map[string]interface{} `json:"featureAvailability,omitempty"` + // Id of the network equipment + Id *string `json:"id,omitempty"` + // Location of the network equipment + Location map[string]interface{} `json:"location,omitempty"` + // The name of the network equipment + Name *string `json:"name,omitempty"` + // The network equipment type + Type *string `json:"type,omitempty"` + // Network interface information grouped by type + NetworkInterfaces map[string]interface{} `json:"networkInterfaces,omitempty"` + // List of ports that can be used to manage power of the network equipment + PowerPorts []Powerport `json:"powerPorts,omitempty"` + Rack *Rack `json:"rack,omitempty"` + // Serial number of network equipment + SerialNumber *string `json:"serialNumber,omitempty"` + Specs *NetworkEquipmentSpecs `json:"specs,omitempty"` +} + +// NewNetworkEquipment instantiates a new NetworkEquipment object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewNetworkEquipment() *NetworkEquipment { + this := NetworkEquipment{} + return &this +} + +// NewNetworkEquipmentWithDefaults instantiates a new NetworkEquipment object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewNetworkEquipmentWithDefaults() *NetworkEquipment { + this := NetworkEquipment{} + return &this +} + +// GetContract returns the Contract field value if set, zero value otherwise. +func (o *NetworkEquipment) GetContract() map[string]interface{} { + if o == nil || IsNil(o.Contract) { + var ret map[string]interface{} + return ret + } + return o.Contract +} + +// GetContractOk returns a tuple with the Contract field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *NetworkEquipment) GetContractOk() (map[string]interface{}, bool) { + if o == nil || IsNil(o.Contract) { + return map[string]interface{}{}, false + } + return o.Contract, true +} + +// HasContract returns a boolean if a field has been set. +func (o *NetworkEquipment) HasContract() bool { + if o != nil && !IsNil(o.Contract) { + return true + } + + return false +} + +// SetContract gets a reference to the given map[string]interface{} and assigns it to the Contract field. +func (o *NetworkEquipment) SetContract(v map[string]interface{}) { + o.Contract = v +} + +// GetFeatureAvailability returns the FeatureAvailability field value if set, zero value otherwise. +func (o *NetworkEquipment) GetFeatureAvailability() map[string]interface{} { + if o == nil || IsNil(o.FeatureAvailability) { + var ret map[string]interface{} + return ret + } + return o.FeatureAvailability +} + +// GetFeatureAvailabilityOk returns a tuple with the FeatureAvailability field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *NetworkEquipment) GetFeatureAvailabilityOk() (map[string]interface{}, bool) { + if o == nil || IsNil(o.FeatureAvailability) { + return map[string]interface{}{}, false + } + return o.FeatureAvailability, true +} + +// HasFeatureAvailability returns a boolean if a field has been set. +func (o *NetworkEquipment) HasFeatureAvailability() bool { + if o != nil && !IsNil(o.FeatureAvailability) { + return true + } + + return false +} + +// SetFeatureAvailability gets a reference to the given map[string]interface{} and assigns it to the FeatureAvailability field. +func (o *NetworkEquipment) SetFeatureAvailability(v map[string]interface{}) { + o.FeatureAvailability = v +} + +// GetId returns the Id field value if set, zero value otherwise. +func (o *NetworkEquipment) GetId() string { + if o == nil || IsNil(o.Id) { + var ret string + return ret + } + return *o.Id +} + +// GetIdOk returns a tuple with the Id field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *NetworkEquipment) GetIdOk() (*string, bool) { + if o == nil || IsNil(o.Id) { + return nil, false + } + return o.Id, true +} + +// HasId returns a boolean if a field has been set. +func (o *NetworkEquipment) HasId() bool { + if o != nil && !IsNil(o.Id) { + return true + } + + return false +} + +// SetId gets a reference to the given string and assigns it to the Id field. +func (o *NetworkEquipment) SetId(v string) { + o.Id = &v +} + +// GetLocation returns the Location field value if set, zero value otherwise. +func (o *NetworkEquipment) GetLocation() map[string]interface{} { + if o == nil || IsNil(o.Location) { + var ret map[string]interface{} + return ret + } + return o.Location +} + +// GetLocationOk returns a tuple with the Location field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *NetworkEquipment) GetLocationOk() (map[string]interface{}, bool) { + if o == nil || IsNil(o.Location) { + return map[string]interface{}{}, false + } + return o.Location, true +} + +// HasLocation returns a boolean if a field has been set. +func (o *NetworkEquipment) HasLocation() bool { + if o != nil && !IsNil(o.Location) { + return true + } + + return false +} + +// SetLocation gets a reference to the given map[string]interface{} and assigns it to the Location field. +func (o *NetworkEquipment) SetLocation(v map[string]interface{}) { + o.Location = v +} + +// GetName returns the Name field value if set, zero value otherwise. +func (o *NetworkEquipment) GetName() string { + if o == nil || IsNil(o.Name) { + var ret string + return ret + } + return *o.Name +} + +// GetNameOk returns a tuple with the Name field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *NetworkEquipment) GetNameOk() (*string, bool) { + if o == nil || IsNil(o.Name) { + return nil, false + } + return o.Name, true +} + +// HasName returns a boolean if a field has been set. +func (o *NetworkEquipment) HasName() bool { + if o != nil && !IsNil(o.Name) { + return true + } + + return false +} + +// SetName gets a reference to the given string and assigns it to the Name field. +func (o *NetworkEquipment) SetName(v string) { + o.Name = &v +} + +// GetType returns the Type field value if set, zero value otherwise. +func (o *NetworkEquipment) GetType() string { + if o == nil || IsNil(o.Type) { + var ret string + return ret + } + return *o.Type +} + +// GetTypeOk returns a tuple with the Type field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *NetworkEquipment) GetTypeOk() (*string, bool) { + if o == nil || IsNil(o.Type) { + return nil, false + } + return o.Type, true +} + +// HasType returns a boolean if a field has been set. +func (o *NetworkEquipment) HasType() bool { + if o != nil && !IsNil(o.Type) { + return true + } + + return false +} + +// SetType gets a reference to the given string and assigns it to the Type field. +func (o *NetworkEquipment) SetType(v string) { + o.Type = &v +} + +// GetNetworkInterfaces returns the NetworkInterfaces field value if set, zero value otherwise. +func (o *NetworkEquipment) GetNetworkInterfaces() map[string]interface{} { + if o == nil || IsNil(o.NetworkInterfaces) { + var ret map[string]interface{} + return ret + } + return o.NetworkInterfaces +} + +// GetNetworkInterfacesOk returns a tuple with the NetworkInterfaces field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *NetworkEquipment) GetNetworkInterfacesOk() (map[string]interface{}, bool) { + if o == nil || IsNil(o.NetworkInterfaces) { + return map[string]interface{}{}, false + } + return o.NetworkInterfaces, true +} + +// HasNetworkInterfaces returns a boolean if a field has been set. +func (o *NetworkEquipment) HasNetworkInterfaces() bool { + if o != nil && !IsNil(o.NetworkInterfaces) { + return true + } + + return false +} + +// SetNetworkInterfaces gets a reference to the given map[string]interface{} and assigns it to the NetworkInterfaces field. +func (o *NetworkEquipment) SetNetworkInterfaces(v map[string]interface{}) { + o.NetworkInterfaces = v +} + +// GetPowerPorts returns the PowerPorts field value if set, zero value otherwise. +func (o *NetworkEquipment) GetPowerPorts() []Powerport { + if o == nil || IsNil(o.PowerPorts) { + var ret []Powerport + return ret + } + return o.PowerPorts +} + +// GetPowerPortsOk returns a tuple with the PowerPorts field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *NetworkEquipment) GetPowerPortsOk() ([]Powerport, bool) { + if o == nil || IsNil(o.PowerPorts) { + return nil, false + } + return o.PowerPorts, true +} + +// HasPowerPorts returns a boolean if a field has been set. +func (o *NetworkEquipment) HasPowerPorts() bool { + if o != nil && !IsNil(o.PowerPorts) { + return true + } + + return false +} + +// SetPowerPorts gets a reference to the given []Powerport and assigns it to the PowerPorts field. +func (o *NetworkEquipment) SetPowerPorts(v []Powerport) { + o.PowerPorts = v +} + +// GetRack returns the Rack field value if set, zero value otherwise. +func (o *NetworkEquipment) GetRack() Rack { + if o == nil || IsNil(o.Rack) { + var ret Rack + return ret + } + return *o.Rack +} + +// GetRackOk returns a tuple with the Rack field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *NetworkEquipment) GetRackOk() (*Rack, bool) { + if o == nil || IsNil(o.Rack) { + return nil, false + } + return o.Rack, true +} + +// HasRack returns a boolean if a field has been set. +func (o *NetworkEquipment) HasRack() bool { + if o != nil && !IsNil(o.Rack) { + return true + } + + return false +} + +// SetRack gets a reference to the given Rack and assigns it to the Rack field. +func (o *NetworkEquipment) SetRack(v Rack) { + o.Rack = &v +} + +// GetSerialNumber returns the SerialNumber field value if set, zero value otherwise. +func (o *NetworkEquipment) GetSerialNumber() string { + if o == nil || IsNil(o.SerialNumber) { + var ret string + return ret + } + return *o.SerialNumber +} + +// GetSerialNumberOk returns a tuple with the SerialNumber field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *NetworkEquipment) GetSerialNumberOk() (*string, bool) { + if o == nil || IsNil(o.SerialNumber) { + return nil, false + } + return o.SerialNumber, true +} + +// HasSerialNumber returns a boolean if a field has been set. +func (o *NetworkEquipment) HasSerialNumber() bool { + if o != nil && !IsNil(o.SerialNumber) { + return true + } + + return false +} + +// SetSerialNumber gets a reference to the given string and assigns it to the SerialNumber field. +func (o *NetworkEquipment) SetSerialNumber(v string) { + o.SerialNumber = &v +} + +// GetSpecs returns the Specs field value if set, zero value otherwise. +func (o *NetworkEquipment) GetSpecs() NetworkEquipmentSpecs { + if o == nil || IsNil(o.Specs) { + var ret NetworkEquipmentSpecs + return ret + } + return *o.Specs +} + +// GetSpecsOk returns a tuple with the Specs field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *NetworkEquipment) GetSpecsOk() (*NetworkEquipmentSpecs, bool) { + if o == nil || IsNil(o.Specs) { + return nil, false + } + return o.Specs, true +} + +// HasSpecs returns a boolean if a field has been set. +func (o *NetworkEquipment) HasSpecs() bool { + if o != nil && !IsNil(o.Specs) { + return true + } + + return false +} + +// SetSpecs gets a reference to the given NetworkEquipmentSpecs and assigns it to the Specs field. +func (o *NetworkEquipment) SetSpecs(v NetworkEquipmentSpecs) { + o.Specs = &v +} + +func (o NetworkEquipment) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o NetworkEquipment) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Contract) { + toSerialize["contract"] = o.Contract + } + if !IsNil(o.FeatureAvailability) { + toSerialize["featureAvailability"] = o.FeatureAvailability + } + if !IsNil(o.Id) { + toSerialize["id"] = o.Id + } + if !IsNil(o.Location) { + toSerialize["location"] = o.Location + } + if !IsNil(o.Name) { + toSerialize["name"] = o.Name + } + if !IsNil(o.Type) { + toSerialize["type"] = o.Type + } + if !IsNil(o.NetworkInterfaces) { + toSerialize["networkInterfaces"] = o.NetworkInterfaces + } + if !IsNil(o.PowerPorts) { + toSerialize["powerPorts"] = o.PowerPorts + } + if !IsNil(o.Rack) { + toSerialize["rack"] = o.Rack + } + if !IsNil(o.SerialNumber) { + toSerialize["serialNumber"] = o.SerialNumber + } + if !IsNil(o.Specs) { + toSerialize["specs"] = o.Specs + } + return toSerialize, nil +} + +type NullableNetworkEquipment struct { + value *NetworkEquipment + isSet bool +} + +func (v NullableNetworkEquipment) Get() *NetworkEquipment { + return v.value +} + +func (v *NullableNetworkEquipment) Set(val *NetworkEquipment) { + v.value = val + v.isSet = true +} + +func (v NullableNetworkEquipment) IsSet() bool { + return v.isSet +} + +func (v *NullableNetworkEquipment) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableNetworkEquipment(val *NetworkEquipment) *NullableNetworkEquipment { + return &NullableNetworkEquipment{value: val, isSet: true} +} + +func (v NullableNetworkEquipment) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableNetworkEquipment) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/dedicatedserver/model_network_equipment_specs.go b/dedicatedserver/model_network_equipment_specs.go new file mode 100644 index 0000000..d64725c --- /dev/null +++ b/dedicatedserver/model_network_equipment_specs.go @@ -0,0 +1,165 @@ +/* +Leaseweb API for dedicated servers + +This documents the rest api dedicatedserver provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package dedicatedserver + +import ( + "encoding/json" +) + +// checks if the NetworkEquipmentSpecs type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &NetworkEquipmentSpecs{} + +// NetworkEquipmentSpecs Hardware information of the network equipment +type NetworkEquipmentSpecs struct { + // The brand of the network equipment + Brand *string `json:"brand,omitempty"` + // The model of the network equipment + Model *string `json:"model,omitempty"` +} + +// NewNetworkEquipmentSpecs instantiates a new NetworkEquipmentSpecs object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewNetworkEquipmentSpecs() *NetworkEquipmentSpecs { + this := NetworkEquipmentSpecs{} + return &this +} + +// NewNetworkEquipmentSpecsWithDefaults instantiates a new NetworkEquipmentSpecs object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewNetworkEquipmentSpecsWithDefaults() *NetworkEquipmentSpecs { + this := NetworkEquipmentSpecs{} + return &this +} + +// GetBrand returns the Brand field value if set, zero value otherwise. +func (o *NetworkEquipmentSpecs) GetBrand() string { + if o == nil || IsNil(o.Brand) { + var ret string + return ret + } + return *o.Brand +} + +// GetBrandOk returns a tuple with the Brand field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *NetworkEquipmentSpecs) GetBrandOk() (*string, bool) { + if o == nil || IsNil(o.Brand) { + return nil, false + } + return o.Brand, true +} + +// HasBrand returns a boolean if a field has been set. +func (o *NetworkEquipmentSpecs) HasBrand() bool { + if o != nil && !IsNil(o.Brand) { + return true + } + + return false +} + +// SetBrand gets a reference to the given string and assigns it to the Brand field. +func (o *NetworkEquipmentSpecs) SetBrand(v string) { + o.Brand = &v +} + +// GetModel returns the Model field value if set, zero value otherwise. +func (o *NetworkEquipmentSpecs) GetModel() string { + if o == nil || IsNil(o.Model) { + var ret string + return ret + } + return *o.Model +} + +// GetModelOk returns a tuple with the Model field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *NetworkEquipmentSpecs) GetModelOk() (*string, bool) { + if o == nil || IsNil(o.Model) { + return nil, false + } + return o.Model, true +} + +// HasModel returns a boolean if a field has been set. +func (o *NetworkEquipmentSpecs) HasModel() bool { + if o != nil && !IsNil(o.Model) { + return true + } + + return false +} + +// SetModel gets a reference to the given string and assigns it to the Model field. +func (o *NetworkEquipmentSpecs) SetModel(v string) { + o.Model = &v +} + +func (o NetworkEquipmentSpecs) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o NetworkEquipmentSpecs) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Brand) { + toSerialize["brand"] = o.Brand + } + if !IsNil(o.Model) { + toSerialize["model"] = o.Model + } + return toSerialize, nil +} + +type NullableNetworkEquipmentSpecs struct { + value *NetworkEquipmentSpecs + isSet bool +} + +func (v NullableNetworkEquipmentSpecs) Get() *NetworkEquipmentSpecs { + return v.value +} + +func (v *NullableNetworkEquipmentSpecs) Set(val *NetworkEquipmentSpecs) { + v.value = val + v.isSet = true +} + +func (v NullableNetworkEquipmentSpecs) IsSet() bool { + return v.isSet +} + +func (v *NullableNetworkEquipmentSpecs) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableNetworkEquipmentSpecs(val *NetworkEquipmentSpecs) *NullableNetworkEquipmentSpecs { + return &NullableNetworkEquipmentSpecs{value: val, isSet: true} +} + +func (v NullableNetworkEquipmentSpecs) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableNetworkEquipmentSpecs) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/dedicatedserver/model_null_route.go b/dedicatedserver/model_null_route.go new file mode 100644 index 0000000..af81caa --- /dev/null +++ b/dedicatedserver/model_null_route.go @@ -0,0 +1,314 @@ +/* +Leaseweb API for dedicated servers + +This documents the rest api dedicatedserver provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package dedicatedserver + +import ( + "encoding/json" + "time" +) + +// checks if the NullRoute type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &NullRoute{} + +// NullRoute struct for NullRoute +type NullRoute struct { + // The time the null route was removed or will be removed. + AutomatedUnnullingAt *time.Time `json:"automatedUnnullingAt,omitempty"` + // An optional comment for the reason of the null route + Comment *string `json:"comment,omitempty"` + // The ip address that was null routed + Ip *string `json:"ip,omitempty"` + // The level of the null route + NullLevel *int32 `json:"nullLevel,omitempty"` + // The time the null route was created + NulledAt *time.Time `json:"nulledAt,omitempty"` + // A ticket number if available + TicketId *string `json:"ticketId,omitempty"` +} + +// NewNullRoute instantiates a new NullRoute object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewNullRoute() *NullRoute { + this := NullRoute{} + return &this +} + +// NewNullRouteWithDefaults instantiates a new NullRoute object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewNullRouteWithDefaults() *NullRoute { + this := NullRoute{} + return &this +} + +// GetAutomatedUnnullingAt returns the AutomatedUnnullingAt field value if set, zero value otherwise. +func (o *NullRoute) GetAutomatedUnnullingAt() time.Time { + if o == nil || IsNil(o.AutomatedUnnullingAt) { + var ret time.Time + return ret + } + return *o.AutomatedUnnullingAt +} + +// GetAutomatedUnnullingAtOk returns a tuple with the AutomatedUnnullingAt field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *NullRoute) GetAutomatedUnnullingAtOk() (*time.Time, bool) { + if o == nil || IsNil(o.AutomatedUnnullingAt) { + return nil, false + } + return o.AutomatedUnnullingAt, true +} + +// HasAutomatedUnnullingAt returns a boolean if a field has been set. +func (o *NullRoute) HasAutomatedUnnullingAt() bool { + if o != nil && !IsNil(o.AutomatedUnnullingAt) { + return true + } + + return false +} + +// SetAutomatedUnnullingAt gets a reference to the given time.Time and assigns it to the AutomatedUnnullingAt field. +func (o *NullRoute) SetAutomatedUnnullingAt(v time.Time) { + o.AutomatedUnnullingAt = &v +} + +// GetComment returns the Comment field value if set, zero value otherwise. +func (o *NullRoute) GetComment() string { + if o == nil || IsNil(o.Comment) { + var ret string + return ret + } + return *o.Comment +} + +// GetCommentOk returns a tuple with the Comment field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *NullRoute) GetCommentOk() (*string, bool) { + if o == nil || IsNil(o.Comment) { + return nil, false + } + return o.Comment, true +} + +// HasComment returns a boolean if a field has been set. +func (o *NullRoute) HasComment() bool { + if o != nil && !IsNil(o.Comment) { + return true + } + + return false +} + +// SetComment gets a reference to the given string and assigns it to the Comment field. +func (o *NullRoute) SetComment(v string) { + o.Comment = &v +} + +// GetIp returns the Ip field value if set, zero value otherwise. +func (o *NullRoute) GetIp() string { + if o == nil || IsNil(o.Ip) { + var ret string + return ret + } + return *o.Ip +} + +// GetIpOk returns a tuple with the Ip field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *NullRoute) GetIpOk() (*string, bool) { + if o == nil || IsNil(o.Ip) { + return nil, false + } + return o.Ip, true +} + +// HasIp returns a boolean if a field has been set. +func (o *NullRoute) HasIp() bool { + if o != nil && !IsNil(o.Ip) { + return true + } + + return false +} + +// SetIp gets a reference to the given string and assigns it to the Ip field. +func (o *NullRoute) SetIp(v string) { + o.Ip = &v +} + +// GetNullLevel returns the NullLevel field value if set, zero value otherwise. +func (o *NullRoute) GetNullLevel() int32 { + if o == nil || IsNil(o.NullLevel) { + var ret int32 + return ret + } + return *o.NullLevel +} + +// GetNullLevelOk returns a tuple with the NullLevel field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *NullRoute) GetNullLevelOk() (*int32, bool) { + if o == nil || IsNil(o.NullLevel) { + return nil, false + } + return o.NullLevel, true +} + +// HasNullLevel returns a boolean if a field has been set. +func (o *NullRoute) HasNullLevel() bool { + if o != nil && !IsNil(o.NullLevel) { + return true + } + + return false +} + +// SetNullLevel gets a reference to the given int32 and assigns it to the NullLevel field. +func (o *NullRoute) SetNullLevel(v int32) { + o.NullLevel = &v +} + +// GetNulledAt returns the NulledAt field value if set, zero value otherwise. +func (o *NullRoute) GetNulledAt() time.Time { + if o == nil || IsNil(o.NulledAt) { + var ret time.Time + return ret + } + return *o.NulledAt +} + +// GetNulledAtOk returns a tuple with the NulledAt field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *NullRoute) GetNulledAtOk() (*time.Time, bool) { + if o == nil || IsNil(o.NulledAt) { + return nil, false + } + return o.NulledAt, true +} + +// HasNulledAt returns a boolean if a field has been set. +func (o *NullRoute) HasNulledAt() bool { + if o != nil && !IsNil(o.NulledAt) { + return true + } + + return false +} + +// SetNulledAt gets a reference to the given time.Time and assigns it to the NulledAt field. +func (o *NullRoute) SetNulledAt(v time.Time) { + o.NulledAt = &v +} + +// GetTicketId returns the TicketId field value if set, zero value otherwise. +func (o *NullRoute) GetTicketId() string { + if o == nil || IsNil(o.TicketId) { + var ret string + return ret + } + return *o.TicketId +} + +// GetTicketIdOk returns a tuple with the TicketId field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *NullRoute) GetTicketIdOk() (*string, bool) { + if o == nil || IsNil(o.TicketId) { + return nil, false + } + return o.TicketId, true +} + +// HasTicketId returns a boolean if a field has been set. +func (o *NullRoute) HasTicketId() bool { + if o != nil && !IsNil(o.TicketId) { + return true + } + + return false +} + +// SetTicketId gets a reference to the given string and assigns it to the TicketId field. +func (o *NullRoute) SetTicketId(v string) { + o.TicketId = &v +} + +func (o NullRoute) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o NullRoute) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.AutomatedUnnullingAt) { + toSerialize["automatedUnnullingAt"] = o.AutomatedUnnullingAt + } + if !IsNil(o.Comment) { + toSerialize["comment"] = o.Comment + } + if !IsNil(o.Ip) { + toSerialize["ip"] = o.Ip + } + if !IsNil(o.NullLevel) { + toSerialize["nullLevel"] = o.NullLevel + } + if !IsNil(o.NulledAt) { + toSerialize["nulledAt"] = o.NulledAt + } + if !IsNil(o.TicketId) { + toSerialize["ticketId"] = o.TicketId + } + return toSerialize, nil +} + +type NullableNullRoute struct { + value *NullRoute + isSet bool +} + +func (v NullableNullRoute) Get() *NullRoute { + return v.value +} + +func (v *NullableNullRoute) Set(val *NullRoute) { + v.value = val + v.isSet = true +} + +func (v NullableNullRoute) IsSet() bool { + return v.isSet +} + +func (v *NullableNullRoute) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableNullRoute(val *NullRoute) *NullableNullRoute { + return &NullableNullRoute{value: val, isSet: true} +} + +func (v NullableNullRoute) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableNullRoute) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/dedicatedserver/model_pci_card.go b/dedicatedserver/model_pci_card.go new file mode 100644 index 0000000..e0b3f88 --- /dev/null +++ b/dedicatedserver/model_pci_card.go @@ -0,0 +1,128 @@ +/* +Leaseweb API for dedicated servers + +This documents the rest api dedicatedserver provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package dedicatedserver + +import ( + "encoding/json" +) + +// checks if the PciCard type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &PciCard{} + +// PciCard A single object of the PCI card +type PciCard struct { + // The description of the PCI card of the server + Description *string `json:"description,omitempty"` +} + +// NewPciCard instantiates a new PciCard object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewPciCard() *PciCard { + this := PciCard{} + return &this +} + +// NewPciCardWithDefaults instantiates a new PciCard object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewPciCardWithDefaults() *PciCard { + this := PciCard{} + return &this +} + +// GetDescription returns the Description field value if set, zero value otherwise. +func (o *PciCard) GetDescription() string { + if o == nil || IsNil(o.Description) { + var ret string + return ret + } + return *o.Description +} + +// GetDescriptionOk returns a tuple with the Description field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *PciCard) GetDescriptionOk() (*string, bool) { + if o == nil || IsNil(o.Description) { + return nil, false + } + return o.Description, true +} + +// HasDescription returns a boolean if a field has been set. +func (o *PciCard) HasDescription() bool { + if o != nil && !IsNil(o.Description) { + return true + } + + return false +} + +// SetDescription gets a reference to the given string and assigns it to the Description field. +func (o *PciCard) SetDescription(v string) { + o.Description = &v +} + +func (o PciCard) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o PciCard) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Description) { + toSerialize["description"] = o.Description + } + return toSerialize, nil +} + +type NullablePciCard struct { + value *PciCard + isSet bool +} + +func (v NullablePciCard) Get() *PciCard { + return v.value +} + +func (v *NullablePciCard) Set(val *PciCard) { + v.value = val + v.isSet = true +} + +func (v NullablePciCard) IsSet() bool { + return v.isSet +} + +func (v *NullablePciCard) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullablePciCard(val *PciCard) *NullablePciCard { + return &NullablePciCard{value: val, isSet: true} +} + +func (v NullablePciCard) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullablePciCard) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/dedicatedserver/model_powerport.go b/dedicatedserver/model_powerport.go new file mode 100644 index 0000000..582ec75 --- /dev/null +++ b/dedicatedserver/model_powerport.go @@ -0,0 +1,163 @@ +/* +Leaseweb API for dedicated servers + +This documents the rest api dedicatedserver provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package dedicatedserver + +import ( + "encoding/json" +) + +// checks if the Powerport type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &Powerport{} + +// Powerport struct for Powerport +type Powerport struct { + Name *string `json:"name,omitempty"` + Port *string `json:"port,omitempty"` +} + +// NewPowerport instantiates a new Powerport object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewPowerport() *Powerport { + this := Powerport{} + return &this +} + +// NewPowerportWithDefaults instantiates a new Powerport object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewPowerportWithDefaults() *Powerport { + this := Powerport{} + return &this +} + +// GetName returns the Name field value if set, zero value otherwise. +func (o *Powerport) GetName() string { + if o == nil || IsNil(o.Name) { + var ret string + return ret + } + return *o.Name +} + +// GetNameOk returns a tuple with the Name field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Powerport) GetNameOk() (*string, bool) { + if o == nil || IsNil(o.Name) { + return nil, false + } + return o.Name, true +} + +// HasName returns a boolean if a field has been set. +func (o *Powerport) HasName() bool { + if o != nil && !IsNil(o.Name) { + return true + } + + return false +} + +// SetName gets a reference to the given string and assigns it to the Name field. +func (o *Powerport) SetName(v string) { + o.Name = &v +} + +// GetPort returns the Port field value if set, zero value otherwise. +func (o *Powerport) GetPort() string { + if o == nil || IsNil(o.Port) { + var ret string + return ret + } + return *o.Port +} + +// GetPortOk returns a tuple with the Port field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Powerport) GetPortOk() (*string, bool) { + if o == nil || IsNil(o.Port) { + return nil, false + } + return o.Port, true +} + +// HasPort returns a boolean if a field has been set. +func (o *Powerport) HasPort() bool { + if o != nil && !IsNil(o.Port) { + return true + } + + return false +} + +// SetPort gets a reference to the given string and assigns it to the Port field. +func (o *Powerport) SetPort(v string) { + o.Port = &v +} + +func (o Powerport) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o Powerport) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Name) { + toSerialize["name"] = o.Name + } + if !IsNil(o.Port) { + toSerialize["port"] = o.Port + } + return toSerialize, nil +} + +type NullablePowerport struct { + value *Powerport + isSet bool +} + +func (v NullablePowerport) Get() *Powerport { + return v.value +} + +func (v *NullablePowerport) Set(val *Powerport) { + v.value = val + v.isSet = true +} + +func (v NullablePowerport) IsSet() bool { + return v.isSet +} + +func (v *NullablePowerport) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullablePowerport(val *Powerport) *NullablePowerport { + return &NullablePowerport{value: val, isSet: true} +} + +func (v NullablePowerport) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullablePowerport) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/dedicatedserver/model_private_network.go b/dedicatedserver/model_private_network.go new file mode 100644 index 0000000..019d1d7 --- /dev/null +++ b/dedicatedserver/model_private_network.go @@ -0,0 +1,274 @@ +/* +Leaseweb API for dedicated servers + +This documents the rest api dedicatedserver provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package dedicatedserver + +import ( + "encoding/json" +) + +// checks if the PrivateNetwork type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &PrivateNetwork{} + +// PrivateNetwork struct for PrivateNetwork +type PrivateNetwork struct { + // Private network id + Id *string `json:"id,omitempty"` + LinkSpeed *LinkSpeed `json:"linkSpeed,omitempty"` + // Configuration status + Status *string `json:"status,omitempty"` + Subnet *string `json:"subnet,omitempty"` + // VLAN id + VlanId *string `json:"vlanId,omitempty"` +} + +// NewPrivateNetwork instantiates a new PrivateNetwork object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewPrivateNetwork() *PrivateNetwork { + this := PrivateNetwork{} + return &this +} + +// NewPrivateNetworkWithDefaults instantiates a new PrivateNetwork object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewPrivateNetworkWithDefaults() *PrivateNetwork { + this := PrivateNetwork{} + return &this +} + +// GetId returns the Id field value if set, zero value otherwise. +func (o *PrivateNetwork) GetId() string { + if o == nil || IsNil(o.Id) { + var ret string + return ret + } + return *o.Id +} + +// GetIdOk returns a tuple with the Id field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *PrivateNetwork) GetIdOk() (*string, bool) { + if o == nil || IsNil(o.Id) { + return nil, false + } + return o.Id, true +} + +// HasId returns a boolean if a field has been set. +func (o *PrivateNetwork) HasId() bool { + if o != nil && !IsNil(o.Id) { + return true + } + + return false +} + +// SetId gets a reference to the given string and assigns it to the Id field. +func (o *PrivateNetwork) SetId(v string) { + o.Id = &v +} + +// GetLinkSpeed returns the LinkSpeed field value if set, zero value otherwise. +func (o *PrivateNetwork) GetLinkSpeed() LinkSpeed { + if o == nil || IsNil(o.LinkSpeed) { + var ret LinkSpeed + return ret + } + return *o.LinkSpeed +} + +// GetLinkSpeedOk returns a tuple with the LinkSpeed field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *PrivateNetwork) GetLinkSpeedOk() (*LinkSpeed, bool) { + if o == nil || IsNil(o.LinkSpeed) { + return nil, false + } + return o.LinkSpeed, true +} + +// HasLinkSpeed returns a boolean if a field has been set. +func (o *PrivateNetwork) HasLinkSpeed() bool { + if o != nil && !IsNil(o.LinkSpeed) { + return true + } + + return false +} + +// SetLinkSpeed gets a reference to the given LinkSpeed and assigns it to the LinkSpeed field. +func (o *PrivateNetwork) SetLinkSpeed(v LinkSpeed) { + o.LinkSpeed = &v +} + +// GetStatus returns the Status field value if set, zero value otherwise. +func (o *PrivateNetwork) GetStatus() string { + if o == nil || IsNil(o.Status) { + var ret string + return ret + } + return *o.Status +} + +// GetStatusOk returns a tuple with the Status field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *PrivateNetwork) GetStatusOk() (*string, bool) { + if o == nil || IsNil(o.Status) { + return nil, false + } + return o.Status, true +} + +// HasStatus returns a boolean if a field has been set. +func (o *PrivateNetwork) HasStatus() bool { + if o != nil && !IsNil(o.Status) { + return true + } + + return false +} + +// SetStatus gets a reference to the given string and assigns it to the Status field. +func (o *PrivateNetwork) SetStatus(v string) { + o.Status = &v +} + +// GetSubnet returns the Subnet field value if set, zero value otherwise. +func (o *PrivateNetwork) GetSubnet() string { + if o == nil || IsNil(o.Subnet) { + var ret string + return ret + } + return *o.Subnet +} + +// GetSubnetOk returns a tuple with the Subnet field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *PrivateNetwork) GetSubnetOk() (*string, bool) { + if o == nil || IsNil(o.Subnet) { + return nil, false + } + return o.Subnet, true +} + +// HasSubnet returns a boolean if a field has been set. +func (o *PrivateNetwork) HasSubnet() bool { + if o != nil && !IsNil(o.Subnet) { + return true + } + + return false +} + +// SetSubnet gets a reference to the given string and assigns it to the Subnet field. +func (o *PrivateNetwork) SetSubnet(v string) { + o.Subnet = &v +} + +// GetVlanId returns the VlanId field value if set, zero value otherwise. +func (o *PrivateNetwork) GetVlanId() string { + if o == nil || IsNil(o.VlanId) { + var ret string + return ret + } + return *o.VlanId +} + +// GetVlanIdOk returns a tuple with the VlanId field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *PrivateNetwork) GetVlanIdOk() (*string, bool) { + if o == nil || IsNil(o.VlanId) { + return nil, false + } + return o.VlanId, true +} + +// HasVlanId returns a boolean if a field has been set. +func (o *PrivateNetwork) HasVlanId() bool { + if o != nil && !IsNil(o.VlanId) { + return true + } + + return false +} + +// SetVlanId gets a reference to the given string and assigns it to the VlanId field. +func (o *PrivateNetwork) SetVlanId(v string) { + o.VlanId = &v +} + +func (o PrivateNetwork) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o PrivateNetwork) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Id) { + toSerialize["id"] = o.Id + } + if !IsNil(o.LinkSpeed) { + toSerialize["linkSpeed"] = o.LinkSpeed + } + if !IsNil(o.Status) { + toSerialize["status"] = o.Status + } + if !IsNil(o.Subnet) { + toSerialize["subnet"] = o.Subnet + } + if !IsNil(o.VlanId) { + toSerialize["vlanId"] = o.VlanId + } + return toSerialize, nil +} + +type NullablePrivateNetwork struct { + value *PrivateNetwork + isSet bool +} + +func (v NullablePrivateNetwork) Get() *PrivateNetwork { + return v.value +} + +func (v *NullablePrivateNetwork) Set(val *PrivateNetwork) { + v.value = val + v.isSet = true +} + +func (v NullablePrivateNetwork) IsSet() bool { + return v.isSet +} + +func (v *NullablePrivateNetwork) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullablePrivateNetwork(val *PrivateNetwork) *NullablePrivateNetwork { + return &NullablePrivateNetwork{value: val, isSet: true} +} + +func (v NullablePrivateNetwork) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullablePrivateNetwork) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/dedicatedserver/model_rack.go b/dedicatedserver/model_rack.go new file mode 100644 index 0000000..6629e50 --- /dev/null +++ b/dedicatedserver/model_rack.go @@ -0,0 +1,201 @@ +/* +Leaseweb API for dedicated servers + +This documents the rest api dedicatedserver provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package dedicatedserver + +import ( + "encoding/json" +) + +// checks if the Rack type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &Rack{} + +// Rack Rack details where this network equipment is located at +type Rack struct { + // Rack id + Id *string `json:"id,omitempty"` + // Rack capacity + Capacity *string `json:"capacity,omitempty"` + Type *string `json:"type,omitempty"` +} + +// NewRack instantiates a new Rack object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewRack() *Rack { + this := Rack{} + return &this +} + +// NewRackWithDefaults instantiates a new Rack object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewRackWithDefaults() *Rack { + this := Rack{} + return &this +} + +// GetId returns the Id field value if set, zero value otherwise. +func (o *Rack) GetId() string { + if o == nil || IsNil(o.Id) { + var ret string + return ret + } + return *o.Id +} + +// GetIdOk returns a tuple with the Id field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Rack) GetIdOk() (*string, bool) { + if o == nil || IsNil(o.Id) { + return nil, false + } + return o.Id, true +} + +// HasId returns a boolean if a field has been set. +func (o *Rack) HasId() bool { + if o != nil && !IsNil(o.Id) { + return true + } + + return false +} + +// SetId gets a reference to the given string and assigns it to the Id field. +func (o *Rack) SetId(v string) { + o.Id = &v +} + +// GetCapacity returns the Capacity field value if set, zero value otherwise. +func (o *Rack) GetCapacity() string { + if o == nil || IsNil(o.Capacity) { + var ret string + return ret + } + return *o.Capacity +} + +// GetCapacityOk returns a tuple with the Capacity field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Rack) GetCapacityOk() (*string, bool) { + if o == nil || IsNil(o.Capacity) { + return nil, false + } + return o.Capacity, true +} + +// HasCapacity returns a boolean if a field has been set. +func (o *Rack) HasCapacity() bool { + if o != nil && !IsNil(o.Capacity) { + return true + } + + return false +} + +// SetCapacity gets a reference to the given string and assigns it to the Capacity field. +func (o *Rack) SetCapacity(v string) { + o.Capacity = &v +} + +// GetType returns the Type field value if set, zero value otherwise. +func (o *Rack) GetType() string { + if o == nil || IsNil(o.Type) { + var ret string + return ret + } + return *o.Type +} + +// GetTypeOk returns a tuple with the Type field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Rack) GetTypeOk() (*string, bool) { + if o == nil || IsNil(o.Type) { + return nil, false + } + return o.Type, true +} + +// HasType returns a boolean if a field has been set. +func (o *Rack) HasType() bool { + if o != nil && !IsNil(o.Type) { + return true + } + + return false +} + +// SetType gets a reference to the given string and assigns it to the Type field. +func (o *Rack) SetType(v string) { + o.Type = &v +} + +func (o Rack) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o Rack) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Id) { + toSerialize["id"] = o.Id + } + if !IsNil(o.Capacity) { + toSerialize["capacity"] = o.Capacity + } + if !IsNil(o.Type) { + toSerialize["type"] = o.Type + } + return toSerialize, nil +} + +type NullableRack struct { + value *Rack + isSet bool +} + +func (v NullableRack) Get() *Rack { + return v.value +} + +func (v *NullableRack) Set(val *Rack) { + v.value = val + v.isSet = true +} + +func (v NullableRack) IsSet() bool { + return v.isSet +} + +func (v *NullableRack) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableRack(val *Rack) *NullableRack { + return &NullableRack{value: val, isSet: true} +} + +func (v NullableRack) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableRack) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/dedicatedserver/model_ram.go b/dedicatedserver/model_ram.go new file mode 100644 index 0000000..1e50f54 --- /dev/null +++ b/dedicatedserver/model_ram.go @@ -0,0 +1,165 @@ +/* +Leaseweb API for dedicated servers + +This documents the rest api dedicatedserver provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package dedicatedserver + +import ( + "encoding/json" +) + +// checks if the Ram type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &Ram{} + +// Ram RAM of the server +type Ram struct { + // The total RAM size of the server + Size *int32 `json:"size,omitempty"` + // RAM type of the server + Unit *string `json:"unit,omitempty"` +} + +// NewRam instantiates a new Ram object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewRam() *Ram { + this := Ram{} + return &this +} + +// NewRamWithDefaults instantiates a new Ram object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewRamWithDefaults() *Ram { + this := Ram{} + return &this +} + +// GetSize returns the Size field value if set, zero value otherwise. +func (o *Ram) GetSize() int32 { + if o == nil || IsNil(o.Size) { + var ret int32 + return ret + } + return *o.Size +} + +// GetSizeOk returns a tuple with the Size field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Ram) GetSizeOk() (*int32, bool) { + if o == nil || IsNil(o.Size) { + return nil, false + } + return o.Size, true +} + +// HasSize returns a boolean if a field has been set. +func (o *Ram) HasSize() bool { + if o != nil && !IsNil(o.Size) { + return true + } + + return false +} + +// SetSize gets a reference to the given int32 and assigns it to the Size field. +func (o *Ram) SetSize(v int32) { + o.Size = &v +} + +// GetUnit returns the Unit field value if set, zero value otherwise. +func (o *Ram) GetUnit() string { + if o == nil || IsNil(o.Unit) { + var ret string + return ret + } + return *o.Unit +} + +// GetUnitOk returns a tuple with the Unit field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Ram) GetUnitOk() (*string, bool) { + if o == nil || IsNil(o.Unit) { + return nil, false + } + return o.Unit, true +} + +// HasUnit returns a boolean if a field has been set. +func (o *Ram) HasUnit() bool { + if o != nil && !IsNil(o.Unit) { + return true + } + + return false +} + +// SetUnit gets a reference to the given string and assigns it to the Unit field. +func (o *Ram) SetUnit(v string) { + o.Unit = &v +} + +func (o Ram) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o Ram) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Size) { + toSerialize["size"] = o.Size + } + if !IsNil(o.Unit) { + toSerialize["unit"] = o.Unit + } + return toSerialize, nil +} + +type NullableRam struct { + value *Ram + isSet bool +} + +func (v NullableRam) Get() *Ram { + return v.value +} + +func (v *NullableRam) Set(val *Ram) { + v.value = val + v.isSet = true +} + +func (v NullableRam) IsSet() bool { + return v.isSet +} + +func (v *NullableRam) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableRam(val *Ram) *NullableRam { + return &NullableRam{value: val, isSet: true} +} + +func (v NullableRam) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableRam) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/dedicatedserver/model_server.go b/dedicatedserver/model_server.go new file mode 100644 index 0000000..52190a5 --- /dev/null +++ b/dedicatedserver/model_server.go @@ -0,0 +1,496 @@ +/* +Leaseweb API for dedicated servers + +This documents the rest api dedicatedserver provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package dedicatedserver + +import ( + "encoding/json" +) + +// checks if the Server type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &Server{} + +// Server struct for Server +type Server struct { + // The Asset Id of the server + AssetId *string `json:"assetId,omitempty"` + // Contract information + Contract map[string]interface{} `json:"contract,omitempty"` + // List of features that are available for this server + FeatureAvailability map[string]interface{} `json:"featureAvailability,omitempty"` + // Id of the server + Id *string `json:"id,omitempty"` + // Location of the server + Location map[string]interface{} `json:"location,omitempty"` + // Network interface information grouped by type + NetworkInterfaces map[string]interface{} `json:"networkInterfaces,omitempty"` + // List of ports that can be used to manage power of the server + PowerPorts []Powerport `json:"powerPorts,omitempty"` + // An array of private networks + PrivateNetworks []PrivateNetwork `json:"privateNetworks,omitempty"` + Rack *Rack `json:"rack,omitempty"` + // Serial number of server + SerialNumber *string `json:"serialNumber,omitempty"` + Specs *ServerSpecs `json:"specs,omitempty"` +} + +// NewServer instantiates a new Server object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewServer() *Server { + this := Server{} + return &this +} + +// NewServerWithDefaults instantiates a new Server object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewServerWithDefaults() *Server { + this := Server{} + return &this +} + +// GetAssetId returns the AssetId field value if set, zero value otherwise. +func (o *Server) GetAssetId() string { + if o == nil || IsNil(o.AssetId) { + var ret string + return ret + } + return *o.AssetId +} + +// GetAssetIdOk returns a tuple with the AssetId field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Server) GetAssetIdOk() (*string, bool) { + if o == nil || IsNil(o.AssetId) { + return nil, false + } + return o.AssetId, true +} + +// HasAssetId returns a boolean if a field has been set. +func (o *Server) HasAssetId() bool { + if o != nil && !IsNil(o.AssetId) { + return true + } + + return false +} + +// SetAssetId gets a reference to the given string and assigns it to the AssetId field. +func (o *Server) SetAssetId(v string) { + o.AssetId = &v +} + +// GetContract returns the Contract field value if set, zero value otherwise. +func (o *Server) GetContract() map[string]interface{} { + if o == nil || IsNil(o.Contract) { + var ret map[string]interface{} + return ret + } + return o.Contract +} + +// GetContractOk returns a tuple with the Contract field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Server) GetContractOk() (map[string]interface{}, bool) { + if o == nil || IsNil(o.Contract) { + return map[string]interface{}{}, false + } + return o.Contract, true +} + +// HasContract returns a boolean if a field has been set. +func (o *Server) HasContract() bool { + if o != nil && !IsNil(o.Contract) { + return true + } + + return false +} + +// SetContract gets a reference to the given map[string]interface{} and assigns it to the Contract field. +func (o *Server) SetContract(v map[string]interface{}) { + o.Contract = v +} + +// GetFeatureAvailability returns the FeatureAvailability field value if set, zero value otherwise. +func (o *Server) GetFeatureAvailability() map[string]interface{} { + if o == nil || IsNil(o.FeatureAvailability) { + var ret map[string]interface{} + return ret + } + return o.FeatureAvailability +} + +// GetFeatureAvailabilityOk returns a tuple with the FeatureAvailability field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Server) GetFeatureAvailabilityOk() (map[string]interface{}, bool) { + if o == nil || IsNil(o.FeatureAvailability) { + return map[string]interface{}{}, false + } + return o.FeatureAvailability, true +} + +// HasFeatureAvailability returns a boolean if a field has been set. +func (o *Server) HasFeatureAvailability() bool { + if o != nil && !IsNil(o.FeatureAvailability) { + return true + } + + return false +} + +// SetFeatureAvailability gets a reference to the given map[string]interface{} and assigns it to the FeatureAvailability field. +func (o *Server) SetFeatureAvailability(v map[string]interface{}) { + o.FeatureAvailability = v +} + +// GetId returns the Id field value if set, zero value otherwise. +func (o *Server) GetId() string { + if o == nil || IsNil(o.Id) { + var ret string + return ret + } + return *o.Id +} + +// GetIdOk returns a tuple with the Id field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Server) GetIdOk() (*string, bool) { + if o == nil || IsNil(o.Id) { + return nil, false + } + return o.Id, true +} + +// HasId returns a boolean if a field has been set. +func (o *Server) HasId() bool { + if o != nil && !IsNil(o.Id) { + return true + } + + return false +} + +// SetId gets a reference to the given string and assigns it to the Id field. +func (o *Server) SetId(v string) { + o.Id = &v +} + +// GetLocation returns the Location field value if set, zero value otherwise. +func (o *Server) GetLocation() map[string]interface{} { + if o == nil || IsNil(o.Location) { + var ret map[string]interface{} + return ret + } + return o.Location +} + +// GetLocationOk returns a tuple with the Location field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Server) GetLocationOk() (map[string]interface{}, bool) { + if o == nil || IsNil(o.Location) { + return map[string]interface{}{}, false + } + return o.Location, true +} + +// HasLocation returns a boolean if a field has been set. +func (o *Server) HasLocation() bool { + if o != nil && !IsNil(o.Location) { + return true + } + + return false +} + +// SetLocation gets a reference to the given map[string]interface{} and assigns it to the Location field. +func (o *Server) SetLocation(v map[string]interface{}) { + o.Location = v +} + +// GetNetworkInterfaces returns the NetworkInterfaces field value if set, zero value otherwise. +func (o *Server) GetNetworkInterfaces() map[string]interface{} { + if o == nil || IsNil(o.NetworkInterfaces) { + var ret map[string]interface{} + return ret + } + return o.NetworkInterfaces +} + +// GetNetworkInterfacesOk returns a tuple with the NetworkInterfaces field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Server) GetNetworkInterfacesOk() (map[string]interface{}, bool) { + if o == nil || IsNil(o.NetworkInterfaces) { + return map[string]interface{}{}, false + } + return o.NetworkInterfaces, true +} + +// HasNetworkInterfaces returns a boolean if a field has been set. +func (o *Server) HasNetworkInterfaces() bool { + if o != nil && !IsNil(o.NetworkInterfaces) { + return true + } + + return false +} + +// SetNetworkInterfaces gets a reference to the given map[string]interface{} and assigns it to the NetworkInterfaces field. +func (o *Server) SetNetworkInterfaces(v map[string]interface{}) { + o.NetworkInterfaces = v +} + +// GetPowerPorts returns the PowerPorts field value if set, zero value otherwise. +func (o *Server) GetPowerPorts() []Powerport { + if o == nil || IsNil(o.PowerPorts) { + var ret []Powerport + return ret + } + return o.PowerPorts +} + +// GetPowerPortsOk returns a tuple with the PowerPorts field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Server) GetPowerPortsOk() ([]Powerport, bool) { + if o == nil || IsNil(o.PowerPorts) { + return nil, false + } + return o.PowerPorts, true +} + +// HasPowerPorts returns a boolean if a field has been set. +func (o *Server) HasPowerPorts() bool { + if o != nil && !IsNil(o.PowerPorts) { + return true + } + + return false +} + +// SetPowerPorts gets a reference to the given []Powerport and assigns it to the PowerPorts field. +func (o *Server) SetPowerPorts(v []Powerport) { + o.PowerPorts = v +} + +// GetPrivateNetworks returns the PrivateNetworks field value if set, zero value otherwise. +func (o *Server) GetPrivateNetworks() []PrivateNetwork { + if o == nil || IsNil(o.PrivateNetworks) { + var ret []PrivateNetwork + return ret + } + return o.PrivateNetworks +} + +// GetPrivateNetworksOk returns a tuple with the PrivateNetworks field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Server) GetPrivateNetworksOk() ([]PrivateNetwork, bool) { + if o == nil || IsNil(o.PrivateNetworks) { + return nil, false + } + return o.PrivateNetworks, true +} + +// HasPrivateNetworks returns a boolean if a field has been set. +func (o *Server) HasPrivateNetworks() bool { + if o != nil && !IsNil(o.PrivateNetworks) { + return true + } + + return false +} + +// SetPrivateNetworks gets a reference to the given []PrivateNetwork and assigns it to the PrivateNetworks field. +func (o *Server) SetPrivateNetworks(v []PrivateNetwork) { + o.PrivateNetworks = v +} + +// GetRack returns the Rack field value if set, zero value otherwise. +func (o *Server) GetRack() Rack { + if o == nil || IsNil(o.Rack) { + var ret Rack + return ret + } + return *o.Rack +} + +// GetRackOk returns a tuple with the Rack field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Server) GetRackOk() (*Rack, bool) { + if o == nil || IsNil(o.Rack) { + return nil, false + } + return o.Rack, true +} + +// HasRack returns a boolean if a field has been set. +func (o *Server) HasRack() bool { + if o != nil && !IsNil(o.Rack) { + return true + } + + return false +} + +// SetRack gets a reference to the given Rack and assigns it to the Rack field. +func (o *Server) SetRack(v Rack) { + o.Rack = &v +} + +// GetSerialNumber returns the SerialNumber field value if set, zero value otherwise. +func (o *Server) GetSerialNumber() string { + if o == nil || IsNil(o.SerialNumber) { + var ret string + return ret + } + return *o.SerialNumber +} + +// GetSerialNumberOk returns a tuple with the SerialNumber field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Server) GetSerialNumberOk() (*string, bool) { + if o == nil || IsNil(o.SerialNumber) { + return nil, false + } + return o.SerialNumber, true +} + +// HasSerialNumber returns a boolean if a field has been set. +func (o *Server) HasSerialNumber() bool { + if o != nil && !IsNil(o.SerialNumber) { + return true + } + + return false +} + +// SetSerialNumber gets a reference to the given string and assigns it to the SerialNumber field. +func (o *Server) SetSerialNumber(v string) { + o.SerialNumber = &v +} + +// GetSpecs returns the Specs field value if set, zero value otherwise. +func (o *Server) GetSpecs() ServerSpecs { + if o == nil || IsNil(o.Specs) { + var ret ServerSpecs + return ret + } + return *o.Specs +} + +// GetSpecsOk returns a tuple with the Specs field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Server) GetSpecsOk() (*ServerSpecs, bool) { + if o == nil || IsNil(o.Specs) { + return nil, false + } + return o.Specs, true +} + +// HasSpecs returns a boolean if a field has been set. +func (o *Server) HasSpecs() bool { + if o != nil && !IsNil(o.Specs) { + return true + } + + return false +} + +// SetSpecs gets a reference to the given ServerSpecs and assigns it to the Specs field. +func (o *Server) SetSpecs(v ServerSpecs) { + o.Specs = &v +} + +func (o Server) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o Server) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.AssetId) { + toSerialize["assetId"] = o.AssetId + } + if !IsNil(o.Contract) { + toSerialize["contract"] = o.Contract + } + if !IsNil(o.FeatureAvailability) { + toSerialize["featureAvailability"] = o.FeatureAvailability + } + if !IsNil(o.Id) { + toSerialize["id"] = o.Id + } + if !IsNil(o.Location) { + toSerialize["location"] = o.Location + } + if !IsNil(o.NetworkInterfaces) { + toSerialize["networkInterfaces"] = o.NetworkInterfaces + } + if !IsNil(o.PowerPorts) { + toSerialize["powerPorts"] = o.PowerPorts + } + if !IsNil(o.PrivateNetworks) { + toSerialize["privateNetworks"] = o.PrivateNetworks + } + if !IsNil(o.Rack) { + toSerialize["rack"] = o.Rack + } + if !IsNil(o.SerialNumber) { + toSerialize["serialNumber"] = o.SerialNumber + } + if !IsNil(o.Specs) { + toSerialize["specs"] = o.Specs + } + return toSerialize, nil +} + +type NullableServer struct { + value *Server + isSet bool +} + +func (v NullableServer) Get() *Server { + return v.value +} + +func (v *NullableServer) Set(val *Server) { + v.value = val + v.isSet = true +} + +func (v NullableServer) IsSet() bool { + return v.isSet +} + +func (v *NullableServer) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableServer(val *Server) *NullableServer { + return &NullableServer{value: val, isSet: true} +} + +func (v NullableServer) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableServer) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/dedicatedserver/model_server_specs.go b/dedicatedserver/model_server_specs.go new file mode 100644 index 0000000..e1c2438 --- /dev/null +++ b/dedicatedserver/model_server_specs.go @@ -0,0 +1,311 @@ +/* +Leaseweb API for dedicated servers + +This documents the rest api dedicatedserver provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package dedicatedserver + +import ( + "encoding/json" +) + +// checks if the ServerSpecs type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &ServerSpecs{} + +// ServerSpecs Hardware information of the server +type ServerSpecs struct { + // The chassis description of the server + Chassis *string `json:"chassis,omitempty"` + Cpu *Cpu `json:"cpu,omitempty"` + // Hardware RAID capability of the server + HardwareRaidCapable *bool `json:"hardwareRaidCapable,omitempty"` + // List of hard disk drives of the server + Hdd []Hdd `json:"hdd,omitempty"` + // List of PCI cards of the server + PciCards []PciCard `json:"pciCards,omitempty"` + Ram *Ram `json:"ram,omitempty"` +} + +// NewServerSpecs instantiates a new ServerSpecs object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewServerSpecs() *ServerSpecs { + this := ServerSpecs{} + return &this +} + +// NewServerSpecsWithDefaults instantiates a new ServerSpecs object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewServerSpecsWithDefaults() *ServerSpecs { + this := ServerSpecs{} + return &this +} + +// GetChassis returns the Chassis field value if set, zero value otherwise. +func (o *ServerSpecs) GetChassis() string { + if o == nil || IsNil(o.Chassis) { + var ret string + return ret + } + return *o.Chassis +} + +// GetChassisOk returns a tuple with the Chassis field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ServerSpecs) GetChassisOk() (*string, bool) { + if o == nil || IsNil(o.Chassis) { + return nil, false + } + return o.Chassis, true +} + +// HasChassis returns a boolean if a field has been set. +func (o *ServerSpecs) HasChassis() bool { + if o != nil && !IsNil(o.Chassis) { + return true + } + + return false +} + +// SetChassis gets a reference to the given string and assigns it to the Chassis field. +func (o *ServerSpecs) SetChassis(v string) { + o.Chassis = &v +} + +// GetCpu returns the Cpu field value if set, zero value otherwise. +func (o *ServerSpecs) GetCpu() Cpu { + if o == nil || IsNil(o.Cpu) { + var ret Cpu + return ret + } + return *o.Cpu +} + +// GetCpuOk returns a tuple with the Cpu field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ServerSpecs) GetCpuOk() (*Cpu, bool) { + if o == nil || IsNil(o.Cpu) { + return nil, false + } + return o.Cpu, true +} + +// HasCpu returns a boolean if a field has been set. +func (o *ServerSpecs) HasCpu() bool { + if o != nil && !IsNil(o.Cpu) { + return true + } + + return false +} + +// SetCpu gets a reference to the given Cpu and assigns it to the Cpu field. +func (o *ServerSpecs) SetCpu(v Cpu) { + o.Cpu = &v +} + +// GetHardwareRaidCapable returns the HardwareRaidCapable field value if set, zero value otherwise. +func (o *ServerSpecs) GetHardwareRaidCapable() bool { + if o == nil || IsNil(o.HardwareRaidCapable) { + var ret bool + return ret + } + return *o.HardwareRaidCapable +} + +// GetHardwareRaidCapableOk returns a tuple with the HardwareRaidCapable field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ServerSpecs) GetHardwareRaidCapableOk() (*bool, bool) { + if o == nil || IsNil(o.HardwareRaidCapable) { + return nil, false + } + return o.HardwareRaidCapable, true +} + +// HasHardwareRaidCapable returns a boolean if a field has been set. +func (o *ServerSpecs) HasHardwareRaidCapable() bool { + if o != nil && !IsNil(o.HardwareRaidCapable) { + return true + } + + return false +} + +// SetHardwareRaidCapable gets a reference to the given bool and assigns it to the HardwareRaidCapable field. +func (o *ServerSpecs) SetHardwareRaidCapable(v bool) { + o.HardwareRaidCapable = &v +} + +// GetHdd returns the Hdd field value if set, zero value otherwise. +func (o *ServerSpecs) GetHdd() []Hdd { + if o == nil || IsNil(o.Hdd) { + var ret []Hdd + return ret + } + return o.Hdd +} + +// GetHddOk returns a tuple with the Hdd field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ServerSpecs) GetHddOk() ([]Hdd, bool) { + if o == nil || IsNil(o.Hdd) { + return nil, false + } + return o.Hdd, true +} + +// HasHdd returns a boolean if a field has been set. +func (o *ServerSpecs) HasHdd() bool { + if o != nil && !IsNil(o.Hdd) { + return true + } + + return false +} + +// SetHdd gets a reference to the given []Hdd and assigns it to the Hdd field. +func (o *ServerSpecs) SetHdd(v []Hdd) { + o.Hdd = v +} + +// GetPciCards returns the PciCards field value if set, zero value otherwise. +func (o *ServerSpecs) GetPciCards() []PciCard { + if o == nil || IsNil(o.PciCards) { + var ret []PciCard + return ret + } + return o.PciCards +} + +// GetPciCardsOk returns a tuple with the PciCards field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ServerSpecs) GetPciCardsOk() ([]PciCard, bool) { + if o == nil || IsNil(o.PciCards) { + return nil, false + } + return o.PciCards, true +} + +// HasPciCards returns a boolean if a field has been set. +func (o *ServerSpecs) HasPciCards() bool { + if o != nil && !IsNil(o.PciCards) { + return true + } + + return false +} + +// SetPciCards gets a reference to the given []PciCard and assigns it to the PciCards field. +func (o *ServerSpecs) SetPciCards(v []PciCard) { + o.PciCards = v +} + +// GetRam returns the Ram field value if set, zero value otherwise. +func (o *ServerSpecs) GetRam() Ram { + if o == nil || IsNil(o.Ram) { + var ret Ram + return ret + } + return *o.Ram +} + +// GetRamOk returns a tuple with the Ram field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ServerSpecs) GetRamOk() (*Ram, bool) { + if o == nil || IsNil(o.Ram) { + return nil, false + } + return o.Ram, true +} + +// HasRam returns a boolean if a field has been set. +func (o *ServerSpecs) HasRam() bool { + if o != nil && !IsNil(o.Ram) { + return true + } + + return false +} + +// SetRam gets a reference to the given Ram and assigns it to the Ram field. +func (o *ServerSpecs) SetRam(v Ram) { + o.Ram = &v +} + +func (o ServerSpecs) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o ServerSpecs) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Chassis) { + toSerialize["chassis"] = o.Chassis + } + if !IsNil(o.Cpu) { + toSerialize["cpu"] = o.Cpu + } + if !IsNil(o.HardwareRaidCapable) { + toSerialize["hardwareRaidCapable"] = o.HardwareRaidCapable + } + if !IsNil(o.Hdd) { + toSerialize["hdd"] = o.Hdd + } + if !IsNil(o.PciCards) { + toSerialize["pciCards"] = o.PciCards + } + if !IsNil(o.Ram) { + toSerialize["ram"] = o.Ram + } + return toSerialize, nil +} + +type NullableServerSpecs struct { + value *ServerSpecs + isSet bool +} + +func (v NullableServerSpecs) Get() *ServerSpecs { + return v.value +} + +func (v *NullableServerSpecs) Set(val *ServerSpecs) { + v.value = val + v.isSet = true +} + +func (v NullableServerSpecs) IsSet() bool { + return v.isSet +} + +func (v *NullableServerSpecs) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableServerSpecs(val *ServerSpecs) *NullableServerSpecs { + return &NullableServerSpecs{value: val, isSet: true} +} + +func (v NullableServerSpecs) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableServerSpecs) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/dedicatedserver/model_update_ip_profile_opts.go b/dedicatedserver/model_update_ip_profile_opts.go new file mode 100644 index 0000000..9d947df --- /dev/null +++ b/dedicatedserver/model_update_ip_profile_opts.go @@ -0,0 +1,165 @@ +/* +Leaseweb API for dedicated servers + +This documents the rest api dedicatedserver provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package dedicatedserver + +import ( + "encoding/json" +) + +// checks if the UpdateIpProfileOpts type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &UpdateIpProfileOpts{} + +// UpdateIpProfileOpts struct for UpdateIpProfileOpts +type UpdateIpProfileOpts struct { + // The detection profile value + DetectionProfile *string `json:"detectionProfile,omitempty"` + // The reverse lookup value + ReverseLookup *string `json:"reverseLookup,omitempty"` +} + +// NewUpdateIpProfileOpts instantiates a new UpdateIpProfileOpts object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewUpdateIpProfileOpts() *UpdateIpProfileOpts { + this := UpdateIpProfileOpts{} + return &this +} + +// NewUpdateIpProfileOptsWithDefaults instantiates a new UpdateIpProfileOpts object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewUpdateIpProfileOptsWithDefaults() *UpdateIpProfileOpts { + this := UpdateIpProfileOpts{} + return &this +} + +// GetDetectionProfile returns the DetectionProfile field value if set, zero value otherwise. +func (o *UpdateIpProfileOpts) GetDetectionProfile() string { + if o == nil || IsNil(o.DetectionProfile) { + var ret string + return ret + } + return *o.DetectionProfile +} + +// GetDetectionProfileOk returns a tuple with the DetectionProfile field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *UpdateIpProfileOpts) GetDetectionProfileOk() (*string, bool) { + if o == nil || IsNil(o.DetectionProfile) { + return nil, false + } + return o.DetectionProfile, true +} + +// HasDetectionProfile returns a boolean if a field has been set. +func (o *UpdateIpProfileOpts) HasDetectionProfile() bool { + if o != nil && !IsNil(o.DetectionProfile) { + return true + } + + return false +} + +// SetDetectionProfile gets a reference to the given string and assigns it to the DetectionProfile field. +func (o *UpdateIpProfileOpts) SetDetectionProfile(v string) { + o.DetectionProfile = &v +} + +// GetReverseLookup returns the ReverseLookup field value if set, zero value otherwise. +func (o *UpdateIpProfileOpts) GetReverseLookup() string { + if o == nil || IsNil(o.ReverseLookup) { + var ret string + return ret + } + return *o.ReverseLookup +} + +// GetReverseLookupOk returns a tuple with the ReverseLookup field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *UpdateIpProfileOpts) GetReverseLookupOk() (*string, bool) { + if o == nil || IsNil(o.ReverseLookup) { + return nil, false + } + return o.ReverseLookup, true +} + +// HasReverseLookup returns a boolean if a field has been set. +func (o *UpdateIpProfileOpts) HasReverseLookup() bool { + if o != nil && !IsNil(o.ReverseLookup) { + return true + } + + return false +} + +// SetReverseLookup gets a reference to the given string and assigns it to the ReverseLookup field. +func (o *UpdateIpProfileOpts) SetReverseLookup(v string) { + o.ReverseLookup = &v +} + +func (o UpdateIpProfileOpts) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o UpdateIpProfileOpts) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.DetectionProfile) { + toSerialize["detectionProfile"] = o.DetectionProfile + } + if !IsNil(o.ReverseLookup) { + toSerialize["reverseLookup"] = o.ReverseLookup + } + return toSerialize, nil +} + +type NullableUpdateIpProfileOpts struct { + value *UpdateIpProfileOpts + isSet bool +} + +func (v NullableUpdateIpProfileOpts) Get() *UpdateIpProfileOpts { + return v.value +} + +func (v *NullableUpdateIpProfileOpts) Set(val *UpdateIpProfileOpts) { + v.value = val + v.isSet = true +} + +func (v NullableUpdateIpProfileOpts) IsSet() bool { + return v.isSet +} + +func (v *NullableUpdateIpProfileOpts) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableUpdateIpProfileOpts(val *UpdateIpProfileOpts) *NullableUpdateIpProfileOpts { + return &NullableUpdateIpProfileOpts{value: val, isSet: true} +} + +func (v NullableUpdateIpProfileOpts) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableUpdateIpProfileOpts) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/dedicatedserver/model_update_network_equipment_ip_opts.go b/dedicatedserver/model_update_network_equipment_ip_opts.go new file mode 100644 index 0000000..d756d85 --- /dev/null +++ b/dedicatedserver/model_update_network_equipment_ip_opts.go @@ -0,0 +1,165 @@ +/* +Leaseweb API for dedicated servers + +This documents the rest api dedicatedserver provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package dedicatedserver + +import ( + "encoding/json" +) + +// checks if the UpdateNetworkEquipmentIpOpts type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &UpdateNetworkEquipmentIpOpts{} + +// UpdateNetworkEquipmentIpOpts struct for UpdateNetworkEquipmentIpOpts +type UpdateNetworkEquipmentIpOpts struct { + // The detection profile value + DetectionProfile *string `json:"detectionProfile,omitempty"` + // The reverse lookup value + ReverseLookup *string `json:"reverseLookup,omitempty"` +} + +// NewUpdateNetworkEquipmentIpOpts instantiates a new UpdateNetworkEquipmentIpOpts object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewUpdateNetworkEquipmentIpOpts() *UpdateNetworkEquipmentIpOpts { + this := UpdateNetworkEquipmentIpOpts{} + return &this +} + +// NewUpdateNetworkEquipmentIpOptsWithDefaults instantiates a new UpdateNetworkEquipmentIpOpts object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewUpdateNetworkEquipmentIpOptsWithDefaults() *UpdateNetworkEquipmentIpOpts { + this := UpdateNetworkEquipmentIpOpts{} + return &this +} + +// GetDetectionProfile returns the DetectionProfile field value if set, zero value otherwise. +func (o *UpdateNetworkEquipmentIpOpts) GetDetectionProfile() string { + if o == nil || IsNil(o.DetectionProfile) { + var ret string + return ret + } + return *o.DetectionProfile +} + +// GetDetectionProfileOk returns a tuple with the DetectionProfile field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *UpdateNetworkEquipmentIpOpts) GetDetectionProfileOk() (*string, bool) { + if o == nil || IsNil(o.DetectionProfile) { + return nil, false + } + return o.DetectionProfile, true +} + +// HasDetectionProfile returns a boolean if a field has been set. +func (o *UpdateNetworkEquipmentIpOpts) HasDetectionProfile() bool { + if o != nil && !IsNil(o.DetectionProfile) { + return true + } + + return false +} + +// SetDetectionProfile gets a reference to the given string and assigns it to the DetectionProfile field. +func (o *UpdateNetworkEquipmentIpOpts) SetDetectionProfile(v string) { + o.DetectionProfile = &v +} + +// GetReverseLookup returns the ReverseLookup field value if set, zero value otherwise. +func (o *UpdateNetworkEquipmentIpOpts) GetReverseLookup() string { + if o == nil || IsNil(o.ReverseLookup) { + var ret string + return ret + } + return *o.ReverseLookup +} + +// GetReverseLookupOk returns a tuple with the ReverseLookup field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *UpdateNetworkEquipmentIpOpts) GetReverseLookupOk() (*string, bool) { + if o == nil || IsNil(o.ReverseLookup) { + return nil, false + } + return o.ReverseLookup, true +} + +// HasReverseLookup returns a boolean if a field has been set. +func (o *UpdateNetworkEquipmentIpOpts) HasReverseLookup() bool { + if o != nil && !IsNil(o.ReverseLookup) { + return true + } + + return false +} + +// SetReverseLookup gets a reference to the given string and assigns it to the ReverseLookup field. +func (o *UpdateNetworkEquipmentIpOpts) SetReverseLookup(v string) { + o.ReverseLookup = &v +} + +func (o UpdateNetworkEquipmentIpOpts) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o UpdateNetworkEquipmentIpOpts) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.DetectionProfile) { + toSerialize["detectionProfile"] = o.DetectionProfile + } + if !IsNil(o.ReverseLookup) { + toSerialize["reverseLookup"] = o.ReverseLookup + } + return toSerialize, nil +} + +type NullableUpdateNetworkEquipmentIpOpts struct { + value *UpdateNetworkEquipmentIpOpts + isSet bool +} + +func (v NullableUpdateNetworkEquipmentIpOpts) Get() *UpdateNetworkEquipmentIpOpts { + return v.value +} + +func (v *NullableUpdateNetworkEquipmentIpOpts) Set(val *UpdateNetworkEquipmentIpOpts) { + v.value = val + v.isSet = true +} + +func (v NullableUpdateNetworkEquipmentIpOpts) IsSet() bool { + return v.isSet +} + +func (v *NullableUpdateNetworkEquipmentIpOpts) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableUpdateNetworkEquipmentIpOpts(val *UpdateNetworkEquipmentIpOpts) *NullableUpdateNetworkEquipmentIpOpts { + return &NullableUpdateNetworkEquipmentIpOpts{value: val, isSet: true} +} + +func (v NullableUpdateNetworkEquipmentIpOpts) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableUpdateNetworkEquipmentIpOpts) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/dedicatedserver/model_update_network_equipment_reference_opts.go b/dedicatedserver/model_update_network_equipment_reference_opts.go new file mode 100644 index 0000000..b9fc890 --- /dev/null +++ b/dedicatedserver/model_update_network_equipment_reference_opts.go @@ -0,0 +1,160 @@ +/* +Leaseweb API for dedicated servers + +This documents the rest api dedicatedserver provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package dedicatedserver + +import ( + "encoding/json" + "bytes" + "fmt" +) + +// checks if the UpdateNetworkEquipmentReferenceOpts type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &UpdateNetworkEquipmentReferenceOpts{} + +// UpdateNetworkEquipmentReferenceOpts struct for UpdateNetworkEquipmentReferenceOpts +type UpdateNetworkEquipmentReferenceOpts struct { + // The reference for this network equipment + Reference string `json:"reference"` +} + +type _UpdateNetworkEquipmentReferenceOpts UpdateNetworkEquipmentReferenceOpts + +// NewUpdateNetworkEquipmentReferenceOpts instantiates a new UpdateNetworkEquipmentReferenceOpts object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewUpdateNetworkEquipmentReferenceOpts(reference string) *UpdateNetworkEquipmentReferenceOpts { + this := UpdateNetworkEquipmentReferenceOpts{} + this.Reference = reference + return &this +} + +// NewUpdateNetworkEquipmentReferenceOptsWithDefaults instantiates a new UpdateNetworkEquipmentReferenceOpts object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewUpdateNetworkEquipmentReferenceOptsWithDefaults() *UpdateNetworkEquipmentReferenceOpts { + this := UpdateNetworkEquipmentReferenceOpts{} + return &this +} + +// GetReference returns the Reference field value +func (o *UpdateNetworkEquipmentReferenceOpts) GetReference() string { + if o == nil { + var ret string + return ret + } + + return o.Reference +} + +// GetReferenceOk returns a tuple with the Reference field value +// and a boolean to check if the value has been set. +func (o *UpdateNetworkEquipmentReferenceOpts) GetReferenceOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.Reference, true +} + +// SetReference sets field value +func (o *UpdateNetworkEquipmentReferenceOpts) SetReference(v string) { + o.Reference = v +} + +func (o UpdateNetworkEquipmentReferenceOpts) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o UpdateNetworkEquipmentReferenceOpts) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + toSerialize["reference"] = o.Reference + return toSerialize, nil +} + +func (o *UpdateNetworkEquipmentReferenceOpts) UnmarshalJSON(data []byte) (err error) { + // This validates that all required properties are included in the JSON object + // by unmarshalling the object into a generic map with string keys and checking + // that every required field exists as a key in the generic map. + requiredProperties := []string{ + "reference", + } + + allProperties := make(map[string]interface{}) + + err = json.Unmarshal(data, &allProperties) + + if err != nil { + return err; + } + + for _, requiredProperty := range(requiredProperties) { + if _, exists := allProperties[requiredProperty]; !exists { + return fmt.Errorf("no value given for required property %v", requiredProperty) + } + } + + varUpdateNetworkEquipmentReferenceOpts := _UpdateNetworkEquipmentReferenceOpts{} + + decoder := json.NewDecoder(bytes.NewReader(data)) + decoder.DisallowUnknownFields() + err = decoder.Decode(&varUpdateNetworkEquipmentReferenceOpts) + + if err != nil { + return err + } + + *o = UpdateNetworkEquipmentReferenceOpts(varUpdateNetworkEquipmentReferenceOpts) + + return err +} + +type NullableUpdateNetworkEquipmentReferenceOpts struct { + value *UpdateNetworkEquipmentReferenceOpts + isSet bool +} + +func (v NullableUpdateNetworkEquipmentReferenceOpts) Get() *UpdateNetworkEquipmentReferenceOpts { + return v.value +} + +func (v *NullableUpdateNetworkEquipmentReferenceOpts) Set(val *UpdateNetworkEquipmentReferenceOpts) { + v.value = val + v.isSet = true +} + +func (v NullableUpdateNetworkEquipmentReferenceOpts) IsSet() bool { + return v.isSet +} + +func (v *NullableUpdateNetworkEquipmentReferenceOpts) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableUpdateNetworkEquipmentReferenceOpts(val *UpdateNetworkEquipmentReferenceOpts) *NullableUpdateNetworkEquipmentReferenceOpts { + return &NullableUpdateNetworkEquipmentReferenceOpts{value: val, isSet: true} +} + +func (v NullableUpdateNetworkEquipmentReferenceOpts) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableUpdateNetworkEquipmentReferenceOpts) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/dedicatedserver/model_update_server_reference_opts.go b/dedicatedserver/model_update_server_reference_opts.go new file mode 100644 index 0000000..819c3c8 --- /dev/null +++ b/dedicatedserver/model_update_server_reference_opts.go @@ -0,0 +1,160 @@ +/* +Leaseweb API for dedicated servers + +This documents the rest api dedicatedserver provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package dedicatedserver + +import ( + "encoding/json" + "bytes" + "fmt" +) + +// checks if the UpdateServerReferenceOpts type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &UpdateServerReferenceOpts{} + +// UpdateServerReferenceOpts struct for UpdateServerReferenceOpts +type UpdateServerReferenceOpts struct { + // The reference for this server + Reference string `json:"reference"` +} + +type _UpdateServerReferenceOpts UpdateServerReferenceOpts + +// NewUpdateServerReferenceOpts instantiates a new UpdateServerReferenceOpts object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewUpdateServerReferenceOpts(reference string) *UpdateServerReferenceOpts { + this := UpdateServerReferenceOpts{} + this.Reference = reference + return &this +} + +// NewUpdateServerReferenceOptsWithDefaults instantiates a new UpdateServerReferenceOpts object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewUpdateServerReferenceOptsWithDefaults() *UpdateServerReferenceOpts { + this := UpdateServerReferenceOpts{} + return &this +} + +// GetReference returns the Reference field value +func (o *UpdateServerReferenceOpts) GetReference() string { + if o == nil { + var ret string + return ret + } + + return o.Reference +} + +// GetReferenceOk returns a tuple with the Reference field value +// and a boolean to check if the value has been set. +func (o *UpdateServerReferenceOpts) GetReferenceOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.Reference, true +} + +// SetReference sets field value +func (o *UpdateServerReferenceOpts) SetReference(v string) { + o.Reference = v +} + +func (o UpdateServerReferenceOpts) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o UpdateServerReferenceOpts) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + toSerialize["reference"] = o.Reference + return toSerialize, nil +} + +func (o *UpdateServerReferenceOpts) UnmarshalJSON(data []byte) (err error) { + // This validates that all required properties are included in the JSON object + // by unmarshalling the object into a generic map with string keys and checking + // that every required field exists as a key in the generic map. + requiredProperties := []string{ + "reference", + } + + allProperties := make(map[string]interface{}) + + err = json.Unmarshal(data, &allProperties) + + if err != nil { + return err; + } + + for _, requiredProperty := range(requiredProperties) { + if _, exists := allProperties[requiredProperty]; !exists { + return fmt.Errorf("no value given for required property %v", requiredProperty) + } + } + + varUpdateServerReferenceOpts := _UpdateServerReferenceOpts{} + + decoder := json.NewDecoder(bytes.NewReader(data)) + decoder.DisallowUnknownFields() + err = decoder.Decode(&varUpdateServerReferenceOpts) + + if err != nil { + return err + } + + *o = UpdateServerReferenceOpts(varUpdateServerReferenceOpts) + + return err +} + +type NullableUpdateServerReferenceOpts struct { + value *UpdateServerReferenceOpts + isSet bool +} + +func (v NullableUpdateServerReferenceOpts) Get() *UpdateServerReferenceOpts { + return v.value +} + +func (v *NullableUpdateServerReferenceOpts) Set(val *UpdateServerReferenceOpts) { + v.value = val + v.isSet = true +} + +func (v NullableUpdateServerReferenceOpts) IsSet() bool { + return v.isSet +} + +func (v *NullableUpdateServerReferenceOpts) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableUpdateServerReferenceOpts(val *UpdateServerReferenceOpts) *NullableUpdateServerReferenceOpts { + return &NullableUpdateServerReferenceOpts{value: val, isSet: true} +} + +func (v NullableUpdateServerReferenceOpts) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableUpdateServerReferenceOpts) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/dedicatedserver/response.go b/dedicatedserver/response.go new file mode 100644 index 0000000..d6d4615 --- /dev/null +++ b/dedicatedserver/response.go @@ -0,0 +1,48 @@ +/* +Leaseweb API for dedicated servers + +This documents the rest api dedicatedserver provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package dedicatedserver + +import ( + "net/http" +) + +// APIResponse stores the API response returned by the server. +type APIResponse struct { + *http.Response `json:"-"` + Message string `json:"message,omitempty"` + // Operation is the name of the OpenAPI operation. + Operation string `json:"operation,omitempty"` + // RequestURL is the request URL. This value is always available, even if the + // embedded *http.Response is nil. + RequestURL string `json:"url,omitempty"` + // Method is the HTTP method used for the request. This value is always + // available, even if the embedded *http.Response is nil. + Method string `json:"method,omitempty"` + // Payload holds the contents of the response body (which may be nil or empty). + // This is provided here as the raw response.Body() reader will have already + // been drained. + Payload []byte `json:"-"` +} + +// NewAPIResponse returns a new APIResponse object. +func NewAPIResponse(r *http.Response) *APIResponse { + + response := &APIResponse{Response: r} + return response +} + +// NewAPIResponseWithError returns a new APIResponse object with the provided error message. +func NewAPIResponseWithError(errorMessage string) *APIResponse { + + response := &APIResponse{Message: errorMessage} + return response +} diff --git a/dedicatedserver/test/api_dedicatedserver_test.go b/dedicatedserver/test/api_dedicatedserver_test.go new file mode 100644 index 0000000..7d5b992 --- /dev/null +++ b/dedicatedserver/test/api_dedicatedserver_test.go @@ -0,0 +1,307 @@ +/* +Leaseweb API for dedicated servers + +Testing DedicatedserverAPIService + +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); + +package dedicatedserver + +import ( + "context" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "testing" + openapiclient "github.com/leaseweb/leaseweb-go-sdk/dedicatedserver" +) + +func Test_dedicatedserver_DedicatedserverAPIService(t *testing.T) { + + configuration := openapiclient.NewConfiguration() + apiClient := openapiclient.NewAPIClient(configuration) + + t.Run("Test DedicatedserverAPIService AddServerToPrivateNetwork", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var serverId string + var privateNetworkId string + + httpRes, err := apiClient.DedicatedserverAPI.AddServerToPrivateNetwork(context.Background(), serverId, privateNetworkId).Execute() + + require.Nil(t, err) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test DedicatedserverAPIService DeleteServerFromPrivateNetwork", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var serverId string + var privateNetworkId string + + httpRes, err := apiClient.DedicatedserverAPI.DeleteServerFromPrivateNetwork(context.Background(), serverId, privateNetworkId).Execute() + + require.Nil(t, err) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test DedicatedserverAPIService GetNetworkEquipment", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var networkEquipmentId string + + resp, httpRes, err := apiClient.DedicatedserverAPI.GetNetworkEquipment(context.Background(), networkEquipmentId).Execute() + + require.Nil(t, err) + require.NotNil(t, resp) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test DedicatedserverAPIService GetNetworkEquipmentIp", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var networkEquipmentId string + var ip string + + resp, httpRes, err := apiClient.DedicatedserverAPI.GetNetworkEquipmentIp(context.Background(), networkEquipmentId, ip).Execute() + + require.Nil(t, err) + require.NotNil(t, resp) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test DedicatedserverAPIService GetNetworkEquipmentIpList", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var networkEquipmentId string + + resp, httpRes, err := apiClient.DedicatedserverAPI.GetNetworkEquipmentIpList(context.Background(), networkEquipmentId).Execute() + + require.Nil(t, err) + require.NotNil(t, resp) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test DedicatedserverAPIService GetNetworkEquipmentList", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + resp, httpRes, err := apiClient.DedicatedserverAPI.GetNetworkEquipmentList(context.Background()).Execute() + + require.Nil(t, err) + require.NotNil(t, resp) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test DedicatedserverAPIService GetNetworkEquipmentNullRouteHistory", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var networkEquipmentId string + + resp, httpRes, err := apiClient.DedicatedserverAPI.GetNetworkEquipmentNullRouteHistory(context.Background(), networkEquipmentId).Execute() + + require.Nil(t, err) + require.NotNil(t, resp) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test DedicatedserverAPIService GetServer", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var serverId string + + resp, httpRes, err := apiClient.DedicatedserverAPI.GetServer(context.Background(), serverId).Execute() + + require.Nil(t, err) + require.NotNil(t, resp) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test DedicatedserverAPIService GetServerIp", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var serverId string + var ip string + + resp, httpRes, err := apiClient.DedicatedserverAPI.GetServerIp(context.Background(), serverId, ip).Execute() + + require.Nil(t, err) + require.NotNil(t, resp) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test DedicatedserverAPIService GetServerIpList", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var serverId string + + resp, httpRes, err := apiClient.DedicatedserverAPI.GetServerIpList(context.Background(), serverId).Execute() + + require.Nil(t, err) + require.NotNil(t, resp) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test DedicatedserverAPIService GetServerList", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + resp, httpRes, err := apiClient.DedicatedserverAPI.GetServerList(context.Background()).Execute() + + require.Nil(t, err) + require.NotNil(t, resp) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test DedicatedserverAPIService GetServerNullRouteHistory", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var serverId string + + resp, httpRes, err := apiClient.DedicatedserverAPI.GetServerNullRouteHistory(context.Background(), serverId).Execute() + + require.Nil(t, err) + require.NotNil(t, resp) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test DedicatedserverAPIService NetworkEquipmentsIpsNull", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var networkEquipmentId string + var ip string + + resp, httpRes, err := apiClient.DedicatedserverAPI.NetworkEquipmentsIpsNull(context.Background(), networkEquipmentId, ip).Execute() + + require.Nil(t, err) + require.NotNil(t, resp) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test DedicatedserverAPIService NullIpRoute", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var serverId string + var ip string + + resp, httpRes, err := apiClient.DedicatedserverAPI.NullIpRoute(context.Background(), serverId, ip).Execute() + + require.Nil(t, err) + require.NotNil(t, resp) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test DedicatedserverAPIService PutServerIp", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var serverId string + var ip string + + resp, httpRes, err := apiClient.DedicatedserverAPI.PutServerIp(context.Background(), serverId, ip).Execute() + + require.Nil(t, err) + require.NotNil(t, resp) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test DedicatedserverAPIService RemoveNullIpRoute", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var serverId string + var ip string + + resp, httpRes, err := apiClient.DedicatedserverAPI.RemoveNullIpRoute(context.Background(), serverId, ip).Execute() + + require.Nil(t, err) + require.NotNil(t, resp) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test DedicatedserverAPIService UnNullNetworkEquipmentIpRoute", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var networkEquipmentId string + var ip string + + resp, httpRes, err := apiClient.DedicatedserverAPI.UnNullNetworkEquipmentIpRoute(context.Background(), networkEquipmentId, ip).Execute() + + require.Nil(t, err) + require.NotNil(t, resp) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test DedicatedserverAPIService UpdateNetworkEquipmentIp", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var networkEquipmentId string + var ip string + + resp, httpRes, err := apiClient.DedicatedserverAPI.UpdateNetworkEquipmentIp(context.Background(), networkEquipmentId, ip).Execute() + + require.Nil(t, err) + require.NotNil(t, resp) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test DedicatedserverAPIService UpdateNetworkEquipmentReference", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var networkEquipmentId string + + httpRes, err := apiClient.DedicatedserverAPI.UpdateNetworkEquipmentReference(context.Background(), networkEquipmentId).Execute() + + require.Nil(t, err) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test DedicatedserverAPIService UpdateServerReference", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var serverId string + + httpRes, err := apiClient.DedicatedserverAPI.UpdateServerReference(context.Background(), serverId).Execute() + + require.Nil(t, err) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + +} diff --git a/dedicatedserver/utils.go b/dedicatedserver/utils.go new file mode 100644 index 0000000..1adb9da --- /dev/null +++ b/dedicatedserver/utils.go @@ -0,0 +1,348 @@ +/* +Leaseweb API for dedicated servers + +This documents the rest api dedicatedserver provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package dedicatedserver + +import ( + "encoding/json" + "reflect" + "time" +) + +// PtrBool is a helper routine that returns a pointer to given boolean value. +func PtrBool(v bool) *bool { return &v } + +// PtrInt is a helper routine that returns a pointer to given integer value. +func PtrInt(v int) *int { return &v } + +// PtrInt32 is a helper routine that returns a pointer to given integer value. +func PtrInt32(v int32) *int32 { return &v } + +// PtrInt64 is a helper routine that returns a pointer to given integer value. +func PtrInt64(v int64) *int64 { return &v } + +// PtrFloat32 is a helper routine that returns a pointer to given float value. +func PtrFloat32(v float32) *float32 { return &v } + +// PtrFloat64 is a helper routine that returns a pointer to given float value. +func PtrFloat64(v float64) *float64 { return &v } + +// PtrString is a helper routine that returns a pointer to given string value. +func PtrString(v string) *string { return &v } + +// PtrTime is helper routine that returns a pointer to given Time value. +func PtrTime(v time.Time) *time.Time { return &v } + +type NullableBool struct { + value *bool + isSet bool +} + +func (v NullableBool) Get() *bool { + return v.value +} + +func (v *NullableBool) Set(val *bool) { + v.value = val + v.isSet = true +} + +func (v NullableBool) IsSet() bool { + return v.isSet +} + +func (v *NullableBool) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableBool(val *bool) *NullableBool { + return &NullableBool{value: val, isSet: true} +} + +func (v NullableBool) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableBool) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + +type NullableInt struct { + value *int + isSet bool +} + +func (v NullableInt) Get() *int { + return v.value +} + +func (v *NullableInt) Set(val *int) { + v.value = val + v.isSet = true +} + +func (v NullableInt) IsSet() bool { + return v.isSet +} + +func (v *NullableInt) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableInt(val *int) *NullableInt { + return &NullableInt{value: val, isSet: true} +} + +func (v NullableInt) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableInt) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + +type NullableInt32 struct { + value *int32 + isSet bool +} + +func (v NullableInt32) Get() *int32 { + return v.value +} + +func (v *NullableInt32) Set(val *int32) { + v.value = val + v.isSet = true +} + +func (v NullableInt32) IsSet() bool { + return v.isSet +} + +func (v *NullableInt32) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableInt32(val *int32) *NullableInt32 { + return &NullableInt32{value: val, isSet: true} +} + +func (v NullableInt32) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableInt32) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + +type NullableInt64 struct { + value *int64 + isSet bool +} + +func (v NullableInt64) Get() *int64 { + return v.value +} + +func (v *NullableInt64) Set(val *int64) { + v.value = val + v.isSet = true +} + +func (v NullableInt64) IsSet() bool { + return v.isSet +} + +func (v *NullableInt64) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableInt64(val *int64) *NullableInt64 { + return &NullableInt64{value: val, isSet: true} +} + +func (v NullableInt64) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableInt64) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + +type NullableFloat32 struct { + value *float32 + isSet bool +} + +func (v NullableFloat32) Get() *float32 { + return v.value +} + +func (v *NullableFloat32) Set(val *float32) { + v.value = val + v.isSet = true +} + +func (v NullableFloat32) IsSet() bool { + return v.isSet +} + +func (v *NullableFloat32) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableFloat32(val *float32) *NullableFloat32 { + return &NullableFloat32{value: val, isSet: true} +} + +func (v NullableFloat32) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableFloat32) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + +type NullableFloat64 struct { + value *float64 + isSet bool +} + +func (v NullableFloat64) Get() *float64 { + return v.value +} + +func (v *NullableFloat64) Set(val *float64) { + v.value = val + v.isSet = true +} + +func (v NullableFloat64) IsSet() bool { + return v.isSet +} + +func (v *NullableFloat64) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableFloat64(val *float64) *NullableFloat64 { + return &NullableFloat64{value: val, isSet: true} +} + +func (v NullableFloat64) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableFloat64) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + +type NullableString struct { + value *string + isSet bool +} + +func (v NullableString) Get() *string { + return v.value +} + +func (v *NullableString) Set(val *string) { + v.value = val + v.isSet = true +} + +func (v NullableString) IsSet() bool { + return v.isSet +} + +func (v *NullableString) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableString(val *string) *NullableString { + return &NullableString{value: val, isSet: true} +} + +func (v NullableString) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableString) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + +type NullableTime struct { + value *time.Time + isSet bool +} + +func (v NullableTime) Get() *time.Time { + return v.value +} + +func (v *NullableTime) Set(val *time.Time) { + v.value = val + v.isSet = true +} + +func (v NullableTime) IsSet() bool { + return v.isSet +} + +func (v *NullableTime) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableTime(val *time.Time) *NullableTime { + return &NullableTime{value: val, isSet: true} +} + +func (v NullableTime) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableTime) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + +// IsNil checks if an input is nil +func IsNil(i interface{}) bool { + if i == nil { + return true + } + switch reflect.TypeOf(i).Kind() { + case reflect.Chan, reflect.Func, reflect.Map, reflect.Ptr, reflect.UnsafePointer, reflect.Interface, reflect.Slice: + return reflect.ValueOf(i).IsNil() + case reflect.Array: + return reflect.ValueOf(i).IsZero() + } + return false +} + +type MappedNullable interface { + ToMap() (map[string]interface{}, error) +} diff --git a/floating_ip.go b/floating_ip.go deleted file mode 100644 index 7f9a9ad..0000000 --- a/floating_ip.go +++ /dev/null @@ -1,128 +0,0 @@ -package leaseweb - -import ( - "context" - "net/http" - - "github.com/LeaseWeb/leaseweb-go-sdk/options" -) - -const FLOATING_IP_API_VERSION = "v2" - -type FloatingIpApi struct{} - -type FloatingIpRange struct { - Id string `json:"id"` - Range string `json:"range"` - CustomerId string `json:"customerId"` - SalesOrgId string `json:"salesOrgId"` - Location string `json:"location"` - Type string `json:"type"` -} - -type FloatingIpRanges struct { - Ranges []FloatingIpRange `json:"ranges"` - Metadata Metadata `json:"_metadata"` -} - -type FloatingIpDefinition struct { - Id string `json:"id"` - RangeId string `json:"rangeId"` - Location string `json:"location"` - Type string `json:"type"` - CustomerId string `json:"customerId"` - SalesOrgId string `json:"salesOrgId"` - FloatingIp string `json:"floatingIp"` - AnchorIp string `json:"anchorIp"` - Status string `json:"status"` - CreatedAt string `json:"createdAt"` - UpdatedAt string `json:"updatedAt"` -} - -type FloatingIpDefinitions struct { - Definitions []FloatingIpDefinition `json:"floatingIpDefinitions"` - Metadata Metadata `json:"_metadata"` -} - -type FloatingIpListRangesOptions struct { - PaginationOptions - Type *string `param:"type"` - Location *string `param:"location"` -} - -type FloatingIpListRangeDefinitionsOptions struct { - PaginationOptions - Location *string `param:"location"` - Type []string `param:"type"` -} - -func (fia FloatingIpApi) getPath(endpoint string) string { - return "/floatingIps/" + FLOATING_IP_API_VERSION + endpoint -} - -func (fia FloatingIpApi) ListRanges(ctx context.Context, opts FloatingIpListRangesOptions) (*FloatingIpRanges, error) { - path := fia.getPath("/ranges") - query := options.Encode(opts) - result := &FloatingIpRanges{} - if err := doRequest(ctx, http.MethodGet, path, query, result); err != nil { - return nil, err - } - return result, nil -} - -func (fia FloatingIpApi) GetRange(ctx context.Context, rangeId string) (*FloatingIpRange, error) { - path := fia.getPath("/ranges/" + rangeId) - result := &FloatingIpRange{} - if err := doRequest(ctx, http.MethodGet, path, "", result); err != nil { - return nil, err - } - return result, nil -} - -func (fia FloatingIpApi) ListRangeDefinitions(ctx context.Context, rangeId string, opts FloatingIpListRangeDefinitionsOptions) (*FloatingIpDefinitions, error) { - path := fia.getPath("/ranges/" + rangeId + "/floatingIpDefinitions") - query := options.Encode(opts) - result := &FloatingIpDefinitions{} - if err := doRequest(ctx, http.MethodGet, path, query, result); err != nil { - return nil, err - } - return result, nil -} - -func (fia FloatingIpApi) CreateRangeDefinition(ctx context.Context, rangeId string, floatingIp string, anchorIp string) (*FloatingIpDefinition, error) { - payload := map[string]string{"floatingIp": floatingIp, "anchorIp": anchorIp} - path := fia.getPath("/ranges/" + rangeId + "/floatingIpDefinitions") - result := &FloatingIpDefinition{} - if err := doRequest(ctx, http.MethodPost, path, "", result, payload); err != nil { - return nil, err - } - return result, nil -} - -func (fia FloatingIpApi) GetRangeDefinition(ctx context.Context, rangeId string, floatingIpDefinitionId string) (*FloatingIpDefinition, error) { - path := fia.getPath("/ranges/" + rangeId + "/floatingIpDefinitions/" + floatingIpDefinitionId) - result := &FloatingIpDefinition{} - if err := doRequest(ctx, http.MethodGet, path, "", result); err != nil { - return nil, err - } - return result, nil -} - -func (fia FloatingIpApi) UpdateRangeDefinition(ctx context.Context, rangeId string, floatingIpDefinitionId string, anchorIp string) (*FloatingIpDefinition, error) { - payload := map[string]string{"anchorIp": anchorIp} - path := fia.getPath("/ranges/" + rangeId + "/floatingIpDefinitions/" + floatingIpDefinitionId) - result := &FloatingIpDefinition{} - if err := doRequest(ctx, http.MethodPut, path, "", result, payload); err != nil { - return nil, err - } - return result, nil -} - -func (fia FloatingIpApi) RemoveRangeDefinition(ctx context.Context, rangeId string, floatingIpDefinitionId string) (*FloatingIpDefinition, error) { - path := fia.getPath("/ranges/" + rangeId + "/floatingIpDefinitions/" + floatingIpDefinitionId) - result := &FloatingIpDefinition{} - if err := doRequest(ctx, http.MethodDelete, path, "", result); err != nil { - return nil, err - } - return result, nil -} diff --git a/floating_ip_test.go b/floating_ip_test.go deleted file mode 100644 index 95ee82d..0000000 --- a/floating_ip_test.go +++ /dev/null @@ -1,911 +0,0 @@ -package leaseweb - -import ( - "context" - "fmt" - "net/http" - "testing" - - "github.com/stretchr/testify/assert" -) - -func TestFloatingIpListRanges(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{"_metadata":{"limit": 10, "offset": 0, "totalCount": 2}, "ranges": [ - { - "id": "85.17.0.0_17", - "range": "85.17.0.0/17", - "customerId": "10001234", - "salesOrgId": "2000", - "location": "AMS-01", - "type": "SITE" - }, - { - "id": "86.17.0.1_17", - "range": "86.17.0.1/17", - "customerId": "10001234", - "salesOrgId": "2000", - "location": "AMS", - "type": "METRO" - } - ]}`) - }) - defer teardown() - - floatingIpApi := FloatingIpApi{} - ctx := context.Background() - response, err := floatingIpApi.ListRanges(ctx, FloatingIpListRangesOptions{}) - - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 2) - assert.Equal(response.Metadata.Offset, 0) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.Ranges), 2) - - range1 := response.Ranges[0] - assert.Equal(range1.Id, "85.17.0.0_17") - assert.Equal(range1.Range, "85.17.0.0/17") - assert.Equal(range1.CustomerId, "10001234") - assert.Equal(range1.SalesOrgId, "2000") - assert.Equal(range1.Location, "AMS-01") - assert.Equal(range1.Type, "SITE") - - range2 := response.Ranges[1] - assert.Equal(range2.Id, "86.17.0.1_17") - assert.Equal(range2.Range, "86.17.0.1/17") - assert.Equal(range2.CustomerId, "10001234") - assert.Equal(range2.SalesOrgId, "2000") - assert.Equal(range2.Location, "AMS") - assert.Equal(range2.Type, "METRO") -} - -func TestFloatingIpListRangesPaginateAndFilter(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{"_metadata":{"limit": 10, "offset": 1, "totalCount": 11}, "ranges": [ - { - "id": "85.17.0.0_17", - "range": "85.17.0.0/17", - "customerId": "10001234", - "salesOrgId": "2000", - "location": "AMS-01", - "type": "SITE" - } - ]}`) - }) - defer teardown() - - floatingIpApi := FloatingIpApi{} - ctx := context.Background() - opts := FloatingIpListRangesOptions{ - PaginationOptions: PaginationOptions{ - Limit: Int(1), - Offset: Int(10), - }, - Type: String("SITE, METRO"), - Location: String("AMS-01"), - } - response, err := floatingIpApi.ListRanges(ctx, opts) - - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 11) - assert.Equal(response.Metadata.Offset, 1) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.Ranges), 1) - - range1 := response.Ranges[0] - assert.Equal(range1.Id, "85.17.0.0_17") - assert.Equal(range1.Range, "85.17.0.0/17") - assert.Equal(range1.CustomerId, "10001234") - assert.Equal(range1.SalesOrgId, "2000") - assert.Equal(range1.Location, "AMS-01") - assert.Equal(range1.Type, "SITE") -} - -func TestFloatingIpListRangesServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId": "289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "ACCESS_DENIED", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return FloatingIpApi{}.ListRanges(ctx, FloatingIpListRangesOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "ACCESS_DENIED", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId": "289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The server encountered an unexpected condition that prevented it from fulfilling the request."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return FloatingIpApi{}.ListRanges(ctx, FloatingIpListRangesOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The server encountered an unexpected condition that prevented it from fulfilling the request.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId": "289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return FloatingIpApi{}.ListRanges(ctx, FloatingIpListRangesOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestFloatingIpGetRange(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "id": "85.17.0.0_17", - "range": "88.17.0.0/17", - "customerId": "10001234", - "salesOrgId": "2000", - "location": "AMS-01", - "type": "SITE" - }`) - }) - defer teardown() - - floatingIpApi := FloatingIpApi{} - ctx := context.Background() - response, err := floatingIpApi.GetRange(ctx, "123456789") - - assert := assert.New(t) - assert.Nil(err) - - assert.Equal(response.Id, "85.17.0.0_17") - assert.Equal(response.Range, "88.17.0.0/17") - assert.Equal(response.CustomerId, "10001234") - assert.Equal(response.SalesOrgId, "2000") - assert.Equal(response.Location, "AMS-01") - assert.Equal(response.Type, "SITE") -} - -func TestFloatingIpGetRangeServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"errorCode": "ACCESS_DENIED", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return FloatingIpApi{}.GetRange(ctx, "123456789") - }, - ExpectedError: ApiError{ - Code: "ACCESS_DENIED", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusNotFound) - fmt.Fprintf(w, `{"correlationId": "39e010ed-0e93-42c3-c28f-3ffc373553d5", "errorCode": "404", "errorMessage": "Range with id 88.17.0.0_17 does not exist"}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return FloatingIpApi{}.GetRange(ctx, "123456789") - }, - ExpectedError: ApiError{ - CorrelationId: "39e010ed-0e93-42c3-c28f-3ffc373553d5", - Code: "404", - Message: "Range with id 88.17.0.0_17 does not exist", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId": "289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The server encountered an unexpected condition that prevented it from fulfilling the request."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return FloatingIpApi{}.GetRange(ctx, "123456789") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The server encountered an unexpected condition that prevented it from fulfilling the request.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId": "289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return FloatingIpApi{}.GetRange(ctx, "123456789") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestFloatingIpListRangeDefinitions(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{"_metadata":{"limit": 10, "offset": 0, "totalCount": 2}, "floatingIpDefinitions": [ - { - "id": "88.17.34.108_32", - "rangeId": "88.17.0.0_17", - "location": "AMS-01", - "type": "SITE", - "customerId": "10001234", - "salesOrgId": "2000", - "floatingIp": "88.17.34.108/32", - "anchorIp": "95.10.126.1", - "status": "ACTIVE", - "createdAt": "2019-03-13T09:10:02+0000", - "updatedAt": "2019-03-13T09:10:02+0000" - }, - { - "id": "88.17.34.109_32", - "rangeId": "88.17.0.0_17", - "location": "AMS-01", - "type": "SITE", - "customerId": "10001234", - "salesOrgId": "2000", - "floatingIp": "88.17.34.109/32", - "anchorIp": "95.10.126.12", - "status": "ACTIVE", - "createdAt": "2019-03-13T09:10:02+0000", - "updatedAt": "2019-03-13T09:10:02+0000" - } - ]}`) - }) - defer teardown() - - floatingIpApi := FloatingIpApi{} - ctx := context.Background() - response, err := floatingIpApi.ListRangeDefinitions(ctx, "123456789", FloatingIpListRangeDefinitionsOptions{}) - - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 2) - assert.Equal(response.Metadata.Offset, 0) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.Definitions), 2) - - floatingIpDefinition1 := response.Definitions[0] - assert.Equal(floatingIpDefinition1.Id, "88.17.34.108_32") - assert.Equal(floatingIpDefinition1.RangeId, "88.17.0.0_17") - assert.Equal(floatingIpDefinition1.CustomerId, "10001234") - assert.Equal(floatingIpDefinition1.SalesOrgId, "2000") - assert.Equal(floatingIpDefinition1.Location, "AMS-01") - assert.Equal(floatingIpDefinition1.Type, "SITE") - assert.Equal(floatingIpDefinition1.FloatingIp, "88.17.34.108/32") - assert.Equal(floatingIpDefinition1.AnchorIp, "95.10.126.1") - assert.Equal(floatingIpDefinition1.Status, "ACTIVE") - assert.Equal(floatingIpDefinition1.CreatedAt, "2019-03-13T09:10:02+0000") - assert.Equal(floatingIpDefinition1.UpdatedAt, "2019-03-13T09:10:02+0000") - - floatingIpDefinition2 := response.Definitions[1] - assert.Equal(floatingIpDefinition2.Id, "88.17.34.109_32") - assert.Equal(floatingIpDefinition2.RangeId, "88.17.0.0_17") - assert.Equal(floatingIpDefinition2.CustomerId, "10001234") - assert.Equal(floatingIpDefinition2.SalesOrgId, "2000") - assert.Equal(floatingIpDefinition2.Location, "AMS-01") - assert.Equal(floatingIpDefinition2.Type, "SITE") - assert.Equal(floatingIpDefinition2.FloatingIp, "88.17.34.109/32") - assert.Equal(floatingIpDefinition2.AnchorIp, "95.10.126.12") - assert.Equal(floatingIpDefinition2.Status, "ACTIVE") - assert.Equal(floatingIpDefinition2.CreatedAt, "2019-03-13T09:10:02+0000") - assert.Equal(floatingIpDefinition2.UpdatedAt, "2019-03-13T09:10:02+0000") -} - -func TestFloatingIpListRangeDefinitionsPaginateAndFilter(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{"_metadata":{"limit": 10, "offset": 1, "totalCount": 11}, "floatingIpDefinitions": [ - { - "id": "88.17.34.108_32", - "rangeId": "88.17.0.0_17", - "location": "AMS-01", - "type": "SITE", - "customerId": "10001234", - "salesOrgId": "2000", - "floatingIp": "88.17.34.108/32", - "anchorIp": "95.10.126.1", - "status": "ACTIVE", - "createdAt": "2019-03-13T09:10:02+0000", - "updatedAt": "2019-03-13T09:10:02+0000" - } - ]}`) - }) - defer teardown() - - floatingIpApi := FloatingIpApi{} - ctx := context.Background() - opts := FloatingIpListRangeDefinitionsOptions{ - PaginationOptions: PaginationOptions{ - Limit: Int(1), - Offset: Int(10), - }, - Location: String("AMS-01"), - Type: []string{"SITE", "METRO"}, - } - response, err := floatingIpApi.ListRangeDefinitions(ctx, "123456789", opts) - - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 11) - assert.Equal(response.Metadata.Offset, 1) - assert.Equal(response.Metadata.Limit, 10) - - floatingIpDefinition1 := response.Definitions[0] - assert.Equal(floatingIpDefinition1.Id, "88.17.34.108_32") - assert.Equal(floatingIpDefinition1.RangeId, "88.17.0.0_17") - assert.Equal(floatingIpDefinition1.CustomerId, "10001234") - assert.Equal(floatingIpDefinition1.SalesOrgId, "2000") - assert.Equal(floatingIpDefinition1.Location, "AMS-01") - assert.Equal(floatingIpDefinition1.Type, "SITE") - assert.Equal(floatingIpDefinition1.FloatingIp, "88.17.34.108/32") - assert.Equal(floatingIpDefinition1.AnchorIp, "95.10.126.1") - assert.Equal(floatingIpDefinition1.Status, "ACTIVE") - assert.Equal(floatingIpDefinition1.CreatedAt, "2019-03-13T09:10:02+0000") - assert.Equal(floatingIpDefinition1.UpdatedAt, "2019-03-13T09:10:02+0000") -} - -func TestFloatingIpListRangeDefinitionsServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"errorCode": "ACCESS_DENIED", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return FloatingIpApi{}.ListRangeDefinitions(ctx, "123456789", FloatingIpListRangeDefinitionsOptions{}) - }, - ExpectedError: ApiError{ - Code: "ACCESS_DENIED", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusNotFound) - fmt.Fprintf(w, `{"correlationId": "39e010ed-0e93-42c3-c28f-3ffc373553d5", "errorCode": "404", "errorMessage": "Range with id 88.17.0.0_17 does not exist"}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return FloatingIpApi{}.ListRangeDefinitions(ctx, "123456789", FloatingIpListRangeDefinitionsOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "39e010ed-0e93-42c3-c28f-3ffc373553d5", - Code: "404", - Message: "Range with id 88.17.0.0_17 does not exist", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId": "289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The server encountered an unexpected condition that prevented it from fulfilling the request."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return FloatingIpApi{}.ListRangeDefinitions(ctx, "123456789", FloatingIpListRangeDefinitionsOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The server encountered an unexpected condition that prevented it from fulfilling the request.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId": "289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return FloatingIpApi{}.ListRangeDefinitions(ctx, "123456789", FloatingIpListRangeDefinitionsOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestFloatingIpCreateRangeDefinition(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "id": "88.17.34.108_32", - "rangeId": "88.17.0.0_17", - "location": "AMS-01", - "type": "SITE", - "customerId": "10001234", - "salesOrgId": "2000", - "floatingIp": "88.17.34.108/32", - "anchorIp": "95.10.126.1", - "status": "ACTIVE", - "createdAt": "2019-03-13T09:10:02+0000", - "updatedAt": "2019-03-13T09:10:02+0000" - }`) - }) - defer teardown() - - floatingIpApi := FloatingIpApi{} - ctx := context.Background() - response, err := floatingIpApi.CreateRangeDefinition(ctx, "10.0.0.0_29", "88.17.0.5/32", "95.10.126.1") - - assert := assert.New(t) - assert.Nil(err) - - assert.Equal(response.Id, "88.17.34.108_32") - assert.Equal(response.RangeId, "88.17.0.0_17") - assert.Equal(response.CustomerId, "10001234") - assert.Equal(response.SalesOrgId, "2000") - assert.Equal(response.Location, "AMS-01") - assert.Equal(response.Type, "SITE") - assert.Equal(response.FloatingIp, "88.17.34.108/32") - assert.Equal(response.AnchorIp, "95.10.126.1") - assert.Equal(response.Status, "ACTIVE") - assert.Equal(response.CreatedAt, "2019-03-13T09:10:02+0000") - assert.Equal(response.UpdatedAt, "2019-03-13T09:10:02+0000") -} - -func TestFloatingIpCreateRangeDefinitionServerError(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 400", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusBadRequest) - fmt.Fprintf(w, `{"errorCode": "400", "errorMessage": "Validation Failed"}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return FloatingIpApi{}.CreateRangeDefinition(ctx, "10.0.0.0_29", "88.17.0.5/32", "95.10.126.1") - }, - ExpectedError: ApiError{ - Code: "400", - Message: "Validation Failed", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"errorCode": "ACCESS_DENIED", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return FloatingIpApi{}.CreateRangeDefinition(ctx, "10.0.0.0_29", "88.17.0.5/32", "95.10.126.1") - }, - ExpectedError: ApiError{ - Code: "ACCESS_DENIED", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId": "289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The server encountered an unexpected condition that prevented it from fulfilling the request."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return FloatingIpApi{}.CreateRangeDefinition(ctx, "10.0.0.0_29", "88.17.0.5/32", "95.10.126.1") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The server encountered an unexpected condition that prevented it from fulfilling the request.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId": "289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return FloatingIpApi{}.CreateRangeDefinition(ctx, "10.0.0.0_29", "88.17.0.5/32", "95.10.126.1") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestFloatingIpGetRangeDefinition(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "id": "88.17.34.108_32", - "rangeId": "88.17.0.0_17", - "location": "AMS-01", - "type": "SITE", - "customerId": "10001234", - "salesOrgId": "2000", - "floatingIp": "88.17.34.108/32", - "anchorIp": "95.10.126.1", - "status": "ACTIVE", - "createdAt": "2019-03-13T09:10:02+0000", - "updatedAt": "2019-03-13T09:10:02+0000" - }`) - }) - defer teardown() - - floatingIpApi := FloatingIpApi{} - ctx := context.Background() - response, err := floatingIpApi.GetRangeDefinition(ctx, "88.17.0.0_17", "88.17.34.108_32") - - assert := assert.New(t) - assert.Nil(err) - - assert.Equal(response.Id, "88.17.34.108_32") - assert.Equal(response.RangeId, "88.17.0.0_17") - assert.Equal(response.CustomerId, "10001234") - assert.Equal(response.SalesOrgId, "2000") - assert.Equal(response.Location, "AMS-01") - assert.Equal(response.Type, "SITE") - assert.Equal(response.FloatingIp, "88.17.34.108/32") - assert.Equal(response.AnchorIp, "95.10.126.1") - assert.Equal(response.Status, "ACTIVE") - assert.Equal(response.CreatedAt, "2019-03-13T09:10:02+0000") - assert.Equal(response.UpdatedAt, "2019-03-13T09:10:02+0000") -} - -func TestFloatingIpGetRangeDefinitionServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"errorCode": "ACCESS_DENIED", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return FloatingIpApi{}.GetRangeDefinition(ctx, "88.17.0.0_17", "88.17.34.108_32") - }, - ExpectedError: ApiError{ - Code: "ACCESS_DENIED", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId": "289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The server encountered an unexpected condition that prevented it from fulfilling the request."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return FloatingIpApi{}.GetRangeDefinition(ctx, "88.17.0.0_17", "88.17.34.108_32") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The server encountered an unexpected condition that prevented it from fulfilling the request.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId": "289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return FloatingIpApi{}.GetRangeDefinition(ctx, "88.17.0.0_17", "88.17.34.108_32") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestFloatingIpUpdateRangeDefinition(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "id": "88.17.34.108_32", - "rangeId": "88.17.0.0_17", - "location": "AMS-01", - "type": "SITE", - "customerId": "10001234", - "salesOrgId": "2000", - "floatingIp": "88.17.34.108/32", - "anchorIp": "95.10.126.1", - "status": "ACTIVE", - "createdAt": "2019-03-13T09:10:02+0000", - "updatedAt": "2019-03-13T09:10:02+0000" - }`) - }) - defer teardown() - - floatingIpApi := FloatingIpApi{} - ctx := context.Background() - response, err := floatingIpApi.UpdateRangeDefinition(ctx, "88.17.0.0_17", "88.17.34.108_32", "95.10.126.1") - - assert := assert.New(t) - assert.Nil(err) - - assert.Equal(response.Id, "88.17.34.108_32") - assert.Equal(response.RangeId, "88.17.0.0_17") - assert.Equal(response.CustomerId, "10001234") - assert.Equal(response.SalesOrgId, "2000") - assert.Equal(response.Location, "AMS-01") - assert.Equal(response.Type, "SITE") - assert.Equal(response.FloatingIp, "88.17.34.108/32") - assert.Equal(response.AnchorIp, "95.10.126.1") - assert.Equal(response.Status, "ACTIVE") - assert.Equal(response.CreatedAt, "2019-03-13T09:10:02+0000") - assert.Equal(response.UpdatedAt, "2019-03-13T09:10:02+0000") -} - -func TestFloatingIpUpdateRangeDefinitionServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 400", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusBadRequest) - fmt.Fprintf(w, `{"correlationId": "945bef2e-1caf-4027-bd0a-8976848f3dee", "errorCode": "400", "errorMessage": "Validation Failed"}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return FloatingIpApi{}.UpdateRangeDefinition(ctx, "wrong 1", "88.17.34.108_32", "95.10.126.1") - }, - ExpectedError: ApiError{ - CorrelationId: "945bef2e-1caf-4027-bd0a-8976848f3dee", - Code: "400", - Message: "Validation Failed", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"errorCode": "ACCESS_DENIED", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return FloatingIpApi{}.UpdateRangeDefinition(ctx, "wrong 1", "88.17.34.108_32", "95.10.126.1") - }, - ExpectedError: ApiError{ - Code: "ACCESS_DENIED", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId": "289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The server encountered an unexpected condition that prevented it from fulfilling the request."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return FloatingIpApi{}.UpdateRangeDefinition(ctx, "wrong 1", "88.17.34.108_32", "95.10.126.1") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The server encountered an unexpected condition that prevented it from fulfilling the request.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId": "289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return FloatingIpApi{}.UpdateRangeDefinition(ctx, "wrong 1", "88.17.34.108_32", "95.10.126.1") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestFloatingIpRemoveRangeDefinition(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "id": "88.17.34.108_32", - "rangeId": "88.17.0.0_17", - "location": "AMS-01", - "type": "SITE", - "customerId": "10001234", - "salesOrgId": "2000", - "floatingIp": "88.17.34.108/32", - "anchorIp": "95.10.126.1", - "status": "ACTIVE", - "createdAt": "2019-03-13T09:10:02+0000", - "updatedAt": "2019-03-13T09:10:02+0000" - }`) - }) - defer teardown() - - floatingIpApi := FloatingIpApi{} - ctx := context.Background() - response, err := floatingIpApi.RemoveRangeDefinition(ctx, "88.17.0.0_17", "88.17.34.108_32") - - assert := assert.New(t) - assert.Nil(err) - - assert.Equal(response.Id, "88.17.34.108_32") - assert.Equal(response.RangeId, "88.17.0.0_17") - assert.Equal(response.CustomerId, "10001234") - assert.Equal(response.SalesOrgId, "2000") - assert.Equal(response.Location, "AMS-01") - assert.Equal(response.Type, "SITE") - assert.Equal(response.FloatingIp, "88.17.34.108/32") - assert.Equal(response.AnchorIp, "95.10.126.1") - assert.Equal(response.Status, "ACTIVE") - assert.Equal(response.CreatedAt, "2019-03-13T09:10:02+0000") - assert.Equal(response.UpdatedAt, "2019-03-13T09:10:02+0000") -} - -func TestFloatingIpRemoveRangeDefinitionServerErrors(t *testing.T) { - - serverErrorTests := []serverErrorTest{ - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"errorCode": "ACCESS_DENIED", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return FloatingIpApi{}.RemoveRangeDefinition(ctx, "88.17.0.0_17", "88.17.34.108_32") - }, - ExpectedError: ApiError{ - Code: "ACCESS_DENIED", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId": "289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The server encountered an unexpected condition that prevented it from fulfilling the request."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return FloatingIpApi{}.RemoveRangeDefinition(ctx, "88.17.0.0_17", "88.17.34.108_32") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The server encountered an unexpected condition that prevented it from fulfilling the request.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId": "289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return FloatingIpApi{}.RemoveRangeDefinition(ctx, "88.17.0.0_17", "88.17.34.108_32") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} diff --git a/go.mod b/go.mod index ce92c2d..f396e7f 100644 --- a/go.mod +++ b/go.mod @@ -1,11 +1,3 @@ module github.com/LeaseWeb/leaseweb-go-sdk -go 1.18 - -require github.com/stretchr/testify v1.8.0 - -require ( - github.com/davecgh/go-spew v1.1.1 // indirect - github.com/pmezard/go-difflib v1.0.0 // indirect - gopkg.in/yaml.v3 v3.0.1 // indirect -) +go 1.22.2 diff --git a/go.sum b/go.sum index 5164829..e69de29 100644 --- a/go.sum +++ b/go.sum @@ -1,15 +0,0 @@ -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= -github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk= -github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= -gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/hosting.go b/hosting.go deleted file mode 100644 index b7fe380..0000000 --- a/hosting.go +++ /dev/null @@ -1,474 +0,0 @@ -package leaseweb - -import ( - "context" - "encoding/json" - "net/http" - - "github.com/LeaseWeb/leaseweb-go-sdk/options" -) - -const HOSTING_API_VERSION = "v2" - -type HostingApi struct{} - -type HostingDomains struct { - Domains []HostingDomain `json:"domains"` - Link HostingLink `json:"_links"` - Metadata Metadata `json:"_metadata"` -} - -type HostingDomain struct { - DomainName string `json:"domainName"` - Suspended bool `json:"suspended"` - DnsOnly bool `json:"dnsOnly"` - Status string `json:"status"` - ContractStartDate string `json:"contractStartDate"` - ContractEndDate string `json:"contractEndDate"` - Link HostingLink `json:"_links"` -} - -type HostingLink struct { - Self HostingHref `json:"self"` - Dns HostingHref `json:"dns"` - Email HostingHref `json:"email"` - Collection HostingHref `json:"collection"` - CatchAll HostingHref `json:"catchAll"` - Contacts HostingHref `json:"contacts"` - Nameservers HostingHref `json:"nameservers"` - EmailAliases HostingHref `json:"emailAliases"` - Forwards HostingHref `json:"forwards"` - Mailboxes HostingHref `json:"mailboxes"` - ResourceRecordSets HostingHref `json:"resourceRecordSets"` - ValidateZone HostingHref `json:"validateZone"` - ValidateSet HostingHref `json:"validateSet"` - Parent HostingHref `json:"parent"` - AutoResponder HostingHref `json:"autoResponder"` -} - -type HostingHref struct { - Href string `json:"href"` -} - -type HostingDomainAvailability struct { - DomainName string `json:"domainName"` - Available bool `json:"available"` - Link HostingLink `json:"_links"` -} - -type HostingNameservers struct { - Nameservers []HostingNameserver `json:"nameservers"` - Status string `json:"status"` - Link HostingLink `json:"_links"` - Metadata Metadata `json:"_metadata"` -} - -type HostingNameserver struct { - Name string `json:"name"` -} - -type HostingDnsSecurity struct { - Status string `json:"status"` - Nsec HostingDnsSecurityNsec `json:"nsec3"` - KeyRollover HostingDnsSecurityKeyRollover `json:"keyRollover"` - Link HostingLink `json:"_links"` -} - -type HostingDnsSecurityNsec struct { - Active bool `json:"active"` -} - -type HostingDnsSecurityKeyRollover struct { - Status string `json:"status"` - Type string `json:"type"` - Message string `json:"message"` -} - -type HostingInfoMessageResponse struct { - InfoMessage string `json:"infoMessage"` -} - -type HostingResourceRecordSets struct { - InfoMessage string `json:"infoMessage"` - ResourceRecordSets []HostingResourceRecordSet `json:"resourceRecordSets"` - Link HostingLink `json:"_links"` - Metadata Metadata `json:"_metadata"` -} - -type HostingResourceRecordSet struct { - Name string `json:"name"` - Type string `json:"type"` - Ttl json.Number `json:"ttl"` - Content []string `json:"content"` - Editable bool `json:"editable"` - Link HostingLink `json:"_links"` -} - -type HostingEmailAliases struct { - EmailAliases []HostingEmail `json:"emailAliases"` - Link HostingLink `json:"_links"` - Metadata Metadata `json:"_metadata"` -} - -type HostingEmailForwards struct { - Forwards []HostingEmail `json:"forwards"` - Link HostingLink `json:"_links"` - Metadata Metadata `json:"_metadata"` -} - -type HostingEmailMailboxes struct { - Mailboxes []HostingEmail `json:"mailboxes"` - Link HostingLink `json:"_links"` - Metadata Metadata `json:"_metadata"` -} - -type HostingEmail struct { - Destination string `json:"destination"` - Source string `json:"source"` - Active bool `json:"active"` - SpamChecksEnabled bool `json:"spamChecksEnabled"` - VirusChecksEnabled bool `json:"virusChecksEnabled"` - CurrentSize json.Number `json:"currentSize"` - MaximumSize json.Number `json:"maximumSize"` - Suspended bool `json:"suspended"` - LocalDelivery bool `json:"localDelivery"` - EmailAddress string `json:"emailAddress"` - Body string `json:"body"` - Subject string `json:"subject"` - Embedded struct { - AutoResponder struct { - Link HostingLink `json:"_links"` - } `json:"autoResponder"` - } `json:"_embedded"` - Link HostingLink `json:"_links"` -} - -type HostingListDomainsOptions struct { - PaginationOptions - Type *string `param:"type"` -} - -func (ha HostingApi) getPath(endpoint string) string { - return "/hosting/" + FLOATING_IP_API_VERSION + endpoint -} - -func (ha HostingApi) ListDomains(ctx context.Context, opts HostingListDomainsOptions) (*HostingDomains, error) { - path := ha.getPath("/domains") - query := options.Encode(opts) - result := &HostingDomains{} - if err := doRequest(ctx, http.MethodGet, path, query, result); err != nil { - return nil, err - } - return result, nil -} - -func (ha HostingApi) GetDomain(ctx context.Context, domainName string) (*HostingDomain, error) { - path := ha.getPath("/domains/" + domainName) - result := &HostingDomain{} - if err := doRequest(ctx, http.MethodGet, path, "", result); err != nil { - return nil, err - } - return result, nil -} - -func (ha HostingApi) GetAvailability(ctx context.Context, domainName string) (*HostingDomainAvailability, error) { - path := ha.getPath("/domains/" + domainName + "/available") - result := &HostingDomainAvailability{} - if err := doRequest(ctx, http.MethodGet, path, "", result); err != nil { - return nil, err - } - return result, nil -} - -func (ha HostingApi) ListNameservers(ctx context.Context, domainName string, opts PaginationOptions) (*HostingNameservers, error) { - path := ha.getPath("/domains/" + domainName + "/nameservers") - result := &HostingNameservers{} - query := options.Encode(opts) - if err := doRequest(ctx, http.MethodGet, path, query, result); err != nil { - return nil, err - } - return result, nil -} - -func (ha HostingApi) UpdateNameservers(ctx context.Context, domainName string, nameservers []string) (*HostingNameservers, error) { - payload := make(map[string][]string) - payload["nameservers"] = nameservers - path := ha.getPath("/domains/" + domainName + "/nameservers") - result := &HostingNameservers{} - if err := doRequest(ctx, http.MethodPut, path, "", result, payload); err != nil { - return nil, err - } - return result, nil -} - -func (ha HostingApi) GetDnsSecurity(ctx context.Context, domainName string) (*HostingDnsSecurity, error) { - path := ha.getPath("/domains/" + domainName + "/dnssec") - result := &HostingDnsSecurity{} - if err := doRequest(ctx, http.MethodGet, path, "", result); err != nil { - return nil, err - } - return result, nil -} - -func (ha HostingApi) UpdateDnsSecurity(ctx context.Context, domainName string, payload map[string]interface{}) (*HostingInfoMessageResponse, error) { - path := ha.getPath("/domains/" + domainName + "/dnssec") - result := &HostingInfoMessageResponse{} - if err := doRequest(ctx, http.MethodPut, path, "", result, payload); err != nil { - return nil, err - } - return result, nil -} - -func (ha HostingApi) ListResourceRecordSets(ctx context.Context, domainName string, opts PaginationOptions) (*HostingResourceRecordSets, error) { - path := ha.getPath("/domains/" + domainName + "/resourceRecordSets") - result := &HostingResourceRecordSets{} - query := options.Encode(opts) - if err := doRequest(ctx, http.MethodGet, path, query, result); err != nil { - return nil, err - } - return result, nil -} - -func (ha HostingApi) CreateResourceRecordSet(ctx context.Context, domainName string, payload map[string]interface{}) (*HostingResourceRecordSet, error) { - path := ha.getPath("/domains/" + domainName + "/resourceRecordSets") - result := &HostingResourceRecordSet{} - if err := doRequest(ctx, http.MethodPost, path, "", result, payload); err != nil { - return nil, err - } - return result, nil -} - -func (ha HostingApi) DeleteResourceRecordSets(ctx context.Context, domainName string) error { - path := ha.getPath("/domains/" + domainName + "/resourceRecordSets") - return doRequest(ctx, http.MethodDelete, path, "") -} - -func (ha HostingApi) GetResourceRecordSet(ctx context.Context, domainName, name, recordType string) (*HostingResourceRecordSet, error) { - path := ha.getPath("/domains/" + domainName + "/resourceRecordSets/" + name + "/" + recordType) - result := &HostingResourceRecordSet{} - if err := doRequest(ctx, http.MethodGet, path, "", result); err != nil { - return nil, err - } - return result, nil -} - -func (ha HostingApi) UpdateResourceRecordSet(ctx context.Context, domainName, name, recordType string, content []string, ttl int) (*HostingResourceRecordSet, error) { - path := ha.getPath("/domains/" + domainName + "/resourceRecordSets/" + name + "/" + recordType) - result := &HostingResourceRecordSet{} - payload := make(map[string]interface{}) - payload["content"] = content - payload["ttl"] = ttl - if err := doRequest(ctx, http.MethodPut, path, "", result, payload); err != nil { - return nil, err - } - return result, nil -} - -func (ha HostingApi) DeleteResourceRecordSet(ctx context.Context, domainName, name, recordType string) error { - path := ha.getPath("/domains/" + domainName + "/resourceRecordSets/" + name + "/" + recordType) - return doRequest(ctx, http.MethodDelete, path, "") -} - -func (ha HostingApi) ValidateResourceRecordSet(ctx context.Context, domainName, name, recordType string, content []string, ttl int) (*HostingInfoMessageResponse, error) { - path := ha.getPath("/domains/" + domainName + "/resourceRecordSets/validateSet") - result := &HostingInfoMessageResponse{} - payload := make(map[string]interface{}) - payload["name"] = name - payload["type"] = recordType - payload["content"] = content - payload["ttl"] = ttl - if err := doRequest(ctx, http.MethodPost, path, "", result); err != nil { - return nil, err - } - return result, nil -} - -func (ha HostingApi) ListCatchAll(ctx context.Context, domainName string) (*HostingEmail, error) { - path := ha.getPath("/domains/" + domainName + "/catchAll") - result := &HostingEmail{} - if err := doRequest(ctx, http.MethodGet, path, "", result); err != nil { - return nil, err - } - return result, nil -} - -func (ha HostingApi) UpdateCatchAll(ctx context.Context, domainName string, payload map[string]interface{}) (*HostingEmail, error) { - path := ha.getPath("/domains/" + domainName + "/catchAll") - result := &HostingEmail{} - if err := doRequest(ctx, http.MethodPut, path, "", result, payload); err != nil { - return nil, err - } - return result, nil -} - -func (ha HostingApi) CreateCatchAll(ctx context.Context, domainName string, payload map[string]interface{}) (*HostingEmail, error) { - return ha.UpdateCatchAll(ctx, domainName, payload) -} - -func (ha HostingApi) DeleteCatchAll(ctx context.Context, domainName string) error { - path := ha.getPath("/domains/" + domainName + "/catchAll") - return doRequest(ctx, http.MethodDelete, path, "") -} - -func (ha HostingApi) ListEmailAliases(ctx context.Context, domainName string, opts PaginationOptions) (*HostingEmailAliases, error) { - path := ha.getPath("/domains/" + domainName + "/emailAliases") - query := options.Encode(opts) - result := &HostingEmailAliases{} - if err := doRequest(ctx, http.MethodGet, path, query, result); err != nil { - return nil, err - } - return result, nil -} - -func (ha HostingApi) CreateEmailAlias(ctx context.Context, domainName string, payload map[string]interface{}) (*HostingEmail, error) { - path := ha.getPath("/domains/" + domainName + "/emailAliases") - result := &HostingEmail{} - if err := doRequest(ctx, http.MethodPost, path, "", result, payload); err != nil { - return nil, err - } - return result, nil -} - -func (ha HostingApi) GetEmailAlias(ctx context.Context, domainName, source, destination string) (*HostingEmail, error) { - path := ha.getPath("/domains/" + domainName + "/emailAliases/" + source + "/" + destination) - result := &HostingEmail{} - if err := doRequest(ctx, http.MethodGet, path, "", result); err != nil { - return nil, err - } - return result, nil -} - -func (ha HostingApi) UpdateEmailAlias(ctx context.Context, domainName, source, destination string, payload map[string]bool) (*HostingEmail, error) { - path := ha.getPath("/domains/" + domainName + "/emailAliases/" + source + "/" + destination) - result := &HostingEmail{} - if err := doRequest(ctx, http.MethodPut, path, "", result, payload); err != nil { - return nil, err - } - return result, nil -} - -func (ha HostingApi) DeleteEmailAlias(ctx context.Context, domainName, source, destination string) error { - path := ha.getPath("/domains/" + domainName + "/emailAliases/" + source + "/" + destination) - return doRequest(ctx, http.MethodDelete, path, "") -} - -func (ha HostingApi) ListDomainForwards(ctx context.Context, domainName string, opts PaginationOptions) (*HostingEmailForwards, error) { - path := ha.getPath("/domains/" + domainName + "/forwards") - query := options.Encode(opts) - result := &HostingEmailForwards{} - if err := doRequest(ctx, http.MethodGet, path, query, result); err != nil { - return nil, err - } - return result, nil -} - -func (ha HostingApi) ListMailBoxes(ctx context.Context, domainName string, opts PaginationOptions) (*HostingEmailMailboxes, error) { - path := ha.getPath("/domains/" + domainName + "/mailboxes") - query := options.Encode(opts) - result := &HostingEmailMailboxes{} - if err := doRequest(ctx, http.MethodGet, path, query, result); err != nil { - return nil, err - } - return result, nil -} - -func (ha HostingApi) CreateMailBox(ctx context.Context, domainName string, payload map[string]interface{}) (*HostingEmail, error) { - path := ha.getPath("/domains/" + domainName + "/mailboxes") - result := &HostingEmail{} - if err := doRequest(ctx, http.MethodPost, path, "", result, payload); err != nil { - return nil, err - } - return result, nil -} - -func (ha HostingApi) GetMailBox(ctx context.Context, domainName, emailAddress string) (*HostingEmail, error) { - path := ha.getPath("/domains/" + domainName + "/mailboxes/" + emailAddress) - result := &HostingEmail{} - if err := doRequest(ctx, http.MethodGet, path, "", result); err != nil { - return nil, err - } - return result, nil -} - -func (ha HostingApi) UpdateMailBox(ctx context.Context, domainName, emailAddress string, payload map[string]interface{}) (*HostingEmail, error) { - path := ha.getPath("/domains/" + domainName + "/mailboxes/" + emailAddress) - result := &HostingEmail{} - if err := doRequest(ctx, http.MethodPut, path, "", result, payload); err != nil { - return nil, err - } - return result, nil -} - -func (ha HostingApi) DeleteMailBox(ctx context.Context, domainName, emailAddress string) error { - path := ha.getPath("/domains/" + domainName + "/mailboxes/" + emailAddress) - return doRequest(ctx, http.MethodDelete, path, "") -} - -func (ha HostingApi) GetAutoResponder(ctx context.Context, domainName, emailAddress string) (*HostingEmail, error) { - path := ha.getPath("/domains/" + domainName + "/mailboxes/" + emailAddress + "/autoResponder") - result := &HostingEmail{} - if err := doRequest(ctx, http.MethodGet, path, "", result); err != nil { - return nil, err - } - return result, nil -} - -func (ha HostingApi) UpdateAutoResponder(ctx context.Context, domainName, emailAddress string, payload map[string]interface{}) (*HostingEmail, error) { - path := ha.getPath("/domains/" + domainName + "/mailboxes/" + emailAddress + "/autoResponder") - result := &HostingEmail{} - if err := doRequest(ctx, http.MethodPut, path, "", result, payload); err != nil { - return nil, err - } - return result, nil -} - -func (ha HostingApi) CreateAutoResponder(ctx context.Context, domainName, emailAddress string, payload map[string]interface{}) (*HostingEmail, error) { - return ha.UpdateAutoResponder(ctx, domainName, emailAddress, payload) -} - -func (ha HostingApi) DeleteAutoResponder(ctx context.Context, domainName, emailAddress string) error { - path := ha.getPath("/domains/" + domainName + "/mailboxes/" + emailAddress + "/autoResponder") - return doRequest(ctx, http.MethodDelete, path, "") -} - -func (ha HostingApi) ListForwards(ctx context.Context, domainName, emailAddress string, opts PaginationOptions) (*HostingEmailForwards, error) { - path := ha.getPath("/domains/" + domainName + "/mailboxes/" + emailAddress + "/forwards") - result := &HostingEmailForwards{} - query := options.Encode(opts) - if err := doRequest(ctx, http.MethodGet, path, query, result); err != nil { - return nil, err - } - return result, nil -} - -func (ha HostingApi) CreateForward(ctx context.Context, domainName, emailAddress string, payload map[string]interface{}) (*HostingEmail, error) { - path := ha.getPath("/domains/" + domainName + "/mailboxes/" + emailAddress + "/forwards") - result := &HostingEmail{} - if err := doRequest(ctx, http.MethodPost, path, "", result, payload); err != nil { - return nil, err - } - return result, nil -} - -func (ha HostingApi) GetForward(ctx context.Context, domainName, emailAddress, destination string) (*HostingEmail, error) { - path := ha.getPath("/domains/" + domainName + "/mailboxes/" + emailAddress + "/forwards/" + destination) - result := &HostingEmail{} - if err := doRequest(ctx, http.MethodGet, path, "", result); err != nil { - return nil, err - } - return result, nil -} - -func (ha HostingApi) UpdateForward(ctx context.Context, domainName, emailAddress, destination string, payload map[string]bool) (*HostingEmail, error) { - path := ha.getPath("/domains/" + domainName + "/mailboxes/" + emailAddress + "/forwards/" + destination) - result := &HostingEmail{} - if err := doRequest(ctx, http.MethodPut, path, "", result, payload); err != nil { - return nil, err - } - return result, nil -} - -func (ha HostingApi) DeleteForward(ctx context.Context, domainName, emailAddress, destination string) error { - path := ha.getPath("/domains/" + domainName + "/mailboxes/" + emailAddress + "/forwards/" + destination) - return doRequest(ctx, http.MethodDelete, path, "") -} diff --git a/hosting_test.go b/hosting_test.go deleted file mode 100644 index 34d3fcc..0000000 --- a/hosting_test.go +++ /dev/null @@ -1,5007 +0,0 @@ -package leaseweb - -import ( - "context" - "fmt" - "net/http" - "testing" - - "github.com/stretchr/testify/assert" -) - -func TestHostingListDomains(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "domains": [ - { - "domainName": "example.com", - "suspended": true, - "dnsOnly": false, - "status": "SUSPENDED", - "contractStartDate": "2017-04-01T00:00:00+02:00", - "contractEndDate": "2018-04-01T00:00:00+02:00", - "_links": { - "self": { - "href": "/domains/example.com" - }, - "collection": { - "href": "/domains" - }, - "catchAll": { - "href": "/domains/example.com/catchAll" - }, - "contacts": { - "href": "/domains/example.com/contacts" - }, - "nameservers": { - "href": "/domains/example.com/nameservers" - }, - "emailAliases": { - "href": "/domains/example.com/emailAliases" - }, - "forwards": { - "href": "/domains/example.com/forwards" - }, - "mailboxes": { - "href": "/domains/example.com/mailboxes" - }, - "resourceRecordSets": { - "href": "/domains/example.com/resourceRecordSets" - }, - "validateZone": { - "href": "/domains/example.com/validateZone" - } - } - }, - { - "domainName": "example.org", - "suspended": false, - "dnsOnly": true, - "status": "ACTIVE", - "contractStartDate": "2015-01-01T00:00:00+00:00", - "_links": { - "self": { - "href": "/domains/example.org" - }, - "collection": { - "href": "/domains" - }, - "catchAll": { - "href": "/domains/example.org/catchAll" - }, - "contacts": { - "href": "/domains/example.com/contacts" - }, - "nameservers": { - "href": "/domains/example.com/nameservers" - }, - "emailAliases": { - "href": "/domains/example.org/emailAliases" - }, - "forwards": { - "href": "/domains/example.org/forwards" - }, - "mailboxes": { - "href": "/domains/example.org/mailboxes" - }, - "resourceRecordSets": { - "href": "/domains/example.org/resourceRecordSets" - }, - "validateZone": { - "href": "/domains/example.org/validateZone" - } - } - } - ], - "_metadata": { - "totalCount": 2, - "limit": 10, - "offset": 0 - } - }`) - }) - defer teardown() - - hostingApi := HostingApi{} - ctx := context.Background() - response, err := hostingApi.ListDomains(ctx, HostingListDomainsOptions{}) - - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 2) - assert.Equal(response.Metadata.Offset, 0) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.Domains), 2) - - domain1 := response.Domains[0] - assert.Equal(domain1.DomainName, "example.com") - assert.Equal(domain1.Suspended, true) - assert.Equal(domain1.DnsOnly, false) - assert.Equal(domain1.Status, "SUSPENDED") - assert.Equal(domain1.ContractStartDate, "2017-04-01T00:00:00+02:00") - assert.Equal(domain1.ContractEndDate, "2018-04-01T00:00:00+02:00") - assert.Equal(domain1.Link.Self.Href, "/domains/example.com") - assert.Equal(domain1.Link.Collection.Href, "/domains") - assert.Equal(domain1.Link.CatchAll.Href, "/domains/example.com/catchAll") - assert.Equal(domain1.Link.Contacts.Href, "/domains/example.com/contacts") - assert.Equal(domain1.Link.Nameservers.Href, "/domains/example.com/nameservers") - assert.Equal(domain1.Link.EmailAliases.Href, "/domains/example.com/emailAliases") - assert.Equal(domain1.Link.Forwards.Href, "/domains/example.com/forwards") - assert.Equal(domain1.Link.Mailboxes.Href, "/domains/example.com/mailboxes") - assert.Equal(domain1.Link.ResourceRecordSets.Href, "/domains/example.com/resourceRecordSets") - assert.Equal(domain1.Link.ValidateZone.Href, "/domains/example.com/validateZone") - - domain2 := response.Domains[1] - assert.Equal(domain2.DomainName, "example.org") - assert.Equal(domain2.Suspended, false) - assert.Equal(domain2.DnsOnly, true) - assert.Equal(domain2.Status, "ACTIVE") - assert.Equal(domain2.ContractStartDate, "2015-01-01T00:00:00+00:00") - assert.Equal(domain1.Link.Self.Href, "/domains/example.com") - assert.Equal(domain1.Link.Collection.Href, "/domains") - assert.Equal(domain1.Link.CatchAll.Href, "/domains/example.com/catchAll") - assert.Equal(domain1.Link.Contacts.Href, "/domains/example.com/contacts") - assert.Equal(domain1.Link.Nameservers.Href, "/domains/example.com/nameservers") - assert.Equal(domain1.Link.EmailAliases.Href, "/domains/example.com/emailAliases") - assert.Equal(domain1.Link.Forwards.Href, "/domains/example.com/forwards") - assert.Equal(domain1.Link.Mailboxes.Href, "/domains/example.com/mailboxes") - assert.Equal(domain1.Link.ResourceRecordSets.Href, "/domains/example.com/resourceRecordSets") - assert.Equal(domain1.Link.ValidateZone.Href, "/domains/example.com/validateZone") -} - -func TestHostingListDomainsPaginateAndFilter(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "domains": [ - { - "domainName": "example.com", - "suspended": true, - "dnsOnly": false, - "status": "SUSPENDED", - "contractStartDate": "2017-04-01T00:00:00+02:00", - "contractEndDate": "2018-04-01T00:00:00+02:00", - "_links": { - "self": { - "href": "/domains/example.com" - }, - "collection": { - "href": "/domains" - }, - "catchAll": { - "href": "/domains/example.com/catchAll" - }, - "contacts": { - "href": "/domains/example.com/contacts" - }, - "nameservers": { - "href": "/domains/example.com/nameservers" - }, - "emailAliases": { - "href": "/domains/example.com/emailAliases" - }, - "forwards": { - "href": "/domains/example.com/forwards" - }, - "mailboxes": { - "href": "/domains/example.com/mailboxes" - }, - "resourceRecordSets": { - "href": "/domains/example.com/resourceRecordSets" - }, - "validateZone": { - "href": "/domains/example.com/validateZone" - } - } - } - ], - "_metadata": { - "totalCount": 1, - "limit": 10, - "offset": 1 - } - }`) - }) - defer teardown() - - hostingApi := HostingApi{} - ctx := context.Background() - opts := HostingListDomainsOptions{ - PaginationOptions: PaginationOptions{ - Limit: Int(1), - }, - } - response, err := hostingApi.ListDomains(ctx, opts) - - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 1) - assert.Equal(response.Metadata.Offset, 1) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.Domains), 1) - - domain1 := response.Domains[0] - assert.Equal(domain1.DomainName, "example.com") - assert.Equal(domain1.Suspended, true) - assert.Equal(domain1.DnsOnly, false) - assert.Equal(domain1.Status, "SUSPENDED") - assert.Equal(domain1.ContractStartDate, "2017-04-01T00:00:00+02:00") - assert.Equal(domain1.ContractEndDate, "2018-04-01T00:00:00+02:00") - assert.Equal(domain1.Link.Self.Href, "/domains/example.com") - assert.Equal(domain1.Link.Collection.Href, "/domains") - assert.Equal(domain1.Link.CatchAll.Href, "/domains/example.com/catchAll") - assert.Equal(domain1.Link.Contacts.Href, "/domains/example.com/contacts") - assert.Equal(domain1.Link.Nameservers.Href, "/domains/example.com/nameservers") - assert.Equal(domain1.Link.EmailAliases.Href, "/domains/example.com/emailAliases") - assert.Equal(domain1.Link.Forwards.Href, "/domains/example.com/forwards") - assert.Equal(domain1.Link.Mailboxes.Href, "/domains/example.com/mailboxes") - assert.Equal(domain1.Link.ResourceRecordSets.Href, "/domains/example.com/resourceRecordSets") - assert.Equal(domain1.Link.ValidateZone.Href, "/domains/example.com/validateZone") -} - -func TestHostingListDomainsServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId": "289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "ACCESS_DENIED", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.ListDomains(ctx, HostingListDomainsOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "ACCESS_DENIED", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId": "289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The server encountered an unexpected condition that prevented it from fulfilling the request."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.ListDomains(ctx, HostingListDomainsOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The server encountered an unexpected condition that prevented it from fulfilling the request.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId": "289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.ListDomains(ctx, HostingListDomainsOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestHostingGetDomain(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "domainName": "example.com", - "suspended": true, - "dnsOnly": false, - "status": "SUSPENDED", - "contractStartDate": "2017-04-01T00:00:00+02:00", - "contractEndDate": "2018-04-01T00:00:00+02:00", - "_links": { - "self": { - "href": "/domains/example.com" - }, - "collection": { - "href": "/domains" - }, - "catchAll": { - "href": "/domains/example.com/catchAll" - }, - "contacts": { - "href": "/domains/example.com/contacts" - }, - "nameservers": { - "href": "/domains/example.com/nameservers" - }, - "emailAliases": { - "href": "/domains/example.com/emailAliases" - }, - "forwards": { - "href": "/domains/example.com/forwards" - }, - "mailboxes": { - "href": "/domains/example.com/mailboxes" - }, - "resourceRecordSets": { - "href": "/domains/example.com/resourceRecordSets" - }, - "validateZone": { - "href": "/domains/example.com/validateZone" - } - } - }`) - }) - defer teardown() - - hostingApi := HostingApi{} - ctx := context.Background() - domain, err := hostingApi.GetDomain(ctx, "exmple.com") - - assert := assert.New(t) - assert.Nil(err) - - assert.Equal(domain.DomainName, "example.com") - assert.Equal(domain.Suspended, true) - assert.Equal(domain.DnsOnly, false) - assert.Equal(domain.Status, "SUSPENDED") - assert.Equal(domain.ContractStartDate, "2017-04-01T00:00:00+02:00") - assert.Equal(domain.ContractEndDate, "2018-04-01T00:00:00+02:00") - assert.Equal(domain.Link.Self.Href, "/domains/example.com") - assert.Equal(domain.Link.Collection.Href, "/domains") - assert.Equal(domain.Link.CatchAll.Href, "/domains/example.com/catchAll") - assert.Equal(domain.Link.Contacts.Href, "/domains/example.com/contacts") - assert.Equal(domain.Link.Nameservers.Href, "/domains/example.com/nameservers") - assert.Equal(domain.Link.EmailAliases.Href, "/domains/example.com/emailAliases") - assert.Equal(domain.Link.Forwards.Href, "/domains/example.com/forwards") - assert.Equal(domain.Link.Mailboxes.Href, "/domains/example.com/mailboxes") - assert.Equal(domain.Link.ResourceRecordSets.Href, "/domains/example.com/resourceRecordSets") - assert.Equal(domain.Link.ValidateZone.Href, "/domains/example.com/validateZone") -} - -func TestHostingGetDomainServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"errorCode": "ACCESS_DENIED", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.GetDomain(ctx, "exmple.com") - }, - ExpectedError: ApiError{ - Code: "ACCESS_DENIED", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusNotFound) - fmt.Fprintf(w, `{"correlationId": "39e010ed-0e93-42c3-c28f-3ffc373553d5", "errorCode": "404", "errorMessage": "Range with id 88.17.0.0_17 does not exist"}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.GetDomain(ctx, "exmple.com") - }, - ExpectedError: ApiError{ - CorrelationId: "39e010ed-0e93-42c3-c28f-3ffc373553d5", - Code: "404", - Message: "Range with id 88.17.0.0_17 does not exist", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId": "289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The server encountered an unexpected condition that prevented it from fulfilling the request."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.GetDomain(ctx, "exmple.com") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The server encountered an unexpected condition that prevented it from fulfilling the request.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId": "289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.GetDomain(ctx, "exmple.com") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestHostingGetAvailability(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "domainName": "example.com", - "available": true, - "_links": { - "self": { - "href": "/domains/example.com/available" - } - } - }`) - }) - defer teardown() - - hostingApi := HostingApi{} - ctx := context.Background() - domain, err := hostingApi.GetAvailability(ctx, "exmple.com") - - assert := assert.New(t) - assert.Nil(err) - - assert.Equal(domain.DomainName, "example.com") - assert.Equal(domain.Available, true) - assert.Equal(domain.Link.Self.Href, "/domains/example.com/available") -} - -func TestHostingGetAvailabilityServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"errorCode": "ACCESS_DENIED", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.GetAvailability(ctx, "exmple.com") - }, - ExpectedError: ApiError{ - Code: "ACCESS_DENIED", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusNotFound) - fmt.Fprintf(w, `{"correlationId": "39e010ed-0e93-42c3-c28f-3ffc373553d5", "errorCode": "404", "errorMessage": "Range with id 88.17.0.0_17 does not exist"}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.GetAvailability(ctx, "exmple.com") - }, - ExpectedError: ApiError{ - CorrelationId: "39e010ed-0e93-42c3-c28f-3ffc373553d5", - Code: "404", - Message: "Range with id 88.17.0.0_17 does not exist", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId": "289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The server encountered an unexpected condition that prevented it from fulfilling the request."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.GetAvailability(ctx, "exmple.com") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The server encountered an unexpected condition that prevented it from fulfilling the request.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId": "289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.GetAvailability(ctx, "exmple.com") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestHostingListNameservers(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "nameservers": [ - { - "name": "ns1.example.com" - }, - { - "name": "ns2.example.net" - } - ], - "status": "Nameservers update request is accepted. This request will be processed after 24 hours.", - "_links": { - "self": { - "href": "/domains/{domainName}/nameservers" - } - }, - "_metadata": { - "totalCount": 2, - "limit": 10, - "offset": 0 - } - }`) - }) - defer teardown() - - hostingApi := HostingApi{} - ctx := context.Background() - response, err := hostingApi.ListNameservers(ctx, "example.com", PaginationOptions{}) - - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 2) - assert.Equal(response.Metadata.Offset, 0) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.Nameservers), 2) - - assert.Equal(response.Nameservers[0].Name, "ns1.example.com") - assert.Equal(response.Nameservers[1].Name, "ns2.example.net") - assert.Equal(response.Status, "Nameservers update request is accepted. This request will be processed after 24 hours.") - assert.Equal(response.Link.Self.Href, "/domains/{domainName}/nameservers") -} - -func TestHostingListNameserversPaginateAndFilter(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "nameservers": [ - { - "name": "ns1.example.com" - } - ], - "status": "Nameservers update request is accepted. This request will be processed after 24 hours.", - "_links": { - "self": { - "href": "/domains/{domainName}/nameservers" - } - }, - "_metadata": { - "totalCount": 11, - "limit": 10, - "offset": 1 - } - }`) - }) - defer teardown() - - hostingApi := HostingApi{} - ctx := context.Background() - response, err := hostingApi.ListNameservers(ctx, "example.com", PaginationOptions{}) - - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 11) - assert.Equal(response.Metadata.Offset, 1) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.Nameservers), 1) - - assert.Equal(response.Nameservers[0].Name, "ns1.example.com") - assert.Equal(response.Status, "Nameservers update request is accepted. This request will be processed after 24 hours.") - assert.Equal(response.Link.Self.Href, "/domains/{domainName}/nameservers") -} - -func TestHostingListNameserversServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId": "289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "ACCESS_DENIED", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - opts := PaginationOptions{ - Limit: Int(1), - } - return HostingApi{}.ListNameservers(ctx, "example.com", opts) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "ACCESS_DENIED", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId": "289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The server encountered an unexpected condition that prevented it from fulfilling the request."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - opts := PaginationOptions{ - Limit: Int(1), - } - return HostingApi{}.ListNameservers(ctx, "example.com", opts) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The server encountered an unexpected condition that prevented it from fulfilling the request.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId": "289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - opts := PaginationOptions{ - Limit: Int(1), - } - return HostingApi{}.ListNameservers(ctx, "example.com", opts) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestHostingUpdateNameservers(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "nameservers": [ - { - "name": "ns1.example.com" - }, - { - "name": "ns2.example.com" - } - ], - "status": "Nameservers update request is accepted. This request will be processed after 24 hours.", - "_links": { - "self": { - "href": "/domains/{domainName}/nameservers" - } - }, - "_metadata": { - "totalCount": 2, - "limit": 10, - "offset": 0 - } - }`) - }) - defer teardown() - - ctx := context.Background() - response, err := HostingApi{}.UpdateNameservers(ctx, "example.com", []string{"ns1.example.com", "ns2.example.com"}) - - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 2) - assert.Equal(response.Metadata.Offset, 0) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.Nameservers), 2) - - assert.Equal(response.Nameservers[0].Name, "ns1.example.com") - assert.Equal(response.Nameservers[1].Name, "ns2.example.com") - assert.Equal(response.Status, "Nameservers update request is accepted. This request will be processed after 24 hours.") - assert.Equal(response.Link.Self.Href, "/domains/{domainName}/nameservers") -} - -func TestHostingUpdateNameserversServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.UpdateNameservers(ctx, "example.com", []string{"ns1.example.com", "ns2.example.com"}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "ACCESS_DENIED", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.UpdateNameservers(ctx, "example.com", []string{"ns1.example.com", "ns2.example.com"}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "ACCESS_DENIED", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "SERVER_ERROR", "errorMessage": "The server encountered an unexpected condition that prevented it from fulfilling the request."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.UpdateNameservers(ctx, "example.com", []string{"ns1.example.com", "ns2.example.com"}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "SERVER_ERROR", - Message: "The server encountered an unexpected condition that prevented it from fulfilling the request.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "TEMPORARILY_UNAVAILABLE", "errorMessage": "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.UpdateNameservers(ctx, "example.com", []string{"ns1.example.com", "ns2.example.com"}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "TEMPORARILY_UNAVAILABLE", - Message: "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestHostingGetGetDnsSecurity(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "status": "ENABLED", - "nsec3": { - "active": true - }, - "keyRollover": { - "status": "INITIALIZED", - "type": "KSK", - "message": "It would take 25 hours to complete the process from the time its been initialized" - }, - "_links": { - "self": { - "href": "/domains/example.com/dnssec" - } - } - }`) - }) - defer teardown() - - hostingApi := HostingApi{} - ctx := context.Background() - resp, err := hostingApi.GetDnsSecurity(ctx, "exmple.com") - - assert := assert.New(t) - assert.Nil(err) - - assert.Equal(resp.Status, "ENABLED") - assert.Equal(resp.Nsec.Active, true) - assert.Equal(resp.KeyRollover.Message, "It would take 25 hours to complete the process from the time its been initialized") - assert.Equal(resp.KeyRollover.Type, "KSK") - assert.Equal(resp.KeyRollover.Status, "INITIALIZED") - assert.Equal(resp.Link.Self.Href, "/domains/example.com/dnssec") -} - -func TestHostingGetGetDnsSecurityServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"errorCode": "ACCESS_DENIED", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.GetDnsSecurity(ctx, "exmple.com") - }, - ExpectedError: ApiError{ - Code: "ACCESS_DENIED", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusNotFound) - fmt.Fprintf(w, `{"correlationId": "39e010ed-0e93-42c3-c28f-3ffc373553d5", "errorCode": "404", "errorMessage": "Range with id 88.17.0.0_17 does not exist"}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.GetDnsSecurity(ctx, "exmple.com") - }, - ExpectedError: ApiError{ - CorrelationId: "39e010ed-0e93-42c3-c28f-3ffc373553d5", - Code: "404", - Message: "Range with id 88.17.0.0_17 does not exist", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId": "289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The server encountered an unexpected condition that prevented it from fulfilling the request."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.GetDnsSecurity(ctx, "exmple.com") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The server encountered an unexpected condition that prevented it from fulfilling the request.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId": "289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.GetDnsSecurity(ctx, "exmple.com") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestHostingUpdateDnsSecurity(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "infoMessage": "DNSSEC enabled successfully. It may take up to 25 hours to reflect." - }`) - }) - defer teardown() - - ctx := context.Background() - response, err := HostingApi{}.UpdateDnsSecurity(ctx, "example.com", map[string]interface{}{"status": "ENABLED"}) - - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.InfoMessage, "DNSSEC enabled successfully. It may take up to 25 hours to reflect.") -} - -func TestHostingUpdateDnsSecurityServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.UpdateDnsSecurity(ctx, "example.com", map[string]interface{}{"status": "ENABLED"}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "ACCESS_DENIED", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.UpdateDnsSecurity(ctx, "example.com", map[string]interface{}{"status": "ENABLED"}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "ACCESS_DENIED", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "SERVER_ERROR", "errorMessage": "The server encountered an unexpected condition that prevented it from fulfilling the request."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.UpdateDnsSecurity(ctx, "example.com", map[string]interface{}{"status": "ENABLED"}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "SERVER_ERROR", - Message: "The server encountered an unexpected condition that prevented it from fulfilling the request.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "TEMPORARILY_UNAVAILABLE", "errorMessage": "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.UpdateDnsSecurity(ctx, "example.com", map[string]interface{}{"status": "ENABLED"}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "TEMPORARILY_UNAVAILABLE", - Message: "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestHostingListResourceRecordSets(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "infoMessage": "Sorry, but your domain is not yet listed on our nameservers. Please create a DNS record first so we can add your domain.", - "resourceRecordSets": [ - { - "name": "example.com.", - "type": "A", - "content": [ - "85.17.150.50", - "85.17.150.50", - "85.17.150.53" - ], - "ttl": 300, - "editable": true, - "_links": { - "self": { - "href": "/domains/example.com/resourceRecordSets/example.com./A" - }, - "collection": { - "href": "/domains/example.com/resourceRecordSets" - } - } - }, - { - "name": "subdomain.example.com.", - "type": "A", - "content": [ - "85.17.150.54" - ], - "ttl": 86400, - "editable": true, - "_links": { - "self": { - "href": "/domains/example.com/resourceRecordSets/subdomain.example.com./A" - }, - "collection": { - "href": "/domains/example.com/resourceRecordSets" - } - } - } - ], - "_links": { - "self": { - "href": "/domains/example.com/resourceRecordSets" - }, - "parent": { - "href": "/domains/example.com" - }, - "validateSet": { - "href": "/domains/example.com/resourceRecordSets/validateSet" - } - }, - "_metadata": { - "totalCount": 2, - "limit": 10, - "offset": 0 - } - }`) - }) - defer teardown() - - hostingApi := HostingApi{} - ctx := context.Background() - response, err := hostingApi.ListResourceRecordSets(ctx, "example.com", PaginationOptions{}) - - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 2) - assert.Equal(response.Metadata.Offset, 0) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.ResourceRecordSets), 2) - - assert.Equal(response.InfoMessage, "Sorry, but your domain is not yet listed on our nameservers. Please create a DNS record first so we can add your domain.") - assert.Equal(response.Link.Self.Href, "/domains/example.com/resourceRecordSets") - assert.Equal(response.Link.Parent.Href, "/domains/example.com") - assert.Equal(response.Link.ValidateSet.Href, "/domains/example.com/resourceRecordSets/validateSet") - - recordSet1 := response.ResourceRecordSets[0] - assert.Equal(recordSet1.Name, "example.com.") - assert.Equal(recordSet1.Type, "A") - assert.Equal(recordSet1.Content[0], "85.17.150.50") - assert.Equal(recordSet1.Content[1], "85.17.150.50") - assert.Equal(recordSet1.Content[2], "85.17.150.53") - assert.Equal(recordSet1.Ttl.String(), "300") - assert.Equal(recordSet1.Editable, true) - assert.Equal(recordSet1.Link.Self.Href, "/domains/example.com/resourceRecordSets/example.com./A") - assert.Equal(recordSet1.Link.Collection.Href, "/domains/example.com/resourceRecordSets") - - recordSet2 := response.ResourceRecordSets[1] - assert.Equal(recordSet2.Name, "subdomain.example.com.") - assert.Equal(recordSet2.Type, "A") - assert.Equal(recordSet2.Content[0], "85.17.150.54") - assert.Equal(recordSet2.Ttl.String(), "86400") - assert.Equal(recordSet2.Editable, true) - assert.Equal(recordSet2.Link.Self.Href, "/domains/example.com/resourceRecordSets/subdomain.example.com./A") - assert.Equal(recordSet2.Link.Collection.Href, "/domains/example.com/resourceRecordSets") -} - -func TestHostingListResourceRecordSetsPaginateAndFilter(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "infoMessage": "Sorry, but your domain is not yet listed on our nameservers. Please create a DNS record first so we can add your domain.", - "resourceRecordSets": [ - { - "name": "example.com.", - "type": "A", - "content": [ - "85.17.150.50", - "85.17.150.50", - "85.17.150.53" - ], - "ttl": 300, - "editable": true, - "_links": { - "self": { - "href": "/domains/example.com/resourceRecordSets/example.com./A" - }, - "collection": { - "href": "/domains/example.com/resourceRecordSets" - } - } - } - ], - "_links": { - "self": { - "href": "/domains/example.com/resourceRecordSets" - }, - "parent": { - "href": "/domains/example.com" - }, - "validateSet": { - "href": "/domains/example.com/resourceRecordSets/validateSet" - } - }, - "_metadata": { - "totalCount": 11, - "limit": 10, - "offset": 1 - } - }`) - }) - defer teardown() - - hostingApi := HostingApi{} - ctx := context.Background() - response, err := hostingApi.ListResourceRecordSets(ctx, "example.com", PaginationOptions{}) - - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 11) - assert.Equal(response.Metadata.Offset, 1) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.ResourceRecordSets), 1) - - assert.Equal(response.InfoMessage, "Sorry, but your domain is not yet listed on our nameservers. Please create a DNS record first so we can add your domain.") - assert.Equal(response.Link.Self.Href, "/domains/example.com/resourceRecordSets") - assert.Equal(response.Link.Parent.Href, "/domains/example.com") - assert.Equal(response.Link.ValidateSet.Href, "/domains/example.com/resourceRecordSets/validateSet") - - recordSet1 := response.ResourceRecordSets[0] - assert.Equal(recordSet1.Name, "example.com.") - assert.Equal(recordSet1.Type, "A") - assert.Equal(recordSet1.Content[0], "85.17.150.50") - assert.Equal(recordSet1.Content[1], "85.17.150.50") - assert.Equal(recordSet1.Content[2], "85.17.150.53") - assert.Equal(recordSet1.Ttl.String(), "300") - assert.Equal(recordSet1.Editable, true) - assert.Equal(recordSet1.Link.Self.Href, "/domains/example.com/resourceRecordSets/example.com./A") - assert.Equal(recordSet1.Link.Collection.Href, "/domains/example.com/resourceRecordSets") -} - -func TestHostingListResourceRecordSetsServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId": "289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "ACCESS_DENIED", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.ListResourceRecordSets(ctx, "example.com", PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "ACCESS_DENIED", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId": "289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The server encountered an unexpected condition that prevented it from fulfilling the request."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - opts := PaginationOptions{ - Limit: Int(1), - } - return HostingApi{}.ListResourceRecordSets(ctx, "example.com", opts) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The server encountered an unexpected condition that prevented it from fulfilling the request.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId": "289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.ListResourceRecordSets(ctx, "example.com", PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestHostingCreateResourceRecordSet(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "name": "example.com.", - "type": "A", - "content": [ - "85.17.150.51", - "85.17.150.52", - "85.17.150.53" - ], - "ttl": 3600, - "editable": true, - "_links": { - "self": { - "href": "/domains/example.com/resourceRecordSets/example.com./A" - }, - "collection": { - "href": "/domains/example.com/resourceRecordSets" - } - } - }`) - }) - defer teardown() - - ctx := context.Background() - resp, err := HostingApi{}.CreateResourceRecordSet(ctx, "example.com", map[string]interface{}{ - "name": "example.com.", - "type": "A", - "ttl": 3600, - "content": []string{"85.17.150.51", "85.17.150.52", "85.17.150.53"}, - }) - - assert := assert.New(t) - assert.Nil(err) - assert.Equal(resp.Name, "example.com.") - assert.Equal(resp.Type, "A") - assert.Equal(resp.Content[0], "85.17.150.51") - assert.Equal(resp.Content[1], "85.17.150.52") - assert.Equal(resp.Content[2], "85.17.150.53") - assert.Equal(resp.Ttl.String(), "3600") - assert.Equal(resp.Editable, true) - assert.Equal(resp.Link.Self.Href, "/domains/example.com/resourceRecordSets/example.com./A") - assert.Equal(resp.Link.Collection.Href, "/domains/example.com/resourceRecordSets") -} - -func TestHostingCreateResourceRecordSetServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.CreateResourceRecordSet(ctx, "example.com", map[string]interface{}{ - "name": "example.com.", - "type": "A", - "ttl": 3600, - "content": []string{"85.17.150.51", "85.17.150.52", "85.17.150.53"}, - }) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "ACCESS_DENIED", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.CreateResourceRecordSet(ctx, "example.com", map[string]interface{}{ - "name": "example.com.", - "type": "A", - "ttl": 3600, - "content": []string{"85.17.150.51", "85.17.150.52", "85.17.150.53"}, - }) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "ACCESS_DENIED", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "SERVER_ERROR", "errorMessage": "The server encountered an unexpected condition that prevented it from fulfilling the request."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.CreateResourceRecordSet(ctx, "example.com", map[string]interface{}{ - "name": "example.com.", - "type": "A", - "ttl": 3600, - "content": []string{"85.17.150.51", "85.17.150.52", "85.17.150.53"}, - }) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "SERVER_ERROR", - Message: "The server encountered an unexpected condition that prevented it from fulfilling the request.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "TEMPORARILY_UNAVAILABLE", "errorMessage": "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.CreateResourceRecordSet(ctx, "example.com", map[string]interface{}{ - "name": "example.com.", - "type": "A", - "ttl": 3600, - "content": []string{"85.17.150.51", "85.17.150.52", "85.17.150.53"}, - }) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "TEMPORARILY_UNAVAILABLE", - Message: "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestHostingDeleteResourceRecordSets(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusNoContent) - }) - defer teardown() - - ctx := context.Background() - err := HostingApi{}.DeleteResourceRecordSets(ctx, "example.com") - - assert := assert.New(t) - assert.Nil(err) -} - -func TestHostingDeleteResourceRecordSetsServerError(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, HostingApi{}.DeleteResourceRecordSet(ctx, "example.com", "example.com.", "A") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "ACCESS_DENIED", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, HostingApi{}.DeleteResourceRecordSet(ctx, "example.com", "example.com.", "A") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "ACCESS_DENIED", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "SERVER_ERROR", "errorMessage": "The server encountered an unexpected condition that prevented it from fulfilling the request."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, HostingApi{}.DeleteResourceRecordSet(ctx, "example.com", "example.com.", "A") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "SERVER_ERROR", - Message: "The server encountered an unexpected condition that prevented it from fulfilling the request.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "TEMPORARILY_UNAVAILABLE", "errorMessage": "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, HostingApi{}.DeleteResourceRecordSet(ctx, "example.com", "example.com.", "A") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "TEMPORARILY_UNAVAILABLE", - Message: "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestHostingGetResourceRecordSet(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "name": "example.com.", - "type": "A", - "content": [ - "85.17.150.51", - "85.17.150.52", - "85.17.150.53" - ], - "ttl": 3600, - "editable": true, - "_links": { - "self": { - "href": "/domains/example.com/resourceRecordSets/example.com./A" - }, - "collection": { - "href": "/domains/example.com/resourceRecordSets" - } - } - }`) - }) - defer teardown() - - ctx := context.Background() - resp, err := HostingApi{}.GetResourceRecordSet(ctx, "exmple.com", "example.com.", "A") - - assert := assert.New(t) - assert.Nil(err) - - assert.Equal(resp.Name, "example.com.") - assert.Equal(resp.Type, "A") - assert.Equal(resp.Ttl.String(), "3600") - assert.Equal(resp.Editable, true) - assert.Equal(resp.Content[0], "85.17.150.51") - assert.Equal(resp.Content[1], "85.17.150.52") - assert.Equal(resp.Content[2], "85.17.150.53") - assert.Equal(resp.Link.Self.Href, "/domains/example.com/resourceRecordSets/example.com./A") - assert.Equal(resp.Link.Collection.Href, "/domains/example.com/resourceRecordSets") -} - -func TestHostingGetResourceRecordSetServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"errorCode": "ACCESS_DENIED", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.GetResourceRecordSet(ctx, "exmple.com", "example.com.", "A") - }, - ExpectedError: ApiError{ - Code: "ACCESS_DENIED", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusNotFound) - fmt.Fprintf(w, `{"correlationId": "39e010ed-0e93-42c3-c28f-3ffc373553d5", "errorCode": "404", "errorMessage": "Range with id 88.17.0.0_17 does not exist"}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.GetResourceRecordSet(ctx, "exmple.com", "example.com.", "A") - }, - ExpectedError: ApiError{ - CorrelationId: "39e010ed-0e93-42c3-c28f-3ffc373553d5", - Code: "404", - Message: "Range with id 88.17.0.0_17 does not exist", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId": "289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The server encountered an unexpected condition that prevented it from fulfilling the request."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.GetResourceRecordSet(ctx, "exmple.com", "example.com.", "A") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The server encountered an unexpected condition that prevented it from fulfilling the request.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId": "289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.GetResourceRecordSet(ctx, "exmple.com", "example.com.", "A") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestHostingUpdateResourceRecordSet(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "name": "example.com.", - "type": "A", - "content": [ - "85.17.150.54" - ], - "ttl": 4200, - "editable": true, - "_links": { - "self": { - "href": "/domains/example.com/resourceRecordSets/example.com./A" - }, - "collection": { - "href": "/domains/example.com/resourceRecordSets" - } - } - }`) - }) - defer teardown() - - ctx := context.Background() - resp, err := HostingApi{}.UpdateResourceRecordSet(ctx, "exmple.com", "example.com.", "A", []string{"85.17.150.54"}, 4200) - - assert := assert.New(t) - assert.Nil(err) - - assert.Equal(resp.Name, "example.com.") - assert.Equal(resp.Type, "A") - assert.Equal(resp.Ttl.String(), "4200") - assert.Equal(resp.Editable, true) - assert.Equal(resp.Content[0], "85.17.150.54") - assert.Equal(resp.Link.Self.Href, "/domains/example.com/resourceRecordSets/example.com./A") - assert.Equal(resp.Link.Collection.Href, "/domains/example.com/resourceRecordSets") -} - -func TestHostingUpdateResourceRecordSetServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.UpdateResourceRecordSet(ctx, "exmple.com", "example.com.", "A", []string{"85.17.150.54"}, 4200) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "ACCESS_DENIED", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.UpdateResourceRecordSet(ctx, "exmple.com", "example.com.", "A", []string{"85.17.150.54"}, 4200) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "ACCESS_DENIED", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "SERVER_ERROR", "errorMessage": "The server encountered an unexpected condition that prevented it from fulfilling the request."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.UpdateResourceRecordSet(ctx, "exmple.com", "example.com.", "A", []string{"85.17.150.54"}, 4200) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "SERVER_ERROR", - Message: "The server encountered an unexpected condition that prevented it from fulfilling the request.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "TEMPORARILY_UNAVAILABLE", "errorMessage": "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.UpdateResourceRecordSet(ctx, "exmple.com", "example.com.", "A", []string{"85.17.150.54"}, 4200) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "TEMPORARILY_UNAVAILABLE", - Message: "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestHostingDeleteResourceRecordSet(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusNoContent) - }) - defer teardown() - - ctx := context.Background() - err := HostingApi{}.DeleteResourceRecordSet(ctx, "example.com", "example.com.", "A") - - assert := assert.New(t) - assert.Nil(err) -} - -func TestHostingDeleteResourceRecordSetsServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, HostingApi{}.DeleteResourceRecordSets(ctx, "example.com") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "ACCESS_DENIED", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, HostingApi{}.DeleteResourceRecordSets(ctx, "example.com") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "ACCESS_DENIED", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "SERVER_ERROR", "errorMessage": "The server encountered an unexpected condition that prevented it from fulfilling the request."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, HostingApi{}.DeleteResourceRecordSets(ctx, "example.com") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "SERVER_ERROR", - Message: "The server encountered an unexpected condition that prevented it from fulfilling the request.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "TEMPORARILY_UNAVAILABLE", "errorMessage": "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, HostingApi{}.DeleteResourceRecordSets(ctx, "example.com") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "TEMPORARILY_UNAVAILABLE", - Message: "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestHostingValidateResourceRecordSet(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "infoMessage": "Resource record set is valid." - }`) - }) - defer teardown() - - ctx := context.Background() - resp, err := HostingApi{}.ValidateResourceRecordSet(ctx, "example.com", "example.com.", "A", []string{"127.0.0.1"}, 3600) - - assert := assert.New(t) - assert.Nil(err) - assert.Equal(resp.InfoMessage, "Resource record set is valid.") -} - -func TestHostingValidateResourceRecordSetServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.ValidateResourceRecordSet(ctx, "example.com", "example.com.", "A", []string{"127.0.0.1"}, 3600) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "ACCESS_DENIED", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.ValidateResourceRecordSet(ctx, "example.com", "example.com.", "A", []string{"127.0.0.1"}, 3600) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "ACCESS_DENIED", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "SERVER_ERROR", "errorMessage": "The server encountered an unexpected condition that prevented it from fulfilling the request."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.ValidateResourceRecordSet(ctx, "example.com", "example.com.", "A", []string{"127.0.0.1"}, 3600) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "SERVER_ERROR", - Message: "The server encountered an unexpected condition that prevented it from fulfilling the request.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "TEMPORARILY_UNAVAILABLE", "errorMessage": "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.ValidateResourceRecordSet(ctx, "example.com", "example.com.", "A", []string{"127.0.0.1"}, 3600) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "TEMPORARILY_UNAVAILABLE", - Message: "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestHostingListCatchAll(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "destination": "destination@example.org", - "spamChecksEnabled": true, - "virusChecksEnabled": false, - "_links": { - "self": { - "href": "/domains/example.com/catchAll" - }, - "parent": { - "href": "/domains/example.com" - } - } - }`) - }) - defer teardown() - - ctx := context.Background() - resp, err := HostingApi{}.ListCatchAll(ctx, "example.com") - - assert := assert.New(t) - assert.Nil(err) - assert.Equal(resp.Destination, "destination@example.org") - assert.Equal(resp.SpamChecksEnabled, true) - assert.Equal(resp.VirusChecksEnabled, false) - assert.Equal(resp.Link.Self.Href, "/domains/example.com/catchAll") - assert.Equal(resp.Link.Parent.Href, "/domains/example.com") -} - -func TestHostingListCatchAllServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId": "289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "ACCESS_DENIED", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.ListCatchAll(ctx, "example.com") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "ACCESS_DENIED", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId": "289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The server encountered an unexpected condition that prevented it from fulfilling the request."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.ListCatchAll(ctx, "example.com") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The server encountered an unexpected condition that prevented it from fulfilling the request.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId": "289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.ListCatchAll(ctx, "example.com") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestHostingUpdateOrCreateCatchAll(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "destination": "destination@example.org", - "spamChecksEnabled": true, - "virusChecksEnabled": false, - "_links": { - "self": { - "href": "/domains/example.com/catchAll" - }, - "parent": { - "href": "/domains/example.com" - } - } - }`) - }) - defer teardown() - - ctx := context.Background() - resp, err := HostingApi{}.UpdateCatchAll(ctx, "exmple.com", map[string]interface{}{ - "destination": "destination@example.org", - "spamChecksEnabled": true, - "virusChecksEnabled": false, - }) - - assert := assert.New(t) - - assert.Nil(err) - assert.Equal(resp.Destination, "destination@example.org") - assert.Equal(resp.SpamChecksEnabled, true) - assert.Equal(resp.VirusChecksEnabled, false) - assert.Equal(resp.Link.Self.Href, "/domains/example.com/catchAll") - assert.Equal(resp.Link.Parent.Href, "/domains/example.com") -} - -func TestHostingUpdateOrCreateCatchAllServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.UpdateCatchAll(ctx, "exmple.com", map[string]interface{}{ - "destination": "destination@example.org", - "spamChecksEnabled": true, - "virusChecksEnabled": false, - }) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "ACCESS_DENIED", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.UpdateCatchAll(ctx, "exmple.com", map[string]interface{}{ - "destination": "destination@example.org", - "spamChecksEnabled": true, - "virusChecksEnabled": false, - }) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "ACCESS_DENIED", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "SERVER_ERROR", "errorMessage": "The server encountered an unexpected condition that prevented it from fulfilling the request."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.UpdateCatchAll(ctx, "exmple.com", map[string]interface{}{ - "destination": "destination@example.org", - "spamChecksEnabled": true, - "virusChecksEnabled": false, - }) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "SERVER_ERROR", - Message: "The server encountered an unexpected condition that prevented it from fulfilling the request.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "TEMPORARILY_UNAVAILABLE", "errorMessage": "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.UpdateCatchAll(ctx, "exmple.com", map[string]interface{}{ - "destination": "destination@example.org", - "spamChecksEnabled": true, - "virusChecksEnabled": false, - }) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "TEMPORARILY_UNAVAILABLE", - Message: "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestHostingDeleteCatchAll(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusNoContent) - }) - defer teardown() - - ctx := context.Background() - err := HostingApi{}.DeleteCatchAll(ctx, "example.com") - - assert := assert.New(t) - assert.Nil(err) -} - -func TestHostingDeleteCatchAllsServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, HostingApi{}.DeleteCatchAll(ctx, "example.com") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "ACCESS_DENIED", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, HostingApi{}.DeleteCatchAll(ctx, "example.com") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "ACCESS_DENIED", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "SERVER_ERROR", "errorMessage": "The server encountered an unexpected condition that prevented it from fulfilling the request."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, HostingApi{}.DeleteCatchAll(ctx, "example.com") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "SERVER_ERROR", - Message: "The server encountered an unexpected condition that prevented it from fulfilling the request.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "TEMPORARILY_UNAVAILABLE", "errorMessage": "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, HostingApi{}.DeleteCatchAll(ctx, "example.com") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "TEMPORARILY_UNAVAILABLE", - Message: "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestHostingListEmailAliases(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "emailAliases": [ - { - "active": true, - "destination": "destination@example.com", - "source": "source@example.com", - "spamChecksEnabled": true, - "virusChecksEnabled": true, - "_links": { - "self": { - "href": "/domains/example.com/emailAliases/source.example.com/destination.example.com" - }, - "collection": { - "href": "/domains/example.com/emailAliases" - } - } - }, - { - "active": true, - "destination": "destination@example.com", - "source": "source@example.com", - "spamChecksEnabled": false, - "virusChecksEnabled": true, - "_links": { - "self": { - "href": "/domains/example.com/emailAliases/source.example.com/destination.example.org" - }, - "collection": { - "href": "/domains/example.com/emailAliases" - } - } - } - ], - "_links": { - "self": { - "href": "/domains/example.com/emailAliases" - }, - "parent": { - "href": "/domains/example.com" - } - }, - "_metadata": { - "totalCount": 2, - "limit": 10, - "offset": 0 - } - }`) - }) - defer teardown() - - ctx := context.Background() - response, err := HostingApi{}.ListEmailAliases(ctx, "example.com", PaginationOptions{}) - - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 2) - assert.Equal(response.Metadata.Offset, 0) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.EmailAliases), 2) - assert.Equal(response.Link.Self.Href, "/domains/example.com/emailAliases") - assert.Equal(response.Link.Parent.Href, "/domains/example.com") - - email1 := response.EmailAliases[0] - assert.Equal(email1.Active, true) - assert.Equal(email1.Destination, "destination@example.com") - assert.Equal(email1.Source, "source@example.com") - assert.Equal(email1.SpamChecksEnabled, true) - assert.Equal(email1.VirusChecksEnabled, true) - assert.Equal(email1.Link.Self.Href, "/domains/example.com/emailAliases/source.example.com/destination.example.com") - assert.Equal(email1.Link.Collection.Href, "/domains/example.com/emailAliases") - - email2 := response.EmailAliases[1] - assert.Equal(email2.Active, true) - assert.Equal(email2.Destination, "destination@example.com") - assert.Equal(email2.Source, "source@example.com") - assert.Equal(email2.SpamChecksEnabled, false) - assert.Equal(email2.VirusChecksEnabled, true) - assert.Equal(email2.Link.Self.Href, "/domains/example.com/emailAliases/source.example.com/destination.example.org") - assert.Equal(email2.Link.Collection.Href, "/domains/example.com/emailAliases") -} - -func TestHostingListEmailAliasesPaginateAndFilter(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "emailAliases": [ - { - "active": true, - "destination": "destination@example.com", - "source": "source@example.com", - "spamChecksEnabled": true, - "virusChecksEnabled": true, - "_links": { - "self": { - "href": "/domains/example.com/emailAliases/source.example.com/destination.example.com" - }, - "collection": { - "href": "/domains/example.com/emailAliases" - } - } - } - ], - "_links": { - "self": { - "href": "/domains/example.com/emailAliases" - }, - "parent": { - "href": "/domains/example.com" - } - }, - "_metadata": { - "totalCount": 11, - "limit": 10, - "offset": 1 - } - }`) - }) - defer teardown() - - ctx := context.Background() - opts := PaginationOptions{ - Limit: Int(1), - } - response, err := HostingApi{}.ListEmailAliases(ctx, "example.com", opts) - - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 11) - assert.Equal(response.Metadata.Offset, 1) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.EmailAliases), 1) - assert.Equal(response.Link.Self.Href, "/domains/example.com/emailAliases") - assert.Equal(response.Link.Parent.Href, "/domains/example.com") - - email1 := response.EmailAliases[0] - assert.Equal(email1.Active, true) - assert.Equal(email1.Destination, "destination@example.com") - assert.Equal(email1.Source, "source@example.com") - assert.Equal(email1.SpamChecksEnabled, true) - assert.Equal(email1.VirusChecksEnabled, true) - assert.Equal(email1.Link.Self.Href, "/domains/example.com/emailAliases/source.example.com/destination.example.com") - assert.Equal(email1.Link.Collection.Href, "/domains/example.com/emailAliases") -} - -func TestHostingListEmailAliasesServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId": "289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "ACCESS_DENIED", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - opts := PaginationOptions{ - Limit: Int(1), - } - return HostingApi{}.ListEmailAliases(ctx, "example.com", opts) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "ACCESS_DENIED", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId": "289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The server encountered an unexpected condition that prevented it from fulfilling the request."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.ListEmailAliases(ctx, "example.com", PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The server encountered an unexpected condition that prevented it from fulfilling the request.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId": "289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.ListEmailAliases(ctx, "example.com", PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestHostingCreateEmailAlias(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "active": true, - "destination": "destination@example.com", - "source": "source@example.com", - "spamChecksEnabled": true, - "virusChecksEnabled": true, - "_links": { - "self": { - "href": "/domains/example.com/emailAliases/source.example.com/destination.example.com" - }, - "collection": { - "href": "/domains/example.com/emailAliases" - } - } - }`) - }) - defer teardown() - - ctx := context.Background() - resp, err := HostingApi{}.CreateEmailAlias(ctx, "example.com", map[string]interface{}{ - "active": true, - "destination": "destination@example.com", - "source": "source@example.com", - "spamChecksEnabled": true, - "virusChecksEnabled": true, - }) - - assert := assert.New(t) - assert.Nil(err) - assert.Equal(resp.Active, true) - assert.Equal(resp.Destination, "destination@example.com") - assert.Equal(resp.Source, "source@example.com") - assert.Equal(resp.SpamChecksEnabled, true) - assert.Equal(resp.VirusChecksEnabled, true) - assert.Equal(resp.Link.Self.Href, "/domains/example.com/emailAliases/source.example.com/destination.example.com") - assert.Equal(resp.Link.Collection.Href, "/domains/example.com/emailAliases") -} - -func TestHostingCreateEmailAliasServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.CreateEmailAlias(ctx, "example.com", map[string]interface{}{ - "active": true, - "destination": "destination@example.com", - "source": "source@example.com", - "spamChecksEnabled": true, - "virusChecksEnabled": true, - }) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "ACCESS_DENIED", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.CreateEmailAlias(ctx, "example.com", map[string]interface{}{ - "active": true, - "destination": "destination@example.com", - "source": "source@example.com", - "spamChecksEnabled": true, - "virusChecksEnabled": true, - }) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "ACCESS_DENIED", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "SERVER_ERROR", "errorMessage": "The server encountered an unexpected condition that prevented it from fulfilling the request."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.CreateEmailAlias(ctx, "example.com", map[string]interface{}{ - "active": true, - "destination": "destination@example.com", - "source": "source@example.com", - "spamChecksEnabled": true, - "virusChecksEnabled": true, - }) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "SERVER_ERROR", - Message: "The server encountered an unexpected condition that prevented it from fulfilling the request.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "TEMPORARILY_UNAVAILABLE", "errorMessage": "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.CreateEmailAlias(ctx, "example.com", map[string]interface{}{ - "active": true, - "destination": "destination@example.com", - "source": "source@example.com", - "spamChecksEnabled": true, - "virusChecksEnabled": true, - }) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "TEMPORARILY_UNAVAILABLE", - Message: "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestHostingGetEmailAlias(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "active": true, - "destination": "destination@example.com", - "source": "source@example.com", - "spamChecksEnabled": true, - "virusChecksEnabled": true, - "_links": { - "self": { - "href": "/domains/example.com/emailAliases/source.example.com/destination.example.com" - }, - "collection": { - "href": "/domains/example.com/emailAliases" - } - } - }`) - }) - defer teardown() - - ctx := context.Background() - resp, err := HostingApi{}.GetEmailAlias(ctx, "example.com", "source@example.com", "destination@example.com") - - assert := assert.New(t) - assert.Nil(err) - assert.Equal(resp.Active, true) - assert.Equal(resp.Destination, "destination@example.com") - assert.Equal(resp.Source, "source@example.com") - assert.Equal(resp.SpamChecksEnabled, true) - assert.Equal(resp.VirusChecksEnabled, true) - assert.Equal(resp.Link.Self.Href, "/domains/example.com/emailAliases/source.example.com/destination.example.com") - assert.Equal(resp.Link.Collection.Href, "/domains/example.com/emailAliases") -} - -func TestHostingGetEmailAliasServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.GetEmailAlias(ctx, "example.com", "source@example.com", "destination@example.com") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "ACCESS_DENIED", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.GetEmailAlias(ctx, "example.com", "source@example.com", "destination@example.com") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "ACCESS_DENIED", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "SERVER_ERROR", "errorMessage": "The server encountered an unexpected condition that prevented it from fulfilling the request."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.GetEmailAlias(ctx, "example.com", "source@example.com", "destination@example.com") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "SERVER_ERROR", - Message: "The server encountered an unexpected condition that prevented it from fulfilling the request.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "TEMPORARILY_UNAVAILABLE", "errorMessage": "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.GetEmailAlias(ctx, "example.com", "source@example.com", "destination@example.com") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "TEMPORARILY_UNAVAILABLE", - Message: "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestHostingUpdateEmailAlias(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "active": true, - "destination": "destination@example.com", - "source": "source@example.com", - "spamChecksEnabled": true, - "virusChecksEnabled": true, - "_links": { - "self": { - "href": "/domains/example.com/emailAliases/source.example.com/destination.example.com" - }, - "collection": { - "href": "/domains/example.com/emailAliases" - } - } - }`) - }) - defer teardown() - - ctx := context.Background() - resp, err := HostingApi{}.UpdateEmailAlias(ctx, "example.com", "source@example.com", "destination@example.com", map[string]bool{ - "active": true, - "spamChecksEnabled": true, - "virusChecksEnabled": true, - }) - - assert := assert.New(t) - assert.Nil(err) - assert.Equal(resp.Active, true) - assert.Equal(resp.Destination, "destination@example.com") - assert.Equal(resp.Source, "source@example.com") - assert.Equal(resp.SpamChecksEnabled, true) - assert.Equal(resp.VirusChecksEnabled, true) - assert.Equal(resp.Link.Self.Href, "/domains/example.com/emailAliases/source.example.com/destination.example.com") - assert.Equal(resp.Link.Collection.Href, "/domains/example.com/emailAliases") -} - -func TestHostingUpdateEmailAliasServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.UpdateEmailAlias(ctx, "example.com", "source@example.com", "destination@example.com", map[string]bool{ - "active": true, - "spamChecksEnabled": true, - "virusChecksEnabled": true, - }) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "ACCESS_DENIED", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.UpdateEmailAlias(ctx, "example.com", "source@example.com", "destination@example.com", map[string]bool{ - "active": true, - "spamChecksEnabled": true, - "virusChecksEnabled": true, - }) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "ACCESS_DENIED", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "SERVER_ERROR", "errorMessage": "The server encountered an unexpected condition that prevented it from fulfilling the request."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.UpdateEmailAlias(ctx, "example.com", "source@example.com", "destination@example.com", map[string]bool{ - "active": true, - "spamChecksEnabled": true, - "virusChecksEnabled": true, - }) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "SERVER_ERROR", - Message: "The server encountered an unexpected condition that prevented it from fulfilling the request.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "TEMPORARILY_UNAVAILABLE", "errorMessage": "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.UpdateEmailAlias(ctx, "example.com", "source@example.com", "destination@example.com", map[string]bool{ - "active": true, - "spamChecksEnabled": true, - "virusChecksEnabled": true, - }) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "TEMPORARILY_UNAVAILABLE", - Message: "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestHostingDeleteEmailAlias(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusNoContent) - }) - defer teardown() - - ctx := context.Background() - err := HostingApi{}.DeleteEmailAlias(ctx, "example.com", "source", "dest") - - assert := assert.New(t) - assert.Nil(err) -} - -func TestHostingDeleteEmailAliasServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, HostingApi{}.DeleteEmailAlias(ctx, "example.com", "source", "dest") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "ACCESS_DENIED", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, HostingApi{}.DeleteEmailAlias(ctx, "example.com", "source", "dest") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "ACCESS_DENIED", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "SERVER_ERROR", "errorMessage": "The server encountered an unexpected condition that prevented it from fulfilling the request."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, HostingApi{}.DeleteEmailAlias(ctx, "example.com", "source", "dest") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "SERVER_ERROR", - Message: "The server encountered an unexpected condition that prevented it from fulfilling the request.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "TEMPORARILY_UNAVAILABLE", "errorMessage": "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, HostingApi{}.DeleteEmailAlias(ctx, "example.com", "source", "dest") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "TEMPORARILY_UNAVAILABLE", - Message: "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestHostingListDomainForwards(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "forwards": [ - { - "active": true, - "destination": "destination@example.com", - "source": "source@example.com", - "spamChecksEnabled": true, - "virusChecksEnabled": true, - "_links": { - "self": { - "href": "/domains/example.com/forwards/source.example.com/destination.example.com" - }, - "collection": { - "href": "/domains/example.com/forwards" - } - } - }, - { - "active": true, - "destination": "destination@example.com", - "source": "source@example.com", - "spamChecksEnabled": false, - "virusChecksEnabled": true, - "_links": { - "self": { - "href": "/domains/example.com/forwards/source.example.com/destination.example.org" - }, - "collection": { - "href": "/domains/example.com/forwards" - } - } - } - ], - "_links": { - "self": { - "href": "/domains/example.com/forwards" - }, - "parent": { - "href": "/domains/example.com" - } - }, - "_metadata": { - "totalCount": 2, - "limit": 10, - "offset": 0 - } - }`) - }) - defer teardown() - - ctx := context.Background() - response, err := HostingApi{}.ListDomainForwards(ctx, "example.com", PaginationOptions{}) - - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 2) - assert.Equal(response.Metadata.Offset, 0) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.Forwards), 2) - assert.Equal(response.Link.Self.Href, "/domains/example.com/forwards") - assert.Equal(response.Link.Parent.Href, "/domains/example.com") - - forward1 := response.Forwards[0] - assert.Equal(forward1.Active, true) - assert.Equal(forward1.Destination, "destination@example.com") - assert.Equal(forward1.Source, "source@example.com") - assert.Equal(forward1.SpamChecksEnabled, true) - assert.Equal(forward1.VirusChecksEnabled, true) - assert.Equal(forward1.Link.Self.Href, "/domains/example.com/forwards/source.example.com/destination.example.com") - assert.Equal(forward1.Link.Collection.Href, "/domains/example.com/forwards") - - forward2 := response.Forwards[1] - assert.Equal(forward2.Active, true) - assert.Equal(forward2.Destination, "destination@example.com") - assert.Equal(forward2.Source, "source@example.com") - assert.Equal(forward2.SpamChecksEnabled, false) - assert.Equal(forward2.VirusChecksEnabled, true) - assert.Equal(forward2.Link.Self.Href, "/domains/example.com/forwards/source.example.com/destination.example.org") - assert.Equal(forward2.Link.Collection.Href, "/domains/example.com/forwards") -} - -func TestHostingListDomainForwardsPaginateAndFilter(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "forwards": [ - { - "active": true, - "destination": "destination@example.com", - "source": "source@example.com", - "spamChecksEnabled": true, - "virusChecksEnabled": true, - "_links": { - "self": { - "href": "/domains/example.com/forwards/source.example.com/destination.example.com" - }, - "collection": { - "href": "/domains/example.com/forwards" - } - } - } - ], - "_links": { - "self": { - "href": "/domains/example.com/forwards" - }, - "parent": { - "href": "/domains/example.com" - } - }, - "_metadata": { - "totalCount": 11, - "limit": 10, - "offset": 1 - } - }`) - }) - defer teardown() - - ctx := context.Background() - opts := PaginationOptions{ - Limit: Int(1), - } - response, err := HostingApi{}.ListDomainForwards(ctx, "example.com", opts) - - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 11) - assert.Equal(response.Metadata.Offset, 1) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.Forwards), 1) - assert.Equal(response.Link.Self.Href, "/domains/example.com/forwards") - assert.Equal(response.Link.Parent.Href, "/domains/example.com") - - forward1 := response.Forwards[0] - assert.Equal(forward1.Active, true) - assert.Equal(forward1.Destination, "destination@example.com") - assert.Equal(forward1.Source, "source@example.com") - assert.Equal(forward1.SpamChecksEnabled, true) - assert.Equal(forward1.VirusChecksEnabled, true) - assert.Equal(forward1.Link.Self.Href, "/domains/example.com/forwards/source.example.com/destination.example.com") - assert.Equal(forward1.Link.Collection.Href, "/domains/example.com/forwards") -} - -func TestHostingListDomainForwardsServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId": "289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "ACCESS_DENIED", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.ListDomainForwards(ctx, "example.com", PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "ACCESS_DENIED", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId": "289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The server encountered an unexpected condition that prevented it from fulfilling the request."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.ListDomainForwards(ctx, "example.com", PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The server encountered an unexpected condition that prevented it from fulfilling the request.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId": "289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.ListDomainForwards(ctx, "example.com", PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestHostingListMailBoxes(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "mailboxes": [ - { - "active": true, - "destination": "destination@example.com", - "source": "source@example.com", - "spamChecksEnabled": true, - "virusChecksEnabled": true, - "currentSize": 1234, - "maximumSize": 4321, - "suspended": true, - "emailAddress": "mailbox@example.com", - "_links": { - "self": { - "href": "/domains/example.com/emailAliases/source.example.com/destination.example.com" - }, - "collection": { - "href": "/domains/example.com/emailAliases" - } - } - }, - { - "active": true, - "destination": "destination@example.com", - "source": "source@example.com", - "spamChecksEnabled": false, - "virusChecksEnabled": true, - "currentSize": 6789, - "maximumSize": 9876, - "suspended": false, - "emailAddress": "info@example.com", - "_links": { - "self": { - "href": "/domains/example.com/emailAliases/source.example.com/destination.example.org" - }, - "collection": { - "href": "/domains/example.com/emailAliases" - } - } - } - ], - "_links": { - "self": { - "href": "/domains/example.com/emailAliases" - }, - "parent": { - "href": "/domains/example.com" - } - }, - "_metadata": { - "totalCount": 2, - "limit": 10, - "offset": 0 - } - }`) - }) - defer teardown() - - ctx := context.Background() - response, err := HostingApi{}.ListMailBoxes(ctx, "example.com", PaginationOptions{}) - - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 2) - assert.Equal(response.Metadata.Offset, 0) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.Mailboxes), 2) - assert.Equal(response.Link.Self.Href, "/domains/example.com/emailAliases") - assert.Equal(response.Link.Parent.Href, "/domains/example.com") - - mailBox1 := response.Mailboxes[0] - assert.Equal(mailBox1.Active, true) - assert.Equal(mailBox1.Destination, "destination@example.com") - assert.Equal(mailBox1.Source, "source@example.com") - assert.Equal(mailBox1.SpamChecksEnabled, true) - assert.Equal(mailBox1.VirusChecksEnabled, true) - assert.Equal(mailBox1.CurrentSize.String(), "1234") - assert.Equal(mailBox1.EmailAddress, "mailbox@example.com") - assert.Equal(mailBox1.MaximumSize.String(), "4321") - assert.Equal(mailBox1.Suspended, true) - assert.Equal(mailBox1.Link.Self.Href, "/domains/example.com/emailAliases/source.example.com/destination.example.com") - assert.Equal(mailBox1.Link.Collection.Href, "/domains/example.com/emailAliases") - - mailBox2 := response.Mailboxes[1] - assert.Equal(mailBox2.Active, true) - assert.Equal(mailBox2.Destination, "destination@example.com") - assert.Equal(mailBox2.Source, "source@example.com") - assert.Equal(mailBox2.SpamChecksEnabled, false) - assert.Equal(mailBox2.VirusChecksEnabled, true) - assert.Equal(mailBox2.CurrentSize.String(), "6789") - assert.Equal(mailBox2.EmailAddress, "info@example.com") - assert.Equal(mailBox2.MaximumSize.String(), "9876") - assert.Equal(mailBox2.Suspended, false) - assert.Equal(mailBox2.Link.Self.Href, "/domains/example.com/emailAliases/source.example.com/destination.example.org") - assert.Equal(mailBox2.Link.Collection.Href, "/domains/example.com/emailAliases") -} - -func TestHostingListMailBoxesPaginateAndFilter(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "mailboxes": [ - { - "active": true, - "destination": "destination@example.com", - "source": "source@example.com", - "spamChecksEnabled": true, - "virusChecksEnabled": true, - "currentSize": 1234, - "maximumSize": 4321, - "suspended": true, - "emailAddress": "mailbox@example.com", - "_links": { - "self": { - "href": "/domains/example.com/emailAliases/source.example.com/destination.example.com" - }, - "collection": { - "href": "/domains/example.com/emailAliases" - } - } - } - ], - "_links": { - "self": { - "href": "/domains/example.com/emailAliases" - }, - "parent": { - "href": "/domains/example.com" - } - }, - "_metadata": { - "totalCount": 11, - "limit": 10, - "offset": 1 - } - }`) - }) - defer teardown() - - ctx := context.Background() - opts := PaginationOptions{ - Limit: Int(1), - } - response, err := HostingApi{}.ListMailBoxes(ctx, "example.com", opts) - - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 11) - assert.Equal(response.Metadata.Offset, 1) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.Mailboxes), 1) - assert.Equal(response.Link.Self.Href, "/domains/example.com/emailAliases") - assert.Equal(response.Link.Parent.Href, "/domains/example.com") - - mailBox1 := response.Mailboxes[0] - assert.Equal(mailBox1.Active, true) - assert.Equal(mailBox1.Destination, "destination@example.com") - assert.Equal(mailBox1.Source, "source@example.com") - assert.Equal(mailBox1.SpamChecksEnabled, true) - assert.Equal(mailBox1.VirusChecksEnabled, true) - assert.Equal(mailBox1.CurrentSize.String(), "1234") - assert.Equal(mailBox1.EmailAddress, "mailbox@example.com") - assert.Equal(mailBox1.MaximumSize.String(), "4321") - assert.Equal(mailBox1.Suspended, true) - assert.Equal(mailBox1.Link.Self.Href, "/domains/example.com/emailAliases/source.example.com/destination.example.com") - assert.Equal(mailBox1.Link.Collection.Href, "/domains/example.com/emailAliases") -} - -func TestHostingListMailBoxesServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId": "289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "ACCESS_DENIED", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.ListMailBoxes(ctx, "example.com", PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "ACCESS_DENIED", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId": "289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The server encountered an unexpected condition that prevented it from fulfilling the request."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.ListMailBoxes(ctx, "example.com", PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The server encountered an unexpected condition that prevented it from fulfilling the request.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId": "289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.ListMailBoxes(ctx, "example.com", PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestHostingCreateMailBox(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "active": true, - "currentSize": 123456789, - "emailAddress": "mailbox@example.com", - "maximumSize": 5368709120, - "spamChecksEnabled": true, - "suspended": false, - "virusChecksEnabled": false, - "localDelivery": true, - "_embedded": { - "autoResponder": { - "_links": { - "self": { - "href": "/domains/example.com/mailboxes/mailbox.example.com/autoResponder" - } - } - } - }, - "_links": { - "self": { - "href": "/domains/example.com/mailboxes/mailbox.example.com" - }, - "collection": { - "href": "/domains/example.com/mailboxes" - }, - "autoResponder": { - "href": "/domains/example.com/mailboxes/mailbox.example.com/autoResponder" - }, - "forwards": { - "href": "/domains/example.com/mailboxes/mailbox.example.com/forwards" - } - } - }`) - }) - defer teardown() - - ctx := context.Background() - resp, err := HostingApi{}.CreateMailBox(ctx, "example.com", map[string]interface{}{ - "emailAddress": "mailbox@example.com", - "active": true, - "password": "CHANGETHIS", - "spamChecksEnabled": true, - "virusChecksEnabled": false, - "localDelivery": true, - }) - - assert := assert.New(t) - assert.Nil(err) - assert.Equal(resp.Active, true) - assert.Equal(resp.CurrentSize.String(), "123456789") - assert.Equal(resp.EmailAddress, "mailbox@example.com") - assert.Equal(resp.MaximumSize.String(), "5368709120") - assert.Equal(resp.SpamChecksEnabled, true) - assert.Equal(resp.Suspended, false) - assert.Equal(resp.VirusChecksEnabled, false) - assert.Equal(resp.LocalDelivery, true) - assert.Equal(resp.Embedded.AutoResponder.Link.Self.Href, "/domains/example.com/mailboxes/mailbox.example.com/autoResponder") - assert.Equal(resp.Link.Self.Href, "/domains/example.com/mailboxes/mailbox.example.com") - assert.Equal(resp.Link.Collection.Href, "/domains/example.com/mailboxes") - assert.Equal(resp.Link.AutoResponder.Href, "/domains/example.com/mailboxes/mailbox.example.com/autoResponder") - assert.Equal(resp.Link.Forwards.Href, "/domains/example.com/mailboxes/mailbox.example.com/forwards") -} - -func TestHostingCreateMailBoxServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.CreateMailBox(ctx, "example.com", map[string]interface{}{ - "emailAddress": "mailbox@example.com", - "active": true, - "password": "CHANGETHIS", - "spamChecksEnabled": true, - "virusChecksEnabled": false, - "localDelivery": true, - }) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "ACCESS_DENIED", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.CreateMailBox(ctx, "example.com", map[string]interface{}{ - "emailAddress": "mailbox@example.com", - "active": true, - "password": "CHANGETHIS", - "spamChecksEnabled": true, - "virusChecksEnabled": false, - "localDelivery": true, - }) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "ACCESS_DENIED", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "SERVER_ERROR", "errorMessage": "The server encountered an unexpected condition that prevented it from fulfilling the request."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.CreateMailBox(ctx, "example.com", map[string]interface{}{ - "emailAddress": "mailbox@example.com", - "active": true, - "password": "CHANGETHIS", - "spamChecksEnabled": true, - "virusChecksEnabled": false, - "localDelivery": true, - }) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "SERVER_ERROR", - Message: "The server encountered an unexpected condition that prevented it from fulfilling the request.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "TEMPORARILY_UNAVAILABLE", "errorMessage": "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.CreateMailBox(ctx, "example.com", map[string]interface{}{ - "emailAddress": "mailbox@example.com", - "active": true, - "password": "CHANGETHIS", - "spamChecksEnabled": true, - "virusChecksEnabled": false, - "localDelivery": true, - }) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "TEMPORARILY_UNAVAILABLE", - Message: "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestHostingGetMailBox(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "active": true, - "currentSize": 123456789, - "emailAddress": "mailbox@example.com", - "maximumSize": 5368709120, - "spamChecksEnabled": true, - "suspended": false, - "virusChecksEnabled": false, - "localDelivery": true, - "_embedded": { - "autoResponder": { - "_links": { - "self": { - "href": "/domains/example.com/mailboxes/mailbox.example.com/autoResponder" - } - } - } - }, - "_links": { - "self": { - "href": "/domains/example.com/mailboxes/mailbox.example.com" - }, - "collection": { - "href": "/domains/example.com/mailboxes" - }, - "autoResponder": { - "href": "/domains/example.com/mailboxes/mailbox.example.com/autoResponder" - }, - "forwards": { - "href": "/domains/example.com/mailboxes/mailbox.example.com/forwards" - } - } - }`) - }) - defer teardown() - - ctx := context.Background() - resp, err := HostingApi{}.GetMailBox(ctx, "example.com", "mailbox@example.com") - - assert := assert.New(t) - assert.Nil(err) - assert.Equal(resp.Active, true) - assert.Equal(resp.CurrentSize.String(), "123456789") - assert.Equal(resp.EmailAddress, "mailbox@example.com") - assert.Equal(resp.MaximumSize.String(), "5368709120") - assert.Equal(resp.SpamChecksEnabled, true) - assert.Equal(resp.Suspended, false) - assert.Equal(resp.VirusChecksEnabled, false) - assert.Equal(resp.LocalDelivery, true) - assert.Equal(resp.Embedded.AutoResponder.Link.Self.Href, "/domains/example.com/mailboxes/mailbox.example.com/autoResponder") - assert.Equal(resp.Link.Self.Href, "/domains/example.com/mailboxes/mailbox.example.com") - assert.Equal(resp.Link.Collection.Href, "/domains/example.com/mailboxes") - assert.Equal(resp.Link.AutoResponder.Href, "/domains/example.com/mailboxes/mailbox.example.com/autoResponder") - assert.Equal(resp.Link.Forwards.Href, "/domains/example.com/mailboxes/mailbox.example.com/forwards") -} - -func TestHostingGetMailBoxServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.GetMailBox(ctx, "example.com", "mailbox@example.com") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "ACCESS_DENIED", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.GetMailBox(ctx, "example.com", "mailbox@example.com") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "ACCESS_DENIED", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "SERVER_ERROR", "errorMessage": "The server encountered an unexpected condition that prevented it from fulfilling the request."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.GetMailBox(ctx, "example.com", "mailbox@example.com") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "SERVER_ERROR", - Message: "The server encountered an unexpected condition that prevented it from fulfilling the request.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "TEMPORARILY_UNAVAILABLE", "errorMessage": "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.GetMailBox(ctx, "example.com", "mailbox@example.com") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "TEMPORARILY_UNAVAILABLE", - Message: "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestHostingUpdateMailBox(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "active": true, - "currentSize": 123456789, - "emailAddress": "mailbox@example.com", - "maximumSize": 5368709120, - "spamChecksEnabled": true, - "suspended": false, - "virusChecksEnabled": false, - "localDelivery": true, - "_embedded": { - "autoResponder": { - "_links": { - "self": { - "href": "/domains/example.com/mailboxes/mailbox.example.com/autoResponder" - } - } - } - }, - "_links": { - "self": { - "href": "/domains/example.com/mailboxes/mailbox.example.com" - }, - "collection": { - "href": "/domains/example.com/mailboxes" - }, - "autoResponder": { - "href": "/domains/example.com/mailboxes/mailbox.example.com/autoResponder" - }, - "forwards": { - "href": "/domains/example.com/mailboxes/mailbox.example.com/forwards" - } - } - }`) - }) - defer teardown() - - ctx := context.Background() - resp, err := HostingApi{}.UpdateMailBox(ctx, "example.com", "mailbox@example.com", map[string]interface{}{ - "emailAddress": "mailbox@example.com", - "active": true, - "password": "CHANGETHIS", - "spamChecksEnabled": true, - "virusChecksEnabled": false, - "localDelivery": true, - }) - - assert := assert.New(t) - assert.Nil(err) - assert.Equal(resp.Active, true) - assert.Equal(resp.CurrentSize.String(), "123456789") - assert.Equal(resp.EmailAddress, "mailbox@example.com") - assert.Equal(resp.MaximumSize.String(), "5368709120") - assert.Equal(resp.SpamChecksEnabled, true) - assert.Equal(resp.Suspended, false) - assert.Equal(resp.VirusChecksEnabled, false) - assert.Equal(resp.LocalDelivery, true) - assert.Equal(resp.Embedded.AutoResponder.Link.Self.Href, "/domains/example.com/mailboxes/mailbox.example.com/autoResponder") - assert.Equal(resp.Link.Self.Href, "/domains/example.com/mailboxes/mailbox.example.com") - assert.Equal(resp.Link.Collection.Href, "/domains/example.com/mailboxes") - assert.Equal(resp.Link.AutoResponder.Href, "/domains/example.com/mailboxes/mailbox.example.com/autoResponder") - assert.Equal(resp.Link.Forwards.Href, "/domains/example.com/mailboxes/mailbox.example.com/forwards") -} - -func TestHostingUpdateMailBoxServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.UpdateMailBox(ctx, "example.com", "mailbox@example.com", map[string]interface{}{ - "emailAddress": "mailbox@example.com", - "active": true, - "password": "CHANGETHIS", - "spamChecksEnabled": true, - "virusChecksEnabled": false, - "localDelivery": true, - }) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "ACCESS_DENIED", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.UpdateMailBox(ctx, "example.com", "mailbox@example.com", map[string]interface{}{ - "emailAddress": "mailbox@example.com", - "active": true, - "password": "CHANGETHIS", - "spamChecksEnabled": true, - "virusChecksEnabled": false, - "localDelivery": true, - }) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "ACCESS_DENIED", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "SERVER_ERROR", "errorMessage": "The server encountered an unexpected condition that prevented it from fulfilling the request."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.UpdateMailBox(ctx, "example.com", "mailbox@example.com", map[string]interface{}{ - "emailAddress": "mailbox@example.com", - "active": true, - "password": "CHANGETHIS", - "spamChecksEnabled": true, - "virusChecksEnabled": false, - "localDelivery": true, - }) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "SERVER_ERROR", - Message: "The server encountered an unexpected condition that prevented it from fulfilling the request.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "TEMPORARILY_UNAVAILABLE", "errorMessage": "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.UpdateMailBox(ctx, "example.com", "mailbox@example.com", map[string]interface{}{ - "emailAddress": "mailbox@example.com", - "active": true, - "password": "CHANGETHIS", - "spamChecksEnabled": true, - "virusChecksEnabled": false, - "localDelivery": true, - }) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "TEMPORARILY_UNAVAILABLE", - Message: "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestHostingDeleteMailBox(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusNoContent) - }) - defer teardown() - - ctx := context.Background() - err := HostingApi{}.DeleteMailBox(ctx, "example.com", "info@example.com") - - assert := assert.New(t) - assert.Nil(err) -} - -func TestHostingDeleteMailBoxServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, HostingApi{}.DeleteMailBox(ctx, "example.com", "info@example.com") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "ACCESS_DENIED", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, HostingApi{}.DeleteMailBox(ctx, "example.com", "info@example.com") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "ACCESS_DENIED", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "SERVER_ERROR", "errorMessage": "The server encountered an unexpected condition that prevented it from fulfilling the request."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, HostingApi{}.DeleteMailBox(ctx, "example.com", "info@example.com") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "SERVER_ERROR", - Message: "The server encountered an unexpected condition that prevented it from fulfilling the request.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "TEMPORARILY_UNAVAILABLE", "errorMessage": "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, HostingApi{}.DeleteMailBox(ctx, "example.com", "info@example.com") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "TEMPORARILY_UNAVAILABLE", - Message: "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestHostingGetAutoResponder(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "active": true, - "body": "I will be out of office until 14-12-2020. Please contact the reception desk for urgent matters.", - "subject": "Out of office", - "_links": { - "self": { - "href": "/domains/example.com/mailboxes/mailbox.example.com" - }, - "parent": { - "href": "/domains/example.com/mailboxes/mailbox.example.com" - } - } - }`) - }) - defer teardown() - - ctx := context.Background() - resp, err := HostingApi{}.GetAutoResponder(ctx, "example.com", "mailbox@example.com") - - assert := assert.New(t) - assert.Nil(err) - assert.Equal(resp.Active, true) - assert.Equal(resp.Body, "I will be out of office until 14-12-2020. Please contact the reception desk for urgent matters.") - assert.Equal(resp.Subject, "Out of office") - assert.Equal(resp.Link.Self.Href, "/domains/example.com/mailboxes/mailbox.example.com") - assert.Equal(resp.Link.Parent.Href, "/domains/example.com/mailboxes/mailbox.example.com") -} - -func TestHostingGetAutoResponderServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.GetAutoResponder(ctx, "example.com", "mailbox@example.com") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "ACCESS_DENIED", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.GetAutoResponder(ctx, "example.com", "mailbox@example.com") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "ACCESS_DENIED", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "SERVER_ERROR", "errorMessage": "The server encountered an unexpected condition that prevented it from fulfilling the request."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.GetAutoResponder(ctx, "example.com", "mailbox@example.com") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "SERVER_ERROR", - Message: "The server encountered an unexpected condition that prevented it from fulfilling the request.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "TEMPORARILY_UNAVAILABLE", "errorMessage": "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.GetAutoResponder(ctx, "example.com", "mailbox@example.com") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "TEMPORARILY_UNAVAILABLE", - Message: "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestHostingUpdateOrCreateAutoResponder(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "active": true, - "body": "I will be out of office until 14-12-2020. Please contact the reception desk for urgent matters.", - "subject": "Out of office", - "_links": { - "self": { - "href": "/domains/example.com/mailboxes/mailbox.example.com" - }, - "parent": { - "href": "/domains/example.com/mailboxes/mailbox.example.com" - } - } - }`) - }) - defer teardown() - - ctx := context.Background() - resp, err := HostingApi{}.UpdateAutoResponder(ctx, "example.com", "mailbox@example.com", map[string]interface{}{ - "active": true, - "body": "I will be out of office until 14-12-2020. Please contact the reception desk for urgent matters.", - "subject": "Out of office", - }) - - assert := assert.New(t) - assert.Nil(err) - assert.Equal(resp.Active, true) - assert.Equal(resp.Body, "I will be out of office until 14-12-2020. Please contact the reception desk for urgent matters.") - assert.Equal(resp.Subject, "Out of office") - assert.Equal(resp.Link.Self.Href, "/domains/example.com/mailboxes/mailbox.example.com") - assert.Equal(resp.Link.Parent.Href, "/domains/example.com/mailboxes/mailbox.example.com") -} - -func TestHostingUpdateOrCreateAutoResponderServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.UpdateAutoResponder(ctx, "example.com", "mailbox@example.com", map[string]interface{}{ - "active": true, - "body": "I will be out of office until 14-12-2020. Please contact the reception desk for urgent matters.", - "subject": "Out of office", - }) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "ACCESS_DENIED", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.UpdateAutoResponder(ctx, "example.com", "mailbox@example.com", map[string]interface{}{ - "active": true, - "body": "I will be out of office until 14-12-2020. Please contact the reception desk for urgent matters.", - "subject": "Out of office", - }) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "ACCESS_DENIED", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "SERVER_ERROR", "errorMessage": "The server encountered an unexpected condition that prevented it from fulfilling the request."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.UpdateAutoResponder(ctx, "example.com", "mailbox@example.com", map[string]interface{}{ - "active": true, - "body": "I will be out of office until 14-12-2020. Please contact the reception desk for urgent matters.", - "subject": "Out of office", - }) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "SERVER_ERROR", - Message: "The server encountered an unexpected condition that prevented it from fulfilling the request.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "TEMPORARILY_UNAVAILABLE", "errorMessage": "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.UpdateAutoResponder(ctx, "example.com", "mailbox@example.com", map[string]interface{}{ - "active": true, - "body": "I will be out of office until 14-12-2020. Please contact the reception desk for urgent matters.", - "subject": "Out of office", - }) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "TEMPORARILY_UNAVAILABLE", - Message: "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestHostingDeleteAutoResponder(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusNoContent) - }) - defer teardown() - - ctx := context.Background() - err := HostingApi{}.DeleteAutoResponder(ctx, "example.com", "info@example.com") - - assert := assert.New(t) - assert.Nil(err) -} - -func TestHostingDeleteAutoResponderServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, HostingApi{}.DeleteAutoResponder(ctx, "example.com", "info@example.com") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "ACCESS_DENIED", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, HostingApi{}.DeleteAutoResponder(ctx, "example.com", "info@example.com") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "ACCESS_DENIED", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "SERVER_ERROR", "errorMessage": "The server encountered an unexpected condition that prevented it from fulfilling the request."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, HostingApi{}.DeleteAutoResponder(ctx, "example.com", "info@example.com") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "SERVER_ERROR", - Message: "The server encountered an unexpected condition that prevented it from fulfilling the request.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "TEMPORARILY_UNAVAILABLE", "errorMessage": "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, HostingApi{}.DeleteAutoResponder(ctx, "example.com", "info@example.com") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "TEMPORARILY_UNAVAILABLE", - Message: "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestHostingListForwards(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "forwards": [ - { - "active": true, - "destination": "destination@example.com", - "source": "source@example.com", - "spamChecksEnabled": true, - "virusChecksEnabled": true, - "_links": { - "self": { - "href": "/domains/example.com/emailAliases/source.example.com/destination.example.com" - }, - "collection": { - "href": "/domains/example.com/emailAliases" - } - } - }, - { - "active": true, - "destination": "destination@example.com", - "source": "source@example.com", - "spamChecksEnabled": false, - "virusChecksEnabled": true, - "_links": { - "self": { - "href": "/domains/example.com/emailAliases/source.example.com/destination.example.org" - }, - "collection": { - "href": "/domains/example.com/emailAliases" - } - } - } - ], - "_links": { - "self": { - "href": "/domains/example.com/emailAliases" - }, - "parent": { - "href": "/domains/example.com" - } - }, - "_metadata": { - "totalCount": 2, - "limit": 10, - "offset": 0 - } - }`) - }) - defer teardown() - - ctx := context.Background() - response, err := HostingApi{}.ListForwards(ctx, "example.com", "random@example.com", PaginationOptions{}) - - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 2) - assert.Equal(response.Metadata.Offset, 0) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.Forwards), 2) - assert.Equal(response.Link.Self.Href, "/domains/example.com/emailAliases") - assert.Equal(response.Link.Parent.Href, "/domains/example.com") - - forward1 := response.Forwards[0] - assert.Equal(forward1.Active, true) - assert.Equal(forward1.Destination, "destination@example.com") - assert.Equal(forward1.Source, "source@example.com") - assert.Equal(forward1.SpamChecksEnabled, true) - assert.Equal(forward1.VirusChecksEnabled, true) - assert.Equal(forward1.Link.Self.Href, "/domains/example.com/emailAliases/source.example.com/destination.example.com") - assert.Equal(forward1.Link.Collection.Href, "/domains/example.com/emailAliases") - - forward2 := response.Forwards[1] - assert.Equal(forward2.Active, true) - assert.Equal(forward2.Destination, "destination@example.com") - assert.Equal(forward2.Source, "source@example.com") - assert.Equal(forward2.SpamChecksEnabled, false) - assert.Equal(forward2.VirusChecksEnabled, true) - assert.Equal(forward2.Link.Self.Href, "/domains/example.com/emailAliases/source.example.com/destination.example.org") - assert.Equal(forward2.Link.Collection.Href, "/domains/example.com/emailAliases") -} - -func TestHostingListForwardsPaginateAndFilter(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "forwards": [ - { - "active": true, - "destination": "destination@example.com", - "source": "source@example.com", - "spamChecksEnabled": true, - "virusChecksEnabled": true, - "_links": { - "self": { - "href": "/domains/example.com/emailAliases/source.example.com/destination.example.com" - }, - "collection": { - "href": "/domains/example.com/emailAliases" - } - } - } - ], - "_links": { - "self": { - "href": "/domains/example.com/emailAliases" - }, - "parent": { - "href": "/domains/example.com" - } - }, - "_metadata": { - "totalCount": 11, - "limit": 10, - "offset": 1 - } - }`) - }) - defer teardown() - - ctx := context.Background() - opts := PaginationOptions{ - Limit: Int(1), - } - response, err := HostingApi{}.ListForwards(ctx, "example.com", "random@example.com", opts) - - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 11) - assert.Equal(response.Metadata.Offset, 1) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.Forwards), 1) - assert.Equal(response.Link.Self.Href, "/domains/example.com/emailAliases") - assert.Equal(response.Link.Parent.Href, "/domains/example.com") - - forward1 := response.Forwards[0] - assert.Equal(forward1.Active, true) - assert.Equal(forward1.Destination, "destination@example.com") - assert.Equal(forward1.Source, "source@example.com") - assert.Equal(forward1.SpamChecksEnabled, true) - assert.Equal(forward1.VirusChecksEnabled, true) - assert.Equal(forward1.Link.Self.Href, "/domains/example.com/emailAliases/source.example.com/destination.example.com") - assert.Equal(forward1.Link.Collection.Href, "/domains/example.com/emailAliases") -} - -func TestHostingListForwardsServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId": "289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "ACCESS_DENIED", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.ListForwards(ctx, "example.com", "random@example.com", PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "ACCESS_DENIED", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId": "289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The server encountered an unexpected condition that prevented it from fulfilling the request."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.ListForwards(ctx, "example.com", "random@example.com", PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The server encountered an unexpected condition that prevented it from fulfilling the request.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId": "289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.ListForwards(ctx, "example.com", "random@example.com", PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestHostingCreateForward(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "active": true, - "destination": "destination@example.com", - "source": "source@example.com", - "spamChecksEnabled": true, - "virusChecksEnabled": true, - "_links": { - "self": { - "href": "/domains/example.com/emailAliases/source.example.com/destination.example.com" - }, - "collection": { - "href": "/domains/example.com/emailAliases" - } - } - }`) - }) - defer teardown() - - ctx := context.Background() - resp, err := HostingApi{}.CreateForward(ctx, "example.com", "random@example.com", map[string]interface{}{ - "active": true, - "destination": "destination@example.com", - "source": "source@example.com", - "spamChecksEnabled": true, - "virusChecksEnabled": true, - }) - - assert := assert.New(t) - assert.Nil(err) - assert.Equal(resp.Active, true) - assert.Equal(resp.Destination, "destination@example.com") - assert.Equal(resp.Source, "source@example.com") - assert.Equal(resp.SpamChecksEnabled, true) - assert.Equal(resp.VirusChecksEnabled, true) - assert.Equal(resp.Link.Self.Href, "/domains/example.com/emailAliases/source.example.com/destination.example.com") - assert.Equal(resp.Link.Collection.Href, "/domains/example.com/emailAliases") -} - -func TestHostingCreateForwardServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.CreateForward(ctx, "example.com", "random@example.com", map[string]interface{}{ - "active": true, - "destination": "destination@example.com", - "source": "source@example.com", - "spamChecksEnabled": true, - "virusChecksEnabled": true, - }) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "ACCESS_DENIED", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.CreateForward(ctx, "example.com", "random@example.com", map[string]interface{}{ - "active": true, - "destination": "destination@example.com", - "source": "source@example.com", - "spamChecksEnabled": true, - "virusChecksEnabled": true, - }) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "ACCESS_DENIED", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "SERVER_ERROR", "errorMessage": "The server encountered an unexpected condition that prevented it from fulfilling the request."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.CreateForward(ctx, "example.com", "random@example.com", map[string]interface{}{ - "active": true, - "destination": "destination@example.com", - "source": "source@example.com", - "spamChecksEnabled": true, - "virusChecksEnabled": true, - }) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "SERVER_ERROR", - Message: "The server encountered an unexpected condition that prevented it from fulfilling the request.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "TEMPORARILY_UNAVAILABLE", "errorMessage": "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.CreateForward(ctx, "example.com", "random@example.com", map[string]interface{}{ - "active": true, - "destination": "destination@example.com", - "source": "source@example.com", - "spamChecksEnabled": true, - "virusChecksEnabled": true, - }) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "TEMPORARILY_UNAVAILABLE", - Message: "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestHostingGetForward(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "active": true, - "destination": "destination@example.com", - "source": "source@example.com", - "spamChecksEnabled": true, - "virusChecksEnabled": true, - "_links": { - "self": { - "href": "/domains/example.com/emailAliases/source.example.com/destination.example.com" - }, - "collection": { - "href": "/domains/example.com/emailAliases" - } - } - }`) - }) - defer teardown() - - ctx := context.Background() - resp, err := HostingApi{}.GetForward(ctx, "example.com", "random@example.com", "destination@example.com") - - assert := assert.New(t) - assert.Nil(err) - assert.Equal(resp.Active, true) - assert.Equal(resp.Destination, "destination@example.com") - assert.Equal(resp.Source, "source@example.com") - assert.Equal(resp.SpamChecksEnabled, true) - assert.Equal(resp.VirusChecksEnabled, true) - assert.Equal(resp.Link.Self.Href, "/domains/example.com/emailAliases/source.example.com/destination.example.com") - assert.Equal(resp.Link.Collection.Href, "/domains/example.com/emailAliases") -} - -func TestHostingGetForwardServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.GetForward(ctx, "example.com", "random@example.com", "destination@example.com") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "ACCESS_DENIED", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.GetForward(ctx, "example.com", "random@example.com", "destination@example.com") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "ACCESS_DENIED", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "SERVER_ERROR", "errorMessage": "The server encountered an unexpected condition that prevented it from fulfilling the request."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.GetForward(ctx, "example.com", "random@example.com", "destination@example.com") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "SERVER_ERROR", - Message: "The server encountered an unexpected condition that prevented it from fulfilling the request.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "TEMPORARILY_UNAVAILABLE", "errorMessage": "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.GetForward(ctx, "example.com", "random@example.com", "destination@example.com") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "TEMPORARILY_UNAVAILABLE", - Message: "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestHostingUpdateForward(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "active": true, - "destination": "destination@example.com", - "source": "source@example.com", - "spamChecksEnabled": true, - "virusChecksEnabled": true, - "_links": { - "self": { - "href": "/domains/example.com/emailAliases/source.example.com/destination.example.com" - }, - "collection": { - "href": "/domains/example.com/emailAliases" - } - } - }`) - }) - defer teardown() - - ctx := context.Background() - resp, err := HostingApi{}.UpdateForward(ctx, "example.com", "random@example.com", "destination@example.com", map[string]bool{ - "active": true, - "spamChecksEnabled": true, - "virusChecksEnabled": true, - }) - - assert := assert.New(t) - assert.Nil(err) - assert.Equal(resp.Active, true) - assert.Equal(resp.Destination, "destination@example.com") - assert.Equal(resp.Source, "source@example.com") - assert.Equal(resp.SpamChecksEnabled, true) - assert.Equal(resp.VirusChecksEnabled, true) - assert.Equal(resp.Link.Self.Href, "/domains/example.com/emailAliases/source.example.com/destination.example.com") - assert.Equal(resp.Link.Collection.Href, "/domains/example.com/emailAliases") -} - -func TestHostingUpdateForwardServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.UpdateForward(ctx, "example.com", "random@example.com", "destination@example.com", map[string]bool{ - "active": true, - "spamChecksEnabled": true, - "virusChecksEnabled": true, - }) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "ACCESS_DENIED", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.UpdateForward(ctx, "example.com", "random@example.com", "destination@example.com", map[string]bool{ - "active": true, - "spamChecksEnabled": true, - "virusChecksEnabled": true, - }) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "ACCESS_DENIED", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "SERVER_ERROR", "errorMessage": "The server encountered an unexpected condition that prevented it from fulfilling the request."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.UpdateForward(ctx, "example.com", "random@example.com", "destination@example.com", map[string]bool{ - "active": true, - "spamChecksEnabled": true, - "virusChecksEnabled": true, - }) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "SERVER_ERROR", - Message: "The server encountered an unexpected condition that prevented it from fulfilling the request.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "TEMPORARILY_UNAVAILABLE", "errorMessage": "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return HostingApi{}.UpdateForward(ctx, "example.com", "random@example.com", "destination@example.com", map[string]bool{ - "active": true, - "spamChecksEnabled": true, - "virusChecksEnabled": true, - }) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "TEMPORARILY_UNAVAILABLE", - Message: "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestHostingDeleteForward(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusNoContent) - }) - defer teardown() - - ctx := context.Background() - err := HostingApi{}.DeleteForward(ctx, "example.com", "email", "dest") - - assert := assert.New(t) - assert.Nil(err) -} - -func TestHostingDeleteForwardServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, HostingApi{}.DeleteForward(ctx, "example.com", "email", "dest") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "ACCESS_DENIED", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, HostingApi{}.DeleteForward(ctx, "example.com", "email", "dest") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "ACCESS_DENIED", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "SERVER_ERROR", "errorMessage": "The server encountered an unexpected condition that prevented it from fulfilling the request."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, HostingApi{}.DeleteForward(ctx, "example.com", "email", "dest") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "SERVER_ERROR", - Message: "The server encountered an unexpected condition that prevented it from fulfilling the request.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "TEMPORARILY_UNAVAILABLE", "errorMessage": "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, HostingApi{}.DeleteForward(ctx, "example.com", "email", "dest") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "TEMPORARILY_UNAVAILABLE", - Message: "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} diff --git a/invoice.go b/invoice.go deleted file mode 100644 index 8bc4eb9..0000000 --- a/invoice.go +++ /dev/null @@ -1,104 +0,0 @@ -package leaseweb - -import ( - "context" - "encoding/json" - "net/http" - - "github.com/LeaseWeb/leaseweb-go-sdk/options" -) - -const INVOICE_API_VERSION = "v1" - -type InvoiceApi struct{} - -type Invoice struct { - Currency string `json:"currency"` - Date string `json:"date"` - DueDate string `json:"dueDate"` - Id string `json:"id"` - IsPartialPaymentAllowed bool `json:"isPartialPaymentAllowed"` - OpenAmount json.Number `json:"openAmount"` - Status string `json:"status"` - TaxAmount json.Number `json:"taxAmount"` - Total json.Number `json:"total"` - Credits []InvoiceCredit `json:"credits"` - Lines []InvoiceLine `json:"lineItems"` -} - -type InvoiceCredit struct { - Date string `json:"date"` - Id string `json:"id"` - TaxAmount json.Number `json:"taxAmount"` - Total json.Number `json:"total"` -} - -type InvoiceLine struct { - ContractId string `json:"contractId"` - EquipmentId string `json:"equipmentId"` - Product string `json:"product"` - Quantity json.Number `json:"quantity"` - Reference string `json:"reference"` - TotalAmount json.Number `json:"totalAmount"` - UnitAmount json.Number `json:"unitAmount"` -} - -type InvoiceContract struct { - ContractId string `json:"contractId"` - Currency string `json:"currency"` - EndDate string `json:"endDate"` - EquipmentId string `json:"equipmentId"` - PoNumber string `json:"poNumber"` - Price json.Number `json:"price"` - Product string `json:"product"` - Reference string `json:"reference"` - StartDate string `json:"startDate"` -} - -type Invoices struct { - Invoices []Invoice `json:"invoices"` - Metadata Metadata `json:"_metadata"` -} - -type InvoiceProForma struct { - Currency string `json:"currency"` - ProformaDate string `json:"proformaDate"` - SubTotal json.Number `json:"subTotal"` - Total json.Number `json:"total"` - VatAmount json.Number `json:"vatAmount"` - Metadata Metadata `json:"_metadata"` - Contracts []InvoiceContract `json:"contractItems"` -} - -func (ia InvoiceApi) getPath(endpoint string) string { - return "/invoices/" + INVOICE_API_VERSION + endpoint -} - -func (ia InvoiceApi) List(ctx context.Context, opts PaginationOptions) (*Invoices, error) { - path := ia.getPath("/invoices") - query := options.Encode(opts) - result := &Invoices{} - if err := doRequest(ctx, http.MethodGet, path, query, result); err != nil { - return nil, err - } - return result, nil -} - -func (ia InvoiceApi) ListProForma(ctx context.Context, opts PaginationOptions) (*InvoiceProForma, error) { - path := ia.getPath("/invoices/proforma") - query := options.Encode(opts) - result := &InvoiceProForma{} - if err := doRequest(ctx, http.MethodGet, path, query, result); err != nil { - return nil, err - } - return result, nil -} - -func (ia InvoiceApi) Get(ctx context.Context, invoiceId string) (*Invoice, error) { - path := ia.getPath("/invoices/" + invoiceId) - result := &Invoice{} - if err := doRequest(ctx, http.MethodGet, path, "", result); err != nil { - return nil, err - } - return result, nil -} diff --git a/invoice_test.go b/invoice_test.go deleted file mode 100644 index bba77b5..0000000 --- a/invoice_test.go +++ /dev/null @@ -1,561 +0,0 @@ -package leaseweb - -import ( - "context" - "fmt" - "net/http" - "testing" - - "github.com/stretchr/testify/assert" -) - -func TestInvoiceList(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{"_metadata":{"limit": 10, "offset": 0, "totalCount": 2}, "invoices": [ - { - "currency": "EUR", - "date": "2022-01-06T00:00:00+00:00", - "dueDate": "2022-02-30T00:00:00+00:00", - "id": "00000001", - "isPartialPaymentAllowed": true, - "openAmount": 1756.21, - "status": "OVERDUE", - "taxAmount": 0, - "total": 1756.21 - }, - { - "currency": "EUR", - "date": "2022-03-06T00:00:00+00:00", - "dueDate": "2022-04-30T00:00:00+00:00", - "id": "00000002", - "isPartialPaymentAllowed": true, - "openAmount": 34, - "status": "OPEN", - "taxAmount": 0, - "total": 34 - } - ]}`) - }) - defer teardown() - - invoiceApi := InvoiceApi{} - ctx := context.Background() - response, err := invoiceApi.List(ctx, PaginationOptions{}) - - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 2) - assert.Equal(response.Metadata.Offset, 0) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.Invoices), 2) - - invoices1 := response.Invoices[0] - assert.Equal(invoices1.Currency, "EUR") - assert.Equal(invoices1.Date, "2022-01-06T00:00:00+00:00") - assert.Equal(invoices1.DueDate, "2022-02-30T00:00:00+00:00") - assert.Equal(invoices1.IsPartialPaymentAllowed, true) - assert.Equal(invoices1.OpenAmount.String(), "1756.21") - assert.Equal(invoices1.Status, "OVERDUE") - assert.Equal(invoices1.TaxAmount.String(), "0") - assert.Equal(invoices1.Total.String(), "1756.21") - - invoices2 := response.Invoices[1] - assert.Equal(invoices2.Currency, "EUR") - assert.Equal(invoices2.Date, "2022-03-06T00:00:00+00:00") - assert.Equal(invoices2.DueDate, "2022-04-30T00:00:00+00:00") - assert.Equal(invoices2.Id, "00000002") - assert.Equal(invoices2.IsPartialPaymentAllowed, true) - assert.Equal(invoices2.OpenAmount.String(), "34") - assert.Equal(invoices2.Status, "OPEN") - assert.Equal(invoices2.TaxAmount.String(), "0") - assert.Equal(invoices2.Total.String(), "34") -} - -func TestInvoiceListBeEmpty(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{"_metadata":{"limit": 10, "offset": 0, "totalCount": 0}, "invoices": []}`) - }) - defer teardown() - - invoiceApi := InvoiceApi{} - ctx := context.Background() - response, err := invoiceApi.List(ctx, PaginationOptions{}) - - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 0) - assert.Equal(response.Metadata.Offset, 0) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.Invoices), 0) -} - -func TestInvoiceListPaginate(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{"_metadata":{"limit": 10, "offset": 1, "totalCount": 11}, "invoices": [{"id": "00000001"}]}`) - }) - defer teardown() - - invoiceApi := InvoiceApi{} - ctx := context.Background() - opts := PaginationOptions{ - Limit: Int(1), - } - response, err := invoiceApi.List(ctx, opts) - - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 11) - assert.Equal(response.Metadata.Offset, 1) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.Invoices), 1) -} - -func TestInvoiceListServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return InvoiceApi{}.List(ctx, PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "Access to the requested resource is forbidden."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return InvoiceApi{}.List(ctx, PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "Access to the requested resource is forbidden.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return InvoiceApi{}.List(ctx, PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return InvoiceApi{}.List(ctx, PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestInvoiceListProForma(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, - `{"_metadata":{"limit": 10, "offset": 0, "totalCount": 2}, - "contractItems": [ - { - "contractId": "50000103", - "currency": "EUR", - "endDate": "2022-01-01T00:00:00+00:00", - "equipmentId": "26430", - "poNumber": "40002154000110", - "price": 151.05, - "product": "DEDICATED SERVER", - "reference": "this is a reference 1", - "startDate": "2022-03-01T00:00:00+00:00" - }, - { - "contractId": "50000104", - "currency": "EUR", - "endDate": "2021-01-01T00:00:00+00:00", - "equipmentId": "26431", - "poNumber": "40002154000111", - "price": 150.05, - "product": "ATS", - "reference": "this is a reference 2", - "startDate": "2020-02-01T00:00:00+00:00" - } - ], - "currency": "EUR", - "proformaDate": "2021-07-01T00:00:00+00:00", - "subTotal": 300.04, - "total": 352.55, - "vatAmount": 52.51 - }`) - }) - defer teardown() - - invoiceApi := InvoiceApi{} - ctx := context.Background() - response, err := invoiceApi.ListProForma(ctx, PaginationOptions{}) - - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 2) - assert.Equal(response.Metadata.Offset, 0) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.Contracts), 2) - - assert.Equal(response.Currency, "EUR") - assert.Equal(response.ProformaDate, "2021-07-01T00:00:00+00:00") - assert.Equal(response.SubTotal.String(), "300.04") - assert.Equal(response.Total.String(), "352.55") - assert.Equal(response.VatAmount.String(), "52.51") - - contract1 := response.Contracts[0] - assert.Equal(contract1.Currency, "EUR") - assert.Equal(contract1.ContractId, "50000103") - assert.Equal(contract1.EndDate, "2022-01-01T00:00:00+00:00") - assert.Equal(contract1.EquipmentId, "26430") - assert.Equal(contract1.PoNumber, "40002154000110") - assert.Equal(contract1.Price.String(), "151.05") - assert.Equal(contract1.Product, "DEDICATED SERVER") - assert.Equal(contract1.Reference, "this is a reference 1") - assert.Equal(contract1.StartDate, "2022-03-01T00:00:00+00:00") - - contract2 := response.Contracts[1] - assert.Equal(contract2.Currency, "EUR") - assert.Equal(contract2.ContractId, "50000104") - assert.Equal(contract2.EndDate, "2021-01-01T00:00:00+00:00") - assert.Equal(contract2.EquipmentId, "26431") - assert.Equal(contract2.PoNumber, "40002154000111") - assert.Equal(contract2.Price.String(), "150.05") - assert.Equal(contract2.Product, "ATS") - assert.Equal(contract2.Reference, "this is a reference 2") - assert.Equal(contract2.StartDate, "2020-02-01T00:00:00+00:00") -} - -func TestInvoiceListProFormaPaginate(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, - `{"_metadata":{"limit": 10, "offset": 1, "totalCount": 11}, - "contractItems": [ - { - "contractId": "50000103", - "currency": "EUR", - "endDate": "2022-01-01T00:00:00+00:00", - "equipmentId": "26430", - "poNumber": "40002154000110", - "price": 151.05, - "product": "DEDICATED SERVER", - "reference": "this is a reference 1", - "startDate": "2022-03-01T00:00:00+00:00" - } - ], - "currency": "EUR", - "proformaDate": "2021-07-01T00:00:00+00:00", - "subTotal": 300.04, - "total": 352.55, - "vatAmount": 52.51 - }`) - }) - defer teardown() - - invoiceApi := InvoiceApi{} - ctx := context.Background() - opts := PaginationOptions{ - Limit: Int(1), - } - response, err := invoiceApi.ListProForma(ctx, opts) - - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 11) - assert.Equal(response.Metadata.Offset, 1) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.Contracts), 1) - - assert.Equal(response.Currency, "EUR") - assert.Equal(response.ProformaDate, "2021-07-01T00:00:00+00:00") - assert.Equal(response.SubTotal.String(), "300.04") - assert.Equal(response.Total.String(), "352.55") - assert.Equal(response.VatAmount.String(), "52.51") - - contract1 := response.Contracts[0] - assert.Equal(contract1.Currency, "EUR") - assert.Equal(contract1.ContractId, "50000103") - assert.Equal(contract1.EndDate, "2022-01-01T00:00:00+00:00") - assert.Equal(contract1.EquipmentId, "26430") - assert.Equal(contract1.PoNumber, "40002154000110") - assert.Equal(contract1.Price.String(), "151.05") - assert.Equal(contract1.Product, "DEDICATED SERVER") - assert.Equal(contract1.Reference, "this is a reference 1") - assert.Equal(contract1.StartDate, "2022-03-01T00:00:00+00:00") -} - -func TestInvoiceListProFormaServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return InvoiceApi{}.ListProForma(ctx, PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "Access to the requested resource is forbidden."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return InvoiceApi{}.ListProForma(ctx, PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "Access to the requested resource is forbidden.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return InvoiceApi{}.ListProForma(ctx, PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return InvoiceApi{}.ListProForma(ctx, PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestInvoiceGet(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, ` - {"credits": [ - { - "date": "2019-05-06T00:00:00+00:00", - "id": "00001211", - "taxAmount": 1.5, - "total": 15 - } - ], - "currency": "EUR", - "date": "2022-07-01T00:00:00+00:00", - "dueDate": "2019-05-30T00:00:00+00:00", - "id": "00000001", - "isPartialPaymentAllowed": true, - "lineItems": [ - { - "contractId": "12345678", - "equipmentId": "1234", - "product": "Rackspace", - "quantity": 1, - "reference": "This is a reference", - "totalAmount": 151.5, - "unitAmount": 152.5 - } - ], - "openAmount": 1751.21, - "status": "OPEN", - "taxAmount": 0, - "total": 1756.21 - }`) - }) - defer teardown() - - invoiceApi := InvoiceApi{} - ctx := context.Background() - response, err := invoiceApi.Get(ctx, "00000001") - - assert := assert.New(t) - assert.Nil(err) - - assert.Equal(len(response.Credits), 1) - assert.Equal(len(response.Lines), 1) - - assert.Equal(response.Currency, "EUR") - assert.Equal(response.Date, "2022-07-01T00:00:00+00:00") - assert.Equal(response.DueDate, "2019-05-30T00:00:00+00:00") - assert.Equal(response.Id, "00000001") - assert.Equal(response.IsPartialPaymentAllowed, true) - assert.Equal(response.OpenAmount.String(), "1751.21") - assert.Equal(response.Status, "OPEN") - assert.Equal(response.TaxAmount.String(), "0") - assert.Equal(response.Total.String(), "1756.21") - - assert.Equal(response.Credits[0].Date, "2019-05-06T00:00:00+00:00") - assert.Equal(response.Credits[0].Id, "00001211") - assert.Equal(response.Credits[0].TaxAmount.String(), "1.5") - assert.Equal(response.Credits[0].Total.String(), "15") - - assert.Equal(response.Lines[0].ContractId, "12345678") - assert.Equal(response.Lines[0].EquipmentId, "1234") - assert.Equal(response.Lines[0].Product, "Rackspace") - assert.Equal(response.Lines[0].Quantity.String(), "1") - assert.Equal(response.Lines[0].Reference, "This is a reference") - assert.Equal(response.Lines[0].TotalAmount.String(), "151.5") - assert.Equal(response.Lines[0].UnitAmount.String(), "152.5") -} - -func TestInvoiceGetServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return InvoiceApi{}.Get(ctx, "000000001") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "Access to the requested resource is forbidden."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return InvoiceApi{}.Get(ctx, "000000001") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "Access to the requested resource is forbidden.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The API could not handle your request at this time."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return InvoiceApi{}.Get(ctx, "000000001") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The API could not handle your request at this time.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The API is not available at the moment."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return InvoiceApi{}.Get(ctx, "000000001") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The API is not available at the moment.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} diff --git a/ip_management.go b/ip_management.go deleted file mode 100644 index dd698df..0000000 --- a/ip_management.go +++ /dev/null @@ -1,111 +0,0 @@ -package leaseweb - -import ( - "context" - "fmt" - "net/http" - "net/url" -) - -const IP_MANAGEMENT_API_VERSION = "v2" - -type IpManagementApi struct{} - -func (ima IpManagementApi) getPath(endpoint string) string { - return "/ipMgmt/" + IP_MANAGEMENT_API_VERSION + endpoint -} - -func (ima IpManagementApi) List(ctx context.Context, params ...map[string]interface{}) (*Ips, error) { - v := url.Values{} - if len(params) != 0 { - for key, value := range params[0] { - v.Add(key, fmt.Sprint(value)) - } - } - path := ima.getPath("/ips") - query := v.Encode() - result := &Ips{} - if err := doRequest(ctx, http.MethodGet, path, query, result); err != nil { - return nil, err - } - return result, nil -} - -func (ima IpManagementApi) Get(ctx context.Context, ip string) (*Ip, error) { - path := ima.getPath("/ips/" + ip) - result := &Ip{} - if err := doRequest(ctx, http.MethodGet, path, "", result); err != nil { - return nil, err - } - return result, nil -} - -func (ima IpManagementApi) Update(ctx context.Context, ip, reverseLookup string) (*Ip, error) { - payload := map[string]string{"reverseLookup": reverseLookup} - path := ima.getPath("/ips/" + ip) - result := &Ip{} - if err := doRequest(ctx, http.MethodPut, path, "", result, payload); err != nil { - return nil, err - } - return result, nil -} - -func (ima IpManagementApi) NullRouteAnIp(ctx context.Context, ip string, params ...map[string]string) (*NullRoute, error) { - payload := make(map[string]string) - if len(params) != 0 { - for key, value := range params[0] { - payload[key] = value - } - } - path := ima.getPath("/ips/" + ip + "/nullRoute") - result := &NullRoute{} - if err := doRequest(ctx, http.MethodPost, path, "", result, payload); err != nil { - return nil, err - } - return result, nil -} - -func (ima IpManagementApi) RemoveNullRouteAnIp(ctx context.Context, ip string) error { - path := ima.getPath("/ips/" + ip + "/nullRoute") - return doRequest(ctx, http.MethodDelete, path, "") -} - -func (ima IpManagementApi) ListNullRoutes(ctx context.Context, params ...map[string]interface{}) (*NullRoutes, error) { - v := url.Values{} - if len(params) != 0 { - for key, value := range params[0] { - v.Add(key, fmt.Sprint(value)) - } - } - path := ima.getPath("/nullRoutes") - query := v.Encode() - result := &NullRoutes{} - if err := doRequest(ctx, http.MethodGet, path, query, result); err != nil { - return nil, err - } - return result, nil -} - -func (ima IpManagementApi) GetNullRoute(ctx context.Context, id string) (*NullRoute, error) { - path := ima.getPath("/nullRoutes/" + id) - result := &NullRoute{} - if err := doRequest(ctx, http.MethodGet, path, "", result); err != nil { - return nil, err - } - return result, nil -} - -func (ima IpManagementApi) UpdateNullRoute(ctx context.Context, id string, params ...map[string]string) (*NullRoute, error) { - payload := make(map[string]string) - if len(params) != 0 { - for key, value := range params[0] { - payload[key] = value - } - } - path := ima.getPath("/nullRoutes/" + id) - result := &NullRoute{} - if err := doRequest(ctx, http.MethodPut, path, "", result, payload); err != nil { - return nil, err - } - return result, nil -} diff --git a/ip_management_test.go b/ip_management_test.go deleted file mode 100644 index 56bdfe8..0000000 --- a/ip_management_test.go +++ /dev/null @@ -1,1229 +0,0 @@ -package leaseweb - -import ( - "context" - "fmt" - "net/http" - "testing" - - "github.com/stretchr/testify/assert" -) - -func TestIpManagementListIps(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "ips": [ - { - "ip": "192.0.2.1", - "version": 4, - "type": "NORMAL_IP", - "prefixLength": 32, - "primary": true, - "reverseLookup": "mydomain1.example.com", - "nullRouted": false, - "unnullingAllowed": false, - "equipmentId": "1234", - "assignedContract": { - "id": "5643634" - }, - "subnet": { - "id": "192.0.2.0_24", - "networkIp": "192.0.2.0", - "prefixLength": 24, - "gateway": "192.0.2.254" - } - }, - { - "ip": "192.0.2.2", - "version": 4, - "type": "NORMAL_IP", - "prefixLength": 32, - "primary": false, - "reverseLookup": "mydomain2.example.com", - "nullRouted": false, - "unnullingAllowed": false, - "equipmentId": "1235", - "assignedContract": { - "id": "4363465" - }, - "subnet": { - "id": "192.0.2.0_24", - "networkIp": "192.0.2.0", - "prefixLength": 24, - "gateway": "192.0.2.254" - } - } - ], - "_metadata": { - "totalCount": 2, - "offset": 0, - "limit": 10 - } - }`) - }) - defer teardown() - - ctx := context.Background() - response, err := IpManagementApi{}.List(ctx) - - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 2) - assert.Equal(response.Metadata.Offset, 0) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.Ips), 2) - - Ip1 := response.Ips[0] - assert.Equal(Ip1.Ip, "192.0.2.1") - assert.Equal(Ip1.Version.String(), "4") - assert.Equal(Ip1.Type, "NORMAL_IP") - assert.Equal(Ip1.PrefixLength.String(), "32") - assert.Equal(Ip1.Primary, true) - assert.Equal(Ip1.ReverseLookup, "mydomain1.example.com") - assert.Equal(Ip1.NullRouted, false) - assert.Equal(Ip1.UnnullingAllowed, false) - assert.Equal(Ip1.EquipmentId, "1234") - assert.Equal(Ip1.Subnet.Gateway, "192.0.2.254") - assert.Equal(Ip1.Subnet.Id, "192.0.2.0_24") - assert.Equal(Ip1.Subnet.NetworkIp, "192.0.2.0") - assert.Equal(Ip1.Subnet.PrefixLength.String(), "24") - assert.Equal(Ip1.AssignedContract.Id, "5643634") - - Ip2 := response.Ips[1] - assert.Equal(Ip2.Ip, "192.0.2.2") - assert.Equal(Ip2.Version.String(), "4") - assert.Equal(Ip2.Type, "NORMAL_IP") - assert.Equal(Ip2.PrefixLength.String(), "32") - assert.Equal(Ip2.Primary, false) - assert.Equal(Ip2.ReverseLookup, "mydomain2.example.com") - assert.Equal(Ip2.NullRouted, false) - assert.Equal(Ip2.UnnullingAllowed, false) - assert.Equal(Ip2.EquipmentId, "1235") - assert.Equal(Ip2.Subnet.Gateway, "192.0.2.254") - assert.Equal(Ip2.Subnet.Id, "192.0.2.0_24") - assert.Equal(Ip2.Subnet.NetworkIp, "192.0.2.0") - assert.Equal(Ip2.Subnet.PrefixLength.String(), "24") - assert.Equal(Ip2.AssignedContract.Id, "4363465") -} - -func TestIpManagementListIpsPaginate(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "ips": [ - { - "ip": "192.0.2.1", - "version": 4, - "type": "NORMAL_IP", - "prefixLength": 32, - "primary": true, - "reverseLookup": "mydomain1.example.com", - "nullRouted": false, - "unnullingAllowed": false, - "equipmentId": "1234", - "assignedContract": { - "id": "5643634" - }, - "subnet": { - "id": "192.0.2.0_24", - "networkIp": "192.0.2.0", - "prefixLength": 24, - "gateway": "192.0.2.254" - } - } - ], - "_metadata": { - "totalCount": 11, - "offset": 1, - "limit": 10 - } - }`) - }) - defer teardown() - - ctx := context.Background() - response, err := IpManagementApi{}.List(ctx, map[string]interface{}{"offset": 1}) - - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 11) - assert.Equal(response.Metadata.Offset, 1) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.Ips), 1) - - Ip1 := response.Ips[0] - assert.Equal(Ip1.Ip, "192.0.2.1") - assert.Equal(Ip1.Version.String(), "4") - assert.Equal(Ip1.Type, "NORMAL_IP") - assert.Equal(Ip1.PrefixLength.String(), "32") - assert.Equal(Ip1.Primary, true) - assert.Equal(Ip1.ReverseLookup, "mydomain1.example.com") - assert.Equal(Ip1.NullRouted, false) - assert.Equal(Ip1.UnnullingAllowed, false) - assert.Equal(Ip1.EquipmentId, "1234") - assert.Equal(Ip1.Subnet.Gateway, "192.0.2.254") - assert.Equal(Ip1.Subnet.Id, "192.0.2.0_24") - assert.Equal(Ip1.Subnet.NetworkIp, "192.0.2.0") - assert.Equal(Ip1.Subnet.PrefixLength.String(), "24") - assert.Equal(Ip1.AssignedContract.Id, "5643634") -} - -func TestIpManagementListIpsServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return IpManagementApi{}.List(ctx, map[string]interface{}{"offset": 1}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "ACCESS_DENIED", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return IpManagementApi{}.List(ctx, map[string]interface{}{"offset": 1}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "ACCESS_DENIED", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "SERVER_ERROR", "errorMessage": "The server encountered an unexpected condition that prevented it from fulfilling the request."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return IpManagementApi{}.List(ctx, map[string]interface{}{"offset": 1}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "SERVER_ERROR", - Message: "The server encountered an unexpected condition that prevented it from fulfilling the request.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "TEMPORARILY_UNAVAILABLE", "errorMessage": "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return IpManagementApi{}.List(ctx, map[string]interface{}{"offset": 1}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "TEMPORARILY_UNAVAILABLE", - Message: "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestIpManagementGetIps(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "ip": "192.0.2.1", - "version": 4, - "type": "NORMAL_IP", - "prefixLength": 32, - "primary": true, - "reverseLookup": "mydomain1.example.com", - "nullRouted": false, - "unnullingAllowed": false, - "equipmentId": "1234", - "assignedContract": { - "id": "5643634" - }, - "subnet": { - "id": "192.0.2.0_24", - "networkIp": "192.0.2.0", - "prefixLength": 24, - "gateway": "192.0.2.254" - } - }`) - }) - defer teardown() - - ctx := context.Background() - Ip, err := IpManagementApi{}.Get(ctx, "192.0.2.1") - - assert := assert.New(t) - assert.Nil(err) - assert.Equal(Ip.Ip, "192.0.2.1") - assert.Equal(Ip.Version.String(), "4") - assert.Equal(Ip.Type, "NORMAL_IP") - assert.Equal(Ip.PrefixLength.String(), "32") - assert.Equal(Ip.Primary, true) - assert.Equal(Ip.ReverseLookup, "mydomain1.example.com") - assert.Equal(Ip.NullRouted, false) - assert.Equal(Ip.UnnullingAllowed, false) - assert.Equal(Ip.EquipmentId, "1234") - assert.Equal(Ip.Subnet.Gateway, "192.0.2.254") - assert.Equal(Ip.Subnet.Id, "192.0.2.0_24") - assert.Equal(Ip.Subnet.NetworkIp, "192.0.2.0") - assert.Equal(Ip.Subnet.PrefixLength.String(), "24") - assert.Equal(Ip.AssignedContract.Id, "5643634") -} - -func TestIpManagementGetIpsServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return IpManagementApi{}.Get(ctx, "192.0.2.1") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "ACCESS_DENIED", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return IpManagementApi{}.Get(ctx, "192.0.2.1") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "ACCESS_DENIED", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "SERVER_ERROR", "errorMessage": "The server encountered an unexpected condition that prevented it from fulfilling the request."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return IpManagementApi{}.Get(ctx, "192.0.2.1") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "SERVER_ERROR", - Message: "The server encountered an unexpected condition that prevented it from fulfilling the request.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "TEMPORARILY_UNAVAILABLE", "errorMessage": "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return IpManagementApi{}.Get(ctx, "192.0.2.1") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "TEMPORARILY_UNAVAILABLE", - Message: "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestIpManagementUpdate(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "ip": "192.0.2.1", - "version": 4, - "type": "NORMAL_IP", - "prefixLength": 32, - "primary": true, - "reverseLookup": "mydomain1.example.com", - "nullRouted": false, - "unnullingAllowed": false, - "equipmentId": "1234", - "assignedContract": { - "id": "5643634" - }, - "subnet": { - "id": "192.0.2.0_24", - "networkIp": "192.0.2.0", - "prefixLength": 24, - "gateway": "192.0.2.254" - } - }`) - }) - defer teardown() - - ctx := context.Background() - Ip, err := IpManagementApi{}.Update(ctx, "192.0.2.1", "mydomain1.example.com") - - assert := assert.New(t) - assert.Nil(err) - assert.Equal(Ip.Ip, "192.0.2.1") - assert.Equal(Ip.Version.String(), "4") - assert.Equal(Ip.Type, "NORMAL_IP") - assert.Equal(Ip.PrefixLength.String(), "32") - assert.Equal(Ip.Primary, true) - assert.Equal(Ip.ReverseLookup, "mydomain1.example.com") - assert.Equal(Ip.NullRouted, false) - assert.Equal(Ip.UnnullingAllowed, false) - assert.Equal(Ip.EquipmentId, "1234") - assert.Equal(Ip.Subnet.Gateway, "192.0.2.254") - assert.Equal(Ip.Subnet.Id, "192.0.2.0_24") - assert.Equal(Ip.Subnet.NetworkIp, "192.0.2.0") - assert.Equal(Ip.Subnet.PrefixLength.String(), "24") - assert.Equal(Ip.AssignedContract.Id, "5643634") -} - -func TestIpManagementUpdateServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return IpManagementApi{}.Update(ctx, "192.0.2.1", "mydomain1.example.com") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "ACCESS_DENIED", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return IpManagementApi{}.Update(ctx, "192.0.2.1", "mydomain1.example.com") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "ACCESS_DENIED", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "SERVER_ERROR", "errorMessage": "The server encountered an unexpected condition that prevented it from fulfilling the request."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return IpManagementApi{}.Update(ctx, "192.0.2.1", "mydomain1.example.com") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "SERVER_ERROR", - Message: "The server encountered an unexpected condition that prevented it from fulfilling the request.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "TEMPORARILY_UNAVAILABLE", "errorMessage": "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return IpManagementApi{}.Update(ctx, "192.0.2.1", "mydomain1.example.com") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "TEMPORARILY_UNAVAILABLE", - Message: "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestIpManagementNullRouteAnIp(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "id": "4534536", - "ip": "192.0.2.1", - "nulledAt": "2015-06-28T12:00:00Z", - "nulledBy": "john.doe@example.com", - "nullLevel": 1, - "automatedUnnullingAt": "2015-06-25T11:13:00Z", - "unnulledAt": null, - "unnulledBy": null, - "ticketId": "188612", - "comment": "This IP is evil", - "equipmentId": "456", - "assignedContract": { - "id": "123456" - } - }`) - }) - defer teardown() - - payload := map[string]string{ - "automatedUnnullingAt": "2015-06-25T11:13:00Z", - "ticketId": "188612", - "comment": "This IP is evil", - } - ctx := context.Background() - NullRoute, err := IpManagementApi{}.NullRouteAnIp(ctx, "192.0.2.1", payload) - - assert := assert.New(t) - assert.Nil(err) - assert.Equal(NullRoute.Id, "4534536") - assert.Equal(NullRoute.AssignedContract.Id, "123456") - assert.Equal(NullRoute.AutomatedUnnullingAt, "2015-06-25T11:13:00Z") - assert.Equal(NullRoute.Comment, "This IP is evil") - assert.Equal(NullRoute.EquipmentId, "456") - assert.Equal(NullRoute.Ip, "192.0.2.1") - assert.Equal(NullRoute.NullLevel.String(), "1") - assert.Equal(NullRoute.NulledAt, "2015-06-28T12:00:00Z") - assert.Equal(NullRoute.NulledBy, "john.doe@example.com") - assert.Equal(NullRoute.TicketId, "188612") - assert.Empty(NullRoute.UnnulledAt) - assert.Empty(NullRoute.UnnulledBy) -} - -func TestIpManagementNullRouteAnIpServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - payload := map[string]string{ - "automatedUnnullingAt": "2015-06-25T11:13:00Z", - "ticketId": "188612", - "comment": "This IP is evil", - } - ctx := context.Background() - return IpManagementApi{}.NullRouteAnIp(ctx, "192.0.2.1", payload) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "ACCESS_DENIED", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - payload := map[string]string{ - "automatedUnnullingAt": "2015-06-25T11:13:00Z", - "ticketId": "188612", - "comment": "This IP is evil", - } - ctx := context.Background() - return IpManagementApi{}.NullRouteAnIp(ctx, "192.0.2.1", payload) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "ACCESS_DENIED", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "SERVER_ERROR", "errorMessage": "The server encountered an unexpected condition that prevented it from fulfilling the request."}`) - }, - FunctionCall: func() (interface{}, error) { - payload := map[string]string{ - "automatedUnnullingAt": "2015-06-25T11:13:00Z", - "ticketId": "188612", - "comment": "This IP is evil", - } - ctx := context.Background() - return IpManagementApi{}.NullRouteAnIp(ctx, "192.0.2.1", payload) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "SERVER_ERROR", - Message: "The server encountered an unexpected condition that prevented it from fulfilling the request.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "TEMPORARILY_UNAVAILABLE", "errorMessage": "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."}`) - }, - FunctionCall: func() (interface{}, error) { - payload := map[string]string{ - "automatedUnnullingAt": "2015-06-25T11:13:00Z", - "ticketId": "188612", - "comment": "This IP is evil", - } - ctx := context.Background() - return IpManagementApi{}.NullRouteAnIp(ctx, "192.0.2.1", payload) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "TEMPORARILY_UNAVAILABLE", - Message: "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestIpManagementRemoveNullRouteAnIp(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusNoContent) - }) - defer teardown() - - ctx := context.Background() - err := IpManagementApi{}.RemoveNullRouteAnIp(ctx, "192.0.2.1") - - assert := assert.New(t) - assert.Nil(err) -} - -func TestIpManagementRemoveNullRouteAnIpServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, IpManagementApi{}.RemoveNullRouteAnIp(ctx, "192.0.2.1") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "ACCESS_DENIED", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, IpManagementApi{}.RemoveNullRouteAnIp(ctx, "192.0.2.1") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "ACCESS_DENIED", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "SERVER_ERROR", "errorMessage": "The server encountered an unexpected condition that prevented it from fulfilling the request."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, IpManagementApi{}.RemoveNullRouteAnIp(ctx, "192.0.2.1") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "SERVER_ERROR", - Message: "The server encountered an unexpected condition that prevented it from fulfilling the request.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "TEMPORARILY_UNAVAILABLE", "errorMessage": "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, IpManagementApi{}.RemoveNullRouteAnIp(ctx, "192.0.2.1") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "TEMPORARILY_UNAVAILABLE", - Message: "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestIpManagementListNullRoutes(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "nullroutes": [ - { - "id": "4534536", - "ip": "192.0.2.1", - "nulledAt": "2015-06-28T12:00:00Z", - "nulledBy": "john.doe@example.com", - "nullLevel": 1, - "automatedUnnullingAt": "2015-06-28T13:00:00Z", - "unnulledAt": null, - "unnulledBy": null, - "ticketId": "188612", - "comment": "This IP is evil", - "equipmentid": "456", - "assignedContract": { - "id": "123456" - } - }, - { - "id": "4534535", - "ip": "192.0.2.1", - "nulledAt": "2015-06-27T12:00:00Z", - "nulledBy": "john.doe@example.com", - "nullLevel": 1, - "automatedUnnullingAt": "2015-06-27T13:00:00Z", - "unnulledAt": "2015-06-27T13:00:05Z", - "unnulledBy": "UnnullRunner", - "ticketId": "188612", - "comment": "This IP is evil", - "equipmentId": "456", - "assignedContract": { - "id": "123456" - } - } - ], - "_metadata": { - "totalCount": 2, - "offset": 0, - "limit": 10 - } - }`) - }) - defer teardown() - - ctx := context.Background() - response, err := IpManagementApi{}.ListNullRoutes(ctx) - - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 2) - assert.Equal(response.Metadata.Offset, 0) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.NullRoutes), 2) - - NullRoute1 := response.NullRoutes[0] - assert.Equal(NullRoute1.Id, "4534536") - assert.Equal(NullRoute1.AssignedContract.Id, "123456") - assert.Equal(NullRoute1.AutomatedUnnullingAt, "2015-06-28T13:00:00Z") - assert.Equal(NullRoute1.Comment, "This IP is evil") - assert.Equal(NullRoute1.EquipmentId, "456") - assert.Equal(NullRoute1.Ip, "192.0.2.1") - assert.Equal(NullRoute1.NullLevel.String(), "1") - assert.Equal(NullRoute1.NulledAt, "2015-06-28T12:00:00Z") - assert.Equal(NullRoute1.NulledBy, "john.doe@example.com") - assert.Equal(NullRoute1.TicketId, "188612") - assert.Empty(NullRoute1.UnnulledAt) - assert.Empty(NullRoute1.UnnulledBy) - NullRoute2 := response.NullRoutes[1] - - assert.Equal(NullRoute2.Id, "4534535") - assert.Equal(NullRoute2.AssignedContract.Id, "123456") - assert.Equal(NullRoute2.AutomatedUnnullingAt, "2015-06-27T13:00:00Z") - assert.Equal(NullRoute2.Comment, "This IP is evil") - assert.Equal(NullRoute2.EquipmentId, "456") - assert.Equal(NullRoute2.Ip, "192.0.2.1") - assert.Equal(NullRoute2.NullLevel.String(), "1") - assert.Equal(NullRoute2.NulledAt, "2015-06-27T12:00:00Z") - assert.Equal(NullRoute2.NulledBy, "john.doe@example.com") - assert.Equal(NullRoute2.TicketId, "188612") - assert.Equal(NullRoute2.UnnulledAt, "2015-06-27T13:00:05Z") - assert.Equal(NullRoute2.UnnulledBy, "UnnullRunner") -} - -func TestIpManagementListNullRoutesPaginate(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "nullroutes": [ - { - "id": "4534536", - "ip": "192.0.2.1", - "nulledAt": "2015-06-28T12:00:00Z", - "nulledBy": "john.doe@example.com", - "nullLevel": 1, - "automatedUnnullingAt": "2015-06-28T13:00:00Z", - "unnulledAt": null, - "unnulledBy": null, - "ticketId": "188612", - "comment": "This IP is evil", - "equipmentid": "456", - "assignedContract": { - "id": "123456" - } - } - ], - "_metadata": { - "totalCount": 11, - "offset": 1, - "limit": 10 - } - }`) - }) - defer teardown() - - ctx := context.Background() - response, err := IpManagementApi{}.ListNullRoutes(ctx, map[string]interface{}{"offset": 1}) - - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 11) - assert.Equal(response.Metadata.Offset, 1) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.NullRoutes), 1) - - NullRoute1 := response.NullRoutes[0] - assert.Equal(NullRoute1.Id, "4534536") - assert.Equal(NullRoute1.AssignedContract.Id, "123456") - assert.Equal(NullRoute1.AutomatedUnnullingAt, "2015-06-28T13:00:00Z") - assert.Equal(NullRoute1.Comment, "This IP is evil") - assert.Equal(NullRoute1.EquipmentId, "456") - assert.Equal(NullRoute1.Ip, "192.0.2.1") - assert.Equal(NullRoute1.NullLevel.String(), "1") - assert.Equal(NullRoute1.NulledAt, "2015-06-28T12:00:00Z") - assert.Equal(NullRoute1.NulledBy, "john.doe@example.com") - assert.Equal(NullRoute1.TicketId, "188612") - assert.Empty(NullRoute1.UnnulledAt) - assert.Empty(NullRoute1.UnnulledBy) -} - -func TestIpManagementListNullRoutesServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return IpManagementApi{}.ListNullRoutes(ctx, map[string]interface{}{"offset": 1}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "ACCESS_DENIED", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return IpManagementApi{}.ListNullRoutes(ctx, map[string]interface{}{"offset": 1}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "ACCESS_DENIED", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "SERVER_ERROR", "errorMessage": "The server encountered an unexpected condition that prevented it from fulfilling the request."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return IpManagementApi{}.ListNullRoutes(ctx, map[string]interface{}{"offset": 1}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "SERVER_ERROR", - Message: "The server encountered an unexpected condition that prevented it from fulfilling the request.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "TEMPORARILY_UNAVAILABLE", "errorMessage": "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return IpManagementApi{}.ListNullRoutes(ctx, map[string]interface{}{"offset": 1}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "TEMPORARILY_UNAVAILABLE", - Message: "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestIpManagementGetNullRoute(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "id": "4534536", - "ip": "192.0.2.1", - "nulledAt": "2015-06-28T12:00:00Z", - "nulledBy": "john.doe@example.com", - "nullLevel": 1, - "automatedUnnullingAt": "2015-06-28T13:00:00Z", - "unnulledAt": null, - "unnulledBy": null, - "ticketId": "188612", - "comment": "This IP is evil", - "equipmentid": "456", - "assignedContract": { - "id": "123456" - } - }`) - }) - defer teardown() - - ctx := context.Background() - NullRoute, err := IpManagementApi{}.GetNullRoute(ctx, "123456") - - assert := assert.New(t) - assert.Nil(err) - - assert.Equal(NullRoute.Id, "4534536") - assert.Equal(NullRoute.AssignedContract.Id, "123456") - assert.Equal(NullRoute.AutomatedUnnullingAt, "2015-06-28T13:00:00Z") - assert.Equal(NullRoute.Comment, "This IP is evil") - assert.Equal(NullRoute.EquipmentId, "456") - assert.Equal(NullRoute.Ip, "192.0.2.1") - assert.Equal(NullRoute.NullLevel.String(), "1") - assert.Equal(NullRoute.NulledAt, "2015-06-28T12:00:00Z") - assert.Equal(NullRoute.NulledBy, "john.doe@example.com") - assert.Equal(NullRoute.TicketId, "188612") - assert.Empty(NullRoute.UnnulledAt) - assert.Empty(NullRoute.UnnulledBy) -} - -func TestIpManagementGetNullRouteServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return IpManagementApi{}.GetNullRoute(ctx, "123456") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "ACCESS_DENIED", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return IpManagementApi{}.GetNullRoute(ctx, "123456") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "ACCESS_DENIED", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "SERVER_ERROR", "errorMessage": "The server encountered an unexpected condition that prevented it from fulfilling the request."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return IpManagementApi{}.GetNullRoute(ctx, "123456") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "SERVER_ERROR", - Message: "The server encountered an unexpected condition that prevented it from fulfilling the request.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "TEMPORARILY_UNAVAILABLE", "errorMessage": "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return IpManagementApi{}.GetNullRoute(ctx, "123456") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "TEMPORARILY_UNAVAILABLE", - Message: "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestIpManagementUpdateNullRouteHistory(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "id": "4534536", - "ip": "192.0.2.1", - "nulledAt": "2015-06-28T12:00:00Z", - "nulledBy": "john.doe@example.com", - "nullLevel": 1, - "automatedUnnullingAt": "2015-06-28T13:00:00Z", - "unnulledAt": null, - "unnulledBy": null, - "ticketId": "188612", - "comment": "This IP is evil", - "equipmentid": "456", - "assignedContract": { - "id": "123456" - } - }`) - }) - defer teardown() - - payload := map[string]string{ - "automatedUnnullingAt": "2015-06-25T11:13:00Z", - "ticketId": "188612", - "comment": "This IP is evil", - } - ctx := context.Background() - NullRoute, err := IpManagementApi{}.UpdateNullRoute(ctx, "123456", payload) - - assert := assert.New(t) - assert.Nil(err) - - assert.Equal(NullRoute.Id, "4534536") - assert.Equal(NullRoute.AssignedContract.Id, "123456") - assert.Equal(NullRoute.AutomatedUnnullingAt, "2015-06-28T13:00:00Z") - assert.Equal(NullRoute.Comment, "This IP is evil") - assert.Equal(NullRoute.EquipmentId, "456") - assert.Equal(NullRoute.Ip, "192.0.2.1") - assert.Equal(NullRoute.NullLevel.String(), "1") - assert.Equal(NullRoute.NulledAt, "2015-06-28T12:00:00Z") - assert.Equal(NullRoute.NulledBy, "john.doe@example.com") - assert.Equal(NullRoute.TicketId, "188612") - assert.Empty(NullRoute.UnnulledAt) - assert.Empty(NullRoute.UnnulledBy) -} - -func TestIpManagementUpdateNullRouteHistoryServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - payload := map[string]string{ - "automatedUnnullingAt": "2015-06-25T11:13:00Z", - "ticketId": "188612", - "comment": "This IP is evil", - } - ctx := context.Background() - return IpManagementApi{}.UpdateNullRoute(ctx, "123456", payload) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "ACCESS_DENIED", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - payload := map[string]string{ - "automatedUnnullingAt": "2015-06-25T11:13:00Z", - "ticketId": "188612", - "comment": "This IP is evil", - } - ctx := context.Background() - return IpManagementApi{}.UpdateNullRoute(ctx, "123456", payload) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "ACCESS_DENIED", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "SERVER_ERROR", "errorMessage": "The server encountered an unexpected condition that prevented it from fulfilling the request."}`) - }, - FunctionCall: func() (interface{}, error) { - payload := map[string]string{ - "automatedUnnullingAt": "2015-06-25T11:13:00Z", - "ticketId": "188612", - "comment": "This IP is evil", - } - ctx := context.Background() - return IpManagementApi{}.UpdateNullRoute(ctx, "123456", payload) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "SERVER_ERROR", - Message: "The server encountered an unexpected condition that prevented it from fulfilling the request.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "TEMPORARILY_UNAVAILABLE", "errorMessage": "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."}`) - }, - FunctionCall: func() (interface{}, error) { - payload := map[string]string{ - "automatedUnnullingAt": "2015-06-25T11:13:00Z", - "ticketId": "188612", - "comment": "This IP is evil", - } - ctx := context.Background() - return IpManagementApi{}.UpdateNullRoute(ctx, "123456", payload) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "TEMPORARILY_UNAVAILABLE", - Message: "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} diff --git a/nse/README.md b/nse/README.md new file mode 100644 index 0000000..8b9c218 --- /dev/null +++ b/nse/README.md @@ -0,0 +1,189 @@ +# Go API client for nse + +This documents the rest api nse api provides. + +## Overview +This API client was generated by the [OpenAPI Generator](https://openapi-generator.tech) project. By using the [OpenAPI-spec](https://www.openapis.org/) from a remote server, you can easily generate an API client. + +- API version: v2 +- Package version: 1.0.0 +- Generator version: 7.4.0 +- Build package: org.openapitools.codegen.languages.GoClientCodegen + +## Installation + +Install the following dependencies: + +```sh +go get github.com/stretchr/testify/assert +go get golang.org/x/oauth2 +go get golang.org/x/net/context +``` + +Put the package under your project folder and add the following in import: + +```go +import nse "github.com/leaseweb/leaseweb-go-sdk/nse" +``` + +To use a proxy, set the environment variable `HTTP_PROXY`: + +```go +os.Setenv("HTTP_PROXY", "http://proxy_name:proxy_port") +``` + +## Configuration of Server URL + +Default configuration comes with `Servers` field that contains server objects as defined in the OpenAPI specification. + +### Select Server Configuration + +For using other server than the one defined on index 0 set context value `nse.ContextServerIndex` of type `int`. + +```go +ctx := context.WithValue(context.Background(), nse.ContextServerIndex, 1) +``` + +### Templated Server URL + +Templated server URL is formatted using default variables from configuration or from context value `nse.ContextServerVariables` of type `map[string]string`. + +```go +ctx := context.WithValue(context.Background(), nse.ContextServerVariables, map[string]string{ + "basePath": "v2", +}) +``` + +Note, enum values are always validated and all unused variables are silently ignored. + +### URLs Configuration per Operation + +Each operation can use different server URL defined using `OperationServers` map in the `Configuration`. +An operation is uniquely identified by `"{classname}Service.{nickname}"` string. +Similar rules for overriding default operation server index and variables applies by using `nse.ContextOperationServerIndices` and `nse.ContextOperationServerVariables` context maps. + +```go +ctx := context.WithValue(context.Background(), nse.ContextOperationServerIndices, map[string]int{ + "{classname}Service.{nickname}": 2, +}) +ctx = context.WithValue(context.Background(), nse.ContextOperationServerVariables, map[string]map[string]string{ + "{classname}Service.{nickname}": { + "port": "8443", + }, +}) +``` + +## Documentation for API Endpoints + +All URIs are relative to *https://api.leaseweb.com/internal/nseapi/v2* + +Class | Method | HTTP request | Description +------------ | ------------- | ------------- | ------------- +*NseAPI* | [**CloseNetworkInterface**](docs/NseAPI.md#closenetworkinterface) | **Post** /servers/{serverId}/networkInterfaces/{networkType}/close | Close network interface +*NseAPI* | [**CloseNetworkInterfaces**](docs/NseAPI.md#closenetworkinterfaces) | **Post** /servers/{serverId}/networkInterfaces/close | Close all network interfaces +*NseAPI* | [**GetDdosNotificationSettingList**](docs/NseAPI.md#getddosnotificationsettinglist) | **Get** /servers/{serverId}/notificationSettings/ddos | Inspect DDoS notification settings +*NseAPI* | [**GetNetworkInterface**](docs/NseAPI.md#getnetworkinterface) | **Get** /servers/{serverId}/networkInterfaces/{networkType} | Show a network interface +*NseAPI* | [**GetNetworkInterfaceList**](docs/NseAPI.md#getnetworkinterfacelist) | **Get** /servers/{serverId}/networkInterfaces | List network interfaces +*NseAPI* | [**OpenNetworkInterface**](docs/NseAPI.md#opennetworkinterface) | **Post** /servers/{serverId}/networkInterfaces/{networkType}/open | Open network interface +*NseAPI* | [**OpenNetworkInterfaces**](docs/NseAPI.md#opennetworkinterfaces) | **Post** /servers/{serverId}/networkInterfaces/open | Open all network interfaces +*NseAPI* | [**UpdateNullRoute**](docs/NseAPI.md#updatenullroute) | **Post** /actions/nullRoute | Announce/Withdraw Null Routes +*NseAPI* | [**UpdateServerDdosNotificationSetting**](docs/NseAPI.md#updateserverddosnotificationsetting) | **Put** /servers/{serverId}/notificationSettings/ddos | Update DDoS notification settings + + +## Documentation For Models + + - [ErrorResult](docs/ErrorResult.md) + - [GetDdosNotificationSettingResult](docs/GetDdosNotificationSettingResult.md) + - [GetNetworkInterfaceListResult](docs/GetNetworkInterfaceListResult.md) + - [Metadata](docs/Metadata.md) + - [NetworkInterface](docs/NetworkInterface.md) + - [UpdateDdosNotificationSettingOpts](docs/UpdateDdosNotificationSettingOpts.md) + - [UpdateNullRouteAcceptedResult](docs/UpdateNullRouteAcceptedResult.md) + - [UpdateNullRouteBadRequestResult](docs/UpdateNullRouteBadRequestResult.md) + - [UpdateNullRouteOpts](docs/UpdateNullRouteOpts.md) + + +## Documentation For Authorization + + +Authentication schemes defined for the API: +### ApiKeyAuth + +- **Type**: API key +- **API key parameter name**: X-LSW-Auth +- **Location**: HTTP header + +Note, each API key must be added to a map of `map[string]APIKey` where the key is: X-LSW-Auth and passed in as the auth context for each request. + +Example + +```go +auth := context.WithValue( + context.Background(), + nse.ContextAPIKeys, + map[string]nse.APIKey{ + "X-LSW-Auth": {Key: "API_KEY_STRING"}, + }, + ) +r, err := client.Service.Operation(auth, args) +``` + +### OAuth2 + + +- **Type**: OAuth +- **Flow**: application +- **Authorization URL**: +- **Scopes**: N/A + +Example + +```go +auth := context.WithValue(context.Background(), nse.ContextAccessToken, "ACCESSTOKENSTRING") +r, err := client.Service.Operation(auth, args) +``` + +Or via OAuth2 module to automatically refresh tokens and perform user authentication. + +```go +import "golang.org/x/oauth2" + +/* Perform OAuth2 round trip request and obtain a token */ + +tokenSource := oauth2cfg.TokenSource(createContext(httpClient), &token) +auth := context.WithValue(oauth2.NoContext, nse.ContextOAuth2, tokenSource) +r, err := client.Service.Operation(auth, args) +``` + +### BearerAuth + +- **Type**: HTTP Bearer token authentication + +Example + +```go +auth := context.WithValue(context.Background(), nse.ContextAccessToken, "BEARER_TOKEN_STRING") +r, err := client.Service.Operation(auth, args) +``` + + +## Documentation for Utility Methods + +Due to the fact that model structure members are all pointers, this package contains +a number of utility functions to easily obtain pointers to values of basic types. +Each of these functions takes a value of the given basic type and returns a pointer to it: + +* `PtrBool` +* `PtrInt` +* `PtrInt32` +* `PtrInt64` +* `PtrFloat` +* `PtrFloat32` +* `PtrFloat64` +* `PtrString` +* `PtrTime` + +## Author + +development-networkautomation@leaseweb.com + diff --git a/nse/api_nse.go b/nse/api_nse.go new file mode 100644 index 0000000..cf906bb --- /dev/null +++ b/nse/api_nse.go @@ -0,0 +1,1549 @@ +/* +nse + +This documents the rest api nse api provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package nse + +import ( + "bytes" + "context" + "io" + "net/http" + "net/url" + "strings" +) + + +// NseAPIService NseAPI service +type NseAPIService service + +type ApiCloseNetworkInterfaceRequest struct { + ctx context.Context + ApiService *NseAPIService + serverId string + networkType string +} + +func (r ApiCloseNetworkInterfaceRequest) Execute() (*http.Response, error) { + return r.ApiService.CloseNetworkInterfaceExecute(r) +} + +/* +CloseNetworkInterface Close network interface + +Close the network interface of this type of this server. + + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param serverId The ID of a server + @param networkType The network type + @return ApiCloseNetworkInterfaceRequest +*/ +func (a *NseAPIService) CloseNetworkInterface(ctx context.Context, serverId string, networkType string) ApiCloseNetworkInterfaceRequest { + return ApiCloseNetworkInterfaceRequest{ + ApiService: a, + ctx: ctx, + serverId: serverId, + networkType: networkType, + } +} + +// Execute executes the request +func (a *NseAPIService) CloseNetworkInterfaceExecute(r ApiCloseNetworkInterfaceRequest) (*http.Response, error) { + var ( + localVarHTTPMethod = http.MethodPost + localVarPostBody interface{} + formFiles []formFile + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "NseAPIService.CloseNetworkInterface") + if err != nil { + return nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/servers/{serverId}/networkInterfaces/{networkType}/close" + localVarPath = strings.Replace(localVarPath, "{"+"serverId"+"}", url.PathEscape(parameterValueToString(r.serverId, "serverId")), -1) + localVarPath = strings.Replace(localVarPath, "{"+"networkType"+"}", url.PathEscape(parameterValueToString(r.networkType, "networkType")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarHTTPResponse, newErr + } + + return localVarHTTPResponse, nil +} + +type ApiCloseNetworkInterfacesRequest struct { + ctx context.Context + ApiService *NseAPIService + serverId string +} + +func (r ApiCloseNetworkInterfacesRequest) Execute() (*http.Response, error) { + return r.ApiService.CloseNetworkInterfacesExecute(r) +} + +/* +CloseNetworkInterfaces Close all network interfaces + +Close all network interfaces for this server. + + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param serverId The ID of a server + @return ApiCloseNetworkInterfacesRequest +*/ +func (a *NseAPIService) CloseNetworkInterfaces(ctx context.Context, serverId string) ApiCloseNetworkInterfacesRequest { + return ApiCloseNetworkInterfacesRequest{ + ApiService: a, + ctx: ctx, + serverId: serverId, + } +} + +// Execute executes the request +func (a *NseAPIService) CloseNetworkInterfacesExecute(r ApiCloseNetworkInterfacesRequest) (*http.Response, error) { + var ( + localVarHTTPMethod = http.MethodPost + localVarPostBody interface{} + formFiles []formFile + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "NseAPIService.CloseNetworkInterfaces") + if err != nil { + return nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/servers/{serverId}/networkInterfaces/close" + localVarPath = strings.Replace(localVarPath, "{"+"serverId"+"}", url.PathEscape(parameterValueToString(r.serverId, "serverId")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarHTTPResponse, newErr + } + + return localVarHTTPResponse, nil +} + +type ApiGetDdosNotificationSettingListRequest struct { + ctx context.Context + ApiService *NseAPIService + serverId string +} + +func (r ApiGetDdosNotificationSettingListRequest) Execute() (*GetDdosNotificationSettingResult, *http.Response, error) { + return r.ApiService.GetDdosNotificationSettingListExecute(r) +} + +/* +GetDdosNotificationSettingList Inspect DDoS notification settings + +Show all DDoS Protection related notification settings for this server. These +settings control if you want to be notified via email in case a DDoS was +mitigated. + + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param serverId The ID of a server + @return ApiGetDdosNotificationSettingListRequest +*/ +func (a *NseAPIService) GetDdosNotificationSettingList(ctx context.Context, serverId string) ApiGetDdosNotificationSettingListRequest { + return ApiGetDdosNotificationSettingListRequest{ + ApiService: a, + ctx: ctx, + serverId: serverId, + } +} + +// Execute executes the request +// @return GetDdosNotificationSettingResult +func (a *NseAPIService) GetDdosNotificationSettingListExecute(r ApiGetDdosNotificationSettingListRequest) (*GetDdosNotificationSettingResult, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodGet + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *GetDdosNotificationSettingResult + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "NseAPIService.GetDdosNotificationSettingList") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/servers/{serverId}/notificationSettings/ddos" + localVarPath = strings.Replace(localVarPath, "{"+"serverId"+"}", url.PathEscape(parameterValueToString(r.serverId, "serverId")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiGetNetworkInterfaceRequest struct { + ctx context.Context + ApiService *NseAPIService + serverId string + networkType string +} + +func (r ApiGetNetworkInterfaceRequest) Execute() (*NetworkInterface, *http.Response, error) { + return r.ApiService.GetNetworkInterfaceExecute(r) +} + +/* +GetNetworkInterface Show a network interface + +Show the network interface of the given type of this server, including its +status. + + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param serverId The ID of a server + @param networkType The network type + @return ApiGetNetworkInterfaceRequest +*/ +func (a *NseAPIService) GetNetworkInterface(ctx context.Context, serverId string, networkType string) ApiGetNetworkInterfaceRequest { + return ApiGetNetworkInterfaceRequest{ + ApiService: a, + ctx: ctx, + serverId: serverId, + networkType: networkType, + } +} + +// Execute executes the request +// @return NetworkInterface +func (a *NseAPIService) GetNetworkInterfaceExecute(r ApiGetNetworkInterfaceRequest) (*NetworkInterface, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodGet + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *NetworkInterface + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "NseAPIService.GetNetworkInterface") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/servers/{serverId}/networkInterfaces/{networkType}" + localVarPath = strings.Replace(localVarPath, "{"+"serverId"+"}", url.PathEscape(parameterValueToString(r.serverId, "serverId")), -1) + localVarPath = strings.Replace(localVarPath, "{"+"networkType"+"}", url.PathEscape(parameterValueToString(r.networkType, "networkType")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiGetNetworkInterfaceListRequest struct { + ctx context.Context + ApiService *NseAPIService + serverId string +} + +func (r ApiGetNetworkInterfaceListRequest) Execute() (*GetNetworkInterfaceListResult, *http.Response, error) { + return r.ApiService.GetNetworkInterfaceListExecute(r) +} + +/* +GetNetworkInterfaceList List network interfaces + +List all network interfaces for this server, including their current status. + + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param serverId The ID of a server + @return ApiGetNetworkInterfaceListRequest +*/ +func (a *NseAPIService) GetNetworkInterfaceList(ctx context.Context, serverId string) ApiGetNetworkInterfaceListRequest { + return ApiGetNetworkInterfaceListRequest{ + ApiService: a, + ctx: ctx, + serverId: serverId, + } +} + +// Execute executes the request +// @return GetNetworkInterfaceListResult +func (a *NseAPIService) GetNetworkInterfaceListExecute(r ApiGetNetworkInterfaceListRequest) (*GetNetworkInterfaceListResult, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodGet + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *GetNetworkInterfaceListResult + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "NseAPIService.GetNetworkInterfaceList") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/servers/{serverId}/networkInterfaces" + localVarPath = strings.Replace(localVarPath, "{"+"serverId"+"}", url.PathEscape(parameterValueToString(r.serverId, "serverId")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiOpenNetworkInterfaceRequest struct { + ctx context.Context + ApiService *NseAPIService + serverId string + networkType string +} + +func (r ApiOpenNetworkInterfaceRequest) Execute() (*http.Response, error) { + return r.ApiService.OpenNetworkInterfaceExecute(r) +} + +/* +OpenNetworkInterface Open network interface + +Open all network interfaces of the given type for this server. + + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param serverId The ID of a server + @param networkType The network type + @return ApiOpenNetworkInterfaceRequest +*/ +func (a *NseAPIService) OpenNetworkInterface(ctx context.Context, serverId string, networkType string) ApiOpenNetworkInterfaceRequest { + return ApiOpenNetworkInterfaceRequest{ + ApiService: a, + ctx: ctx, + serverId: serverId, + networkType: networkType, + } +} + +// Execute executes the request +func (a *NseAPIService) OpenNetworkInterfaceExecute(r ApiOpenNetworkInterfaceRequest) (*http.Response, error) { + var ( + localVarHTTPMethod = http.MethodPost + localVarPostBody interface{} + formFiles []formFile + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "NseAPIService.OpenNetworkInterface") + if err != nil { + return nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/servers/{serverId}/networkInterfaces/{networkType}/open" + localVarPath = strings.Replace(localVarPath, "{"+"serverId"+"}", url.PathEscape(parameterValueToString(r.serverId, "serverId")), -1) + localVarPath = strings.Replace(localVarPath, "{"+"networkType"+"}", url.PathEscape(parameterValueToString(r.networkType, "networkType")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarHTTPResponse, newErr + } + + return localVarHTTPResponse, nil +} + +type ApiOpenNetworkInterfacesRequest struct { + ctx context.Context + ApiService *NseAPIService + serverId string +} + +func (r ApiOpenNetworkInterfacesRequest) Execute() (*http.Response, error) { + return r.ApiService.OpenNetworkInterfacesExecute(r) +} + +/* +OpenNetworkInterfaces Open all network interfaces + +Open all network interfaces of this server. + + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param serverId The ID of a server + @return ApiOpenNetworkInterfacesRequest +*/ +func (a *NseAPIService) OpenNetworkInterfaces(ctx context.Context, serverId string) ApiOpenNetworkInterfacesRequest { + return ApiOpenNetworkInterfacesRequest{ + ApiService: a, + ctx: ctx, + serverId: serverId, + } +} + +// Execute executes the request +func (a *NseAPIService) OpenNetworkInterfacesExecute(r ApiOpenNetworkInterfacesRequest) (*http.Response, error) { + var ( + localVarHTTPMethod = http.MethodPost + localVarPostBody interface{} + formFiles []formFile + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "NseAPIService.OpenNetworkInterfaces") + if err != nil { + return nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/servers/{serverId}/networkInterfaces/open" + localVarPath = strings.Replace(localVarPath, "{"+"serverId"+"}", url.PathEscape(parameterValueToString(r.serverId, "serverId")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarHTTPResponse, newErr + } + + return localVarHTTPResponse, nil +} + +type ApiUpdateNullRouteRequest struct { + ctx context.Context + ApiService *NseAPIService + updateNullRouteOpts *UpdateNullRouteOpts +} + +func (r ApiUpdateNullRouteRequest) UpdateNullRouteOpts(updateNullRouteOpts UpdateNullRouteOpts) ApiUpdateNullRouteRequest { + r.updateNullRouteOpts = &updateNullRouteOpts + return r +} + +func (r ApiUpdateNullRouteRequest) Execute() (*UpdateNullRouteAcceptedResult, *http.Response, error) { + return r.ApiService.UpdateNullRouteExecute(r) +} + +/* +UpdateNullRoute Announce/Withdraw Null Routes + +This API call is intented to be used _only_ by IPAM to announce or withdraw +null routes. + +Clients needing to `null` or `unnull` IP Addresses should always use the IPAM +API for this. + + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @return ApiUpdateNullRouteRequest +*/ +func (a *NseAPIService) UpdateNullRoute(ctx context.Context) ApiUpdateNullRouteRequest { + return ApiUpdateNullRouteRequest{ + ApiService: a, + ctx: ctx, + } +} + +// Execute executes the request +// @return UpdateNullRouteAcceptedResult +func (a *NseAPIService) UpdateNullRouteExecute(r ApiUpdateNullRouteRequest) (*UpdateNullRouteAcceptedResult, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodPost + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *UpdateNullRouteAcceptedResult + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "NseAPIService.UpdateNullRoute") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/actions/nullRoute" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{"application/json"} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + // body params + localVarPostBody = r.updateNullRouteOpts + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v UpdateNullRouteBadRequestResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiUpdateServerDdosNotificationSettingRequest struct { + ctx context.Context + ApiService *NseAPIService + serverId string + updateDdosNotificationSettingOpts *UpdateDdosNotificationSettingOpts +} + +func (r ApiUpdateServerDdosNotificationSettingRequest) UpdateDdosNotificationSettingOpts(updateDdosNotificationSettingOpts UpdateDdosNotificationSettingOpts) ApiUpdateServerDdosNotificationSettingRequest { + r.updateDdosNotificationSettingOpts = &updateDdosNotificationSettingOpts + return r +} + +func (r ApiUpdateServerDdosNotificationSettingRequest) Execute() (*http.Response, error) { + return r.ApiService.UpdateServerDdosNotificationSettingExecute(r) +} + +/* +UpdateServerDdosNotificationSetting Update DDoS notification settings + +Update your DDoS notification settings for this server. + + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param serverId The ID of a server + @return ApiUpdateServerDdosNotificationSettingRequest +*/ +func (a *NseAPIService) UpdateServerDdosNotificationSetting(ctx context.Context, serverId string) ApiUpdateServerDdosNotificationSettingRequest { + return ApiUpdateServerDdosNotificationSettingRequest{ + ApiService: a, + ctx: ctx, + serverId: serverId, + } +} + +// Execute executes the request +func (a *NseAPIService) UpdateServerDdosNotificationSettingExecute(r ApiUpdateServerDdosNotificationSettingRequest) (*http.Response, error) { + var ( + localVarHTTPMethod = http.MethodPut + localVarPostBody interface{} + formFiles []formFile + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "NseAPIService.UpdateServerDdosNotificationSetting") + if err != nil { + return nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/servers/{serverId}/notificationSettings/ddos" + localVarPath = strings.Replace(localVarPath, "{"+"serverId"+"}", url.PathEscape(parameterValueToString(r.serverId, "serverId")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{"application/json"} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + // body params + localVarPostBody = r.updateDdosNotificationSettingOpts + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarHTTPResponse, newErr + } + + return localVarHTTPResponse, nil +} diff --git a/nse/client.go b/nse/client.go new file mode 100644 index 0000000..9f32ff0 --- /dev/null +++ b/nse/client.go @@ -0,0 +1,678 @@ +/* +nse + +This documents the rest api nse api provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package nse + +import ( + "bytes" + "context" + "encoding/json" + "encoding/xml" + "errors" + "fmt" + "io" + "log" + "mime/multipart" + "net/http" + "net/http/httputil" + "net/url" + "os" + "path/filepath" + "reflect" + "regexp" + "strconv" + "strings" + "time" + "unicode/utf8" + + "golang.org/x/oauth2" +) + +var ( + JsonCheck = regexp.MustCompile(`(?i:(?:application|text)/(?:[^;]+\+)?json)`) + XmlCheck = regexp.MustCompile(`(?i:(?:application|text)/(?:[^;]+\+)?xml)`) + queryParamSplit = regexp.MustCompile(`(^|&)([^&]+)`) + queryDescape = strings.NewReplacer( "%5B", "[", "%5D", "]" ) +) + +// APIClient manages communication with the nse API vv2 +// In most cases there should be only one, shared, APIClient. +type APIClient struct { + cfg *Configuration + common service // Reuse a single struct instead of allocating one for each service on the heap. + + // API Services + + NseAPI *NseAPIService +} + +type service struct { + client *APIClient +} + +// NewAPIClient creates a new API client. Requires a userAgent string describing your application. +// optionally a custom http.Client to allow for advanced features such as caching. +func NewAPIClient(cfg *Configuration) *APIClient { + if cfg.HTTPClient == nil { + cfg.HTTPClient = http.DefaultClient + } + + c := &APIClient{} + c.cfg = cfg + c.common.client = c + + // API Services + c.NseAPI = (*NseAPIService)(&c.common) + + return c +} + +func atoi(in string) (int, error) { + return strconv.Atoi(in) +} + +// selectHeaderContentType select a content type from the available list. +func selectHeaderContentType(contentTypes []string) string { + if len(contentTypes) == 0 { + return "" + } + if contains(contentTypes, "application/json") { + return "application/json" + } + return contentTypes[0] // use the first content type specified in 'consumes' +} + +// selectHeaderAccept join all accept types and return +func selectHeaderAccept(accepts []string) string { + if len(accepts) == 0 { + return "" + } + + if contains(accepts, "application/json") { + return "application/json" + } + + return strings.Join(accepts, ",") +} + +// contains is a case insensitive match, finding needle in a haystack +func contains(haystack []string, needle string) bool { + for _, a := range haystack { + if strings.EqualFold(a, needle) { + return true + } + } + return false +} + +// Verify optional parameters are of the correct type. +func typeCheckParameter(obj interface{}, expected string, name string) error { + // Make sure there is an object. + if obj == nil { + return nil + } + + // Check the type is as expected. + if reflect.TypeOf(obj).String() != expected { + return fmt.Errorf("expected %s to be of type %s but received %s", name, expected, reflect.TypeOf(obj).String()) + } + return nil +} + +func parameterValueToString( obj interface{}, key string ) string { + if reflect.TypeOf(obj).Kind() != reflect.Ptr { + return fmt.Sprintf("%v", obj) + } + var param,ok = obj.(MappedNullable) + if !ok { + return "" + } + dataMap,err := param.ToMap() + if err != nil { + return "" + } + return fmt.Sprintf("%v", dataMap[key]) +} + +// parameterAddToHeaderOrQuery adds the provided object to the request header or url query +// supporting deep object syntax +func parameterAddToHeaderOrQuery(headerOrQueryParams interface{}, keyPrefix string, obj interface{}, collectionType string) { + var v = reflect.ValueOf(obj) + var value = "" + if v == reflect.ValueOf(nil) { + value = "null" + } else { + switch v.Kind() { + case reflect.Invalid: + value = "invalid" + + case reflect.Struct: + if t,ok := obj.(MappedNullable); ok { + dataMap,err := t.ToMap() + if err != nil { + return + } + parameterAddToHeaderOrQuery(headerOrQueryParams, keyPrefix, dataMap, collectionType) + return + } + if t, ok := obj.(time.Time); ok { + parameterAddToHeaderOrQuery(headerOrQueryParams, keyPrefix, t.Format(time.RFC3339), collectionType) + return + } + value = v.Type().String() + " value" + case reflect.Slice: + var indValue = reflect.ValueOf(obj) + if indValue == reflect.ValueOf(nil) { + return + } + var lenIndValue = indValue.Len() + for i:=0;i 0 || (len(formFiles) > 0) { + if body != nil { + return nil, errors.New("Cannot specify postBody and multipart form at the same time.") + } + body = &bytes.Buffer{} + w := multipart.NewWriter(body) + + for k, v := range formParams { + for _, iv := range v { + if strings.HasPrefix(k, "@") { // file + err = addFile(w, k[1:], iv) + if err != nil { + return nil, err + } + } else { // form value + w.WriteField(k, iv) + } + } + } + for _, formFile := range formFiles { + if len(formFile.fileBytes) > 0 && formFile.fileName != "" { + w.Boundary() + part, err := w.CreateFormFile(formFile.formFileName, filepath.Base(formFile.fileName)) + if err != nil { + return nil, err + } + _, err = part.Write(formFile.fileBytes) + if err != nil { + return nil, err + } + } + } + + // Set the Boundary in the Content-Type + headerParams["Content-Type"] = w.FormDataContentType() + + // Set Content-Length + headerParams["Content-Length"] = fmt.Sprintf("%d", body.Len()) + w.Close() + } + + if strings.HasPrefix(headerParams["Content-Type"], "application/x-www-form-urlencoded") && len(formParams) > 0 { + if body != nil { + return nil, errors.New("Cannot specify postBody and x-www-form-urlencoded form at the same time.") + } + body = &bytes.Buffer{} + body.WriteString(formParams.Encode()) + // Set Content-Length + headerParams["Content-Length"] = fmt.Sprintf("%d", body.Len()) + } + + // Setup path and query parameters + url, err := url.Parse(path) + if err != nil { + return nil, err + } + + // Override request host, if applicable + if c.cfg.Host != "" { + url.Host = c.cfg.Host + } + + // Override request scheme, if applicable + if c.cfg.Scheme != "" { + url.Scheme = c.cfg.Scheme + } + + // Adding Query Param + query := url.Query() + for k, v := range queryParams { + for _, iv := range v { + query.Add(k, iv) + } + } + + // Encode the parameters. + url.RawQuery = queryParamSplit.ReplaceAllStringFunc(query.Encode(), func(s string) string { + pieces := strings.Split(s, "=") + pieces[0] = queryDescape.Replace(pieces[0]) + return strings.Join(pieces, "=") + }) + + // Generate a new request + if body != nil { + localVarRequest, err = http.NewRequest(method, url.String(), body) + } else { + localVarRequest, err = http.NewRequest(method, url.String(), nil) + } + if err != nil { + return nil, err + } + + // add header parameters, if any + if len(headerParams) > 0 { + headers := http.Header{} + for h, v := range headerParams { + headers[h] = []string{v} + } + localVarRequest.Header = headers + } + + // Add the user agent to the request. + localVarRequest.Header.Add("User-Agent", c.cfg.UserAgent) + + if ctx != nil { + // add context to the request + localVarRequest = localVarRequest.WithContext(ctx) + + // Walk through any authentication. + + // OAuth2 authentication + if tok, ok := ctx.Value(ContextOAuth2).(oauth2.TokenSource); ok { + // We were able to grab an oauth2 token from the context + var latestToken *oauth2.Token + if latestToken, err = tok.Token(); err != nil { + return nil, err + } + + latestToken.SetAuthHeader(localVarRequest) + } + + // AccessToken Authentication + if auth, ok := ctx.Value(ContextAccessToken).(string); ok { + localVarRequest.Header.Add("Authorization", "Bearer "+auth) + } + + } + + for header, value := range c.cfg.DefaultHeader { + localVarRequest.Header.Add(header, value) + } + return localVarRequest, nil +} + +func (c *APIClient) decode(v interface{}, b []byte, contentType string) (err error) { + if len(b) == 0 { + return nil + } + if s, ok := v.(*string); ok { + *s = string(b) + return nil + } + if f, ok := v.(*os.File); ok { + f, err = os.CreateTemp("", "HttpClientFile") + if err != nil { + return + } + _, err = f.Write(b) + if err != nil { + return + } + _, err = f.Seek(0, io.SeekStart) + return + } + if f, ok := v.(**os.File); ok { + *f, err = os.CreateTemp("", "HttpClientFile") + if err != nil { + return + } + _, err = (*f).Write(b) + if err != nil { + return + } + _, err = (*f).Seek(0, io.SeekStart) + return + } + if XmlCheck.MatchString(contentType) { + if err = xml.Unmarshal(b, v); err != nil { + return err + } + return nil + } + if JsonCheck.MatchString(contentType) { + if actualObj, ok := v.(interface{ GetActualInstance() interface{} }); ok { // oneOf, anyOf schemas + if unmarshalObj, ok := actualObj.(interface{ UnmarshalJSON([]byte) error }); ok { // make sure it has UnmarshalJSON defined + if err = unmarshalObj.UnmarshalJSON(b); err != nil { + return err + } + } else { + return errors.New("Unknown type with GetActualInstance but no unmarshalObj.UnmarshalJSON defined") + } + } else if err = json.Unmarshal(b, v); err != nil { // simple model + return err + } + return nil + } + return errors.New("undefined response type") +} + +// Add a file to the multipart request +func addFile(w *multipart.Writer, fieldName, path string) error { + file, err := os.Open(filepath.Clean(path)) + if err != nil { + return err + } + err = file.Close() + if err != nil { + return err + } + + part, err := w.CreateFormFile(fieldName, filepath.Base(path)) + if err != nil { + return err + } + _, err = io.Copy(part, file) + + return err +} + +// Prevent trying to import "fmt" +func reportError(format string, a ...interface{}) error { + return fmt.Errorf(format, a...) +} + +// A wrapper for strict JSON decoding +func newStrictDecoder(data []byte) *json.Decoder { + dec := json.NewDecoder(bytes.NewBuffer(data)) + dec.DisallowUnknownFields() + return dec +} + +// Set request body from an interface{} +func setBody(body interface{}, contentType string) (bodyBuf *bytes.Buffer, err error) { + if bodyBuf == nil { + bodyBuf = &bytes.Buffer{} + } + + if reader, ok := body.(io.Reader); ok { + _, err = bodyBuf.ReadFrom(reader) + } else if fp, ok := body.(*os.File); ok { + _, err = bodyBuf.ReadFrom(fp) + } else if b, ok := body.([]byte); ok { + _, err = bodyBuf.Write(b) + } else if s, ok := body.(string); ok { + _, err = bodyBuf.WriteString(s) + } else if s, ok := body.(*string); ok { + _, err = bodyBuf.WriteString(*s) + } else if JsonCheck.MatchString(contentType) { + err = json.NewEncoder(bodyBuf).Encode(body) + } else if XmlCheck.MatchString(contentType) { + var bs []byte + bs, err = xml.Marshal(body) + if err == nil { + bodyBuf.Write(bs) + } + } + + if err != nil { + return nil, err + } + + if bodyBuf.Len() == 0 { + err = fmt.Errorf("invalid body type %s\n", contentType) + return nil, err + } + return bodyBuf, nil +} + +// detectContentType method is used to figure out `Request.Body` content type for request header +func detectContentType(body interface{}) string { + contentType := "text/plain; charset=utf-8" + kind := reflect.TypeOf(body).Kind() + + switch kind { + case reflect.Struct, reflect.Map, reflect.Ptr: + contentType = "application/json; charset=utf-8" + case reflect.String: + contentType = "text/plain; charset=utf-8" + default: + if b, ok := body.([]byte); ok { + contentType = http.DetectContentType(b) + } else if kind == reflect.Slice { + contentType = "application/json; charset=utf-8" + } + } + + return contentType +} + +// Ripped from https://github.com/gregjones/httpcache/blob/master/httpcache.go +type cacheControl map[string]string + +func parseCacheControl(headers http.Header) cacheControl { + cc := cacheControl{} + ccHeader := headers.Get("Cache-Control") + for _, part := range strings.Split(ccHeader, ",") { + part = strings.Trim(part, " ") + if part == "" { + continue + } + if strings.ContainsRune(part, '=') { + keyval := strings.Split(part, "=") + cc[strings.Trim(keyval[0], " ")] = strings.Trim(keyval[1], ",") + } else { + cc[part] = "" + } + } + return cc +} + +// CacheExpires helper function to determine remaining time before repeating a request. +func CacheExpires(r *http.Response) time.Time { + // Figure out when the cache expires. + var expires time.Time + now, err := time.Parse(time.RFC1123, r.Header.Get("date")) + if err != nil { + return time.Now() + } + respCacheControl := parseCacheControl(r.Header) + + if maxAge, ok := respCacheControl["max-age"]; ok { + lifetime, err := time.ParseDuration(maxAge + "s") + if err != nil { + expires = now + } else { + expires = now.Add(lifetime) + } + } else { + expiresHeader := r.Header.Get("Expires") + if expiresHeader != "" { + expires, err = time.Parse(time.RFC1123, expiresHeader) + if err != nil { + expires = now + } + } + } + return expires +} + +func strlen(s string) int { + return utf8.RuneCountInString(s) +} + +// GenericOpenAPIError Provides access to the body, error and model on returned errors. +type GenericOpenAPIError struct { + body []byte + error string + model interface{} +} + +// Error returns non-empty string if there was an error. +func (e GenericOpenAPIError) Error() string { + return e.error +} + +// Body returns the raw bytes of the response +func (e GenericOpenAPIError) Body() []byte { + return e.body +} + +// Model returns the unpacked model of the error +func (e GenericOpenAPIError) Model() interface{} { + return e.model +} + +// format error message using title and detail when model implements rfc7807 +func formatErrorMessage(status string, v interface{}) string { + str := "" + metaValue := reflect.ValueOf(v).Elem() + + if metaValue.Kind() == reflect.Struct { + field := metaValue.FieldByName("Title") + if field != (reflect.Value{}) { + str = fmt.Sprintf("%s", field.Interface()) + } + + field = metaValue.FieldByName("Detail") + if field != (reflect.Value{}) { + str = fmt.Sprintf("%s (%s)", str, field.Interface()) + } + } + + return strings.TrimSpace(fmt.Sprintf("%s %s", status, str)) +} diff --git a/nse/configuration.go b/nse/configuration.go new file mode 100644 index 0000000..6abc1f0 --- /dev/null +++ b/nse/configuration.go @@ -0,0 +1,225 @@ +/* +nse + +This documents the rest api nse api provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package nse + +import ( + "context" + "fmt" + "net/http" + "strings" +) + +// contextKeys are used to identify the type of value in the context. +// Since these are string, it is possible to get a short description of the +// context key for logging and debugging using key.String(). + +type contextKey string + +func (c contextKey) String() string { + return "auth " + string(c) +} + +var ( + // ContextOAuth2 takes an oauth2.TokenSource as authentication for the request. + ContextOAuth2 = contextKey("token") + + // ContextAccessToken takes a string oauth2 access token as authentication for the request. + ContextAccessToken = contextKey("accesstoken") + + // ContextAPIKeys takes a string apikey as authentication for the request + ContextAPIKeys = contextKey("apiKeys") + + // ContextServerIndex uses a server configuration from the index. + ContextServerIndex = contextKey("serverIndex") + + // ContextOperationServerIndices uses a server configuration from the index mapping. + ContextOperationServerIndices = contextKey("serverOperationIndices") + + // ContextServerVariables overrides a server configuration variables. + ContextServerVariables = contextKey("serverVariables") + + // ContextOperationServerVariables overrides a server configuration variables using operation specific values. + ContextOperationServerVariables = contextKey("serverOperationVariables") +) + +// BasicAuth provides basic http authentication to a request passed via context using ContextBasicAuth +type BasicAuth struct { + UserName string `json:"userName,omitempty"` + Password string `json:"password,omitempty"` +} + +// APIKey provides API key based authentication to a request passed via context using ContextAPIKey +type APIKey struct { + Key string + Prefix string +} + +// ServerVariable stores the information about a server variable +type ServerVariable struct { + Description string + DefaultValue string + EnumValues []string +} + +// ServerConfiguration stores the information about a server +type ServerConfiguration struct { + URL string + Description string + Variables map[string]ServerVariable +} + +// ServerConfigurations stores multiple ServerConfiguration items +type ServerConfigurations []ServerConfiguration + +// Configuration stores the configuration of the API client +type Configuration struct { + Host string `json:"host,omitempty"` + Scheme string `json:"scheme,omitempty"` + DefaultHeader map[string]string `json:"defaultHeader,omitempty"` + UserAgent string `json:"userAgent,omitempty"` + Debug bool `json:"debug,omitempty"` + Servers ServerConfigurations + OperationServers map[string]ServerConfigurations + HTTPClient *http.Client +} + +// NewConfiguration returns a new Configuration object +func NewConfiguration() *Configuration { + cfg := &Configuration{ + DefaultHeader: make(map[string]string), + UserAgent: "OpenAPI-Generator/1.0.0/go", + Debug: false, + Servers: ServerConfigurations{ + { + URL: "https://api.leaseweb.com/internal/nseapi/v2", + Description: "No description provided", + }, + }, + OperationServers: map[string]ServerConfigurations{ + }, + } + return cfg +} + +// AddDefaultHeader adds a new HTTP header to the default header in the request +func (c *Configuration) AddDefaultHeader(key string, value string) { + c.DefaultHeader[key] = value +} + +// URL formats template on a index using given variables +func (sc ServerConfigurations) URL(index int, variables map[string]string) (string, error) { + if index < 0 || len(sc) <= index { + return "", fmt.Errorf("index %v out of range %v", index, len(sc)-1) + } + server := sc[index] + url := server.URL + + // go through variables and replace placeholders + for name, variable := range server.Variables { + if value, ok := variables[name]; ok { + found := bool(len(variable.EnumValues) == 0) + for _, enumValue := range variable.EnumValues { + if value == enumValue { + found = true + } + } + if !found { + return "", fmt.Errorf("the variable %s in the server URL has invalid value %v. Must be %v", name, value, variable.EnumValues) + } + url = strings.Replace(url, "{"+name+"}", value, -1) + } else { + url = strings.Replace(url, "{"+name+"}", variable.DefaultValue, -1) + } + } + return url, nil +} + +// ServerURL returns URL based on server settings +func (c *Configuration) ServerURL(index int, variables map[string]string) (string, error) { + return c.Servers.URL(index, variables) +} + +func getServerIndex(ctx context.Context) (int, error) { + si := ctx.Value(ContextServerIndex) + if si != nil { + if index, ok := si.(int); ok { + return index, nil + } + return 0, reportError("Invalid type %T should be int", si) + } + return 0, nil +} + +func getServerOperationIndex(ctx context.Context, endpoint string) (int, error) { + osi := ctx.Value(ContextOperationServerIndices) + if osi != nil { + if operationIndices, ok := osi.(map[string]int); !ok { + return 0, reportError("Invalid type %T should be map[string]int", osi) + } else { + index, ok := operationIndices[endpoint] + if ok { + return index, nil + } + } + } + return getServerIndex(ctx) +} + +func getServerVariables(ctx context.Context) (map[string]string, error) { + sv := ctx.Value(ContextServerVariables) + if sv != nil { + if variables, ok := sv.(map[string]string); ok { + return variables, nil + } + return nil, reportError("ctx value of ContextServerVariables has invalid type %T should be map[string]string", sv) + } + return nil, nil +} + +func getServerOperationVariables(ctx context.Context, endpoint string) (map[string]string, error) { + osv := ctx.Value(ContextOperationServerVariables) + if osv != nil { + if operationVariables, ok := osv.(map[string]map[string]string); !ok { + return nil, reportError("ctx value of ContextOperationServerVariables has invalid type %T should be map[string]map[string]string", osv) + } else { + variables, ok := operationVariables[endpoint] + if ok { + return variables, nil + } + } + } + return getServerVariables(ctx) +} + +// ServerURLWithContext returns a new server URL given an endpoint +func (c *Configuration) ServerURLWithContext(ctx context.Context, endpoint string) (string, error) { + sc, ok := c.OperationServers[endpoint] + if !ok { + sc = c.Servers + } + + if ctx == nil { + return sc.URL(0, nil) + } + + index, err := getServerOperationIndex(ctx, endpoint) + if err != nil { + return "", err + } + + variables, err := getServerOperationVariables(ctx, endpoint) + if err != nil { + return "", err + } + + return sc.URL(index, variables) +} diff --git a/nse/go.mod b/nse/go.mod new file mode 100644 index 0000000..6c1208d --- /dev/null +++ b/nse/go.mod @@ -0,0 +1,7 @@ +module github.com/leaseweb/leaseweb-go-sdk/nse + +go 1.18 + +require ( + golang.org/x/oauth2 v0.0.0-20210323180902-22b0adad7558 +) diff --git a/nse/go.sum b/nse/go.sum new file mode 100644 index 0000000..3dee6d6 --- /dev/null +++ b/nse/go.sum @@ -0,0 +1,360 @@ +cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU= +cloud.google.com/go v0.44.1/go.mod h1:iSa0KzasP4Uvy3f1mN/7PiObzGgflwredwwASm/v6AU= +cloud.google.com/go v0.44.2/go.mod h1:60680Gw3Yr4ikxnPRS/oxxkBccT6SA1yMk63TGekxKY= +cloud.google.com/go v0.45.1/go.mod h1:RpBamKRgapWJb87xiFSdk4g1CME7QZg3uwTez+TSTjc= +cloud.google.com/go v0.46.3/go.mod h1:a6bKKbmY7er1mI7TEI4lsAkts/mkhTSZK8w33B4RAg0= +cloud.google.com/go v0.50.0/go.mod h1:r9sluTvynVuxRIOHXQEHMFffphuXHOMZMycpNR5e6To= +cloud.google.com/go v0.52.0/go.mod h1:pXajvRH/6o3+F9jDHZWQ5PbGhn+o8w9qiu/CffaVdO4= +cloud.google.com/go v0.53.0/go.mod h1:fp/UouUEsRkN6ryDKNW/Upv/JBKnv6WDthjR6+vze6M= +cloud.google.com/go v0.54.0/go.mod h1:1rq2OEkV3YMf6n/9ZvGWI3GWw0VoqH/1x2nd8Is/bPc= +cloud.google.com/go v0.56.0/go.mod h1:jr7tqZxxKOVYizybht9+26Z/gUq7tiRzu+ACVAMbKVk= +cloud.google.com/go v0.57.0/go.mod h1:oXiQ6Rzq3RAkkY7N6t3TcE6jE+CIBBbA36lwQ1JyzZs= +cloud.google.com/go v0.62.0/go.mod h1:jmCYTdRCQuc1PHIIJ/maLInMho30T/Y0M4hTdTShOYc= +cloud.google.com/go v0.65.0/go.mod h1:O5N8zS7uWy9vkA9vayVHs65eM1ubvY4h553ofrNHObY= +cloud.google.com/go/bigquery v1.0.1/go.mod h1:i/xbL2UlR5RvWAURpBYZTtm/cXjCha9lbfbpx4poX+o= +cloud.google.com/go/bigquery v1.3.0/go.mod h1:PjpwJnslEMmckchkHFfq+HTD2DmtT67aNFKH1/VBDHE= +cloud.google.com/go/bigquery v1.4.0/go.mod h1:S8dzgnTigyfTmLBfrtrhyYhwRxG72rYxvftPBK2Dvzc= +cloud.google.com/go/bigquery v1.5.0/go.mod h1:snEHRnqQbz117VIFhE8bmtwIDY80NLUZUMb4Nv6dBIg= +cloud.google.com/go/bigquery v1.7.0/go.mod h1://okPTzCYNXSlb24MZs83e2Do+h+VXtc4gLoIoXIAPc= +cloud.google.com/go/bigquery v1.8.0/go.mod h1:J5hqkt3O0uAFnINi6JXValWIb1v0goeZM77hZzJN/fQ= +cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7TKLgZqpHYE= +cloud.google.com/go/datastore v1.1.0/go.mod h1:umbIZjpQpHh4hmRpGhH4tLFup+FVzqBi1b3c64qFpCk= +cloud.google.com/go/pubsub v1.0.1/go.mod h1:R0Gpsv3s54REJCy4fxDixWD93lHJMoZTyQ2kNxGRt3I= +cloud.google.com/go/pubsub v1.1.0/go.mod h1:EwwdRX2sKPjnvnqCa270oGRyludottCI76h+R3AArQw= +cloud.google.com/go/pubsub v1.2.0/go.mod h1:jhfEVHT8odbXTkndysNHCcx0awwzvfOlguIAii9o8iA= +cloud.google.com/go/pubsub v1.3.1/go.mod h1:i+ucay31+CNRpDW4Lu78I4xXG+O1r/MAHgjpRVR+TSU= +cloud.google.com/go/storage v1.0.0/go.mod h1:IhtSnM/ZTZV8YYJWCY8RULGVqBDmpoyjwiyrjsg+URw= +cloud.google.com/go/storage v1.5.0/go.mod h1:tpKbwo567HUNpVclU5sGELwQWBDZ8gh0ZeosJ0Rtdos= +cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohlUTyfDhBk= +cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs= +cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0= +dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= +github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= +github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= +github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= +github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= +github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= +github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= +github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= +github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= +github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y= +github.com/golang/mock v1.4.0/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= +github.com/golang/mock v1.4.1/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= +github.com/golang/mock v1.4.3/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= +github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4= +github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= +github.com/golang/protobuf v1.3.4/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= +github.com/golang/protobuf v1.3.5/go.mod h1:6O5/vntMXwX2lRkT1hjjk0nAC1IDOTvTlVgjlRvqsdk= +github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= +github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= +github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= +github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= +github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= +github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= +github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= +github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= +github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= +github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.4.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= +github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0= +github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= +github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= +github.com/google/pprof v0.0.0-20191218002539-d4f498aebedc/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= +github.com/google/pprof v0.0.0-20200212024743-f11f1df84d12/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= +github.com/google/pprof v0.0.0-20200229191704-1ebb73c60ed3/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= +github.com/google/pprof v0.0.0-20200430221834-fc25d7d30c6d/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= +github.com/google/pprof v0.0.0-20200708004538-1a94d8640e99/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= +github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= +github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= +github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= +github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= +github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= +github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= +github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= +github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk= +github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= +go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= +go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= +go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= +go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= +golang.org/x/exp v0.0.0-20190829153037-c13cbed26979/go.mod h1:86+5VVa7VpoJ4kLfm080zCjGlMRFzhUhsZKEZO7MGek= +golang.org/x/exp v0.0.0-20191030013958-a1ab85dbe136/go.mod h1:JXzH8nQsPlswgeRAPE3MuO9GYsAcnJvJ4vnMwN/5qkY= +golang.org/x/exp v0.0.0-20191129062945-2f5052295587/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= +golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= +golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= +golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM= +golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU= +golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= +golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= +golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= +golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f/go.mod h1:5qLYkcX4OjUUV8bRuDixDT3tpyyb+LUpUlRWLxfhWrs= +golang.org/x/lint v0.0.0-20200130185559-910be7a94367/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= +golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= +golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= +golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o= +golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= +golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY= +golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= +golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= +golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e h1:bRhVy7zSSasaqNksaRZiA5EEI+Ei4I1nO5Jh72wfHlg= +golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190501004415-9ce7a6920f09/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20190628185345-da137c7871d7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200222125558-5a598a2470a0/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200501053045-e0ff5e5a1de5/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200506145744-7e3656a0809f/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200513185701-a91f0712d120/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200520182314-0ba52f642ac2/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= +golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= +golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= +golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= +golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45 h1:SVwTIAaPC2U/AvvLNZ2a7OVsmBpC8L5BlwK1whH3hm0= +golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/oauth2 v0.0.0-20191202225959-858c2ad4c8b6/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/oauth2 v0.0.0-20210323180902-22b0adad7558/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4 h1:YUO/7uOKsKeq9UokNS62b8FYywz3ker1l1vDZRCRefw= +golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200113162924-86b910548bc1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200122134326-e047566fdf82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200331124033-c3d80250170d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200501052902-10377860bb8e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200511232937-7e40ca221e25/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200515095857-1151b9dac4a9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200523222454-059865788121/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200803210538-64077c9b5642/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= +golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20190506145303-2d16b83fe98c/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191113191852-77e3bb0ad9e7/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191115202509-3a792d9c32b2/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191130070609-6e064ea0cf2d/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191216173652-a0e659d51361/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20191227053925-7b8e75db28f4/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200117161641-43d50277825c/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200122220014-bf1340f18c4a/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200204074204-1cc6d1ef6c74/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200207183749-b753a1ba74fa/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200212150539-ea181f53ac56/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200224181240-023911ca70b2/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200227222343-706bc42d1f0d/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200304193943-95d2e580d8eb/go.mod h1:o4KQGtdN14AW+yjsvvwRTJJuXz8XRtIHtEnmAXLyFUw= +golang.org/x/tools v0.0.0-20200312045724-11d5b4c81c7d/go.mod h1:o4KQGtdN14AW+yjsvvwRTJJuXz8XRtIHtEnmAXLyFUw= +golang.org/x/tools v0.0.0-20200331025713-a30bf2db82d4/go.mod h1:Sl4aGygMT6LrqrWclx+PTx3U+LnKx/seiNR+3G19Ar8= +golang.org/x/tools v0.0.0-20200501065659-ab2804fb9c9d/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20200512131952-2bc93b1c0c88/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20200515010526-7d3b6ebf133d/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20200618134242-20370b0cb4b2/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20200729194436-6467de6f59a7/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= +golang.org/x/tools v0.0.0-20200804011535-6c149bb5ef0d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= +golang.org/x/tools v0.0.0-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= +google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M= +google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= +google.golang.org/api v0.9.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= +google.golang.org/api v0.13.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= +google.golang.org/api v0.14.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= +google.golang.org/api v0.15.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= +google.golang.org/api v0.17.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= +google.golang.org/api v0.18.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= +google.golang.org/api v0.19.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= +google.golang.org/api v0.20.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= +google.golang.org/api v0.22.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= +google.golang.org/api v0.24.0/go.mod h1:lIXQywCXRcnZPGlsd8NbLnOjtAoL6em04bJ9+z0MncE= +google.golang.org/api v0.28.0/go.mod h1:lIXQywCXRcnZPGlsd8NbLnOjtAoL6em04bJ9+z0MncE= +google.golang.org/api v0.29.0/go.mod h1:Lcubydp8VUV7KeIHD9z2Bys/sm/vGKnG1UHuDBSrHWM= +google.golang.org/api v0.30.0/go.mod h1:QGmEvQ87FHZNiUVJkT14jQNYJ4ZJjdRF23ZXz5138Fc= +google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= +google.golang.org/appengine v1.4.0 h1:/wp5JvzpHIxhs/dumFmF7BXTf3Z+dd4uXta4kVyO508= +google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0= +google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= +google.golang.org/appengine v1.6.6/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= +google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= +google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190801165951-fa694d86fc64/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= +google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= +google.golang.org/genproto v0.0.0-20190911173649-1774047e7e51/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8= +google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20191115194625-c23dd37a84c9/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20191216164720-4f79533eabd1/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20191230161307-f3c370f40bfb/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20200115191322-ca5a22157cba/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20200122232147-0452cf42e150/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20200204135345-fa8e72b47b90/go.mod h1:GmwEX6Z4W5gMy59cAlVYjN9JhxgbQH6Gn+gFDQe2lzA= +google.golang.org/genproto v0.0.0-20200212174721-66ed5ce911ce/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200224152610-e50cd9704f63/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200228133532-8c2c7df3a383/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200305110556-506484158171/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200312145019-da6875a35672/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200331122359-1ee6d9798940/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200430143042-b979b6f78d84/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200511104702-f5ebc3bea380/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200515170657-fc4c6c6a6587/go.mod h1:YsZOwe1myG/8QRHRsmBRE1LrgQY60beZKjly0O1fX9U= +google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= +google.golang.org/genproto v0.0.0-20200618031413-b414f8b61790/go.mod h1:jDfRM7FcilCzHH/e9qn6dsT145K34l5v+OpcnNgKAAA= +google.golang.org/genproto v0.0.0-20200729003335-053ba62fc06f/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20200804131852-c06518451d9c/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20200825200019-8632dd797987/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= +google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= +google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= +google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= +google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= +google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= +google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= +google.golang.org/grpc v1.27.1/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= +google.golang.org/grpc v1.28.0/go.mod h1:rpkK4SK4GF4Ach/+MFLZUBavHOvF2JJB5uozKKal+60= +google.golang.org/grpc v1.29.1/go.mod h1:itym6AZVZYACWQqET3MqgPpjcuV5QH3BxFS3IjizoKk= +google.golang.org/grpc v1.30.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= +google.golang.org/grpc v1.31.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= +google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= +google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= +google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= +google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= +google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= +google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4= +google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= +honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= +honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= +rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= +rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0= +rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= diff --git a/nse/model__metadata.go b/nse/model__metadata.go new file mode 100644 index 0000000..9948f0a --- /dev/null +++ b/nse/model__metadata.go @@ -0,0 +1,210 @@ +/* +nse + +This documents the rest api nse api provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package nse + +import ( + "encoding/json" +) + +// checks if the Metadata type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &Metadata{} + +// Metadata Metadata about the collection +type Metadata struct { + // Total amount of orders in this collection + TotalCount *float32 `json:"totalCount,omitempty"` + // The offset used to generate this response + Offset *float32 `json:"offset,omitempty"` + // The limit used to generate this response + Limit *float32 `json:"limit,omitempty"` +} + +// NewMetadata instantiates a new Metadata object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewMetadata() *Metadata { + this := Metadata{} + var offset float32 = 0 + this.Offset = &offset + var limit float32 = 5 + this.Limit = &limit + return &this +} + +// NewMetadataWithDefaults instantiates a new Metadata object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewMetadataWithDefaults() *Metadata { + this := Metadata{} + var offset float32 = 0 + this.Offset = &offset + var limit float32 = 5 + this.Limit = &limit + return &this +} + +// GetTotalCount returns the TotalCount field value if set, zero value otherwise. +func (o *Metadata) GetTotalCount() float32 { + if o == nil || IsNil(o.TotalCount) { + var ret float32 + return ret + } + return *o.TotalCount +} + +// GetTotalCountOk returns a tuple with the TotalCount field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Metadata) GetTotalCountOk() (*float32, bool) { + if o == nil || IsNil(o.TotalCount) { + return nil, false + } + return o.TotalCount, true +} + +// HasTotalCount returns a boolean if a field has been set. +func (o *Metadata) HasTotalCount() bool { + if o != nil && !IsNil(o.TotalCount) { + return true + } + + return false +} + +// SetTotalCount gets a reference to the given float32 and assigns it to the TotalCount field. +func (o *Metadata) SetTotalCount(v float32) { + o.TotalCount = &v +} + +// GetOffset returns the Offset field value if set, zero value otherwise. +func (o *Metadata) GetOffset() float32 { + if o == nil || IsNil(o.Offset) { + var ret float32 + return ret + } + return *o.Offset +} + +// GetOffsetOk returns a tuple with the Offset field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Metadata) GetOffsetOk() (*float32, bool) { + if o == nil || IsNil(o.Offset) { + return nil, false + } + return o.Offset, true +} + +// HasOffset returns a boolean if a field has been set. +func (o *Metadata) HasOffset() bool { + if o != nil && !IsNil(o.Offset) { + return true + } + + return false +} + +// SetOffset gets a reference to the given float32 and assigns it to the Offset field. +func (o *Metadata) SetOffset(v float32) { + o.Offset = &v +} + +// GetLimit returns the Limit field value if set, zero value otherwise. +func (o *Metadata) GetLimit() float32 { + if o == nil || IsNil(o.Limit) { + var ret float32 + return ret + } + return *o.Limit +} + +// GetLimitOk returns a tuple with the Limit field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Metadata) GetLimitOk() (*float32, bool) { + if o == nil || IsNil(o.Limit) { + return nil, false + } + return o.Limit, true +} + +// HasLimit returns a boolean if a field has been set. +func (o *Metadata) HasLimit() bool { + if o != nil && !IsNil(o.Limit) { + return true + } + + return false +} + +// SetLimit gets a reference to the given float32 and assigns it to the Limit field. +func (o *Metadata) SetLimit(v float32) { + o.Limit = &v +} + +func (o Metadata) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o Metadata) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.TotalCount) { + toSerialize["totalCount"] = o.TotalCount + } + if !IsNil(o.Offset) { + toSerialize["offset"] = o.Offset + } + if !IsNil(o.Limit) { + toSerialize["limit"] = o.Limit + } + return toSerialize, nil +} + +type NullableMetadata struct { + value *Metadata + isSet bool +} + +func (v NullableMetadata) Get() *Metadata { + return v.value +} + +func (v *NullableMetadata) Set(val *Metadata) { + v.value = val + v.isSet = true +} + +func (v NullableMetadata) IsSet() bool { + return v.isSet +} + +func (v *NullableMetadata) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableMetadata(val *Metadata) *NullableMetadata { + return &NullableMetadata{value: val, isSet: true} +} + +func (v NullableMetadata) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableMetadata) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/nse/model_error_result.go b/nse/model_error_result.go new file mode 100644 index 0000000..99579d1 --- /dev/null +++ b/nse/model_error_result.go @@ -0,0 +1,238 @@ +/* +nse + +This documents the rest api nse api provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package nse + +import ( + "encoding/json" +) + +// checks if the ErrorResult type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &ErrorResult{} + +// ErrorResult struct for ErrorResult +type ErrorResult struct { + // The correlation ID of the current request. + CorrelationId *string `json:"correlationId,omitempty"` + // The error code. + ErrorCode *string `json:"errorCode,omitempty"` + // A human friendly description of the error. + ErrorMessage *string `json:"errorMessage,omitempty"` + ErrorDetails []map[string][]string `json:"errorDetails,omitempty"` +} + +// NewErrorResult instantiates a new ErrorResult object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewErrorResult() *ErrorResult { + this := ErrorResult{} + return &this +} + +// NewErrorResultWithDefaults instantiates a new ErrorResult object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewErrorResultWithDefaults() *ErrorResult { + this := ErrorResult{} + return &this +} + +// GetCorrelationId returns the CorrelationId field value if set, zero value otherwise. +func (o *ErrorResult) GetCorrelationId() string { + if o == nil || IsNil(o.CorrelationId) { + var ret string + return ret + } + return *o.CorrelationId +} + +// GetCorrelationIdOk returns a tuple with the CorrelationId field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ErrorResult) GetCorrelationIdOk() (*string, bool) { + if o == nil || IsNil(o.CorrelationId) { + return nil, false + } + return o.CorrelationId, true +} + +// HasCorrelationId returns a boolean if a field has been set. +func (o *ErrorResult) HasCorrelationId() bool { + if o != nil && !IsNil(o.CorrelationId) { + return true + } + + return false +} + +// SetCorrelationId gets a reference to the given string and assigns it to the CorrelationId field. +func (o *ErrorResult) SetCorrelationId(v string) { + o.CorrelationId = &v +} + +// GetErrorCode returns the ErrorCode field value if set, zero value otherwise. +func (o *ErrorResult) GetErrorCode() string { + if o == nil || IsNil(o.ErrorCode) { + var ret string + return ret + } + return *o.ErrorCode +} + +// GetErrorCodeOk returns a tuple with the ErrorCode field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ErrorResult) GetErrorCodeOk() (*string, bool) { + if o == nil || IsNil(o.ErrorCode) { + return nil, false + } + return o.ErrorCode, true +} + +// HasErrorCode returns a boolean if a field has been set. +func (o *ErrorResult) HasErrorCode() bool { + if o != nil && !IsNil(o.ErrorCode) { + return true + } + + return false +} + +// SetErrorCode gets a reference to the given string and assigns it to the ErrorCode field. +func (o *ErrorResult) SetErrorCode(v string) { + o.ErrorCode = &v +} + +// GetErrorMessage returns the ErrorMessage field value if set, zero value otherwise. +func (o *ErrorResult) GetErrorMessage() string { + if o == nil || IsNil(o.ErrorMessage) { + var ret string + return ret + } + return *o.ErrorMessage +} + +// GetErrorMessageOk returns a tuple with the ErrorMessage field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ErrorResult) GetErrorMessageOk() (*string, bool) { + if o == nil || IsNil(o.ErrorMessage) { + return nil, false + } + return o.ErrorMessage, true +} + +// HasErrorMessage returns a boolean if a field has been set. +func (o *ErrorResult) HasErrorMessage() bool { + if o != nil && !IsNil(o.ErrorMessage) { + return true + } + + return false +} + +// SetErrorMessage gets a reference to the given string and assigns it to the ErrorMessage field. +func (o *ErrorResult) SetErrorMessage(v string) { + o.ErrorMessage = &v +} + +// GetErrorDetails returns the ErrorDetails field value if set, zero value otherwise. +func (o *ErrorResult) GetErrorDetails() []map[string][]string { + if o == nil || IsNil(o.ErrorDetails) { + var ret []map[string][]string + return ret + } + return o.ErrorDetails +} + +// GetErrorDetailsOk returns a tuple with the ErrorDetails field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ErrorResult) GetErrorDetailsOk() ([]map[string][]string, bool) { + if o == nil || IsNil(o.ErrorDetails) { + return nil, false + } + return o.ErrorDetails, true +} + +// HasErrorDetails returns a boolean if a field has been set. +func (o *ErrorResult) HasErrorDetails() bool { + if o != nil && !IsNil(o.ErrorDetails) { + return true + } + + return false +} + +// SetErrorDetails gets a reference to the given []map[string][]string and assigns it to the ErrorDetails field. +func (o *ErrorResult) SetErrorDetails(v []map[string][]string) { + o.ErrorDetails = v +} + +func (o ErrorResult) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o ErrorResult) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.CorrelationId) { + toSerialize["correlationId"] = o.CorrelationId + } + if !IsNil(o.ErrorCode) { + toSerialize["errorCode"] = o.ErrorCode + } + if !IsNil(o.ErrorMessage) { + toSerialize["errorMessage"] = o.ErrorMessage + } + if !IsNil(o.ErrorDetails) { + toSerialize["errorDetails"] = o.ErrorDetails + } + return toSerialize, nil +} + +type NullableErrorResult struct { + value *ErrorResult + isSet bool +} + +func (v NullableErrorResult) Get() *ErrorResult { + return v.value +} + +func (v *NullableErrorResult) Set(val *ErrorResult) { + v.value = val + v.isSet = true +} + +func (v NullableErrorResult) IsSet() bool { + return v.isSet +} + +func (v *NullableErrorResult) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableErrorResult(val *ErrorResult) *NullableErrorResult { + return &NullableErrorResult{value: val, isSet: true} +} + +func (v NullableErrorResult) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableErrorResult) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/nse/model_get_ddos_notification_setting_result.go b/nse/model_get_ddos_notification_setting_result.go new file mode 100644 index 0000000..d631c13 --- /dev/null +++ b/nse/model_get_ddos_notification_setting_result.go @@ -0,0 +1,165 @@ +/* +nse + +This documents the rest api nse api provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package nse + +import ( + "encoding/json" +) + +// checks if the GetDdosNotificationSettingResult type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &GetDdosNotificationSettingResult{} + +// GetDdosNotificationSettingResult struct for GetDdosNotificationSettingResult +type GetDdosNotificationSettingResult struct { + // Email notifications for nulling events + Nulling *string `json:"nulling,omitempty"` + // Email notifications for scrubbing events + Scrubbing *string `json:"scrubbing,omitempty"` +} + +// NewGetDdosNotificationSettingResult instantiates a new GetDdosNotificationSettingResult object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewGetDdosNotificationSettingResult() *GetDdosNotificationSettingResult { + this := GetDdosNotificationSettingResult{} + return &this +} + +// NewGetDdosNotificationSettingResultWithDefaults instantiates a new GetDdosNotificationSettingResult object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewGetDdosNotificationSettingResultWithDefaults() *GetDdosNotificationSettingResult { + this := GetDdosNotificationSettingResult{} + return &this +} + +// GetNulling returns the Nulling field value if set, zero value otherwise. +func (o *GetDdosNotificationSettingResult) GetNulling() string { + if o == nil || IsNil(o.Nulling) { + var ret string + return ret + } + return *o.Nulling +} + +// GetNullingOk returns a tuple with the Nulling field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetDdosNotificationSettingResult) GetNullingOk() (*string, bool) { + if o == nil || IsNil(o.Nulling) { + return nil, false + } + return o.Nulling, true +} + +// HasNulling returns a boolean if a field has been set. +func (o *GetDdosNotificationSettingResult) HasNulling() bool { + if o != nil && !IsNil(o.Nulling) { + return true + } + + return false +} + +// SetNulling gets a reference to the given string and assigns it to the Nulling field. +func (o *GetDdosNotificationSettingResult) SetNulling(v string) { + o.Nulling = &v +} + +// GetScrubbing returns the Scrubbing field value if set, zero value otherwise. +func (o *GetDdosNotificationSettingResult) GetScrubbing() string { + if o == nil || IsNil(o.Scrubbing) { + var ret string + return ret + } + return *o.Scrubbing +} + +// GetScrubbingOk returns a tuple with the Scrubbing field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetDdosNotificationSettingResult) GetScrubbingOk() (*string, bool) { + if o == nil || IsNil(o.Scrubbing) { + return nil, false + } + return o.Scrubbing, true +} + +// HasScrubbing returns a boolean if a field has been set. +func (o *GetDdosNotificationSettingResult) HasScrubbing() bool { + if o != nil && !IsNil(o.Scrubbing) { + return true + } + + return false +} + +// SetScrubbing gets a reference to the given string and assigns it to the Scrubbing field. +func (o *GetDdosNotificationSettingResult) SetScrubbing(v string) { + o.Scrubbing = &v +} + +func (o GetDdosNotificationSettingResult) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o GetDdosNotificationSettingResult) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Nulling) { + toSerialize["nulling"] = o.Nulling + } + if !IsNil(o.Scrubbing) { + toSerialize["scrubbing"] = o.Scrubbing + } + return toSerialize, nil +} + +type NullableGetDdosNotificationSettingResult struct { + value *GetDdosNotificationSettingResult + isSet bool +} + +func (v NullableGetDdosNotificationSettingResult) Get() *GetDdosNotificationSettingResult { + return v.value +} + +func (v *NullableGetDdosNotificationSettingResult) Set(val *GetDdosNotificationSettingResult) { + v.value = val + v.isSet = true +} + +func (v NullableGetDdosNotificationSettingResult) IsSet() bool { + return v.isSet +} + +func (v *NullableGetDdosNotificationSettingResult) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableGetDdosNotificationSettingResult(val *GetDdosNotificationSettingResult) *NullableGetDdosNotificationSettingResult { + return &NullableGetDdosNotificationSettingResult{value: val, isSet: true} +} + +func (v NullableGetDdosNotificationSettingResult) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableGetDdosNotificationSettingResult) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/nse/model_get_network_interface_list_result.go b/nse/model_get_network_interface_list_result.go new file mode 100644 index 0000000..5acb4f2 --- /dev/null +++ b/nse/model_get_network_interface_list_result.go @@ -0,0 +1,164 @@ +/* +nse + +This documents the rest api nse api provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package nse + +import ( + "encoding/json" +) + +// checks if the GetNetworkInterfaceListResult type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &GetNetworkInterfaceListResult{} + +// GetNetworkInterfaceListResult struct for GetNetworkInterfaceListResult +type GetNetworkInterfaceListResult struct { + Metadata *Metadata `json:"_metadata,omitempty"` + // An array of network interfaces + NetworkInterfaces []NetworkInterface `json:"networkInterfaces,omitempty"` +} + +// NewGetNetworkInterfaceListResult instantiates a new GetNetworkInterfaceListResult object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewGetNetworkInterfaceListResult() *GetNetworkInterfaceListResult { + this := GetNetworkInterfaceListResult{} + return &this +} + +// NewGetNetworkInterfaceListResultWithDefaults instantiates a new GetNetworkInterfaceListResult object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewGetNetworkInterfaceListResultWithDefaults() *GetNetworkInterfaceListResult { + this := GetNetworkInterfaceListResult{} + return &this +} + +// GetMetadata returns the Metadata field value if set, zero value otherwise. +func (o *GetNetworkInterfaceListResult) GetMetadata() Metadata { + if o == nil || IsNil(o.Metadata) { + var ret Metadata + return ret + } + return *o.Metadata +} + +// GetMetadataOk returns a tuple with the Metadata field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetNetworkInterfaceListResult) GetMetadataOk() (*Metadata, bool) { + if o == nil || IsNil(o.Metadata) { + return nil, false + } + return o.Metadata, true +} + +// HasMetadata returns a boolean if a field has been set. +func (o *GetNetworkInterfaceListResult) HasMetadata() bool { + if o != nil && !IsNil(o.Metadata) { + return true + } + + return false +} + +// SetMetadata gets a reference to the given Metadata and assigns it to the Metadata field. +func (o *GetNetworkInterfaceListResult) SetMetadata(v Metadata) { + o.Metadata = &v +} + +// GetNetworkInterfaces returns the NetworkInterfaces field value if set, zero value otherwise. +func (o *GetNetworkInterfaceListResult) GetNetworkInterfaces() []NetworkInterface { + if o == nil || IsNil(o.NetworkInterfaces) { + var ret []NetworkInterface + return ret + } + return o.NetworkInterfaces +} + +// GetNetworkInterfacesOk returns a tuple with the NetworkInterfaces field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetNetworkInterfaceListResult) GetNetworkInterfacesOk() ([]NetworkInterface, bool) { + if o == nil || IsNil(o.NetworkInterfaces) { + return nil, false + } + return o.NetworkInterfaces, true +} + +// HasNetworkInterfaces returns a boolean if a field has been set. +func (o *GetNetworkInterfaceListResult) HasNetworkInterfaces() bool { + if o != nil && !IsNil(o.NetworkInterfaces) { + return true + } + + return false +} + +// SetNetworkInterfaces gets a reference to the given []NetworkInterface and assigns it to the NetworkInterfaces field. +func (o *GetNetworkInterfaceListResult) SetNetworkInterfaces(v []NetworkInterface) { + o.NetworkInterfaces = v +} + +func (o GetNetworkInterfaceListResult) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o GetNetworkInterfaceListResult) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Metadata) { + toSerialize["_metadata"] = o.Metadata + } + if !IsNil(o.NetworkInterfaces) { + toSerialize["networkInterfaces"] = o.NetworkInterfaces + } + return toSerialize, nil +} + +type NullableGetNetworkInterfaceListResult struct { + value *GetNetworkInterfaceListResult + isSet bool +} + +func (v NullableGetNetworkInterfaceListResult) Get() *GetNetworkInterfaceListResult { + return v.value +} + +func (v *NullableGetNetworkInterfaceListResult) Set(val *GetNetworkInterfaceListResult) { + v.value = val + v.isSet = true +} + +func (v NullableGetNetworkInterfaceListResult) IsSet() bool { + return v.isSet +} + +func (v *NullableGetNetworkInterfaceListResult) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableGetNetworkInterfaceListResult(val *GetNetworkInterfaceListResult) *NullableGetNetworkInterfaceListResult { + return &NullableGetNetworkInterfaceListResult{value: val, isSet: true} +} + +func (v NullableGetNetworkInterfaceListResult) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableGetNetworkInterfaceListResult) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/nse/model_network_interface.go b/nse/model_network_interface.go new file mode 100644 index 0000000..edb89cd --- /dev/null +++ b/nse/model_network_interface.go @@ -0,0 +1,313 @@ +/* +nse + +This documents the rest api nse api provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package nse + +import ( + "encoding/json" +) + +// checks if the NetworkInterface type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &NetworkInterface{} + +// NetworkInterface struct for NetworkInterface +type NetworkInterface struct { + // The link speed + LinkSpeed *string `json:"linkSpeed,omitempty"` + // The operational status + OperStatus *string `json:"operStatus,omitempty"` + // The administrative status + Status *string `json:"status,omitempty"` + // The switch port number + SwitchInterface *string `json:"switchInterface,omitempty"` + // The switch name + SwitchName *string `json:"switchName,omitempty"` + // The network type + Type *string `json:"type,omitempty"` +} + +// NewNetworkInterface instantiates a new NetworkInterface object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewNetworkInterface() *NetworkInterface { + this := NetworkInterface{} + return &this +} + +// NewNetworkInterfaceWithDefaults instantiates a new NetworkInterface object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewNetworkInterfaceWithDefaults() *NetworkInterface { + this := NetworkInterface{} + return &this +} + +// GetLinkSpeed returns the LinkSpeed field value if set, zero value otherwise. +func (o *NetworkInterface) GetLinkSpeed() string { + if o == nil || IsNil(o.LinkSpeed) { + var ret string + return ret + } + return *o.LinkSpeed +} + +// GetLinkSpeedOk returns a tuple with the LinkSpeed field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *NetworkInterface) GetLinkSpeedOk() (*string, bool) { + if o == nil || IsNil(o.LinkSpeed) { + return nil, false + } + return o.LinkSpeed, true +} + +// HasLinkSpeed returns a boolean if a field has been set. +func (o *NetworkInterface) HasLinkSpeed() bool { + if o != nil && !IsNil(o.LinkSpeed) { + return true + } + + return false +} + +// SetLinkSpeed gets a reference to the given string and assigns it to the LinkSpeed field. +func (o *NetworkInterface) SetLinkSpeed(v string) { + o.LinkSpeed = &v +} + +// GetOperStatus returns the OperStatus field value if set, zero value otherwise. +func (o *NetworkInterface) GetOperStatus() string { + if o == nil || IsNil(o.OperStatus) { + var ret string + return ret + } + return *o.OperStatus +} + +// GetOperStatusOk returns a tuple with the OperStatus field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *NetworkInterface) GetOperStatusOk() (*string, bool) { + if o == nil || IsNil(o.OperStatus) { + return nil, false + } + return o.OperStatus, true +} + +// HasOperStatus returns a boolean if a field has been set. +func (o *NetworkInterface) HasOperStatus() bool { + if o != nil && !IsNil(o.OperStatus) { + return true + } + + return false +} + +// SetOperStatus gets a reference to the given string and assigns it to the OperStatus field. +func (o *NetworkInterface) SetOperStatus(v string) { + o.OperStatus = &v +} + +// GetStatus returns the Status field value if set, zero value otherwise. +func (o *NetworkInterface) GetStatus() string { + if o == nil || IsNil(o.Status) { + var ret string + return ret + } + return *o.Status +} + +// GetStatusOk returns a tuple with the Status field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *NetworkInterface) GetStatusOk() (*string, bool) { + if o == nil || IsNil(o.Status) { + return nil, false + } + return o.Status, true +} + +// HasStatus returns a boolean if a field has been set. +func (o *NetworkInterface) HasStatus() bool { + if o != nil && !IsNil(o.Status) { + return true + } + + return false +} + +// SetStatus gets a reference to the given string and assigns it to the Status field. +func (o *NetworkInterface) SetStatus(v string) { + o.Status = &v +} + +// GetSwitchInterface returns the SwitchInterface field value if set, zero value otherwise. +func (o *NetworkInterface) GetSwitchInterface() string { + if o == nil || IsNil(o.SwitchInterface) { + var ret string + return ret + } + return *o.SwitchInterface +} + +// GetSwitchInterfaceOk returns a tuple with the SwitchInterface field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *NetworkInterface) GetSwitchInterfaceOk() (*string, bool) { + if o == nil || IsNil(o.SwitchInterface) { + return nil, false + } + return o.SwitchInterface, true +} + +// HasSwitchInterface returns a boolean if a field has been set. +func (o *NetworkInterface) HasSwitchInterface() bool { + if o != nil && !IsNil(o.SwitchInterface) { + return true + } + + return false +} + +// SetSwitchInterface gets a reference to the given string and assigns it to the SwitchInterface field. +func (o *NetworkInterface) SetSwitchInterface(v string) { + o.SwitchInterface = &v +} + +// GetSwitchName returns the SwitchName field value if set, zero value otherwise. +func (o *NetworkInterface) GetSwitchName() string { + if o == nil || IsNil(o.SwitchName) { + var ret string + return ret + } + return *o.SwitchName +} + +// GetSwitchNameOk returns a tuple with the SwitchName field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *NetworkInterface) GetSwitchNameOk() (*string, bool) { + if o == nil || IsNil(o.SwitchName) { + return nil, false + } + return o.SwitchName, true +} + +// HasSwitchName returns a boolean if a field has been set. +func (o *NetworkInterface) HasSwitchName() bool { + if o != nil && !IsNil(o.SwitchName) { + return true + } + + return false +} + +// SetSwitchName gets a reference to the given string and assigns it to the SwitchName field. +func (o *NetworkInterface) SetSwitchName(v string) { + o.SwitchName = &v +} + +// GetType returns the Type field value if set, zero value otherwise. +func (o *NetworkInterface) GetType() string { + if o == nil || IsNil(o.Type) { + var ret string + return ret + } + return *o.Type +} + +// GetTypeOk returns a tuple with the Type field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *NetworkInterface) GetTypeOk() (*string, bool) { + if o == nil || IsNil(o.Type) { + return nil, false + } + return o.Type, true +} + +// HasType returns a boolean if a field has been set. +func (o *NetworkInterface) HasType() bool { + if o != nil && !IsNil(o.Type) { + return true + } + + return false +} + +// SetType gets a reference to the given string and assigns it to the Type field. +func (o *NetworkInterface) SetType(v string) { + o.Type = &v +} + +func (o NetworkInterface) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o NetworkInterface) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.LinkSpeed) { + toSerialize["linkSpeed"] = o.LinkSpeed + } + if !IsNil(o.OperStatus) { + toSerialize["operStatus"] = o.OperStatus + } + if !IsNil(o.Status) { + toSerialize["status"] = o.Status + } + if !IsNil(o.SwitchInterface) { + toSerialize["switchInterface"] = o.SwitchInterface + } + if !IsNil(o.SwitchName) { + toSerialize["switchName"] = o.SwitchName + } + if !IsNil(o.Type) { + toSerialize["type"] = o.Type + } + return toSerialize, nil +} + +type NullableNetworkInterface struct { + value *NetworkInterface + isSet bool +} + +func (v NullableNetworkInterface) Get() *NetworkInterface { + return v.value +} + +func (v *NullableNetworkInterface) Set(val *NetworkInterface) { + v.value = val + v.isSet = true +} + +func (v NullableNetworkInterface) IsSet() bool { + return v.isSet +} + +func (v *NullableNetworkInterface) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableNetworkInterface(val *NetworkInterface) *NullableNetworkInterface { + return &NullableNetworkInterface{value: val, isSet: true} +} + +func (v NullableNetworkInterface) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableNetworkInterface) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/nse/model_update_ddos_notification_setting_opts.go b/nse/model_update_ddos_notification_setting_opts.go new file mode 100644 index 0000000..8281b6e --- /dev/null +++ b/nse/model_update_ddos_notification_setting_opts.go @@ -0,0 +1,165 @@ +/* +nse + +This documents the rest api nse api provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package nse + +import ( + "encoding/json" +) + +// checks if the UpdateDdosNotificationSettingOpts type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &UpdateDdosNotificationSettingOpts{} + +// UpdateDdosNotificationSettingOpts struct for UpdateDdosNotificationSettingOpts +type UpdateDdosNotificationSettingOpts struct { + // Enable or disable email notifications for nulling events + Nulling *string `json:"nulling,omitempty"` + // Enable or disable email notifications for nulling events + Scrubbing *string `json:"scrubbing,omitempty"` +} + +// NewUpdateDdosNotificationSettingOpts instantiates a new UpdateDdosNotificationSettingOpts object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewUpdateDdosNotificationSettingOpts() *UpdateDdosNotificationSettingOpts { + this := UpdateDdosNotificationSettingOpts{} + return &this +} + +// NewUpdateDdosNotificationSettingOptsWithDefaults instantiates a new UpdateDdosNotificationSettingOpts object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewUpdateDdosNotificationSettingOptsWithDefaults() *UpdateDdosNotificationSettingOpts { + this := UpdateDdosNotificationSettingOpts{} + return &this +} + +// GetNulling returns the Nulling field value if set, zero value otherwise. +func (o *UpdateDdosNotificationSettingOpts) GetNulling() string { + if o == nil || IsNil(o.Nulling) { + var ret string + return ret + } + return *o.Nulling +} + +// GetNullingOk returns a tuple with the Nulling field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *UpdateDdosNotificationSettingOpts) GetNullingOk() (*string, bool) { + if o == nil || IsNil(o.Nulling) { + return nil, false + } + return o.Nulling, true +} + +// HasNulling returns a boolean if a field has been set. +func (o *UpdateDdosNotificationSettingOpts) HasNulling() bool { + if o != nil && !IsNil(o.Nulling) { + return true + } + + return false +} + +// SetNulling gets a reference to the given string and assigns it to the Nulling field. +func (o *UpdateDdosNotificationSettingOpts) SetNulling(v string) { + o.Nulling = &v +} + +// GetScrubbing returns the Scrubbing field value if set, zero value otherwise. +func (o *UpdateDdosNotificationSettingOpts) GetScrubbing() string { + if o == nil || IsNil(o.Scrubbing) { + var ret string + return ret + } + return *o.Scrubbing +} + +// GetScrubbingOk returns a tuple with the Scrubbing field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *UpdateDdosNotificationSettingOpts) GetScrubbingOk() (*string, bool) { + if o == nil || IsNil(o.Scrubbing) { + return nil, false + } + return o.Scrubbing, true +} + +// HasScrubbing returns a boolean if a field has been set. +func (o *UpdateDdosNotificationSettingOpts) HasScrubbing() bool { + if o != nil && !IsNil(o.Scrubbing) { + return true + } + + return false +} + +// SetScrubbing gets a reference to the given string and assigns it to the Scrubbing field. +func (o *UpdateDdosNotificationSettingOpts) SetScrubbing(v string) { + o.Scrubbing = &v +} + +func (o UpdateDdosNotificationSettingOpts) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o UpdateDdosNotificationSettingOpts) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Nulling) { + toSerialize["nulling"] = o.Nulling + } + if !IsNil(o.Scrubbing) { + toSerialize["scrubbing"] = o.Scrubbing + } + return toSerialize, nil +} + +type NullableUpdateDdosNotificationSettingOpts struct { + value *UpdateDdosNotificationSettingOpts + isSet bool +} + +func (v NullableUpdateDdosNotificationSettingOpts) Get() *UpdateDdosNotificationSettingOpts { + return v.value +} + +func (v *NullableUpdateDdosNotificationSettingOpts) Set(val *UpdateDdosNotificationSettingOpts) { + v.value = val + v.isSet = true +} + +func (v NullableUpdateDdosNotificationSettingOpts) IsSet() bool { + return v.isSet +} + +func (v *NullableUpdateDdosNotificationSettingOpts) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableUpdateDdosNotificationSettingOpts(val *UpdateDdosNotificationSettingOpts) *NullableUpdateDdosNotificationSettingOpts { + return &NullableUpdateDdosNotificationSettingOpts{value: val, isSet: true} +} + +func (v NullableUpdateDdosNotificationSettingOpts) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableUpdateDdosNotificationSettingOpts) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/nse/model_update_null_route_accepted_result.go b/nse/model_update_null_route_accepted_result.go new file mode 100644 index 0000000..ec9ab76 --- /dev/null +++ b/nse/model_update_null_route_accepted_result.go @@ -0,0 +1,128 @@ +/* +nse + +This documents the rest api nse api provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package nse + +import ( + "encoding/json" +) + +// checks if the UpdateNullRouteAcceptedResult type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &UpdateNullRouteAcceptedResult{} + +// UpdateNullRouteAcceptedResult struct for UpdateNullRouteAcceptedResult +type UpdateNullRouteAcceptedResult struct { + // A human friendly message describing the action that will be taken + Message *string `json:"message,omitempty"` +} + +// NewUpdateNullRouteAcceptedResult instantiates a new UpdateNullRouteAcceptedResult object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewUpdateNullRouteAcceptedResult() *UpdateNullRouteAcceptedResult { + this := UpdateNullRouteAcceptedResult{} + return &this +} + +// NewUpdateNullRouteAcceptedResultWithDefaults instantiates a new UpdateNullRouteAcceptedResult object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewUpdateNullRouteAcceptedResultWithDefaults() *UpdateNullRouteAcceptedResult { + this := UpdateNullRouteAcceptedResult{} + return &this +} + +// GetMessage returns the Message field value if set, zero value otherwise. +func (o *UpdateNullRouteAcceptedResult) GetMessage() string { + if o == nil || IsNil(o.Message) { + var ret string + return ret + } + return *o.Message +} + +// GetMessageOk returns a tuple with the Message field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *UpdateNullRouteAcceptedResult) GetMessageOk() (*string, bool) { + if o == nil || IsNil(o.Message) { + return nil, false + } + return o.Message, true +} + +// HasMessage returns a boolean if a field has been set. +func (o *UpdateNullRouteAcceptedResult) HasMessage() bool { + if o != nil && !IsNil(o.Message) { + return true + } + + return false +} + +// SetMessage gets a reference to the given string and assigns it to the Message field. +func (o *UpdateNullRouteAcceptedResult) SetMessage(v string) { + o.Message = &v +} + +func (o UpdateNullRouteAcceptedResult) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o UpdateNullRouteAcceptedResult) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Message) { + toSerialize["message"] = o.Message + } + return toSerialize, nil +} + +type NullableUpdateNullRouteAcceptedResult struct { + value *UpdateNullRouteAcceptedResult + isSet bool +} + +func (v NullableUpdateNullRouteAcceptedResult) Get() *UpdateNullRouteAcceptedResult { + return v.value +} + +func (v *NullableUpdateNullRouteAcceptedResult) Set(val *UpdateNullRouteAcceptedResult) { + v.value = val + v.isSet = true +} + +func (v NullableUpdateNullRouteAcceptedResult) IsSet() bool { + return v.isSet +} + +func (v *NullableUpdateNullRouteAcceptedResult) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableUpdateNullRouteAcceptedResult(val *UpdateNullRouteAcceptedResult) *NullableUpdateNullRouteAcceptedResult { + return &NullableUpdateNullRouteAcceptedResult{value: val, isSet: true} +} + +func (v NullableUpdateNullRouteAcceptedResult) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableUpdateNullRouteAcceptedResult) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/nse/model_update_null_route_bad_request_result.go b/nse/model_update_null_route_bad_request_result.go new file mode 100644 index 0000000..b8659a7 --- /dev/null +++ b/nse/model_update_null_route_bad_request_result.go @@ -0,0 +1,239 @@ +/* +nse + +This documents the rest api nse api provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package nse + +import ( + "encoding/json" +) + +// checks if the UpdateNullRouteBadRequestResult type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &UpdateNullRouteBadRequestResult{} + +// UpdateNullRouteBadRequestResult struct for UpdateNullRouteBadRequestResult +type UpdateNullRouteBadRequestResult struct { + // The correlation ID of the current request. + CorrelationId *string `json:"correlationId,omitempty"` + // The error code. + ErrorCode *string `json:"errorCode,omitempty"` + // An object describing the errors for the current request. + ErrorDetails map[string]interface{} `json:"errorDetails,omitempty"` + // A human friendly description of the error. + ErrorMessage *string `json:"errorMessage,omitempty"` +} + +// NewUpdateNullRouteBadRequestResult instantiates a new UpdateNullRouteBadRequestResult object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewUpdateNullRouteBadRequestResult() *UpdateNullRouteBadRequestResult { + this := UpdateNullRouteBadRequestResult{} + return &this +} + +// NewUpdateNullRouteBadRequestResultWithDefaults instantiates a new UpdateNullRouteBadRequestResult object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewUpdateNullRouteBadRequestResultWithDefaults() *UpdateNullRouteBadRequestResult { + this := UpdateNullRouteBadRequestResult{} + return &this +} + +// GetCorrelationId returns the CorrelationId field value if set, zero value otherwise. +func (o *UpdateNullRouteBadRequestResult) GetCorrelationId() string { + if o == nil || IsNil(o.CorrelationId) { + var ret string + return ret + } + return *o.CorrelationId +} + +// GetCorrelationIdOk returns a tuple with the CorrelationId field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *UpdateNullRouteBadRequestResult) GetCorrelationIdOk() (*string, bool) { + if o == nil || IsNil(o.CorrelationId) { + return nil, false + } + return o.CorrelationId, true +} + +// HasCorrelationId returns a boolean if a field has been set. +func (o *UpdateNullRouteBadRequestResult) HasCorrelationId() bool { + if o != nil && !IsNil(o.CorrelationId) { + return true + } + + return false +} + +// SetCorrelationId gets a reference to the given string and assigns it to the CorrelationId field. +func (o *UpdateNullRouteBadRequestResult) SetCorrelationId(v string) { + o.CorrelationId = &v +} + +// GetErrorCode returns the ErrorCode field value if set, zero value otherwise. +func (o *UpdateNullRouteBadRequestResult) GetErrorCode() string { + if o == nil || IsNil(o.ErrorCode) { + var ret string + return ret + } + return *o.ErrorCode +} + +// GetErrorCodeOk returns a tuple with the ErrorCode field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *UpdateNullRouteBadRequestResult) GetErrorCodeOk() (*string, bool) { + if o == nil || IsNil(o.ErrorCode) { + return nil, false + } + return o.ErrorCode, true +} + +// HasErrorCode returns a boolean if a field has been set. +func (o *UpdateNullRouteBadRequestResult) HasErrorCode() bool { + if o != nil && !IsNil(o.ErrorCode) { + return true + } + + return false +} + +// SetErrorCode gets a reference to the given string and assigns it to the ErrorCode field. +func (o *UpdateNullRouteBadRequestResult) SetErrorCode(v string) { + o.ErrorCode = &v +} + +// GetErrorDetails returns the ErrorDetails field value if set, zero value otherwise. +func (o *UpdateNullRouteBadRequestResult) GetErrorDetails() map[string]interface{} { + if o == nil || IsNil(o.ErrorDetails) { + var ret map[string]interface{} + return ret + } + return o.ErrorDetails +} + +// GetErrorDetailsOk returns a tuple with the ErrorDetails field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *UpdateNullRouteBadRequestResult) GetErrorDetailsOk() (map[string]interface{}, bool) { + if o == nil || IsNil(o.ErrorDetails) { + return map[string]interface{}{}, false + } + return o.ErrorDetails, true +} + +// HasErrorDetails returns a boolean if a field has been set. +func (o *UpdateNullRouteBadRequestResult) HasErrorDetails() bool { + if o != nil && !IsNil(o.ErrorDetails) { + return true + } + + return false +} + +// SetErrorDetails gets a reference to the given map[string]interface{} and assigns it to the ErrorDetails field. +func (o *UpdateNullRouteBadRequestResult) SetErrorDetails(v map[string]interface{}) { + o.ErrorDetails = v +} + +// GetErrorMessage returns the ErrorMessage field value if set, zero value otherwise. +func (o *UpdateNullRouteBadRequestResult) GetErrorMessage() string { + if o == nil || IsNil(o.ErrorMessage) { + var ret string + return ret + } + return *o.ErrorMessage +} + +// GetErrorMessageOk returns a tuple with the ErrorMessage field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *UpdateNullRouteBadRequestResult) GetErrorMessageOk() (*string, bool) { + if o == nil || IsNil(o.ErrorMessage) { + return nil, false + } + return o.ErrorMessage, true +} + +// HasErrorMessage returns a boolean if a field has been set. +func (o *UpdateNullRouteBadRequestResult) HasErrorMessage() bool { + if o != nil && !IsNil(o.ErrorMessage) { + return true + } + + return false +} + +// SetErrorMessage gets a reference to the given string and assigns it to the ErrorMessage field. +func (o *UpdateNullRouteBadRequestResult) SetErrorMessage(v string) { + o.ErrorMessage = &v +} + +func (o UpdateNullRouteBadRequestResult) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o UpdateNullRouteBadRequestResult) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.CorrelationId) { + toSerialize["correlationId"] = o.CorrelationId + } + if !IsNil(o.ErrorCode) { + toSerialize["errorCode"] = o.ErrorCode + } + if !IsNil(o.ErrorDetails) { + toSerialize["errorDetails"] = o.ErrorDetails + } + if !IsNil(o.ErrorMessage) { + toSerialize["errorMessage"] = o.ErrorMessage + } + return toSerialize, nil +} + +type NullableUpdateNullRouteBadRequestResult struct { + value *UpdateNullRouteBadRequestResult + isSet bool +} + +func (v NullableUpdateNullRouteBadRequestResult) Get() *UpdateNullRouteBadRequestResult { + return v.value +} + +func (v *NullableUpdateNullRouteBadRequestResult) Set(val *UpdateNullRouteBadRequestResult) { + v.value = val + v.isSet = true +} + +func (v NullableUpdateNullRouteBadRequestResult) IsSet() bool { + return v.isSet +} + +func (v *NullableUpdateNullRouteBadRequestResult) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableUpdateNullRouteBadRequestResult(val *UpdateNullRouteBadRequestResult) *NullableUpdateNullRouteBadRequestResult { + return &NullableUpdateNullRouteBadRequestResult{value: val, isSet: true} +} + +func (v NullableUpdateNullRouteBadRequestResult) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableUpdateNullRouteBadRequestResult) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/nse/model_update_null_route_opts.go b/nse/model_update_null_route_opts.go new file mode 100644 index 0000000..121e8b3 --- /dev/null +++ b/nse/model_update_null_route_opts.go @@ -0,0 +1,189 @@ +/* +nse + +This documents the rest api nse api provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package nse + +import ( + "encoding/json" + "bytes" + "fmt" +) + +// checks if the UpdateNullRouteOpts type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &UpdateNullRouteOpts{} + +// UpdateNullRouteOpts struct for UpdateNullRouteOpts +type UpdateNullRouteOpts struct { + // The action to take + Action string `json:"action"` + // The IP address for which to announce or withdraw the null route + IpAddress string `json:"ipAddress"` +} + +type _UpdateNullRouteOpts UpdateNullRouteOpts + +// NewUpdateNullRouteOpts instantiates a new UpdateNullRouteOpts object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewUpdateNullRouteOpts(action string, ipAddress string) *UpdateNullRouteOpts { + this := UpdateNullRouteOpts{} + this.Action = action + this.IpAddress = ipAddress + return &this +} + +// NewUpdateNullRouteOptsWithDefaults instantiates a new UpdateNullRouteOpts object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewUpdateNullRouteOptsWithDefaults() *UpdateNullRouteOpts { + this := UpdateNullRouteOpts{} + return &this +} + +// GetAction returns the Action field value +func (o *UpdateNullRouteOpts) GetAction() string { + if o == nil { + var ret string + return ret + } + + return o.Action +} + +// GetActionOk returns a tuple with the Action field value +// and a boolean to check if the value has been set. +func (o *UpdateNullRouteOpts) GetActionOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.Action, true +} + +// SetAction sets field value +func (o *UpdateNullRouteOpts) SetAction(v string) { + o.Action = v +} + +// GetIpAddress returns the IpAddress field value +func (o *UpdateNullRouteOpts) GetIpAddress() string { + if o == nil { + var ret string + return ret + } + + return o.IpAddress +} + +// GetIpAddressOk returns a tuple with the IpAddress field value +// and a boolean to check if the value has been set. +func (o *UpdateNullRouteOpts) GetIpAddressOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.IpAddress, true +} + +// SetIpAddress sets field value +func (o *UpdateNullRouteOpts) SetIpAddress(v string) { + o.IpAddress = v +} + +func (o UpdateNullRouteOpts) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o UpdateNullRouteOpts) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + toSerialize["action"] = o.Action + toSerialize["ipAddress"] = o.IpAddress + return toSerialize, nil +} + +func (o *UpdateNullRouteOpts) UnmarshalJSON(data []byte) (err error) { + // This validates that all required properties are included in the JSON object + // by unmarshalling the object into a generic map with string keys and checking + // that every required field exists as a key in the generic map. + requiredProperties := []string{ + "action", + "ipAddress", + } + + allProperties := make(map[string]interface{}) + + err = json.Unmarshal(data, &allProperties) + + if err != nil { + return err; + } + + for _, requiredProperty := range(requiredProperties) { + if _, exists := allProperties[requiredProperty]; !exists { + return fmt.Errorf("no value given for required property %v", requiredProperty) + } + } + + varUpdateNullRouteOpts := _UpdateNullRouteOpts{} + + decoder := json.NewDecoder(bytes.NewReader(data)) + decoder.DisallowUnknownFields() + err = decoder.Decode(&varUpdateNullRouteOpts) + + if err != nil { + return err + } + + *o = UpdateNullRouteOpts(varUpdateNullRouteOpts) + + return err +} + +type NullableUpdateNullRouteOpts struct { + value *UpdateNullRouteOpts + isSet bool +} + +func (v NullableUpdateNullRouteOpts) Get() *UpdateNullRouteOpts { + return v.value +} + +func (v *NullableUpdateNullRouteOpts) Set(val *UpdateNullRouteOpts) { + v.value = val + v.isSet = true +} + +func (v NullableUpdateNullRouteOpts) IsSet() bool { + return v.isSet +} + +func (v *NullableUpdateNullRouteOpts) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableUpdateNullRouteOpts(val *UpdateNullRouteOpts) *NullableUpdateNullRouteOpts { + return &NullableUpdateNullRouteOpts{value: val, isSet: true} +} + +func (v NullableUpdateNullRouteOpts) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableUpdateNullRouteOpts) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/nse/response.go b/nse/response.go new file mode 100644 index 0000000..4debaa8 --- /dev/null +++ b/nse/response.go @@ -0,0 +1,48 @@ +/* +nse + +This documents the rest api nse api provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package nse + +import ( + "net/http" +) + +// APIResponse stores the API response returned by the server. +type APIResponse struct { + *http.Response `json:"-"` + Message string `json:"message,omitempty"` + // Operation is the name of the OpenAPI operation. + Operation string `json:"operation,omitempty"` + // RequestURL is the request URL. This value is always available, even if the + // embedded *http.Response is nil. + RequestURL string `json:"url,omitempty"` + // Method is the HTTP method used for the request. This value is always + // available, even if the embedded *http.Response is nil. + Method string `json:"method,omitempty"` + // Payload holds the contents of the response body (which may be nil or empty). + // This is provided here as the raw response.Body() reader will have already + // been drained. + Payload []byte `json:"-"` +} + +// NewAPIResponse returns a new APIResponse object. +func NewAPIResponse(r *http.Response) *APIResponse { + + response := &APIResponse{Response: r} + return response +} + +// NewAPIResponseWithError returns a new APIResponse object with the provided error message. +func NewAPIResponseWithError(errorMessage string) *APIResponse { + + response := &APIResponse{Message: errorMessage} + return response +} diff --git a/nse/test/api_nse_test.go b/nse/test/api_nse_test.go new file mode 100644 index 0000000..9abd456 --- /dev/null +++ b/nse/test/api_nse_test.go @@ -0,0 +1,147 @@ +/* +nse + +Testing NseAPIService + +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); + +package nse + +import ( + "context" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "testing" + openapiclient "github.com/leaseweb/leaseweb-go-sdk/nse" +) + +func Test_nse_NseAPIService(t *testing.T) { + + configuration := openapiclient.NewConfiguration() + apiClient := openapiclient.NewAPIClient(configuration) + + t.Run("Test NseAPIService CloseNetworkInterface", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var serverId string + var networkType string + + httpRes, err := apiClient.NseAPI.CloseNetworkInterface(context.Background(), serverId, networkType).Execute() + + require.Nil(t, err) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test NseAPIService CloseNetworkInterfaces", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var serverId string + + httpRes, err := apiClient.NseAPI.CloseNetworkInterfaces(context.Background(), serverId).Execute() + + require.Nil(t, err) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test NseAPIService GetDdosNotificationSettingList", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var serverId string + + resp, httpRes, err := apiClient.NseAPI.GetDdosNotificationSettingList(context.Background(), serverId).Execute() + + require.Nil(t, err) + require.NotNil(t, resp) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test NseAPIService GetNetworkInterface", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var serverId string + var networkType string + + resp, httpRes, err := apiClient.NseAPI.GetNetworkInterface(context.Background(), serverId, networkType).Execute() + + require.Nil(t, err) + require.NotNil(t, resp) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test NseAPIService GetNetworkInterfaceList", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var serverId string + + resp, httpRes, err := apiClient.NseAPI.GetNetworkInterfaceList(context.Background(), serverId).Execute() + + require.Nil(t, err) + require.NotNil(t, resp) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test NseAPIService OpenNetworkInterface", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var serverId string + var networkType string + + httpRes, err := apiClient.NseAPI.OpenNetworkInterface(context.Background(), serverId, networkType).Execute() + + require.Nil(t, err) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test NseAPIService OpenNetworkInterfaces", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var serverId string + + httpRes, err := apiClient.NseAPI.OpenNetworkInterfaces(context.Background(), serverId).Execute() + + require.Nil(t, err) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test NseAPIService UpdateNullRoute", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + resp, httpRes, err := apiClient.NseAPI.UpdateNullRoute(context.Background()).Execute() + + require.Nil(t, err) + require.NotNil(t, resp) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test NseAPIService UpdateServerDdosNotificationSetting", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var serverId string + + httpRes, err := apiClient.NseAPI.UpdateServerDdosNotificationSetting(context.Background(), serverId).Execute() + + require.Nil(t, err) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + +} diff --git a/nse/utils.go b/nse/utils.go new file mode 100644 index 0000000..534ddd6 --- /dev/null +++ b/nse/utils.go @@ -0,0 +1,348 @@ +/* +nse + +This documents the rest api nse api provides. + +API version: v2 +Contact: development-networkautomation@leaseweb.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package nse + +import ( + "encoding/json" + "reflect" + "time" +) + +// PtrBool is a helper routine that returns a pointer to given boolean value. +func PtrBool(v bool) *bool { return &v } + +// PtrInt is a helper routine that returns a pointer to given integer value. +func PtrInt(v int) *int { return &v } + +// PtrInt32 is a helper routine that returns a pointer to given integer value. +func PtrInt32(v int32) *int32 { return &v } + +// PtrInt64 is a helper routine that returns a pointer to given integer value. +func PtrInt64(v int64) *int64 { return &v } + +// PtrFloat32 is a helper routine that returns a pointer to given float value. +func PtrFloat32(v float32) *float32 { return &v } + +// PtrFloat64 is a helper routine that returns a pointer to given float value. +func PtrFloat64(v float64) *float64 { return &v } + +// PtrString is a helper routine that returns a pointer to given string value. +func PtrString(v string) *string { return &v } + +// PtrTime is helper routine that returns a pointer to given Time value. +func PtrTime(v time.Time) *time.Time { return &v } + +type NullableBool struct { + value *bool + isSet bool +} + +func (v NullableBool) Get() *bool { + return v.value +} + +func (v *NullableBool) Set(val *bool) { + v.value = val + v.isSet = true +} + +func (v NullableBool) IsSet() bool { + return v.isSet +} + +func (v *NullableBool) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableBool(val *bool) *NullableBool { + return &NullableBool{value: val, isSet: true} +} + +func (v NullableBool) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableBool) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + +type NullableInt struct { + value *int + isSet bool +} + +func (v NullableInt) Get() *int { + return v.value +} + +func (v *NullableInt) Set(val *int) { + v.value = val + v.isSet = true +} + +func (v NullableInt) IsSet() bool { + return v.isSet +} + +func (v *NullableInt) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableInt(val *int) *NullableInt { + return &NullableInt{value: val, isSet: true} +} + +func (v NullableInt) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableInt) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + +type NullableInt32 struct { + value *int32 + isSet bool +} + +func (v NullableInt32) Get() *int32 { + return v.value +} + +func (v *NullableInt32) Set(val *int32) { + v.value = val + v.isSet = true +} + +func (v NullableInt32) IsSet() bool { + return v.isSet +} + +func (v *NullableInt32) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableInt32(val *int32) *NullableInt32 { + return &NullableInt32{value: val, isSet: true} +} + +func (v NullableInt32) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableInt32) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + +type NullableInt64 struct { + value *int64 + isSet bool +} + +func (v NullableInt64) Get() *int64 { + return v.value +} + +func (v *NullableInt64) Set(val *int64) { + v.value = val + v.isSet = true +} + +func (v NullableInt64) IsSet() bool { + return v.isSet +} + +func (v *NullableInt64) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableInt64(val *int64) *NullableInt64 { + return &NullableInt64{value: val, isSet: true} +} + +func (v NullableInt64) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableInt64) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + +type NullableFloat32 struct { + value *float32 + isSet bool +} + +func (v NullableFloat32) Get() *float32 { + return v.value +} + +func (v *NullableFloat32) Set(val *float32) { + v.value = val + v.isSet = true +} + +func (v NullableFloat32) IsSet() bool { + return v.isSet +} + +func (v *NullableFloat32) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableFloat32(val *float32) *NullableFloat32 { + return &NullableFloat32{value: val, isSet: true} +} + +func (v NullableFloat32) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableFloat32) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + +type NullableFloat64 struct { + value *float64 + isSet bool +} + +func (v NullableFloat64) Get() *float64 { + return v.value +} + +func (v *NullableFloat64) Set(val *float64) { + v.value = val + v.isSet = true +} + +func (v NullableFloat64) IsSet() bool { + return v.isSet +} + +func (v *NullableFloat64) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableFloat64(val *float64) *NullableFloat64 { + return &NullableFloat64{value: val, isSet: true} +} + +func (v NullableFloat64) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableFloat64) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + +type NullableString struct { + value *string + isSet bool +} + +func (v NullableString) Get() *string { + return v.value +} + +func (v *NullableString) Set(val *string) { + v.value = val + v.isSet = true +} + +func (v NullableString) IsSet() bool { + return v.isSet +} + +func (v *NullableString) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableString(val *string) *NullableString { + return &NullableString{value: val, isSet: true} +} + +func (v NullableString) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableString) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + +type NullableTime struct { + value *time.Time + isSet bool +} + +func (v NullableTime) Get() *time.Time { + return v.value +} + +func (v *NullableTime) Set(val *time.Time) { + v.value = val + v.isSet = true +} + +func (v NullableTime) IsSet() bool { + return v.isSet +} + +func (v *NullableTime) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableTime(val *time.Time) *NullableTime { + return &NullableTime{value: val, isSet: true} +} + +func (v NullableTime) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableTime) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + +// IsNil checks if an input is nil +func IsNil(i interface{}) bool { + if i == nil { + return true + } + switch reflect.TypeOf(i).Kind() { + case reflect.Chan, reflect.Func, reflect.Map, reflect.Ptr, reflect.UnsafePointer, reflect.Interface, reflect.Slice: + return reflect.ValueOf(i).IsNil() + case reflect.Array: + return reflect.ValueOf(i).IsZero() + } + return false +} + +type MappedNullable interface { + ToMap() (map[string]interface{}, error) +} diff --git a/private_cloud.go b/private_cloud.go deleted file mode 100644 index 2c60fa5..0000000 --- a/private_cloud.go +++ /dev/null @@ -1,148 +0,0 @@ -package leaseweb - -import ( - "context" - "net/http" - - "github.com/LeaseWeb/leaseweb-go-sdk/options" -) - -const PRIVATE_CLOUD_API_VERSION = "v2" - -type PrivateCloudApi struct{} - -type PrivateClouds struct { - PrivateClouds []PrivateCloud `json:"privateClouds"` - Metadata Metadata `json:"_metadata"` -} - -type PrivateCloud struct { - Id string `json:"id"` - CustomerId string `json:"customerId"` - DataCenter string `json:"dataCenter"` - ServiceOffering string `json:"serviceOffering"` - Sla string `json:"sla"` - Contract Contract `json:"contract"` - NetworkTraffic NetworkTraffic `json:"networkTraffic"` - Ips []Ip `json:"ips"` - Hardware Hardware `json:"hardware"` -} - -type PrivateCloudCpuMetrics struct { - Metric PrivateCloudCpuMetric `json:"metrics"` - Metadata MetricMetadata `json:"_metadata"` -} - -type PrivateCloudCpuMetric struct { - Cpu BasicMetric `json:"CPU"` -} - -type PrivateCloudMemoryMetrics struct { - Metric PrivateCloudMemoryMetric `json:"metrics"` - Metadata MetricMetadata `json:"_metadata"` -} - -type PrivateCloudMemoryMetric struct { - Memory BasicMetric `json:"MEMORY"` -} - -type PrivateCloudStorageMetrics struct { - Metric PrivateCloudStorageMetric `json:"metrics"` - Metadata MetricMetadata `json:"_metadata"` -} - -type PrivateCloudStorageMetric struct { - Storage BasicMetric `json:"STORAGE"` -} - -func (pca PrivateCloudApi) getPath(endpoint string) string { - return "/cloud/" + PRIVATE_CLOUD_API_VERSION + endpoint -} - -func (pca PrivateCloudApi) List(ctx context.Context, opts PaginationOptions) (*PrivateClouds, error) { - path := pca.getPath("/privateClouds") - query := options.Encode(opts) - result := &PrivateClouds{} - if err := doRequest(ctx, http.MethodGet, path, query, result); err != nil { - return nil, err - } - return result, nil -} - -func (pca PrivateCloudApi) Get(ctx context.Context, privateCloudId string) (*PrivateCloud, error) { - path := pca.getPath("/privateClouds/" + privateCloudId) - result := &PrivateCloud{} - if err := doRequest(ctx, http.MethodGet, path, "", result); err != nil { - return nil, err - } - return result, nil -} - -func (pca PrivateCloudApi) ListCredentials(ctx context.Context, privateCloudId string, credentialType string, opts PaginationOptions) (*Credentials, error) { - path := pca.getPath("/privateClouds/" + privateCloudId + "/credentials/" + credentialType) - query := options.Encode(opts) - result := &Credentials{} - if err := doRequest(ctx, http.MethodGet, path, query, result); err != nil { - return nil, err - } - return result, nil -} - -func (pca PrivateCloudApi) GetCredential(ctx context.Context, privateCloudId string, credentialType string, username string) (*Credential, error) { - path := pca.getPath("/privateClouds/" + privateCloudId + "/credentials/" + credentialType + "/" + username) - result := &Credential{} - if err := doRequest(ctx, http.MethodGet, path, "", result); err != nil { - return nil, err - } - return result, nil -} - -func (pca PrivateCloudApi) GetDataTrafficMetrics(ctx context.Context, privateCloudId string, opts MetricsOptions) (*DataTrafficMetricsV2, error) { - path := pca.getPath("/privateClouds/" + privateCloudId + "/metrics/datatraffic") - query := options.Encode(opts) - result := &DataTrafficMetricsV2{} - if err := doRequest(ctx, http.MethodGet, path, query, result); err != nil { - return nil, err - } - return result, nil -} - -func (pca PrivateCloudApi) GetBandWidthMetrics(ctx context.Context, privateCloudId string, opts MetricsOptions) (*BandWidthMetrics, error) { - path := pca.getPath("/privateClouds/" + privateCloudId + "/metrics/bandwidth") - query := options.Encode(opts) - result := &BandWidthMetrics{} - if err := doRequest(ctx, http.MethodGet, path, query, result); err != nil { - return nil, err - } - return result, nil -} - -func (pca PrivateCloudApi) GetCpuMetrics(ctx context.Context, privateCloudId string, opts MetricsOptions) (*PrivateCloudCpuMetrics, error) { - path := pca.getPath("/privateClouds/" + privateCloudId + "/metrics/cpu") - query := options.Encode(opts) - result := &PrivateCloudCpuMetrics{} - if err := doRequest(ctx, http.MethodGet, path, query, result); err != nil { - return nil, err - } - return result, nil -} - -func (pca PrivateCloudApi) GetMemoryMetrics(ctx context.Context, privateCloudId string, opts MetricsOptions) (*PrivateCloudMemoryMetrics, error) { - path := pca.getPath("/privateClouds/" + privateCloudId + "/metrics/memory") - query := options.Encode(opts) - result := &PrivateCloudMemoryMetrics{} - if err := doRequest(ctx, http.MethodGet, path, query, result); err != nil { - return nil, err - } - return result, nil -} - -func (pca PrivateCloudApi) GetStorageMetrics(ctx context.Context, privateCloudId string, opts MetricsOptions) (*PrivateCloudStorageMetrics, error) { - path := pca.getPath("/privateClouds/" + privateCloudId + "/metrics/storage") - query := options.Encode(opts) - result := &PrivateCloudStorageMetrics{} - if err := doRequest(ctx, http.MethodGet, path, query, result); err != nil { - return nil, err - } - return result, nil -} diff --git a/private_cloud_test.go b/private_cloud_test.go deleted file mode 100644 index 3dc95d8..0000000 --- a/private_cloud_test.go +++ /dev/null @@ -1,1579 +0,0 @@ -package leaseweb - -import ( - "context" - "fmt" - "net/http" - "testing" - - "github.com/stretchr/testify/assert" -) - -func TestPrivateCloudList(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{"_metadata":{"limit": 10, "offset": 0, "totalCount": 1}, "privateClouds": [ - { - "id": "218030", - "customerId": "1301178860", - "dataCenter": "AMS-01", - "serviceOffering": "FLAT_FEE", - "sla": "Bronze", - "contract": { - "id": "30000775", - "startsAt": "2015-11-01T00:00:00+02:00", - "endsAt": "2016-12-30T10:39:27+01:00", - "billingCycle": 12, - "billingFrequency": "MONTH", - "pricePerFrequency": 0, - "currency": "EUR" - }, - "hardware": { - "cpu": { - "cores": 25 - }, - "memory": { - "unit": "GB", - "amount": 50 - }, - "storage": { - "unit": "GB", - "amount": 1 - } - }, - "ips": [ - { - "ip": "10.12.144.32", - "version": 4, - "type": "PUBLIC" - } - ], - "networkTraffic": { - "type": "DATATRAFFIC", - "trafficType": "PREMIUM", - "datatrafficUnit": "TB", - "datatrafficLimit": 6 - } - } - ]}`) - }) - defer teardown() - - privateCloudApi := PrivateCloudApi{} - ctx := context.Background() - response, err := privateCloudApi.List(ctx, PaginationOptions{}) - - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 1) - assert.Equal(response.Metadata.Offset, 0) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.PrivateClouds), 1) - - privateCloud1 := response.PrivateClouds[0] - assert.Equal(privateCloud1.Id, "218030") - assert.Equal(privateCloud1.CustomerId, "1301178860") - assert.Equal(privateCloud1.DataCenter, "AMS-01") - assert.Equal(privateCloud1.ServiceOffering, "FLAT_FEE") - assert.Equal(privateCloud1.Sla, "Bronze") - assert.Equal(privateCloud1.Contract.Id, "30000775") - assert.Equal(privateCloud1.Contract.StartsAt, "2015-11-01T00:00:00+02:00") - assert.Equal(privateCloud1.Contract.EndsAt, "2016-12-30T10:39:27+01:00") - assert.Equal(privateCloud1.Contract.BillingCycle.String(), "12") - assert.Equal(privateCloud1.Contract.BillingFrequency, "MONTH") - assert.Equal(privateCloud1.Contract.PricePerFrequency.String(), "0") - assert.Equal(privateCloud1.Contract.Currency, "EUR") - assert.Equal(privateCloud1.Hardware.Cpu.Cores.String(), "25") - assert.Equal(privateCloud1.Hardware.Memory.Amount.String(), "50") - assert.Equal(privateCloud1.Hardware.Memory.Unit, "GB") - assert.Equal(privateCloud1.Hardware.Storage.Amount.String(), "1") - assert.Equal(privateCloud1.Hardware.Storage.Unit, "GB") - assert.Equal(privateCloud1.Ips[0].Ip, "10.12.144.32") - assert.Equal(privateCloud1.Ips[0].Type, "PUBLIC") - assert.Equal(privateCloud1.Ips[0].Version.String(), "4") - assert.Equal(privateCloud1.NetworkTraffic.DataTrafficLimit.String(), "6") - assert.Equal(privateCloud1.NetworkTraffic.DataTrafficUnit, "TB") - assert.Equal(privateCloud1.NetworkTraffic.TrafficType, "PREMIUM") - assert.Equal(privateCloud1.NetworkTraffic.Type, "DATATRAFFIC") -} - -func TestPrivateCloudListBeEmpty(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - if h := r.Header.Get("x-lsw-auth"); h != "test-api-key" { - t.Errorf("request did not have x-lsw-auth header set!") - } - fmt.Fprintf(w, `{"_metadata":{"limit": 10, "offset": 0, "totalCount": 0}, "privateClouds": []}`) - }) - defer teardown() - - privateCloudApi := PrivateCloudApi{} - ctx := context.Background() - response, err := privateCloudApi.List(ctx, PaginationOptions{}) - - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 0) - assert.Equal(response.Metadata.Offset, 0) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.PrivateClouds), 0) -} - -func TestPrivateCloudListPaginate(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{"_metadata":{"limit": 20, "offset": 10, "totalCount": 2}, "privateClouds": []}`) - }) - defer teardown() - - privateCloudApi := PrivateCloudApi{} - ctx := context.Background() - opts := PaginationOptions{ - Limit: Int(10), - Offset: Int(20), - } - response, err := privateCloudApi.List(ctx, opts) - - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 2) - assert.Equal(response.Metadata.Offset, 10) - assert.Equal(response.Metadata.Limit, 20) - assert.Equal(len(response.PrivateClouds), 0) -} - -func TestPrivateCloudListServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"errorCode": "ACCESS_DENIED", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return PrivateCloudApi{}.List(ctx, PaginationOptions{}) - }, - ExpectedError: ApiError{ - Code: "ACCESS_DENIED", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"errorCode": "SERVER_ERROR", "errorMessage": "The server encountered an unexpected condition that prevented it from fulfilling the request."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return PrivateCloudApi{}.List(ctx, PaginationOptions{}) - }, - ExpectedError: ApiError{ - Code: "SERVER_ERROR", - Message: "The server encountered an unexpected condition that prevented it from fulfilling the request.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"errorCode": "TEMPORARILY_UNAVAILABLE", "errorMessage": "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return PrivateCloudApi{}.List(ctx, PaginationOptions{}) - }, - ExpectedError: ApiError{ - Code: "TEMPORARILY_UNAVAILABLE", - Message: "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestPrivateCloudGet(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "id": "218030", - "customerId": "1301178860", - "dataCenter": "AMS-01", - "serviceOffering": "FLAT_FEE", - "sla": "Bronze", - "contract": { - "id": "30000775", - "startsAt": "2015-11-01T00:00:00+02:00", - "endsAt": "2016-12-30T10:39:27+01:00", - "billingCycle": 12, - "billingFrequency": "MONTH", - "pricePerFrequency": 0, - "currency": "EUR" - }, - "hardware": { - "cpu": { - "cores": 25 - }, - "memory": { - "unit": "GB", - "amount": 50 - }, - "storage": { - "unit": "GB", - "amount": 1 - } - }, - "ips": [ - { - "ip": "10.12.144.32", - "version": 4, - "type": "PUBLIC" - } - ], - "networkTraffic": { - "type": "DATATRAFFIC", - "trafficType": "PREMIUM", - "datatrafficUnit": "TB", - "datatrafficLimit": 6 - } - }`) - }) - defer teardown() - - privateCloudApi := PrivateCloudApi{} - ctx := context.Background() - response, err := privateCloudApi.Get(ctx, "218030") - - assert := assert.New(t) - assert.Nil(err) - - assert.Equal(response.Id, "218030") - assert.Equal(response.CustomerId, "1301178860") - assert.Equal(response.DataCenter, "AMS-01") - assert.Equal(response.ServiceOffering, "FLAT_FEE") - assert.Equal(response.Sla, "Bronze") - assert.Equal(response.Contract.Id, "30000775") - assert.Equal(response.Contract.StartsAt, "2015-11-01T00:00:00+02:00") - assert.Equal(response.Contract.EndsAt, "2016-12-30T10:39:27+01:00") - assert.Equal(response.Contract.BillingCycle.String(), "12") - assert.Equal(response.Contract.BillingFrequency, "MONTH") - assert.Equal(response.Contract.PricePerFrequency.String(), "0") - assert.Equal(response.Contract.Currency, "EUR") - assert.Equal(response.Hardware.Cpu.Cores.String(), "25") - assert.Equal(response.Hardware.Memory.Amount.String(), "50") - assert.Equal(response.Hardware.Memory.Unit, "GB") - assert.Equal(response.Hardware.Storage.Amount.String(), "1") - assert.Equal(response.Hardware.Storage.Unit, "GB") - assert.Equal(response.Ips[0].Ip, "10.12.144.32") - assert.Equal(response.Ips[0].Type, "PUBLIC") - assert.Equal(response.Ips[0].Version.String(), "4") - assert.Equal(response.NetworkTraffic.DataTrafficLimit.String(), "6") - assert.Equal(response.NetworkTraffic.DataTrafficUnit, "TB") - assert.Equal(response.NetworkTraffic.TrafficType, "PREMIUM") - assert.Equal(response.NetworkTraffic.Type, "DATATRAFFIC") -} - -func TestPrivateCloudGetServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"errorCode": "ACCESS_DENIED", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return PrivateCloudApi{}.Get(ctx, "218030") - }, - ExpectedError: ApiError{ - Code: "ACCESS_DENIED", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusNotFound) - fmt.Fprintf(w, `{"errorCode": "404", "errorMessage": "Resource 218030 was not found", "userMessage": "Resource with id 218030 not found."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return PrivateCloudApi{}.Get(ctx, "218030") - }, - ExpectedError: ApiError{ - Code: "404", - Message: "Resource 218030 was not found", - UserMessage: "Resource with id 218030 not found.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"errorCode": "SERVER_ERROR", "errorMessage": "The server encountered an unexpected condition that prevented it from fulfilling the request."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return PrivateCloudApi{}.Get(ctx, "218030") - }, - ExpectedError: ApiError{ - Code: "SERVER_ERROR", - Message: "The server encountered an unexpected condition that prevented it from fulfilling the request.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"errorCode": "TEMPORARILY_UNAVAILABLE", "errorMessage": "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return PrivateCloudApi{}.Get(ctx, "218030") - }, - ExpectedError: ApiError{ - Code: "TEMPORARILY_UNAVAILABLE", - Message: "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestPrivateCloudListCredentials(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{"_metadata":{"limit": 10, "offset": 0, "totalCount": 1}, "credentials": [ - { - "type": "REMOTE_MANAGEMENT", - "username": "root", - "domain": "123456" - } - ]}`) - }) - defer teardown() - - privateCloudApi := PrivateCloudApi{} - ctx := context.Background() - response, err := privateCloudApi.ListCredentials(ctx, "12345678", "REMOTE_MANAGEMENT", PaginationOptions{}) - - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 1) - assert.Equal(response.Metadata.Offset, 0) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.Credentials), 1) - - credential := response.Credentials[0] - assert.Equal(credential.Type, "REMOTE_MANAGEMENT") - assert.Equal(credential.Username, "root") - assert.Equal(credential.Domain, "123456") -} - -func TestPrivateCloudListCredentialsBeEmpty(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{"_metadata":{"limit": 10, "offset": 0, "totalCount": 0}, "credentials": []}`) - }) - defer teardown() - - privateCloudApi := PrivateCloudApi{} - ctx := context.Background() - response, err := privateCloudApi.ListCredentials(ctx, "12345678", "REMOTE_MANAGEMENT", PaginationOptions{}) - - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 0) - assert.Equal(response.Metadata.Offset, 0) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.Credentials), 0) -} - -func TestPrivateCloudListCredentialsPaginate(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{"_metadata":{"limit": 10, "offset": 1, "totalCount": 11}, "credentials": [ - { - "type": "REMOTE_MANAGEMENT", - "username": "root", - "password": "password123", - "domain": "123456" - } - ]}`) - }) - defer teardown() - - privateCloudApi := PrivateCloudApi{} - ctx := context.Background() - opts := PaginationOptions{ - Limit: Int(1), - Offset: Int(10), - } - response, err := privateCloudApi.ListCredentials(ctx, "12345678", "REMOTE_MANAGEMENT", opts) - - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 11) - assert.Equal(response.Metadata.Offset, 1) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.Credentials), 1) - - credential := response.Credentials[0] - assert.Equal(credential.Type, "REMOTE_MANAGEMENT") - assert.Equal(credential.Username, "root") - assert.Equal(credential.Password, "password123") - assert.Equal(credential.Domain, "123456") -} - -func TestPrivateCloudListCredentialsServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"errorCode": "ACCESS_DENIED", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return PrivateCloudApi{}.ListCredentials(ctx, "12345678", "REMOTE_MANAGEMENT", PaginationOptions{}) - }, - ExpectedError: ApiError{ - Code: "ACCESS_DENIED", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusNotFound) - fmt.Fprintf(w, `{"errorCode": "404", "errorMessage": "Resource 218030 was not found", "userMessage": "Resource with id 218030 not found."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return PrivateCloudApi{}.ListCredentials(ctx, "12345678", "REMOTE_MANAGEMENT", PaginationOptions{}) - }, - ExpectedError: ApiError{ - Code: "404", - Message: "Resource 218030 was not found", - UserMessage: "Resource with id 218030 not found.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"errorCode": "SERVER_ERROR", "errorMessage": "The server encountered an unexpected condition that prevented it from fulfilling the request."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return PrivateCloudApi{}.ListCredentials(ctx, "12345678", "REMOTE_MANAGEMENT", PaginationOptions{}) - }, - ExpectedError: ApiError{ - Code: "SERVER_ERROR", - Message: "The server encountered an unexpected condition that prevented it from fulfilling the request.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"errorCode": "TEMPORARILY_UNAVAILABLE", "errorMessage": "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return PrivateCloudApi{}.ListCredentials(ctx, "12345678", "REMOTE_MANAGEMENT", PaginationOptions{}) - }, - ExpectedError: ApiError{ - Code: "TEMPORARILY_UNAVAILABLE", - Message: "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestPrivateCloudGetCredential(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "type": "REMOTE_MANAGEMENT", - "username": "root", - "password": "password123", - "domain": "123456" - }`) - }) - defer teardown() - - privateCloudApi := PrivateCloudApi{} - ctx := context.Background() - response, err := privateCloudApi.GetCredential(ctx, "218030", "REMOTE_MANAGEMENT", "root") - - assert := assert.New(t) - assert.Nil(err) - - assert.Equal(response.Type, "REMOTE_MANAGEMENT") - assert.Equal(response.Username, "root") - assert.Equal(response.Password, "password123") - assert.Equal(response.Domain, "123456") -} - -func TestPrivateCloudGetCredentialServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"errorCode": "ACCESS_DENIED", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return PrivateCloudApi{}.GetCredential(ctx, "218030", "REMOTE_MANAGEMENT", "root") - }, - ExpectedError: ApiError{ - Code: "ACCESS_DENIED", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusNotFound) - fmt.Fprintf(w, `{"errorCode": "404", "errorMessage": "Resource 218030 was not found", "userMessage": "Resource with id 218030 not found."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return PrivateCloudApi{}.GetCredential(ctx, "218030", "REMOTE_MANAGEMENT", "root") - }, - ExpectedError: ApiError{ - Code: "404", - Message: "Resource 218030 was not found", - UserMessage: "Resource with id 218030 not found.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"errorCode": "SERVER_ERROR", "errorMessage": "The server encountered an unexpected condition that prevented it from fulfilling the request."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return PrivateCloudApi{}.GetCredential(ctx, "218030", "REMOTE_MANAGEMENT", "root") - }, - ExpectedError: ApiError{ - Code: "SERVER_ERROR", - Message: "The server encountered an unexpected condition that prevented it from fulfilling the request.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"errorCode": "TEMPORARILY_UNAVAILABLE", "errorMessage": "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return PrivateCloudApi{}.GetCredential(ctx, "218030", "REMOTE_MANAGEMENT", "root") - }, - ExpectedError: ApiError{ - Code: "TEMPORARILY_UNAVAILABLE", - Message: "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestPrivateCloudGetDataTrafficMetrics(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "_metadata": { - "from": "2017-07-01T00:00:00+00:00", - "to": "2017-07-02T00:00:00+00:00", - "granularity": "MONTH", - "aggregation": "SUM" - }, - "metrics": { - "DATATRAFFIC_UP": { - "unit": "GB", - "values": [ - { - "timestamp": "2017-07-01T00:00:00+00:00", - "value": 900 - }, - { - "timestamp": "2017-07-02T00:00:00+00:00", - "value": 2500 - } - ] - }, - "DATATRAFFIC_DOWN": { - "unit": "GB", - "values": [ - { - "timestamp": "2017-07-01T00:00:00+00:00", - "value": 90 - }, - { - "timestamp": "2017-07-02T00:00:00+00:00", - "value": 250 - } - ] - } - } - }`) - }) - defer teardown() - - privateCloudApi := PrivateCloudApi{} - ctx := context.Background() - response, err := privateCloudApi.GetDataTrafficMetrics(ctx, "218030", MetricsOptions{}) - - assert := assert.New(t) - assert.Nil(err) - - assert.Equal(response.Metadata.From, "2017-07-01T00:00:00+00:00") - assert.Equal(response.Metadata.To, "2017-07-02T00:00:00+00:00") - assert.Equal(response.Metadata.Aggregation, "SUM") - assert.Equal(response.Metadata.Granularity, "MONTH") - assert.Equal(response.Metric.DownPublic.Unit, "GB") - assert.Equal(response.Metric.DownPublic.Values[0].Timestamp, "2017-07-01T00:00:00+00:00") - assert.Equal(response.Metric.DownPublic.Values[0].Value.String(), "90") - assert.Equal(response.Metric.DownPublic.Values[1].Timestamp, "2017-07-02T00:00:00+00:00") - assert.Equal(response.Metric.DownPublic.Values[1].Value.String(), "250") - assert.Equal(response.Metric.UpPublic.Unit, "GB") - assert.Equal(response.Metric.UpPublic.Values[0].Timestamp, "2017-07-01T00:00:00+00:00") - assert.Equal(response.Metric.UpPublic.Values[0].Value.String(), "900") - assert.Equal(response.Metric.UpPublic.Values[1].Timestamp, "2017-07-02T00:00:00+00:00") - assert.Equal(response.Metric.UpPublic.Values[1].Value.String(), "2500") -} - -func TestPrivateCloudGetDataTrafficMetricsWithFilter(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "_metadata": { - "from": "2017-07-01T00:00:00+00:00", - "to": "2017-07-02T00:00:00+00:00", - "granularity": "MONTH", - "aggregation": "SUM" - }, - "metrics": { - "DATATRAFFIC_UP": { - "unit": "GB", - "values": [ - { - "timestamp": "2017-07-01T00:00:00+00:00", - "value": 900 - }, - { - "timestamp": "2017-07-02T00:00:00+00:00", - "value": 2500 - } - ] - }, - "DATATRAFFIC_DOWN": { - "unit": "GB", - "values": [ - { - "timestamp": "2017-07-01T00:00:00+00:00", - "value": 90 - }, - { - "timestamp": "2017-07-02T00:00:00+00:00", - "value": 250 - } - ] - } - } - }`) - }) - defer teardown() - - privateCloudApi := PrivateCloudApi{} - ctx := context.Background() - opts := MetricsOptions{ - Granularity: String("MONTH"), - Aggregation: String("SUM"), - From: String("2017-07-01T00:00:00+00:00"), - To: String("2017-07-02T00:00:00+00:00"), - } - response, err := privateCloudApi.GetDataTrafficMetrics(ctx, "218030", opts) - - assert := assert.New(t) - assert.Nil(err) - - assert.Equal(response.Metadata.From, "2017-07-01T00:00:00+00:00") - assert.Equal(response.Metadata.To, "2017-07-02T00:00:00+00:00") - assert.Equal(response.Metadata.Aggregation, "SUM") - assert.Equal(response.Metadata.Granularity, "MONTH") - assert.Equal(response.Metric.DownPublic.Unit, "GB") - assert.Equal(response.Metric.DownPublic.Values[0].Timestamp, "2017-07-01T00:00:00+00:00") - assert.Equal(response.Metric.DownPublic.Values[0].Value.String(), "90") - assert.Equal(response.Metric.DownPublic.Values[1].Timestamp, "2017-07-02T00:00:00+00:00") - assert.Equal(response.Metric.DownPublic.Values[1].Value.String(), "250") - assert.Equal(response.Metric.UpPublic.Unit, "GB") - assert.Equal(response.Metric.UpPublic.Values[0].Timestamp, "2017-07-01T00:00:00+00:00") - assert.Equal(response.Metric.UpPublic.Values[0].Value.String(), "900") - assert.Equal(response.Metric.UpPublic.Values[1].Timestamp, "2017-07-02T00:00:00+00:00") - assert.Equal(response.Metric.UpPublic.Values[1].Value.String(), "2500") -} - -func TestPrivateCloudGetDataTrafficMetricsServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"errorCode": "ACCESS_DENIED", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return PrivateCloudApi{}.GetDataTrafficMetrics(ctx, "218030", MetricsOptions{}) - }, - ExpectedError: ApiError{ - Code: "ACCESS_DENIED", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusNotFound) - fmt.Fprintf(w, `{"errorCode": "404", "errorMessage": "Resource 218030 was not found", "userMessage": "Resource with id 218030 not found."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return PrivateCloudApi{}.GetDataTrafficMetrics(ctx, "218030", MetricsOptions{}) - }, - ExpectedError: ApiError{ - Code: "404", - Message: "Resource 218030 was not found", - UserMessage: "Resource with id 218030 not found.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"errorCode": "SERVER_ERROR", "errorMessage": "The server encountered an unexpected condition that prevented it from fulfilling the request."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return PrivateCloudApi{}.GetDataTrafficMetrics(ctx, "218030", MetricsOptions{}) - }, - ExpectedError: ApiError{ - Code: "SERVER_ERROR", - Message: "The server encountered an unexpected condition that prevented it from fulfilling the request.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"errorCode": "TEMPORARILY_UNAVAILABLE", "errorMessage": "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return PrivateCloudApi{}.GetDataTrafficMetrics(ctx, "218030", MetricsOptions{}) - }, - ExpectedError: ApiError{ - Code: "TEMPORARILY_UNAVAILABLE", - Message: "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestPrivateCloudGetBandWidthMetrics(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "_metadata": { - "from": "2017-07-01T00:00:00+00:00", - "to": "2017-07-02T00:00:00+00:00", - "granularity": "MONTH", - "aggregation": "AVG" - }, - "metrics": { - "DOWN_PUBLIC": { - "unit": "bps", - "values": [ - { - "timestamp": "2017-07-01T00:00:00+00:00", - "value": 28202556 - }, - { - "timestamp": "2017-07-02T00:00:00+00:00", - "value": 28202557 - } - ] - }, - "UP_PUBLIC": { - "unit": "bps", - "values": [ - { - "timestamp": "2017-07-01T00:00:00+00:00", - "value": 158317518 - }, - { - "timestamp": "2017-07-02T00:00:00+00:00", - "value": 158317519 - } - ] - } - } - }`) - }) - defer teardown() - - privateCloudApi := PrivateCloudApi{} - ctx := context.Background() - response, err := privateCloudApi.GetBandWidthMetrics(ctx, "218030", MetricsOptions{}) - - assert := assert.New(t) - assert.Nil(err) - - assert.Equal(response.Metadata.From, "2017-07-01T00:00:00+00:00") - assert.Equal(response.Metadata.To, "2017-07-02T00:00:00+00:00") - assert.Equal(response.Metadata.Aggregation, "AVG") - assert.Equal(response.Metadata.Granularity, "MONTH") - assert.Equal(response.Metric.DownPublic.Unit, "bps") - assert.Equal(response.Metric.DownPublic.Values[0].Timestamp, "2017-07-01T00:00:00+00:00") - assert.Equal(response.Metric.DownPublic.Values[0].Value.String(), "28202556") - assert.Equal(response.Metric.DownPublic.Values[1].Timestamp, "2017-07-02T00:00:00+00:00") - assert.Equal(response.Metric.DownPublic.Values[1].Value.String(), "28202557") - assert.Equal(response.Metric.UpPublic.Unit, "bps") - assert.Equal(response.Metric.UpPublic.Values[0].Timestamp, "2017-07-01T00:00:00+00:00") - assert.Equal(response.Metric.UpPublic.Values[0].Value.String(), "158317518") - assert.Equal(response.Metric.UpPublic.Values[1].Timestamp, "2017-07-02T00:00:00+00:00") - assert.Equal(response.Metric.UpPublic.Values[1].Value.String(), "158317519") -} - -func TestPrivateCloudGetBandWidthMetricsWithFilter(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "_metadata": { - "from": "2017-07-01T00:00:00+00:00", - "to": "2017-07-02T00:00:00+00:00", - "granularity": "MONTH", - "aggregation": "AVG" - }, - "metrics": { - "DOWN_PUBLIC": { - "unit": "bps", - "values": [ - { - "timestamp": "2017-07-01T00:00:00+00:00", - "value": 28202556 - }, - { - "timestamp": "2017-07-02T00:00:00+00:00", - "value": 28202557 - } - ] - }, - "UP_PUBLIC": { - "unit": "bps", - "values": [ - { - "timestamp": "2017-07-01T00:00:00+00:00", - "value": 158317518 - }, - { - "timestamp": "2017-07-02T00:00:00+00:00", - "value": 158317519 - } - ] - } - } - }`) - }) - defer teardown() - - privateCloudApi := PrivateCloudApi{} - ctx := context.Background() - opts := MetricsOptions{ - Granularity: String("MONTH"), - Aggregation: String("AVG"), - From: String("2017-07-01T00:00:00+00:00"), - To: String("2017-07-02T00:00:00+00:00"), - } - response, err := privateCloudApi.GetBandWidthMetrics(ctx, "218030", opts) - - assert := assert.New(t) - assert.Nil(err) - - assert.Equal(response.Metadata.From, "2017-07-01T00:00:00+00:00") - assert.Equal(response.Metadata.To, "2017-07-02T00:00:00+00:00") - assert.Equal(response.Metadata.Aggregation, "AVG") - assert.Equal(response.Metadata.Granularity, "MONTH") - assert.Equal(response.Metric.DownPublic.Unit, "bps") - assert.Equal(response.Metric.DownPublic.Values[0].Timestamp, "2017-07-01T00:00:00+00:00") - assert.Equal(response.Metric.DownPublic.Values[0].Value.String(), "28202556") - assert.Equal(response.Metric.DownPublic.Values[1].Timestamp, "2017-07-02T00:00:00+00:00") - assert.Equal(response.Metric.DownPublic.Values[1].Value.String(), "28202557") - assert.Equal(response.Metric.UpPublic.Unit, "bps") - assert.Equal(response.Metric.UpPublic.Values[0].Timestamp, "2017-07-01T00:00:00+00:00") - assert.Equal(response.Metric.UpPublic.Values[0].Value.String(), "158317518") - assert.Equal(response.Metric.UpPublic.Values[1].Timestamp, "2017-07-02T00:00:00+00:00") - assert.Equal(response.Metric.UpPublic.Values[1].Value.String(), "158317519") -} - -func TestPrivateCloudGetBandWidthMetricsServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"errorCode": "ACCESS_DENIED", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return PrivateCloudApi{}.GetBandWidthMetrics(ctx, "218030", MetricsOptions{}) - }, - ExpectedError: ApiError{ - Code: "ACCESS_DENIED", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusNotFound) - fmt.Fprintf(w, `{"errorCode": "404", "errorMessage": "Resource 218030 was not found", "userMessage": "Resource with id 218030 not found."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return PrivateCloudApi{}.GetBandWidthMetrics(ctx, "218030", MetricsOptions{}) - }, - ExpectedError: ApiError{ - Code: "404", - Message: "Resource 218030 was not found", - UserMessage: "Resource with id 218030 not found.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"errorCode": "SERVER_ERROR", "errorMessage": "The server encountered an unexpected condition that prevented it from fulfilling the request."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return PrivateCloudApi{}.GetBandWidthMetrics(ctx, "218030", MetricsOptions{}) - }, - ExpectedError: ApiError{ - Code: "SERVER_ERROR", - Message: "The server encountered an unexpected condition that prevented it from fulfilling the request.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"errorCode": "TEMPORARILY_UNAVAILABLE", "errorMessage": "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return PrivateCloudApi{}.GetBandWidthMetrics(ctx, "218030", MetricsOptions{}) - }, - ExpectedError: ApiError{ - Code: "TEMPORARILY_UNAVAILABLE", - Message: "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestPrivateCloudGetCpuMetrics(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "_metadata": { - "from": "2017-07-01T00:00:00+00:00", - "to": "2017-07-01T00:00:00+00:00", - "granularity": "MONTH", - "aggregation": "MAX" - }, - "metrics": { - "CPU": { - "unit": "CORES", - "values": [ - { - "timestamp": "2017-07-01T00:00:00+00:00", - "value": 24 - }, - { - "timestamp": "2017-07-02T00:00:00+00:00", - "value": 24 - } - ] - } - } - }`) - }) - defer teardown() - - privateCloudApi := PrivateCloudApi{} - ctx := context.Background() - response, err := privateCloudApi.GetCpuMetrics(ctx, "218030", MetricsOptions{}) - - assert := assert.New(t) - assert.Nil(err) - - assert.Equal(response.Metadata.From, "2017-07-01T00:00:00+00:00") - assert.Equal(response.Metadata.To, "2017-07-01T00:00:00+00:00") - assert.Equal(response.Metadata.Aggregation, "MAX") - assert.Equal(response.Metadata.Granularity, "MONTH") - assert.Equal(response.Metric.Cpu.Unit, "CORES") - assert.Equal(response.Metric.Cpu.Values[0].Timestamp, "2017-07-01T00:00:00+00:00") - assert.Equal(response.Metric.Cpu.Values[0].Value.String(), "24") - assert.Equal(response.Metric.Cpu.Values[1].Timestamp, "2017-07-02T00:00:00+00:00") - assert.Equal(response.Metric.Cpu.Values[1].Value.String(), "24") -} - -func TestPrivateCloudGetCpuMetricsWithFilter(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "_metadata": { - "from": "2017-07-01T00:00:00+00:00", - "to": "2017-07-02T00:00:00+00:00", - "granularity": "MONTH", - "aggregation": "MAX" - }, - "metrics": { - "CPU": { - "unit": "CORES", - "values": [ - { - "timestamp": "2017-07-01T00:00:00+00:00", - "value": 24 - }, - { - "timestamp": "2017-07-02T00:00:00+00:00", - "value": 24 - } - ] - } - } - }`) - }) - defer teardown() - - privateCloudApi := PrivateCloudApi{} - ctx := context.Background() - opts := MetricsOptions{ - Granularity: String("MONTH"), - Aggregation: String("MAX"), - From: String("2017-07-01T00:00:00+00:00"), - To: String("2017-07-02T00:00:00+00:00"), - } - response, err := privateCloudApi.GetCpuMetrics(ctx, "218030", opts) - - assert := assert.New(t) - assert.Nil(err) - - assert.Equal(response.Metadata.From, "2017-07-01T00:00:00+00:00") - assert.Equal(response.Metadata.To, "2017-07-02T00:00:00+00:00") - assert.Equal(response.Metadata.Aggregation, "MAX") - assert.Equal(response.Metadata.Granularity, "MONTH") - assert.Equal(response.Metric.Cpu.Unit, "CORES") - assert.Equal(response.Metric.Cpu.Values[0].Timestamp, "2017-07-01T00:00:00+00:00") - assert.Equal(response.Metric.Cpu.Values[0].Value.String(), "24") - assert.Equal(response.Metric.Cpu.Values[1].Timestamp, "2017-07-02T00:00:00+00:00") - assert.Equal(response.Metric.Cpu.Values[1].Value.String(), "24") -} - -func TestPrivateCloudGetCpuMetricsServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"errorCode": "ACCESS_DENIED", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return PrivateCloudApi{}.GetCpuMetrics(ctx, "218030", MetricsOptions{}) - }, - ExpectedError: ApiError{ - Code: "ACCESS_DENIED", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusNotFound) - fmt.Fprintf(w, `{"errorCode": "404", "errorMessage": "Resource 218030 was not found", "userMessage": "Resource with id 218030 not found."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return PrivateCloudApi{}.GetCpuMetrics(ctx, "218030", MetricsOptions{}) - }, - ExpectedError: ApiError{ - Code: "404", - Message: "Resource 218030 was not found", - UserMessage: "Resource with id 218030 not found.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"errorCode": "SERVER_ERROR", "errorMessage": "The server encountered an unexpected condition that prevented it from fulfilling the request."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return PrivateCloudApi{}.GetCpuMetrics(ctx, "218030", MetricsOptions{}) - }, - ExpectedError: ApiError{ - Code: "SERVER_ERROR", - Message: "The server encountered an unexpected condition that prevented it from fulfilling the request.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"errorCode": "TEMPORARILY_UNAVAILABLE", "errorMessage": "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return PrivateCloudApi{}.GetCpuMetrics(ctx, "218030", MetricsOptions{}) - }, - ExpectedError: ApiError{ - Code: "TEMPORARILY_UNAVAILABLE", - Message: "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestPrivateCloudGetMemoryMetrics(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "_metadata": { - "from": "2017-07-01T00:00:00+00:00", - "to": "2017-07-02T00:00:00+00:00", - "granularity": "MONTH", - "aggregation": "MAX" - }, - "metrics": { - "MEMORY": { - "unit": "GB", - "values": [ - { - "timestamp": "2017-07-01T00:00:00+00:00", - "value": 8 - }, - { - "timestamp": "2017-07-02T00:00:00+00:00", - "value": 16 - } - ] - } - } - }`) - }) - defer teardown() - - privateCloudApi := PrivateCloudApi{} - ctx := context.Background() - response, err := privateCloudApi.GetMemoryMetrics(ctx, "218030", MetricsOptions{}) - - assert := assert.New(t) - assert.Nil(err) - - assert.Equal(response.Metadata.From, "2017-07-01T00:00:00+00:00") - assert.Equal(response.Metadata.To, "2017-07-02T00:00:00+00:00") - assert.Equal(response.Metadata.Aggregation, "MAX") - assert.Equal(response.Metadata.Granularity, "MONTH") - assert.Equal(response.Metric.Memory.Unit, "GB") - assert.Equal(response.Metric.Memory.Values[0].Timestamp, "2017-07-01T00:00:00+00:00") - assert.Equal(response.Metric.Memory.Values[0].Value.String(), "8") - assert.Equal(response.Metric.Memory.Values[1].Timestamp, "2017-07-02T00:00:00+00:00") - assert.Equal(response.Metric.Memory.Values[1].Value.String(), "16") -} - -func TestPrivateCloudGetMemoryMetricsWithFilter(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "_metadata": { - "from": "2017-07-01T00:00:00+00:00", - "to": "2017-07-02T00:00:00+00:00", - "granularity": "MONTH", - "aggregation": "MAX" - }, - "metrics": { - "MEMORY": { - "unit": "GB", - "values": [ - { - "timestamp": "2017-07-01T00:00:00+00:00", - "value": 8 - }, - { - "timestamp": "2017-07-02T00:00:00+00:00", - "value": 16 - } - ] - } - } - }`) - }) - defer teardown() - - privateCloudApi := PrivateCloudApi{} - ctx := context.Background() - opts := MetricsOptions{ - Granularity: String("MONTH"), - Aggregation: String("MAX"), - From: String("2017-07-01T00:00:00+00:00"), - To: String("2017-07-02T00:00:00+00:00"), - } - response, err := privateCloudApi.GetMemoryMetrics(ctx, "218030", opts) - - assert := assert.New(t) - assert.Nil(err) - - assert.Equal(response.Metadata.From, "2017-07-01T00:00:00+00:00") - assert.Equal(response.Metadata.To, "2017-07-02T00:00:00+00:00") - assert.Equal(response.Metadata.Aggregation, "MAX") - assert.Equal(response.Metadata.Granularity, "MONTH") - assert.Equal(response.Metric.Memory.Unit, "GB") - assert.Equal(response.Metric.Memory.Values[0].Timestamp, "2017-07-01T00:00:00+00:00") - assert.Equal(response.Metric.Memory.Values[0].Value.String(), "8") - assert.Equal(response.Metric.Memory.Values[1].Timestamp, "2017-07-02T00:00:00+00:00") - assert.Equal(response.Metric.Memory.Values[1].Value.String(), "16") -} - -func TestPrivateCloudGetMemoryMetricsServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"errorCode": "ACCESS_DENIED", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return PrivateCloudApi{}.GetMemoryMetrics(ctx, "218030", MetricsOptions{}) - }, - ExpectedError: ApiError{ - Code: "ACCESS_DENIED", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusNotFound) - fmt.Fprintf(w, `{"errorCode": "404", "errorMessage": "Resource 218030 was not found", "userMessage": "Resource with id 218030 not found."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return PrivateCloudApi{}.GetMemoryMetrics(ctx, "218030", MetricsOptions{}) - }, - ExpectedError: ApiError{ - Code: "404", - Message: "Resource 218030 was not found", - UserMessage: "Resource with id 218030 not found.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"errorCode": "SERVER_ERROR", "errorMessage": "The server encountered an unexpected condition that prevented it from fulfilling the request."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return PrivateCloudApi{}.GetMemoryMetrics(ctx, "218030", MetricsOptions{}) - }, - ExpectedError: ApiError{ - Code: "SERVER_ERROR", - Message: "The server encountered an unexpected condition that prevented it from fulfilling the request.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"errorCode": "TEMPORARILY_UNAVAILABLE", "errorMessage": "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return PrivateCloudApi{}.GetMemoryMetrics(ctx, "218030", MetricsOptions{}) - }, - ExpectedError: ApiError{ - Code: "TEMPORARILY_UNAVAILABLE", - Message: "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestPrivateCloudGetStorageMetrics(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "_metadata": { - "from": "2017-07-01T00:00:00+00:00", - "to": "2017-07-02T00:00:00+00:00", - "granularity": "MONTH", - "aggregation": "MAX" - }, - "metrics": { - "STORAGE": { - "unit": "GB", - "values": [ - { - "timestamp": "2017-07-01T00:00:00+00:00", - "value": 900 - }, - { - "timestamp": "2017-07-02T00:00:00+00:00", - "value": 2500 - } - ] - } - } - }`) - }) - defer teardown() - - privateCloudApi := PrivateCloudApi{} - ctx := context.Background() - response, err := privateCloudApi.GetStorageMetrics(ctx, "218030", MetricsOptions{}) - - assert := assert.New(t) - assert.Nil(err) - - assert.Equal(response.Metadata.From, "2017-07-01T00:00:00+00:00") - assert.Equal(response.Metadata.To, "2017-07-02T00:00:00+00:00") - assert.Equal(response.Metadata.Aggregation, "MAX") - assert.Equal(response.Metadata.Granularity, "MONTH") - assert.Equal(response.Metric.Storage.Unit, "GB") - assert.Equal(response.Metric.Storage.Values[0].Timestamp, "2017-07-01T00:00:00+00:00") - assert.Equal(response.Metric.Storage.Values[0].Value.String(), "900") - assert.Equal(response.Metric.Storage.Values[1].Timestamp, "2017-07-02T00:00:00+00:00") - assert.Equal(response.Metric.Storage.Values[1].Value.String(), "2500") -} - -func TestPrivateCloudGetStorageMetricsWithFilter(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "_metadata": { - "from": "2017-07-01T00:00:00+00:00", - "to": "2017-07-02T00:00:00+00:00", - "granularity": "MONTH", - "aggregation": "MAX" - }, - "metrics": { - "STORAGE": { - "unit": "GB", - "values": [ - { - "timestamp": "2017-07-01T00:00:00+00:00", - "value": 900 - }, - { - "timestamp": "2017-07-02T00:00:00+00:00", - "value": 2500 - } - ] - } - } - }`) - }) - defer teardown() - - privateCloudApi := PrivateCloudApi{} - ctx := context.Background() - opts := MetricsOptions{ - Granularity: String("MONTH"), - Aggregation: String("MAX"), - From: String("2017-07-01T00:00:00+00:00"), - To: String("2017-07-02T00:00:00+00:00"), - } - response, err := privateCloudApi.GetStorageMetrics(ctx, "218030", opts) - - assert := assert.New(t) - assert.Nil(err) - - assert.Equal(response.Metadata.From, "2017-07-01T00:00:00+00:00") - assert.Equal(response.Metadata.To, "2017-07-02T00:00:00+00:00") - assert.Equal(response.Metadata.Aggregation, "MAX") - assert.Equal(response.Metadata.Granularity, "MONTH") - assert.Equal(response.Metric.Storage.Unit, "GB") - assert.Equal(response.Metric.Storage.Values[0].Timestamp, "2017-07-01T00:00:00+00:00") - assert.Equal(response.Metric.Storage.Values[0].Value.String(), "900") - assert.Equal(response.Metric.Storage.Values[1].Timestamp, "2017-07-02T00:00:00+00:00") - assert.Equal(response.Metric.Storage.Values[1].Value.String(), "2500") -} - -func TestPrivateCloudGetStorageMetricsServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"errorCode": "ACCESS_DENIED", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return PrivateCloudApi{}.GetStorageMetrics(ctx, "218030", MetricsOptions{}) - }, - ExpectedError: ApiError{ - Code: "ACCESS_DENIED", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusNotFound) - fmt.Fprintf(w, `{"errorCode": "404", "errorMessage": "Resource 218030 was not found", "userMessage": "Resource with id 218030 not found."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return PrivateCloudApi{}.GetStorageMetrics(ctx, "218030", MetricsOptions{}) - }, - ExpectedError: ApiError{ - Code: "404", - Message: "Resource 218030 was not found", - UserMessage: "Resource with id 218030 not found.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"errorCode": "SERVER_ERROR", "errorMessage": "The server encountered an unexpected condition that prevented it from fulfilling the request."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return PrivateCloudApi{}.GetStorageMetrics(ctx, "218030", MetricsOptions{}) - }, - ExpectedError: ApiError{ - Code: "SERVER_ERROR", - Message: "The server encountered an unexpected condition that prevented it from fulfilling the request.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"errorCode": "TEMPORARILY_UNAVAILABLE", "errorMessage": "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return PrivateCloudApi{}.GetStorageMetrics(ctx, "218030", MetricsOptions{}) - }, - ExpectedError: ApiError{ - Code: "TEMPORARILY_UNAVAILABLE", - Message: "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} diff --git a/private_networking.go b/private_networking.go deleted file mode 100644 index 28cd950..0000000 --- a/private_networking.go +++ /dev/null @@ -1,109 +0,0 @@ -package leaseweb - -import ( - "context" - "net/http" - - "github.com/LeaseWeb/leaseweb-go-sdk/options" -) - -const PRIVATE_NETWORKING_API_VERSION = "v2" - -type PrivateNetworkingApi struct{} - -type PrivateNetworks struct { - PrivateNetworks []PrivateNetwork `json:"privateNetworks"` - Metadata Metadata `json:"_metadata"` -} - -type PrivateNetworkingDhcpReservations struct { - DhcpReservations []PrivateNetworkingDhcpReservation `json:"reservations"` - Metadata Metadata `json:"_metadata"` -} - -type PrivateNetworkingDhcpReservation struct { - Ip string `json:"ip"` - Mac string `json:"mac"` - Sticky bool `json:"sticky"` -} - -func (pna PrivateNetworkingApi) getPath(endpoint string) string { - return "/bareMetals/" + PRIVATE_NETWORKING_API_VERSION + endpoint -} - -func (pna PrivateNetworkingApi) List(ctx context.Context, opts PaginationOptions) (*PrivateNetworks, error) { - path := pna.getPath("/privateNetworks") - query := options.Encode(opts) - result := &PrivateNetworks{} - if err := doRequest(ctx, http.MethodGet, path, query, result); err != nil { - return nil, err - } - return result, nil -} - -func (pna PrivateNetworkingApi) Create(ctx context.Context, name string) (*PrivateNetwork, error) { - payload := map[string]string{ - "name": name, - } - path := pna.getPath("/privateNetworks") - result := &PrivateNetwork{} - if err := doRequest(ctx, http.MethodPost, path, "", result, payload); err != nil { - return nil, err - } - return result, nil -} - -func (pna PrivateNetworkingApi) Get(ctx context.Context, id string) (*PrivateNetwork, error) { - path := pna.getPath("/privateNetworks/" + id) - result := &PrivateNetwork{} - if err := doRequest(ctx, http.MethodGet, path, "", result); err != nil { - return nil, err - } - return result, nil -} - -func (pna PrivateNetworkingApi) Update(ctx context.Context, id, name string) (*PrivateNetwork, error) { - payload := map[string]string{ - "name": name, - } - path := pna.getPath("/privateNetworks") - result := &PrivateNetwork{} - if err := doRequest(ctx, http.MethodPut, path, "", result, payload); err != nil { - return nil, err - } - return result, nil -} - -func (pna PrivateNetworkingApi) Delete(ctx context.Context, id string) error { - path := pna.getPath("/privateNetworks/" + id) - return doRequest(ctx, http.MethodDelete, path, "") -} - -func (pna PrivateNetworkingApi) ListDhcpReservations(ctx context.Context, id string, opts PaginationOptions) (*PrivateNetworkingDhcpReservations, error) { - path := pna.getPath("/privateNetworks/" + id + "/reservations") - result := &PrivateNetworkingDhcpReservations{} - query := options.Encode(opts) - if err := doRequest(ctx, http.MethodGet, path, query, result); err != nil { - return nil, err - } - return result, nil -} - -func (pna PrivateNetworkingApi) CreateDhcpReservation(ctx context.Context, id, ip, mac string, sticky bool) (*PrivateNetworkingDhcpReservation, error) { - payload := map[string]interface{}{ - "ip": ip, - "mac": mac, - "sticky": sticky, - } - path := pna.getPath("/privateNetworks/" + id + "/reservations") - result := &PrivateNetworkingDhcpReservation{} - if err := doRequest(ctx, http.MethodPost, path, "", result, payload); err != nil { - return nil, err - } - return result, nil -} - -func (pna PrivateNetworkingApi) DeleteDhcpReservation(ctx context.Context, id, ip string) error { - path := pna.getPath("/privateNetworks/" + id + "/reservations/" + ip) - return doRequest(ctx, http.MethodDelete, path, "") -} diff --git a/private_networking_test.go b/private_networking_test.go deleted file mode 100644 index 02c8fd0..0000000 --- a/private_networking_test.go +++ /dev/null @@ -1,928 +0,0 @@ -package leaseweb - -import ( - "context" - "fmt" - "net/http" - "testing" - - "github.com/stretchr/testify/assert" -) - -func TestPrivateNetworkList(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "_metadata": { - "totalCount": 1, - "limit": 10, - "offset": 0 - }, - "privateNetworks": [ - { - "equipmentCount": 4, - "id": "811", - "name": "default", - "createdAt": "2015-07-16T13:06:45+0200", - "updatedAt": "2015-07-16T13:06:45+0200" - } - ] - }`) - }) - defer teardown() - - ctx := context.Background() - response, err := PrivateNetworkingApi{}.List(ctx, PaginationOptions{}) - - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 1) - assert.Equal(response.Metadata.Offset, 0) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.PrivateNetworks), 1) - - PrivateNetwork := response.PrivateNetworks[0] - assert.Equal(PrivateNetwork.EquipmentCount.String(), "4") - assert.Equal(PrivateNetwork.Id, "811") - assert.Equal(PrivateNetwork.Name, "default") - assert.Equal(PrivateNetwork.CreatedAt, "2015-07-16T13:06:45+0200") - assert.Equal(PrivateNetwork.UpdatedAt, "2015-07-16T13:06:45+0200") -} - -func TestPrivateNetworkListPaginate(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "_metadata": { - "totalCount": 11, - "limit": 10, - "offset": 1 - }, - "privateNetworks": [ - { - "equipmentCount": 4, - "id": "811", - "name": "default", - "createdAt": "2015-07-16T13:06:45+0200", - "updatedAt": "2015-07-16T13:06:45+0200" - } - ] - }`) - }) - defer teardown() - - ctx := context.Background() - opts := PaginationOptions{ - Limit: Int(1), - } - response, err := PrivateNetworkingApi{}.List(ctx, opts) - - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 11) - assert.Equal(response.Metadata.Offset, 1) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.PrivateNetworks), 1) - - PrivateNetwork := response.PrivateNetworks[0] - assert.Equal(PrivateNetwork.EquipmentCount.String(), "4") - assert.Equal(PrivateNetwork.Id, "811") - assert.Equal(PrivateNetwork.Name, "default") - assert.Equal(PrivateNetwork.CreatedAt, "2015-07-16T13:06:45+0200") - assert.Equal(PrivateNetwork.UpdatedAt, "2015-07-16T13:06:45+0200") -} - -func TestPrivateNetworkListServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return PrivateNetworkingApi{}.List(ctx, PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "ACCESS_DENIED", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return PrivateNetworkingApi{}.List(ctx, PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "ACCESS_DENIED", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "SERVER_ERROR", "errorMessage": "The server encountered an unexpected condition that prevented it from fulfilling the request."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return PrivateNetworkingApi{}.List(ctx, PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "SERVER_ERROR", - Message: "The server encountered an unexpected condition that prevented it from fulfilling the request.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "TEMPORARILY_UNAVAILABLE", "errorMessage": "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return PrivateNetworkingApi{}.List(ctx, PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "TEMPORARILY_UNAVAILABLE", - Message: "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestPrivateNetworkCreate(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "id": "12345", - "name": "production", - "createdAt": "2015-01-21T14:34:12+0000", - "updatedAt": "2015-01-21T14:34:12+0000", - "equipmentCount": 0, - "servers": [] - }`) - }) - defer teardown() - - ctx := context.Background() - PrivateNetwork, err := PrivateNetworkingApi{}.Create(ctx, "production") - - assert := assert.New(t) - assert.Nil(err) - assert.Equal(PrivateNetwork.EquipmentCount.String(), "0") - assert.Equal(PrivateNetwork.Id, "12345") - assert.Equal(PrivateNetwork.Name, "production") - assert.Equal(PrivateNetwork.CreatedAt, "2015-01-21T14:34:12+0000") - assert.Equal(PrivateNetwork.UpdatedAt, "2015-01-21T14:34:12+0000") - assert.Equal(len(PrivateNetwork.Servers), 0) -} - -func TestPrivateNetworkCreateServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return PrivateNetworkingApi{}.Create(ctx, "production") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "ACCESS_DENIED", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return PrivateNetworkingApi{}.Create(ctx, "production") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "ACCESS_DENIED", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "SERVER_ERROR", "errorMessage": "The server encountered an unexpected condition that prevented it from fulfilling the request."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return PrivateNetworkingApi{}.Create(ctx, "production") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "SERVER_ERROR", - Message: "The server encountered an unexpected condition that prevented it from fulfilling the request.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "TEMPORARILY_UNAVAILABLE", "errorMessage": "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return PrivateNetworkingApi{}.Create(ctx, "production") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "TEMPORARILY_UNAVAILABLE", - Message: "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestPrivateNetworkGet(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "id": "12345", - "name": "default", - "createdAt": "2015-01-21T14:34:12+0000", - "updatedAt": "2015-01-21T14:34:12+0000" - }`) - }) - defer teardown() - - ctx := context.Background() - PrivateNetwork, err := PrivateNetworkingApi{}.Get(ctx, "12345") - - assert := assert.New(t) - assert.Nil(err) - assert.Equal(PrivateNetwork.Id, "12345") - assert.Equal(PrivateNetwork.Name, "default") - assert.Equal(PrivateNetwork.CreatedAt, "2015-01-21T14:34:12+0000") - assert.Equal(PrivateNetwork.UpdatedAt, "2015-01-21T14:34:12+0000") -} - -func TestPrivateNetworkGetServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return PrivateNetworkingApi{}.Get(ctx, "12345") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "ACCESS_DENIED", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return PrivateNetworkingApi{}.Get(ctx, "12345") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "ACCESS_DENIED", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "SERVER_ERROR", "errorMessage": "The server encountered an unexpected condition that prevented it from fulfilling the request."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return PrivateNetworkingApi{}.Get(ctx, "12345") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "SERVER_ERROR", - Message: "The server encountered an unexpected condition that prevented it from fulfilling the request.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "TEMPORARILY_UNAVAILABLE", "errorMessage": "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return PrivateNetworkingApi{}.Get(ctx, "12345") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "TEMPORARILY_UNAVAILABLE", - Message: "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestPrivateNetworkUpdate(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "id": "12345", - "name": "production", - "createdAt": "2015-01-21T14:34:12+0000", - "updatedAt": "2015-01-21T14:34:12+0000", - "equipmentCount": 0, - "servers": [] - }`) - }) - defer teardown() - - ctx := context.Background() - PrivateNetwork, err := PrivateNetworkingApi{}.Update(ctx, "12345", "production") - - assert := assert.New(t) - assert.Nil(err) - assert.Equal(PrivateNetwork.EquipmentCount.String(), "0") - assert.Equal(PrivateNetwork.Id, "12345") - assert.Equal(PrivateNetwork.Name, "production") - assert.Equal(PrivateNetwork.CreatedAt, "2015-01-21T14:34:12+0000") - assert.Equal(PrivateNetwork.UpdatedAt, "2015-01-21T14:34:12+0000") - assert.Equal(len(PrivateNetwork.Servers), 0) -} - -func TestPrivateNetworkUpdateServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return PrivateNetworkingApi{}.Update(ctx, "12345", "production") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "ACCESS_DENIED", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return PrivateNetworkingApi{}.Update(ctx, "12345", "production") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "ACCESS_DENIED", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "SERVER_ERROR", "errorMessage": "The server encountered an unexpected condition that prevented it from fulfilling the request."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return PrivateNetworkingApi{}.Update(ctx, "12345", "production") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "SERVER_ERROR", - Message: "The server encountered an unexpected condition that prevented it from fulfilling the request.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "TEMPORARILY_UNAVAILABLE", "errorMessage": "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return PrivateNetworkingApi{}.Update(ctx, "12345", "production") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "TEMPORARILY_UNAVAILABLE", - Message: "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestPrivateNetworkDelete(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusNoContent) - }) - defer teardown() - - ctx := context.Background() - err := PrivateNetworkingApi{}.Delete(ctx, "12345") - - assert := assert.New(t) - assert.Nil(err) -} - -func TestPrivateNetworkDeleteServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, PrivateNetworkingApi{}.Delete(ctx, "12345") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "ACCESS_DENIED", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, PrivateNetworkingApi{}.Delete(ctx, "12345") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "ACCESS_DENIED", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "SERVER_ERROR", "errorMessage": "The server encountered an unexpected condition that prevented it from fulfilling the request."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, PrivateNetworkingApi{}.Delete(ctx, "12345") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "SERVER_ERROR", - Message: "The server encountered an unexpected condition that prevented it from fulfilling the request.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "TEMPORARILY_UNAVAILABLE", "errorMessage": "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, PrivateNetworkingApi{}.Delete(ctx, "12345") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "TEMPORARILY_UNAVAILABLE", - Message: "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestPrivateNetworkListDhcpReservations(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "_metadata": { - "limit": 10, - "offset": 0, - "totalCount": 1 - }, - "reservations": [ - { - "ip": "127.0.0.1", - "mac": "d8:87:03:52:0a:0f", - "sticky": true - } - ] - }`) - }) - defer teardown() - - ctx := context.Background() - response, err := PrivateNetworkingApi{}.ListDhcpReservations(ctx, "12345", PaginationOptions{}) - - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 1) - assert.Equal(response.Metadata.Offset, 0) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.DhcpReservations), 1) - - DhcpReservation := response.DhcpReservations[0] - assert.Equal(DhcpReservation.Ip, "127.0.0.1") - assert.Equal(DhcpReservation.Mac, "d8:87:03:52:0a:0f") - assert.Equal(DhcpReservation.Sticky, true) -} - -func TestPrivateNetworkListDhcpReservationsPaginate(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "_metadata": { - "limit": 10, - "offset": 1, - "totalCount": 11 - }, - "reservations": [ - { - "ip": "127.0.0.1", - "mac": "d8:87:03:52:0a:0f", - "sticky": true - } - ] - }`) - }) - defer teardown() - - ctx := context.Background() - opts := PaginationOptions{ - Limit: Int(1), - } - response, err := PrivateNetworkingApi{}.ListDhcpReservations(ctx, "12345", opts) - - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 11) - assert.Equal(response.Metadata.Offset, 1) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.DhcpReservations), 1) - - DhcpReservation := response.DhcpReservations[0] - assert.Equal(DhcpReservation.Ip, "127.0.0.1") - assert.Equal(DhcpReservation.Mac, "d8:87:03:52:0a:0f") - assert.Equal(DhcpReservation.Sticky, true) -} - -func TestPrivateNetworkListDhcpReservationsServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return PrivateNetworkingApi{}.ListDhcpReservations(ctx, "12345", PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "ACCESS_DENIED", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return PrivateNetworkingApi{}.ListDhcpReservations(ctx, "12345", PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "ACCESS_DENIED", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "SERVER_ERROR", "errorMessage": "The server encountered an unexpected condition that prevented it from fulfilling the request."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return PrivateNetworkingApi{}.ListDhcpReservations(ctx, "12345", PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "SERVER_ERROR", - Message: "The server encountered an unexpected condition that prevented it from fulfilling the request.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "TEMPORARILY_UNAVAILABLE", "errorMessage": "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return PrivateNetworkingApi{}.ListDhcpReservations(ctx, "12345", PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "TEMPORARILY_UNAVAILABLE", - Message: "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestPrivateNetworkCreateDhcpReservation(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "ip": "127.0.0.1", - "mac": "d8:87:03:52:0a:0f", - "sticky": true - }`) - }) - defer teardown() - - ctx := context.Background() - DhcpReservation, err := PrivateNetworkingApi{}.CreateDhcpReservation(ctx, "12345", "127.0.0.1", "d8:87:03:52:0a:0f", true) - - assert := assert.New(t) - assert.Nil(err) - assert.Equal(DhcpReservation.Ip, "127.0.0.1") - assert.Equal(DhcpReservation.Mac, "d8:87:03:52:0a:0f") - assert.Equal(DhcpReservation.Sticky, true) -} - -func TestPrivateNetworkCreateDhcpReservationServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return PrivateNetworkingApi{}.CreateDhcpReservation(ctx, "12345", "127.0.0.1", "d8:87:03:52:0a:0f", true) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "ACCESS_DENIED", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return PrivateNetworkingApi{}.CreateDhcpReservation(ctx, "12345", "127.0.0.1", "d8:87:03:52:0a:0f", true) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "ACCESS_DENIED", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "SERVER_ERROR", "errorMessage": "The server encountered an unexpected condition that prevented it from fulfilling the request."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return PrivateNetworkingApi{}.CreateDhcpReservation(ctx, "12345", "127.0.0.1", "d8:87:03:52:0a:0f", true) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "SERVER_ERROR", - Message: "The server encountered an unexpected condition that prevented it from fulfilling the request.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "TEMPORARILY_UNAVAILABLE", "errorMessage": "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return PrivateNetworkingApi{}.CreateDhcpReservation(ctx, "12345", "127.0.0.1", "d8:87:03:52:0a:0f", true) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "TEMPORARILY_UNAVAILABLE", - Message: "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestPrivateNetworkDeleteDhcpReservation(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusNoContent) - }) - defer teardown() - - ctx := context.Background() - err := PrivateNetworkingApi{}.DeleteDhcpReservation(ctx, "12345", "127.0.0.1") - - assert := assert.New(t) - assert.Nil(err) -} - -func TestPrivateNetworkDeleteDhcpReservationServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, PrivateNetworkingApi{}.DeleteDhcpReservation(ctx, "12345", "127.0.0.1") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "ACCESS_DENIED", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, PrivateNetworkingApi{}.DeleteDhcpReservation(ctx, "12345", "127.0.0.1") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "ACCESS_DENIED", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "SERVER_ERROR", "errorMessage": "The server encountered an unexpected condition that prevented it from fulfilling the request."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, PrivateNetworkingApi{}.DeleteDhcpReservation(ctx, "12345", "127.0.0.1") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "SERVER_ERROR", - Message: "The server encountered an unexpected condition that prevented it from fulfilling the request.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodDelete, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "TEMPORARILY_UNAVAILABLE", "errorMessage": "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, PrivateNetworkingApi{}.DeleteDhcpReservation(ctx, "12345", "127.0.0.1") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "TEMPORARILY_UNAVAILABLE", - Message: "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} diff --git a/publicCloud/README.md b/publicCloud/README.md new file mode 100644 index 0000000..b998bff --- /dev/null +++ b/publicCloud/README.md @@ -0,0 +1,276 @@ +# Go API client for publicCloud + +> The base URL for this API is: **https://api.leaseweb.com/publicCloud/v1/_** + +This API provides ways to launch and manage Public Cloud instances. + +
BETA
This API is in BETA. Documentation might be incorrect or incomplete. Functionality might change with the final release.> + +## Overview +This API client was generated by the [OpenAPI Generator](https://openapi-generator.tech) project. By using the [OpenAPI-spec](https://www.openapis.org/) from a remote server, you can easily generate an API client. + +- API version: v1 +- Package version: 1.0.0 +- Generator version: 7.4.0 +- Build package: org.openapitools.codegen.languages.GoClientCodegen + +## Installation + +Install the following dependencies: + +```sh +go get github.com/stretchr/testify/assert +go get golang.org/x/oauth2 +go get golang.org/x/net/context +``` + +Put the package under your project folder and add the following in import: + +```go +import publicCloud "github.com/leaseweb/leaseweb-go-sdk/publicCloud" +``` + +To use a proxy, set the environment variable `HTTP_PROXY`: + +```go +os.Setenv("HTTP_PROXY", "http://proxy_name:proxy_port") +``` + +## Configuration of Server URL + +Default configuration comes with `Servers` field that contains server objects as defined in the OpenAPI specification. + +### Select Server Configuration + +For using other server than the one defined on index 0 set context value `publicCloud.ContextServerIndex` of type `int`. + +```go +ctx := context.WithValue(context.Background(), publicCloud.ContextServerIndex, 1) +``` + +### Templated Server URL + +Templated server URL is formatted using default variables from configuration or from context value `publicCloud.ContextServerVariables` of type `map[string]string`. + +```go +ctx := context.WithValue(context.Background(), publicCloud.ContextServerVariables, map[string]string{ + "basePath": "v2", +}) +``` + +Note, enum values are always validated and all unused variables are silently ignored. + +### URLs Configuration per Operation + +Each operation can use different server URL defined using `OperationServers` map in the `Configuration`. +An operation is uniquely identified by `"{classname}Service.{nickname}"` string. +Similar rules for overriding default operation server index and variables applies by using `publicCloud.ContextOperationServerIndices` and `publicCloud.ContextOperationServerVariables` context maps. + +```go +ctx := context.WithValue(context.Background(), publicCloud.ContextOperationServerIndices, map[string]int{ + "{classname}Service.{nickname}": 2, +}) +ctx = context.WithValue(context.Background(), publicCloud.ContextOperationServerVariables, map[string]map[string]string{ + "{classname}Service.{nickname}": { + "port": "8443", + }, +}) +``` + +## Documentation for API Endpoints + +All URIs are relative to *https://api.leaseweb.com/publicCloud/v1* + +Class | Method | HTTP request | Description +------------ | ------------- | ------------- | ------------- +*PublicCloudAPI* | [**AttachIso**](docs/PublicCloudAPI.md#attachiso) | **Post** /instances/{instanceId}/attachIso | Attach ISO to instance +*PublicCloudAPI* | [**CancelInstanceTermination**](docs/PublicCloudAPI.md#cancelinstancetermination) | **Post** /instances/{instanceId}/cancelTermination | Cancel instance termination +*PublicCloudAPI* | [**CreateFirewallRules**](docs/PublicCloudAPI.md#createfirewallrules) | **Post** /instances/{instanceId}/firewall/batchCreate | Add firewall rules in batch +*PublicCloudAPI* | [**CredentialsDelete**](docs/PublicCloudAPI.md#credentialsdelete) | **Delete** /instances/{instanceId}/credentials | Delete all instance credentials +*PublicCloudAPI* | [**DeleteCredential**](docs/PublicCloudAPI.md#deletecredential) | **Delete** /instances/{instanceId}/credentials/{type}/{username} | Delete credentials +*PublicCloudAPI* | [**DeleteFirewallRules**](docs/PublicCloudAPI.md#deletefirewallrules) | **Post** /instances/{instanceId}/firewall/batchDelete | Delete firewall rules in batch +*PublicCloudAPI* | [**DetachIso**](docs/PublicCloudAPI.md#detachiso) | **Post** /instances/{instanceId}/detachIso | Detach ISO from instance +*PublicCloudAPI* | [**EditFirewallRules**](docs/PublicCloudAPI.md#editfirewallrules) | **Post** /instances/{instanceId}/firewall/batchUpdate | Edit firewall rules in batch +*PublicCloudAPI* | [**GetConsoleAccessToInstance**](docs/PublicCloudAPI.md#getconsoleaccesstoinstance) | **Get** /instances/{instanceId}/console | Get console access +*PublicCloudAPI* | [**GetCredential**](docs/PublicCloudAPI.md#getcredential) | **Get** /instances/{instanceId}/credentials/{type}/{username} | Get credentials by type and username +*PublicCloudAPI* | [**GetCredentialList**](docs/PublicCloudAPI.md#getcredentiallist) | **Get** /instances/{instanceId}/credentials | List credentials stored for instance +*PublicCloudAPI* | [**GetCredentialListByType**](docs/PublicCloudAPI.md#getcredentiallistbytype) | **Get** /instances/{instanceId}/credentials/{type} | Get credentials by type +*PublicCloudAPI* | [**GetExpenses**](docs/PublicCloudAPI.md#getexpenses) | **Get** /equipments/{equipmentId}/expenses | Get costs for a given month. +*PublicCloudAPI* | [**GetFirewallRuleList**](docs/PublicCloudAPI.md#getfirewallrulelist) | **Get** /instances/{instanceId}/firewall | List firewall rules +*PublicCloudAPI* | [**GetInstance**](docs/PublicCloudAPI.md#getinstance) | **Get** /instances/{instanceId} | Get instance details +*PublicCloudAPI* | [**GetInstanceTypeList**](docs/PublicCloudAPI.md#getinstancetypelist) | **Get** /instanceTypes | List instance types +*PublicCloudAPI* | [**GetIsoList**](docs/PublicCloudAPI.md#getisolist) | **Get** /isos | List available ISOs +*PublicCloudAPI* | [**GetMarketAppList**](docs/PublicCloudAPI.md#getmarketapplist) | **Get** /marketApps | Get marketplace apps +*PublicCloudAPI* | [**GetOperatingSystemList**](docs/PublicCloudAPI.md#getoperatingsystemlist) | **Get** /operatingSystems | List all available Operating Systems +*PublicCloudAPI* | [**GetReinstallOsList**](docs/PublicCloudAPI.md#getreinstalloslist) | **Get** /instances/{instanceId}/reinstall/operatingSystems | List OSes available for reinstall +*PublicCloudAPI* | [**GetUpdateInstanceTypeList**](docs/PublicCloudAPI.md#getupdateinstancetypelist) | **Get** /instances/{instanceId}/instanceTypesUpdate | List available instance types for update +*PublicCloudAPI* | [**InstanceList**](docs/PublicCloudAPI.md#instancelist) | **Get** /instances | Get instance list +*PublicCloudAPI* | [**LaunchInstance**](docs/PublicCloudAPI.md#launchinstance) | **Post** /instances | Launch instance +*PublicCloudAPI* | [**RebootInstance**](docs/PublicCloudAPI.md#rebootinstance) | **Post** /instances/{instanceId}/reboot | Reboot instance +*PublicCloudAPI* | [**RegionsList**](docs/PublicCloudAPI.md#regionslist) | **Get** /regions | List regions +*PublicCloudAPI* | [**ResetPassword**](docs/PublicCloudAPI.md#resetpassword) | **Post** /instances/{instanceId}/resetPassword | Reset instance password +*PublicCloudAPI* | [**StartInstance**](docs/PublicCloudAPI.md#startinstance) | **Post** /instances/{instanceId}/start | Start instance +*PublicCloudAPI* | [**StopInstance**](docs/PublicCloudAPI.md#stopinstance) | **Post** /instances/{instanceId}/stop | Stop instance +*PublicCloudAPI* | [**StoreCredential**](docs/PublicCloudAPI.md#storecredential) | **Post** /instances/{instanceId}/credentials | Store credentials +*PublicCloudAPI* | [**TerminateInstance**](docs/PublicCloudAPI.md#terminateinstance) | **Delete** /instances/{instanceId} | Terminate instance +*PublicCloudAPI* | [**UpdateCredential**](docs/PublicCloudAPI.md#updatecredential) | **Put** /instances/{instanceId}/credentials/{type}/{username} | Update credentials +*PublicCloudAPI* | [**UpdateInstance**](docs/PublicCloudAPI.md#updateinstance) | **Put** /instances/{instanceId} | Update instance + + +## Documentation For Models + + - [AttachIsoOpts](docs/AttachIsoOpts.md) + - [BaseFirewallRule](docs/BaseFirewallRule.md) + - [Billing](docs/Billing.md) + - [Central](docs/Central.md) + - [Compute](docs/Compute.md) + - [ContractType](docs/ContractType.md) + - [Cpu](docs/Cpu.md) + - [CreateFirewallRulesCreatedResult](docs/CreateFirewallRulesCreatedResult.md) + - [CreateFirewallRulesOpts](docs/CreateFirewallRulesOpts.md) + - [CreateRule](docs/CreateRule.md) + - [Credential](docs/Credential.md) + - [CredentialType](docs/CredentialType.md) + - [Ddos](docs/Ddos.md) + - [DeleteFirewallRulesOpts](docs/DeleteFirewallRulesOpts.md) + - [DeleteFirewallRulesResult](docs/DeleteFirewallRulesResult.md) + - [DeletionRule](docs/DeletionRule.md) + - [EditFirewallRulesOpts](docs/EditFirewallRulesOpts.md) + - [EditFirewallRulesResult](docs/EditFirewallRulesResult.md) + - [EditRule](docs/EditRule.md) + - [ErrorResult](docs/ErrorResult.md) + - [ExpenseResultInstance](docs/ExpenseResultInstance.md) + - [FailedRule](docs/FailedRule.md) + - [FirewallRule](docs/FirewallRule.md) + - [GetConsoleAccessToInstanceResult](docs/GetConsoleAccessToInstanceResult.md) + - [GetCredentialListByTypeResult](docs/GetCredentialListByTypeResult.md) + - [GetCredentialListResult](docs/GetCredentialListResult.md) + - [GetCredentialResult](docs/GetCredentialResult.md) + - [GetExpensesResult](docs/GetExpensesResult.md) + - [GetFirewallRuleListResult](docs/GetFirewallRuleListResult.md) + - [GetInstanceListResult](docs/GetInstanceListResult.md) + - [GetInstanceResult](docs/GetInstanceResult.md) + - [GetInstanceTypeListResult](docs/GetInstanceTypeListResult.md) + - [GetIsoListResult](docs/GetIsoListResult.md) + - [GetMarketAppListResult](docs/GetMarketAppListResult.md) + - [GetOperatingSystemListResult](docs/GetOperatingSystemListResult.md) + - [GetRegionListResult](docs/GetRegionListResult.md) + - [GetUpdateInstanceTypeListResult](docs/GetUpdateInstanceTypeListResult.md) + - [IcmpFirewallRule](docs/IcmpFirewallRule.md) + - [Instance](docs/Instance.md) + - [InstanceResources](docs/InstanceResources.md) + - [InstanceState](docs/InstanceState.md) + - [InstanceTypeDetails](docs/InstanceTypeDetails.md) + - [Ip](docs/Ip.md) + - [Iso](docs/Iso.md) + - [LaunchInstanceCreatedResult](docs/LaunchInstanceCreatedResult.md) + - [LaunchInstanceOpts](docs/LaunchInstanceOpts.md) + - [Local](docs/Local.md) + - [MarketApp](docs/MarketApp.md) + - [Memory](docs/Memory.md) + - [Metadata](docs/Metadata.md) + - [OperatingSystem](docs/OperatingSystem.md) + - [OperatingSystemDetail](docs/OperatingSystemDetail.md) + - [Price](docs/Price.md) + - [PrivateNetwork](docs/PrivateNetwork.md) + - [PrivateNetworkSpeed](docs/PrivateNetworkSpeed.md) + - [PublicNetworkSpeed](docs/PublicNetworkSpeed.md) + - [Region](docs/Region.md) + - [Storage](docs/Storage.md) + - [StoreCredentialOpts](docs/StoreCredentialOpts.md) + - [StoreCredentialResult](docs/StoreCredentialResult.md) + - [TcpUdpFirewallRule](docs/TcpUdpFirewallRule.md) + - [Tier](docs/Tier.md) + - [Traffic](docs/Traffic.md) + - [UpdateCredentialOpts](docs/UpdateCredentialOpts.md) + - [UpdateCredentialResult](docs/UpdateCredentialResult.md) + - [UpdateInstanceOpts](docs/UpdateInstanceOpts.md) + - [UpdateInstanceResult](docs/UpdateInstanceResult.md) + - [UpdateInstanceType](docs/UpdateInstanceType.md) + - [Values](docs/Values.md) + + +## Documentation For Authorization + + +Authentication schemes defined for the API: +### ApiKeyAuth + +- **Type**: API key +- **API key parameter name**: X-LSW-Auth +- **Location**: HTTP header + +Note, each API key must be added to a map of `map[string]APIKey` where the key is: X-LSW-Auth and passed in as the auth context for each request. + +Example + +```go +auth := context.WithValue( + context.Background(), + publicCloud.ContextAPIKeys, + map[string]publicCloud.APIKey{ + "X-LSW-Auth": {Key: "API_KEY_STRING"}, + }, + ) +r, err := client.Service.Operation(auth, args) +``` + +### OAuth2 + + +- **Type**: OAuth +- **Flow**: application +- **Authorization URL**: +- **Scopes**: N/A + +Example + +```go +auth := context.WithValue(context.Background(), publicCloud.ContextAccessToken, "ACCESSTOKENSTRING") +r, err := client.Service.Operation(auth, args) +``` + +Or via OAuth2 module to automatically refresh tokens and perform user authentication. + +```go +import "golang.org/x/oauth2" + +/* Perform OAuth2 round trip request and obtain a token */ + +tokenSource := oauth2cfg.TokenSource(createContext(httpClient), &token) +auth := context.WithValue(oauth2.NoContext, publicCloud.ContextOAuth2, tokenSource) +r, err := client.Service.Operation(auth, args) +``` + +### BearerAuth + +- **Type**: HTTP Bearer token authentication + +Example + +```go +auth := context.WithValue(context.Background(), publicCloud.ContextAccessToken, "BEARER_TOKEN_STRING") +r, err := client.Service.Operation(auth, args) +``` + + +## Documentation for Utility Methods + +Due to the fact that model structure members are all pointers, this package contains +a number of utility functions to easily obtain pointers to values of basic types. +Each of these functions takes a value of the given basic type and returns a pointer to it: + +* `PtrBool` +* `PtrInt` +* `PtrInt32` +* `PtrInt64` +* `PtrFloat` +* `PtrFloat32` +* `PtrFloat64` +* `PtrString` +* `PtrTime` + +## Author + + + diff --git a/publicCloud/api_public_cloud.go b/publicCloud/api_public_cloud.go new file mode 100644 index 0000000..6957964 --- /dev/null +++ b/publicCloud/api_public_cloud.go @@ -0,0 +1,5998 @@ +/* +LeaseWeb API for launching and managing Public Cloud instances + +> The base URL for this API is: **https://api.leaseweb.com/publicCloud/v1/_** This API provides ways to launch and manage Public Cloud instances.
BETA
This API is in BETA. Documentation might be incorrect or incomplete. Functionality might change with the final release.> + +API version: v1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package publicCloud + +import ( + "bytes" + "context" + "io" + "net/http" + "net/url" + "strings" +) + + +// PublicCloudAPIService PublicCloudAPI service +type PublicCloudAPIService service + +type ApiAttachIsoRequest struct { + ctx context.Context + ApiService *PublicCloudAPIService + instanceId string + attachIsoOpts *AttachIsoOpts +} + +func (r ApiAttachIsoRequest) AttachIsoOpts(attachIsoOpts AttachIsoOpts) ApiAttachIsoRequest { + r.attachIsoOpts = &attachIsoOpts + return r +} + +func (r ApiAttachIsoRequest) Execute() (*http.Response, error) { + return r.ApiService.AttachIsoExecute(r) +} + +/* +AttachIso Attach ISO to instance + +Instance must not have ISO attached, otherwise, it will return a validation error. + +Available ISOs can be obtained using `/v1/isos`. + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param instanceId Instance's ID + @return ApiAttachIsoRequest +*/ +func (a *PublicCloudAPIService) AttachIso(ctx context.Context, instanceId string) ApiAttachIsoRequest { + return ApiAttachIsoRequest{ + ApiService: a, + ctx: ctx, + instanceId: instanceId, + } +} + +// Execute executes the request +func (a *PublicCloudAPIService) AttachIsoExecute(r ApiAttachIsoRequest) (*http.Response, error) { + var ( + localVarHTTPMethod = http.MethodPost + localVarPostBody interface{} + formFiles []formFile + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "PublicCloudAPIService.AttachIso") + if err != nil { + return nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/instances/{instanceId}/attachIso" + localVarPath = strings.Replace(localVarPath, "{"+"instanceId"+"}", url.PathEscape(parameterValueToString(r.instanceId, "instanceId")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + if r.attachIsoOpts == nil { + return nil, reportError("attachIsoOpts is required and must be specified") + } + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{"application/json"} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + // body params + localVarPostBody = r.attachIsoOpts + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 404 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarHTTPResponse, newErr + } + + return localVarHTTPResponse, nil +} + +type ApiCancelInstanceTerminationRequest struct { + ctx context.Context + ApiService *PublicCloudAPIService + instanceId string +} + +func (r ApiCancelInstanceTerminationRequest) Execute() (*http.Response, error) { + return r.ApiService.CancelInstanceTerminationExecute(r) +} + +/* +CancelInstanceTermination Cancel instance termination + +Cancel the termination process of monthly instances. Must be executed prior to the instance's `contractEndsAt`. + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param instanceId Instance's ID + @return ApiCancelInstanceTerminationRequest +*/ +func (a *PublicCloudAPIService) CancelInstanceTermination(ctx context.Context, instanceId string) ApiCancelInstanceTerminationRequest { + return ApiCancelInstanceTerminationRequest{ + ApiService: a, + ctx: ctx, + instanceId: instanceId, + } +} + +// Execute executes the request +func (a *PublicCloudAPIService) CancelInstanceTerminationExecute(r ApiCancelInstanceTerminationRequest) (*http.Response, error) { + var ( + localVarHTTPMethod = http.MethodPost + localVarPostBody interface{} + formFiles []formFile + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "PublicCloudAPIService.CancelInstanceTermination") + if err != nil { + return nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/instances/{instanceId}/cancelTermination" + localVarPath = strings.Replace(localVarPath, "{"+"instanceId"+"}", url.PathEscape(parameterValueToString(r.instanceId, "instanceId")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 404 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarHTTPResponse, newErr + } + + return localVarHTTPResponse, nil +} + +type ApiCreateFirewallRulesRequest struct { + ctx context.Context + ApiService *PublicCloudAPIService + instanceId string + createFirewallRulesOpts *CreateFirewallRulesOpts +} + +func (r ApiCreateFirewallRulesRequest) CreateFirewallRulesOpts(createFirewallRulesOpts CreateFirewallRulesOpts) ApiCreateFirewallRulesRequest { + r.createFirewallRulesOpts = &createFirewallRulesOpts + return r +} + +func (r ApiCreateFirewallRulesRequest) Execute() (*CreateFirewallRulesCreatedResult, *http.Response, error) { + return r.ApiService.CreateFirewallRulesExecute(r) +} + +/* +CreateFirewallRules Add firewall rules in batch + +Add multiple rules at once + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param instanceId Instance's ID + @return ApiCreateFirewallRulesRequest +*/ +func (a *PublicCloudAPIService) CreateFirewallRules(ctx context.Context, instanceId string) ApiCreateFirewallRulesRequest { + return ApiCreateFirewallRulesRequest{ + ApiService: a, + ctx: ctx, + instanceId: instanceId, + } +} + +// Execute executes the request +// @return CreateFirewallRulesCreatedResult +func (a *PublicCloudAPIService) CreateFirewallRulesExecute(r ApiCreateFirewallRulesRequest) (*CreateFirewallRulesCreatedResult, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodPost + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *CreateFirewallRulesCreatedResult + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "PublicCloudAPIService.CreateFirewallRules") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/instances/{instanceId}/firewall/batchCreate" + localVarPath = strings.Replace(localVarPath, "{"+"instanceId"+"}", url.PathEscape(parameterValueToString(r.instanceId, "instanceId")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + if r.createFirewallRulesOpts == nil { + return localVarReturnValue, nil, reportError("createFirewallRulesOpts is required and must be specified") + } + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{"application/json"} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + // body params + localVarPostBody = r.createFirewallRulesOpts + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 404 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiCredentialsDeleteRequest struct { + ctx context.Context + ApiService *PublicCloudAPIService + instanceId string +} + +func (r ApiCredentialsDeleteRequest) Execute() (*http.Response, error) { + return r.ApiService.CredentialsDeleteExecute(r) +} + +/* +CredentialsDelete Delete all instance credentials + +Delete all credentials stored for a given instance + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param instanceId Instance's ID + @return ApiCredentialsDeleteRequest +*/ +func (a *PublicCloudAPIService) CredentialsDelete(ctx context.Context, instanceId string) ApiCredentialsDeleteRequest { + return ApiCredentialsDeleteRequest{ + ApiService: a, + ctx: ctx, + instanceId: instanceId, + } +} + +// Execute executes the request +func (a *PublicCloudAPIService) CredentialsDeleteExecute(r ApiCredentialsDeleteRequest) (*http.Response, error) { + var ( + localVarHTTPMethod = http.MethodDelete + localVarPostBody interface{} + formFiles []formFile + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "PublicCloudAPIService.CredentialsDelete") + if err != nil { + return nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/instances/{instanceId}/credentials" + localVarPath = strings.Replace(localVarPath, "{"+"instanceId"+"}", url.PathEscape(parameterValueToString(r.instanceId, "instanceId")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 404 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarHTTPResponse, newErr + } + + return localVarHTTPResponse, nil +} + +type ApiDeleteCredentialRequest struct { + ctx context.Context + ApiService *PublicCloudAPIService + instanceId string + type_ string + username string +} + +func (r ApiDeleteCredentialRequest) Execute() (*http.Response, error) { + return r.ApiService.DeleteCredentialExecute(r) +} + +/* +DeleteCredential Delete credentials + +Delete credential for a given type and username + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param instanceId Instance's ID + @param type_ Credential type + @param username Username + @return ApiDeleteCredentialRequest +*/ +func (a *PublicCloudAPIService) DeleteCredential(ctx context.Context, instanceId string, type_ string, username string) ApiDeleteCredentialRequest { + return ApiDeleteCredentialRequest{ + ApiService: a, + ctx: ctx, + instanceId: instanceId, + type_: type_, + username: username, + } +} + +// Execute executes the request +func (a *PublicCloudAPIService) DeleteCredentialExecute(r ApiDeleteCredentialRequest) (*http.Response, error) { + var ( + localVarHTTPMethod = http.MethodDelete + localVarPostBody interface{} + formFiles []formFile + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "PublicCloudAPIService.DeleteCredential") + if err != nil { + return nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/instances/{instanceId}/credentials/{type}/{username}" + localVarPath = strings.Replace(localVarPath, "{"+"instanceId"+"}", url.PathEscape(parameterValueToString(r.instanceId, "instanceId")), -1) + localVarPath = strings.Replace(localVarPath, "{"+"type"+"}", url.PathEscape(parameterValueToString(r.type_, "type_")), -1) + localVarPath = strings.Replace(localVarPath, "{"+"username"+"}", url.PathEscape(parameterValueToString(r.username, "username")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 404 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarHTTPResponse, newErr + } + + return localVarHTTPResponse, nil +} + +type ApiDeleteFirewallRulesRequest struct { + ctx context.Context + ApiService *PublicCloudAPIService + instanceId string + deleteFirewallRulesOpts *DeleteFirewallRulesOpts +} + +func (r ApiDeleteFirewallRulesRequest) DeleteFirewallRulesOpts(deleteFirewallRulesOpts DeleteFirewallRulesOpts) ApiDeleteFirewallRulesRequest { + r.deleteFirewallRulesOpts = &deleteFirewallRulesOpts + return r +} + +func (r ApiDeleteFirewallRulesRequest) Execute() (*DeleteFirewallRulesResult, *http.Response, error) { + return r.ApiService.DeleteFirewallRulesExecute(r) +} + +/* +DeleteFirewallRules Delete firewall rules in batch + +Delete multiple rules at once + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param instanceId Instance's ID + @return ApiDeleteFirewallRulesRequest +*/ +func (a *PublicCloudAPIService) DeleteFirewallRules(ctx context.Context, instanceId string) ApiDeleteFirewallRulesRequest { + return ApiDeleteFirewallRulesRequest{ + ApiService: a, + ctx: ctx, + instanceId: instanceId, + } +} + +// Execute executes the request +// @return DeleteFirewallRulesResult +func (a *PublicCloudAPIService) DeleteFirewallRulesExecute(r ApiDeleteFirewallRulesRequest) (*DeleteFirewallRulesResult, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodPost + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *DeleteFirewallRulesResult + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "PublicCloudAPIService.DeleteFirewallRules") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/instances/{instanceId}/firewall/batchDelete" + localVarPath = strings.Replace(localVarPath, "{"+"instanceId"+"}", url.PathEscape(parameterValueToString(r.instanceId, "instanceId")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + if r.deleteFirewallRulesOpts == nil { + return localVarReturnValue, nil, reportError("deleteFirewallRulesOpts is required and must be specified") + } + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{"application/json"} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + // body params + localVarPostBody = r.deleteFirewallRulesOpts + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 404 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiDetachIsoRequest struct { + ctx context.Context + ApiService *PublicCloudAPIService + instanceId string +} + +func (r ApiDetachIsoRequest) Execute() (*http.Response, error) { + return r.ApiService.DetachIsoExecute(r) +} + +/* +DetachIso Detach ISO from instance + +Instance must have ISO attached, otherwise, it will return a validation error + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param instanceId Instance's ID + @return ApiDetachIsoRequest +*/ +func (a *PublicCloudAPIService) DetachIso(ctx context.Context, instanceId string) ApiDetachIsoRequest { + return ApiDetachIsoRequest{ + ApiService: a, + ctx: ctx, + instanceId: instanceId, + } +} + +// Execute executes the request +func (a *PublicCloudAPIService) DetachIsoExecute(r ApiDetachIsoRequest) (*http.Response, error) { + var ( + localVarHTTPMethod = http.MethodPost + localVarPostBody interface{} + formFiles []formFile + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "PublicCloudAPIService.DetachIso") + if err != nil { + return nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/instances/{instanceId}/detachIso" + localVarPath = strings.Replace(localVarPath, "{"+"instanceId"+"}", url.PathEscape(parameterValueToString(r.instanceId, "instanceId")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 404 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarHTTPResponse, newErr + } + + return localVarHTTPResponse, nil +} + +type ApiEditFirewallRulesRequest struct { + ctx context.Context + ApiService *PublicCloudAPIService + instanceId string + editFirewallRulesOpts *EditFirewallRulesOpts +} + +func (r ApiEditFirewallRulesRequest) EditFirewallRulesOpts(editFirewallRulesOpts EditFirewallRulesOpts) ApiEditFirewallRulesRequest { + r.editFirewallRulesOpts = &editFirewallRulesOpts + return r +} + +func (r ApiEditFirewallRulesRequest) Execute() (*EditFirewallRulesResult, *http.Response, error) { + return r.ApiService.EditFirewallRulesExecute(r) +} + +/* +EditFirewallRules Edit firewall rules in batch + +Edit multiple rules at once + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param instanceId Instance's ID + @return ApiEditFirewallRulesRequest +*/ +func (a *PublicCloudAPIService) EditFirewallRules(ctx context.Context, instanceId string) ApiEditFirewallRulesRequest { + return ApiEditFirewallRulesRequest{ + ApiService: a, + ctx: ctx, + instanceId: instanceId, + } +} + +// Execute executes the request +// @return EditFirewallRulesResult +func (a *PublicCloudAPIService) EditFirewallRulesExecute(r ApiEditFirewallRulesRequest) (*EditFirewallRulesResult, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodPost + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *EditFirewallRulesResult + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "PublicCloudAPIService.EditFirewallRules") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/instances/{instanceId}/firewall/batchUpdate" + localVarPath = strings.Replace(localVarPath, "{"+"instanceId"+"}", url.PathEscape(parameterValueToString(r.instanceId, "instanceId")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + if r.editFirewallRulesOpts == nil { + return localVarReturnValue, nil, reportError("editFirewallRulesOpts is required and must be specified") + } + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{"application/json"} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + // body params + localVarPostBody = r.editFirewallRulesOpts + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 404 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiGetConsoleAccessToInstanceRequest struct { + ctx context.Context + ApiService *PublicCloudAPIService + instanceId string +} + +func (r ApiGetConsoleAccessToInstanceRequest) Execute() (*GetConsoleAccessToInstanceResult, *http.Response, error) { + return r.ApiService.GetConsoleAccessToInstanceExecute(r) +} + +/* +GetConsoleAccessToInstance Get console access + +Get console access to the instance + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param instanceId Instance's ID + @return ApiGetConsoleAccessToInstanceRequest +*/ +func (a *PublicCloudAPIService) GetConsoleAccessToInstance(ctx context.Context, instanceId string) ApiGetConsoleAccessToInstanceRequest { + return ApiGetConsoleAccessToInstanceRequest{ + ApiService: a, + ctx: ctx, + instanceId: instanceId, + } +} + +// Execute executes the request +// @return GetConsoleAccessToInstanceResult +func (a *PublicCloudAPIService) GetConsoleAccessToInstanceExecute(r ApiGetConsoleAccessToInstanceRequest) (*GetConsoleAccessToInstanceResult, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodGet + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *GetConsoleAccessToInstanceResult + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "PublicCloudAPIService.GetConsoleAccessToInstance") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/instances/{instanceId}/console" + localVarPath = strings.Replace(localVarPath, "{"+"instanceId"+"}", url.PathEscape(parameterValueToString(r.instanceId, "instanceId")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 404 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiGetCredentialRequest struct { + ctx context.Context + ApiService *PublicCloudAPIService + instanceId string + type_ string + username string +} + +func (r ApiGetCredentialRequest) Execute() (*GetCredentialResult, *http.Response, error) { + return r.ApiService.GetCredentialExecute(r) +} + +/* +GetCredential Get credentials by type and username + +Get credentials by type and username + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param instanceId Instance's ID + @param type_ Credential type + @param username Username + @return ApiGetCredentialRequest +*/ +func (a *PublicCloudAPIService) GetCredential(ctx context.Context, instanceId string, type_ string, username string) ApiGetCredentialRequest { + return ApiGetCredentialRequest{ + ApiService: a, + ctx: ctx, + instanceId: instanceId, + type_: type_, + username: username, + } +} + +// Execute executes the request +// @return GetCredentialResult +func (a *PublicCloudAPIService) GetCredentialExecute(r ApiGetCredentialRequest) (*GetCredentialResult, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodGet + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *GetCredentialResult + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "PublicCloudAPIService.GetCredential") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/instances/{instanceId}/credentials/{type}/{username}" + localVarPath = strings.Replace(localVarPath, "{"+"instanceId"+"}", url.PathEscape(parameterValueToString(r.instanceId, "instanceId")), -1) + localVarPath = strings.Replace(localVarPath, "{"+"type"+"}", url.PathEscape(parameterValueToString(r.type_, "type_")), -1) + localVarPath = strings.Replace(localVarPath, "{"+"username"+"}", url.PathEscape(parameterValueToString(r.username, "username")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 404 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiGetCredentialListRequest struct { + ctx context.Context + ApiService *PublicCloudAPIService + instanceId string +} + +func (r ApiGetCredentialListRequest) Execute() (*GetCredentialListResult, *http.Response, error) { + return r.ApiService.GetCredentialListExecute(r) +} + +/* +GetCredentialList List credentials stored for instance + +Get all credentials stored for the instance + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param instanceId Instance's ID + @return ApiGetCredentialListRequest +*/ +func (a *PublicCloudAPIService) GetCredentialList(ctx context.Context, instanceId string) ApiGetCredentialListRequest { + return ApiGetCredentialListRequest{ + ApiService: a, + ctx: ctx, + instanceId: instanceId, + } +} + +// Execute executes the request +// @return GetCredentialListResult +func (a *PublicCloudAPIService) GetCredentialListExecute(r ApiGetCredentialListRequest) (*GetCredentialListResult, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodGet + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *GetCredentialListResult + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "PublicCloudAPIService.GetCredentialList") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/instances/{instanceId}/credentials" + localVarPath = strings.Replace(localVarPath, "{"+"instanceId"+"}", url.PathEscape(parameterValueToString(r.instanceId, "instanceId")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 404 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiGetCredentialListByTypeRequest struct { + ctx context.Context + ApiService *PublicCloudAPIService + instanceId string + type_ string +} + +func (r ApiGetCredentialListByTypeRequest) Execute() (*GetCredentialListByTypeResult, *http.Response, error) { + return r.ApiService.GetCredentialListByTypeExecute(r) +} + +/* +GetCredentialListByType Get credentials by type + +Get credentials stored for the instance by their types + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param instanceId Instance's ID + @param type_ + @return ApiGetCredentialListByTypeRequest +*/ +func (a *PublicCloudAPIService) GetCredentialListByType(ctx context.Context, instanceId string, type_ string) ApiGetCredentialListByTypeRequest { + return ApiGetCredentialListByTypeRequest{ + ApiService: a, + ctx: ctx, + instanceId: instanceId, + type_: type_, + } +} + +// Execute executes the request +// @return GetCredentialListByTypeResult +func (a *PublicCloudAPIService) GetCredentialListByTypeExecute(r ApiGetCredentialListByTypeRequest) (*GetCredentialListByTypeResult, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodGet + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *GetCredentialListByTypeResult + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "PublicCloudAPIService.GetCredentialListByType") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/instances/{instanceId}/credentials/{type}" + localVarPath = strings.Replace(localVarPath, "{"+"instanceId"+"}", url.PathEscape(parameterValueToString(r.instanceId, "instanceId")), -1) + localVarPath = strings.Replace(localVarPath, "{"+"type"+"}", url.PathEscape(parameterValueToString(r.type_, "type_")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 404 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiGetExpensesRequest struct { + ctx context.Context + ApiService *PublicCloudAPIService + equipmentId string + from *string + to *string +} + +// Start date of the period to get costs for. It must be the first day of the month +func (r ApiGetExpensesRequest) From(from string) ApiGetExpensesRequest { + r.from = &from + return r +} + +// End date of the period to get costs for. This date needs to be exactly one month after the 'from' date. If this value is not passed, it will be calculated based on 'from' parameter +func (r ApiGetExpensesRequest) To(to string) ApiGetExpensesRequest { + r.to = &to + return r +} + +func (r ApiGetExpensesRequest) Execute() (*GetExpensesResult, *http.Response, error) { + return r.ApiService.GetExpensesExecute(r) +} + +/* +GetExpenses Get costs for a given month. + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param equipmentId Equipment's UUID + @return ApiGetExpensesRequest +*/ +func (a *PublicCloudAPIService) GetExpenses(ctx context.Context, equipmentId string) ApiGetExpensesRequest { + return ApiGetExpensesRequest{ + ApiService: a, + ctx: ctx, + equipmentId: equipmentId, + } +} + +// Execute executes the request +// @return GetExpensesResult +func (a *PublicCloudAPIService) GetExpensesExecute(r ApiGetExpensesRequest) (*GetExpensesResult, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodGet + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *GetExpensesResult + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "PublicCloudAPIService.GetExpenses") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/equipments/{equipmentId}/expenses" + localVarPath = strings.Replace(localVarPath, "{"+"equipmentId"+"}", url.PathEscape(parameterValueToString(r.equipmentId, "equipmentId")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + if r.from == nil { + return localVarReturnValue, nil, reportError("from is required and must be specified") + } + + parameterAddToHeaderOrQuery(localVarQueryParams, "from", r.from, "") + if r.to != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "to", r.to, "") + } + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiGetFirewallRuleListRequest struct { + ctx context.Context + ApiService *PublicCloudAPIService + instanceId string + limit *int32 + offset *int32 +} + +// Limit the number of results returned. +func (r ApiGetFirewallRuleListRequest) Limit(limit int32) ApiGetFirewallRuleListRequest { + r.limit = &limit + return r +} + +// Return results starting from the given offset. +func (r ApiGetFirewallRuleListRequest) Offset(offset int32) ApiGetFirewallRuleListRequest { + r.offset = &offset + return r +} + +func (r ApiGetFirewallRuleListRequest) Execute() (*GetFirewallRuleListResult, *http.Response, error) { + return r.ApiService.GetFirewallRuleListExecute(r) +} + +/* +GetFirewallRuleList List firewall rules + +List firewall rules + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param instanceId Instance's ID + @return ApiGetFirewallRuleListRequest +*/ +func (a *PublicCloudAPIService) GetFirewallRuleList(ctx context.Context, instanceId string) ApiGetFirewallRuleListRequest { + return ApiGetFirewallRuleListRequest{ + ApiService: a, + ctx: ctx, + instanceId: instanceId, + } +} + +// Execute executes the request +// @return GetFirewallRuleListResult +func (a *PublicCloudAPIService) GetFirewallRuleListExecute(r ApiGetFirewallRuleListRequest) (*GetFirewallRuleListResult, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodGet + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *GetFirewallRuleListResult + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "PublicCloudAPIService.GetFirewallRuleList") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/instances/{instanceId}/firewall" + localVarPath = strings.Replace(localVarPath, "{"+"instanceId"+"}", url.PathEscape(parameterValueToString(r.instanceId, "instanceId")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + if r.limit != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "limit", r.limit, "") + } + if r.offset != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "offset", r.offset, "") + } + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 404 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiGetInstanceRequest struct { + ctx context.Context + ApiService *PublicCloudAPIService + instanceId string +} + +func (r ApiGetInstanceRequest) Execute() (*GetInstanceResult, *http.Response, error) { + return r.ApiService.GetInstanceExecute(r) +} + +/* +GetInstance Get instance details + +Get details about the instance + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param instanceId Instance's ID + @return ApiGetInstanceRequest +*/ +func (a *PublicCloudAPIService) GetInstance(ctx context.Context, instanceId string) ApiGetInstanceRequest { + return ApiGetInstanceRequest{ + ApiService: a, + ctx: ctx, + instanceId: instanceId, + } +} + +// Execute executes the request +// @return GetInstanceResult +func (a *PublicCloudAPIService) GetInstanceExecute(r ApiGetInstanceRequest) (*GetInstanceResult, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodGet + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *GetInstanceResult + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "PublicCloudAPIService.GetInstance") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/instances/{instanceId}" + localVarPath = strings.Replace(localVarPath, "{"+"instanceId"+"}", url.PathEscape(parameterValueToString(r.instanceId, "instanceId")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 404 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiGetInstanceTypeListRequest struct { + ctx context.Context + ApiService *PublicCloudAPIService + region *string + limit *int32 + offset *int32 +} + +func (r ApiGetInstanceTypeListRequest) Region(region string) ApiGetInstanceTypeListRequest { + r.region = ®ion + return r +} + +func (r ApiGetInstanceTypeListRequest) Limit(limit int32) ApiGetInstanceTypeListRequest { + r.limit = &limit + return r +} + +func (r ApiGetInstanceTypeListRequest) Offset(offset int32) ApiGetInstanceTypeListRequest { + r.offset = &offset + return r +} + +func (r ApiGetInstanceTypeListRequest) Execute() (*GetInstanceTypeListResult, *http.Response, error) { + return r.ApiService.GetInstanceTypeListExecute(r) +} + +/* +GetInstanceTypeList List instance types + +Get instance types + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @return ApiGetInstanceTypeListRequest +*/ +func (a *PublicCloudAPIService) GetInstanceTypeList(ctx context.Context) ApiGetInstanceTypeListRequest { + return ApiGetInstanceTypeListRequest{ + ApiService: a, + ctx: ctx, + } +} + +// Execute executes the request +// @return GetInstanceTypeListResult +func (a *PublicCloudAPIService) GetInstanceTypeListExecute(r ApiGetInstanceTypeListRequest) (*GetInstanceTypeListResult, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodGet + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *GetInstanceTypeListResult + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "PublicCloudAPIService.GetInstanceTypeList") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/instanceTypes" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + if r.region == nil { + return localVarReturnValue, nil, reportError("region is required and must be specified") + } + + parameterAddToHeaderOrQuery(localVarQueryParams, "region", r.region, "") + if r.limit != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "limit", r.limit, "") + } else { + var defaultValue int32 = 50 + r.limit = &defaultValue + } + if r.offset != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "offset", r.offset, "") + } else { + var defaultValue int32 = 0 + r.offset = &defaultValue + } + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiGetIsoListRequest struct { + ctx context.Context + ApiService *PublicCloudAPIService + limit *int32 + offset *int32 +} + +// Limit the number of results returned. +func (r ApiGetIsoListRequest) Limit(limit int32) ApiGetIsoListRequest { + r.limit = &limit + return r +} + +// Return results starting from the given offset. +func (r ApiGetIsoListRequest) Offset(offset int32) ApiGetIsoListRequest { + r.offset = &offset + return r +} + +func (r ApiGetIsoListRequest) Execute() (*GetIsoListResult, *http.Response, error) { + return r.ApiService.GetIsoListExecute(r) +} + +/* +GetIsoList List available ISOs + +List all available ISO images + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @return ApiGetIsoListRequest +*/ +func (a *PublicCloudAPIService) GetIsoList(ctx context.Context) ApiGetIsoListRequest { + return ApiGetIsoListRequest{ + ApiService: a, + ctx: ctx, + } +} + +// Execute executes the request +// @return GetIsoListResult +func (a *PublicCloudAPIService) GetIsoListExecute(r ApiGetIsoListRequest) (*GetIsoListResult, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodGet + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *GetIsoListResult + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "PublicCloudAPIService.GetIsoList") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/isos" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + if r.limit != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "limit", r.limit, "") + } + if r.offset != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "offset", r.offset, "") + } + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiGetMarketAppListRequest struct { + ctx context.Context + ApiService *PublicCloudAPIService +} + +func (r ApiGetMarketAppListRequest) Execute() (*GetMarketAppListResult, *http.Response, error) { + return r.ApiService.GetMarketAppListExecute(r) +} + +/* +GetMarketAppList Get marketplace apps + +Get all available marketplace apps. + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @return ApiGetMarketAppListRequest +*/ +func (a *PublicCloudAPIService) GetMarketAppList(ctx context.Context) ApiGetMarketAppListRequest { + return ApiGetMarketAppListRequest{ + ApiService: a, + ctx: ctx, + } +} + +// Execute executes the request +// @return GetMarketAppListResult +func (a *PublicCloudAPIService) GetMarketAppListExecute(r ApiGetMarketAppListRequest) (*GetMarketAppListResult, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodGet + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *GetMarketAppListResult + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "PublicCloudAPIService.GetMarketAppList") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/marketApps" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiGetOperatingSystemListRequest struct { + ctx context.Context + ApiService *PublicCloudAPIService + limit *int32 + offset *int32 +} + +// Limit the number of results returned. +func (r ApiGetOperatingSystemListRequest) Limit(limit int32) ApiGetOperatingSystemListRequest { + r.limit = &limit + return r +} + +// Return results starting from the given offset. +func (r ApiGetOperatingSystemListRequest) Offset(offset int32) ApiGetOperatingSystemListRequest { + r.offset = &offset + return r +} + +func (r ApiGetOperatingSystemListRequest) Execute() (*GetOperatingSystemListResult, *http.Response, error) { + return r.ApiService.GetOperatingSystemListExecute(r) +} + +/* +GetOperatingSystemList List all available Operating Systems + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @return ApiGetOperatingSystemListRequest +*/ +func (a *PublicCloudAPIService) GetOperatingSystemList(ctx context.Context) ApiGetOperatingSystemListRequest { + return ApiGetOperatingSystemListRequest{ + ApiService: a, + ctx: ctx, + } +} + +// Execute executes the request +// @return GetOperatingSystemListResult +func (a *PublicCloudAPIService) GetOperatingSystemListExecute(r ApiGetOperatingSystemListRequest) (*GetOperatingSystemListResult, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodGet + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *GetOperatingSystemListResult + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "PublicCloudAPIService.GetOperatingSystemList") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/operatingSystems" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + if r.limit != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "limit", r.limit, "") + } + if r.offset != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "offset", r.offset, "") + } + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiGetReinstallOsListRequest struct { + ctx context.Context + ApiService *PublicCloudAPIService + instanceId string +} + +func (r ApiGetReinstallOsListRequest) Execute() ([]OperatingSystem, *http.Response, error) { + return r.ApiService.GetReinstallOsListExecute(r) +} + +/* +GetReinstallOsList List OSes available for reinstall + +List Operating Systems available for reinstall + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param instanceId Instance's ID + @return ApiGetReinstallOsListRequest +*/ +func (a *PublicCloudAPIService) GetReinstallOsList(ctx context.Context, instanceId string) ApiGetReinstallOsListRequest { + return ApiGetReinstallOsListRequest{ + ApiService: a, + ctx: ctx, + instanceId: instanceId, + } +} + +// Execute executes the request +// @return []OperatingSystem +func (a *PublicCloudAPIService) GetReinstallOsListExecute(r ApiGetReinstallOsListRequest) ([]OperatingSystem, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodGet + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue []OperatingSystem + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "PublicCloudAPIService.GetReinstallOsList") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/instances/{instanceId}/reinstall/operatingSystems" + localVarPath = strings.Replace(localVarPath, "{"+"instanceId"+"}", url.PathEscape(parameterValueToString(r.instanceId, "instanceId")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 404 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiGetUpdateInstanceTypeListRequest struct { + ctx context.Context + ApiService *PublicCloudAPIService + instanceId string + limit *int32 + offset *int32 +} + +func (r ApiGetUpdateInstanceTypeListRequest) Limit(limit int32) ApiGetUpdateInstanceTypeListRequest { + r.limit = &limit + return r +} + +func (r ApiGetUpdateInstanceTypeListRequest) Offset(offset int32) ApiGetUpdateInstanceTypeListRequest { + r.offset = &offset + return r +} + +func (r ApiGetUpdateInstanceTypeListRequest) Execute() (*GetUpdateInstanceTypeListResult, *http.Response, error) { + return r.ApiService.GetUpdateInstanceTypeListExecute(r) +} + +/* +GetUpdateInstanceTypeList List available instance types for update + +Get available instance types for update + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param instanceId Instance's ID + @return ApiGetUpdateInstanceTypeListRequest +*/ +func (a *PublicCloudAPIService) GetUpdateInstanceTypeList(ctx context.Context, instanceId string) ApiGetUpdateInstanceTypeListRequest { + return ApiGetUpdateInstanceTypeListRequest{ + ApiService: a, + ctx: ctx, + instanceId: instanceId, + } +} + +// Execute executes the request +// @return GetUpdateInstanceTypeListResult +func (a *PublicCloudAPIService) GetUpdateInstanceTypeListExecute(r ApiGetUpdateInstanceTypeListRequest) (*GetUpdateInstanceTypeListResult, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodGet + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *GetUpdateInstanceTypeListResult + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "PublicCloudAPIService.GetUpdateInstanceTypeList") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/instances/{instanceId}/instanceTypesUpdate" + localVarPath = strings.Replace(localVarPath, "{"+"instanceId"+"}", url.PathEscape(parameterValueToString(r.instanceId, "instanceId")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + if r.limit != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "limit", r.limit, "") + } else { + var defaultValue int32 = 50 + r.limit = &defaultValue + } + if r.offset != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "offset", r.offset, "") + } else { + var defaultValue int32 = 0 + r.offset = &defaultValue + } + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 404 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiInstanceListRequest struct { + ctx context.Context + ApiService *PublicCloudAPIService + limit *int32 + offset *int32 + ip *string + reference *string + id *string + filter *string + contractType *string + state *string + region *string + type_ *string +} + +// Limit the number of results returned. +func (r ApiInstanceListRequest) Limit(limit int32) ApiInstanceListRequest { + r.limit = &limit + return r +} + +// Return results starting from the given offset. +func (r ApiInstanceListRequest) Offset(offset int32) ApiInstanceListRequest { + r.offset = &offset + return r +} + +func (r ApiInstanceListRequest) Ip(ip string) ApiInstanceListRequest { + r.ip = &ip + return r +} + +func (r ApiInstanceListRequest) Reference(reference string) ApiInstanceListRequest { + r.reference = &reference + return r +} + +func (r ApiInstanceListRequest) Id(id string) ApiInstanceListRequest { + r.id = &id + return r +} + +// Using this parameter, you can filter by id, reference or IP. +func (r ApiInstanceListRequest) Filter(filter string) ApiInstanceListRequest { + r.filter = &filter + return r +} + +func (r ApiInstanceListRequest) ContractType(contractType string) ApiInstanceListRequest { + r.contractType = &contractType + return r +} + +func (r ApiInstanceListRequest) State(state string) ApiInstanceListRequest { + r.state = &state + return r +} + +// Available regions can be found using the List Regions endpoint. +func (r ApiInstanceListRequest) Region(region string) ApiInstanceListRequest { + r.region = ®ion + return r +} + +// Available instance types can be found using the List Instance Types endpoint. +func (r ApiInstanceListRequest) Type_(type_ string) ApiInstanceListRequest { + r.type_ = &type_ + return r +} + +func (r ApiInstanceListRequest) Execute() (*GetInstanceListResult, *http.Response, error) { + return r.ApiService.InstanceListExecute(r) +} + +/* +InstanceList Get instance list + +List and filter instances + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @return ApiInstanceListRequest +*/ +func (a *PublicCloudAPIService) InstanceList(ctx context.Context) ApiInstanceListRequest { + return ApiInstanceListRequest{ + ApiService: a, + ctx: ctx, + } +} + +// Execute executes the request +// @return GetInstanceListResult +func (a *PublicCloudAPIService) InstanceListExecute(r ApiInstanceListRequest) (*GetInstanceListResult, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodGet + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *GetInstanceListResult + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "PublicCloudAPIService.InstanceList") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/instances" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + if r.limit != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "limit", r.limit, "") + } + if r.offset != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "offset", r.offset, "") + } + if r.ip != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "ip", r.ip, "") + } + if r.reference != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "reference", r.reference, "") + } + if r.id != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "id", r.id, "") + } + if r.filter != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "filter", r.filter, "") + } + if r.contractType != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "contractType", r.contractType, "") + } + if r.state != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "state", r.state, "") + } + if r.region != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "region", r.region, "") + } + if r.type_ != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "type", r.type_, "") + } + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiLaunchInstanceRequest struct { + ctx context.Context + ApiService *PublicCloudAPIService + launchInstanceOpts *LaunchInstanceOpts +} + +func (r ApiLaunchInstanceRequest) LaunchInstanceOpts(launchInstanceOpts LaunchInstanceOpts) ApiLaunchInstanceRequest { + r.launchInstanceOpts = &launchInstanceOpts + return r +} + +func (r ApiLaunchInstanceRequest) Execute() (*LaunchInstanceCreatedResult, *http.Response, error) { + return r.ApiService.LaunchInstanceExecute(r) +} + +/* +LaunchInstance Launch instance + +Launch a Public Cloud instance. + +Available regions can be obtained using `/v1/regions`. + +Available Operating Systems can be obtained using `/v1/operatingSystems`. + +Available instance types for your region can be obtained using `/v1/instanceTypes`. + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @return ApiLaunchInstanceRequest +*/ +func (a *PublicCloudAPIService) LaunchInstance(ctx context.Context) ApiLaunchInstanceRequest { + return ApiLaunchInstanceRequest{ + ApiService: a, + ctx: ctx, + } +} + +// Execute executes the request +// @return LaunchInstanceCreatedResult +func (a *PublicCloudAPIService) LaunchInstanceExecute(r ApiLaunchInstanceRequest) (*LaunchInstanceCreatedResult, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodPost + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *LaunchInstanceCreatedResult + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "PublicCloudAPIService.LaunchInstance") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/instances" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + if r.launchInstanceOpts == nil { + return localVarReturnValue, nil, reportError("launchInstanceOpts is required and must be specified") + } + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{"application/json"} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + // body params + localVarPostBody = r.launchInstanceOpts + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiRebootInstanceRequest struct { + ctx context.Context + ApiService *PublicCloudAPIService + instanceId string +} + +func (r ApiRebootInstanceRequest) Execute() (*http.Response, error) { + return r.ApiService.RebootInstanceExecute(r) +} + +/* +RebootInstance Reboot instance + +The instance must be running before the execution + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param instanceId Instance's ID + @return ApiRebootInstanceRequest +*/ +func (a *PublicCloudAPIService) RebootInstance(ctx context.Context, instanceId string) ApiRebootInstanceRequest { + return ApiRebootInstanceRequest{ + ApiService: a, + ctx: ctx, + instanceId: instanceId, + } +} + +// Execute executes the request +func (a *PublicCloudAPIService) RebootInstanceExecute(r ApiRebootInstanceRequest) (*http.Response, error) { + var ( + localVarHTTPMethod = http.MethodPost + localVarPostBody interface{} + formFiles []formFile + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "PublicCloudAPIService.RebootInstance") + if err != nil { + return nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/instances/{instanceId}/reboot" + localVarPath = strings.Replace(localVarPath, "{"+"instanceId"+"}", url.PathEscape(parameterValueToString(r.instanceId, "instanceId")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 404 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarHTTPResponse, newErr + } + + return localVarHTTPResponse, nil +} + +type ApiRegionsListRequest struct { + ctx context.Context + ApiService *PublicCloudAPIService + limit *int32 + offset *int32 +} + +// Limit the number of results returned. +func (r ApiRegionsListRequest) Limit(limit int32) ApiRegionsListRequest { + r.limit = &limit + return r +} + +// Return results starting from the given offset. +func (r ApiRegionsListRequest) Offset(offset int32) ApiRegionsListRequest { + r.offset = &offset + return r +} + +func (r ApiRegionsListRequest) Execute() (*GetRegionListResult, *http.Response, error) { + return r.ApiService.RegionsListExecute(r) +} + +/* +RegionsList List regions + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @return ApiRegionsListRequest +*/ +func (a *PublicCloudAPIService) RegionsList(ctx context.Context) ApiRegionsListRequest { + return ApiRegionsListRequest{ + ApiService: a, + ctx: ctx, + } +} + +// Execute executes the request +// @return GetRegionListResult +func (a *PublicCloudAPIService) RegionsListExecute(r ApiRegionsListRequest) (*GetRegionListResult, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodGet + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *GetRegionListResult + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "PublicCloudAPIService.RegionsList") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/regions" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + if r.limit != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "limit", r.limit, "") + } + if r.offset != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "offset", r.offset, "") + } + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiResetPasswordRequest struct { + ctx context.Context + ApiService *PublicCloudAPIService + instanceId string +} + +func (r ApiResetPasswordRequest) Execute() (*http.Response, error) { + return r.ApiService.ResetPasswordExecute(r) +} + +/* +ResetPassword Reset instance password + +The operation may take a few moments to complete. + +You can obtain the new credential using the credentials endpoints + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param instanceId Instance's ID + @return ApiResetPasswordRequest +*/ +func (a *PublicCloudAPIService) ResetPassword(ctx context.Context, instanceId string) ApiResetPasswordRequest { + return ApiResetPasswordRequest{ + ApiService: a, + ctx: ctx, + instanceId: instanceId, + } +} + +// Execute executes the request +func (a *PublicCloudAPIService) ResetPasswordExecute(r ApiResetPasswordRequest) (*http.Response, error) { + var ( + localVarHTTPMethod = http.MethodPost + localVarPostBody interface{} + formFiles []formFile + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "PublicCloudAPIService.ResetPassword") + if err != nil { + return nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/instances/{instanceId}/resetPassword" + localVarPath = strings.Replace(localVarPath, "{"+"instanceId"+"}", url.PathEscape(parameterValueToString(r.instanceId, "instanceId")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 404 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarHTTPResponse, newErr + } + + return localVarHTTPResponse, nil +} + +type ApiStartInstanceRequest struct { + ctx context.Context + ApiService *PublicCloudAPIService + instanceId string +} + +func (r ApiStartInstanceRequest) Execute() (*http.Response, error) { + return r.ApiService.StartInstanceExecute(r) +} + +/* +StartInstance Start instance + +The instance must be stopped before the execution + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param instanceId Instance's ID + @return ApiStartInstanceRequest +*/ +func (a *PublicCloudAPIService) StartInstance(ctx context.Context, instanceId string) ApiStartInstanceRequest { + return ApiStartInstanceRequest{ + ApiService: a, + ctx: ctx, + instanceId: instanceId, + } +} + +// Execute executes the request +func (a *PublicCloudAPIService) StartInstanceExecute(r ApiStartInstanceRequest) (*http.Response, error) { + var ( + localVarHTTPMethod = http.MethodPost + localVarPostBody interface{} + formFiles []formFile + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "PublicCloudAPIService.StartInstance") + if err != nil { + return nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/instances/{instanceId}/start" + localVarPath = strings.Replace(localVarPath, "{"+"instanceId"+"}", url.PathEscape(parameterValueToString(r.instanceId, "instanceId")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 404 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarHTTPResponse, newErr + } + + return localVarHTTPResponse, nil +} + +type ApiStopInstanceRequest struct { + ctx context.Context + ApiService *PublicCloudAPIService + instanceId string +} + +func (r ApiStopInstanceRequest) Execute() (*http.Response, error) { + return r.ApiService.StopInstanceExecute(r) +} + +/* +StopInstance Stop instance + +The instance must be running before the execution + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param instanceId Instance's ID + @return ApiStopInstanceRequest +*/ +func (a *PublicCloudAPIService) StopInstance(ctx context.Context, instanceId string) ApiStopInstanceRequest { + return ApiStopInstanceRequest{ + ApiService: a, + ctx: ctx, + instanceId: instanceId, + } +} + +// Execute executes the request +func (a *PublicCloudAPIService) StopInstanceExecute(r ApiStopInstanceRequest) (*http.Response, error) { + var ( + localVarHTTPMethod = http.MethodPost + localVarPostBody interface{} + formFiles []formFile + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "PublicCloudAPIService.StopInstance") + if err != nil { + return nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/instances/{instanceId}/stop" + localVarPath = strings.Replace(localVarPath, "{"+"instanceId"+"}", url.PathEscape(parameterValueToString(r.instanceId, "instanceId")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 404 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarHTTPResponse, newErr + } + + return localVarHTTPResponse, nil +} + +type ApiStoreCredentialRequest struct { + ctx context.Context + ApiService *PublicCloudAPIService + instanceId string + storeCredentialOpts *StoreCredentialOpts +} + +func (r ApiStoreCredentialRequest) StoreCredentialOpts(storeCredentialOpts StoreCredentialOpts) ApiStoreCredentialRequest { + r.storeCredentialOpts = &storeCredentialOpts + return r +} + +func (r ApiStoreCredentialRequest) Execute() (*StoreCredentialResult, *http.Response, error) { + return r.ApiService.StoreCredentialExecute(r) +} + +/* +StoreCredential Store credentials + +Store credential used for the instance + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param instanceId Instance's ID + @return ApiStoreCredentialRequest +*/ +func (a *PublicCloudAPIService) StoreCredential(ctx context.Context, instanceId string) ApiStoreCredentialRequest { + return ApiStoreCredentialRequest{ + ApiService: a, + ctx: ctx, + instanceId: instanceId, + } +} + +// Execute executes the request +// @return StoreCredentialResult +func (a *PublicCloudAPIService) StoreCredentialExecute(r ApiStoreCredentialRequest) (*StoreCredentialResult, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodPost + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *StoreCredentialResult + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "PublicCloudAPIService.StoreCredential") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/instances/{instanceId}/credentials" + localVarPath = strings.Replace(localVarPath, "{"+"instanceId"+"}", url.PathEscape(parameterValueToString(r.instanceId, "instanceId")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + if r.storeCredentialOpts == nil { + return localVarReturnValue, nil, reportError("storeCredentialOpts is required and must be specified") + } + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{"application/json"} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + // body params + localVarPostBody = r.storeCredentialOpts + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 404 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiTerminateInstanceRequest struct { + ctx context.Context + ApiService *PublicCloudAPIService + instanceId string +} + +func (r ApiTerminateInstanceRequest) Execute() (*http.Response, error) { + return r.ApiService.TerminateInstanceExecute(r) +} + +/* +TerminateInstance Terminate instance + +Terminate Public Cloud instance + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param instanceId Instance's ID + @return ApiTerminateInstanceRequest +*/ +func (a *PublicCloudAPIService) TerminateInstance(ctx context.Context, instanceId string) ApiTerminateInstanceRequest { + return ApiTerminateInstanceRequest{ + ApiService: a, + ctx: ctx, + instanceId: instanceId, + } +} + +// Execute executes the request +func (a *PublicCloudAPIService) TerminateInstanceExecute(r ApiTerminateInstanceRequest) (*http.Response, error) { + var ( + localVarHTTPMethod = http.MethodDelete + localVarPostBody interface{} + formFiles []formFile + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "PublicCloudAPIService.TerminateInstance") + if err != nil { + return nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/instances/{instanceId}" + localVarPath = strings.Replace(localVarPath, "{"+"instanceId"+"}", url.PathEscape(parameterValueToString(r.instanceId, "instanceId")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 404 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarHTTPResponse, newErr + } + + return localVarHTTPResponse, nil +} + +type ApiUpdateCredentialRequest struct { + ctx context.Context + ApiService *PublicCloudAPIService + instanceId string + type_ string + username string + updateCredentialOpts *UpdateCredentialOpts +} + +func (r ApiUpdateCredentialRequest) UpdateCredentialOpts(updateCredentialOpts UpdateCredentialOpts) ApiUpdateCredentialRequest { + r.updateCredentialOpts = &updateCredentialOpts + return r +} + +func (r ApiUpdateCredentialRequest) Execute() (*UpdateCredentialResult, *http.Response, error) { + return r.ApiService.UpdateCredentialExecute(r) +} + +/* +UpdateCredential Update credentials + +Update credentials for a given type and username + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param instanceId Instance's ID + @param type_ Credential type + @param username Username + @return ApiUpdateCredentialRequest +*/ +func (a *PublicCloudAPIService) UpdateCredential(ctx context.Context, instanceId string, type_ string, username string) ApiUpdateCredentialRequest { + return ApiUpdateCredentialRequest{ + ApiService: a, + ctx: ctx, + instanceId: instanceId, + type_: type_, + username: username, + } +} + +// Execute executes the request +// @return UpdateCredentialResult +func (a *PublicCloudAPIService) UpdateCredentialExecute(r ApiUpdateCredentialRequest) (*UpdateCredentialResult, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodPut + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *UpdateCredentialResult + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "PublicCloudAPIService.UpdateCredential") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/instances/{instanceId}/credentials/{type}/{username}" + localVarPath = strings.Replace(localVarPath, "{"+"instanceId"+"}", url.PathEscape(parameterValueToString(r.instanceId, "instanceId")), -1) + localVarPath = strings.Replace(localVarPath, "{"+"type"+"}", url.PathEscape(parameterValueToString(r.type_, "type_")), -1) + localVarPath = strings.Replace(localVarPath, "{"+"username"+"}", url.PathEscape(parameterValueToString(r.username, "username")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + if r.updateCredentialOpts == nil { + return localVarReturnValue, nil, reportError("updateCredentialOpts is required and must be specified") + } + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{"application/json"} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + // body params + localVarPostBody = r.updateCredentialOpts + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 404 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiUpdateInstanceRequest struct { + ctx context.Context + ApiService *PublicCloudAPIService + instanceId string + updateInstanceOpts *UpdateInstanceOpts +} + +func (r ApiUpdateInstanceRequest) UpdateInstanceOpts(updateInstanceOpts UpdateInstanceOpts) ApiUpdateInstanceRequest { + r.updateInstanceOpts = &updateInstanceOpts + return r +} + +func (r ApiUpdateInstanceRequest) Execute() (*UpdateInstanceResult, *http.Response, error) { + return r.ApiService.UpdateInstanceExecute(r) +} + +/* +UpdateInstance Update instance + +Update the instance's reference, type, storage or contract type. + +Eligible instance types for update can be obtained using `/v1/instances/{instanceId}/instanceTypesUpdate`. + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param instanceId Instance's ID + @return ApiUpdateInstanceRequest +*/ +func (a *PublicCloudAPIService) UpdateInstance(ctx context.Context, instanceId string) ApiUpdateInstanceRequest { + return ApiUpdateInstanceRequest{ + ApiService: a, + ctx: ctx, + instanceId: instanceId, + } +} + +// Execute executes the request +// @return UpdateInstanceResult +func (a *PublicCloudAPIService) UpdateInstanceExecute(r ApiUpdateInstanceRequest) (*UpdateInstanceResult, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodPut + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *UpdateInstanceResult + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "PublicCloudAPIService.UpdateInstance") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/instances/{instanceId}" + localVarPath = strings.Replace(localVarPath, "{"+"instanceId"+"}", url.PathEscape(parameterValueToString(r.instanceId, "instanceId")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + if r.updateInstanceOpts == nil { + return localVarReturnValue, nil, reportError("updateInstanceOpts is required and must be specified") + } + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{"application/json"} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + // body params + localVarPostBody = r.updateInstanceOpts + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["ApiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["X-LSW-Auth"] = key + } + } + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 404 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 503 { + var v ErrorResult + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} diff --git a/publicCloud/client.go b/publicCloud/client.go new file mode 100644 index 0000000..33147f2 --- /dev/null +++ b/publicCloud/client.go @@ -0,0 +1,677 @@ +/* +LeaseWeb API for launching and managing Public Cloud instances + +> The base URL for this API is: **https://api.leaseweb.com/publicCloud/v1/_** This API provides ways to launch and manage Public Cloud instances.
BETA
This API is in BETA. Documentation might be incorrect or incomplete. Functionality might change with the final release.> + +API version: v1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package publicCloud + +import ( + "bytes" + "context" + "encoding/json" + "encoding/xml" + "errors" + "fmt" + "io" + "log" + "mime/multipart" + "net/http" + "net/http/httputil" + "net/url" + "os" + "path/filepath" + "reflect" + "regexp" + "strconv" + "strings" + "time" + "unicode/utf8" + + "golang.org/x/oauth2" +) + +var ( + JsonCheck = regexp.MustCompile(`(?i:(?:application|text)/(?:[^;]+\+)?json)`) + XmlCheck = regexp.MustCompile(`(?i:(?:application|text)/(?:[^;]+\+)?xml)`) + queryParamSplit = regexp.MustCompile(`(^|&)([^&]+)`) + queryDescape = strings.NewReplacer( "%5B", "[", "%5D", "]" ) +) + +// APIClient manages communication with the LeaseWeb API for launching and managing Public Cloud instances API vv1 +// In most cases there should be only one, shared, APIClient. +type APIClient struct { + cfg *Configuration + common service // Reuse a single struct instead of allocating one for each service on the heap. + + // API Services + + PublicCloudAPI *PublicCloudAPIService +} + +type service struct { + client *APIClient +} + +// NewAPIClient creates a new API client. Requires a userAgent string describing your application. +// optionally a custom http.Client to allow for advanced features such as caching. +func NewAPIClient(cfg *Configuration) *APIClient { + if cfg.HTTPClient == nil { + cfg.HTTPClient = http.DefaultClient + } + + c := &APIClient{} + c.cfg = cfg + c.common.client = c + + // API Services + c.PublicCloudAPI = (*PublicCloudAPIService)(&c.common) + + return c +} + +func atoi(in string) (int, error) { + return strconv.Atoi(in) +} + +// selectHeaderContentType select a content type from the available list. +func selectHeaderContentType(contentTypes []string) string { + if len(contentTypes) == 0 { + return "" + } + if contains(contentTypes, "application/json") { + return "application/json" + } + return contentTypes[0] // use the first content type specified in 'consumes' +} + +// selectHeaderAccept join all accept types and return +func selectHeaderAccept(accepts []string) string { + if len(accepts) == 0 { + return "" + } + + if contains(accepts, "application/json") { + return "application/json" + } + + return strings.Join(accepts, ",") +} + +// contains is a case insensitive match, finding needle in a haystack +func contains(haystack []string, needle string) bool { + for _, a := range haystack { + if strings.EqualFold(a, needle) { + return true + } + } + return false +} + +// Verify optional parameters are of the correct type. +func typeCheckParameter(obj interface{}, expected string, name string) error { + // Make sure there is an object. + if obj == nil { + return nil + } + + // Check the type is as expected. + if reflect.TypeOf(obj).String() != expected { + return fmt.Errorf("expected %s to be of type %s but received %s", name, expected, reflect.TypeOf(obj).String()) + } + return nil +} + +func parameterValueToString( obj interface{}, key string ) string { + if reflect.TypeOf(obj).Kind() != reflect.Ptr { + return fmt.Sprintf("%v", obj) + } + var param,ok = obj.(MappedNullable) + if !ok { + return "" + } + dataMap,err := param.ToMap() + if err != nil { + return "" + } + return fmt.Sprintf("%v", dataMap[key]) +} + +// parameterAddToHeaderOrQuery adds the provided object to the request header or url query +// supporting deep object syntax +func parameterAddToHeaderOrQuery(headerOrQueryParams interface{}, keyPrefix string, obj interface{}, collectionType string) { + var v = reflect.ValueOf(obj) + var value = "" + if v == reflect.ValueOf(nil) { + value = "null" + } else { + switch v.Kind() { + case reflect.Invalid: + value = "invalid" + + case reflect.Struct: + if t,ok := obj.(MappedNullable); ok { + dataMap,err := t.ToMap() + if err != nil { + return + } + parameterAddToHeaderOrQuery(headerOrQueryParams, keyPrefix, dataMap, collectionType) + return + } + if t, ok := obj.(time.Time); ok { + parameterAddToHeaderOrQuery(headerOrQueryParams, keyPrefix, t.Format(time.RFC3339), collectionType) + return + } + value = v.Type().String() + " value" + case reflect.Slice: + var indValue = reflect.ValueOf(obj) + if indValue == reflect.ValueOf(nil) { + return + } + var lenIndValue = indValue.Len() + for i:=0;i 0 || (len(formFiles) > 0) { + if body != nil { + return nil, errors.New("Cannot specify postBody and multipart form at the same time.") + } + body = &bytes.Buffer{} + w := multipart.NewWriter(body) + + for k, v := range formParams { + for _, iv := range v { + if strings.HasPrefix(k, "@") { // file + err = addFile(w, k[1:], iv) + if err != nil { + return nil, err + } + } else { // form value + w.WriteField(k, iv) + } + } + } + for _, formFile := range formFiles { + if len(formFile.fileBytes) > 0 && formFile.fileName != "" { + w.Boundary() + part, err := w.CreateFormFile(formFile.formFileName, filepath.Base(formFile.fileName)) + if err != nil { + return nil, err + } + _, err = part.Write(formFile.fileBytes) + if err != nil { + return nil, err + } + } + } + + // Set the Boundary in the Content-Type + headerParams["Content-Type"] = w.FormDataContentType() + + // Set Content-Length + headerParams["Content-Length"] = fmt.Sprintf("%d", body.Len()) + w.Close() + } + + if strings.HasPrefix(headerParams["Content-Type"], "application/x-www-form-urlencoded") && len(formParams) > 0 { + if body != nil { + return nil, errors.New("Cannot specify postBody and x-www-form-urlencoded form at the same time.") + } + body = &bytes.Buffer{} + body.WriteString(formParams.Encode()) + // Set Content-Length + headerParams["Content-Length"] = fmt.Sprintf("%d", body.Len()) + } + + // Setup path and query parameters + url, err := url.Parse(path) + if err != nil { + return nil, err + } + + // Override request host, if applicable + if c.cfg.Host != "" { + url.Host = c.cfg.Host + } + + // Override request scheme, if applicable + if c.cfg.Scheme != "" { + url.Scheme = c.cfg.Scheme + } + + // Adding Query Param + query := url.Query() + for k, v := range queryParams { + for _, iv := range v { + query.Add(k, iv) + } + } + + // Encode the parameters. + url.RawQuery = queryParamSplit.ReplaceAllStringFunc(query.Encode(), func(s string) string { + pieces := strings.Split(s, "=") + pieces[0] = queryDescape.Replace(pieces[0]) + return strings.Join(pieces, "=") + }) + + // Generate a new request + if body != nil { + localVarRequest, err = http.NewRequest(method, url.String(), body) + } else { + localVarRequest, err = http.NewRequest(method, url.String(), nil) + } + if err != nil { + return nil, err + } + + // add header parameters, if any + if len(headerParams) > 0 { + headers := http.Header{} + for h, v := range headerParams { + headers[h] = []string{v} + } + localVarRequest.Header = headers + } + + // Add the user agent to the request. + localVarRequest.Header.Add("User-Agent", c.cfg.UserAgent) + + if ctx != nil { + // add context to the request + localVarRequest = localVarRequest.WithContext(ctx) + + // Walk through any authentication. + + // OAuth2 authentication + if tok, ok := ctx.Value(ContextOAuth2).(oauth2.TokenSource); ok { + // We were able to grab an oauth2 token from the context + var latestToken *oauth2.Token + if latestToken, err = tok.Token(); err != nil { + return nil, err + } + + latestToken.SetAuthHeader(localVarRequest) + } + + // AccessToken Authentication + if auth, ok := ctx.Value(ContextAccessToken).(string); ok { + localVarRequest.Header.Add("Authorization", "Bearer "+auth) + } + + } + + for header, value := range c.cfg.DefaultHeader { + localVarRequest.Header.Add(header, value) + } + return localVarRequest, nil +} + +func (c *APIClient) decode(v interface{}, b []byte, contentType string) (err error) { + if len(b) == 0 { + return nil + } + if s, ok := v.(*string); ok { + *s = string(b) + return nil + } + if f, ok := v.(*os.File); ok { + f, err = os.CreateTemp("", "HttpClientFile") + if err != nil { + return + } + _, err = f.Write(b) + if err != nil { + return + } + _, err = f.Seek(0, io.SeekStart) + return + } + if f, ok := v.(**os.File); ok { + *f, err = os.CreateTemp("", "HttpClientFile") + if err != nil { + return + } + _, err = (*f).Write(b) + if err != nil { + return + } + _, err = (*f).Seek(0, io.SeekStart) + return + } + if XmlCheck.MatchString(contentType) { + if err = xml.Unmarshal(b, v); err != nil { + return err + } + return nil + } + if JsonCheck.MatchString(contentType) { + if actualObj, ok := v.(interface{ GetActualInstance() interface{} }); ok { // oneOf, anyOf schemas + if unmarshalObj, ok := actualObj.(interface{ UnmarshalJSON([]byte) error }); ok { // make sure it has UnmarshalJSON defined + if err = unmarshalObj.UnmarshalJSON(b); err != nil { + return err + } + } else { + return errors.New("Unknown type with GetActualInstance but no unmarshalObj.UnmarshalJSON defined") + } + } else if err = json.Unmarshal(b, v); err != nil { // simple model + return err + } + return nil + } + return errors.New("undefined response type") +} + +// Add a file to the multipart request +func addFile(w *multipart.Writer, fieldName, path string) error { + file, err := os.Open(filepath.Clean(path)) + if err != nil { + return err + } + err = file.Close() + if err != nil { + return err + } + + part, err := w.CreateFormFile(fieldName, filepath.Base(path)) + if err != nil { + return err + } + _, err = io.Copy(part, file) + + return err +} + +// Prevent trying to import "fmt" +func reportError(format string, a ...interface{}) error { + return fmt.Errorf(format, a...) +} + +// A wrapper for strict JSON decoding +func newStrictDecoder(data []byte) *json.Decoder { + dec := json.NewDecoder(bytes.NewBuffer(data)) + dec.DisallowUnknownFields() + return dec +} + +// Set request body from an interface{} +func setBody(body interface{}, contentType string) (bodyBuf *bytes.Buffer, err error) { + if bodyBuf == nil { + bodyBuf = &bytes.Buffer{} + } + + if reader, ok := body.(io.Reader); ok { + _, err = bodyBuf.ReadFrom(reader) + } else if fp, ok := body.(*os.File); ok { + _, err = bodyBuf.ReadFrom(fp) + } else if b, ok := body.([]byte); ok { + _, err = bodyBuf.Write(b) + } else if s, ok := body.(string); ok { + _, err = bodyBuf.WriteString(s) + } else if s, ok := body.(*string); ok { + _, err = bodyBuf.WriteString(*s) + } else if JsonCheck.MatchString(contentType) { + err = json.NewEncoder(bodyBuf).Encode(body) + } else if XmlCheck.MatchString(contentType) { + var bs []byte + bs, err = xml.Marshal(body) + if err == nil { + bodyBuf.Write(bs) + } + } + + if err != nil { + return nil, err + } + + if bodyBuf.Len() == 0 { + err = fmt.Errorf("invalid body type %s\n", contentType) + return nil, err + } + return bodyBuf, nil +} + +// detectContentType method is used to figure out `Request.Body` content type for request header +func detectContentType(body interface{}) string { + contentType := "text/plain; charset=utf-8" + kind := reflect.TypeOf(body).Kind() + + switch kind { + case reflect.Struct, reflect.Map, reflect.Ptr: + contentType = "application/json; charset=utf-8" + case reflect.String: + contentType = "text/plain; charset=utf-8" + default: + if b, ok := body.([]byte); ok { + contentType = http.DetectContentType(b) + } else if kind == reflect.Slice { + contentType = "application/json; charset=utf-8" + } + } + + return contentType +} + +// Ripped from https://github.com/gregjones/httpcache/blob/master/httpcache.go +type cacheControl map[string]string + +func parseCacheControl(headers http.Header) cacheControl { + cc := cacheControl{} + ccHeader := headers.Get("Cache-Control") + for _, part := range strings.Split(ccHeader, ",") { + part = strings.Trim(part, " ") + if part == "" { + continue + } + if strings.ContainsRune(part, '=') { + keyval := strings.Split(part, "=") + cc[strings.Trim(keyval[0], " ")] = strings.Trim(keyval[1], ",") + } else { + cc[part] = "" + } + } + return cc +} + +// CacheExpires helper function to determine remaining time before repeating a request. +func CacheExpires(r *http.Response) time.Time { + // Figure out when the cache expires. + var expires time.Time + now, err := time.Parse(time.RFC1123, r.Header.Get("date")) + if err != nil { + return time.Now() + } + respCacheControl := parseCacheControl(r.Header) + + if maxAge, ok := respCacheControl["max-age"]; ok { + lifetime, err := time.ParseDuration(maxAge + "s") + if err != nil { + expires = now + } else { + expires = now.Add(lifetime) + } + } else { + expiresHeader := r.Header.Get("Expires") + if expiresHeader != "" { + expires, err = time.Parse(time.RFC1123, expiresHeader) + if err != nil { + expires = now + } + } + } + return expires +} + +func strlen(s string) int { + return utf8.RuneCountInString(s) +} + +// GenericOpenAPIError Provides access to the body, error and model on returned errors. +type GenericOpenAPIError struct { + body []byte + error string + model interface{} +} + +// Error returns non-empty string if there was an error. +func (e GenericOpenAPIError) Error() string { + return e.error +} + +// Body returns the raw bytes of the response +func (e GenericOpenAPIError) Body() []byte { + return e.body +} + +// Model returns the unpacked model of the error +func (e GenericOpenAPIError) Model() interface{} { + return e.model +} + +// format error message using title and detail when model implements rfc7807 +func formatErrorMessage(status string, v interface{}) string { + str := "" + metaValue := reflect.ValueOf(v).Elem() + + if metaValue.Kind() == reflect.Struct { + field := metaValue.FieldByName("Title") + if field != (reflect.Value{}) { + str = fmt.Sprintf("%s", field.Interface()) + } + + field = metaValue.FieldByName("Detail") + if field != (reflect.Value{}) { + str = fmt.Sprintf("%s (%s)", str, field.Interface()) + } + } + + return strings.TrimSpace(fmt.Sprintf("%s %s", status, str)) +} diff --git a/publicCloud/configuration.go b/publicCloud/configuration.go new file mode 100644 index 0000000..2145e8e --- /dev/null +++ b/publicCloud/configuration.go @@ -0,0 +1,224 @@ +/* +LeaseWeb API for launching and managing Public Cloud instances + +> The base URL for this API is: **https://api.leaseweb.com/publicCloud/v1/_** This API provides ways to launch and manage Public Cloud instances.
BETA
This API is in BETA. Documentation might be incorrect or incomplete. Functionality might change with the final release.> + +API version: v1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package publicCloud + +import ( + "context" + "fmt" + "net/http" + "strings" +) + +// contextKeys are used to identify the type of value in the context. +// Since these are string, it is possible to get a short description of the +// context key for logging and debugging using key.String(). + +type contextKey string + +func (c contextKey) String() string { + return "auth " + string(c) +} + +var ( + // ContextOAuth2 takes an oauth2.TokenSource as authentication for the request. + ContextOAuth2 = contextKey("token") + + // ContextAccessToken takes a string oauth2 access token as authentication for the request. + ContextAccessToken = contextKey("accesstoken") + + // ContextAPIKeys takes a string apikey as authentication for the request + ContextAPIKeys = contextKey("apiKeys") + + // ContextServerIndex uses a server configuration from the index. + ContextServerIndex = contextKey("serverIndex") + + // ContextOperationServerIndices uses a server configuration from the index mapping. + ContextOperationServerIndices = contextKey("serverOperationIndices") + + // ContextServerVariables overrides a server configuration variables. + ContextServerVariables = contextKey("serverVariables") + + // ContextOperationServerVariables overrides a server configuration variables using operation specific values. + ContextOperationServerVariables = contextKey("serverOperationVariables") +) + +// BasicAuth provides basic http authentication to a request passed via context using ContextBasicAuth +type BasicAuth struct { + UserName string `json:"userName,omitempty"` + Password string `json:"password,omitempty"` +} + +// APIKey provides API key based authentication to a request passed via context using ContextAPIKey +type APIKey struct { + Key string + Prefix string +} + +// ServerVariable stores the information about a server variable +type ServerVariable struct { + Description string + DefaultValue string + EnumValues []string +} + +// ServerConfiguration stores the information about a server +type ServerConfiguration struct { + URL string + Description string + Variables map[string]ServerVariable +} + +// ServerConfigurations stores multiple ServerConfiguration items +type ServerConfigurations []ServerConfiguration + +// Configuration stores the configuration of the API client +type Configuration struct { + Host string `json:"host,omitempty"` + Scheme string `json:"scheme,omitempty"` + DefaultHeader map[string]string `json:"defaultHeader,omitempty"` + UserAgent string `json:"userAgent,omitempty"` + Debug bool `json:"debug,omitempty"` + Servers ServerConfigurations + OperationServers map[string]ServerConfigurations + HTTPClient *http.Client +} + +// NewConfiguration returns a new Configuration object +func NewConfiguration() *Configuration { + cfg := &Configuration{ + DefaultHeader: make(map[string]string), + UserAgent: "OpenAPI-Generator/1.0.0/go", + Debug: false, + Servers: ServerConfigurations{ + { + URL: "https://api.leaseweb.com/publicCloud/v1", + Description: "No description provided", + }, + }, + OperationServers: map[string]ServerConfigurations{ + }, + } + return cfg +} + +// AddDefaultHeader adds a new HTTP header to the default header in the request +func (c *Configuration) AddDefaultHeader(key string, value string) { + c.DefaultHeader[key] = value +} + +// URL formats template on a index using given variables +func (sc ServerConfigurations) URL(index int, variables map[string]string) (string, error) { + if index < 0 || len(sc) <= index { + return "", fmt.Errorf("index %v out of range %v", index, len(sc)-1) + } + server := sc[index] + url := server.URL + + // go through variables and replace placeholders + for name, variable := range server.Variables { + if value, ok := variables[name]; ok { + found := bool(len(variable.EnumValues) == 0) + for _, enumValue := range variable.EnumValues { + if value == enumValue { + found = true + } + } + if !found { + return "", fmt.Errorf("the variable %s in the server URL has invalid value %v. Must be %v", name, value, variable.EnumValues) + } + url = strings.Replace(url, "{"+name+"}", value, -1) + } else { + url = strings.Replace(url, "{"+name+"}", variable.DefaultValue, -1) + } + } + return url, nil +} + +// ServerURL returns URL based on server settings +func (c *Configuration) ServerURL(index int, variables map[string]string) (string, error) { + return c.Servers.URL(index, variables) +} + +func getServerIndex(ctx context.Context) (int, error) { + si := ctx.Value(ContextServerIndex) + if si != nil { + if index, ok := si.(int); ok { + return index, nil + } + return 0, reportError("Invalid type %T should be int", si) + } + return 0, nil +} + +func getServerOperationIndex(ctx context.Context, endpoint string) (int, error) { + osi := ctx.Value(ContextOperationServerIndices) + if osi != nil { + if operationIndices, ok := osi.(map[string]int); !ok { + return 0, reportError("Invalid type %T should be map[string]int", osi) + } else { + index, ok := operationIndices[endpoint] + if ok { + return index, nil + } + } + } + return getServerIndex(ctx) +} + +func getServerVariables(ctx context.Context) (map[string]string, error) { + sv := ctx.Value(ContextServerVariables) + if sv != nil { + if variables, ok := sv.(map[string]string); ok { + return variables, nil + } + return nil, reportError("ctx value of ContextServerVariables has invalid type %T should be map[string]string", sv) + } + return nil, nil +} + +func getServerOperationVariables(ctx context.Context, endpoint string) (map[string]string, error) { + osv := ctx.Value(ContextOperationServerVariables) + if osv != nil { + if operationVariables, ok := osv.(map[string]map[string]string); !ok { + return nil, reportError("ctx value of ContextOperationServerVariables has invalid type %T should be map[string]map[string]string", osv) + } else { + variables, ok := operationVariables[endpoint] + if ok { + return variables, nil + } + } + } + return getServerVariables(ctx) +} + +// ServerURLWithContext returns a new server URL given an endpoint +func (c *Configuration) ServerURLWithContext(ctx context.Context, endpoint string) (string, error) { + sc, ok := c.OperationServers[endpoint] + if !ok { + sc = c.Servers + } + + if ctx == nil { + return sc.URL(0, nil) + } + + index, err := getServerOperationIndex(ctx, endpoint) + if err != nil { + return "", err + } + + variables, err := getServerOperationVariables(ctx, endpoint) + if err != nil { + return "", err + } + + return sc.URL(index, variables) +} diff --git a/publicCloud/go.mod b/publicCloud/go.mod new file mode 100644 index 0000000..ad416c0 --- /dev/null +++ b/publicCloud/go.mod @@ -0,0 +1,7 @@ +module github.com/leaseweb/leaseweb-go-sdk/publicCloud + +go 1.18 + +require ( + golang.org/x/oauth2 v0.0.0-20210323180902-22b0adad7558 +) diff --git a/publicCloud/go.sum b/publicCloud/go.sum new file mode 100644 index 0000000..3dee6d6 --- /dev/null +++ b/publicCloud/go.sum @@ -0,0 +1,360 @@ +cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU= +cloud.google.com/go v0.44.1/go.mod h1:iSa0KzasP4Uvy3f1mN/7PiObzGgflwredwwASm/v6AU= +cloud.google.com/go v0.44.2/go.mod h1:60680Gw3Yr4ikxnPRS/oxxkBccT6SA1yMk63TGekxKY= +cloud.google.com/go v0.45.1/go.mod h1:RpBamKRgapWJb87xiFSdk4g1CME7QZg3uwTez+TSTjc= +cloud.google.com/go v0.46.3/go.mod h1:a6bKKbmY7er1mI7TEI4lsAkts/mkhTSZK8w33B4RAg0= +cloud.google.com/go v0.50.0/go.mod h1:r9sluTvynVuxRIOHXQEHMFffphuXHOMZMycpNR5e6To= +cloud.google.com/go v0.52.0/go.mod h1:pXajvRH/6o3+F9jDHZWQ5PbGhn+o8w9qiu/CffaVdO4= +cloud.google.com/go v0.53.0/go.mod h1:fp/UouUEsRkN6ryDKNW/Upv/JBKnv6WDthjR6+vze6M= +cloud.google.com/go v0.54.0/go.mod h1:1rq2OEkV3YMf6n/9ZvGWI3GWw0VoqH/1x2nd8Is/bPc= +cloud.google.com/go v0.56.0/go.mod h1:jr7tqZxxKOVYizybht9+26Z/gUq7tiRzu+ACVAMbKVk= +cloud.google.com/go v0.57.0/go.mod h1:oXiQ6Rzq3RAkkY7N6t3TcE6jE+CIBBbA36lwQ1JyzZs= +cloud.google.com/go v0.62.0/go.mod h1:jmCYTdRCQuc1PHIIJ/maLInMho30T/Y0M4hTdTShOYc= +cloud.google.com/go v0.65.0/go.mod h1:O5N8zS7uWy9vkA9vayVHs65eM1ubvY4h553ofrNHObY= +cloud.google.com/go/bigquery v1.0.1/go.mod h1:i/xbL2UlR5RvWAURpBYZTtm/cXjCha9lbfbpx4poX+o= +cloud.google.com/go/bigquery v1.3.0/go.mod h1:PjpwJnslEMmckchkHFfq+HTD2DmtT67aNFKH1/VBDHE= +cloud.google.com/go/bigquery v1.4.0/go.mod h1:S8dzgnTigyfTmLBfrtrhyYhwRxG72rYxvftPBK2Dvzc= +cloud.google.com/go/bigquery v1.5.0/go.mod h1:snEHRnqQbz117VIFhE8bmtwIDY80NLUZUMb4Nv6dBIg= +cloud.google.com/go/bigquery v1.7.0/go.mod h1://okPTzCYNXSlb24MZs83e2Do+h+VXtc4gLoIoXIAPc= +cloud.google.com/go/bigquery v1.8.0/go.mod h1:J5hqkt3O0uAFnINi6JXValWIb1v0goeZM77hZzJN/fQ= +cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7TKLgZqpHYE= +cloud.google.com/go/datastore v1.1.0/go.mod h1:umbIZjpQpHh4hmRpGhH4tLFup+FVzqBi1b3c64qFpCk= +cloud.google.com/go/pubsub v1.0.1/go.mod h1:R0Gpsv3s54REJCy4fxDixWD93lHJMoZTyQ2kNxGRt3I= +cloud.google.com/go/pubsub v1.1.0/go.mod h1:EwwdRX2sKPjnvnqCa270oGRyludottCI76h+R3AArQw= +cloud.google.com/go/pubsub v1.2.0/go.mod h1:jhfEVHT8odbXTkndysNHCcx0awwzvfOlguIAii9o8iA= +cloud.google.com/go/pubsub v1.3.1/go.mod h1:i+ucay31+CNRpDW4Lu78I4xXG+O1r/MAHgjpRVR+TSU= +cloud.google.com/go/storage v1.0.0/go.mod h1:IhtSnM/ZTZV8YYJWCY8RULGVqBDmpoyjwiyrjsg+URw= +cloud.google.com/go/storage v1.5.0/go.mod h1:tpKbwo567HUNpVclU5sGELwQWBDZ8gh0ZeosJ0Rtdos= +cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohlUTyfDhBk= +cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs= +cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0= +dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= +github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= +github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= +github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= +github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= +github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= +github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= +github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= +github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= +github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y= +github.com/golang/mock v1.4.0/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= +github.com/golang/mock v1.4.1/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= +github.com/golang/mock v1.4.3/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= +github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4= +github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= +github.com/golang/protobuf v1.3.4/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= +github.com/golang/protobuf v1.3.5/go.mod h1:6O5/vntMXwX2lRkT1hjjk0nAC1IDOTvTlVgjlRvqsdk= +github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= +github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= +github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= +github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= +github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= +github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= +github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= +github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= +github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= +github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.4.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= +github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0= +github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= +github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= +github.com/google/pprof v0.0.0-20191218002539-d4f498aebedc/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= +github.com/google/pprof v0.0.0-20200212024743-f11f1df84d12/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= +github.com/google/pprof v0.0.0-20200229191704-1ebb73c60ed3/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= +github.com/google/pprof v0.0.0-20200430221834-fc25d7d30c6d/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= +github.com/google/pprof v0.0.0-20200708004538-1a94d8640e99/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= +github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= +github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= +github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= +github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= +github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= +github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= +github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= +github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk= +github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= +go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= +go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= +go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= +go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= +golang.org/x/exp v0.0.0-20190829153037-c13cbed26979/go.mod h1:86+5VVa7VpoJ4kLfm080zCjGlMRFzhUhsZKEZO7MGek= +golang.org/x/exp v0.0.0-20191030013958-a1ab85dbe136/go.mod h1:JXzH8nQsPlswgeRAPE3MuO9GYsAcnJvJ4vnMwN/5qkY= +golang.org/x/exp v0.0.0-20191129062945-2f5052295587/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= +golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= +golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= +golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM= +golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU= +golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= +golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= +golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= +golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f/go.mod h1:5qLYkcX4OjUUV8bRuDixDT3tpyyb+LUpUlRWLxfhWrs= +golang.org/x/lint v0.0.0-20200130185559-910be7a94367/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= +golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= +golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= +golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o= +golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= +golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY= +golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= +golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= +golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e h1:bRhVy7zSSasaqNksaRZiA5EEI+Ei4I1nO5Jh72wfHlg= +golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190501004415-9ce7a6920f09/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20190628185345-da137c7871d7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200222125558-5a598a2470a0/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200501053045-e0ff5e5a1de5/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200506145744-7e3656a0809f/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200513185701-a91f0712d120/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200520182314-0ba52f642ac2/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= +golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= +golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= +golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= +golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45 h1:SVwTIAaPC2U/AvvLNZ2a7OVsmBpC8L5BlwK1whH3hm0= +golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/oauth2 v0.0.0-20191202225959-858c2ad4c8b6/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/oauth2 v0.0.0-20210323180902-22b0adad7558/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4 h1:YUO/7uOKsKeq9UokNS62b8FYywz3ker1l1vDZRCRefw= +golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200113162924-86b910548bc1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200122134326-e047566fdf82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200331124033-c3d80250170d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200501052902-10377860bb8e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200511232937-7e40ca221e25/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200515095857-1151b9dac4a9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200523222454-059865788121/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200803210538-64077c9b5642/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= +golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20190506145303-2d16b83fe98c/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191113191852-77e3bb0ad9e7/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191115202509-3a792d9c32b2/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191130070609-6e064ea0cf2d/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191216173652-a0e659d51361/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20191227053925-7b8e75db28f4/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200117161641-43d50277825c/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200122220014-bf1340f18c4a/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200204074204-1cc6d1ef6c74/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200207183749-b753a1ba74fa/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200212150539-ea181f53ac56/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200224181240-023911ca70b2/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200227222343-706bc42d1f0d/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200304193943-95d2e580d8eb/go.mod h1:o4KQGtdN14AW+yjsvvwRTJJuXz8XRtIHtEnmAXLyFUw= +golang.org/x/tools v0.0.0-20200312045724-11d5b4c81c7d/go.mod h1:o4KQGtdN14AW+yjsvvwRTJJuXz8XRtIHtEnmAXLyFUw= +golang.org/x/tools v0.0.0-20200331025713-a30bf2db82d4/go.mod h1:Sl4aGygMT6LrqrWclx+PTx3U+LnKx/seiNR+3G19Ar8= +golang.org/x/tools v0.0.0-20200501065659-ab2804fb9c9d/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20200512131952-2bc93b1c0c88/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20200515010526-7d3b6ebf133d/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20200618134242-20370b0cb4b2/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20200729194436-6467de6f59a7/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= +golang.org/x/tools v0.0.0-20200804011535-6c149bb5ef0d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= +golang.org/x/tools v0.0.0-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= +google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M= +google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= +google.golang.org/api v0.9.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= +google.golang.org/api v0.13.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= +google.golang.org/api v0.14.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= +google.golang.org/api v0.15.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= +google.golang.org/api v0.17.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= +google.golang.org/api v0.18.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= +google.golang.org/api v0.19.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= +google.golang.org/api v0.20.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= +google.golang.org/api v0.22.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= +google.golang.org/api v0.24.0/go.mod h1:lIXQywCXRcnZPGlsd8NbLnOjtAoL6em04bJ9+z0MncE= +google.golang.org/api v0.28.0/go.mod h1:lIXQywCXRcnZPGlsd8NbLnOjtAoL6em04bJ9+z0MncE= +google.golang.org/api v0.29.0/go.mod h1:Lcubydp8VUV7KeIHD9z2Bys/sm/vGKnG1UHuDBSrHWM= +google.golang.org/api v0.30.0/go.mod h1:QGmEvQ87FHZNiUVJkT14jQNYJ4ZJjdRF23ZXz5138Fc= +google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= +google.golang.org/appengine v1.4.0 h1:/wp5JvzpHIxhs/dumFmF7BXTf3Z+dd4uXta4kVyO508= +google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0= +google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= +google.golang.org/appengine v1.6.6/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= +google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= +google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190801165951-fa694d86fc64/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= +google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= +google.golang.org/genproto v0.0.0-20190911173649-1774047e7e51/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8= +google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20191115194625-c23dd37a84c9/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20191216164720-4f79533eabd1/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20191230161307-f3c370f40bfb/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20200115191322-ca5a22157cba/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20200122232147-0452cf42e150/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20200204135345-fa8e72b47b90/go.mod h1:GmwEX6Z4W5gMy59cAlVYjN9JhxgbQH6Gn+gFDQe2lzA= +google.golang.org/genproto v0.0.0-20200212174721-66ed5ce911ce/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200224152610-e50cd9704f63/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200228133532-8c2c7df3a383/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200305110556-506484158171/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200312145019-da6875a35672/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200331122359-1ee6d9798940/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200430143042-b979b6f78d84/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200511104702-f5ebc3bea380/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200515170657-fc4c6c6a6587/go.mod h1:YsZOwe1myG/8QRHRsmBRE1LrgQY60beZKjly0O1fX9U= +google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= +google.golang.org/genproto v0.0.0-20200618031413-b414f8b61790/go.mod h1:jDfRM7FcilCzHH/e9qn6dsT145K34l5v+OpcnNgKAAA= +google.golang.org/genproto v0.0.0-20200729003335-053ba62fc06f/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20200804131852-c06518451d9c/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20200825200019-8632dd797987/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= +google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= +google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= +google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= +google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= +google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= +google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= +google.golang.org/grpc v1.27.1/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= +google.golang.org/grpc v1.28.0/go.mod h1:rpkK4SK4GF4Ach/+MFLZUBavHOvF2JJB5uozKKal+60= +google.golang.org/grpc v1.29.1/go.mod h1:itym6AZVZYACWQqET3MqgPpjcuV5QH3BxFS3IjizoKk= +google.golang.org/grpc v1.30.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= +google.golang.org/grpc v1.31.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= +google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= +google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= +google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= +google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= +google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= +google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4= +google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= +honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= +honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= +rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= +rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0= +rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= diff --git a/publicCloud/model__metadata.go b/publicCloud/model__metadata.go new file mode 100644 index 0000000..fd61fc9 --- /dev/null +++ b/publicCloud/model__metadata.go @@ -0,0 +1,209 @@ +/* +LeaseWeb API for launching and managing Public Cloud instances + +> The base URL for this API is: **https://api.leaseweb.com/publicCloud/v1/_** This API provides ways to launch and manage Public Cloud instances.
BETA
This API is in BETA. Documentation might be incorrect or incomplete. Functionality might change with the final release.> + +API version: v1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package publicCloud + +import ( + "encoding/json" +) + +// checks if the Metadata type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &Metadata{} + +// Metadata Metadata about the collection +type Metadata struct { + // Total amount of orders in this collection + TotalCount *float32 `json:"totalCount,omitempty"` + // The offset used to generate this response + Offset *float32 `json:"offset,omitempty"` + // The limit used to generate this response + Limit *float32 `json:"limit,omitempty"` +} + +// NewMetadata instantiates a new Metadata object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewMetadata() *Metadata { + this := Metadata{} + var offset float32 = 0 + this.Offset = &offset + var limit float32 = 5 + this.Limit = &limit + return &this +} + +// NewMetadataWithDefaults instantiates a new Metadata object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewMetadataWithDefaults() *Metadata { + this := Metadata{} + var offset float32 = 0 + this.Offset = &offset + var limit float32 = 5 + this.Limit = &limit + return &this +} + +// GetTotalCount returns the TotalCount field value if set, zero value otherwise. +func (o *Metadata) GetTotalCount() float32 { + if o == nil || IsNil(o.TotalCount) { + var ret float32 + return ret + } + return *o.TotalCount +} + +// GetTotalCountOk returns a tuple with the TotalCount field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Metadata) GetTotalCountOk() (*float32, bool) { + if o == nil || IsNil(o.TotalCount) { + return nil, false + } + return o.TotalCount, true +} + +// HasTotalCount returns a boolean if a field has been set. +func (o *Metadata) HasTotalCount() bool { + if o != nil && !IsNil(o.TotalCount) { + return true + } + + return false +} + +// SetTotalCount gets a reference to the given float32 and assigns it to the TotalCount field. +func (o *Metadata) SetTotalCount(v float32) { + o.TotalCount = &v +} + +// GetOffset returns the Offset field value if set, zero value otherwise. +func (o *Metadata) GetOffset() float32 { + if o == nil || IsNil(o.Offset) { + var ret float32 + return ret + } + return *o.Offset +} + +// GetOffsetOk returns a tuple with the Offset field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Metadata) GetOffsetOk() (*float32, bool) { + if o == nil || IsNil(o.Offset) { + return nil, false + } + return o.Offset, true +} + +// HasOffset returns a boolean if a field has been set. +func (o *Metadata) HasOffset() bool { + if o != nil && !IsNil(o.Offset) { + return true + } + + return false +} + +// SetOffset gets a reference to the given float32 and assigns it to the Offset field. +func (o *Metadata) SetOffset(v float32) { + o.Offset = &v +} + +// GetLimit returns the Limit field value if set, zero value otherwise. +func (o *Metadata) GetLimit() float32 { + if o == nil || IsNil(o.Limit) { + var ret float32 + return ret + } + return *o.Limit +} + +// GetLimitOk returns a tuple with the Limit field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Metadata) GetLimitOk() (*float32, bool) { + if o == nil || IsNil(o.Limit) { + return nil, false + } + return o.Limit, true +} + +// HasLimit returns a boolean if a field has been set. +func (o *Metadata) HasLimit() bool { + if o != nil && !IsNil(o.Limit) { + return true + } + + return false +} + +// SetLimit gets a reference to the given float32 and assigns it to the Limit field. +func (o *Metadata) SetLimit(v float32) { + o.Limit = &v +} + +func (o Metadata) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o Metadata) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.TotalCount) { + toSerialize["totalCount"] = o.TotalCount + } + if !IsNil(o.Offset) { + toSerialize["offset"] = o.Offset + } + if !IsNil(o.Limit) { + toSerialize["limit"] = o.Limit + } + return toSerialize, nil +} + +type NullableMetadata struct { + value *Metadata + isSet bool +} + +func (v NullableMetadata) Get() *Metadata { + return v.value +} + +func (v *NullableMetadata) Set(val *Metadata) { + v.value = val + v.isSet = true +} + +func (v NullableMetadata) IsSet() bool { + return v.isSet +} + +func (v *NullableMetadata) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableMetadata(val *Metadata) *NullableMetadata { + return &NullableMetadata{value: val, isSet: true} +} + +func (v NullableMetadata) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableMetadata) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/publicCloud/model_attach_iso_opts.go b/publicCloud/model_attach_iso_opts.go new file mode 100644 index 0000000..2463345 --- /dev/null +++ b/publicCloud/model_attach_iso_opts.go @@ -0,0 +1,159 @@ +/* +LeaseWeb API for launching and managing Public Cloud instances + +> The base URL for this API is: **https://api.leaseweb.com/publicCloud/v1/_** This API provides ways to launch and manage Public Cloud instances.
BETA
This API is in BETA. Documentation might be incorrect or incomplete. Functionality might change with the final release.> + +API version: v1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package publicCloud + +import ( + "encoding/json" + "bytes" + "fmt" +) + +// checks if the AttachIsoOpts type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &AttachIsoOpts{} + +// AttachIsoOpts struct for AttachIsoOpts +type AttachIsoOpts struct { + // The ISO ID, obtained using the ISO endpoints + IsoId string `json:"isoId"` +} + +type _AttachIsoOpts AttachIsoOpts + +// NewAttachIsoOpts instantiates a new AttachIsoOpts object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewAttachIsoOpts(isoId string) *AttachIsoOpts { + this := AttachIsoOpts{} + this.IsoId = isoId + return &this +} + +// NewAttachIsoOptsWithDefaults instantiates a new AttachIsoOpts object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewAttachIsoOptsWithDefaults() *AttachIsoOpts { + this := AttachIsoOpts{} + return &this +} + +// GetIsoId returns the IsoId field value +func (o *AttachIsoOpts) GetIsoId() string { + if o == nil { + var ret string + return ret + } + + return o.IsoId +} + +// GetIsoIdOk returns a tuple with the IsoId field value +// and a boolean to check if the value has been set. +func (o *AttachIsoOpts) GetIsoIdOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.IsoId, true +} + +// SetIsoId sets field value +func (o *AttachIsoOpts) SetIsoId(v string) { + o.IsoId = v +} + +func (o AttachIsoOpts) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o AttachIsoOpts) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + toSerialize["isoId"] = o.IsoId + return toSerialize, nil +} + +func (o *AttachIsoOpts) UnmarshalJSON(data []byte) (err error) { + // This validates that all required properties are included in the JSON object + // by unmarshalling the object into a generic map with string keys and checking + // that every required field exists as a key in the generic map. + requiredProperties := []string{ + "isoId", + } + + allProperties := make(map[string]interface{}) + + err = json.Unmarshal(data, &allProperties) + + if err != nil { + return err; + } + + for _, requiredProperty := range(requiredProperties) { + if _, exists := allProperties[requiredProperty]; !exists { + return fmt.Errorf("no value given for required property %v", requiredProperty) + } + } + + varAttachIsoOpts := _AttachIsoOpts{} + + decoder := json.NewDecoder(bytes.NewReader(data)) + decoder.DisallowUnknownFields() + err = decoder.Decode(&varAttachIsoOpts) + + if err != nil { + return err + } + + *o = AttachIsoOpts(varAttachIsoOpts) + + return err +} + +type NullableAttachIsoOpts struct { + value *AttachIsoOpts + isSet bool +} + +func (v NullableAttachIsoOpts) Get() *AttachIsoOpts { + return v.value +} + +func (v *NullableAttachIsoOpts) Set(val *AttachIsoOpts) { + v.value = val + v.isSet = true +} + +func (v NullableAttachIsoOpts) IsSet() bool { + return v.isSet +} + +func (v *NullableAttachIsoOpts) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableAttachIsoOpts(val *AttachIsoOpts) *NullableAttachIsoOpts { + return &NullableAttachIsoOpts{value: val, isSet: true} +} + +func (v NullableAttachIsoOpts) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableAttachIsoOpts) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/publicCloud/model_base_firewall_rule.go b/publicCloud/model_base_firewall_rule.go new file mode 100644 index 0000000..449dacb --- /dev/null +++ b/publicCloud/model_base_firewall_rule.go @@ -0,0 +1,208 @@ +/* +LeaseWeb API for launching and managing Public Cloud instances + +> The base URL for this API is: **https://api.leaseweb.com/publicCloud/v1/_** This API provides ways to launch and manage Public Cloud instances.
BETA
This API is in BETA. Documentation might be incorrect or incomplete. Functionality might change with the final release.> + +API version: v1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package publicCloud + +import ( + "encoding/json" +) + +// checks if the BaseFirewallRule type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &BaseFirewallRule{} + +// BaseFirewallRule struct for BaseFirewallRule +type BaseFirewallRule struct { + Id *string `json:"id,omitempty"` + Name NullableString `json:"name,omitempty"` + Cidr *string `json:"cidr,omitempty"` +} + +// NewBaseFirewallRule instantiates a new BaseFirewallRule object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewBaseFirewallRule() *BaseFirewallRule { + this := BaseFirewallRule{} + return &this +} + +// NewBaseFirewallRuleWithDefaults instantiates a new BaseFirewallRule object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewBaseFirewallRuleWithDefaults() *BaseFirewallRule { + this := BaseFirewallRule{} + return &this +} + +// GetId returns the Id field value if set, zero value otherwise. +func (o *BaseFirewallRule) GetId() string { + if o == nil || IsNil(o.Id) { + var ret string + return ret + } + return *o.Id +} + +// GetIdOk returns a tuple with the Id field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *BaseFirewallRule) GetIdOk() (*string, bool) { + if o == nil || IsNil(o.Id) { + return nil, false + } + return o.Id, true +} + +// HasId returns a boolean if a field has been set. +func (o *BaseFirewallRule) HasId() bool { + if o != nil && !IsNil(o.Id) { + return true + } + + return false +} + +// SetId gets a reference to the given string and assigns it to the Id field. +func (o *BaseFirewallRule) SetId(v string) { + o.Id = &v +} + +// GetName returns the Name field value if set, zero value otherwise (both if not set or set to explicit null). +func (o *BaseFirewallRule) GetName() string { + if o == nil || IsNil(o.Name.Get()) { + var ret string + return ret + } + return *o.Name.Get() +} + +// GetNameOk returns a tuple with the Name field value if set, nil otherwise +// and a boolean to check if the value has been set. +// NOTE: If the value is an explicit nil, `nil, true` will be returned +func (o *BaseFirewallRule) GetNameOk() (*string, bool) { + if o == nil { + return nil, false + } + return o.Name.Get(), o.Name.IsSet() +} + +// HasName returns a boolean if a field has been set. +func (o *BaseFirewallRule) HasName() bool { + if o != nil && o.Name.IsSet() { + return true + } + + return false +} + +// SetName gets a reference to the given NullableString and assigns it to the Name field. +func (o *BaseFirewallRule) SetName(v string) { + o.Name.Set(&v) +} +// SetNameNil sets the value for Name to be an explicit nil +func (o *BaseFirewallRule) SetNameNil() { + o.Name.Set(nil) +} + +// UnsetName ensures that no value is present for Name, not even an explicit nil +func (o *BaseFirewallRule) UnsetName() { + o.Name.Unset() +} + +// GetCidr returns the Cidr field value if set, zero value otherwise. +func (o *BaseFirewallRule) GetCidr() string { + if o == nil || IsNil(o.Cidr) { + var ret string + return ret + } + return *o.Cidr +} + +// GetCidrOk returns a tuple with the Cidr field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *BaseFirewallRule) GetCidrOk() (*string, bool) { + if o == nil || IsNil(o.Cidr) { + return nil, false + } + return o.Cidr, true +} + +// HasCidr returns a boolean if a field has been set. +func (o *BaseFirewallRule) HasCidr() bool { + if o != nil && !IsNil(o.Cidr) { + return true + } + + return false +} + +// SetCidr gets a reference to the given string and assigns it to the Cidr field. +func (o *BaseFirewallRule) SetCidr(v string) { + o.Cidr = &v +} + +func (o BaseFirewallRule) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o BaseFirewallRule) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Id) { + toSerialize["id"] = o.Id + } + if o.Name.IsSet() { + toSerialize["name"] = o.Name.Get() + } + if !IsNil(o.Cidr) { + toSerialize["cidr"] = o.Cidr + } + return toSerialize, nil +} + +type NullableBaseFirewallRule struct { + value *BaseFirewallRule + isSet bool +} + +func (v NullableBaseFirewallRule) Get() *BaseFirewallRule { + return v.value +} + +func (v *NullableBaseFirewallRule) Set(val *BaseFirewallRule) { + v.value = val + v.isSet = true +} + +func (v NullableBaseFirewallRule) IsSet() bool { + return v.isSet +} + +func (v *NullableBaseFirewallRule) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableBaseFirewallRule(val *BaseFirewallRule) *NullableBaseFirewallRule { + return &NullableBaseFirewallRule{value: val, isSet: true} +} + +func (v NullableBaseFirewallRule) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableBaseFirewallRule) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/publicCloud/model_billing.go b/publicCloud/model_billing.go new file mode 100644 index 0000000..e6e2f8a --- /dev/null +++ b/publicCloud/model_billing.go @@ -0,0 +1,163 @@ +/* +LeaseWeb API for launching and managing Public Cloud instances + +> The base URL for this API is: **https://api.leaseweb.com/publicCloud/v1/_** This API provides ways to launch and manage Public Cloud instances.
BETA
This API is in BETA. Documentation might be incorrect or incomplete. Functionality might change with the final release.> + +API version: v1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package publicCloud + +import ( + "encoding/json" +) + +// checks if the Billing type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &Billing{} + +// Billing struct for Billing +type Billing struct { + // List of instances to be billed in the period + Instances []ExpenseResultInstance `json:"instances,omitempty"` + Traffic *Traffic `json:"traffic,omitempty"` +} + +// NewBilling instantiates a new Billing object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewBilling() *Billing { + this := Billing{} + return &this +} + +// NewBillingWithDefaults instantiates a new Billing object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewBillingWithDefaults() *Billing { + this := Billing{} + return &this +} + +// GetInstances returns the Instances field value if set, zero value otherwise. +func (o *Billing) GetInstances() []ExpenseResultInstance { + if o == nil || IsNil(o.Instances) { + var ret []ExpenseResultInstance + return ret + } + return o.Instances +} + +// GetInstancesOk returns a tuple with the Instances field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Billing) GetInstancesOk() ([]ExpenseResultInstance, bool) { + if o == nil || IsNil(o.Instances) { + return nil, false + } + return o.Instances, true +} + +// HasInstances returns a boolean if a field has been set. +func (o *Billing) HasInstances() bool { + if o != nil && !IsNil(o.Instances) { + return true + } + + return false +} + +// SetInstances gets a reference to the given []ExpenseResultInstance and assigns it to the Instances field. +func (o *Billing) SetInstances(v []ExpenseResultInstance) { + o.Instances = v +} + +// GetTraffic returns the Traffic field value if set, zero value otherwise. +func (o *Billing) GetTraffic() Traffic { + if o == nil || IsNil(o.Traffic) { + var ret Traffic + return ret + } + return *o.Traffic +} + +// GetTrafficOk returns a tuple with the Traffic field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Billing) GetTrafficOk() (*Traffic, bool) { + if o == nil || IsNil(o.Traffic) { + return nil, false + } + return o.Traffic, true +} + +// HasTraffic returns a boolean if a field has been set. +func (o *Billing) HasTraffic() bool { + if o != nil && !IsNil(o.Traffic) { + return true + } + + return false +} + +// SetTraffic gets a reference to the given Traffic and assigns it to the Traffic field. +func (o *Billing) SetTraffic(v Traffic) { + o.Traffic = &v +} + +func (o Billing) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o Billing) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Instances) { + toSerialize["instances"] = o.Instances + } + if !IsNil(o.Traffic) { + toSerialize["traffic"] = o.Traffic + } + return toSerialize, nil +} + +type NullableBilling struct { + value *Billing + isSet bool +} + +func (v NullableBilling) Get() *Billing { + return v.value +} + +func (v *NullableBilling) Set(val *Billing) { + v.value = val + v.isSet = true +} + +func (v NullableBilling) IsSet() bool { + return v.isSet +} + +func (v *NullableBilling) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableBilling(val *Billing) *NullableBilling { + return &NullableBilling{value: val, isSet: true} +} + +func (v NullableBilling) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableBilling) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/publicCloud/model_central.go b/publicCloud/model_central.go new file mode 100644 index 0000000..47b1bc8 --- /dev/null +++ b/publicCloud/model_central.go @@ -0,0 +1,162 @@ +/* +LeaseWeb API for launching and managing Public Cloud instances + +> The base URL for this API is: **https://api.leaseweb.com/publicCloud/v1/_** This API provides ways to launch and manage Public Cloud instances.
BETA
This API is in BETA. Documentation might be incorrect or incomplete. Functionality might change with the final release.> + +API version: v1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package publicCloud + +import ( + "encoding/json" +) + +// checks if the Central type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &Central{} + +// Central struct for Central +type Central struct { + HourlyPrice *string `json:"hourlyPrice,omitempty"` + MonthlyPrice *string `json:"monthlyPrice,omitempty"` +} + +// NewCentral instantiates a new Central object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewCentral() *Central { + this := Central{} + return &this +} + +// NewCentralWithDefaults instantiates a new Central object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewCentralWithDefaults() *Central { + this := Central{} + return &this +} + +// GetHourlyPrice returns the HourlyPrice field value if set, zero value otherwise. +func (o *Central) GetHourlyPrice() string { + if o == nil || IsNil(o.HourlyPrice) { + var ret string + return ret + } + return *o.HourlyPrice +} + +// GetHourlyPriceOk returns a tuple with the HourlyPrice field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Central) GetHourlyPriceOk() (*string, bool) { + if o == nil || IsNil(o.HourlyPrice) { + return nil, false + } + return o.HourlyPrice, true +} + +// HasHourlyPrice returns a boolean if a field has been set. +func (o *Central) HasHourlyPrice() bool { + if o != nil && !IsNil(o.HourlyPrice) { + return true + } + + return false +} + +// SetHourlyPrice gets a reference to the given string and assigns it to the HourlyPrice field. +func (o *Central) SetHourlyPrice(v string) { + o.HourlyPrice = &v +} + +// GetMonthlyPrice returns the MonthlyPrice field value if set, zero value otherwise. +func (o *Central) GetMonthlyPrice() string { + if o == nil || IsNil(o.MonthlyPrice) { + var ret string + return ret + } + return *o.MonthlyPrice +} + +// GetMonthlyPriceOk returns a tuple with the MonthlyPrice field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Central) GetMonthlyPriceOk() (*string, bool) { + if o == nil || IsNil(o.MonthlyPrice) { + return nil, false + } + return o.MonthlyPrice, true +} + +// HasMonthlyPrice returns a boolean if a field has been set. +func (o *Central) HasMonthlyPrice() bool { + if o != nil && !IsNil(o.MonthlyPrice) { + return true + } + + return false +} + +// SetMonthlyPrice gets a reference to the given string and assigns it to the MonthlyPrice field. +func (o *Central) SetMonthlyPrice(v string) { + o.MonthlyPrice = &v +} + +func (o Central) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o Central) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.HourlyPrice) { + toSerialize["hourlyPrice"] = o.HourlyPrice + } + if !IsNil(o.MonthlyPrice) { + toSerialize["monthlyPrice"] = o.MonthlyPrice + } + return toSerialize, nil +} + +type NullableCentral struct { + value *Central + isSet bool +} + +func (v NullableCentral) Get() *Central { + return v.value +} + +func (v *NullableCentral) Set(val *Central) { + v.value = val + v.isSet = true +} + +func (v NullableCentral) IsSet() bool { + return v.isSet +} + +func (v *NullableCentral) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableCentral(val *Central) *NullableCentral { + return &NullableCentral{value: val, isSet: true} +} + +func (v NullableCentral) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableCentral) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/publicCloud/model_compute.go b/publicCloud/model_compute.go new file mode 100644 index 0000000..9cb2c84 --- /dev/null +++ b/publicCloud/model_compute.go @@ -0,0 +1,162 @@ +/* +LeaseWeb API for launching and managing Public Cloud instances + +> The base URL for this API is: **https://api.leaseweb.com/publicCloud/v1/_** This API provides ways to launch and manage Public Cloud instances.
BETA
This API is in BETA. Documentation might be incorrect or incomplete. Functionality might change with the final release.> + +API version: v1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package publicCloud + +import ( + "encoding/json" +) + +// checks if the Compute type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &Compute{} + +// Compute struct for Compute +type Compute struct { + HourlyPrice *string `json:"hourlyPrice,omitempty"` + MonthlyPrice *string `json:"monthlyPrice,omitempty"` +} + +// NewCompute instantiates a new Compute object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewCompute() *Compute { + this := Compute{} + return &this +} + +// NewComputeWithDefaults instantiates a new Compute object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewComputeWithDefaults() *Compute { + this := Compute{} + return &this +} + +// GetHourlyPrice returns the HourlyPrice field value if set, zero value otherwise. +func (o *Compute) GetHourlyPrice() string { + if o == nil || IsNil(o.HourlyPrice) { + var ret string + return ret + } + return *o.HourlyPrice +} + +// GetHourlyPriceOk returns a tuple with the HourlyPrice field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Compute) GetHourlyPriceOk() (*string, bool) { + if o == nil || IsNil(o.HourlyPrice) { + return nil, false + } + return o.HourlyPrice, true +} + +// HasHourlyPrice returns a boolean if a field has been set. +func (o *Compute) HasHourlyPrice() bool { + if o != nil && !IsNil(o.HourlyPrice) { + return true + } + + return false +} + +// SetHourlyPrice gets a reference to the given string and assigns it to the HourlyPrice field. +func (o *Compute) SetHourlyPrice(v string) { + o.HourlyPrice = &v +} + +// GetMonthlyPrice returns the MonthlyPrice field value if set, zero value otherwise. +func (o *Compute) GetMonthlyPrice() string { + if o == nil || IsNil(o.MonthlyPrice) { + var ret string + return ret + } + return *o.MonthlyPrice +} + +// GetMonthlyPriceOk returns a tuple with the MonthlyPrice field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Compute) GetMonthlyPriceOk() (*string, bool) { + if o == nil || IsNil(o.MonthlyPrice) { + return nil, false + } + return o.MonthlyPrice, true +} + +// HasMonthlyPrice returns a boolean if a field has been set. +func (o *Compute) HasMonthlyPrice() bool { + if o != nil && !IsNil(o.MonthlyPrice) { + return true + } + + return false +} + +// SetMonthlyPrice gets a reference to the given string and assigns it to the MonthlyPrice field. +func (o *Compute) SetMonthlyPrice(v string) { + o.MonthlyPrice = &v +} + +func (o Compute) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o Compute) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.HourlyPrice) { + toSerialize["hourlyPrice"] = o.HourlyPrice + } + if !IsNil(o.MonthlyPrice) { + toSerialize["monthlyPrice"] = o.MonthlyPrice + } + return toSerialize, nil +} + +type NullableCompute struct { + value *Compute + isSet bool +} + +func (v NullableCompute) Get() *Compute { + return v.value +} + +func (v *NullableCompute) Set(val *Compute) { + v.value = val + v.isSet = true +} + +func (v NullableCompute) IsSet() bool { + return v.isSet +} + +func (v *NullableCompute) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableCompute(val *Compute) *NullableCompute { + return &NullableCompute{value: val, isSet: true} +} + +func (v NullableCompute) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableCompute) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/publicCloud/model_contract_type.go b/publicCloud/model_contract_type.go new file mode 100644 index 0000000..655c4c9 --- /dev/null +++ b/publicCloud/model_contract_type.go @@ -0,0 +1,111 @@ +/* +LeaseWeb API for launching and managing Public Cloud instances + +> The base URL for this API is: **https://api.leaseweb.com/publicCloud/v1/_** This API provides ways to launch and manage Public Cloud instances.
BETA
This API is in BETA. Documentation might be incorrect or incomplete. Functionality might change with the final release.> + +API version: v1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package publicCloud + +import ( + "encoding/json" + "fmt" +) + +// ContractType Select HOURLY for billing based on hourly usage, else MONTHLY for billing per month usage +type ContractType string + +// List of contractType +const ( + HOURLY ContractType = "HOURLY" + MONTHLY ContractType = "MONTHLY" +) + +// All allowed values of ContractType enum +var AllowedContractTypeEnumValues = []ContractType{ + "HOURLY", + "MONTHLY", +} + +func (v *ContractType) UnmarshalJSON(src []byte) error { + var value string + err := json.Unmarshal(src, &value) + if err != nil { + return err + } + enumTypeValue := ContractType(value) + for _, existing := range AllowedContractTypeEnumValues { + if existing == enumTypeValue { + *v = enumTypeValue + return nil + } + } + + return fmt.Errorf("%+v is not a valid ContractType", value) +} + +// NewContractTypeFromValue returns a pointer to a valid ContractType +// for the value passed as argument, or an error if the value passed is not allowed by the enum +func NewContractTypeFromValue(v string) (*ContractType, error) { + ev := ContractType(v) + if ev.IsValid() { + return &ev, nil + } else { + return nil, fmt.Errorf("invalid value '%v' for ContractType: valid values are %v", v, AllowedContractTypeEnumValues) + } +} + +// IsValid return true if the value is valid for the enum, false otherwise +func (v ContractType) IsValid() bool { + for _, existing := range AllowedContractTypeEnumValues { + if existing == v { + return true + } + } + return false +} + +// Ptr returns reference to contractType value +func (v ContractType) Ptr() *ContractType { + return &v +} + +type NullableContractType struct { + value *ContractType + isSet bool +} + +func (v NullableContractType) Get() *ContractType { + return v.value +} + +func (v *NullableContractType) Set(val *ContractType) { + v.value = val + v.isSet = true +} + +func (v NullableContractType) IsSet() bool { + return v.isSet +} + +func (v *NullableContractType) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableContractType(val *ContractType) *NullableContractType { + return &NullableContractType{value: val, isSet: true} +} + +func (v NullableContractType) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableContractType) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + diff --git a/publicCloud/model_cpu.go b/publicCloud/model_cpu.go new file mode 100644 index 0000000..1d17f06 --- /dev/null +++ b/publicCloud/model_cpu.go @@ -0,0 +1,162 @@ +/* +LeaseWeb API for launching and managing Public Cloud instances + +> The base URL for this API is: **https://api.leaseweb.com/publicCloud/v1/_** This API provides ways to launch and manage Public Cloud instances.
BETA
This API is in BETA. Documentation might be incorrect or incomplete. Functionality might change with the final release.> + +API version: v1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package publicCloud + +import ( + "encoding/json" +) + +// checks if the Cpu type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &Cpu{} + +// Cpu Number of cores +type Cpu struct { + Value *int32 `json:"value,omitempty"` + Unit *string `json:"unit,omitempty"` +} + +// NewCpu instantiates a new Cpu object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewCpu() *Cpu { + this := Cpu{} + return &this +} + +// NewCpuWithDefaults instantiates a new Cpu object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewCpuWithDefaults() *Cpu { + this := Cpu{} + return &this +} + +// GetValue returns the Value field value if set, zero value otherwise. +func (o *Cpu) GetValue() int32 { + if o == nil || IsNil(o.Value) { + var ret int32 + return ret + } + return *o.Value +} + +// GetValueOk returns a tuple with the Value field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Cpu) GetValueOk() (*int32, bool) { + if o == nil || IsNil(o.Value) { + return nil, false + } + return o.Value, true +} + +// HasValue returns a boolean if a field has been set. +func (o *Cpu) HasValue() bool { + if o != nil && !IsNil(o.Value) { + return true + } + + return false +} + +// SetValue gets a reference to the given int32 and assigns it to the Value field. +func (o *Cpu) SetValue(v int32) { + o.Value = &v +} + +// GetUnit returns the Unit field value if set, zero value otherwise. +func (o *Cpu) GetUnit() string { + if o == nil || IsNil(o.Unit) { + var ret string + return ret + } + return *o.Unit +} + +// GetUnitOk returns a tuple with the Unit field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Cpu) GetUnitOk() (*string, bool) { + if o == nil || IsNil(o.Unit) { + return nil, false + } + return o.Unit, true +} + +// HasUnit returns a boolean if a field has been set. +func (o *Cpu) HasUnit() bool { + if o != nil && !IsNil(o.Unit) { + return true + } + + return false +} + +// SetUnit gets a reference to the given string and assigns it to the Unit field. +func (o *Cpu) SetUnit(v string) { + o.Unit = &v +} + +func (o Cpu) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o Cpu) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Value) { + toSerialize["value"] = o.Value + } + if !IsNil(o.Unit) { + toSerialize["unit"] = o.Unit + } + return toSerialize, nil +} + +type NullableCpu struct { + value *Cpu + isSet bool +} + +func (v NullableCpu) Get() *Cpu { + return v.value +} + +func (v *NullableCpu) Set(val *Cpu) { + v.value = val + v.isSet = true +} + +func (v NullableCpu) IsSet() bool { + return v.isSet +} + +func (v *NullableCpu) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableCpu(val *Cpu) *NullableCpu { + return &NullableCpu{value: val, isSet: true} +} + +func (v NullableCpu) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableCpu) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/publicCloud/model_create_firewall_rules_created_result.go b/publicCloud/model_create_firewall_rules_created_result.go new file mode 100644 index 0000000..4bc9b3b --- /dev/null +++ b/publicCloud/model_create_firewall_rules_created_result.go @@ -0,0 +1,164 @@ +/* +LeaseWeb API for launching and managing Public Cloud instances + +> The base URL for this API is: **https://api.leaseweb.com/publicCloud/v1/_** This API provides ways to launch and manage Public Cloud instances.
BETA
This API is in BETA. Documentation might be incorrect or incomplete. Functionality might change with the final release.> + +API version: v1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package publicCloud + +import ( + "encoding/json" +) + +// checks if the CreateFirewallRulesCreatedResult type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &CreateFirewallRulesCreatedResult{} + +// CreateFirewallRulesCreatedResult struct for CreateFirewallRulesCreatedResult +type CreateFirewallRulesCreatedResult struct { + // List of rules that have been successfully added + Created []FirewallRule `json:"created,omitempty"` + // List of rules that have failed to be added + Failed []FirewallRule `json:"failed,omitempty"` +} + +// NewCreateFirewallRulesCreatedResult instantiates a new CreateFirewallRulesCreatedResult object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewCreateFirewallRulesCreatedResult() *CreateFirewallRulesCreatedResult { + this := CreateFirewallRulesCreatedResult{} + return &this +} + +// NewCreateFirewallRulesCreatedResultWithDefaults instantiates a new CreateFirewallRulesCreatedResult object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewCreateFirewallRulesCreatedResultWithDefaults() *CreateFirewallRulesCreatedResult { + this := CreateFirewallRulesCreatedResult{} + return &this +} + +// GetCreated returns the Created field value if set, zero value otherwise. +func (o *CreateFirewallRulesCreatedResult) GetCreated() []FirewallRule { + if o == nil || IsNil(o.Created) { + var ret []FirewallRule + return ret + } + return o.Created +} + +// GetCreatedOk returns a tuple with the Created field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *CreateFirewallRulesCreatedResult) GetCreatedOk() ([]FirewallRule, bool) { + if o == nil || IsNil(o.Created) { + return nil, false + } + return o.Created, true +} + +// HasCreated returns a boolean if a field has been set. +func (o *CreateFirewallRulesCreatedResult) HasCreated() bool { + if o != nil && !IsNil(o.Created) { + return true + } + + return false +} + +// SetCreated gets a reference to the given []FirewallRule and assigns it to the Created field. +func (o *CreateFirewallRulesCreatedResult) SetCreated(v []FirewallRule) { + o.Created = v +} + +// GetFailed returns the Failed field value if set, zero value otherwise. +func (o *CreateFirewallRulesCreatedResult) GetFailed() []FirewallRule { + if o == nil || IsNil(o.Failed) { + var ret []FirewallRule + return ret + } + return o.Failed +} + +// GetFailedOk returns a tuple with the Failed field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *CreateFirewallRulesCreatedResult) GetFailedOk() ([]FirewallRule, bool) { + if o == nil || IsNil(o.Failed) { + return nil, false + } + return o.Failed, true +} + +// HasFailed returns a boolean if a field has been set. +func (o *CreateFirewallRulesCreatedResult) HasFailed() bool { + if o != nil && !IsNil(o.Failed) { + return true + } + + return false +} + +// SetFailed gets a reference to the given []FirewallRule and assigns it to the Failed field. +func (o *CreateFirewallRulesCreatedResult) SetFailed(v []FirewallRule) { + o.Failed = v +} + +func (o CreateFirewallRulesCreatedResult) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o CreateFirewallRulesCreatedResult) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Created) { + toSerialize["created"] = o.Created + } + if !IsNil(o.Failed) { + toSerialize["failed"] = o.Failed + } + return toSerialize, nil +} + +type NullableCreateFirewallRulesCreatedResult struct { + value *CreateFirewallRulesCreatedResult + isSet bool +} + +func (v NullableCreateFirewallRulesCreatedResult) Get() *CreateFirewallRulesCreatedResult { + return v.value +} + +func (v *NullableCreateFirewallRulesCreatedResult) Set(val *CreateFirewallRulesCreatedResult) { + v.value = val + v.isSet = true +} + +func (v NullableCreateFirewallRulesCreatedResult) IsSet() bool { + return v.isSet +} + +func (v *NullableCreateFirewallRulesCreatedResult) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableCreateFirewallRulesCreatedResult(val *CreateFirewallRulesCreatedResult) *NullableCreateFirewallRulesCreatedResult { + return &NullableCreateFirewallRulesCreatedResult{value: val, isSet: true} +} + +func (v NullableCreateFirewallRulesCreatedResult) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableCreateFirewallRulesCreatedResult) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/publicCloud/model_create_firewall_rules_opts.go b/publicCloud/model_create_firewall_rules_opts.go new file mode 100644 index 0000000..f4bb866 --- /dev/null +++ b/publicCloud/model_create_firewall_rules_opts.go @@ -0,0 +1,158 @@ +/* +LeaseWeb API for launching and managing Public Cloud instances + +> The base URL for this API is: **https://api.leaseweb.com/publicCloud/v1/_** This API provides ways to launch and manage Public Cloud instances.
BETA
This API is in BETA. Documentation might be incorrect or incomplete. Functionality might change with the final release.> + +API version: v1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package publicCloud + +import ( + "encoding/json" + "bytes" + "fmt" +) + +// checks if the CreateFirewallRulesOpts type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &CreateFirewallRulesOpts{} + +// CreateFirewallRulesOpts struct for CreateFirewallRulesOpts +type CreateFirewallRulesOpts struct { + Rules []CreateRule `json:"rules"` +} + +type _CreateFirewallRulesOpts CreateFirewallRulesOpts + +// NewCreateFirewallRulesOpts instantiates a new CreateFirewallRulesOpts object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewCreateFirewallRulesOpts(rules []CreateRule) *CreateFirewallRulesOpts { + this := CreateFirewallRulesOpts{} + this.Rules = rules + return &this +} + +// NewCreateFirewallRulesOptsWithDefaults instantiates a new CreateFirewallRulesOpts object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewCreateFirewallRulesOptsWithDefaults() *CreateFirewallRulesOpts { + this := CreateFirewallRulesOpts{} + return &this +} + +// GetRules returns the Rules field value +func (o *CreateFirewallRulesOpts) GetRules() []CreateRule { + if o == nil { + var ret []CreateRule + return ret + } + + return o.Rules +} + +// GetRulesOk returns a tuple with the Rules field value +// and a boolean to check if the value has been set. +func (o *CreateFirewallRulesOpts) GetRulesOk() ([]CreateRule, bool) { + if o == nil { + return nil, false + } + return o.Rules, true +} + +// SetRules sets field value +func (o *CreateFirewallRulesOpts) SetRules(v []CreateRule) { + o.Rules = v +} + +func (o CreateFirewallRulesOpts) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o CreateFirewallRulesOpts) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + toSerialize["rules"] = o.Rules + return toSerialize, nil +} + +func (o *CreateFirewallRulesOpts) UnmarshalJSON(data []byte) (err error) { + // This validates that all required properties are included in the JSON object + // by unmarshalling the object into a generic map with string keys and checking + // that every required field exists as a key in the generic map. + requiredProperties := []string{ + "rules", + } + + allProperties := make(map[string]interface{}) + + err = json.Unmarshal(data, &allProperties) + + if err != nil { + return err; + } + + for _, requiredProperty := range(requiredProperties) { + if _, exists := allProperties[requiredProperty]; !exists { + return fmt.Errorf("no value given for required property %v", requiredProperty) + } + } + + varCreateFirewallRulesOpts := _CreateFirewallRulesOpts{} + + decoder := json.NewDecoder(bytes.NewReader(data)) + decoder.DisallowUnknownFields() + err = decoder.Decode(&varCreateFirewallRulesOpts) + + if err != nil { + return err + } + + *o = CreateFirewallRulesOpts(varCreateFirewallRulesOpts) + + return err +} + +type NullableCreateFirewallRulesOpts struct { + value *CreateFirewallRulesOpts + isSet bool +} + +func (v NullableCreateFirewallRulesOpts) Get() *CreateFirewallRulesOpts { + return v.value +} + +func (v *NullableCreateFirewallRulesOpts) Set(val *CreateFirewallRulesOpts) { + v.value = val + v.isSet = true +} + +func (v NullableCreateFirewallRulesOpts) IsSet() bool { + return v.isSet +} + +func (v *NullableCreateFirewallRulesOpts) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableCreateFirewallRulesOpts(val *CreateFirewallRulesOpts) *NullableCreateFirewallRulesOpts { + return &NullableCreateFirewallRulesOpts{value: val, isSet: true} +} + +func (v NullableCreateFirewallRulesOpts) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableCreateFirewallRulesOpts) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/publicCloud/model_create_rule.go b/publicCloud/model_create_rule.go new file mode 100644 index 0000000..f0e2387 --- /dev/null +++ b/publicCloud/model_create_rule.go @@ -0,0 +1,368 @@ +/* +LeaseWeb API for launching and managing Public Cloud instances + +> The base URL for this API is: **https://api.leaseweb.com/publicCloud/v1/_** This API provides ways to launch and manage Public Cloud instances.
BETA
This API is in BETA. Documentation might be incorrect or incomplete. Functionality might change with the final release.> + +API version: v1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package publicCloud + +import ( + "encoding/json" + "bytes" + "fmt" +) + +// checks if the CreateRule type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &CreateRule{} + +// CreateRule struct for CreateRule +type CreateRule struct { + Protocol string `json:"protocol"` + StartPort NullableInt32 `json:"startPort"` + EndPort NullableInt32 `json:"endPort"` + IcmpType int32 `json:"icmpType"` + IcmpCode int32 `json:"icmpCode"` + Id *string `json:"id,omitempty"` + Name NullableString `json:"name"` + Cidr string `json:"cidr"` +} + +type _CreateRule CreateRule + +// NewCreateRule instantiates a new CreateRule object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewCreateRule(protocol string, startPort NullableInt32, endPort NullableInt32, icmpType int32, icmpCode int32, name NullableString, cidr string) *CreateRule { + this := CreateRule{} + this.Protocol = protocol + this.StartPort = startPort + this.EndPort = endPort + this.IcmpType = icmpType + this.IcmpCode = icmpCode + this.Name = name + this.Cidr = cidr + return &this +} + +// NewCreateRuleWithDefaults instantiates a new CreateRule object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewCreateRuleWithDefaults() *CreateRule { + this := CreateRule{} + return &this +} + +// GetProtocol returns the Protocol field value +func (o *CreateRule) GetProtocol() string { + if o == nil { + var ret string + return ret + } + + return o.Protocol +} + +// GetProtocolOk returns a tuple with the Protocol field value +// and a boolean to check if the value has been set. +func (o *CreateRule) GetProtocolOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.Protocol, true +} + +// SetProtocol sets field value +func (o *CreateRule) SetProtocol(v string) { + o.Protocol = v +} + +// GetStartPort returns the StartPort field value +// If the value is explicit nil, the zero value for int32 will be returned +func (o *CreateRule) GetStartPort() int32 { + if o == nil || o.StartPort.Get() == nil { + var ret int32 + return ret + } + + return *o.StartPort.Get() +} + +// GetStartPortOk returns a tuple with the StartPort field value +// and a boolean to check if the value has been set. +// NOTE: If the value is an explicit nil, `nil, true` will be returned +func (o *CreateRule) GetStartPortOk() (*int32, bool) { + if o == nil { + return nil, false + } + return o.StartPort.Get(), o.StartPort.IsSet() +} + +// SetStartPort sets field value +func (o *CreateRule) SetStartPort(v int32) { + o.StartPort.Set(&v) +} + +// GetEndPort returns the EndPort field value +// If the value is explicit nil, the zero value for int32 will be returned +func (o *CreateRule) GetEndPort() int32 { + if o == nil || o.EndPort.Get() == nil { + var ret int32 + return ret + } + + return *o.EndPort.Get() +} + +// GetEndPortOk returns a tuple with the EndPort field value +// and a boolean to check if the value has been set. +// NOTE: If the value is an explicit nil, `nil, true` will be returned +func (o *CreateRule) GetEndPortOk() (*int32, bool) { + if o == nil { + return nil, false + } + return o.EndPort.Get(), o.EndPort.IsSet() +} + +// SetEndPort sets field value +func (o *CreateRule) SetEndPort(v int32) { + o.EndPort.Set(&v) +} + +// GetIcmpType returns the IcmpType field value +func (o *CreateRule) GetIcmpType() int32 { + if o == nil { + var ret int32 + return ret + } + + return o.IcmpType +} + +// GetIcmpTypeOk returns a tuple with the IcmpType field value +// and a boolean to check if the value has been set. +func (o *CreateRule) GetIcmpTypeOk() (*int32, bool) { + if o == nil { + return nil, false + } + return &o.IcmpType, true +} + +// SetIcmpType sets field value +func (o *CreateRule) SetIcmpType(v int32) { + o.IcmpType = v +} + +// GetIcmpCode returns the IcmpCode field value +func (o *CreateRule) GetIcmpCode() int32 { + if o == nil { + var ret int32 + return ret + } + + return o.IcmpCode +} + +// GetIcmpCodeOk returns a tuple with the IcmpCode field value +// and a boolean to check if the value has been set. +func (o *CreateRule) GetIcmpCodeOk() (*int32, bool) { + if o == nil { + return nil, false + } + return &o.IcmpCode, true +} + +// SetIcmpCode sets field value +func (o *CreateRule) SetIcmpCode(v int32) { + o.IcmpCode = v +} + +// GetId returns the Id field value if set, zero value otherwise. +func (o *CreateRule) GetId() string { + if o == nil || IsNil(o.Id) { + var ret string + return ret + } + return *o.Id +} + +// GetIdOk returns a tuple with the Id field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *CreateRule) GetIdOk() (*string, bool) { + if o == nil || IsNil(o.Id) { + return nil, false + } + return o.Id, true +} + +// HasId returns a boolean if a field has been set. +func (o *CreateRule) HasId() bool { + if o != nil && !IsNil(o.Id) { + return true + } + + return false +} + +// SetId gets a reference to the given string and assigns it to the Id field. +func (o *CreateRule) SetId(v string) { + o.Id = &v +} + +// GetName returns the Name field value +// If the value is explicit nil, the zero value for string will be returned +func (o *CreateRule) GetName() string { + if o == nil || o.Name.Get() == nil { + var ret string + return ret + } + + return *o.Name.Get() +} + +// GetNameOk returns a tuple with the Name field value +// and a boolean to check if the value has been set. +// NOTE: If the value is an explicit nil, `nil, true` will be returned +func (o *CreateRule) GetNameOk() (*string, bool) { + if o == nil { + return nil, false + } + return o.Name.Get(), o.Name.IsSet() +} + +// SetName sets field value +func (o *CreateRule) SetName(v string) { + o.Name.Set(&v) +} + +// GetCidr returns the Cidr field value +func (o *CreateRule) GetCidr() string { + if o == nil { + var ret string + return ret + } + + return o.Cidr +} + +// GetCidrOk returns a tuple with the Cidr field value +// and a boolean to check if the value has been set. +func (o *CreateRule) GetCidrOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.Cidr, true +} + +// SetCidr sets field value +func (o *CreateRule) SetCidr(v string) { + o.Cidr = v +} + +func (o CreateRule) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o CreateRule) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + toSerialize["protocol"] = o.Protocol + toSerialize["startPort"] = o.StartPort.Get() + toSerialize["endPort"] = o.EndPort.Get() + toSerialize["icmpType"] = o.IcmpType + toSerialize["icmpCode"] = o.IcmpCode + if !IsNil(o.Id) { + toSerialize["id"] = o.Id + } + toSerialize["name"] = o.Name.Get() + toSerialize["cidr"] = o.Cidr + return toSerialize, nil +} + +func (o *CreateRule) UnmarshalJSON(data []byte) (err error) { + // This validates that all required properties are included in the JSON object + // by unmarshalling the object into a generic map with string keys and checking + // that every required field exists as a key in the generic map. + requiredProperties := []string{ + "protocol", + "startPort", + "endPort", + "icmpType", + "icmpCode", + "name", + "cidr", + } + + allProperties := make(map[string]interface{}) + + err = json.Unmarshal(data, &allProperties) + + if err != nil { + return err; + } + + for _, requiredProperty := range(requiredProperties) { + if _, exists := allProperties[requiredProperty]; !exists { + return fmt.Errorf("no value given for required property %v", requiredProperty) + } + } + + varCreateRule := _CreateRule{} + + decoder := json.NewDecoder(bytes.NewReader(data)) + decoder.DisallowUnknownFields() + err = decoder.Decode(&varCreateRule) + + if err != nil { + return err + } + + *o = CreateRule(varCreateRule) + + return err +} + +type NullableCreateRule struct { + value *CreateRule + isSet bool +} + +func (v NullableCreateRule) Get() *CreateRule { + return v.value +} + +func (v *NullableCreateRule) Set(val *CreateRule) { + v.value = val + v.isSet = true +} + +func (v NullableCreateRule) IsSet() bool { + return v.isSet +} + +func (v *NullableCreateRule) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableCreateRule(val *CreateRule) *NullableCreateRule { + return &NullableCreateRule{value: val, isSet: true} +} + +func (v NullableCreateRule) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableCreateRule) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/publicCloud/model_credential.go b/publicCloud/model_credential.go new file mode 100644 index 0000000..960719d --- /dev/null +++ b/publicCloud/model_credential.go @@ -0,0 +1,162 @@ +/* +LeaseWeb API for launching and managing Public Cloud instances + +> The base URL for this API is: **https://api.leaseweb.com/publicCloud/v1/_** This API provides ways to launch and manage Public Cloud instances.
BETA
This API is in BETA. Documentation might be incorrect or incomplete. Functionality might change with the final release.> + +API version: v1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package publicCloud + +import ( + "encoding/json" +) + +// checks if the Credential type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &Credential{} + +// Credential struct for Credential +type Credential struct { + Type *CredentialType `json:"type,omitempty"` + Username *string `json:"username,omitempty"` +} + +// NewCredential instantiates a new Credential object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewCredential() *Credential { + this := Credential{} + return &this +} + +// NewCredentialWithDefaults instantiates a new Credential object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewCredentialWithDefaults() *Credential { + this := Credential{} + return &this +} + +// GetType returns the Type field value if set, zero value otherwise. +func (o *Credential) GetType() CredentialType { + if o == nil || IsNil(o.Type) { + var ret CredentialType + return ret + } + return *o.Type +} + +// GetTypeOk returns a tuple with the Type field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Credential) GetTypeOk() (*CredentialType, bool) { + if o == nil || IsNil(o.Type) { + return nil, false + } + return o.Type, true +} + +// HasType returns a boolean if a field has been set. +func (o *Credential) HasType() bool { + if o != nil && !IsNil(o.Type) { + return true + } + + return false +} + +// SetType gets a reference to the given CredentialType and assigns it to the Type field. +func (o *Credential) SetType(v CredentialType) { + o.Type = &v +} + +// GetUsername returns the Username field value if set, zero value otherwise. +func (o *Credential) GetUsername() string { + if o == nil || IsNil(o.Username) { + var ret string + return ret + } + return *o.Username +} + +// GetUsernameOk returns a tuple with the Username field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Credential) GetUsernameOk() (*string, bool) { + if o == nil || IsNil(o.Username) { + return nil, false + } + return o.Username, true +} + +// HasUsername returns a boolean if a field has been set. +func (o *Credential) HasUsername() bool { + if o != nil && !IsNil(o.Username) { + return true + } + + return false +} + +// SetUsername gets a reference to the given string and assigns it to the Username field. +func (o *Credential) SetUsername(v string) { + o.Username = &v +} + +func (o Credential) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o Credential) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Type) { + toSerialize["type"] = o.Type + } + if !IsNil(o.Username) { + toSerialize["username"] = o.Username + } + return toSerialize, nil +} + +type NullableCredential struct { + value *Credential + isSet bool +} + +func (v NullableCredential) Get() *Credential { + return v.value +} + +func (v *NullableCredential) Set(val *Credential) { + v.value = val + v.isSet = true +} + +func (v NullableCredential) IsSet() bool { + return v.isSet +} + +func (v *NullableCredential) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableCredential(val *Credential) *NullableCredential { + return &NullableCredential{value: val, isSet: true} +} + +func (v NullableCredential) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableCredential) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/publicCloud/model_credential_type.go b/publicCloud/model_credential_type.go new file mode 100644 index 0000000..e9277ed --- /dev/null +++ b/publicCloud/model_credential_type.go @@ -0,0 +1,111 @@ +/* +LeaseWeb API for launching and managing Public Cloud instances + +> The base URL for this API is: **https://api.leaseweb.com/publicCloud/v1/_** This API provides ways to launch and manage Public Cloud instances.
BETA
This API is in BETA. Documentation might be incorrect or incomplete. Functionality might change with the final release.> + +API version: v1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package publicCloud + +import ( + "encoding/json" + "fmt" +) + +// CredentialType the model 'CredentialType' +type CredentialType string + +// List of credentialType +const ( + OPERATING_SYSTEM CredentialType = "OPERATING_SYSTEM" + CONTROL_PANEL CredentialType = "CONTROL_PANEL" +) + +// All allowed values of CredentialType enum +var AllowedCredentialTypeEnumValues = []CredentialType{ + "OPERATING_SYSTEM", + "CONTROL_PANEL", +} + +func (v *CredentialType) UnmarshalJSON(src []byte) error { + var value string + err := json.Unmarshal(src, &value) + if err != nil { + return err + } + enumTypeValue := CredentialType(value) + for _, existing := range AllowedCredentialTypeEnumValues { + if existing == enumTypeValue { + *v = enumTypeValue + return nil + } + } + + return fmt.Errorf("%+v is not a valid CredentialType", value) +} + +// NewCredentialTypeFromValue returns a pointer to a valid CredentialType +// for the value passed as argument, or an error if the value passed is not allowed by the enum +func NewCredentialTypeFromValue(v string) (*CredentialType, error) { + ev := CredentialType(v) + if ev.IsValid() { + return &ev, nil + } else { + return nil, fmt.Errorf("invalid value '%v' for CredentialType: valid values are %v", v, AllowedCredentialTypeEnumValues) + } +} + +// IsValid return true if the value is valid for the enum, false otherwise +func (v CredentialType) IsValid() bool { + for _, existing := range AllowedCredentialTypeEnumValues { + if existing == v { + return true + } + } + return false +} + +// Ptr returns reference to credentialType value +func (v CredentialType) Ptr() *CredentialType { + return &v +} + +type NullableCredentialType struct { + value *CredentialType + isSet bool +} + +func (v NullableCredentialType) Get() *CredentialType { + return v.value +} + +func (v *NullableCredentialType) Set(val *CredentialType) { + v.value = val + v.isSet = true +} + +func (v NullableCredentialType) IsSet() bool { + return v.isSet +} + +func (v *NullableCredentialType) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableCredentialType(val *CredentialType) *NullableCredentialType { + return &NullableCredentialType{value: val, isSet: true} +} + +func (v NullableCredentialType) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableCredentialType) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + diff --git a/publicCloud/model_ddos.go b/publicCloud/model_ddos.go new file mode 100644 index 0000000..a37a896 --- /dev/null +++ b/publicCloud/model_ddos.go @@ -0,0 +1,162 @@ +/* +LeaseWeb API for launching and managing Public Cloud instances + +> The base URL for this API is: **https://api.leaseweb.com/publicCloud/v1/_** This API provides ways to launch and manage Public Cloud instances.
BETA
This API is in BETA. Documentation might be incorrect or incomplete. Functionality might change with the final release.> + +API version: v1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package publicCloud + +import ( + "encoding/json" +) + +// checks if the Ddos type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &Ddos{} + +// Ddos struct for Ddos +type Ddos struct { + DetectionProfile *string `json:"detectionProfile,omitempty"` + ProtectionType *string `json:"protectionType,omitempty"` +} + +// NewDdos instantiates a new Ddos object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewDdos() *Ddos { + this := Ddos{} + return &this +} + +// NewDdosWithDefaults instantiates a new Ddos object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewDdosWithDefaults() *Ddos { + this := Ddos{} + return &this +} + +// GetDetectionProfile returns the DetectionProfile field value if set, zero value otherwise. +func (o *Ddos) GetDetectionProfile() string { + if o == nil || IsNil(o.DetectionProfile) { + var ret string + return ret + } + return *o.DetectionProfile +} + +// GetDetectionProfileOk returns a tuple with the DetectionProfile field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Ddos) GetDetectionProfileOk() (*string, bool) { + if o == nil || IsNil(o.DetectionProfile) { + return nil, false + } + return o.DetectionProfile, true +} + +// HasDetectionProfile returns a boolean if a field has been set. +func (o *Ddos) HasDetectionProfile() bool { + if o != nil && !IsNil(o.DetectionProfile) { + return true + } + + return false +} + +// SetDetectionProfile gets a reference to the given string and assigns it to the DetectionProfile field. +func (o *Ddos) SetDetectionProfile(v string) { + o.DetectionProfile = &v +} + +// GetProtectionType returns the ProtectionType field value if set, zero value otherwise. +func (o *Ddos) GetProtectionType() string { + if o == nil || IsNil(o.ProtectionType) { + var ret string + return ret + } + return *o.ProtectionType +} + +// GetProtectionTypeOk returns a tuple with the ProtectionType field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Ddos) GetProtectionTypeOk() (*string, bool) { + if o == nil || IsNil(o.ProtectionType) { + return nil, false + } + return o.ProtectionType, true +} + +// HasProtectionType returns a boolean if a field has been set. +func (o *Ddos) HasProtectionType() bool { + if o != nil && !IsNil(o.ProtectionType) { + return true + } + + return false +} + +// SetProtectionType gets a reference to the given string and assigns it to the ProtectionType field. +func (o *Ddos) SetProtectionType(v string) { + o.ProtectionType = &v +} + +func (o Ddos) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o Ddos) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.DetectionProfile) { + toSerialize["detectionProfile"] = o.DetectionProfile + } + if !IsNil(o.ProtectionType) { + toSerialize["protectionType"] = o.ProtectionType + } + return toSerialize, nil +} + +type NullableDdos struct { + value *Ddos + isSet bool +} + +func (v NullableDdos) Get() *Ddos { + return v.value +} + +func (v *NullableDdos) Set(val *Ddos) { + v.value = val + v.isSet = true +} + +func (v NullableDdos) IsSet() bool { + return v.isSet +} + +func (v *NullableDdos) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableDdos(val *Ddos) *NullableDdos { + return &NullableDdos{value: val, isSet: true} +} + +func (v NullableDdos) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableDdos) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/publicCloud/model_delete_firewall_rules_opts.go b/publicCloud/model_delete_firewall_rules_opts.go new file mode 100644 index 0000000..23c0513 --- /dev/null +++ b/publicCloud/model_delete_firewall_rules_opts.go @@ -0,0 +1,158 @@ +/* +LeaseWeb API for launching and managing Public Cloud instances + +> The base URL for this API is: **https://api.leaseweb.com/publicCloud/v1/_** This API provides ways to launch and manage Public Cloud instances.
BETA
This API is in BETA. Documentation might be incorrect or incomplete. Functionality might change with the final release.> + +API version: v1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package publicCloud + +import ( + "encoding/json" + "bytes" + "fmt" +) + +// checks if the DeleteFirewallRulesOpts type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &DeleteFirewallRulesOpts{} + +// DeleteFirewallRulesOpts struct for DeleteFirewallRulesOpts +type DeleteFirewallRulesOpts struct { + Rules []DeletionRule `json:"rules"` +} + +type _DeleteFirewallRulesOpts DeleteFirewallRulesOpts + +// NewDeleteFirewallRulesOpts instantiates a new DeleteFirewallRulesOpts object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewDeleteFirewallRulesOpts(rules []DeletionRule) *DeleteFirewallRulesOpts { + this := DeleteFirewallRulesOpts{} + this.Rules = rules + return &this +} + +// NewDeleteFirewallRulesOptsWithDefaults instantiates a new DeleteFirewallRulesOpts object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewDeleteFirewallRulesOptsWithDefaults() *DeleteFirewallRulesOpts { + this := DeleteFirewallRulesOpts{} + return &this +} + +// GetRules returns the Rules field value +func (o *DeleteFirewallRulesOpts) GetRules() []DeletionRule { + if o == nil { + var ret []DeletionRule + return ret + } + + return o.Rules +} + +// GetRulesOk returns a tuple with the Rules field value +// and a boolean to check if the value has been set. +func (o *DeleteFirewallRulesOpts) GetRulesOk() ([]DeletionRule, bool) { + if o == nil { + return nil, false + } + return o.Rules, true +} + +// SetRules sets field value +func (o *DeleteFirewallRulesOpts) SetRules(v []DeletionRule) { + o.Rules = v +} + +func (o DeleteFirewallRulesOpts) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o DeleteFirewallRulesOpts) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + toSerialize["rules"] = o.Rules + return toSerialize, nil +} + +func (o *DeleteFirewallRulesOpts) UnmarshalJSON(data []byte) (err error) { + // This validates that all required properties are included in the JSON object + // by unmarshalling the object into a generic map with string keys and checking + // that every required field exists as a key in the generic map. + requiredProperties := []string{ + "rules", + } + + allProperties := make(map[string]interface{}) + + err = json.Unmarshal(data, &allProperties) + + if err != nil { + return err; + } + + for _, requiredProperty := range(requiredProperties) { + if _, exists := allProperties[requiredProperty]; !exists { + return fmt.Errorf("no value given for required property %v", requiredProperty) + } + } + + varDeleteFirewallRulesOpts := _DeleteFirewallRulesOpts{} + + decoder := json.NewDecoder(bytes.NewReader(data)) + decoder.DisallowUnknownFields() + err = decoder.Decode(&varDeleteFirewallRulesOpts) + + if err != nil { + return err + } + + *o = DeleteFirewallRulesOpts(varDeleteFirewallRulesOpts) + + return err +} + +type NullableDeleteFirewallRulesOpts struct { + value *DeleteFirewallRulesOpts + isSet bool +} + +func (v NullableDeleteFirewallRulesOpts) Get() *DeleteFirewallRulesOpts { + return v.value +} + +func (v *NullableDeleteFirewallRulesOpts) Set(val *DeleteFirewallRulesOpts) { + v.value = val + v.isSet = true +} + +func (v NullableDeleteFirewallRulesOpts) IsSet() bool { + return v.isSet +} + +func (v *NullableDeleteFirewallRulesOpts) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableDeleteFirewallRulesOpts(val *DeleteFirewallRulesOpts) *NullableDeleteFirewallRulesOpts { + return &NullableDeleteFirewallRulesOpts{value: val, isSet: true} +} + +func (v NullableDeleteFirewallRulesOpts) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableDeleteFirewallRulesOpts) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/publicCloud/model_delete_firewall_rules_result.go b/publicCloud/model_delete_firewall_rules_result.go new file mode 100644 index 0000000..bcf1948 --- /dev/null +++ b/publicCloud/model_delete_firewall_rules_result.go @@ -0,0 +1,164 @@ +/* +LeaseWeb API for launching and managing Public Cloud instances + +> The base URL for this API is: **https://api.leaseweb.com/publicCloud/v1/_** This API provides ways to launch and manage Public Cloud instances.
BETA
This API is in BETA. Documentation might be incorrect or incomplete. Functionality might change with the final release.> + +API version: v1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package publicCloud + +import ( + "encoding/json" +) + +// checks if the DeleteFirewallRulesResult type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &DeleteFirewallRulesResult{} + +// DeleteFirewallRulesResult struct for DeleteFirewallRulesResult +type DeleteFirewallRulesResult struct { + // List of rules that have been successfully deleted + Deleted []FirewallRule `json:"deleted,omitempty"` + // List of rules that have failed to be deleted + Failed []FirewallRule `json:"failed,omitempty"` +} + +// NewDeleteFirewallRulesResult instantiates a new DeleteFirewallRulesResult object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewDeleteFirewallRulesResult() *DeleteFirewallRulesResult { + this := DeleteFirewallRulesResult{} + return &this +} + +// NewDeleteFirewallRulesResultWithDefaults instantiates a new DeleteFirewallRulesResult object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewDeleteFirewallRulesResultWithDefaults() *DeleteFirewallRulesResult { + this := DeleteFirewallRulesResult{} + return &this +} + +// GetDeleted returns the Deleted field value if set, zero value otherwise. +func (o *DeleteFirewallRulesResult) GetDeleted() []FirewallRule { + if o == nil || IsNil(o.Deleted) { + var ret []FirewallRule + return ret + } + return o.Deleted +} + +// GetDeletedOk returns a tuple with the Deleted field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *DeleteFirewallRulesResult) GetDeletedOk() ([]FirewallRule, bool) { + if o == nil || IsNil(o.Deleted) { + return nil, false + } + return o.Deleted, true +} + +// HasDeleted returns a boolean if a field has been set. +func (o *DeleteFirewallRulesResult) HasDeleted() bool { + if o != nil && !IsNil(o.Deleted) { + return true + } + + return false +} + +// SetDeleted gets a reference to the given []FirewallRule and assigns it to the Deleted field. +func (o *DeleteFirewallRulesResult) SetDeleted(v []FirewallRule) { + o.Deleted = v +} + +// GetFailed returns the Failed field value if set, zero value otherwise. +func (o *DeleteFirewallRulesResult) GetFailed() []FirewallRule { + if o == nil || IsNil(o.Failed) { + var ret []FirewallRule + return ret + } + return o.Failed +} + +// GetFailedOk returns a tuple with the Failed field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *DeleteFirewallRulesResult) GetFailedOk() ([]FirewallRule, bool) { + if o == nil || IsNil(o.Failed) { + return nil, false + } + return o.Failed, true +} + +// HasFailed returns a boolean if a field has been set. +func (o *DeleteFirewallRulesResult) HasFailed() bool { + if o != nil && !IsNil(o.Failed) { + return true + } + + return false +} + +// SetFailed gets a reference to the given []FirewallRule and assigns it to the Failed field. +func (o *DeleteFirewallRulesResult) SetFailed(v []FirewallRule) { + o.Failed = v +} + +func (o DeleteFirewallRulesResult) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o DeleteFirewallRulesResult) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Deleted) { + toSerialize["deleted"] = o.Deleted + } + if !IsNil(o.Failed) { + toSerialize["failed"] = o.Failed + } + return toSerialize, nil +} + +type NullableDeleteFirewallRulesResult struct { + value *DeleteFirewallRulesResult + isSet bool +} + +func (v NullableDeleteFirewallRulesResult) Get() *DeleteFirewallRulesResult { + return v.value +} + +func (v *NullableDeleteFirewallRulesResult) Set(val *DeleteFirewallRulesResult) { + v.value = val + v.isSet = true +} + +func (v NullableDeleteFirewallRulesResult) IsSet() bool { + return v.isSet +} + +func (v *NullableDeleteFirewallRulesResult) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableDeleteFirewallRulesResult(val *DeleteFirewallRulesResult) *NullableDeleteFirewallRulesResult { + return &NullableDeleteFirewallRulesResult{value: val, isSet: true} +} + +func (v NullableDeleteFirewallRulesResult) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableDeleteFirewallRulesResult) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/publicCloud/model_deletion_rule.go b/publicCloud/model_deletion_rule.go new file mode 100644 index 0000000..7564a8e --- /dev/null +++ b/publicCloud/model_deletion_rule.go @@ -0,0 +1,158 @@ +/* +LeaseWeb API for launching and managing Public Cloud instances + +> The base URL for this API is: **https://api.leaseweb.com/publicCloud/v1/_** This API provides ways to launch and manage Public Cloud instances.
BETA
This API is in BETA. Documentation might be incorrect or incomplete. Functionality might change with the final release.> + +API version: v1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package publicCloud + +import ( + "encoding/json" + "bytes" + "fmt" +) + +// checks if the DeletionRule type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &DeletionRule{} + +// DeletionRule struct for DeletionRule +type DeletionRule struct { + Id string `json:"id"` +} + +type _DeletionRule DeletionRule + +// NewDeletionRule instantiates a new DeletionRule object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewDeletionRule(id string) *DeletionRule { + this := DeletionRule{} + this.Id = id + return &this +} + +// NewDeletionRuleWithDefaults instantiates a new DeletionRule object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewDeletionRuleWithDefaults() *DeletionRule { + this := DeletionRule{} + return &this +} + +// GetId returns the Id field value +func (o *DeletionRule) GetId() string { + if o == nil { + var ret string + return ret + } + + return o.Id +} + +// GetIdOk returns a tuple with the Id field value +// and a boolean to check if the value has been set. +func (o *DeletionRule) GetIdOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.Id, true +} + +// SetId sets field value +func (o *DeletionRule) SetId(v string) { + o.Id = v +} + +func (o DeletionRule) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o DeletionRule) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + toSerialize["id"] = o.Id + return toSerialize, nil +} + +func (o *DeletionRule) UnmarshalJSON(data []byte) (err error) { + // This validates that all required properties are included in the JSON object + // by unmarshalling the object into a generic map with string keys and checking + // that every required field exists as a key in the generic map. + requiredProperties := []string{ + "id", + } + + allProperties := make(map[string]interface{}) + + err = json.Unmarshal(data, &allProperties) + + if err != nil { + return err; + } + + for _, requiredProperty := range(requiredProperties) { + if _, exists := allProperties[requiredProperty]; !exists { + return fmt.Errorf("no value given for required property %v", requiredProperty) + } + } + + varDeletionRule := _DeletionRule{} + + decoder := json.NewDecoder(bytes.NewReader(data)) + decoder.DisallowUnknownFields() + err = decoder.Decode(&varDeletionRule) + + if err != nil { + return err + } + + *o = DeletionRule(varDeletionRule) + + return err +} + +type NullableDeletionRule struct { + value *DeletionRule + isSet bool +} + +func (v NullableDeletionRule) Get() *DeletionRule { + return v.value +} + +func (v *NullableDeletionRule) Set(val *DeletionRule) { + v.value = val + v.isSet = true +} + +func (v NullableDeletionRule) IsSet() bool { + return v.isSet +} + +func (v *NullableDeletionRule) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableDeletionRule(val *DeletionRule) *NullableDeletionRule { + return &NullableDeletionRule{value: val, isSet: true} +} + +func (v NullableDeletionRule) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableDeletionRule) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/publicCloud/model_edit_firewall_rules_opts.go b/publicCloud/model_edit_firewall_rules_opts.go new file mode 100644 index 0000000..7e93c52 --- /dev/null +++ b/publicCloud/model_edit_firewall_rules_opts.go @@ -0,0 +1,158 @@ +/* +LeaseWeb API for launching and managing Public Cloud instances + +> The base URL for this API is: **https://api.leaseweb.com/publicCloud/v1/_** This API provides ways to launch and manage Public Cloud instances.
BETA
This API is in BETA. Documentation might be incorrect or incomplete. Functionality might change with the final release.> + +API version: v1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package publicCloud + +import ( + "encoding/json" + "bytes" + "fmt" +) + +// checks if the EditFirewallRulesOpts type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &EditFirewallRulesOpts{} + +// EditFirewallRulesOpts struct for EditFirewallRulesOpts +type EditFirewallRulesOpts struct { + Rules []EditRule `json:"rules"` +} + +type _EditFirewallRulesOpts EditFirewallRulesOpts + +// NewEditFirewallRulesOpts instantiates a new EditFirewallRulesOpts object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewEditFirewallRulesOpts(rules []EditRule) *EditFirewallRulesOpts { + this := EditFirewallRulesOpts{} + this.Rules = rules + return &this +} + +// NewEditFirewallRulesOptsWithDefaults instantiates a new EditFirewallRulesOpts object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewEditFirewallRulesOptsWithDefaults() *EditFirewallRulesOpts { + this := EditFirewallRulesOpts{} + return &this +} + +// GetRules returns the Rules field value +func (o *EditFirewallRulesOpts) GetRules() []EditRule { + if o == nil { + var ret []EditRule + return ret + } + + return o.Rules +} + +// GetRulesOk returns a tuple with the Rules field value +// and a boolean to check if the value has been set. +func (o *EditFirewallRulesOpts) GetRulesOk() ([]EditRule, bool) { + if o == nil { + return nil, false + } + return o.Rules, true +} + +// SetRules sets field value +func (o *EditFirewallRulesOpts) SetRules(v []EditRule) { + o.Rules = v +} + +func (o EditFirewallRulesOpts) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o EditFirewallRulesOpts) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + toSerialize["rules"] = o.Rules + return toSerialize, nil +} + +func (o *EditFirewallRulesOpts) UnmarshalJSON(data []byte) (err error) { + // This validates that all required properties are included in the JSON object + // by unmarshalling the object into a generic map with string keys and checking + // that every required field exists as a key in the generic map. + requiredProperties := []string{ + "rules", + } + + allProperties := make(map[string]interface{}) + + err = json.Unmarshal(data, &allProperties) + + if err != nil { + return err; + } + + for _, requiredProperty := range(requiredProperties) { + if _, exists := allProperties[requiredProperty]; !exists { + return fmt.Errorf("no value given for required property %v", requiredProperty) + } + } + + varEditFirewallRulesOpts := _EditFirewallRulesOpts{} + + decoder := json.NewDecoder(bytes.NewReader(data)) + decoder.DisallowUnknownFields() + err = decoder.Decode(&varEditFirewallRulesOpts) + + if err != nil { + return err + } + + *o = EditFirewallRulesOpts(varEditFirewallRulesOpts) + + return err +} + +type NullableEditFirewallRulesOpts struct { + value *EditFirewallRulesOpts + isSet bool +} + +func (v NullableEditFirewallRulesOpts) Get() *EditFirewallRulesOpts { + return v.value +} + +func (v *NullableEditFirewallRulesOpts) Set(val *EditFirewallRulesOpts) { + v.value = val + v.isSet = true +} + +func (v NullableEditFirewallRulesOpts) IsSet() bool { + return v.isSet +} + +func (v *NullableEditFirewallRulesOpts) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableEditFirewallRulesOpts(val *EditFirewallRulesOpts) *NullableEditFirewallRulesOpts { + return &NullableEditFirewallRulesOpts{value: val, isSet: true} +} + +func (v NullableEditFirewallRulesOpts) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableEditFirewallRulesOpts) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/publicCloud/model_edit_firewall_rules_result.go b/publicCloud/model_edit_firewall_rules_result.go new file mode 100644 index 0000000..2bd0cd8 --- /dev/null +++ b/publicCloud/model_edit_firewall_rules_result.go @@ -0,0 +1,164 @@ +/* +LeaseWeb API for launching and managing Public Cloud instances + +> The base URL for this API is: **https://api.leaseweb.com/publicCloud/v1/_** This API provides ways to launch and manage Public Cloud instances.
BETA
This API is in BETA. Documentation might be incorrect or incomplete. Functionality might change with the final release.> + +API version: v1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package publicCloud + +import ( + "encoding/json" +) + +// checks if the EditFirewallRulesResult type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &EditFirewallRulesResult{} + +// EditFirewallRulesResult struct for EditFirewallRulesResult +type EditFirewallRulesResult struct { + // List of rules that have been successfully edited + Updated []FirewallRule `json:"updated,omitempty"` + // List of rules that have failed to be edited along with their error messages + Failed []FailedRule `json:"failed,omitempty"` +} + +// NewEditFirewallRulesResult instantiates a new EditFirewallRulesResult object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewEditFirewallRulesResult() *EditFirewallRulesResult { + this := EditFirewallRulesResult{} + return &this +} + +// NewEditFirewallRulesResultWithDefaults instantiates a new EditFirewallRulesResult object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewEditFirewallRulesResultWithDefaults() *EditFirewallRulesResult { + this := EditFirewallRulesResult{} + return &this +} + +// GetUpdated returns the Updated field value if set, zero value otherwise. +func (o *EditFirewallRulesResult) GetUpdated() []FirewallRule { + if o == nil || IsNil(o.Updated) { + var ret []FirewallRule + return ret + } + return o.Updated +} + +// GetUpdatedOk returns a tuple with the Updated field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *EditFirewallRulesResult) GetUpdatedOk() ([]FirewallRule, bool) { + if o == nil || IsNil(o.Updated) { + return nil, false + } + return o.Updated, true +} + +// HasUpdated returns a boolean if a field has been set. +func (o *EditFirewallRulesResult) HasUpdated() bool { + if o != nil && !IsNil(o.Updated) { + return true + } + + return false +} + +// SetUpdated gets a reference to the given []FirewallRule and assigns it to the Updated field. +func (o *EditFirewallRulesResult) SetUpdated(v []FirewallRule) { + o.Updated = v +} + +// GetFailed returns the Failed field value if set, zero value otherwise. +func (o *EditFirewallRulesResult) GetFailed() []FailedRule { + if o == nil || IsNil(o.Failed) { + var ret []FailedRule + return ret + } + return o.Failed +} + +// GetFailedOk returns a tuple with the Failed field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *EditFirewallRulesResult) GetFailedOk() ([]FailedRule, bool) { + if o == nil || IsNil(o.Failed) { + return nil, false + } + return o.Failed, true +} + +// HasFailed returns a boolean if a field has been set. +func (o *EditFirewallRulesResult) HasFailed() bool { + if o != nil && !IsNil(o.Failed) { + return true + } + + return false +} + +// SetFailed gets a reference to the given []FailedRule and assigns it to the Failed field. +func (o *EditFirewallRulesResult) SetFailed(v []FailedRule) { + o.Failed = v +} + +func (o EditFirewallRulesResult) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o EditFirewallRulesResult) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Updated) { + toSerialize["updated"] = o.Updated + } + if !IsNil(o.Failed) { + toSerialize["failed"] = o.Failed + } + return toSerialize, nil +} + +type NullableEditFirewallRulesResult struct { + value *EditFirewallRulesResult + isSet bool +} + +func (v NullableEditFirewallRulesResult) Get() *EditFirewallRulesResult { + return v.value +} + +func (v *NullableEditFirewallRulesResult) Set(val *EditFirewallRulesResult) { + v.value = val + v.isSet = true +} + +func (v NullableEditFirewallRulesResult) IsSet() bool { + return v.isSet +} + +func (v *NullableEditFirewallRulesResult) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableEditFirewallRulesResult(val *EditFirewallRulesResult) *NullableEditFirewallRulesResult { + return &NullableEditFirewallRulesResult{value: val, isSet: true} +} + +func (v NullableEditFirewallRulesResult) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableEditFirewallRulesResult) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/publicCloud/model_edit_rule.go b/publicCloud/model_edit_rule.go new file mode 100644 index 0000000..7ef1f84 --- /dev/null +++ b/publicCloud/model_edit_rule.go @@ -0,0 +1,360 @@ +/* +LeaseWeb API for launching and managing Public Cloud instances + +> The base URL for this API is: **https://api.leaseweb.com/publicCloud/v1/_** This API provides ways to launch and manage Public Cloud instances.
BETA
This API is in BETA. Documentation might be incorrect or incomplete. Functionality might change with the final release.> + +API version: v1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package publicCloud + +import ( + "encoding/json" + "bytes" + "fmt" +) + +// checks if the EditRule type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &EditRule{} + +// EditRule struct for EditRule +type EditRule struct { + Protocol string `json:"protocol"` + StartPort NullableInt32 `json:"startPort"` + EndPort NullableInt32 `json:"endPort"` + IcmpType int32 `json:"icmpType"` + IcmpCode int32 `json:"icmpCode"` + Id string `json:"id"` + Name NullableString `json:"name"` + Cidr string `json:"cidr"` +} + +type _EditRule EditRule + +// NewEditRule instantiates a new EditRule object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewEditRule(protocol string, startPort NullableInt32, endPort NullableInt32, icmpType int32, icmpCode int32, id string, name NullableString, cidr string) *EditRule { + this := EditRule{} + this.Protocol = protocol + this.StartPort = startPort + this.EndPort = endPort + this.IcmpType = icmpType + this.IcmpCode = icmpCode + this.Id = id + this.Name = name + this.Cidr = cidr + return &this +} + +// NewEditRuleWithDefaults instantiates a new EditRule object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewEditRuleWithDefaults() *EditRule { + this := EditRule{} + return &this +} + +// GetProtocol returns the Protocol field value +func (o *EditRule) GetProtocol() string { + if o == nil { + var ret string + return ret + } + + return o.Protocol +} + +// GetProtocolOk returns a tuple with the Protocol field value +// and a boolean to check if the value has been set. +func (o *EditRule) GetProtocolOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.Protocol, true +} + +// SetProtocol sets field value +func (o *EditRule) SetProtocol(v string) { + o.Protocol = v +} + +// GetStartPort returns the StartPort field value +// If the value is explicit nil, the zero value for int32 will be returned +func (o *EditRule) GetStartPort() int32 { + if o == nil || o.StartPort.Get() == nil { + var ret int32 + return ret + } + + return *o.StartPort.Get() +} + +// GetStartPortOk returns a tuple with the StartPort field value +// and a boolean to check if the value has been set. +// NOTE: If the value is an explicit nil, `nil, true` will be returned +func (o *EditRule) GetStartPortOk() (*int32, bool) { + if o == nil { + return nil, false + } + return o.StartPort.Get(), o.StartPort.IsSet() +} + +// SetStartPort sets field value +func (o *EditRule) SetStartPort(v int32) { + o.StartPort.Set(&v) +} + +// GetEndPort returns the EndPort field value +// If the value is explicit nil, the zero value for int32 will be returned +func (o *EditRule) GetEndPort() int32 { + if o == nil || o.EndPort.Get() == nil { + var ret int32 + return ret + } + + return *o.EndPort.Get() +} + +// GetEndPortOk returns a tuple with the EndPort field value +// and a boolean to check if the value has been set. +// NOTE: If the value is an explicit nil, `nil, true` will be returned +func (o *EditRule) GetEndPortOk() (*int32, bool) { + if o == nil { + return nil, false + } + return o.EndPort.Get(), o.EndPort.IsSet() +} + +// SetEndPort sets field value +func (o *EditRule) SetEndPort(v int32) { + o.EndPort.Set(&v) +} + +// GetIcmpType returns the IcmpType field value +func (o *EditRule) GetIcmpType() int32 { + if o == nil { + var ret int32 + return ret + } + + return o.IcmpType +} + +// GetIcmpTypeOk returns a tuple with the IcmpType field value +// and a boolean to check if the value has been set. +func (o *EditRule) GetIcmpTypeOk() (*int32, bool) { + if o == nil { + return nil, false + } + return &o.IcmpType, true +} + +// SetIcmpType sets field value +func (o *EditRule) SetIcmpType(v int32) { + o.IcmpType = v +} + +// GetIcmpCode returns the IcmpCode field value +func (o *EditRule) GetIcmpCode() int32 { + if o == nil { + var ret int32 + return ret + } + + return o.IcmpCode +} + +// GetIcmpCodeOk returns a tuple with the IcmpCode field value +// and a boolean to check if the value has been set. +func (o *EditRule) GetIcmpCodeOk() (*int32, bool) { + if o == nil { + return nil, false + } + return &o.IcmpCode, true +} + +// SetIcmpCode sets field value +func (o *EditRule) SetIcmpCode(v int32) { + o.IcmpCode = v +} + +// GetId returns the Id field value +func (o *EditRule) GetId() string { + if o == nil { + var ret string + return ret + } + + return o.Id +} + +// GetIdOk returns a tuple with the Id field value +// and a boolean to check if the value has been set. +func (o *EditRule) GetIdOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.Id, true +} + +// SetId sets field value +func (o *EditRule) SetId(v string) { + o.Id = v +} + +// GetName returns the Name field value +// If the value is explicit nil, the zero value for string will be returned +func (o *EditRule) GetName() string { + if o == nil || o.Name.Get() == nil { + var ret string + return ret + } + + return *o.Name.Get() +} + +// GetNameOk returns a tuple with the Name field value +// and a boolean to check if the value has been set. +// NOTE: If the value is an explicit nil, `nil, true` will be returned +func (o *EditRule) GetNameOk() (*string, bool) { + if o == nil { + return nil, false + } + return o.Name.Get(), o.Name.IsSet() +} + +// SetName sets field value +func (o *EditRule) SetName(v string) { + o.Name.Set(&v) +} + +// GetCidr returns the Cidr field value +func (o *EditRule) GetCidr() string { + if o == nil { + var ret string + return ret + } + + return o.Cidr +} + +// GetCidrOk returns a tuple with the Cidr field value +// and a boolean to check if the value has been set. +func (o *EditRule) GetCidrOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.Cidr, true +} + +// SetCidr sets field value +func (o *EditRule) SetCidr(v string) { + o.Cidr = v +} + +func (o EditRule) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o EditRule) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + toSerialize["protocol"] = o.Protocol + toSerialize["startPort"] = o.StartPort.Get() + toSerialize["endPort"] = o.EndPort.Get() + toSerialize["icmpType"] = o.IcmpType + toSerialize["icmpCode"] = o.IcmpCode + toSerialize["id"] = o.Id + toSerialize["name"] = o.Name.Get() + toSerialize["cidr"] = o.Cidr + return toSerialize, nil +} + +func (o *EditRule) UnmarshalJSON(data []byte) (err error) { + // This validates that all required properties are included in the JSON object + // by unmarshalling the object into a generic map with string keys and checking + // that every required field exists as a key in the generic map. + requiredProperties := []string{ + "protocol", + "startPort", + "endPort", + "icmpType", + "icmpCode", + "id", + "name", + "cidr", + } + + allProperties := make(map[string]interface{}) + + err = json.Unmarshal(data, &allProperties) + + if err != nil { + return err; + } + + for _, requiredProperty := range(requiredProperties) { + if _, exists := allProperties[requiredProperty]; !exists { + return fmt.Errorf("no value given for required property %v", requiredProperty) + } + } + + varEditRule := _EditRule{} + + decoder := json.NewDecoder(bytes.NewReader(data)) + decoder.DisallowUnknownFields() + err = decoder.Decode(&varEditRule) + + if err != nil { + return err + } + + *o = EditRule(varEditRule) + + return err +} + +type NullableEditRule struct { + value *EditRule + isSet bool +} + +func (v NullableEditRule) Get() *EditRule { + return v.value +} + +func (v *NullableEditRule) Set(val *EditRule) { + v.value = val + v.isSet = true +} + +func (v NullableEditRule) IsSet() bool { + return v.isSet +} + +func (v *NullableEditRule) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableEditRule(val *EditRule) *NullableEditRule { + return &NullableEditRule{value: val, isSet: true} +} + +func (v NullableEditRule) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableEditRule) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/publicCloud/model_error_result.go b/publicCloud/model_error_result.go new file mode 100644 index 0000000..d2bfa6f --- /dev/null +++ b/publicCloud/model_error_result.go @@ -0,0 +1,237 @@ +/* +LeaseWeb API for launching and managing Public Cloud instances + +> The base URL for this API is: **https://api.leaseweb.com/publicCloud/v1/_** This API provides ways to launch and manage Public Cloud instances.
BETA
This API is in BETA. Documentation might be incorrect or incomplete. Functionality might change with the final release.> + +API version: v1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package publicCloud + +import ( + "encoding/json" +) + +// checks if the ErrorResult type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &ErrorResult{} + +// ErrorResult struct for ErrorResult +type ErrorResult struct { + // The correlation ID of the current request. + CorrelationId *string `json:"correlationId,omitempty"` + // The error code. + ErrorCode *string `json:"errorCode,omitempty"` + // A human friendly description of the error. + ErrorMessage *string `json:"errorMessage,omitempty"` + ErrorDetails []map[string][]string `json:"errorDetails,omitempty"` +} + +// NewErrorResult instantiates a new ErrorResult object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewErrorResult() *ErrorResult { + this := ErrorResult{} + return &this +} + +// NewErrorResultWithDefaults instantiates a new ErrorResult object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewErrorResultWithDefaults() *ErrorResult { + this := ErrorResult{} + return &this +} + +// GetCorrelationId returns the CorrelationId field value if set, zero value otherwise. +func (o *ErrorResult) GetCorrelationId() string { + if o == nil || IsNil(o.CorrelationId) { + var ret string + return ret + } + return *o.CorrelationId +} + +// GetCorrelationIdOk returns a tuple with the CorrelationId field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ErrorResult) GetCorrelationIdOk() (*string, bool) { + if o == nil || IsNil(o.CorrelationId) { + return nil, false + } + return o.CorrelationId, true +} + +// HasCorrelationId returns a boolean if a field has been set. +func (o *ErrorResult) HasCorrelationId() bool { + if o != nil && !IsNil(o.CorrelationId) { + return true + } + + return false +} + +// SetCorrelationId gets a reference to the given string and assigns it to the CorrelationId field. +func (o *ErrorResult) SetCorrelationId(v string) { + o.CorrelationId = &v +} + +// GetErrorCode returns the ErrorCode field value if set, zero value otherwise. +func (o *ErrorResult) GetErrorCode() string { + if o == nil || IsNil(o.ErrorCode) { + var ret string + return ret + } + return *o.ErrorCode +} + +// GetErrorCodeOk returns a tuple with the ErrorCode field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ErrorResult) GetErrorCodeOk() (*string, bool) { + if o == nil || IsNil(o.ErrorCode) { + return nil, false + } + return o.ErrorCode, true +} + +// HasErrorCode returns a boolean if a field has been set. +func (o *ErrorResult) HasErrorCode() bool { + if o != nil && !IsNil(o.ErrorCode) { + return true + } + + return false +} + +// SetErrorCode gets a reference to the given string and assigns it to the ErrorCode field. +func (o *ErrorResult) SetErrorCode(v string) { + o.ErrorCode = &v +} + +// GetErrorMessage returns the ErrorMessage field value if set, zero value otherwise. +func (o *ErrorResult) GetErrorMessage() string { + if o == nil || IsNil(o.ErrorMessage) { + var ret string + return ret + } + return *o.ErrorMessage +} + +// GetErrorMessageOk returns a tuple with the ErrorMessage field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ErrorResult) GetErrorMessageOk() (*string, bool) { + if o == nil || IsNil(o.ErrorMessage) { + return nil, false + } + return o.ErrorMessage, true +} + +// HasErrorMessage returns a boolean if a field has been set. +func (o *ErrorResult) HasErrorMessage() bool { + if o != nil && !IsNil(o.ErrorMessage) { + return true + } + + return false +} + +// SetErrorMessage gets a reference to the given string and assigns it to the ErrorMessage field. +func (o *ErrorResult) SetErrorMessage(v string) { + o.ErrorMessage = &v +} + +// GetErrorDetails returns the ErrorDetails field value if set, zero value otherwise. +func (o *ErrorResult) GetErrorDetails() []map[string][]string { + if o == nil || IsNil(o.ErrorDetails) { + var ret []map[string][]string + return ret + } + return o.ErrorDetails +} + +// GetErrorDetailsOk returns a tuple with the ErrorDetails field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ErrorResult) GetErrorDetailsOk() ([]map[string][]string, bool) { + if o == nil || IsNil(o.ErrorDetails) { + return nil, false + } + return o.ErrorDetails, true +} + +// HasErrorDetails returns a boolean if a field has been set. +func (o *ErrorResult) HasErrorDetails() bool { + if o != nil && !IsNil(o.ErrorDetails) { + return true + } + + return false +} + +// SetErrorDetails gets a reference to the given []map[string][]string and assigns it to the ErrorDetails field. +func (o *ErrorResult) SetErrorDetails(v []map[string][]string) { + o.ErrorDetails = v +} + +func (o ErrorResult) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o ErrorResult) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.CorrelationId) { + toSerialize["correlationId"] = o.CorrelationId + } + if !IsNil(o.ErrorCode) { + toSerialize["errorCode"] = o.ErrorCode + } + if !IsNil(o.ErrorMessage) { + toSerialize["errorMessage"] = o.ErrorMessage + } + if !IsNil(o.ErrorDetails) { + toSerialize["errorDetails"] = o.ErrorDetails + } + return toSerialize, nil +} + +type NullableErrorResult struct { + value *ErrorResult + isSet bool +} + +func (v NullableErrorResult) Get() *ErrorResult { + return v.value +} + +func (v *NullableErrorResult) Set(val *ErrorResult) { + v.value = val + v.isSet = true +} + +func (v NullableErrorResult) IsSet() bool { + return v.isSet +} + +func (v *NullableErrorResult) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableErrorResult(val *ErrorResult) *NullableErrorResult { + return &NullableErrorResult{value: val, isSet: true} +} + +func (v NullableErrorResult) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableErrorResult) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/publicCloud/model_expense_result_instance.go b/publicCloud/model_expense_result_instance.go new file mode 100644 index 0000000..aedbe7a --- /dev/null +++ b/publicCloud/model_expense_result_instance.go @@ -0,0 +1,645 @@ +/* +LeaseWeb API for launching and managing Public Cloud instances + +> The base URL for this API is: **https://api.leaseweb.com/publicCloud/v1/_** This API provides ways to launch and manage Public Cloud instances.
BETA
This API is in BETA. Documentation might be incorrect or incomplete. Functionality might change with the final release.> + +API version: v1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package publicCloud + +import ( + "encoding/json" + "time" +) + +// checks if the ExpenseResultInstance type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &ExpenseResultInstance{} + +// ExpenseResultInstance struct for ExpenseResultInstance +type ExpenseResultInstance struct { + // The unique identifier for the instance. + Id *string `json:"id,omitempty"` + // The reference of the instance. + Reference *string `json:"reference,omitempty"` + Resources *InstanceResources `json:"resources,omitempty"` + // The contract type of the instance. + ContractType *string `json:"contractType,omitempty"` + // Date when the contract was created + ContractCreatedAt *time.Time `json:"contractCreatedAt,omitempty"` + // Date when the instance was started + StartedAt *time.Time `json:"startedAt,omitempty"` + // The contract term (in months) of the instance. + ContractTerm *int32 `json:"contractTerm,omitempty"` + // The billing frequency (in months) of the instance. + BillingFrequency *int32 `json:"billingFrequency,omitempty"` + // The root disk size as specified during its launch or update, in GB + RootDiskSize *int32 `json:"rootDiskSize,omitempty"` + // The root disk type as specified during its launch or update. + RootDiskType *string `json:"rootDiskType,omitempty"` + // The billing type of the instance. PREPAID is used for monthly commited instances, POSTPAID for hourly instances. + BillingType *string `json:"billingType,omitempty"` + // The number of hours the instance has been running. + Hours *int32 `json:"hours,omitempty"` + // The start date of the billing period. + From *time.Time `json:"from,omitempty"` + // The end date of the billing period. + To *time.Time `json:"to,omitempty"` + // The price of the instance for the billing period. + Price *string `json:"price,omitempty"` +} + +// NewExpenseResultInstance instantiates a new ExpenseResultInstance object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewExpenseResultInstance() *ExpenseResultInstance { + this := ExpenseResultInstance{} + return &this +} + +// NewExpenseResultInstanceWithDefaults instantiates a new ExpenseResultInstance object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewExpenseResultInstanceWithDefaults() *ExpenseResultInstance { + this := ExpenseResultInstance{} + return &this +} + +// GetId returns the Id field value if set, zero value otherwise. +func (o *ExpenseResultInstance) GetId() string { + if o == nil || IsNil(o.Id) { + var ret string + return ret + } + return *o.Id +} + +// GetIdOk returns a tuple with the Id field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ExpenseResultInstance) GetIdOk() (*string, bool) { + if o == nil || IsNil(o.Id) { + return nil, false + } + return o.Id, true +} + +// HasId returns a boolean if a field has been set. +func (o *ExpenseResultInstance) HasId() bool { + if o != nil && !IsNil(o.Id) { + return true + } + + return false +} + +// SetId gets a reference to the given string and assigns it to the Id field. +func (o *ExpenseResultInstance) SetId(v string) { + o.Id = &v +} + +// GetReference returns the Reference field value if set, zero value otherwise. +func (o *ExpenseResultInstance) GetReference() string { + if o == nil || IsNil(o.Reference) { + var ret string + return ret + } + return *o.Reference +} + +// GetReferenceOk returns a tuple with the Reference field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ExpenseResultInstance) GetReferenceOk() (*string, bool) { + if o == nil || IsNil(o.Reference) { + return nil, false + } + return o.Reference, true +} + +// HasReference returns a boolean if a field has been set. +func (o *ExpenseResultInstance) HasReference() bool { + if o != nil && !IsNil(o.Reference) { + return true + } + + return false +} + +// SetReference gets a reference to the given string and assigns it to the Reference field. +func (o *ExpenseResultInstance) SetReference(v string) { + o.Reference = &v +} + +// GetResources returns the Resources field value if set, zero value otherwise. +func (o *ExpenseResultInstance) GetResources() InstanceResources { + if o == nil || IsNil(o.Resources) { + var ret InstanceResources + return ret + } + return *o.Resources +} + +// GetResourcesOk returns a tuple with the Resources field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ExpenseResultInstance) GetResourcesOk() (*InstanceResources, bool) { + if o == nil || IsNil(o.Resources) { + return nil, false + } + return o.Resources, true +} + +// HasResources returns a boolean if a field has been set. +func (o *ExpenseResultInstance) HasResources() bool { + if o != nil && !IsNil(o.Resources) { + return true + } + + return false +} + +// SetResources gets a reference to the given InstanceResources and assigns it to the Resources field. +func (o *ExpenseResultInstance) SetResources(v InstanceResources) { + o.Resources = &v +} + +// GetContractType returns the ContractType field value if set, zero value otherwise. +func (o *ExpenseResultInstance) GetContractType() string { + if o == nil || IsNil(o.ContractType) { + var ret string + return ret + } + return *o.ContractType +} + +// GetContractTypeOk returns a tuple with the ContractType field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ExpenseResultInstance) GetContractTypeOk() (*string, bool) { + if o == nil || IsNil(o.ContractType) { + return nil, false + } + return o.ContractType, true +} + +// HasContractType returns a boolean if a field has been set. +func (o *ExpenseResultInstance) HasContractType() bool { + if o != nil && !IsNil(o.ContractType) { + return true + } + + return false +} + +// SetContractType gets a reference to the given string and assigns it to the ContractType field. +func (o *ExpenseResultInstance) SetContractType(v string) { + o.ContractType = &v +} + +// GetContractCreatedAt returns the ContractCreatedAt field value if set, zero value otherwise. +func (o *ExpenseResultInstance) GetContractCreatedAt() time.Time { + if o == nil || IsNil(o.ContractCreatedAt) { + var ret time.Time + return ret + } + return *o.ContractCreatedAt +} + +// GetContractCreatedAtOk returns a tuple with the ContractCreatedAt field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ExpenseResultInstance) GetContractCreatedAtOk() (*time.Time, bool) { + if o == nil || IsNil(o.ContractCreatedAt) { + return nil, false + } + return o.ContractCreatedAt, true +} + +// HasContractCreatedAt returns a boolean if a field has been set. +func (o *ExpenseResultInstance) HasContractCreatedAt() bool { + if o != nil && !IsNil(o.ContractCreatedAt) { + return true + } + + return false +} + +// SetContractCreatedAt gets a reference to the given time.Time and assigns it to the ContractCreatedAt field. +func (o *ExpenseResultInstance) SetContractCreatedAt(v time.Time) { + o.ContractCreatedAt = &v +} + +// GetStartedAt returns the StartedAt field value if set, zero value otherwise. +func (o *ExpenseResultInstance) GetStartedAt() time.Time { + if o == nil || IsNil(o.StartedAt) { + var ret time.Time + return ret + } + return *o.StartedAt +} + +// GetStartedAtOk returns a tuple with the StartedAt field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ExpenseResultInstance) GetStartedAtOk() (*time.Time, bool) { + if o == nil || IsNil(o.StartedAt) { + return nil, false + } + return o.StartedAt, true +} + +// HasStartedAt returns a boolean if a field has been set. +func (o *ExpenseResultInstance) HasStartedAt() bool { + if o != nil && !IsNil(o.StartedAt) { + return true + } + + return false +} + +// SetStartedAt gets a reference to the given time.Time and assigns it to the StartedAt field. +func (o *ExpenseResultInstance) SetStartedAt(v time.Time) { + o.StartedAt = &v +} + +// GetContractTerm returns the ContractTerm field value if set, zero value otherwise. +func (o *ExpenseResultInstance) GetContractTerm() int32 { + if o == nil || IsNil(o.ContractTerm) { + var ret int32 + return ret + } + return *o.ContractTerm +} + +// GetContractTermOk returns a tuple with the ContractTerm field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ExpenseResultInstance) GetContractTermOk() (*int32, bool) { + if o == nil || IsNil(o.ContractTerm) { + return nil, false + } + return o.ContractTerm, true +} + +// HasContractTerm returns a boolean if a field has been set. +func (o *ExpenseResultInstance) HasContractTerm() bool { + if o != nil && !IsNil(o.ContractTerm) { + return true + } + + return false +} + +// SetContractTerm gets a reference to the given int32 and assigns it to the ContractTerm field. +func (o *ExpenseResultInstance) SetContractTerm(v int32) { + o.ContractTerm = &v +} + +// GetBillingFrequency returns the BillingFrequency field value if set, zero value otherwise. +func (o *ExpenseResultInstance) GetBillingFrequency() int32 { + if o == nil || IsNil(o.BillingFrequency) { + var ret int32 + return ret + } + return *o.BillingFrequency +} + +// GetBillingFrequencyOk returns a tuple with the BillingFrequency field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ExpenseResultInstance) GetBillingFrequencyOk() (*int32, bool) { + if o == nil || IsNil(o.BillingFrequency) { + return nil, false + } + return o.BillingFrequency, true +} + +// HasBillingFrequency returns a boolean if a field has been set. +func (o *ExpenseResultInstance) HasBillingFrequency() bool { + if o != nil && !IsNil(o.BillingFrequency) { + return true + } + + return false +} + +// SetBillingFrequency gets a reference to the given int32 and assigns it to the BillingFrequency field. +func (o *ExpenseResultInstance) SetBillingFrequency(v int32) { + o.BillingFrequency = &v +} + +// GetRootDiskSize returns the RootDiskSize field value if set, zero value otherwise. +func (o *ExpenseResultInstance) GetRootDiskSize() int32 { + if o == nil || IsNil(o.RootDiskSize) { + var ret int32 + return ret + } + return *o.RootDiskSize +} + +// GetRootDiskSizeOk returns a tuple with the RootDiskSize field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ExpenseResultInstance) GetRootDiskSizeOk() (*int32, bool) { + if o == nil || IsNil(o.RootDiskSize) { + return nil, false + } + return o.RootDiskSize, true +} + +// HasRootDiskSize returns a boolean if a field has been set. +func (o *ExpenseResultInstance) HasRootDiskSize() bool { + if o != nil && !IsNil(o.RootDiskSize) { + return true + } + + return false +} + +// SetRootDiskSize gets a reference to the given int32 and assigns it to the RootDiskSize field. +func (o *ExpenseResultInstance) SetRootDiskSize(v int32) { + o.RootDiskSize = &v +} + +// GetRootDiskType returns the RootDiskType field value if set, zero value otherwise. +func (o *ExpenseResultInstance) GetRootDiskType() string { + if o == nil || IsNil(o.RootDiskType) { + var ret string + return ret + } + return *o.RootDiskType +} + +// GetRootDiskTypeOk returns a tuple with the RootDiskType field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ExpenseResultInstance) GetRootDiskTypeOk() (*string, bool) { + if o == nil || IsNil(o.RootDiskType) { + return nil, false + } + return o.RootDiskType, true +} + +// HasRootDiskType returns a boolean if a field has been set. +func (o *ExpenseResultInstance) HasRootDiskType() bool { + if o != nil && !IsNil(o.RootDiskType) { + return true + } + + return false +} + +// SetRootDiskType gets a reference to the given string and assigns it to the RootDiskType field. +func (o *ExpenseResultInstance) SetRootDiskType(v string) { + o.RootDiskType = &v +} + +// GetBillingType returns the BillingType field value if set, zero value otherwise. +func (o *ExpenseResultInstance) GetBillingType() string { + if o == nil || IsNil(o.BillingType) { + var ret string + return ret + } + return *o.BillingType +} + +// GetBillingTypeOk returns a tuple with the BillingType field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ExpenseResultInstance) GetBillingTypeOk() (*string, bool) { + if o == nil || IsNil(o.BillingType) { + return nil, false + } + return o.BillingType, true +} + +// HasBillingType returns a boolean if a field has been set. +func (o *ExpenseResultInstance) HasBillingType() bool { + if o != nil && !IsNil(o.BillingType) { + return true + } + + return false +} + +// SetBillingType gets a reference to the given string and assigns it to the BillingType field. +func (o *ExpenseResultInstance) SetBillingType(v string) { + o.BillingType = &v +} + +// GetHours returns the Hours field value if set, zero value otherwise. +func (o *ExpenseResultInstance) GetHours() int32 { + if o == nil || IsNil(o.Hours) { + var ret int32 + return ret + } + return *o.Hours +} + +// GetHoursOk returns a tuple with the Hours field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ExpenseResultInstance) GetHoursOk() (*int32, bool) { + if o == nil || IsNil(o.Hours) { + return nil, false + } + return o.Hours, true +} + +// HasHours returns a boolean if a field has been set. +func (o *ExpenseResultInstance) HasHours() bool { + if o != nil && !IsNil(o.Hours) { + return true + } + + return false +} + +// SetHours gets a reference to the given int32 and assigns it to the Hours field. +func (o *ExpenseResultInstance) SetHours(v int32) { + o.Hours = &v +} + +// GetFrom returns the From field value if set, zero value otherwise. +func (o *ExpenseResultInstance) GetFrom() time.Time { + if o == nil || IsNil(o.From) { + var ret time.Time + return ret + } + return *o.From +} + +// GetFromOk returns a tuple with the From field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ExpenseResultInstance) GetFromOk() (*time.Time, bool) { + if o == nil || IsNil(o.From) { + return nil, false + } + return o.From, true +} + +// HasFrom returns a boolean if a field has been set. +func (o *ExpenseResultInstance) HasFrom() bool { + if o != nil && !IsNil(o.From) { + return true + } + + return false +} + +// SetFrom gets a reference to the given time.Time and assigns it to the From field. +func (o *ExpenseResultInstance) SetFrom(v time.Time) { + o.From = &v +} + +// GetTo returns the To field value if set, zero value otherwise. +func (o *ExpenseResultInstance) GetTo() time.Time { + if o == nil || IsNil(o.To) { + var ret time.Time + return ret + } + return *o.To +} + +// GetToOk returns a tuple with the To field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ExpenseResultInstance) GetToOk() (*time.Time, bool) { + if o == nil || IsNil(o.To) { + return nil, false + } + return o.To, true +} + +// HasTo returns a boolean if a field has been set. +func (o *ExpenseResultInstance) HasTo() bool { + if o != nil && !IsNil(o.To) { + return true + } + + return false +} + +// SetTo gets a reference to the given time.Time and assigns it to the To field. +func (o *ExpenseResultInstance) SetTo(v time.Time) { + o.To = &v +} + +// GetPrice returns the Price field value if set, zero value otherwise. +func (o *ExpenseResultInstance) GetPrice() string { + if o == nil || IsNil(o.Price) { + var ret string + return ret + } + return *o.Price +} + +// GetPriceOk returns a tuple with the Price field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ExpenseResultInstance) GetPriceOk() (*string, bool) { + if o == nil || IsNil(o.Price) { + return nil, false + } + return o.Price, true +} + +// HasPrice returns a boolean if a field has been set. +func (o *ExpenseResultInstance) HasPrice() bool { + if o != nil && !IsNil(o.Price) { + return true + } + + return false +} + +// SetPrice gets a reference to the given string and assigns it to the Price field. +func (o *ExpenseResultInstance) SetPrice(v string) { + o.Price = &v +} + +func (o ExpenseResultInstance) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o ExpenseResultInstance) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Id) { + toSerialize["id"] = o.Id + } + if !IsNil(o.Reference) { + toSerialize["reference"] = o.Reference + } + if !IsNil(o.Resources) { + toSerialize["resources"] = o.Resources + } + if !IsNil(o.ContractType) { + toSerialize["contractType"] = o.ContractType + } + if !IsNil(o.ContractCreatedAt) { + toSerialize["contractCreatedAt"] = o.ContractCreatedAt + } + if !IsNil(o.StartedAt) { + toSerialize["startedAt"] = o.StartedAt + } + if !IsNil(o.ContractTerm) { + toSerialize["contractTerm"] = o.ContractTerm + } + if !IsNil(o.BillingFrequency) { + toSerialize["billingFrequency"] = o.BillingFrequency + } + if !IsNil(o.RootDiskSize) { + toSerialize["rootDiskSize"] = o.RootDiskSize + } + if !IsNil(o.RootDiskType) { + toSerialize["rootDiskType"] = o.RootDiskType + } + if !IsNil(o.BillingType) { + toSerialize["billingType"] = o.BillingType + } + if !IsNil(o.Hours) { + toSerialize["hours"] = o.Hours + } + if !IsNil(o.From) { + toSerialize["from"] = o.From + } + if !IsNil(o.To) { + toSerialize["to"] = o.To + } + if !IsNil(o.Price) { + toSerialize["price"] = o.Price + } + return toSerialize, nil +} + +type NullableExpenseResultInstance struct { + value *ExpenseResultInstance + isSet bool +} + +func (v NullableExpenseResultInstance) Get() *ExpenseResultInstance { + return v.value +} + +func (v *NullableExpenseResultInstance) Set(val *ExpenseResultInstance) { + v.value = val + v.isSet = true +} + +func (v NullableExpenseResultInstance) IsSet() bool { + return v.isSet +} + +func (v *NullableExpenseResultInstance) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableExpenseResultInstance(val *ExpenseResultInstance) *NullableExpenseResultInstance { + return &NullableExpenseResultInstance{value: val, isSet: true} +} + +func (v NullableExpenseResultInstance) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableExpenseResultInstance) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/publicCloud/model_failed_rule.go b/publicCloud/model_failed_rule.go new file mode 100644 index 0000000..ee3a137 --- /dev/null +++ b/publicCloud/model_failed_rule.go @@ -0,0 +1,163 @@ +/* +LeaseWeb API for launching and managing Public Cloud instances + +> The base URL for this API is: **https://api.leaseweb.com/publicCloud/v1/_** This API provides ways to launch and manage Public Cloud instances.
BETA
This API is in BETA. Documentation might be incorrect or incomplete. Functionality might change with the final release.> + +API version: v1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package publicCloud + +import ( + "encoding/json" +) + +// checks if the FailedRule type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &FailedRule{} + +// FailedRule struct for FailedRule +type FailedRule struct { + Id *string `json:"id,omitempty"` + // The reason which the edition has failed + Message *string `json:"message,omitempty"` +} + +// NewFailedRule instantiates a new FailedRule object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewFailedRule() *FailedRule { + this := FailedRule{} + return &this +} + +// NewFailedRuleWithDefaults instantiates a new FailedRule object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewFailedRuleWithDefaults() *FailedRule { + this := FailedRule{} + return &this +} + +// GetId returns the Id field value if set, zero value otherwise. +func (o *FailedRule) GetId() string { + if o == nil || IsNil(o.Id) { + var ret string + return ret + } + return *o.Id +} + +// GetIdOk returns a tuple with the Id field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *FailedRule) GetIdOk() (*string, bool) { + if o == nil || IsNil(o.Id) { + return nil, false + } + return o.Id, true +} + +// HasId returns a boolean if a field has been set. +func (o *FailedRule) HasId() bool { + if o != nil && !IsNil(o.Id) { + return true + } + + return false +} + +// SetId gets a reference to the given string and assigns it to the Id field. +func (o *FailedRule) SetId(v string) { + o.Id = &v +} + +// GetMessage returns the Message field value if set, zero value otherwise. +func (o *FailedRule) GetMessage() string { + if o == nil || IsNil(o.Message) { + var ret string + return ret + } + return *o.Message +} + +// GetMessageOk returns a tuple with the Message field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *FailedRule) GetMessageOk() (*string, bool) { + if o == nil || IsNil(o.Message) { + return nil, false + } + return o.Message, true +} + +// HasMessage returns a boolean if a field has been set. +func (o *FailedRule) HasMessage() bool { + if o != nil && !IsNil(o.Message) { + return true + } + + return false +} + +// SetMessage gets a reference to the given string and assigns it to the Message field. +func (o *FailedRule) SetMessage(v string) { + o.Message = &v +} + +func (o FailedRule) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o FailedRule) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Id) { + toSerialize["id"] = o.Id + } + if !IsNil(o.Message) { + toSerialize["message"] = o.Message + } + return toSerialize, nil +} + +type NullableFailedRule struct { + value *FailedRule + isSet bool +} + +func (v NullableFailedRule) Get() *FailedRule { + return v.value +} + +func (v *NullableFailedRule) Set(val *FailedRule) { + v.value = val + v.isSet = true +} + +func (v NullableFailedRule) IsSet() bool { + return v.isSet +} + +func (v *NullableFailedRule) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableFailedRule(val *FailedRule) *NullableFailedRule { + return &NullableFailedRule{value: val, isSet: true} +} + +func (v NullableFailedRule) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableFailedRule) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/publicCloud/model_firewall_rule.go b/publicCloud/model_firewall_rule.go new file mode 100644 index 0000000..3faaac7 --- /dev/null +++ b/publicCloud/model_firewall_rule.go @@ -0,0 +1,400 @@ +/* +LeaseWeb API for launching and managing Public Cloud instances + +> The base URL for this API is: **https://api.leaseweb.com/publicCloud/v1/_** This API provides ways to launch and manage Public Cloud instances.
BETA
This API is in BETA. Documentation might be incorrect or incomplete. Functionality might change with the final release.> + +API version: v1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package publicCloud + +import ( + "encoding/json" + "bytes" + "fmt" +) + +// checks if the FirewallRule type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &FirewallRule{} + +// FirewallRule struct for FirewallRule +type FirewallRule struct { + Protocol *string `json:"protocol,omitempty"` + StartPort NullableInt32 `json:"startPort"` + EndPort NullableInt32 `json:"endPort"` + IcmpType int32 `json:"icmpType"` + IcmpCode int32 `json:"icmpCode"` + Id *string `json:"id,omitempty"` + Name NullableString `json:"name,omitempty"` + Cidr *string `json:"cidr,omitempty"` +} + +type _FirewallRule FirewallRule + +// NewFirewallRule instantiates a new FirewallRule object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewFirewallRule(startPort NullableInt32, endPort NullableInt32, icmpType int32, icmpCode int32) *FirewallRule { + this := FirewallRule{} + this.StartPort = startPort + this.EndPort = endPort + this.IcmpType = icmpType + this.IcmpCode = icmpCode + return &this +} + +// NewFirewallRuleWithDefaults instantiates a new FirewallRule object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewFirewallRuleWithDefaults() *FirewallRule { + this := FirewallRule{} + return &this +} + +// GetProtocol returns the Protocol field value if set, zero value otherwise. +func (o *FirewallRule) GetProtocol() string { + if o == nil || IsNil(o.Protocol) { + var ret string + return ret + } + return *o.Protocol +} + +// GetProtocolOk returns a tuple with the Protocol field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *FirewallRule) GetProtocolOk() (*string, bool) { + if o == nil || IsNil(o.Protocol) { + return nil, false + } + return o.Protocol, true +} + +// HasProtocol returns a boolean if a field has been set. +func (o *FirewallRule) HasProtocol() bool { + if o != nil && !IsNil(o.Protocol) { + return true + } + + return false +} + +// SetProtocol gets a reference to the given string and assigns it to the Protocol field. +func (o *FirewallRule) SetProtocol(v string) { + o.Protocol = &v +} + +// GetStartPort returns the StartPort field value +// If the value is explicit nil, the zero value for int32 will be returned +func (o *FirewallRule) GetStartPort() int32 { + if o == nil || o.StartPort.Get() == nil { + var ret int32 + return ret + } + + return *o.StartPort.Get() +} + +// GetStartPortOk returns a tuple with the StartPort field value +// and a boolean to check if the value has been set. +// NOTE: If the value is an explicit nil, `nil, true` will be returned +func (o *FirewallRule) GetStartPortOk() (*int32, bool) { + if o == nil { + return nil, false + } + return o.StartPort.Get(), o.StartPort.IsSet() +} + +// SetStartPort sets field value +func (o *FirewallRule) SetStartPort(v int32) { + o.StartPort.Set(&v) +} + +// GetEndPort returns the EndPort field value +// If the value is explicit nil, the zero value for int32 will be returned +func (o *FirewallRule) GetEndPort() int32 { + if o == nil || o.EndPort.Get() == nil { + var ret int32 + return ret + } + + return *o.EndPort.Get() +} + +// GetEndPortOk returns a tuple with the EndPort field value +// and a boolean to check if the value has been set. +// NOTE: If the value is an explicit nil, `nil, true` will be returned +func (o *FirewallRule) GetEndPortOk() (*int32, bool) { + if o == nil { + return nil, false + } + return o.EndPort.Get(), o.EndPort.IsSet() +} + +// SetEndPort sets field value +func (o *FirewallRule) SetEndPort(v int32) { + o.EndPort.Set(&v) +} + +// GetIcmpType returns the IcmpType field value +func (o *FirewallRule) GetIcmpType() int32 { + if o == nil { + var ret int32 + return ret + } + + return o.IcmpType +} + +// GetIcmpTypeOk returns a tuple with the IcmpType field value +// and a boolean to check if the value has been set. +func (o *FirewallRule) GetIcmpTypeOk() (*int32, bool) { + if o == nil { + return nil, false + } + return &o.IcmpType, true +} + +// SetIcmpType sets field value +func (o *FirewallRule) SetIcmpType(v int32) { + o.IcmpType = v +} + +// GetIcmpCode returns the IcmpCode field value +func (o *FirewallRule) GetIcmpCode() int32 { + if o == nil { + var ret int32 + return ret + } + + return o.IcmpCode +} + +// GetIcmpCodeOk returns a tuple with the IcmpCode field value +// and a boolean to check if the value has been set. +func (o *FirewallRule) GetIcmpCodeOk() (*int32, bool) { + if o == nil { + return nil, false + } + return &o.IcmpCode, true +} + +// SetIcmpCode sets field value +func (o *FirewallRule) SetIcmpCode(v int32) { + o.IcmpCode = v +} + +// GetId returns the Id field value if set, zero value otherwise. +func (o *FirewallRule) GetId() string { + if o == nil || IsNil(o.Id) { + var ret string + return ret + } + return *o.Id +} + +// GetIdOk returns a tuple with the Id field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *FirewallRule) GetIdOk() (*string, bool) { + if o == nil || IsNil(o.Id) { + return nil, false + } + return o.Id, true +} + +// HasId returns a boolean if a field has been set. +func (o *FirewallRule) HasId() bool { + if o != nil && !IsNil(o.Id) { + return true + } + + return false +} + +// SetId gets a reference to the given string and assigns it to the Id field. +func (o *FirewallRule) SetId(v string) { + o.Id = &v +} + +// GetName returns the Name field value if set, zero value otherwise (both if not set or set to explicit null). +func (o *FirewallRule) GetName() string { + if o == nil || IsNil(o.Name.Get()) { + var ret string + return ret + } + return *o.Name.Get() +} + +// GetNameOk returns a tuple with the Name field value if set, nil otherwise +// and a boolean to check if the value has been set. +// NOTE: If the value is an explicit nil, `nil, true` will be returned +func (o *FirewallRule) GetNameOk() (*string, bool) { + if o == nil { + return nil, false + } + return o.Name.Get(), o.Name.IsSet() +} + +// HasName returns a boolean if a field has been set. +func (o *FirewallRule) HasName() bool { + if o != nil && o.Name.IsSet() { + return true + } + + return false +} + +// SetName gets a reference to the given NullableString and assigns it to the Name field. +func (o *FirewallRule) SetName(v string) { + o.Name.Set(&v) +} +// SetNameNil sets the value for Name to be an explicit nil +func (o *FirewallRule) SetNameNil() { + o.Name.Set(nil) +} + +// UnsetName ensures that no value is present for Name, not even an explicit nil +func (o *FirewallRule) UnsetName() { + o.Name.Unset() +} + +// GetCidr returns the Cidr field value if set, zero value otherwise. +func (o *FirewallRule) GetCidr() string { + if o == nil || IsNil(o.Cidr) { + var ret string + return ret + } + return *o.Cidr +} + +// GetCidrOk returns a tuple with the Cidr field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *FirewallRule) GetCidrOk() (*string, bool) { + if o == nil || IsNil(o.Cidr) { + return nil, false + } + return o.Cidr, true +} + +// HasCidr returns a boolean if a field has been set. +func (o *FirewallRule) HasCidr() bool { + if o != nil && !IsNil(o.Cidr) { + return true + } + + return false +} + +// SetCidr gets a reference to the given string and assigns it to the Cidr field. +func (o *FirewallRule) SetCidr(v string) { + o.Cidr = &v +} + +func (o FirewallRule) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o FirewallRule) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Protocol) { + toSerialize["protocol"] = o.Protocol + } + toSerialize["startPort"] = o.StartPort.Get() + toSerialize["endPort"] = o.EndPort.Get() + toSerialize["icmpType"] = o.IcmpType + toSerialize["icmpCode"] = o.IcmpCode + if !IsNil(o.Id) { + toSerialize["id"] = o.Id + } + if o.Name.IsSet() { + toSerialize["name"] = o.Name.Get() + } + if !IsNil(o.Cidr) { + toSerialize["cidr"] = o.Cidr + } + return toSerialize, nil +} + +func (o *FirewallRule) UnmarshalJSON(data []byte) (err error) { + // This validates that all required properties are included in the JSON object + // by unmarshalling the object into a generic map with string keys and checking + // that every required field exists as a key in the generic map. + requiredProperties := []string{ + "startPort", + "endPort", + "icmpType", + "icmpCode", + } + + allProperties := make(map[string]interface{}) + + err = json.Unmarshal(data, &allProperties) + + if err != nil { + return err; + } + + for _, requiredProperty := range(requiredProperties) { + if _, exists := allProperties[requiredProperty]; !exists { + return fmt.Errorf("no value given for required property %v", requiredProperty) + } + } + + varFirewallRule := _FirewallRule{} + + decoder := json.NewDecoder(bytes.NewReader(data)) + decoder.DisallowUnknownFields() + err = decoder.Decode(&varFirewallRule) + + if err != nil { + return err + } + + *o = FirewallRule(varFirewallRule) + + return err +} + +type NullableFirewallRule struct { + value *FirewallRule + isSet bool +} + +func (v NullableFirewallRule) Get() *FirewallRule { + return v.value +} + +func (v *NullableFirewallRule) Set(val *FirewallRule) { + v.value = val + v.isSet = true +} + +func (v NullableFirewallRule) IsSet() bool { + return v.isSet +} + +func (v *NullableFirewallRule) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableFirewallRule(val *FirewallRule) *NullableFirewallRule { + return &NullableFirewallRule{value: val, isSet: true} +} + +func (v NullableFirewallRule) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableFirewallRule) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/publicCloud/model_get_console_access_to_instance_result.go b/publicCloud/model_get_console_access_to_instance_result.go new file mode 100644 index 0000000..d276f59 --- /dev/null +++ b/publicCloud/model_get_console_access_to_instance_result.go @@ -0,0 +1,127 @@ +/* +LeaseWeb API for launching and managing Public Cloud instances + +> The base URL for this API is: **https://api.leaseweb.com/publicCloud/v1/_** This API provides ways to launch and manage Public Cloud instances.
BETA
This API is in BETA. Documentation might be incorrect or incomplete. Functionality might change with the final release.> + +API version: v1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package publicCloud + +import ( + "encoding/json" +) + +// checks if the GetConsoleAccessToInstanceResult type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &GetConsoleAccessToInstanceResult{} + +// GetConsoleAccessToInstanceResult struct for GetConsoleAccessToInstanceResult +type GetConsoleAccessToInstanceResult struct { + // The URL to the console + Url *string `json:"url,omitempty"` +} + +// NewGetConsoleAccessToInstanceResult instantiates a new GetConsoleAccessToInstanceResult object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewGetConsoleAccessToInstanceResult() *GetConsoleAccessToInstanceResult { + this := GetConsoleAccessToInstanceResult{} + return &this +} + +// NewGetConsoleAccessToInstanceResultWithDefaults instantiates a new GetConsoleAccessToInstanceResult object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewGetConsoleAccessToInstanceResultWithDefaults() *GetConsoleAccessToInstanceResult { + this := GetConsoleAccessToInstanceResult{} + return &this +} + +// GetUrl returns the Url field value if set, zero value otherwise. +func (o *GetConsoleAccessToInstanceResult) GetUrl() string { + if o == nil || IsNil(o.Url) { + var ret string + return ret + } + return *o.Url +} + +// GetUrlOk returns a tuple with the Url field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetConsoleAccessToInstanceResult) GetUrlOk() (*string, bool) { + if o == nil || IsNil(o.Url) { + return nil, false + } + return o.Url, true +} + +// HasUrl returns a boolean if a field has been set. +func (o *GetConsoleAccessToInstanceResult) HasUrl() bool { + if o != nil && !IsNil(o.Url) { + return true + } + + return false +} + +// SetUrl gets a reference to the given string and assigns it to the Url field. +func (o *GetConsoleAccessToInstanceResult) SetUrl(v string) { + o.Url = &v +} + +func (o GetConsoleAccessToInstanceResult) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o GetConsoleAccessToInstanceResult) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Url) { + toSerialize["url"] = o.Url + } + return toSerialize, nil +} + +type NullableGetConsoleAccessToInstanceResult struct { + value *GetConsoleAccessToInstanceResult + isSet bool +} + +func (v NullableGetConsoleAccessToInstanceResult) Get() *GetConsoleAccessToInstanceResult { + return v.value +} + +func (v *NullableGetConsoleAccessToInstanceResult) Set(val *GetConsoleAccessToInstanceResult) { + v.value = val + v.isSet = true +} + +func (v NullableGetConsoleAccessToInstanceResult) IsSet() bool { + return v.isSet +} + +func (v *NullableGetConsoleAccessToInstanceResult) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableGetConsoleAccessToInstanceResult(val *GetConsoleAccessToInstanceResult) *NullableGetConsoleAccessToInstanceResult { + return &NullableGetConsoleAccessToInstanceResult{value: val, isSet: true} +} + +func (v NullableGetConsoleAccessToInstanceResult) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableGetConsoleAccessToInstanceResult) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/publicCloud/model_get_credential_list_by_type_result.go b/publicCloud/model_get_credential_list_by_type_result.go new file mode 100644 index 0000000..e12b4f1 --- /dev/null +++ b/publicCloud/model_get_credential_list_by_type_result.go @@ -0,0 +1,162 @@ +/* +LeaseWeb API for launching and managing Public Cloud instances + +> The base URL for this API is: **https://api.leaseweb.com/publicCloud/v1/_** This API provides ways to launch and manage Public Cloud instances.
BETA
This API is in BETA. Documentation might be incorrect or incomplete. Functionality might change with the final release.> + +API version: v1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package publicCloud + +import ( + "encoding/json" +) + +// checks if the GetCredentialListByTypeResult type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &GetCredentialListByTypeResult{} + +// GetCredentialListByTypeResult struct for GetCredentialListByTypeResult +type GetCredentialListByTypeResult struct { + Credentials []Credential `json:"credentials,omitempty"` + Metadata *Metadata `json:"_metadata,omitempty"` +} + +// NewGetCredentialListByTypeResult instantiates a new GetCredentialListByTypeResult object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewGetCredentialListByTypeResult() *GetCredentialListByTypeResult { + this := GetCredentialListByTypeResult{} + return &this +} + +// NewGetCredentialListByTypeResultWithDefaults instantiates a new GetCredentialListByTypeResult object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewGetCredentialListByTypeResultWithDefaults() *GetCredentialListByTypeResult { + this := GetCredentialListByTypeResult{} + return &this +} + +// GetCredentials returns the Credentials field value if set, zero value otherwise. +func (o *GetCredentialListByTypeResult) GetCredentials() []Credential { + if o == nil || IsNil(o.Credentials) { + var ret []Credential + return ret + } + return o.Credentials +} + +// GetCredentialsOk returns a tuple with the Credentials field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetCredentialListByTypeResult) GetCredentialsOk() ([]Credential, bool) { + if o == nil || IsNil(o.Credentials) { + return nil, false + } + return o.Credentials, true +} + +// HasCredentials returns a boolean if a field has been set. +func (o *GetCredentialListByTypeResult) HasCredentials() bool { + if o != nil && !IsNil(o.Credentials) { + return true + } + + return false +} + +// SetCredentials gets a reference to the given []Credential and assigns it to the Credentials field. +func (o *GetCredentialListByTypeResult) SetCredentials(v []Credential) { + o.Credentials = v +} + +// GetMetadata returns the Metadata field value if set, zero value otherwise. +func (o *GetCredentialListByTypeResult) GetMetadata() Metadata { + if o == nil || IsNil(o.Metadata) { + var ret Metadata + return ret + } + return *o.Metadata +} + +// GetMetadataOk returns a tuple with the Metadata field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetCredentialListByTypeResult) GetMetadataOk() (*Metadata, bool) { + if o == nil || IsNil(o.Metadata) { + return nil, false + } + return o.Metadata, true +} + +// HasMetadata returns a boolean if a field has been set. +func (o *GetCredentialListByTypeResult) HasMetadata() bool { + if o != nil && !IsNil(o.Metadata) { + return true + } + + return false +} + +// SetMetadata gets a reference to the given Metadata and assigns it to the Metadata field. +func (o *GetCredentialListByTypeResult) SetMetadata(v Metadata) { + o.Metadata = &v +} + +func (o GetCredentialListByTypeResult) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o GetCredentialListByTypeResult) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Credentials) { + toSerialize["credentials"] = o.Credentials + } + if !IsNil(o.Metadata) { + toSerialize["_metadata"] = o.Metadata + } + return toSerialize, nil +} + +type NullableGetCredentialListByTypeResult struct { + value *GetCredentialListByTypeResult + isSet bool +} + +func (v NullableGetCredentialListByTypeResult) Get() *GetCredentialListByTypeResult { + return v.value +} + +func (v *NullableGetCredentialListByTypeResult) Set(val *GetCredentialListByTypeResult) { + v.value = val + v.isSet = true +} + +func (v NullableGetCredentialListByTypeResult) IsSet() bool { + return v.isSet +} + +func (v *NullableGetCredentialListByTypeResult) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableGetCredentialListByTypeResult(val *GetCredentialListByTypeResult) *NullableGetCredentialListByTypeResult { + return &NullableGetCredentialListByTypeResult{value: val, isSet: true} +} + +func (v NullableGetCredentialListByTypeResult) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableGetCredentialListByTypeResult) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/publicCloud/model_get_credential_list_result.go b/publicCloud/model_get_credential_list_result.go new file mode 100644 index 0000000..2d379f8 --- /dev/null +++ b/publicCloud/model_get_credential_list_result.go @@ -0,0 +1,162 @@ +/* +LeaseWeb API for launching and managing Public Cloud instances + +> The base URL for this API is: **https://api.leaseweb.com/publicCloud/v1/_** This API provides ways to launch and manage Public Cloud instances.
BETA
This API is in BETA. Documentation might be incorrect or incomplete. Functionality might change with the final release.> + +API version: v1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package publicCloud + +import ( + "encoding/json" +) + +// checks if the GetCredentialListResult type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &GetCredentialListResult{} + +// GetCredentialListResult struct for GetCredentialListResult +type GetCredentialListResult struct { + Credentials []Credential `json:"credentials,omitempty"` + Metadata *Metadata `json:"_metadata,omitempty"` +} + +// NewGetCredentialListResult instantiates a new GetCredentialListResult object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewGetCredentialListResult() *GetCredentialListResult { + this := GetCredentialListResult{} + return &this +} + +// NewGetCredentialListResultWithDefaults instantiates a new GetCredentialListResult object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewGetCredentialListResultWithDefaults() *GetCredentialListResult { + this := GetCredentialListResult{} + return &this +} + +// GetCredentials returns the Credentials field value if set, zero value otherwise. +func (o *GetCredentialListResult) GetCredentials() []Credential { + if o == nil || IsNil(o.Credentials) { + var ret []Credential + return ret + } + return o.Credentials +} + +// GetCredentialsOk returns a tuple with the Credentials field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetCredentialListResult) GetCredentialsOk() ([]Credential, bool) { + if o == nil || IsNil(o.Credentials) { + return nil, false + } + return o.Credentials, true +} + +// HasCredentials returns a boolean if a field has been set. +func (o *GetCredentialListResult) HasCredentials() bool { + if o != nil && !IsNil(o.Credentials) { + return true + } + + return false +} + +// SetCredentials gets a reference to the given []Credential and assigns it to the Credentials field. +func (o *GetCredentialListResult) SetCredentials(v []Credential) { + o.Credentials = v +} + +// GetMetadata returns the Metadata field value if set, zero value otherwise. +func (o *GetCredentialListResult) GetMetadata() Metadata { + if o == nil || IsNil(o.Metadata) { + var ret Metadata + return ret + } + return *o.Metadata +} + +// GetMetadataOk returns a tuple with the Metadata field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetCredentialListResult) GetMetadataOk() (*Metadata, bool) { + if o == nil || IsNil(o.Metadata) { + return nil, false + } + return o.Metadata, true +} + +// HasMetadata returns a boolean if a field has been set. +func (o *GetCredentialListResult) HasMetadata() bool { + if o != nil && !IsNil(o.Metadata) { + return true + } + + return false +} + +// SetMetadata gets a reference to the given Metadata and assigns it to the Metadata field. +func (o *GetCredentialListResult) SetMetadata(v Metadata) { + o.Metadata = &v +} + +func (o GetCredentialListResult) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o GetCredentialListResult) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Credentials) { + toSerialize["credentials"] = o.Credentials + } + if !IsNil(o.Metadata) { + toSerialize["_metadata"] = o.Metadata + } + return toSerialize, nil +} + +type NullableGetCredentialListResult struct { + value *GetCredentialListResult + isSet bool +} + +func (v NullableGetCredentialListResult) Get() *GetCredentialListResult { + return v.value +} + +func (v *NullableGetCredentialListResult) Set(val *GetCredentialListResult) { + v.value = val + v.isSet = true +} + +func (v NullableGetCredentialListResult) IsSet() bool { + return v.isSet +} + +func (v *NullableGetCredentialListResult) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableGetCredentialListResult(val *GetCredentialListResult) *NullableGetCredentialListResult { + return &NullableGetCredentialListResult{value: val, isSet: true} +} + +func (v NullableGetCredentialListResult) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableGetCredentialListResult) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/publicCloud/model_get_credential_result.go b/publicCloud/model_get_credential_result.go new file mode 100644 index 0000000..3faf492 --- /dev/null +++ b/publicCloud/model_get_credential_result.go @@ -0,0 +1,198 @@ +/* +LeaseWeb API for launching and managing Public Cloud instances + +> The base URL for this API is: **https://api.leaseweb.com/publicCloud/v1/_** This API provides ways to launch and manage Public Cloud instances.
BETA
This API is in BETA. Documentation might be incorrect or incomplete. Functionality might change with the final release.> + +API version: v1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package publicCloud + +import ( + "encoding/json" +) + +// checks if the GetCredentialResult type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &GetCredentialResult{} + +// GetCredentialResult struct for GetCredentialResult +type GetCredentialResult struct { + Type *CredentialType `json:"type,omitempty"` + Username *string `json:"username,omitempty"` + Password *string `json:"password,omitempty"` +} + +// NewGetCredentialResult instantiates a new GetCredentialResult object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewGetCredentialResult() *GetCredentialResult { + this := GetCredentialResult{} + return &this +} + +// NewGetCredentialResultWithDefaults instantiates a new GetCredentialResult object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewGetCredentialResultWithDefaults() *GetCredentialResult { + this := GetCredentialResult{} + return &this +} + +// GetType returns the Type field value if set, zero value otherwise. +func (o *GetCredentialResult) GetType() CredentialType { + if o == nil || IsNil(o.Type) { + var ret CredentialType + return ret + } + return *o.Type +} + +// GetTypeOk returns a tuple with the Type field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetCredentialResult) GetTypeOk() (*CredentialType, bool) { + if o == nil || IsNil(o.Type) { + return nil, false + } + return o.Type, true +} + +// HasType returns a boolean if a field has been set. +func (o *GetCredentialResult) HasType() bool { + if o != nil && !IsNil(o.Type) { + return true + } + + return false +} + +// SetType gets a reference to the given CredentialType and assigns it to the Type field. +func (o *GetCredentialResult) SetType(v CredentialType) { + o.Type = &v +} + +// GetUsername returns the Username field value if set, zero value otherwise. +func (o *GetCredentialResult) GetUsername() string { + if o == nil || IsNil(o.Username) { + var ret string + return ret + } + return *o.Username +} + +// GetUsernameOk returns a tuple with the Username field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetCredentialResult) GetUsernameOk() (*string, bool) { + if o == nil || IsNil(o.Username) { + return nil, false + } + return o.Username, true +} + +// HasUsername returns a boolean if a field has been set. +func (o *GetCredentialResult) HasUsername() bool { + if o != nil && !IsNil(o.Username) { + return true + } + + return false +} + +// SetUsername gets a reference to the given string and assigns it to the Username field. +func (o *GetCredentialResult) SetUsername(v string) { + o.Username = &v +} + +// GetPassword returns the Password field value if set, zero value otherwise. +func (o *GetCredentialResult) GetPassword() string { + if o == nil || IsNil(o.Password) { + var ret string + return ret + } + return *o.Password +} + +// GetPasswordOk returns a tuple with the Password field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetCredentialResult) GetPasswordOk() (*string, bool) { + if o == nil || IsNil(o.Password) { + return nil, false + } + return o.Password, true +} + +// HasPassword returns a boolean if a field has been set. +func (o *GetCredentialResult) HasPassword() bool { + if o != nil && !IsNil(o.Password) { + return true + } + + return false +} + +// SetPassword gets a reference to the given string and assigns it to the Password field. +func (o *GetCredentialResult) SetPassword(v string) { + o.Password = &v +} + +func (o GetCredentialResult) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o GetCredentialResult) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Type) { + toSerialize["type"] = o.Type + } + if !IsNil(o.Username) { + toSerialize["username"] = o.Username + } + if !IsNil(o.Password) { + toSerialize["password"] = o.Password + } + return toSerialize, nil +} + +type NullableGetCredentialResult struct { + value *GetCredentialResult + isSet bool +} + +func (v NullableGetCredentialResult) Get() *GetCredentialResult { + return v.value +} + +func (v *NullableGetCredentialResult) Set(val *GetCredentialResult) { + v.value = val + v.isSet = true +} + +func (v NullableGetCredentialResult) IsSet() bool { + return v.isSet +} + +func (v *NullableGetCredentialResult) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableGetCredentialResult(val *GetCredentialResult) *NullableGetCredentialResult { + return &NullableGetCredentialResult{value: val, isSet: true} +} + +func (v NullableGetCredentialResult) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableGetCredentialResult) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/publicCloud/model_get_expenses_result.go b/publicCloud/model_get_expenses_result.go new file mode 100644 index 0000000..48a62a5 --- /dev/null +++ b/publicCloud/model_get_expenses_result.go @@ -0,0 +1,126 @@ +/* +LeaseWeb API for launching and managing Public Cloud instances + +> The base URL for this API is: **https://api.leaseweb.com/publicCloud/v1/_** This API provides ways to launch and manage Public Cloud instances.
BETA
This API is in BETA. Documentation might be incorrect or incomplete. Functionality might change with the final release.> + +API version: v1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package publicCloud + +import ( + "encoding/json" +) + +// checks if the GetExpensesResult type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &GetExpensesResult{} + +// GetExpensesResult struct for GetExpensesResult +type GetExpensesResult struct { + Billing *Billing `json:"billing,omitempty"` +} + +// NewGetExpensesResult instantiates a new GetExpensesResult object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewGetExpensesResult() *GetExpensesResult { + this := GetExpensesResult{} + return &this +} + +// NewGetExpensesResultWithDefaults instantiates a new GetExpensesResult object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewGetExpensesResultWithDefaults() *GetExpensesResult { + this := GetExpensesResult{} + return &this +} + +// GetBilling returns the Billing field value if set, zero value otherwise. +func (o *GetExpensesResult) GetBilling() Billing { + if o == nil || IsNil(o.Billing) { + var ret Billing + return ret + } + return *o.Billing +} + +// GetBillingOk returns a tuple with the Billing field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetExpensesResult) GetBillingOk() (*Billing, bool) { + if o == nil || IsNil(o.Billing) { + return nil, false + } + return o.Billing, true +} + +// HasBilling returns a boolean if a field has been set. +func (o *GetExpensesResult) HasBilling() bool { + if o != nil && !IsNil(o.Billing) { + return true + } + + return false +} + +// SetBilling gets a reference to the given Billing and assigns it to the Billing field. +func (o *GetExpensesResult) SetBilling(v Billing) { + o.Billing = &v +} + +func (o GetExpensesResult) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o GetExpensesResult) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Billing) { + toSerialize["billing"] = o.Billing + } + return toSerialize, nil +} + +type NullableGetExpensesResult struct { + value *GetExpensesResult + isSet bool +} + +func (v NullableGetExpensesResult) Get() *GetExpensesResult { + return v.value +} + +func (v *NullableGetExpensesResult) Set(val *GetExpensesResult) { + v.value = val + v.isSet = true +} + +func (v NullableGetExpensesResult) IsSet() bool { + return v.isSet +} + +func (v *NullableGetExpensesResult) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableGetExpensesResult(val *GetExpensesResult) *NullableGetExpensesResult { + return &NullableGetExpensesResult{value: val, isSet: true} +} + +func (v NullableGetExpensesResult) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableGetExpensesResult) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/publicCloud/model_get_firewall_rule_list_result.go b/publicCloud/model_get_firewall_rule_list_result.go new file mode 100644 index 0000000..abc8048 --- /dev/null +++ b/publicCloud/model_get_firewall_rule_list_result.go @@ -0,0 +1,162 @@ +/* +LeaseWeb API for launching and managing Public Cloud instances + +> The base URL for this API is: **https://api.leaseweb.com/publicCloud/v1/_** This API provides ways to launch and manage Public Cloud instances.
BETA
This API is in BETA. Documentation might be incorrect or incomplete. Functionality might change with the final release.> + +API version: v1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package publicCloud + +import ( + "encoding/json" +) + +// checks if the GetFirewallRuleListResult type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &GetFirewallRuleListResult{} + +// GetFirewallRuleListResult struct for GetFirewallRuleListResult +type GetFirewallRuleListResult struct { + FirewallRules []FirewallRule `json:"firewallRules,omitempty"` + Metadata *Metadata `json:"_metadata,omitempty"` +} + +// NewGetFirewallRuleListResult instantiates a new GetFirewallRuleListResult object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewGetFirewallRuleListResult() *GetFirewallRuleListResult { + this := GetFirewallRuleListResult{} + return &this +} + +// NewGetFirewallRuleListResultWithDefaults instantiates a new GetFirewallRuleListResult object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewGetFirewallRuleListResultWithDefaults() *GetFirewallRuleListResult { + this := GetFirewallRuleListResult{} + return &this +} + +// GetFirewallRules returns the FirewallRules field value if set, zero value otherwise. +func (o *GetFirewallRuleListResult) GetFirewallRules() []FirewallRule { + if o == nil || IsNil(o.FirewallRules) { + var ret []FirewallRule + return ret + } + return o.FirewallRules +} + +// GetFirewallRulesOk returns a tuple with the FirewallRules field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetFirewallRuleListResult) GetFirewallRulesOk() ([]FirewallRule, bool) { + if o == nil || IsNil(o.FirewallRules) { + return nil, false + } + return o.FirewallRules, true +} + +// HasFirewallRules returns a boolean if a field has been set. +func (o *GetFirewallRuleListResult) HasFirewallRules() bool { + if o != nil && !IsNil(o.FirewallRules) { + return true + } + + return false +} + +// SetFirewallRules gets a reference to the given []FirewallRule and assigns it to the FirewallRules field. +func (o *GetFirewallRuleListResult) SetFirewallRules(v []FirewallRule) { + o.FirewallRules = v +} + +// GetMetadata returns the Metadata field value if set, zero value otherwise. +func (o *GetFirewallRuleListResult) GetMetadata() Metadata { + if o == nil || IsNil(o.Metadata) { + var ret Metadata + return ret + } + return *o.Metadata +} + +// GetMetadataOk returns a tuple with the Metadata field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetFirewallRuleListResult) GetMetadataOk() (*Metadata, bool) { + if o == nil || IsNil(o.Metadata) { + return nil, false + } + return o.Metadata, true +} + +// HasMetadata returns a boolean if a field has been set. +func (o *GetFirewallRuleListResult) HasMetadata() bool { + if o != nil && !IsNil(o.Metadata) { + return true + } + + return false +} + +// SetMetadata gets a reference to the given Metadata and assigns it to the Metadata field. +func (o *GetFirewallRuleListResult) SetMetadata(v Metadata) { + o.Metadata = &v +} + +func (o GetFirewallRuleListResult) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o GetFirewallRuleListResult) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.FirewallRules) { + toSerialize["firewallRules"] = o.FirewallRules + } + if !IsNil(o.Metadata) { + toSerialize["_metadata"] = o.Metadata + } + return toSerialize, nil +} + +type NullableGetFirewallRuleListResult struct { + value *GetFirewallRuleListResult + isSet bool +} + +func (v NullableGetFirewallRuleListResult) Get() *GetFirewallRuleListResult { + return v.value +} + +func (v *NullableGetFirewallRuleListResult) Set(val *GetFirewallRuleListResult) { + v.value = val + v.isSet = true +} + +func (v NullableGetFirewallRuleListResult) IsSet() bool { + return v.isSet +} + +func (v *NullableGetFirewallRuleListResult) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableGetFirewallRuleListResult(val *GetFirewallRuleListResult) *NullableGetFirewallRuleListResult { + return &NullableGetFirewallRuleListResult{value: val, isSet: true} +} + +func (v NullableGetFirewallRuleListResult) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableGetFirewallRuleListResult) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/publicCloud/model_get_instance_list_result.go b/publicCloud/model_get_instance_list_result.go new file mode 100644 index 0000000..13486ee --- /dev/null +++ b/publicCloud/model_get_instance_list_result.go @@ -0,0 +1,162 @@ +/* +LeaseWeb API for launching and managing Public Cloud instances + +> The base URL for this API is: **https://api.leaseweb.com/publicCloud/v1/_** This API provides ways to launch and manage Public Cloud instances.
BETA
This API is in BETA. Documentation might be incorrect or incomplete. Functionality might change with the final release.> + +API version: v1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package publicCloud + +import ( + "encoding/json" +) + +// checks if the GetInstanceListResult type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &GetInstanceListResult{} + +// GetInstanceListResult struct for GetInstanceListResult +type GetInstanceListResult struct { + Instances []Instance `json:"instances,omitempty"` + Metadata *Metadata `json:"_metadata,omitempty"` +} + +// NewGetInstanceListResult instantiates a new GetInstanceListResult object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewGetInstanceListResult() *GetInstanceListResult { + this := GetInstanceListResult{} + return &this +} + +// NewGetInstanceListResultWithDefaults instantiates a new GetInstanceListResult object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewGetInstanceListResultWithDefaults() *GetInstanceListResult { + this := GetInstanceListResult{} + return &this +} + +// GetInstances returns the Instances field value if set, zero value otherwise. +func (o *GetInstanceListResult) GetInstances() []Instance { + if o == nil || IsNil(o.Instances) { + var ret []Instance + return ret + } + return o.Instances +} + +// GetInstancesOk returns a tuple with the Instances field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetInstanceListResult) GetInstancesOk() ([]Instance, bool) { + if o == nil || IsNil(o.Instances) { + return nil, false + } + return o.Instances, true +} + +// HasInstances returns a boolean if a field has been set. +func (o *GetInstanceListResult) HasInstances() bool { + if o != nil && !IsNil(o.Instances) { + return true + } + + return false +} + +// SetInstances gets a reference to the given []Instance and assigns it to the Instances field. +func (o *GetInstanceListResult) SetInstances(v []Instance) { + o.Instances = v +} + +// GetMetadata returns the Metadata field value if set, zero value otherwise. +func (o *GetInstanceListResult) GetMetadata() Metadata { + if o == nil || IsNil(o.Metadata) { + var ret Metadata + return ret + } + return *o.Metadata +} + +// GetMetadataOk returns a tuple with the Metadata field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetInstanceListResult) GetMetadataOk() (*Metadata, bool) { + if o == nil || IsNil(o.Metadata) { + return nil, false + } + return o.Metadata, true +} + +// HasMetadata returns a boolean if a field has been set. +func (o *GetInstanceListResult) HasMetadata() bool { + if o != nil && !IsNil(o.Metadata) { + return true + } + + return false +} + +// SetMetadata gets a reference to the given Metadata and assigns it to the Metadata field. +func (o *GetInstanceListResult) SetMetadata(v Metadata) { + o.Metadata = &v +} + +func (o GetInstanceListResult) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o GetInstanceListResult) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Instances) { + toSerialize["instances"] = o.Instances + } + if !IsNil(o.Metadata) { + toSerialize["_metadata"] = o.Metadata + } + return toSerialize, nil +} + +type NullableGetInstanceListResult struct { + value *GetInstanceListResult + isSet bool +} + +func (v NullableGetInstanceListResult) Get() *GetInstanceListResult { + return v.value +} + +func (v *NullableGetInstanceListResult) Set(val *GetInstanceListResult) { + v.value = val + v.isSet = true +} + +func (v NullableGetInstanceListResult) IsSet() bool { + return v.isSet +} + +func (v *NullableGetInstanceListResult) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableGetInstanceListResult(val *GetInstanceListResult) *NullableGetInstanceListResult { + return &NullableGetInstanceListResult{value: val, isSet: true} +} + +func (v NullableGetInstanceListResult) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableGetInstanceListResult) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/publicCloud/model_get_instance_result.go b/publicCloud/model_get_instance_result.go new file mode 100644 index 0000000..ca66eaf --- /dev/null +++ b/publicCloud/model_get_instance_result.go @@ -0,0 +1,867 @@ +/* +LeaseWeb API for launching and managing Public Cloud instances + +> The base URL for this API is: **https://api.leaseweb.com/publicCloud/v1/_** This API provides ways to launch and manage Public Cloud instances.
BETA
This API is in BETA. Documentation might be incorrect or incomplete. Functionality might change with the final release.> + +API version: v1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package publicCloud + +import ( + "encoding/json" + "time" +) + +// checks if the GetInstanceResult type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &GetInstanceResult{} + +// GetInstanceResult struct for GetInstanceResult +type GetInstanceResult struct { + // The customer ID who owns the instance + CustomerId *string `json:"customerId,omitempty"` + // The instance unique identifier + Id *string `json:"id,omitempty"` + Resources *InstanceResources `json:"resources,omitempty"` + // Instance type + Type *string `json:"type,omitempty"` + // The region where the instance was launched into + Region *string `json:"region,omitempty"` + // The identifying name set to the instance + Reference *string `json:"reference,omitempty"` + OperatingSystem *OperatingSystem `json:"operatingSystem,omitempty"` + State *InstanceState `json:"state,omitempty"` + HasPublicIpV4 *bool `json:"hasPublicIpV4,omitempty"` + HasPrivateNetwork *bool `json:"hasPrivateNetwork,omitempty"` + // The root disk size as specified during its launch or update, in GB + RootDiskSize *int32 `json:"rootDiskSize,omitempty"` + Ips []Ip `json:"ips,omitempty"` + BillingFrequency *int32 `json:"billingFrequency,omitempty"` + // The contract commitment (in months) + ContractTerm *int32 `json:"contractTerm,omitempty"` + ContractType *ContractType `json:"contractType,omitempty"` + ContractEndsAt *time.Time `json:"contractEndsAt,omitempty"` + // Date and time when the instance was started for the first time, right after launching it + StartedAt *time.Time `json:"startedAt,omitempty"` + // Date when the contract will be automatically renewed + ContractRenewalsAt *time.Time `json:"contractRenewalsAt,omitempty"` + // Date when the contract was created + ContractCreatedAt *time.Time `json:"contractCreatedAt,omitempty"` + Iso NullableIso `json:"iso,omitempty"` + PrivateNetwork *PrivateNetwork `json:"privateNetwork,omitempty"` +} + +// NewGetInstanceResult instantiates a new GetInstanceResult object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewGetInstanceResult() *GetInstanceResult { + this := GetInstanceResult{} + return &this +} + +// NewGetInstanceResultWithDefaults instantiates a new GetInstanceResult object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewGetInstanceResultWithDefaults() *GetInstanceResult { + this := GetInstanceResult{} + return &this +} + +// GetCustomerId returns the CustomerId field value if set, zero value otherwise. +func (o *GetInstanceResult) GetCustomerId() string { + if o == nil || IsNil(o.CustomerId) { + var ret string + return ret + } + return *o.CustomerId +} + +// GetCustomerIdOk returns a tuple with the CustomerId field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetInstanceResult) GetCustomerIdOk() (*string, bool) { + if o == nil || IsNil(o.CustomerId) { + return nil, false + } + return o.CustomerId, true +} + +// HasCustomerId returns a boolean if a field has been set. +func (o *GetInstanceResult) HasCustomerId() bool { + if o != nil && !IsNil(o.CustomerId) { + return true + } + + return false +} + +// SetCustomerId gets a reference to the given string and assigns it to the CustomerId field. +func (o *GetInstanceResult) SetCustomerId(v string) { + o.CustomerId = &v +} + +// GetId returns the Id field value if set, zero value otherwise. +func (o *GetInstanceResult) GetId() string { + if o == nil || IsNil(o.Id) { + var ret string + return ret + } + return *o.Id +} + +// GetIdOk returns a tuple with the Id field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetInstanceResult) GetIdOk() (*string, bool) { + if o == nil || IsNil(o.Id) { + return nil, false + } + return o.Id, true +} + +// HasId returns a boolean if a field has been set. +func (o *GetInstanceResult) HasId() bool { + if o != nil && !IsNil(o.Id) { + return true + } + + return false +} + +// SetId gets a reference to the given string and assigns it to the Id field. +func (o *GetInstanceResult) SetId(v string) { + o.Id = &v +} + +// GetResources returns the Resources field value if set, zero value otherwise. +func (o *GetInstanceResult) GetResources() InstanceResources { + if o == nil || IsNil(o.Resources) { + var ret InstanceResources + return ret + } + return *o.Resources +} + +// GetResourcesOk returns a tuple with the Resources field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetInstanceResult) GetResourcesOk() (*InstanceResources, bool) { + if o == nil || IsNil(o.Resources) { + return nil, false + } + return o.Resources, true +} + +// HasResources returns a boolean if a field has been set. +func (o *GetInstanceResult) HasResources() bool { + if o != nil && !IsNil(o.Resources) { + return true + } + + return false +} + +// SetResources gets a reference to the given InstanceResources and assigns it to the Resources field. +func (o *GetInstanceResult) SetResources(v InstanceResources) { + o.Resources = &v +} + +// GetType returns the Type field value if set, zero value otherwise. +func (o *GetInstanceResult) GetType() string { + if o == nil || IsNil(o.Type) { + var ret string + return ret + } + return *o.Type +} + +// GetTypeOk returns a tuple with the Type field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetInstanceResult) GetTypeOk() (*string, bool) { + if o == nil || IsNil(o.Type) { + return nil, false + } + return o.Type, true +} + +// HasType returns a boolean if a field has been set. +func (o *GetInstanceResult) HasType() bool { + if o != nil && !IsNil(o.Type) { + return true + } + + return false +} + +// SetType gets a reference to the given string and assigns it to the Type field. +func (o *GetInstanceResult) SetType(v string) { + o.Type = &v +} + +// GetRegion returns the Region field value if set, zero value otherwise. +func (o *GetInstanceResult) GetRegion() string { + if o == nil || IsNil(o.Region) { + var ret string + return ret + } + return *o.Region +} + +// GetRegionOk returns a tuple with the Region field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetInstanceResult) GetRegionOk() (*string, bool) { + if o == nil || IsNil(o.Region) { + return nil, false + } + return o.Region, true +} + +// HasRegion returns a boolean if a field has been set. +func (o *GetInstanceResult) HasRegion() bool { + if o != nil && !IsNil(o.Region) { + return true + } + + return false +} + +// SetRegion gets a reference to the given string and assigns it to the Region field. +func (o *GetInstanceResult) SetRegion(v string) { + o.Region = &v +} + +// GetReference returns the Reference field value if set, zero value otherwise. +func (o *GetInstanceResult) GetReference() string { + if o == nil || IsNil(o.Reference) { + var ret string + return ret + } + return *o.Reference +} + +// GetReferenceOk returns a tuple with the Reference field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetInstanceResult) GetReferenceOk() (*string, bool) { + if o == nil || IsNil(o.Reference) { + return nil, false + } + return o.Reference, true +} + +// HasReference returns a boolean if a field has been set. +func (o *GetInstanceResult) HasReference() bool { + if o != nil && !IsNil(o.Reference) { + return true + } + + return false +} + +// SetReference gets a reference to the given string and assigns it to the Reference field. +func (o *GetInstanceResult) SetReference(v string) { + o.Reference = &v +} + +// GetOperatingSystem returns the OperatingSystem field value if set, zero value otherwise. +func (o *GetInstanceResult) GetOperatingSystem() OperatingSystem { + if o == nil || IsNil(o.OperatingSystem) { + var ret OperatingSystem + return ret + } + return *o.OperatingSystem +} + +// GetOperatingSystemOk returns a tuple with the OperatingSystem field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetInstanceResult) GetOperatingSystemOk() (*OperatingSystem, bool) { + if o == nil || IsNil(o.OperatingSystem) { + return nil, false + } + return o.OperatingSystem, true +} + +// HasOperatingSystem returns a boolean if a field has been set. +func (o *GetInstanceResult) HasOperatingSystem() bool { + if o != nil && !IsNil(o.OperatingSystem) { + return true + } + + return false +} + +// SetOperatingSystem gets a reference to the given OperatingSystem and assigns it to the OperatingSystem field. +func (o *GetInstanceResult) SetOperatingSystem(v OperatingSystem) { + o.OperatingSystem = &v +} + +// GetState returns the State field value if set, zero value otherwise. +func (o *GetInstanceResult) GetState() InstanceState { + if o == nil || IsNil(o.State) { + var ret InstanceState + return ret + } + return *o.State +} + +// GetStateOk returns a tuple with the State field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetInstanceResult) GetStateOk() (*InstanceState, bool) { + if o == nil || IsNil(o.State) { + return nil, false + } + return o.State, true +} + +// HasState returns a boolean if a field has been set. +func (o *GetInstanceResult) HasState() bool { + if o != nil && !IsNil(o.State) { + return true + } + + return false +} + +// SetState gets a reference to the given InstanceState and assigns it to the State field. +func (o *GetInstanceResult) SetState(v InstanceState) { + o.State = &v +} + +// GetHasPublicIpV4 returns the HasPublicIpV4 field value if set, zero value otherwise. +func (o *GetInstanceResult) GetHasPublicIpV4() bool { + if o == nil || IsNil(o.HasPublicIpV4) { + var ret bool + return ret + } + return *o.HasPublicIpV4 +} + +// GetHasPublicIpV4Ok returns a tuple with the HasPublicIpV4 field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetInstanceResult) GetHasPublicIpV4Ok() (*bool, bool) { + if o == nil || IsNil(o.HasPublicIpV4) { + return nil, false + } + return o.HasPublicIpV4, true +} + +// HasHasPublicIpV4 returns a boolean if a field has been set. +func (o *GetInstanceResult) HasHasPublicIpV4() bool { + if o != nil && !IsNil(o.HasPublicIpV4) { + return true + } + + return false +} + +// SetHasPublicIpV4 gets a reference to the given bool and assigns it to the HasPublicIpV4 field. +func (o *GetInstanceResult) SetHasPublicIpV4(v bool) { + o.HasPublicIpV4 = &v +} + +// GetHasPrivateNetwork returns the HasPrivateNetwork field value if set, zero value otherwise. +func (o *GetInstanceResult) GetHasPrivateNetwork() bool { + if o == nil || IsNil(o.HasPrivateNetwork) { + var ret bool + return ret + } + return *o.HasPrivateNetwork +} + +// GetHasPrivateNetworkOk returns a tuple with the HasPrivateNetwork field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetInstanceResult) GetHasPrivateNetworkOk() (*bool, bool) { + if o == nil || IsNil(o.HasPrivateNetwork) { + return nil, false + } + return o.HasPrivateNetwork, true +} + +// HasHasPrivateNetwork returns a boolean if a field has been set. +func (o *GetInstanceResult) HasHasPrivateNetwork() bool { + if o != nil && !IsNil(o.HasPrivateNetwork) { + return true + } + + return false +} + +// SetHasPrivateNetwork gets a reference to the given bool and assigns it to the HasPrivateNetwork field. +func (o *GetInstanceResult) SetHasPrivateNetwork(v bool) { + o.HasPrivateNetwork = &v +} + +// GetRootDiskSize returns the RootDiskSize field value if set, zero value otherwise. +func (o *GetInstanceResult) GetRootDiskSize() int32 { + if o == nil || IsNil(o.RootDiskSize) { + var ret int32 + return ret + } + return *o.RootDiskSize +} + +// GetRootDiskSizeOk returns a tuple with the RootDiskSize field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetInstanceResult) GetRootDiskSizeOk() (*int32, bool) { + if o == nil || IsNil(o.RootDiskSize) { + return nil, false + } + return o.RootDiskSize, true +} + +// HasRootDiskSize returns a boolean if a field has been set. +func (o *GetInstanceResult) HasRootDiskSize() bool { + if o != nil && !IsNil(o.RootDiskSize) { + return true + } + + return false +} + +// SetRootDiskSize gets a reference to the given int32 and assigns it to the RootDiskSize field. +func (o *GetInstanceResult) SetRootDiskSize(v int32) { + o.RootDiskSize = &v +} + +// GetIps returns the Ips field value if set, zero value otherwise. +func (o *GetInstanceResult) GetIps() []Ip { + if o == nil || IsNil(o.Ips) { + var ret []Ip + return ret + } + return o.Ips +} + +// GetIpsOk returns a tuple with the Ips field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetInstanceResult) GetIpsOk() ([]Ip, bool) { + if o == nil || IsNil(o.Ips) { + return nil, false + } + return o.Ips, true +} + +// HasIps returns a boolean if a field has been set. +func (o *GetInstanceResult) HasIps() bool { + if o != nil && !IsNil(o.Ips) { + return true + } + + return false +} + +// SetIps gets a reference to the given []Ip and assigns it to the Ips field. +func (o *GetInstanceResult) SetIps(v []Ip) { + o.Ips = v +} + +// GetBillingFrequency returns the BillingFrequency field value if set, zero value otherwise. +func (o *GetInstanceResult) GetBillingFrequency() int32 { + if o == nil || IsNil(o.BillingFrequency) { + var ret int32 + return ret + } + return *o.BillingFrequency +} + +// GetBillingFrequencyOk returns a tuple with the BillingFrequency field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetInstanceResult) GetBillingFrequencyOk() (*int32, bool) { + if o == nil || IsNil(o.BillingFrequency) { + return nil, false + } + return o.BillingFrequency, true +} + +// HasBillingFrequency returns a boolean if a field has been set. +func (o *GetInstanceResult) HasBillingFrequency() bool { + if o != nil && !IsNil(o.BillingFrequency) { + return true + } + + return false +} + +// SetBillingFrequency gets a reference to the given int32 and assigns it to the BillingFrequency field. +func (o *GetInstanceResult) SetBillingFrequency(v int32) { + o.BillingFrequency = &v +} + +// GetContractTerm returns the ContractTerm field value if set, zero value otherwise. +func (o *GetInstanceResult) GetContractTerm() int32 { + if o == nil || IsNil(o.ContractTerm) { + var ret int32 + return ret + } + return *o.ContractTerm +} + +// GetContractTermOk returns a tuple with the ContractTerm field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetInstanceResult) GetContractTermOk() (*int32, bool) { + if o == nil || IsNil(o.ContractTerm) { + return nil, false + } + return o.ContractTerm, true +} + +// HasContractTerm returns a boolean if a field has been set. +func (o *GetInstanceResult) HasContractTerm() bool { + if o != nil && !IsNil(o.ContractTerm) { + return true + } + + return false +} + +// SetContractTerm gets a reference to the given int32 and assigns it to the ContractTerm field. +func (o *GetInstanceResult) SetContractTerm(v int32) { + o.ContractTerm = &v +} + +// GetContractType returns the ContractType field value if set, zero value otherwise. +func (o *GetInstanceResult) GetContractType() ContractType { + if o == nil || IsNil(o.ContractType) { + var ret ContractType + return ret + } + return *o.ContractType +} + +// GetContractTypeOk returns a tuple with the ContractType field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetInstanceResult) GetContractTypeOk() (*ContractType, bool) { + if o == nil || IsNil(o.ContractType) { + return nil, false + } + return o.ContractType, true +} + +// HasContractType returns a boolean if a field has been set. +func (o *GetInstanceResult) HasContractType() bool { + if o != nil && !IsNil(o.ContractType) { + return true + } + + return false +} + +// SetContractType gets a reference to the given ContractType and assigns it to the ContractType field. +func (o *GetInstanceResult) SetContractType(v ContractType) { + o.ContractType = &v +} + +// GetContractEndsAt returns the ContractEndsAt field value if set, zero value otherwise. +func (o *GetInstanceResult) GetContractEndsAt() time.Time { + if o == nil || IsNil(o.ContractEndsAt) { + var ret time.Time + return ret + } + return *o.ContractEndsAt +} + +// GetContractEndsAtOk returns a tuple with the ContractEndsAt field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetInstanceResult) GetContractEndsAtOk() (*time.Time, bool) { + if o == nil || IsNil(o.ContractEndsAt) { + return nil, false + } + return o.ContractEndsAt, true +} + +// HasContractEndsAt returns a boolean if a field has been set. +func (o *GetInstanceResult) HasContractEndsAt() bool { + if o != nil && !IsNil(o.ContractEndsAt) { + return true + } + + return false +} + +// SetContractEndsAt gets a reference to the given time.Time and assigns it to the ContractEndsAt field. +func (o *GetInstanceResult) SetContractEndsAt(v time.Time) { + o.ContractEndsAt = &v +} + +// GetStartedAt returns the StartedAt field value if set, zero value otherwise. +func (o *GetInstanceResult) GetStartedAt() time.Time { + if o == nil || IsNil(o.StartedAt) { + var ret time.Time + return ret + } + return *o.StartedAt +} + +// GetStartedAtOk returns a tuple with the StartedAt field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetInstanceResult) GetStartedAtOk() (*time.Time, bool) { + if o == nil || IsNil(o.StartedAt) { + return nil, false + } + return o.StartedAt, true +} + +// HasStartedAt returns a boolean if a field has been set. +func (o *GetInstanceResult) HasStartedAt() bool { + if o != nil && !IsNil(o.StartedAt) { + return true + } + + return false +} + +// SetStartedAt gets a reference to the given time.Time and assigns it to the StartedAt field. +func (o *GetInstanceResult) SetStartedAt(v time.Time) { + o.StartedAt = &v +} + +// GetContractRenewalsAt returns the ContractRenewalsAt field value if set, zero value otherwise. +func (o *GetInstanceResult) GetContractRenewalsAt() time.Time { + if o == nil || IsNil(o.ContractRenewalsAt) { + var ret time.Time + return ret + } + return *o.ContractRenewalsAt +} + +// GetContractRenewalsAtOk returns a tuple with the ContractRenewalsAt field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetInstanceResult) GetContractRenewalsAtOk() (*time.Time, bool) { + if o == nil || IsNil(o.ContractRenewalsAt) { + return nil, false + } + return o.ContractRenewalsAt, true +} + +// HasContractRenewalsAt returns a boolean if a field has been set. +func (o *GetInstanceResult) HasContractRenewalsAt() bool { + if o != nil && !IsNil(o.ContractRenewalsAt) { + return true + } + + return false +} + +// SetContractRenewalsAt gets a reference to the given time.Time and assigns it to the ContractRenewalsAt field. +func (o *GetInstanceResult) SetContractRenewalsAt(v time.Time) { + o.ContractRenewalsAt = &v +} + +// GetContractCreatedAt returns the ContractCreatedAt field value if set, zero value otherwise. +func (o *GetInstanceResult) GetContractCreatedAt() time.Time { + if o == nil || IsNil(o.ContractCreatedAt) { + var ret time.Time + return ret + } + return *o.ContractCreatedAt +} + +// GetContractCreatedAtOk returns a tuple with the ContractCreatedAt field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetInstanceResult) GetContractCreatedAtOk() (*time.Time, bool) { + if o == nil || IsNil(o.ContractCreatedAt) { + return nil, false + } + return o.ContractCreatedAt, true +} + +// HasContractCreatedAt returns a boolean if a field has been set. +func (o *GetInstanceResult) HasContractCreatedAt() bool { + if o != nil && !IsNil(o.ContractCreatedAt) { + return true + } + + return false +} + +// SetContractCreatedAt gets a reference to the given time.Time and assigns it to the ContractCreatedAt field. +func (o *GetInstanceResult) SetContractCreatedAt(v time.Time) { + o.ContractCreatedAt = &v +} + +// GetIso returns the Iso field value if set, zero value otherwise (both if not set or set to explicit null). +func (o *GetInstanceResult) GetIso() Iso { + if o == nil || IsNil(o.Iso.Get()) { + var ret Iso + return ret + } + return *o.Iso.Get() +} + +// GetIsoOk returns a tuple with the Iso field value if set, nil otherwise +// and a boolean to check if the value has been set. +// NOTE: If the value is an explicit nil, `nil, true` will be returned +func (o *GetInstanceResult) GetIsoOk() (*Iso, bool) { + if o == nil { + return nil, false + } + return o.Iso.Get(), o.Iso.IsSet() +} + +// HasIso returns a boolean if a field has been set. +func (o *GetInstanceResult) HasIso() bool { + if o != nil && o.Iso.IsSet() { + return true + } + + return false +} + +// SetIso gets a reference to the given NullableIso and assigns it to the Iso field. +func (o *GetInstanceResult) SetIso(v Iso) { + o.Iso.Set(&v) +} +// SetIsoNil sets the value for Iso to be an explicit nil +func (o *GetInstanceResult) SetIsoNil() { + o.Iso.Set(nil) +} + +// UnsetIso ensures that no value is present for Iso, not even an explicit nil +func (o *GetInstanceResult) UnsetIso() { + o.Iso.Unset() +} + +// GetPrivateNetwork returns the PrivateNetwork field value if set, zero value otherwise. +func (o *GetInstanceResult) GetPrivateNetwork() PrivateNetwork { + if o == nil || IsNil(o.PrivateNetwork) { + var ret PrivateNetwork + return ret + } + return *o.PrivateNetwork +} + +// GetPrivateNetworkOk returns a tuple with the PrivateNetwork field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetInstanceResult) GetPrivateNetworkOk() (*PrivateNetwork, bool) { + if o == nil || IsNil(o.PrivateNetwork) { + return nil, false + } + return o.PrivateNetwork, true +} + +// HasPrivateNetwork returns a boolean if a field has been set. +func (o *GetInstanceResult) HasPrivateNetwork() bool { + if o != nil && !IsNil(o.PrivateNetwork) { + return true + } + + return false +} + +// SetPrivateNetwork gets a reference to the given PrivateNetwork and assigns it to the PrivateNetwork field. +func (o *GetInstanceResult) SetPrivateNetwork(v PrivateNetwork) { + o.PrivateNetwork = &v +} + +func (o GetInstanceResult) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o GetInstanceResult) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.CustomerId) { + toSerialize["customerId"] = o.CustomerId + } + if !IsNil(o.Id) { + toSerialize["id"] = o.Id + } + if !IsNil(o.Resources) { + toSerialize["resources"] = o.Resources + } + if !IsNil(o.Type) { + toSerialize["type"] = o.Type + } + if !IsNil(o.Region) { + toSerialize["region"] = o.Region + } + if !IsNil(o.Reference) { + toSerialize["reference"] = o.Reference + } + if !IsNil(o.OperatingSystem) { + toSerialize["operatingSystem"] = o.OperatingSystem + } + if !IsNil(o.State) { + toSerialize["state"] = o.State + } + if !IsNil(o.HasPublicIpV4) { + toSerialize["hasPublicIpV4"] = o.HasPublicIpV4 + } + if !IsNil(o.HasPrivateNetwork) { + toSerialize["hasPrivateNetwork"] = o.HasPrivateNetwork + } + if !IsNil(o.RootDiskSize) { + toSerialize["rootDiskSize"] = o.RootDiskSize + } + if !IsNil(o.Ips) { + toSerialize["ips"] = o.Ips + } + if !IsNil(o.BillingFrequency) { + toSerialize["billingFrequency"] = o.BillingFrequency + } + if !IsNil(o.ContractTerm) { + toSerialize["contractTerm"] = o.ContractTerm + } + if !IsNil(o.ContractType) { + toSerialize["contractType"] = o.ContractType + } + if !IsNil(o.ContractEndsAt) { + toSerialize["contractEndsAt"] = o.ContractEndsAt + } + if !IsNil(o.StartedAt) { + toSerialize["startedAt"] = o.StartedAt + } + if !IsNil(o.ContractRenewalsAt) { + toSerialize["contractRenewalsAt"] = o.ContractRenewalsAt + } + if !IsNil(o.ContractCreatedAt) { + toSerialize["contractCreatedAt"] = o.ContractCreatedAt + } + if o.Iso.IsSet() { + toSerialize["iso"] = o.Iso.Get() + } + if !IsNil(o.PrivateNetwork) { + toSerialize["privateNetwork"] = o.PrivateNetwork + } + return toSerialize, nil +} + +type NullableGetInstanceResult struct { + value *GetInstanceResult + isSet bool +} + +func (v NullableGetInstanceResult) Get() *GetInstanceResult { + return v.value +} + +func (v *NullableGetInstanceResult) Set(val *GetInstanceResult) { + v.value = val + v.isSet = true +} + +func (v NullableGetInstanceResult) IsSet() bool { + return v.isSet +} + +func (v *NullableGetInstanceResult) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableGetInstanceResult(val *GetInstanceResult) *NullableGetInstanceResult { + return &NullableGetInstanceResult{value: val, isSet: true} +} + +func (v NullableGetInstanceResult) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableGetInstanceResult) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/publicCloud/model_get_instance_type_list_result.go b/publicCloud/model_get_instance_type_list_result.go new file mode 100644 index 0000000..d650b1e --- /dev/null +++ b/publicCloud/model_get_instance_type_list_result.go @@ -0,0 +1,162 @@ +/* +LeaseWeb API for launching and managing Public Cloud instances + +> The base URL for this API is: **https://api.leaseweb.com/publicCloud/v1/_** This API provides ways to launch and manage Public Cloud instances.
BETA
This API is in BETA. Documentation might be incorrect or incomplete. Functionality might change with the final release.> + +API version: v1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package publicCloud + +import ( + "encoding/json" +) + +// checks if the GetInstanceTypeListResult type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &GetInstanceTypeListResult{} + +// GetInstanceTypeListResult struct for GetInstanceTypeListResult +type GetInstanceTypeListResult struct { + Metadata *Metadata `json:"_metadata,omitempty"` + InstanceTypes []InstanceTypeDetails `json:"instanceTypes,omitempty"` +} + +// NewGetInstanceTypeListResult instantiates a new GetInstanceTypeListResult object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewGetInstanceTypeListResult() *GetInstanceTypeListResult { + this := GetInstanceTypeListResult{} + return &this +} + +// NewGetInstanceTypeListResultWithDefaults instantiates a new GetInstanceTypeListResult object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewGetInstanceTypeListResultWithDefaults() *GetInstanceTypeListResult { + this := GetInstanceTypeListResult{} + return &this +} + +// GetMetadata returns the Metadata field value if set, zero value otherwise. +func (o *GetInstanceTypeListResult) GetMetadata() Metadata { + if o == nil || IsNil(o.Metadata) { + var ret Metadata + return ret + } + return *o.Metadata +} + +// GetMetadataOk returns a tuple with the Metadata field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetInstanceTypeListResult) GetMetadataOk() (*Metadata, bool) { + if o == nil || IsNil(o.Metadata) { + return nil, false + } + return o.Metadata, true +} + +// HasMetadata returns a boolean if a field has been set. +func (o *GetInstanceTypeListResult) HasMetadata() bool { + if o != nil && !IsNil(o.Metadata) { + return true + } + + return false +} + +// SetMetadata gets a reference to the given Metadata and assigns it to the Metadata field. +func (o *GetInstanceTypeListResult) SetMetadata(v Metadata) { + o.Metadata = &v +} + +// GetInstanceTypes returns the InstanceTypes field value if set, zero value otherwise. +func (o *GetInstanceTypeListResult) GetInstanceTypes() []InstanceTypeDetails { + if o == nil || IsNil(o.InstanceTypes) { + var ret []InstanceTypeDetails + return ret + } + return o.InstanceTypes +} + +// GetInstanceTypesOk returns a tuple with the InstanceTypes field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetInstanceTypeListResult) GetInstanceTypesOk() ([]InstanceTypeDetails, bool) { + if o == nil || IsNil(o.InstanceTypes) { + return nil, false + } + return o.InstanceTypes, true +} + +// HasInstanceTypes returns a boolean if a field has been set. +func (o *GetInstanceTypeListResult) HasInstanceTypes() bool { + if o != nil && !IsNil(o.InstanceTypes) { + return true + } + + return false +} + +// SetInstanceTypes gets a reference to the given []InstanceTypeDetails and assigns it to the InstanceTypes field. +func (o *GetInstanceTypeListResult) SetInstanceTypes(v []InstanceTypeDetails) { + o.InstanceTypes = v +} + +func (o GetInstanceTypeListResult) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o GetInstanceTypeListResult) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Metadata) { + toSerialize["_metadata"] = o.Metadata + } + if !IsNil(o.InstanceTypes) { + toSerialize["instanceTypes"] = o.InstanceTypes + } + return toSerialize, nil +} + +type NullableGetInstanceTypeListResult struct { + value *GetInstanceTypeListResult + isSet bool +} + +func (v NullableGetInstanceTypeListResult) Get() *GetInstanceTypeListResult { + return v.value +} + +func (v *NullableGetInstanceTypeListResult) Set(val *GetInstanceTypeListResult) { + v.value = val + v.isSet = true +} + +func (v NullableGetInstanceTypeListResult) IsSet() bool { + return v.isSet +} + +func (v *NullableGetInstanceTypeListResult) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableGetInstanceTypeListResult(val *GetInstanceTypeListResult) *NullableGetInstanceTypeListResult { + return &NullableGetInstanceTypeListResult{value: val, isSet: true} +} + +func (v NullableGetInstanceTypeListResult) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableGetInstanceTypeListResult) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/publicCloud/model_get_iso_list_result.go b/publicCloud/model_get_iso_list_result.go new file mode 100644 index 0000000..ed2c190 --- /dev/null +++ b/publicCloud/model_get_iso_list_result.go @@ -0,0 +1,162 @@ +/* +LeaseWeb API for launching and managing Public Cloud instances + +> The base URL for this API is: **https://api.leaseweb.com/publicCloud/v1/_** This API provides ways to launch and manage Public Cloud instances.
BETA
This API is in BETA. Documentation might be incorrect or incomplete. Functionality might change with the final release.> + +API version: v1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package publicCloud + +import ( + "encoding/json" +) + +// checks if the GetIsoListResult type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &GetIsoListResult{} + +// GetIsoListResult struct for GetIsoListResult +type GetIsoListResult struct { + Isos []Iso `json:"isos,omitempty"` + Metadata *Metadata `json:"_metadata,omitempty"` +} + +// NewGetIsoListResult instantiates a new GetIsoListResult object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewGetIsoListResult() *GetIsoListResult { + this := GetIsoListResult{} + return &this +} + +// NewGetIsoListResultWithDefaults instantiates a new GetIsoListResult object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewGetIsoListResultWithDefaults() *GetIsoListResult { + this := GetIsoListResult{} + return &this +} + +// GetIsos returns the Isos field value if set, zero value otherwise. +func (o *GetIsoListResult) GetIsos() []Iso { + if o == nil || IsNil(o.Isos) { + var ret []Iso + return ret + } + return o.Isos +} + +// GetIsosOk returns a tuple with the Isos field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetIsoListResult) GetIsosOk() ([]Iso, bool) { + if o == nil || IsNil(o.Isos) { + return nil, false + } + return o.Isos, true +} + +// HasIsos returns a boolean if a field has been set. +func (o *GetIsoListResult) HasIsos() bool { + if o != nil && !IsNil(o.Isos) { + return true + } + + return false +} + +// SetIsos gets a reference to the given []Iso and assigns it to the Isos field. +func (o *GetIsoListResult) SetIsos(v []Iso) { + o.Isos = v +} + +// GetMetadata returns the Metadata field value if set, zero value otherwise. +func (o *GetIsoListResult) GetMetadata() Metadata { + if o == nil || IsNil(o.Metadata) { + var ret Metadata + return ret + } + return *o.Metadata +} + +// GetMetadataOk returns a tuple with the Metadata field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetIsoListResult) GetMetadataOk() (*Metadata, bool) { + if o == nil || IsNil(o.Metadata) { + return nil, false + } + return o.Metadata, true +} + +// HasMetadata returns a boolean if a field has been set. +func (o *GetIsoListResult) HasMetadata() bool { + if o != nil && !IsNil(o.Metadata) { + return true + } + + return false +} + +// SetMetadata gets a reference to the given Metadata and assigns it to the Metadata field. +func (o *GetIsoListResult) SetMetadata(v Metadata) { + o.Metadata = &v +} + +func (o GetIsoListResult) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o GetIsoListResult) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Isos) { + toSerialize["isos"] = o.Isos + } + if !IsNil(o.Metadata) { + toSerialize["_metadata"] = o.Metadata + } + return toSerialize, nil +} + +type NullableGetIsoListResult struct { + value *GetIsoListResult + isSet bool +} + +func (v NullableGetIsoListResult) Get() *GetIsoListResult { + return v.value +} + +func (v *NullableGetIsoListResult) Set(val *GetIsoListResult) { + v.value = val + v.isSet = true +} + +func (v NullableGetIsoListResult) IsSet() bool { + return v.isSet +} + +func (v *NullableGetIsoListResult) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableGetIsoListResult(val *GetIsoListResult) *NullableGetIsoListResult { + return &NullableGetIsoListResult{value: val, isSet: true} +} + +func (v NullableGetIsoListResult) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableGetIsoListResult) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/publicCloud/model_get_market_app_list_result.go b/publicCloud/model_get_market_app_list_result.go new file mode 100644 index 0000000..5e67a81 --- /dev/null +++ b/publicCloud/model_get_market_app_list_result.go @@ -0,0 +1,162 @@ +/* +LeaseWeb API for launching and managing Public Cloud instances + +> The base URL for this API is: **https://api.leaseweb.com/publicCloud/v1/_** This API provides ways to launch and manage Public Cloud instances.
BETA
This API is in BETA. Documentation might be incorrect or incomplete. Functionality might change with the final release.> + +API version: v1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package publicCloud + +import ( + "encoding/json" +) + +// checks if the GetMarketAppListResult type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &GetMarketAppListResult{} + +// GetMarketAppListResult struct for GetMarketAppListResult +type GetMarketAppListResult struct { + MarketApps []MarketApp `json:"marketApps,omitempty"` + Metadata *Metadata `json:"_metadata,omitempty"` +} + +// NewGetMarketAppListResult instantiates a new GetMarketAppListResult object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewGetMarketAppListResult() *GetMarketAppListResult { + this := GetMarketAppListResult{} + return &this +} + +// NewGetMarketAppListResultWithDefaults instantiates a new GetMarketAppListResult object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewGetMarketAppListResultWithDefaults() *GetMarketAppListResult { + this := GetMarketAppListResult{} + return &this +} + +// GetMarketApps returns the MarketApps field value if set, zero value otherwise. +func (o *GetMarketAppListResult) GetMarketApps() []MarketApp { + if o == nil || IsNil(o.MarketApps) { + var ret []MarketApp + return ret + } + return o.MarketApps +} + +// GetMarketAppsOk returns a tuple with the MarketApps field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetMarketAppListResult) GetMarketAppsOk() ([]MarketApp, bool) { + if o == nil || IsNil(o.MarketApps) { + return nil, false + } + return o.MarketApps, true +} + +// HasMarketApps returns a boolean if a field has been set. +func (o *GetMarketAppListResult) HasMarketApps() bool { + if o != nil && !IsNil(o.MarketApps) { + return true + } + + return false +} + +// SetMarketApps gets a reference to the given []MarketApp and assigns it to the MarketApps field. +func (o *GetMarketAppListResult) SetMarketApps(v []MarketApp) { + o.MarketApps = v +} + +// GetMetadata returns the Metadata field value if set, zero value otherwise. +func (o *GetMarketAppListResult) GetMetadata() Metadata { + if o == nil || IsNil(o.Metadata) { + var ret Metadata + return ret + } + return *o.Metadata +} + +// GetMetadataOk returns a tuple with the Metadata field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetMarketAppListResult) GetMetadataOk() (*Metadata, bool) { + if o == nil || IsNil(o.Metadata) { + return nil, false + } + return o.Metadata, true +} + +// HasMetadata returns a boolean if a field has been set. +func (o *GetMarketAppListResult) HasMetadata() bool { + if o != nil && !IsNil(o.Metadata) { + return true + } + + return false +} + +// SetMetadata gets a reference to the given Metadata and assigns it to the Metadata field. +func (o *GetMarketAppListResult) SetMetadata(v Metadata) { + o.Metadata = &v +} + +func (o GetMarketAppListResult) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o GetMarketAppListResult) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.MarketApps) { + toSerialize["marketApps"] = o.MarketApps + } + if !IsNil(o.Metadata) { + toSerialize["_metadata"] = o.Metadata + } + return toSerialize, nil +} + +type NullableGetMarketAppListResult struct { + value *GetMarketAppListResult + isSet bool +} + +func (v NullableGetMarketAppListResult) Get() *GetMarketAppListResult { + return v.value +} + +func (v *NullableGetMarketAppListResult) Set(val *GetMarketAppListResult) { + v.value = val + v.isSet = true +} + +func (v NullableGetMarketAppListResult) IsSet() bool { + return v.isSet +} + +func (v *NullableGetMarketAppListResult) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableGetMarketAppListResult(val *GetMarketAppListResult) *NullableGetMarketAppListResult { + return &NullableGetMarketAppListResult{value: val, isSet: true} +} + +func (v NullableGetMarketAppListResult) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableGetMarketAppListResult) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/publicCloud/model_get_operating_system_list_result.go b/publicCloud/model_get_operating_system_list_result.go new file mode 100644 index 0000000..b8aaf78 --- /dev/null +++ b/publicCloud/model_get_operating_system_list_result.go @@ -0,0 +1,162 @@ +/* +LeaseWeb API for launching and managing Public Cloud instances + +> The base URL for this API is: **https://api.leaseweb.com/publicCloud/v1/_** This API provides ways to launch and manage Public Cloud instances.
BETA
This API is in BETA. Documentation might be incorrect or incomplete. Functionality might change with the final release.> + +API version: v1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package publicCloud + +import ( + "encoding/json" +) + +// checks if the GetOperatingSystemListResult type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &GetOperatingSystemListResult{} + +// GetOperatingSystemListResult struct for GetOperatingSystemListResult +type GetOperatingSystemListResult struct { + OperatingSystems []OperatingSystemDetail `json:"operatingSystems,omitempty"` + Metadata *Metadata `json:"_metadata,omitempty"` +} + +// NewGetOperatingSystemListResult instantiates a new GetOperatingSystemListResult object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewGetOperatingSystemListResult() *GetOperatingSystemListResult { + this := GetOperatingSystemListResult{} + return &this +} + +// NewGetOperatingSystemListResultWithDefaults instantiates a new GetOperatingSystemListResult object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewGetOperatingSystemListResultWithDefaults() *GetOperatingSystemListResult { + this := GetOperatingSystemListResult{} + return &this +} + +// GetOperatingSystems returns the OperatingSystems field value if set, zero value otherwise. +func (o *GetOperatingSystemListResult) GetOperatingSystems() []OperatingSystemDetail { + if o == nil || IsNil(o.OperatingSystems) { + var ret []OperatingSystemDetail + return ret + } + return o.OperatingSystems +} + +// GetOperatingSystemsOk returns a tuple with the OperatingSystems field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetOperatingSystemListResult) GetOperatingSystemsOk() ([]OperatingSystemDetail, bool) { + if o == nil || IsNil(o.OperatingSystems) { + return nil, false + } + return o.OperatingSystems, true +} + +// HasOperatingSystems returns a boolean if a field has been set. +func (o *GetOperatingSystemListResult) HasOperatingSystems() bool { + if o != nil && !IsNil(o.OperatingSystems) { + return true + } + + return false +} + +// SetOperatingSystems gets a reference to the given []OperatingSystemDetail and assigns it to the OperatingSystems field. +func (o *GetOperatingSystemListResult) SetOperatingSystems(v []OperatingSystemDetail) { + o.OperatingSystems = v +} + +// GetMetadata returns the Metadata field value if set, zero value otherwise. +func (o *GetOperatingSystemListResult) GetMetadata() Metadata { + if o == nil || IsNil(o.Metadata) { + var ret Metadata + return ret + } + return *o.Metadata +} + +// GetMetadataOk returns a tuple with the Metadata field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetOperatingSystemListResult) GetMetadataOk() (*Metadata, bool) { + if o == nil || IsNil(o.Metadata) { + return nil, false + } + return o.Metadata, true +} + +// HasMetadata returns a boolean if a field has been set. +func (o *GetOperatingSystemListResult) HasMetadata() bool { + if o != nil && !IsNil(o.Metadata) { + return true + } + + return false +} + +// SetMetadata gets a reference to the given Metadata and assigns it to the Metadata field. +func (o *GetOperatingSystemListResult) SetMetadata(v Metadata) { + o.Metadata = &v +} + +func (o GetOperatingSystemListResult) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o GetOperatingSystemListResult) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.OperatingSystems) { + toSerialize["operatingSystems"] = o.OperatingSystems + } + if !IsNil(o.Metadata) { + toSerialize["_metadata"] = o.Metadata + } + return toSerialize, nil +} + +type NullableGetOperatingSystemListResult struct { + value *GetOperatingSystemListResult + isSet bool +} + +func (v NullableGetOperatingSystemListResult) Get() *GetOperatingSystemListResult { + return v.value +} + +func (v *NullableGetOperatingSystemListResult) Set(val *GetOperatingSystemListResult) { + v.value = val + v.isSet = true +} + +func (v NullableGetOperatingSystemListResult) IsSet() bool { + return v.isSet +} + +func (v *NullableGetOperatingSystemListResult) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableGetOperatingSystemListResult(val *GetOperatingSystemListResult) *NullableGetOperatingSystemListResult { + return &NullableGetOperatingSystemListResult{value: val, isSet: true} +} + +func (v NullableGetOperatingSystemListResult) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableGetOperatingSystemListResult) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/publicCloud/model_get_region_list_result.go b/publicCloud/model_get_region_list_result.go new file mode 100644 index 0000000..cdc6073 --- /dev/null +++ b/publicCloud/model_get_region_list_result.go @@ -0,0 +1,162 @@ +/* +LeaseWeb API for launching and managing Public Cloud instances + +> The base URL for this API is: **https://api.leaseweb.com/publicCloud/v1/_** This API provides ways to launch and manage Public Cloud instances.
BETA
This API is in BETA. Documentation might be incorrect or incomplete. Functionality might change with the final release.> + +API version: v1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package publicCloud + +import ( + "encoding/json" +) + +// checks if the GetRegionListResult type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &GetRegionListResult{} + +// GetRegionListResult struct for GetRegionListResult +type GetRegionListResult struct { + Regions []Region `json:"regions,omitempty"` + Metadata *Metadata `json:"_metadata,omitempty"` +} + +// NewGetRegionListResult instantiates a new GetRegionListResult object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewGetRegionListResult() *GetRegionListResult { + this := GetRegionListResult{} + return &this +} + +// NewGetRegionListResultWithDefaults instantiates a new GetRegionListResult object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewGetRegionListResultWithDefaults() *GetRegionListResult { + this := GetRegionListResult{} + return &this +} + +// GetRegions returns the Regions field value if set, zero value otherwise. +func (o *GetRegionListResult) GetRegions() []Region { + if o == nil || IsNil(o.Regions) { + var ret []Region + return ret + } + return o.Regions +} + +// GetRegionsOk returns a tuple with the Regions field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetRegionListResult) GetRegionsOk() ([]Region, bool) { + if o == nil || IsNil(o.Regions) { + return nil, false + } + return o.Regions, true +} + +// HasRegions returns a boolean if a field has been set. +func (o *GetRegionListResult) HasRegions() bool { + if o != nil && !IsNil(o.Regions) { + return true + } + + return false +} + +// SetRegions gets a reference to the given []Region and assigns it to the Regions field. +func (o *GetRegionListResult) SetRegions(v []Region) { + o.Regions = v +} + +// GetMetadata returns the Metadata field value if set, zero value otherwise. +func (o *GetRegionListResult) GetMetadata() Metadata { + if o == nil || IsNil(o.Metadata) { + var ret Metadata + return ret + } + return *o.Metadata +} + +// GetMetadataOk returns a tuple with the Metadata field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetRegionListResult) GetMetadataOk() (*Metadata, bool) { + if o == nil || IsNil(o.Metadata) { + return nil, false + } + return o.Metadata, true +} + +// HasMetadata returns a boolean if a field has been set. +func (o *GetRegionListResult) HasMetadata() bool { + if o != nil && !IsNil(o.Metadata) { + return true + } + + return false +} + +// SetMetadata gets a reference to the given Metadata and assigns it to the Metadata field. +func (o *GetRegionListResult) SetMetadata(v Metadata) { + o.Metadata = &v +} + +func (o GetRegionListResult) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o GetRegionListResult) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Regions) { + toSerialize["regions"] = o.Regions + } + if !IsNil(o.Metadata) { + toSerialize["_metadata"] = o.Metadata + } + return toSerialize, nil +} + +type NullableGetRegionListResult struct { + value *GetRegionListResult + isSet bool +} + +func (v NullableGetRegionListResult) Get() *GetRegionListResult { + return v.value +} + +func (v *NullableGetRegionListResult) Set(val *GetRegionListResult) { + v.value = val + v.isSet = true +} + +func (v NullableGetRegionListResult) IsSet() bool { + return v.isSet +} + +func (v *NullableGetRegionListResult) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableGetRegionListResult(val *GetRegionListResult) *NullableGetRegionListResult { + return &NullableGetRegionListResult{value: val, isSet: true} +} + +func (v NullableGetRegionListResult) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableGetRegionListResult) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/publicCloud/model_get_update_instance_type_list_result.go b/publicCloud/model_get_update_instance_type_list_result.go new file mode 100644 index 0000000..769a6c0 --- /dev/null +++ b/publicCloud/model_get_update_instance_type_list_result.go @@ -0,0 +1,162 @@ +/* +LeaseWeb API for launching and managing Public Cloud instances + +> The base URL for this API is: **https://api.leaseweb.com/publicCloud/v1/_** This API provides ways to launch and manage Public Cloud instances.
BETA
This API is in BETA. Documentation might be incorrect or incomplete. Functionality might change with the final release.> + +API version: v1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package publicCloud + +import ( + "encoding/json" +) + +// checks if the GetUpdateInstanceTypeListResult type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &GetUpdateInstanceTypeListResult{} + +// GetUpdateInstanceTypeListResult struct for GetUpdateInstanceTypeListResult +type GetUpdateInstanceTypeListResult struct { + Metadata *Metadata `json:"_metadata,omitempty"` + InstanceTypes []UpdateInstanceType `json:"instanceTypes,omitempty"` +} + +// NewGetUpdateInstanceTypeListResult instantiates a new GetUpdateInstanceTypeListResult object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewGetUpdateInstanceTypeListResult() *GetUpdateInstanceTypeListResult { + this := GetUpdateInstanceTypeListResult{} + return &this +} + +// NewGetUpdateInstanceTypeListResultWithDefaults instantiates a new GetUpdateInstanceTypeListResult object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewGetUpdateInstanceTypeListResultWithDefaults() *GetUpdateInstanceTypeListResult { + this := GetUpdateInstanceTypeListResult{} + return &this +} + +// GetMetadata returns the Metadata field value if set, zero value otherwise. +func (o *GetUpdateInstanceTypeListResult) GetMetadata() Metadata { + if o == nil || IsNil(o.Metadata) { + var ret Metadata + return ret + } + return *o.Metadata +} + +// GetMetadataOk returns a tuple with the Metadata field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetUpdateInstanceTypeListResult) GetMetadataOk() (*Metadata, bool) { + if o == nil || IsNil(o.Metadata) { + return nil, false + } + return o.Metadata, true +} + +// HasMetadata returns a boolean if a field has been set. +func (o *GetUpdateInstanceTypeListResult) HasMetadata() bool { + if o != nil && !IsNil(o.Metadata) { + return true + } + + return false +} + +// SetMetadata gets a reference to the given Metadata and assigns it to the Metadata field. +func (o *GetUpdateInstanceTypeListResult) SetMetadata(v Metadata) { + o.Metadata = &v +} + +// GetInstanceTypes returns the InstanceTypes field value if set, zero value otherwise. +func (o *GetUpdateInstanceTypeListResult) GetInstanceTypes() []UpdateInstanceType { + if o == nil || IsNil(o.InstanceTypes) { + var ret []UpdateInstanceType + return ret + } + return o.InstanceTypes +} + +// GetInstanceTypesOk returns a tuple with the InstanceTypes field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetUpdateInstanceTypeListResult) GetInstanceTypesOk() ([]UpdateInstanceType, bool) { + if o == nil || IsNil(o.InstanceTypes) { + return nil, false + } + return o.InstanceTypes, true +} + +// HasInstanceTypes returns a boolean if a field has been set. +func (o *GetUpdateInstanceTypeListResult) HasInstanceTypes() bool { + if o != nil && !IsNil(o.InstanceTypes) { + return true + } + + return false +} + +// SetInstanceTypes gets a reference to the given []UpdateInstanceType and assigns it to the InstanceTypes field. +func (o *GetUpdateInstanceTypeListResult) SetInstanceTypes(v []UpdateInstanceType) { + o.InstanceTypes = v +} + +func (o GetUpdateInstanceTypeListResult) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o GetUpdateInstanceTypeListResult) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Metadata) { + toSerialize["_metadata"] = o.Metadata + } + if !IsNil(o.InstanceTypes) { + toSerialize["instanceTypes"] = o.InstanceTypes + } + return toSerialize, nil +} + +type NullableGetUpdateInstanceTypeListResult struct { + value *GetUpdateInstanceTypeListResult + isSet bool +} + +func (v NullableGetUpdateInstanceTypeListResult) Get() *GetUpdateInstanceTypeListResult { + return v.value +} + +func (v *NullableGetUpdateInstanceTypeListResult) Set(val *GetUpdateInstanceTypeListResult) { + v.value = val + v.isSet = true +} + +func (v NullableGetUpdateInstanceTypeListResult) IsSet() bool { + return v.isSet +} + +func (v *NullableGetUpdateInstanceTypeListResult) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableGetUpdateInstanceTypeListResult(val *GetUpdateInstanceTypeListResult) *NullableGetUpdateInstanceTypeListResult { + return &NullableGetUpdateInstanceTypeListResult{value: val, isSet: true} +} + +func (v NullableGetUpdateInstanceTypeListResult) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableGetUpdateInstanceTypeListResult) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/publicCloud/model_icmp_firewall_rule.go b/publicCloud/model_icmp_firewall_rule.go new file mode 100644 index 0000000..deea454 --- /dev/null +++ b/publicCloud/model_icmp_firewall_rule.go @@ -0,0 +1,432 @@ +/* +LeaseWeb API for launching and managing Public Cloud instances + +> The base URL for this API is: **https://api.leaseweb.com/publicCloud/v1/_** This API provides ways to launch and manage Public Cloud instances.
BETA
This API is in BETA. Documentation might be incorrect or incomplete. Functionality might change with the final release.> + +API version: v1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package publicCloud + +import ( + "encoding/json" + "bytes" + "fmt" +) + +// checks if the IcmpFirewallRule type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &IcmpFirewallRule{} + +// IcmpFirewallRule struct for IcmpFirewallRule +type IcmpFirewallRule struct { + Id *string `json:"id,omitempty"` + Name NullableString `json:"name,omitempty"` + Cidr *string `json:"cidr,omitempty"` + Protocol *string `json:"protocol,omitempty"` + StartPort NullableInt32 `json:"startPort,omitempty"` + EndPort NullableInt32 `json:"endPort,omitempty"` + IcmpType int32 `json:"icmpType"` + IcmpCode int32 `json:"icmpCode"` +} + +type _IcmpFirewallRule IcmpFirewallRule + +// NewIcmpFirewallRule instantiates a new IcmpFirewallRule object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewIcmpFirewallRule(icmpType int32, icmpCode int32) *IcmpFirewallRule { + this := IcmpFirewallRule{} + this.IcmpType = icmpType + this.IcmpCode = icmpCode + return &this +} + +// NewIcmpFirewallRuleWithDefaults instantiates a new IcmpFirewallRule object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewIcmpFirewallRuleWithDefaults() *IcmpFirewallRule { + this := IcmpFirewallRule{} + return &this +} + +// GetId returns the Id field value if set, zero value otherwise. +func (o *IcmpFirewallRule) GetId() string { + if o == nil || IsNil(o.Id) { + var ret string + return ret + } + return *o.Id +} + +// GetIdOk returns a tuple with the Id field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *IcmpFirewallRule) GetIdOk() (*string, bool) { + if o == nil || IsNil(o.Id) { + return nil, false + } + return o.Id, true +} + +// HasId returns a boolean if a field has been set. +func (o *IcmpFirewallRule) HasId() bool { + if o != nil && !IsNil(o.Id) { + return true + } + + return false +} + +// SetId gets a reference to the given string and assigns it to the Id field. +func (o *IcmpFirewallRule) SetId(v string) { + o.Id = &v +} + +// GetName returns the Name field value if set, zero value otherwise (both if not set or set to explicit null). +func (o *IcmpFirewallRule) GetName() string { + if o == nil || IsNil(o.Name.Get()) { + var ret string + return ret + } + return *o.Name.Get() +} + +// GetNameOk returns a tuple with the Name field value if set, nil otherwise +// and a boolean to check if the value has been set. +// NOTE: If the value is an explicit nil, `nil, true` will be returned +func (o *IcmpFirewallRule) GetNameOk() (*string, bool) { + if o == nil { + return nil, false + } + return o.Name.Get(), o.Name.IsSet() +} + +// HasName returns a boolean if a field has been set. +func (o *IcmpFirewallRule) HasName() bool { + if o != nil && o.Name.IsSet() { + return true + } + + return false +} + +// SetName gets a reference to the given NullableString and assigns it to the Name field. +func (o *IcmpFirewallRule) SetName(v string) { + o.Name.Set(&v) +} +// SetNameNil sets the value for Name to be an explicit nil +func (o *IcmpFirewallRule) SetNameNil() { + o.Name.Set(nil) +} + +// UnsetName ensures that no value is present for Name, not even an explicit nil +func (o *IcmpFirewallRule) UnsetName() { + o.Name.Unset() +} + +// GetCidr returns the Cidr field value if set, zero value otherwise. +func (o *IcmpFirewallRule) GetCidr() string { + if o == nil || IsNil(o.Cidr) { + var ret string + return ret + } + return *o.Cidr +} + +// GetCidrOk returns a tuple with the Cidr field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *IcmpFirewallRule) GetCidrOk() (*string, bool) { + if o == nil || IsNil(o.Cidr) { + return nil, false + } + return o.Cidr, true +} + +// HasCidr returns a boolean if a field has been set. +func (o *IcmpFirewallRule) HasCidr() bool { + if o != nil && !IsNil(o.Cidr) { + return true + } + + return false +} + +// SetCidr gets a reference to the given string and assigns it to the Cidr field. +func (o *IcmpFirewallRule) SetCidr(v string) { + o.Cidr = &v +} + +// GetProtocol returns the Protocol field value if set, zero value otherwise. +func (o *IcmpFirewallRule) GetProtocol() string { + if o == nil || IsNil(o.Protocol) { + var ret string + return ret + } + return *o.Protocol +} + +// GetProtocolOk returns a tuple with the Protocol field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *IcmpFirewallRule) GetProtocolOk() (*string, bool) { + if o == nil || IsNil(o.Protocol) { + return nil, false + } + return o.Protocol, true +} + +// HasProtocol returns a boolean if a field has been set. +func (o *IcmpFirewallRule) HasProtocol() bool { + if o != nil && !IsNil(o.Protocol) { + return true + } + + return false +} + +// SetProtocol gets a reference to the given string and assigns it to the Protocol field. +func (o *IcmpFirewallRule) SetProtocol(v string) { + o.Protocol = &v +} + +// GetStartPort returns the StartPort field value if set, zero value otherwise (both if not set or set to explicit null). +func (o *IcmpFirewallRule) GetStartPort() int32 { + if o == nil || IsNil(o.StartPort.Get()) { + var ret int32 + return ret + } + return *o.StartPort.Get() +} + +// GetStartPortOk returns a tuple with the StartPort field value if set, nil otherwise +// and a boolean to check if the value has been set. +// NOTE: If the value is an explicit nil, `nil, true` will be returned +func (o *IcmpFirewallRule) GetStartPortOk() (*int32, bool) { + if o == nil { + return nil, false + } + return o.StartPort.Get(), o.StartPort.IsSet() +} + +// HasStartPort returns a boolean if a field has been set. +func (o *IcmpFirewallRule) HasStartPort() bool { + if o != nil && o.StartPort.IsSet() { + return true + } + + return false +} + +// SetStartPort gets a reference to the given NullableInt32 and assigns it to the StartPort field. +func (o *IcmpFirewallRule) SetStartPort(v int32) { + o.StartPort.Set(&v) +} +// SetStartPortNil sets the value for StartPort to be an explicit nil +func (o *IcmpFirewallRule) SetStartPortNil() { + o.StartPort.Set(nil) +} + +// UnsetStartPort ensures that no value is present for StartPort, not even an explicit nil +func (o *IcmpFirewallRule) UnsetStartPort() { + o.StartPort.Unset() +} + +// GetEndPort returns the EndPort field value if set, zero value otherwise (both if not set or set to explicit null). +func (o *IcmpFirewallRule) GetEndPort() int32 { + if o == nil || IsNil(o.EndPort.Get()) { + var ret int32 + return ret + } + return *o.EndPort.Get() +} + +// GetEndPortOk returns a tuple with the EndPort field value if set, nil otherwise +// and a boolean to check if the value has been set. +// NOTE: If the value is an explicit nil, `nil, true` will be returned +func (o *IcmpFirewallRule) GetEndPortOk() (*int32, bool) { + if o == nil { + return nil, false + } + return o.EndPort.Get(), o.EndPort.IsSet() +} + +// HasEndPort returns a boolean if a field has been set. +func (o *IcmpFirewallRule) HasEndPort() bool { + if o != nil && o.EndPort.IsSet() { + return true + } + + return false +} + +// SetEndPort gets a reference to the given NullableInt32 and assigns it to the EndPort field. +func (o *IcmpFirewallRule) SetEndPort(v int32) { + o.EndPort.Set(&v) +} +// SetEndPortNil sets the value for EndPort to be an explicit nil +func (o *IcmpFirewallRule) SetEndPortNil() { + o.EndPort.Set(nil) +} + +// UnsetEndPort ensures that no value is present for EndPort, not even an explicit nil +func (o *IcmpFirewallRule) UnsetEndPort() { + o.EndPort.Unset() +} + +// GetIcmpType returns the IcmpType field value +func (o *IcmpFirewallRule) GetIcmpType() int32 { + if o == nil { + var ret int32 + return ret + } + + return o.IcmpType +} + +// GetIcmpTypeOk returns a tuple with the IcmpType field value +// and a boolean to check if the value has been set. +func (o *IcmpFirewallRule) GetIcmpTypeOk() (*int32, bool) { + if o == nil { + return nil, false + } + return &o.IcmpType, true +} + +// SetIcmpType sets field value +func (o *IcmpFirewallRule) SetIcmpType(v int32) { + o.IcmpType = v +} + +// GetIcmpCode returns the IcmpCode field value +func (o *IcmpFirewallRule) GetIcmpCode() int32 { + if o == nil { + var ret int32 + return ret + } + + return o.IcmpCode +} + +// GetIcmpCodeOk returns a tuple with the IcmpCode field value +// and a boolean to check if the value has been set. +func (o *IcmpFirewallRule) GetIcmpCodeOk() (*int32, bool) { + if o == nil { + return nil, false + } + return &o.IcmpCode, true +} + +// SetIcmpCode sets field value +func (o *IcmpFirewallRule) SetIcmpCode(v int32) { + o.IcmpCode = v +} + +func (o IcmpFirewallRule) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o IcmpFirewallRule) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Id) { + toSerialize["id"] = o.Id + } + if o.Name.IsSet() { + toSerialize["name"] = o.Name.Get() + } + if !IsNil(o.Cidr) { + toSerialize["cidr"] = o.Cidr + } + if !IsNil(o.Protocol) { + toSerialize["protocol"] = o.Protocol + } + if o.StartPort.IsSet() { + toSerialize["startPort"] = o.StartPort.Get() + } + if o.EndPort.IsSet() { + toSerialize["endPort"] = o.EndPort.Get() + } + toSerialize["icmpType"] = o.IcmpType + toSerialize["icmpCode"] = o.IcmpCode + return toSerialize, nil +} + +func (o *IcmpFirewallRule) UnmarshalJSON(data []byte) (err error) { + // This validates that all required properties are included in the JSON object + // by unmarshalling the object into a generic map with string keys and checking + // that every required field exists as a key in the generic map. + requiredProperties := []string{ + "icmpType", + "icmpCode", + } + + allProperties := make(map[string]interface{}) + + err = json.Unmarshal(data, &allProperties) + + if err != nil { + return err; + } + + for _, requiredProperty := range(requiredProperties) { + if _, exists := allProperties[requiredProperty]; !exists { + return fmt.Errorf("no value given for required property %v", requiredProperty) + } + } + + varIcmpFirewallRule := _IcmpFirewallRule{} + + decoder := json.NewDecoder(bytes.NewReader(data)) + decoder.DisallowUnknownFields() + err = decoder.Decode(&varIcmpFirewallRule) + + if err != nil { + return err + } + + *o = IcmpFirewallRule(varIcmpFirewallRule) + + return err +} + +type NullableIcmpFirewallRule struct { + value *IcmpFirewallRule + isSet bool +} + +func (v NullableIcmpFirewallRule) Get() *IcmpFirewallRule { + return v.value +} + +func (v *NullableIcmpFirewallRule) Set(val *IcmpFirewallRule) { + v.value = val + v.isSet = true +} + +func (v NullableIcmpFirewallRule) IsSet() bool { + return v.isSet +} + +func (v *NullableIcmpFirewallRule) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableIcmpFirewallRule(val *IcmpFirewallRule) *NullableIcmpFirewallRule { + return &NullableIcmpFirewallRule{value: val, isSet: true} +} + +func (v NullableIcmpFirewallRule) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableIcmpFirewallRule) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/publicCloud/model_instance.go b/publicCloud/model_instance.go new file mode 100644 index 0000000..fc6d529 --- /dev/null +++ b/publicCloud/model_instance.go @@ -0,0 +1,785 @@ +/* +LeaseWeb API for launching and managing Public Cloud instances + +> The base URL for this API is: **https://api.leaseweb.com/publicCloud/v1/_** This API provides ways to launch and manage Public Cloud instances.
BETA
This API is in BETA. Documentation might be incorrect or incomplete. Functionality might change with the final release.> + +API version: v1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package publicCloud + +import ( + "encoding/json" + "time" +) + +// checks if the Instance type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &Instance{} + +// Instance struct for Instance +type Instance struct { + // The customer ID who owns the instance + CustomerId *string `json:"customerId,omitempty"` + // The instance unique identifier + Id *string `json:"id,omitempty"` + Resources *InstanceResources `json:"resources,omitempty"` + // The region where the instance was launched into + Region *string `json:"region,omitempty"` + // The identifying name set to the instance + Reference *string `json:"reference,omitempty"` + OperatingSystem *OperatingSystem `json:"operatingSystem,omitempty"` + State *InstanceState `json:"state,omitempty"` + HasPublicIpV4 *bool `json:"hasPublicIpV4,omitempty"` + HasPrivateNetwork *bool `json:"hasPrivateNetwork,omitempty"` + // Instance type + Type *string `json:"type,omitempty"` + // The root disk size as specified during its launch or update, in GB + RootDiskSize *int32 `json:"rootDiskSize,omitempty"` + Ips []Ip `json:"ips,omitempty"` + BillingFrequency *int32 `json:"billingFrequency,omitempty"` + // The contract commitment (in months) + ContractTerm *int32 `json:"contractTerm,omitempty"` + ContractType *ContractType `json:"contractType,omitempty"` + ContractEndsAt *time.Time `json:"contractEndsAt,omitempty"` + // Date and time when the instance was started for the first time, right after launching it + StartedAt *time.Time `json:"startedAt,omitempty"` + // Date when the contract will be automatically renewed + ContractRenewalsAt *time.Time `json:"contractRenewalsAt,omitempty"` + // Date when the contract was created + ContractCreatedAt *time.Time `json:"contractCreatedAt,omitempty"` +} + +// NewInstance instantiates a new Instance object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewInstance() *Instance { + this := Instance{} + return &this +} + +// NewInstanceWithDefaults instantiates a new Instance object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewInstanceWithDefaults() *Instance { + this := Instance{} + return &this +} + +// GetCustomerId returns the CustomerId field value if set, zero value otherwise. +func (o *Instance) GetCustomerId() string { + if o == nil || IsNil(o.CustomerId) { + var ret string + return ret + } + return *o.CustomerId +} + +// GetCustomerIdOk returns a tuple with the CustomerId field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Instance) GetCustomerIdOk() (*string, bool) { + if o == nil || IsNil(o.CustomerId) { + return nil, false + } + return o.CustomerId, true +} + +// HasCustomerId returns a boolean if a field has been set. +func (o *Instance) HasCustomerId() bool { + if o != nil && !IsNil(o.CustomerId) { + return true + } + + return false +} + +// SetCustomerId gets a reference to the given string and assigns it to the CustomerId field. +func (o *Instance) SetCustomerId(v string) { + o.CustomerId = &v +} + +// GetId returns the Id field value if set, zero value otherwise. +func (o *Instance) GetId() string { + if o == nil || IsNil(o.Id) { + var ret string + return ret + } + return *o.Id +} + +// GetIdOk returns a tuple with the Id field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Instance) GetIdOk() (*string, bool) { + if o == nil || IsNil(o.Id) { + return nil, false + } + return o.Id, true +} + +// HasId returns a boolean if a field has been set. +func (o *Instance) HasId() bool { + if o != nil && !IsNil(o.Id) { + return true + } + + return false +} + +// SetId gets a reference to the given string and assigns it to the Id field. +func (o *Instance) SetId(v string) { + o.Id = &v +} + +// GetResources returns the Resources field value if set, zero value otherwise. +func (o *Instance) GetResources() InstanceResources { + if o == nil || IsNil(o.Resources) { + var ret InstanceResources + return ret + } + return *o.Resources +} + +// GetResourcesOk returns a tuple with the Resources field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Instance) GetResourcesOk() (*InstanceResources, bool) { + if o == nil || IsNil(o.Resources) { + return nil, false + } + return o.Resources, true +} + +// HasResources returns a boolean if a field has been set. +func (o *Instance) HasResources() bool { + if o != nil && !IsNil(o.Resources) { + return true + } + + return false +} + +// SetResources gets a reference to the given InstanceResources and assigns it to the Resources field. +func (o *Instance) SetResources(v InstanceResources) { + o.Resources = &v +} + +// GetRegion returns the Region field value if set, zero value otherwise. +func (o *Instance) GetRegion() string { + if o == nil || IsNil(o.Region) { + var ret string + return ret + } + return *o.Region +} + +// GetRegionOk returns a tuple with the Region field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Instance) GetRegionOk() (*string, bool) { + if o == nil || IsNil(o.Region) { + return nil, false + } + return o.Region, true +} + +// HasRegion returns a boolean if a field has been set. +func (o *Instance) HasRegion() bool { + if o != nil && !IsNil(o.Region) { + return true + } + + return false +} + +// SetRegion gets a reference to the given string and assigns it to the Region field. +func (o *Instance) SetRegion(v string) { + o.Region = &v +} + +// GetReference returns the Reference field value if set, zero value otherwise. +func (o *Instance) GetReference() string { + if o == nil || IsNil(o.Reference) { + var ret string + return ret + } + return *o.Reference +} + +// GetReferenceOk returns a tuple with the Reference field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Instance) GetReferenceOk() (*string, bool) { + if o == nil || IsNil(o.Reference) { + return nil, false + } + return o.Reference, true +} + +// HasReference returns a boolean if a field has been set. +func (o *Instance) HasReference() bool { + if o != nil && !IsNil(o.Reference) { + return true + } + + return false +} + +// SetReference gets a reference to the given string and assigns it to the Reference field. +func (o *Instance) SetReference(v string) { + o.Reference = &v +} + +// GetOperatingSystem returns the OperatingSystem field value if set, zero value otherwise. +func (o *Instance) GetOperatingSystem() OperatingSystem { + if o == nil || IsNil(o.OperatingSystem) { + var ret OperatingSystem + return ret + } + return *o.OperatingSystem +} + +// GetOperatingSystemOk returns a tuple with the OperatingSystem field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Instance) GetOperatingSystemOk() (*OperatingSystem, bool) { + if o == nil || IsNil(o.OperatingSystem) { + return nil, false + } + return o.OperatingSystem, true +} + +// HasOperatingSystem returns a boolean if a field has been set. +func (o *Instance) HasOperatingSystem() bool { + if o != nil && !IsNil(o.OperatingSystem) { + return true + } + + return false +} + +// SetOperatingSystem gets a reference to the given OperatingSystem and assigns it to the OperatingSystem field. +func (o *Instance) SetOperatingSystem(v OperatingSystem) { + o.OperatingSystem = &v +} + +// GetState returns the State field value if set, zero value otherwise. +func (o *Instance) GetState() InstanceState { + if o == nil || IsNil(o.State) { + var ret InstanceState + return ret + } + return *o.State +} + +// GetStateOk returns a tuple with the State field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Instance) GetStateOk() (*InstanceState, bool) { + if o == nil || IsNil(o.State) { + return nil, false + } + return o.State, true +} + +// HasState returns a boolean if a field has been set. +func (o *Instance) HasState() bool { + if o != nil && !IsNil(o.State) { + return true + } + + return false +} + +// SetState gets a reference to the given InstanceState and assigns it to the State field. +func (o *Instance) SetState(v InstanceState) { + o.State = &v +} + +// GetHasPublicIpV4 returns the HasPublicIpV4 field value if set, zero value otherwise. +func (o *Instance) GetHasPublicIpV4() bool { + if o == nil || IsNil(o.HasPublicIpV4) { + var ret bool + return ret + } + return *o.HasPublicIpV4 +} + +// GetHasPublicIpV4Ok returns a tuple with the HasPublicIpV4 field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Instance) GetHasPublicIpV4Ok() (*bool, bool) { + if o == nil || IsNil(o.HasPublicIpV4) { + return nil, false + } + return o.HasPublicIpV4, true +} + +// HasHasPublicIpV4 returns a boolean if a field has been set. +func (o *Instance) HasHasPublicIpV4() bool { + if o != nil && !IsNil(o.HasPublicIpV4) { + return true + } + + return false +} + +// SetHasPublicIpV4 gets a reference to the given bool and assigns it to the HasPublicIpV4 field. +func (o *Instance) SetHasPublicIpV4(v bool) { + o.HasPublicIpV4 = &v +} + +// GetHasPrivateNetwork returns the HasPrivateNetwork field value if set, zero value otherwise. +func (o *Instance) GetHasPrivateNetwork() bool { + if o == nil || IsNil(o.HasPrivateNetwork) { + var ret bool + return ret + } + return *o.HasPrivateNetwork +} + +// GetHasPrivateNetworkOk returns a tuple with the HasPrivateNetwork field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Instance) GetHasPrivateNetworkOk() (*bool, bool) { + if o == nil || IsNil(o.HasPrivateNetwork) { + return nil, false + } + return o.HasPrivateNetwork, true +} + +// HasHasPrivateNetwork returns a boolean if a field has been set. +func (o *Instance) HasHasPrivateNetwork() bool { + if o != nil && !IsNil(o.HasPrivateNetwork) { + return true + } + + return false +} + +// SetHasPrivateNetwork gets a reference to the given bool and assigns it to the HasPrivateNetwork field. +func (o *Instance) SetHasPrivateNetwork(v bool) { + o.HasPrivateNetwork = &v +} + +// GetType returns the Type field value if set, zero value otherwise. +func (o *Instance) GetType() string { + if o == nil || IsNil(o.Type) { + var ret string + return ret + } + return *o.Type +} + +// GetTypeOk returns a tuple with the Type field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Instance) GetTypeOk() (*string, bool) { + if o == nil || IsNil(o.Type) { + return nil, false + } + return o.Type, true +} + +// HasType returns a boolean if a field has been set. +func (o *Instance) HasType() bool { + if o != nil && !IsNil(o.Type) { + return true + } + + return false +} + +// SetType gets a reference to the given string and assigns it to the Type field. +func (o *Instance) SetType(v string) { + o.Type = &v +} + +// GetRootDiskSize returns the RootDiskSize field value if set, zero value otherwise. +func (o *Instance) GetRootDiskSize() int32 { + if o == nil || IsNil(o.RootDiskSize) { + var ret int32 + return ret + } + return *o.RootDiskSize +} + +// GetRootDiskSizeOk returns a tuple with the RootDiskSize field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Instance) GetRootDiskSizeOk() (*int32, bool) { + if o == nil || IsNil(o.RootDiskSize) { + return nil, false + } + return o.RootDiskSize, true +} + +// HasRootDiskSize returns a boolean if a field has been set. +func (o *Instance) HasRootDiskSize() bool { + if o != nil && !IsNil(o.RootDiskSize) { + return true + } + + return false +} + +// SetRootDiskSize gets a reference to the given int32 and assigns it to the RootDiskSize field. +func (o *Instance) SetRootDiskSize(v int32) { + o.RootDiskSize = &v +} + +// GetIps returns the Ips field value if set, zero value otherwise. +func (o *Instance) GetIps() []Ip { + if o == nil || IsNil(o.Ips) { + var ret []Ip + return ret + } + return o.Ips +} + +// GetIpsOk returns a tuple with the Ips field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Instance) GetIpsOk() ([]Ip, bool) { + if o == nil || IsNil(o.Ips) { + return nil, false + } + return o.Ips, true +} + +// HasIps returns a boolean if a field has been set. +func (o *Instance) HasIps() bool { + if o != nil && !IsNil(o.Ips) { + return true + } + + return false +} + +// SetIps gets a reference to the given []Ip and assigns it to the Ips field. +func (o *Instance) SetIps(v []Ip) { + o.Ips = v +} + +// GetBillingFrequency returns the BillingFrequency field value if set, zero value otherwise. +func (o *Instance) GetBillingFrequency() int32 { + if o == nil || IsNil(o.BillingFrequency) { + var ret int32 + return ret + } + return *o.BillingFrequency +} + +// GetBillingFrequencyOk returns a tuple with the BillingFrequency field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Instance) GetBillingFrequencyOk() (*int32, bool) { + if o == nil || IsNil(o.BillingFrequency) { + return nil, false + } + return o.BillingFrequency, true +} + +// HasBillingFrequency returns a boolean if a field has been set. +func (o *Instance) HasBillingFrequency() bool { + if o != nil && !IsNil(o.BillingFrequency) { + return true + } + + return false +} + +// SetBillingFrequency gets a reference to the given int32 and assigns it to the BillingFrequency field. +func (o *Instance) SetBillingFrequency(v int32) { + o.BillingFrequency = &v +} + +// GetContractTerm returns the ContractTerm field value if set, zero value otherwise. +func (o *Instance) GetContractTerm() int32 { + if o == nil || IsNil(o.ContractTerm) { + var ret int32 + return ret + } + return *o.ContractTerm +} + +// GetContractTermOk returns a tuple with the ContractTerm field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Instance) GetContractTermOk() (*int32, bool) { + if o == nil || IsNil(o.ContractTerm) { + return nil, false + } + return o.ContractTerm, true +} + +// HasContractTerm returns a boolean if a field has been set. +func (o *Instance) HasContractTerm() bool { + if o != nil && !IsNil(o.ContractTerm) { + return true + } + + return false +} + +// SetContractTerm gets a reference to the given int32 and assigns it to the ContractTerm field. +func (o *Instance) SetContractTerm(v int32) { + o.ContractTerm = &v +} + +// GetContractType returns the ContractType field value if set, zero value otherwise. +func (o *Instance) GetContractType() ContractType { + if o == nil || IsNil(o.ContractType) { + var ret ContractType + return ret + } + return *o.ContractType +} + +// GetContractTypeOk returns a tuple with the ContractType field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Instance) GetContractTypeOk() (*ContractType, bool) { + if o == nil || IsNil(o.ContractType) { + return nil, false + } + return o.ContractType, true +} + +// HasContractType returns a boolean if a field has been set. +func (o *Instance) HasContractType() bool { + if o != nil && !IsNil(o.ContractType) { + return true + } + + return false +} + +// SetContractType gets a reference to the given ContractType and assigns it to the ContractType field. +func (o *Instance) SetContractType(v ContractType) { + o.ContractType = &v +} + +// GetContractEndsAt returns the ContractEndsAt field value if set, zero value otherwise. +func (o *Instance) GetContractEndsAt() time.Time { + if o == nil || IsNil(o.ContractEndsAt) { + var ret time.Time + return ret + } + return *o.ContractEndsAt +} + +// GetContractEndsAtOk returns a tuple with the ContractEndsAt field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Instance) GetContractEndsAtOk() (*time.Time, bool) { + if o == nil || IsNil(o.ContractEndsAt) { + return nil, false + } + return o.ContractEndsAt, true +} + +// HasContractEndsAt returns a boolean if a field has been set. +func (o *Instance) HasContractEndsAt() bool { + if o != nil && !IsNil(o.ContractEndsAt) { + return true + } + + return false +} + +// SetContractEndsAt gets a reference to the given time.Time and assigns it to the ContractEndsAt field. +func (o *Instance) SetContractEndsAt(v time.Time) { + o.ContractEndsAt = &v +} + +// GetStartedAt returns the StartedAt field value if set, zero value otherwise. +func (o *Instance) GetStartedAt() time.Time { + if o == nil || IsNil(o.StartedAt) { + var ret time.Time + return ret + } + return *o.StartedAt +} + +// GetStartedAtOk returns a tuple with the StartedAt field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Instance) GetStartedAtOk() (*time.Time, bool) { + if o == nil || IsNil(o.StartedAt) { + return nil, false + } + return o.StartedAt, true +} + +// HasStartedAt returns a boolean if a field has been set. +func (o *Instance) HasStartedAt() bool { + if o != nil && !IsNil(o.StartedAt) { + return true + } + + return false +} + +// SetStartedAt gets a reference to the given time.Time and assigns it to the StartedAt field. +func (o *Instance) SetStartedAt(v time.Time) { + o.StartedAt = &v +} + +// GetContractRenewalsAt returns the ContractRenewalsAt field value if set, zero value otherwise. +func (o *Instance) GetContractRenewalsAt() time.Time { + if o == nil || IsNil(o.ContractRenewalsAt) { + var ret time.Time + return ret + } + return *o.ContractRenewalsAt +} + +// GetContractRenewalsAtOk returns a tuple with the ContractRenewalsAt field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Instance) GetContractRenewalsAtOk() (*time.Time, bool) { + if o == nil || IsNil(o.ContractRenewalsAt) { + return nil, false + } + return o.ContractRenewalsAt, true +} + +// HasContractRenewalsAt returns a boolean if a field has been set. +func (o *Instance) HasContractRenewalsAt() bool { + if o != nil && !IsNil(o.ContractRenewalsAt) { + return true + } + + return false +} + +// SetContractRenewalsAt gets a reference to the given time.Time and assigns it to the ContractRenewalsAt field. +func (o *Instance) SetContractRenewalsAt(v time.Time) { + o.ContractRenewalsAt = &v +} + +// GetContractCreatedAt returns the ContractCreatedAt field value if set, zero value otherwise. +func (o *Instance) GetContractCreatedAt() time.Time { + if o == nil || IsNil(o.ContractCreatedAt) { + var ret time.Time + return ret + } + return *o.ContractCreatedAt +} + +// GetContractCreatedAtOk returns a tuple with the ContractCreatedAt field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Instance) GetContractCreatedAtOk() (*time.Time, bool) { + if o == nil || IsNil(o.ContractCreatedAt) { + return nil, false + } + return o.ContractCreatedAt, true +} + +// HasContractCreatedAt returns a boolean if a field has been set. +func (o *Instance) HasContractCreatedAt() bool { + if o != nil && !IsNil(o.ContractCreatedAt) { + return true + } + + return false +} + +// SetContractCreatedAt gets a reference to the given time.Time and assigns it to the ContractCreatedAt field. +func (o *Instance) SetContractCreatedAt(v time.Time) { + o.ContractCreatedAt = &v +} + +func (o Instance) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o Instance) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.CustomerId) { + toSerialize["customerId"] = o.CustomerId + } + if !IsNil(o.Id) { + toSerialize["id"] = o.Id + } + if !IsNil(o.Resources) { + toSerialize["resources"] = o.Resources + } + if !IsNil(o.Region) { + toSerialize["region"] = o.Region + } + if !IsNil(o.Reference) { + toSerialize["reference"] = o.Reference + } + if !IsNil(o.OperatingSystem) { + toSerialize["operatingSystem"] = o.OperatingSystem + } + if !IsNil(o.State) { + toSerialize["state"] = o.State + } + if !IsNil(o.HasPublicIpV4) { + toSerialize["hasPublicIpV4"] = o.HasPublicIpV4 + } + if !IsNil(o.HasPrivateNetwork) { + toSerialize["hasPrivateNetwork"] = o.HasPrivateNetwork + } + if !IsNil(o.Type) { + toSerialize["type"] = o.Type + } + if !IsNil(o.RootDiskSize) { + toSerialize["rootDiskSize"] = o.RootDiskSize + } + if !IsNil(o.Ips) { + toSerialize["ips"] = o.Ips + } + if !IsNil(o.BillingFrequency) { + toSerialize["billingFrequency"] = o.BillingFrequency + } + if !IsNil(o.ContractTerm) { + toSerialize["contractTerm"] = o.ContractTerm + } + if !IsNil(o.ContractType) { + toSerialize["contractType"] = o.ContractType + } + if !IsNil(o.ContractEndsAt) { + toSerialize["contractEndsAt"] = o.ContractEndsAt + } + if !IsNil(o.StartedAt) { + toSerialize["startedAt"] = o.StartedAt + } + if !IsNil(o.ContractRenewalsAt) { + toSerialize["contractRenewalsAt"] = o.ContractRenewalsAt + } + if !IsNil(o.ContractCreatedAt) { + toSerialize["contractCreatedAt"] = o.ContractCreatedAt + } + return toSerialize, nil +} + +type NullableInstance struct { + value *Instance + isSet bool +} + +func (v NullableInstance) Get() *Instance { + return v.value +} + +func (v *NullableInstance) Set(val *Instance) { + v.value = val + v.isSet = true +} + +func (v NullableInstance) IsSet() bool { + return v.isSet +} + +func (v *NullableInstance) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableInstance(val *Instance) *NullableInstance { + return &NullableInstance{value: val, isSet: true} +} + +func (v NullableInstance) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableInstance) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/publicCloud/model_instance_resources.go b/publicCloud/model_instance_resources.go new file mode 100644 index 0000000..0284361 --- /dev/null +++ b/publicCloud/model_instance_resources.go @@ -0,0 +1,234 @@ +/* +LeaseWeb API for launching and managing Public Cloud instances + +> The base URL for this API is: **https://api.leaseweb.com/publicCloud/v1/_** This API provides ways to launch and manage Public Cloud instances.
BETA
This API is in BETA. Documentation might be incorrect or incomplete. Functionality might change with the final release.> + +API version: v1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package publicCloud + +import ( + "encoding/json" +) + +// checks if the InstanceResources type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &InstanceResources{} + +// InstanceResources Resources available for the load balancer +type InstanceResources struct { + Cpu *Cpu `json:"cpu,omitempty"` + Memory *Memory `json:"memory,omitempty"` + PublicNetworkSpeed *PublicNetworkSpeed `json:"publicNetworkSpeed,omitempty"` + PrivateNetworkSpeed *PrivateNetworkSpeed `json:"privateNetworkSpeed,omitempty"` +} + +// NewInstanceResources instantiates a new InstanceResources object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewInstanceResources() *InstanceResources { + this := InstanceResources{} + return &this +} + +// NewInstanceResourcesWithDefaults instantiates a new InstanceResources object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewInstanceResourcesWithDefaults() *InstanceResources { + this := InstanceResources{} + return &this +} + +// GetCpu returns the Cpu field value if set, zero value otherwise. +func (o *InstanceResources) GetCpu() Cpu { + if o == nil || IsNil(o.Cpu) { + var ret Cpu + return ret + } + return *o.Cpu +} + +// GetCpuOk returns a tuple with the Cpu field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *InstanceResources) GetCpuOk() (*Cpu, bool) { + if o == nil || IsNil(o.Cpu) { + return nil, false + } + return o.Cpu, true +} + +// HasCpu returns a boolean if a field has been set. +func (o *InstanceResources) HasCpu() bool { + if o != nil && !IsNil(o.Cpu) { + return true + } + + return false +} + +// SetCpu gets a reference to the given Cpu and assigns it to the Cpu field. +func (o *InstanceResources) SetCpu(v Cpu) { + o.Cpu = &v +} + +// GetMemory returns the Memory field value if set, zero value otherwise. +func (o *InstanceResources) GetMemory() Memory { + if o == nil || IsNil(o.Memory) { + var ret Memory + return ret + } + return *o.Memory +} + +// GetMemoryOk returns a tuple with the Memory field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *InstanceResources) GetMemoryOk() (*Memory, bool) { + if o == nil || IsNil(o.Memory) { + return nil, false + } + return o.Memory, true +} + +// HasMemory returns a boolean if a field has been set. +func (o *InstanceResources) HasMemory() bool { + if o != nil && !IsNil(o.Memory) { + return true + } + + return false +} + +// SetMemory gets a reference to the given Memory and assigns it to the Memory field. +func (o *InstanceResources) SetMemory(v Memory) { + o.Memory = &v +} + +// GetPublicNetworkSpeed returns the PublicNetworkSpeed field value if set, zero value otherwise. +func (o *InstanceResources) GetPublicNetworkSpeed() PublicNetworkSpeed { + if o == nil || IsNil(o.PublicNetworkSpeed) { + var ret PublicNetworkSpeed + return ret + } + return *o.PublicNetworkSpeed +} + +// GetPublicNetworkSpeedOk returns a tuple with the PublicNetworkSpeed field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *InstanceResources) GetPublicNetworkSpeedOk() (*PublicNetworkSpeed, bool) { + if o == nil || IsNil(o.PublicNetworkSpeed) { + return nil, false + } + return o.PublicNetworkSpeed, true +} + +// HasPublicNetworkSpeed returns a boolean if a field has been set. +func (o *InstanceResources) HasPublicNetworkSpeed() bool { + if o != nil && !IsNil(o.PublicNetworkSpeed) { + return true + } + + return false +} + +// SetPublicNetworkSpeed gets a reference to the given PublicNetworkSpeed and assigns it to the PublicNetworkSpeed field. +func (o *InstanceResources) SetPublicNetworkSpeed(v PublicNetworkSpeed) { + o.PublicNetworkSpeed = &v +} + +// GetPrivateNetworkSpeed returns the PrivateNetworkSpeed field value if set, zero value otherwise. +func (o *InstanceResources) GetPrivateNetworkSpeed() PrivateNetworkSpeed { + if o == nil || IsNil(o.PrivateNetworkSpeed) { + var ret PrivateNetworkSpeed + return ret + } + return *o.PrivateNetworkSpeed +} + +// GetPrivateNetworkSpeedOk returns a tuple with the PrivateNetworkSpeed field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *InstanceResources) GetPrivateNetworkSpeedOk() (*PrivateNetworkSpeed, bool) { + if o == nil || IsNil(o.PrivateNetworkSpeed) { + return nil, false + } + return o.PrivateNetworkSpeed, true +} + +// HasPrivateNetworkSpeed returns a boolean if a field has been set. +func (o *InstanceResources) HasPrivateNetworkSpeed() bool { + if o != nil && !IsNil(o.PrivateNetworkSpeed) { + return true + } + + return false +} + +// SetPrivateNetworkSpeed gets a reference to the given PrivateNetworkSpeed and assigns it to the PrivateNetworkSpeed field. +func (o *InstanceResources) SetPrivateNetworkSpeed(v PrivateNetworkSpeed) { + o.PrivateNetworkSpeed = &v +} + +func (o InstanceResources) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o InstanceResources) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Cpu) { + toSerialize["cpu"] = o.Cpu + } + if !IsNil(o.Memory) { + toSerialize["memory"] = o.Memory + } + if !IsNil(o.PublicNetworkSpeed) { + toSerialize["publicNetworkSpeed"] = o.PublicNetworkSpeed + } + if !IsNil(o.PrivateNetworkSpeed) { + toSerialize["privateNetworkSpeed"] = o.PrivateNetworkSpeed + } + return toSerialize, nil +} + +type NullableInstanceResources struct { + value *InstanceResources + isSet bool +} + +func (v NullableInstanceResources) Get() *InstanceResources { + return v.value +} + +func (v *NullableInstanceResources) Set(val *InstanceResources) { + v.value = val + v.isSet = true +} + +func (v NullableInstanceResources) IsSet() bool { + return v.isSet +} + +func (v *NullableInstanceResources) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableInstanceResources(val *InstanceResources) *NullableInstanceResources { + return &NullableInstanceResources{value: val, isSet: true} +} + +func (v NullableInstanceResources) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableInstanceResources) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/publicCloud/model_instance_state.go b/publicCloud/model_instance_state.go new file mode 100644 index 0000000..8719053 --- /dev/null +++ b/publicCloud/model_instance_state.go @@ -0,0 +1,117 @@ +/* +LeaseWeb API for launching and managing Public Cloud instances + +> The base URL for this API is: **https://api.leaseweb.com/publicCloud/v1/_** This API provides ways to launch and manage Public Cloud instances.
BETA
This API is in BETA. Documentation might be incorrect or incomplete. Functionality might change with the final release.> + +API version: v1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package publicCloud + +import ( + "encoding/json" + "fmt" +) + +// InstanceState The instance's current state +type InstanceState string + +// List of instanceState +const ( + RUNNING InstanceState = "RUNNING" + STOPPED InstanceState = "STOPPED" + CREATING InstanceState = "CREATING" + DESTROYING InstanceState = "DESTROYING" + DESTROYED InstanceState = "DESTROYED" +) + +// All allowed values of InstanceState enum +var AllowedInstanceStateEnumValues = []InstanceState{ + "RUNNING", + "STOPPED", + "CREATING", + "DESTROYING", + "DESTROYED", +} + +func (v *InstanceState) UnmarshalJSON(src []byte) error { + var value string + err := json.Unmarshal(src, &value) + if err != nil { + return err + } + enumTypeValue := InstanceState(value) + for _, existing := range AllowedInstanceStateEnumValues { + if existing == enumTypeValue { + *v = enumTypeValue + return nil + } + } + + return fmt.Errorf("%+v is not a valid InstanceState", value) +} + +// NewInstanceStateFromValue returns a pointer to a valid InstanceState +// for the value passed as argument, or an error if the value passed is not allowed by the enum +func NewInstanceStateFromValue(v string) (*InstanceState, error) { + ev := InstanceState(v) + if ev.IsValid() { + return &ev, nil + } else { + return nil, fmt.Errorf("invalid value '%v' for InstanceState: valid values are %v", v, AllowedInstanceStateEnumValues) + } +} + +// IsValid return true if the value is valid for the enum, false otherwise +func (v InstanceState) IsValid() bool { + for _, existing := range AllowedInstanceStateEnumValues { + if existing == v { + return true + } + } + return false +} + +// Ptr returns reference to instanceState value +func (v InstanceState) Ptr() *InstanceState { + return &v +} + +type NullableInstanceState struct { + value *InstanceState + isSet bool +} + +func (v NullableInstanceState) Get() *InstanceState { + return v.value +} + +func (v *NullableInstanceState) Set(val *InstanceState) { + v.value = val + v.isSet = true +} + +func (v NullableInstanceState) IsSet() bool { + return v.isSet +} + +func (v *NullableInstanceState) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableInstanceState(val *InstanceState) *NullableInstanceState { + return &NullableInstanceState{value: val, isSet: true} +} + +func (v NullableInstanceState) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableInstanceState) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + diff --git a/publicCloud/model_instance_type_details.go b/publicCloud/model_instance_type_details.go new file mode 100644 index 0000000..73af55e --- /dev/null +++ b/publicCloud/model_instance_type_details.go @@ -0,0 +1,237 @@ +/* +LeaseWeb API for launching and managing Public Cloud instances + +> The base URL for this API is: **https://api.leaseweb.com/publicCloud/v1/_** This API provides ways to launch and manage Public Cloud instances.
BETA
This API is in BETA. Documentation might be incorrect or incomplete. Functionality might change with the final release.> + +API version: v1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package publicCloud + +import ( + "encoding/json" +) + +// checks if the InstanceTypeDetails type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &InstanceTypeDetails{} + +// InstanceTypeDetails struct for InstanceTypeDetails +type InstanceTypeDetails struct { + // Instance type's name + Name *string `json:"name,omitempty"` + Resources *InstanceResources `json:"resources,omitempty"` + // The supported storage types for the instance type + StorageTypes []string `json:"storageTypes,omitempty"` + Prices *Price `json:"prices,omitempty"` +} + +// NewInstanceTypeDetails instantiates a new InstanceTypeDetails object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewInstanceTypeDetails() *InstanceTypeDetails { + this := InstanceTypeDetails{} + return &this +} + +// NewInstanceTypeDetailsWithDefaults instantiates a new InstanceTypeDetails object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewInstanceTypeDetailsWithDefaults() *InstanceTypeDetails { + this := InstanceTypeDetails{} + return &this +} + +// GetName returns the Name field value if set, zero value otherwise. +func (o *InstanceTypeDetails) GetName() string { + if o == nil || IsNil(o.Name) { + var ret string + return ret + } + return *o.Name +} + +// GetNameOk returns a tuple with the Name field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *InstanceTypeDetails) GetNameOk() (*string, bool) { + if o == nil || IsNil(o.Name) { + return nil, false + } + return o.Name, true +} + +// HasName returns a boolean if a field has been set. +func (o *InstanceTypeDetails) HasName() bool { + if o != nil && !IsNil(o.Name) { + return true + } + + return false +} + +// SetName gets a reference to the given string and assigns it to the Name field. +func (o *InstanceTypeDetails) SetName(v string) { + o.Name = &v +} + +// GetResources returns the Resources field value if set, zero value otherwise. +func (o *InstanceTypeDetails) GetResources() InstanceResources { + if o == nil || IsNil(o.Resources) { + var ret InstanceResources + return ret + } + return *o.Resources +} + +// GetResourcesOk returns a tuple with the Resources field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *InstanceTypeDetails) GetResourcesOk() (*InstanceResources, bool) { + if o == nil || IsNil(o.Resources) { + return nil, false + } + return o.Resources, true +} + +// HasResources returns a boolean if a field has been set. +func (o *InstanceTypeDetails) HasResources() bool { + if o != nil && !IsNil(o.Resources) { + return true + } + + return false +} + +// SetResources gets a reference to the given InstanceResources and assigns it to the Resources field. +func (o *InstanceTypeDetails) SetResources(v InstanceResources) { + o.Resources = &v +} + +// GetStorageTypes returns the StorageTypes field value if set, zero value otherwise (both if not set or set to explicit null). +func (o *InstanceTypeDetails) GetStorageTypes() []string { + if o == nil { + var ret []string + return ret + } + return o.StorageTypes +} + +// GetStorageTypesOk returns a tuple with the StorageTypes field value if set, nil otherwise +// and a boolean to check if the value has been set. +// NOTE: If the value is an explicit nil, `nil, true` will be returned +func (o *InstanceTypeDetails) GetStorageTypesOk() ([]string, bool) { + if o == nil || IsNil(o.StorageTypes) { + return nil, false + } + return o.StorageTypes, true +} + +// HasStorageTypes returns a boolean if a field has been set. +func (o *InstanceTypeDetails) HasStorageTypes() bool { + if o != nil && !IsNil(o.StorageTypes) { + return true + } + + return false +} + +// SetStorageTypes gets a reference to the given []string and assigns it to the StorageTypes field. +func (o *InstanceTypeDetails) SetStorageTypes(v []string) { + o.StorageTypes = v +} + +// GetPrices returns the Prices field value if set, zero value otherwise. +func (o *InstanceTypeDetails) GetPrices() Price { + if o == nil || IsNil(o.Prices) { + var ret Price + return ret + } + return *o.Prices +} + +// GetPricesOk returns a tuple with the Prices field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *InstanceTypeDetails) GetPricesOk() (*Price, bool) { + if o == nil || IsNil(o.Prices) { + return nil, false + } + return o.Prices, true +} + +// HasPrices returns a boolean if a field has been set. +func (o *InstanceTypeDetails) HasPrices() bool { + if o != nil && !IsNil(o.Prices) { + return true + } + + return false +} + +// SetPrices gets a reference to the given Price and assigns it to the Prices field. +func (o *InstanceTypeDetails) SetPrices(v Price) { + o.Prices = &v +} + +func (o InstanceTypeDetails) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o InstanceTypeDetails) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Name) { + toSerialize["name"] = o.Name + } + if !IsNil(o.Resources) { + toSerialize["resources"] = o.Resources + } + if o.StorageTypes != nil { + toSerialize["storageTypes"] = o.StorageTypes + } + if !IsNil(o.Prices) { + toSerialize["prices"] = o.Prices + } + return toSerialize, nil +} + +type NullableInstanceTypeDetails struct { + value *InstanceTypeDetails + isSet bool +} + +func (v NullableInstanceTypeDetails) Get() *InstanceTypeDetails { + return v.value +} + +func (v *NullableInstanceTypeDetails) Set(val *InstanceTypeDetails) { + v.value = val + v.isSet = true +} + +func (v NullableInstanceTypeDetails) IsSet() bool { + return v.isSet +} + +func (v *NullableInstanceTypeDetails) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableInstanceTypeDetails(val *InstanceTypeDetails) *NullableInstanceTypeDetails { + return &NullableInstanceTypeDetails{value: val, isSet: true} +} + +func (v NullableInstanceTypeDetails) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableInstanceTypeDetails) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/publicCloud/model_ip.go b/publicCloud/model_ip.go new file mode 100644 index 0000000..42b3b67 --- /dev/null +++ b/publicCloud/model_ip.go @@ -0,0 +1,356 @@ +/* +LeaseWeb API for launching and managing Public Cloud instances + +> The base URL for this API is: **https://api.leaseweb.com/publicCloud/v1/_** This API provides ways to launch and manage Public Cloud instances.
BETA
This API is in BETA. Documentation might be incorrect or incomplete. Functionality might change with the final release.> + +API version: v1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package publicCloud + +import ( + "encoding/json" +) + +// checks if the Ip type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &Ip{} + +// Ip struct for Ip +type Ip struct { + // Ip Address + Ip *string `json:"ip,omitempty"` + // The number of leading bits in the IP address + PrefixLength *string `json:"prefixLength,omitempty"` + // Ip version + Version *int32 `json:"version,omitempty"` + // Whether or not the IP has been nulled + NullRouted *bool `json:"nullRouted,omitempty"` + MainIp *bool `json:"mainIp,omitempty"` + ReverseLookup NullableString `json:"reverseLookup,omitempty"` + Ddos *Ddos `json:"ddos,omitempty"` +} + +// NewIp instantiates a new Ip object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewIp() *Ip { + this := Ip{} + return &this +} + +// NewIpWithDefaults instantiates a new Ip object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewIpWithDefaults() *Ip { + this := Ip{} + return &this +} + +// GetIp returns the Ip field value if set, zero value otherwise. +func (o *Ip) GetIp() string { + if o == nil || IsNil(o.Ip) { + var ret string + return ret + } + return *o.Ip +} + +// GetIpOk returns a tuple with the Ip field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Ip) GetIpOk() (*string, bool) { + if o == nil || IsNil(o.Ip) { + return nil, false + } + return o.Ip, true +} + +// HasIp returns a boolean if a field has been set. +func (o *Ip) HasIp() bool { + if o != nil && !IsNil(o.Ip) { + return true + } + + return false +} + +// SetIp gets a reference to the given string and assigns it to the Ip field. +func (o *Ip) SetIp(v string) { + o.Ip = &v +} + +// GetPrefixLength returns the PrefixLength field value if set, zero value otherwise. +func (o *Ip) GetPrefixLength() string { + if o == nil || IsNil(o.PrefixLength) { + var ret string + return ret + } + return *o.PrefixLength +} + +// GetPrefixLengthOk returns a tuple with the PrefixLength field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Ip) GetPrefixLengthOk() (*string, bool) { + if o == nil || IsNil(o.PrefixLength) { + return nil, false + } + return o.PrefixLength, true +} + +// HasPrefixLength returns a boolean if a field has been set. +func (o *Ip) HasPrefixLength() bool { + if o != nil && !IsNil(o.PrefixLength) { + return true + } + + return false +} + +// SetPrefixLength gets a reference to the given string and assigns it to the PrefixLength field. +func (o *Ip) SetPrefixLength(v string) { + o.PrefixLength = &v +} + +// GetVersion returns the Version field value if set, zero value otherwise. +func (o *Ip) GetVersion() int32 { + if o == nil || IsNil(o.Version) { + var ret int32 + return ret + } + return *o.Version +} + +// GetVersionOk returns a tuple with the Version field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Ip) GetVersionOk() (*int32, bool) { + if o == nil || IsNil(o.Version) { + return nil, false + } + return o.Version, true +} + +// HasVersion returns a boolean if a field has been set. +func (o *Ip) HasVersion() bool { + if o != nil && !IsNil(o.Version) { + return true + } + + return false +} + +// SetVersion gets a reference to the given int32 and assigns it to the Version field. +func (o *Ip) SetVersion(v int32) { + o.Version = &v +} + +// GetNullRouted returns the NullRouted field value if set, zero value otherwise. +func (o *Ip) GetNullRouted() bool { + if o == nil || IsNil(o.NullRouted) { + var ret bool + return ret + } + return *o.NullRouted +} + +// GetNullRoutedOk returns a tuple with the NullRouted field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Ip) GetNullRoutedOk() (*bool, bool) { + if o == nil || IsNil(o.NullRouted) { + return nil, false + } + return o.NullRouted, true +} + +// HasNullRouted returns a boolean if a field has been set. +func (o *Ip) HasNullRouted() bool { + if o != nil && !IsNil(o.NullRouted) { + return true + } + + return false +} + +// SetNullRouted gets a reference to the given bool and assigns it to the NullRouted field. +func (o *Ip) SetNullRouted(v bool) { + o.NullRouted = &v +} + +// GetMainIp returns the MainIp field value if set, zero value otherwise. +func (o *Ip) GetMainIp() bool { + if o == nil || IsNil(o.MainIp) { + var ret bool + return ret + } + return *o.MainIp +} + +// GetMainIpOk returns a tuple with the MainIp field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Ip) GetMainIpOk() (*bool, bool) { + if o == nil || IsNil(o.MainIp) { + return nil, false + } + return o.MainIp, true +} + +// HasMainIp returns a boolean if a field has been set. +func (o *Ip) HasMainIp() bool { + if o != nil && !IsNil(o.MainIp) { + return true + } + + return false +} + +// SetMainIp gets a reference to the given bool and assigns it to the MainIp field. +func (o *Ip) SetMainIp(v bool) { + o.MainIp = &v +} + +// GetReverseLookup returns the ReverseLookup field value if set, zero value otherwise (both if not set or set to explicit null). +func (o *Ip) GetReverseLookup() string { + if o == nil || IsNil(o.ReverseLookup.Get()) { + var ret string + return ret + } + return *o.ReverseLookup.Get() +} + +// GetReverseLookupOk returns a tuple with the ReverseLookup field value if set, nil otherwise +// and a boolean to check if the value has been set. +// NOTE: If the value is an explicit nil, `nil, true` will be returned +func (o *Ip) GetReverseLookupOk() (*string, bool) { + if o == nil { + return nil, false + } + return o.ReverseLookup.Get(), o.ReverseLookup.IsSet() +} + +// HasReverseLookup returns a boolean if a field has been set. +func (o *Ip) HasReverseLookup() bool { + if o != nil && o.ReverseLookup.IsSet() { + return true + } + + return false +} + +// SetReverseLookup gets a reference to the given NullableString and assigns it to the ReverseLookup field. +func (o *Ip) SetReverseLookup(v string) { + o.ReverseLookup.Set(&v) +} +// SetReverseLookupNil sets the value for ReverseLookup to be an explicit nil +func (o *Ip) SetReverseLookupNil() { + o.ReverseLookup.Set(nil) +} + +// UnsetReverseLookup ensures that no value is present for ReverseLookup, not even an explicit nil +func (o *Ip) UnsetReverseLookup() { + o.ReverseLookup.Unset() +} + +// GetDdos returns the Ddos field value if set, zero value otherwise. +func (o *Ip) GetDdos() Ddos { + if o == nil || IsNil(o.Ddos) { + var ret Ddos + return ret + } + return *o.Ddos +} + +// GetDdosOk returns a tuple with the Ddos field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Ip) GetDdosOk() (*Ddos, bool) { + if o == nil || IsNil(o.Ddos) { + return nil, false + } + return o.Ddos, true +} + +// HasDdos returns a boolean if a field has been set. +func (o *Ip) HasDdos() bool { + if o != nil && !IsNil(o.Ddos) { + return true + } + + return false +} + +// SetDdos gets a reference to the given Ddos and assigns it to the Ddos field. +func (o *Ip) SetDdos(v Ddos) { + o.Ddos = &v +} + +func (o Ip) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o Ip) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Ip) { + toSerialize["ip"] = o.Ip + } + if !IsNil(o.PrefixLength) { + toSerialize["prefixLength"] = o.PrefixLength + } + if !IsNil(o.Version) { + toSerialize["version"] = o.Version + } + if !IsNil(o.NullRouted) { + toSerialize["nullRouted"] = o.NullRouted + } + if !IsNil(o.MainIp) { + toSerialize["mainIp"] = o.MainIp + } + if o.ReverseLookup.IsSet() { + toSerialize["reverseLookup"] = o.ReverseLookup.Get() + } + if !IsNil(o.Ddos) { + toSerialize["ddos"] = o.Ddos + } + return toSerialize, nil +} + +type NullableIp struct { + value *Ip + isSet bool +} + +func (v NullableIp) Get() *Ip { + return v.value +} + +func (v *NullableIp) Set(val *Ip) { + v.value = val + v.isSet = true +} + +func (v NullableIp) IsSet() bool { + return v.isSet +} + +func (v *NullableIp) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableIp(val *Ip) *NullableIp { + return &NullableIp{value: val, isSet: true} +} + +func (v NullableIp) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableIp) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/publicCloud/model_iso.go b/publicCloud/model_iso.go new file mode 100644 index 0000000..e29e2b9 --- /dev/null +++ b/publicCloud/model_iso.go @@ -0,0 +1,162 @@ +/* +LeaseWeb API for launching and managing Public Cloud instances + +> The base URL for this API is: **https://api.leaseweb.com/publicCloud/v1/_** This API provides ways to launch and manage Public Cloud instances.
BETA
This API is in BETA. Documentation might be incorrect or incomplete. Functionality might change with the final release.> + +API version: v1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package publicCloud + +import ( + "encoding/json" +) + +// checks if the Iso type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &Iso{} + +// Iso struct for Iso +type Iso struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` +} + +// NewIso instantiates a new Iso object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewIso() *Iso { + this := Iso{} + return &this +} + +// NewIsoWithDefaults instantiates a new Iso object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewIsoWithDefaults() *Iso { + this := Iso{} + return &this +} + +// GetId returns the Id field value if set, zero value otherwise. +func (o *Iso) GetId() string { + if o == nil || IsNil(o.Id) { + var ret string + return ret + } + return *o.Id +} + +// GetIdOk returns a tuple with the Id field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Iso) GetIdOk() (*string, bool) { + if o == nil || IsNil(o.Id) { + return nil, false + } + return o.Id, true +} + +// HasId returns a boolean if a field has been set. +func (o *Iso) HasId() bool { + if o != nil && !IsNil(o.Id) { + return true + } + + return false +} + +// SetId gets a reference to the given string and assigns it to the Id field. +func (o *Iso) SetId(v string) { + o.Id = &v +} + +// GetName returns the Name field value if set, zero value otherwise. +func (o *Iso) GetName() string { + if o == nil || IsNil(o.Name) { + var ret string + return ret + } + return *o.Name +} + +// GetNameOk returns a tuple with the Name field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Iso) GetNameOk() (*string, bool) { + if o == nil || IsNil(o.Name) { + return nil, false + } + return o.Name, true +} + +// HasName returns a boolean if a field has been set. +func (o *Iso) HasName() bool { + if o != nil && !IsNil(o.Name) { + return true + } + + return false +} + +// SetName gets a reference to the given string and assigns it to the Name field. +func (o *Iso) SetName(v string) { + o.Name = &v +} + +func (o Iso) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o Iso) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Id) { + toSerialize["id"] = o.Id + } + if !IsNil(o.Name) { + toSerialize["name"] = o.Name + } + return toSerialize, nil +} + +type NullableIso struct { + value *Iso + isSet bool +} + +func (v NullableIso) Get() *Iso { + return v.value +} + +func (v *NullableIso) Set(val *Iso) { + v.value = val + v.isSet = true +} + +func (v NullableIso) IsSet() bool { + return v.isSet +} + +func (v *NullableIso) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableIso(val *Iso) *NullableIso { + return &NullableIso{value: val, isSet: true} +} + +func (v NullableIso) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableIso) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/publicCloud/model_launch_instance_created_result.go b/publicCloud/model_launch_instance_created_result.go new file mode 100644 index 0000000..04945c0 --- /dev/null +++ b/publicCloud/model_launch_instance_created_result.go @@ -0,0 +1,935 @@ +/* +LeaseWeb API for launching and managing Public Cloud instances + +> The base URL for this API is: **https://api.leaseweb.com/publicCloud/v1/_** This API provides ways to launch and manage Public Cloud instances.
BETA
This API is in BETA. Documentation might be incorrect or incomplete. Functionality might change with the final release.> + +API version: v1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package publicCloud + +import ( + "encoding/json" + "time" +) + +// checks if the LaunchInstanceCreatedResult type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &LaunchInstanceCreatedResult{} + +// LaunchInstanceCreatedResult struct for LaunchInstanceCreatedResult +type LaunchInstanceCreatedResult struct { + // The customer ID who owns the instance + CustomerId *string `json:"customerId,omitempty"` + // The instance unique identifier + Id *string `json:"id,omitempty"` + Resources *InstanceResources `json:"resources,omitempty"` + // The region where the instance was launched into + Region *string `json:"region,omitempty"` + // The identifying name set to the instance + Reference *string `json:"reference,omitempty"` + OperatingSystem *OperatingSystem `json:"operatingSystem,omitempty"` + State *InstanceState `json:"state,omitempty"` + PublicIpV4 *bool `json:"publicIpV4,omitempty"` + // Instance type + Type *string `json:"type,omitempty"` + PrivateNetwork *bool `json:"privateNetwork,omitempty"` + // The root disk size as specified during its launch or update, in GB + RootDiskSize *int32 `json:"rootDiskSize,omitempty"` + // The root disk's storage type + RootDiskStorageType *string `json:"rootDiskStorageType,omitempty"` + Ips []Ip `json:"ips,omitempty"` + BillingFrequency *int32 `json:"billingFrequency,omitempty"` + // The contract commitment (in months) + ContractTerm *int32 `json:"contractTerm,omitempty"` + ContractType *ContractType `json:"contractType,omitempty"` + ContractEndsAt NullableTime `json:"contractEndsAt,omitempty"` + // Date and time when the instance was started for the first time, right after launching it + StartedAt NullableTime `json:"startedAt,omitempty"` + // Date when the contract will be automatically renewed + ContractRenewalsAt *time.Time `json:"contractRenewalsAt,omitempty"` + // Date when the contract was created + ContractCreatedAt *time.Time `json:"contractCreatedAt,omitempty"` + Iso NullableIso `json:"iso,omitempty"` + // The market app ID which was deployed in the instance, if any + MarketAppId NullableString `json:"marketAppId,omitempty"` +} + +// NewLaunchInstanceCreatedResult instantiates a new LaunchInstanceCreatedResult object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewLaunchInstanceCreatedResult() *LaunchInstanceCreatedResult { + this := LaunchInstanceCreatedResult{} + return &this +} + +// NewLaunchInstanceCreatedResultWithDefaults instantiates a new LaunchInstanceCreatedResult object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewLaunchInstanceCreatedResultWithDefaults() *LaunchInstanceCreatedResult { + this := LaunchInstanceCreatedResult{} + return &this +} + +// GetCustomerId returns the CustomerId field value if set, zero value otherwise. +func (o *LaunchInstanceCreatedResult) GetCustomerId() string { + if o == nil || IsNil(o.CustomerId) { + var ret string + return ret + } + return *o.CustomerId +} + +// GetCustomerIdOk returns a tuple with the CustomerId field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *LaunchInstanceCreatedResult) GetCustomerIdOk() (*string, bool) { + if o == nil || IsNil(o.CustomerId) { + return nil, false + } + return o.CustomerId, true +} + +// HasCustomerId returns a boolean if a field has been set. +func (o *LaunchInstanceCreatedResult) HasCustomerId() bool { + if o != nil && !IsNil(o.CustomerId) { + return true + } + + return false +} + +// SetCustomerId gets a reference to the given string and assigns it to the CustomerId field. +func (o *LaunchInstanceCreatedResult) SetCustomerId(v string) { + o.CustomerId = &v +} + +// GetId returns the Id field value if set, zero value otherwise. +func (o *LaunchInstanceCreatedResult) GetId() string { + if o == nil || IsNil(o.Id) { + var ret string + return ret + } + return *o.Id +} + +// GetIdOk returns a tuple with the Id field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *LaunchInstanceCreatedResult) GetIdOk() (*string, bool) { + if o == nil || IsNil(o.Id) { + return nil, false + } + return o.Id, true +} + +// HasId returns a boolean if a field has been set. +func (o *LaunchInstanceCreatedResult) HasId() bool { + if o != nil && !IsNil(o.Id) { + return true + } + + return false +} + +// SetId gets a reference to the given string and assigns it to the Id field. +func (o *LaunchInstanceCreatedResult) SetId(v string) { + o.Id = &v +} + +// GetResources returns the Resources field value if set, zero value otherwise. +func (o *LaunchInstanceCreatedResult) GetResources() InstanceResources { + if o == nil || IsNil(o.Resources) { + var ret InstanceResources + return ret + } + return *o.Resources +} + +// GetResourcesOk returns a tuple with the Resources field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *LaunchInstanceCreatedResult) GetResourcesOk() (*InstanceResources, bool) { + if o == nil || IsNil(o.Resources) { + return nil, false + } + return o.Resources, true +} + +// HasResources returns a boolean if a field has been set. +func (o *LaunchInstanceCreatedResult) HasResources() bool { + if o != nil && !IsNil(o.Resources) { + return true + } + + return false +} + +// SetResources gets a reference to the given InstanceResources and assigns it to the Resources field. +func (o *LaunchInstanceCreatedResult) SetResources(v InstanceResources) { + o.Resources = &v +} + +// GetRegion returns the Region field value if set, zero value otherwise. +func (o *LaunchInstanceCreatedResult) GetRegion() string { + if o == nil || IsNil(o.Region) { + var ret string + return ret + } + return *o.Region +} + +// GetRegionOk returns a tuple with the Region field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *LaunchInstanceCreatedResult) GetRegionOk() (*string, bool) { + if o == nil || IsNil(o.Region) { + return nil, false + } + return o.Region, true +} + +// HasRegion returns a boolean if a field has been set. +func (o *LaunchInstanceCreatedResult) HasRegion() bool { + if o != nil && !IsNil(o.Region) { + return true + } + + return false +} + +// SetRegion gets a reference to the given string and assigns it to the Region field. +func (o *LaunchInstanceCreatedResult) SetRegion(v string) { + o.Region = &v +} + +// GetReference returns the Reference field value if set, zero value otherwise. +func (o *LaunchInstanceCreatedResult) GetReference() string { + if o == nil || IsNil(o.Reference) { + var ret string + return ret + } + return *o.Reference +} + +// GetReferenceOk returns a tuple with the Reference field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *LaunchInstanceCreatedResult) GetReferenceOk() (*string, bool) { + if o == nil || IsNil(o.Reference) { + return nil, false + } + return o.Reference, true +} + +// HasReference returns a boolean if a field has been set. +func (o *LaunchInstanceCreatedResult) HasReference() bool { + if o != nil && !IsNil(o.Reference) { + return true + } + + return false +} + +// SetReference gets a reference to the given string and assigns it to the Reference field. +func (o *LaunchInstanceCreatedResult) SetReference(v string) { + o.Reference = &v +} + +// GetOperatingSystem returns the OperatingSystem field value if set, zero value otherwise. +func (o *LaunchInstanceCreatedResult) GetOperatingSystem() OperatingSystem { + if o == nil || IsNil(o.OperatingSystem) { + var ret OperatingSystem + return ret + } + return *o.OperatingSystem +} + +// GetOperatingSystemOk returns a tuple with the OperatingSystem field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *LaunchInstanceCreatedResult) GetOperatingSystemOk() (*OperatingSystem, bool) { + if o == nil || IsNil(o.OperatingSystem) { + return nil, false + } + return o.OperatingSystem, true +} + +// HasOperatingSystem returns a boolean if a field has been set. +func (o *LaunchInstanceCreatedResult) HasOperatingSystem() bool { + if o != nil && !IsNil(o.OperatingSystem) { + return true + } + + return false +} + +// SetOperatingSystem gets a reference to the given OperatingSystem and assigns it to the OperatingSystem field. +func (o *LaunchInstanceCreatedResult) SetOperatingSystem(v OperatingSystem) { + o.OperatingSystem = &v +} + +// GetState returns the State field value if set, zero value otherwise. +func (o *LaunchInstanceCreatedResult) GetState() InstanceState { + if o == nil || IsNil(o.State) { + var ret InstanceState + return ret + } + return *o.State +} + +// GetStateOk returns a tuple with the State field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *LaunchInstanceCreatedResult) GetStateOk() (*InstanceState, bool) { + if o == nil || IsNil(o.State) { + return nil, false + } + return o.State, true +} + +// HasState returns a boolean if a field has been set. +func (o *LaunchInstanceCreatedResult) HasState() bool { + if o != nil && !IsNil(o.State) { + return true + } + + return false +} + +// SetState gets a reference to the given InstanceState and assigns it to the State field. +func (o *LaunchInstanceCreatedResult) SetState(v InstanceState) { + o.State = &v +} + +// GetPublicIpV4 returns the PublicIpV4 field value if set, zero value otherwise. +func (o *LaunchInstanceCreatedResult) GetPublicIpV4() bool { + if o == nil || IsNil(o.PublicIpV4) { + var ret bool + return ret + } + return *o.PublicIpV4 +} + +// GetPublicIpV4Ok returns a tuple with the PublicIpV4 field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *LaunchInstanceCreatedResult) GetPublicIpV4Ok() (*bool, bool) { + if o == nil || IsNil(o.PublicIpV4) { + return nil, false + } + return o.PublicIpV4, true +} + +// HasPublicIpV4 returns a boolean if a field has been set. +func (o *LaunchInstanceCreatedResult) HasPublicIpV4() bool { + if o != nil && !IsNil(o.PublicIpV4) { + return true + } + + return false +} + +// SetPublicIpV4 gets a reference to the given bool and assigns it to the PublicIpV4 field. +func (o *LaunchInstanceCreatedResult) SetPublicIpV4(v bool) { + o.PublicIpV4 = &v +} + +// GetType returns the Type field value if set, zero value otherwise. +func (o *LaunchInstanceCreatedResult) GetType() string { + if o == nil || IsNil(o.Type) { + var ret string + return ret + } + return *o.Type +} + +// GetTypeOk returns a tuple with the Type field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *LaunchInstanceCreatedResult) GetTypeOk() (*string, bool) { + if o == nil || IsNil(o.Type) { + return nil, false + } + return o.Type, true +} + +// HasType returns a boolean if a field has been set. +func (o *LaunchInstanceCreatedResult) HasType() bool { + if o != nil && !IsNil(o.Type) { + return true + } + + return false +} + +// SetType gets a reference to the given string and assigns it to the Type field. +func (o *LaunchInstanceCreatedResult) SetType(v string) { + o.Type = &v +} + +// GetPrivateNetwork returns the PrivateNetwork field value if set, zero value otherwise. +func (o *LaunchInstanceCreatedResult) GetPrivateNetwork() bool { + if o == nil || IsNil(o.PrivateNetwork) { + var ret bool + return ret + } + return *o.PrivateNetwork +} + +// GetPrivateNetworkOk returns a tuple with the PrivateNetwork field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *LaunchInstanceCreatedResult) GetPrivateNetworkOk() (*bool, bool) { + if o == nil || IsNil(o.PrivateNetwork) { + return nil, false + } + return o.PrivateNetwork, true +} + +// HasPrivateNetwork returns a boolean if a field has been set. +func (o *LaunchInstanceCreatedResult) HasPrivateNetwork() bool { + if o != nil && !IsNil(o.PrivateNetwork) { + return true + } + + return false +} + +// SetPrivateNetwork gets a reference to the given bool and assigns it to the PrivateNetwork field. +func (o *LaunchInstanceCreatedResult) SetPrivateNetwork(v bool) { + o.PrivateNetwork = &v +} + +// GetRootDiskSize returns the RootDiskSize field value if set, zero value otherwise. +func (o *LaunchInstanceCreatedResult) GetRootDiskSize() int32 { + if o == nil || IsNil(o.RootDiskSize) { + var ret int32 + return ret + } + return *o.RootDiskSize +} + +// GetRootDiskSizeOk returns a tuple with the RootDiskSize field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *LaunchInstanceCreatedResult) GetRootDiskSizeOk() (*int32, bool) { + if o == nil || IsNil(o.RootDiskSize) { + return nil, false + } + return o.RootDiskSize, true +} + +// HasRootDiskSize returns a boolean if a field has been set. +func (o *LaunchInstanceCreatedResult) HasRootDiskSize() bool { + if o != nil && !IsNil(o.RootDiskSize) { + return true + } + + return false +} + +// SetRootDiskSize gets a reference to the given int32 and assigns it to the RootDiskSize field. +func (o *LaunchInstanceCreatedResult) SetRootDiskSize(v int32) { + o.RootDiskSize = &v +} + +// GetRootDiskStorageType returns the RootDiskStorageType field value if set, zero value otherwise. +func (o *LaunchInstanceCreatedResult) GetRootDiskStorageType() string { + if o == nil || IsNil(o.RootDiskStorageType) { + var ret string + return ret + } + return *o.RootDiskStorageType +} + +// GetRootDiskStorageTypeOk returns a tuple with the RootDiskStorageType field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *LaunchInstanceCreatedResult) GetRootDiskStorageTypeOk() (*string, bool) { + if o == nil || IsNil(o.RootDiskStorageType) { + return nil, false + } + return o.RootDiskStorageType, true +} + +// HasRootDiskStorageType returns a boolean if a field has been set. +func (o *LaunchInstanceCreatedResult) HasRootDiskStorageType() bool { + if o != nil && !IsNil(o.RootDiskStorageType) { + return true + } + + return false +} + +// SetRootDiskStorageType gets a reference to the given string and assigns it to the RootDiskStorageType field. +func (o *LaunchInstanceCreatedResult) SetRootDiskStorageType(v string) { + o.RootDiskStorageType = &v +} + +// GetIps returns the Ips field value if set, zero value otherwise. +func (o *LaunchInstanceCreatedResult) GetIps() []Ip { + if o == nil || IsNil(o.Ips) { + var ret []Ip + return ret + } + return o.Ips +} + +// GetIpsOk returns a tuple with the Ips field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *LaunchInstanceCreatedResult) GetIpsOk() ([]Ip, bool) { + if o == nil || IsNil(o.Ips) { + return nil, false + } + return o.Ips, true +} + +// HasIps returns a boolean if a field has been set. +func (o *LaunchInstanceCreatedResult) HasIps() bool { + if o != nil && !IsNil(o.Ips) { + return true + } + + return false +} + +// SetIps gets a reference to the given []Ip and assigns it to the Ips field. +func (o *LaunchInstanceCreatedResult) SetIps(v []Ip) { + o.Ips = v +} + +// GetBillingFrequency returns the BillingFrequency field value if set, zero value otherwise. +func (o *LaunchInstanceCreatedResult) GetBillingFrequency() int32 { + if o == nil || IsNil(o.BillingFrequency) { + var ret int32 + return ret + } + return *o.BillingFrequency +} + +// GetBillingFrequencyOk returns a tuple with the BillingFrequency field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *LaunchInstanceCreatedResult) GetBillingFrequencyOk() (*int32, bool) { + if o == nil || IsNil(o.BillingFrequency) { + return nil, false + } + return o.BillingFrequency, true +} + +// HasBillingFrequency returns a boolean if a field has been set. +func (o *LaunchInstanceCreatedResult) HasBillingFrequency() bool { + if o != nil && !IsNil(o.BillingFrequency) { + return true + } + + return false +} + +// SetBillingFrequency gets a reference to the given int32 and assigns it to the BillingFrequency field. +func (o *LaunchInstanceCreatedResult) SetBillingFrequency(v int32) { + o.BillingFrequency = &v +} + +// GetContractTerm returns the ContractTerm field value if set, zero value otherwise. +func (o *LaunchInstanceCreatedResult) GetContractTerm() int32 { + if o == nil || IsNil(o.ContractTerm) { + var ret int32 + return ret + } + return *o.ContractTerm +} + +// GetContractTermOk returns a tuple with the ContractTerm field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *LaunchInstanceCreatedResult) GetContractTermOk() (*int32, bool) { + if o == nil || IsNil(o.ContractTerm) { + return nil, false + } + return o.ContractTerm, true +} + +// HasContractTerm returns a boolean if a field has been set. +func (o *LaunchInstanceCreatedResult) HasContractTerm() bool { + if o != nil && !IsNil(o.ContractTerm) { + return true + } + + return false +} + +// SetContractTerm gets a reference to the given int32 and assigns it to the ContractTerm field. +func (o *LaunchInstanceCreatedResult) SetContractTerm(v int32) { + o.ContractTerm = &v +} + +// GetContractType returns the ContractType field value if set, zero value otherwise. +func (o *LaunchInstanceCreatedResult) GetContractType() ContractType { + if o == nil || IsNil(o.ContractType) { + var ret ContractType + return ret + } + return *o.ContractType +} + +// GetContractTypeOk returns a tuple with the ContractType field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *LaunchInstanceCreatedResult) GetContractTypeOk() (*ContractType, bool) { + if o == nil || IsNil(o.ContractType) { + return nil, false + } + return o.ContractType, true +} + +// HasContractType returns a boolean if a field has been set. +func (o *LaunchInstanceCreatedResult) HasContractType() bool { + if o != nil && !IsNil(o.ContractType) { + return true + } + + return false +} + +// SetContractType gets a reference to the given ContractType and assigns it to the ContractType field. +func (o *LaunchInstanceCreatedResult) SetContractType(v ContractType) { + o.ContractType = &v +} + +// GetContractEndsAt returns the ContractEndsAt field value if set, zero value otherwise (both if not set or set to explicit null). +func (o *LaunchInstanceCreatedResult) GetContractEndsAt() time.Time { + if o == nil || IsNil(o.ContractEndsAt.Get()) { + var ret time.Time + return ret + } + return *o.ContractEndsAt.Get() +} + +// GetContractEndsAtOk returns a tuple with the ContractEndsAt field value if set, nil otherwise +// and a boolean to check if the value has been set. +// NOTE: If the value is an explicit nil, `nil, true` will be returned +func (o *LaunchInstanceCreatedResult) GetContractEndsAtOk() (*time.Time, bool) { + if o == nil { + return nil, false + } + return o.ContractEndsAt.Get(), o.ContractEndsAt.IsSet() +} + +// HasContractEndsAt returns a boolean if a field has been set. +func (o *LaunchInstanceCreatedResult) HasContractEndsAt() bool { + if o != nil && o.ContractEndsAt.IsSet() { + return true + } + + return false +} + +// SetContractEndsAt gets a reference to the given NullableTime and assigns it to the ContractEndsAt field. +func (o *LaunchInstanceCreatedResult) SetContractEndsAt(v time.Time) { + o.ContractEndsAt.Set(&v) +} +// SetContractEndsAtNil sets the value for ContractEndsAt to be an explicit nil +func (o *LaunchInstanceCreatedResult) SetContractEndsAtNil() { + o.ContractEndsAt.Set(nil) +} + +// UnsetContractEndsAt ensures that no value is present for ContractEndsAt, not even an explicit nil +func (o *LaunchInstanceCreatedResult) UnsetContractEndsAt() { + o.ContractEndsAt.Unset() +} + +// GetStartedAt returns the StartedAt field value if set, zero value otherwise (both if not set or set to explicit null). +func (o *LaunchInstanceCreatedResult) GetStartedAt() time.Time { + if o == nil || IsNil(o.StartedAt.Get()) { + var ret time.Time + return ret + } + return *o.StartedAt.Get() +} + +// GetStartedAtOk returns a tuple with the StartedAt field value if set, nil otherwise +// and a boolean to check if the value has been set. +// NOTE: If the value is an explicit nil, `nil, true` will be returned +func (o *LaunchInstanceCreatedResult) GetStartedAtOk() (*time.Time, bool) { + if o == nil { + return nil, false + } + return o.StartedAt.Get(), o.StartedAt.IsSet() +} + +// HasStartedAt returns a boolean if a field has been set. +func (o *LaunchInstanceCreatedResult) HasStartedAt() bool { + if o != nil && o.StartedAt.IsSet() { + return true + } + + return false +} + +// SetStartedAt gets a reference to the given NullableTime and assigns it to the StartedAt field. +func (o *LaunchInstanceCreatedResult) SetStartedAt(v time.Time) { + o.StartedAt.Set(&v) +} +// SetStartedAtNil sets the value for StartedAt to be an explicit nil +func (o *LaunchInstanceCreatedResult) SetStartedAtNil() { + o.StartedAt.Set(nil) +} + +// UnsetStartedAt ensures that no value is present for StartedAt, not even an explicit nil +func (o *LaunchInstanceCreatedResult) UnsetStartedAt() { + o.StartedAt.Unset() +} + +// GetContractRenewalsAt returns the ContractRenewalsAt field value if set, zero value otherwise. +func (o *LaunchInstanceCreatedResult) GetContractRenewalsAt() time.Time { + if o == nil || IsNil(o.ContractRenewalsAt) { + var ret time.Time + return ret + } + return *o.ContractRenewalsAt +} + +// GetContractRenewalsAtOk returns a tuple with the ContractRenewalsAt field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *LaunchInstanceCreatedResult) GetContractRenewalsAtOk() (*time.Time, bool) { + if o == nil || IsNil(o.ContractRenewalsAt) { + return nil, false + } + return o.ContractRenewalsAt, true +} + +// HasContractRenewalsAt returns a boolean if a field has been set. +func (o *LaunchInstanceCreatedResult) HasContractRenewalsAt() bool { + if o != nil && !IsNil(o.ContractRenewalsAt) { + return true + } + + return false +} + +// SetContractRenewalsAt gets a reference to the given time.Time and assigns it to the ContractRenewalsAt field. +func (o *LaunchInstanceCreatedResult) SetContractRenewalsAt(v time.Time) { + o.ContractRenewalsAt = &v +} + +// GetContractCreatedAt returns the ContractCreatedAt field value if set, zero value otherwise. +func (o *LaunchInstanceCreatedResult) GetContractCreatedAt() time.Time { + if o == nil || IsNil(o.ContractCreatedAt) { + var ret time.Time + return ret + } + return *o.ContractCreatedAt +} + +// GetContractCreatedAtOk returns a tuple with the ContractCreatedAt field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *LaunchInstanceCreatedResult) GetContractCreatedAtOk() (*time.Time, bool) { + if o == nil || IsNil(o.ContractCreatedAt) { + return nil, false + } + return o.ContractCreatedAt, true +} + +// HasContractCreatedAt returns a boolean if a field has been set. +func (o *LaunchInstanceCreatedResult) HasContractCreatedAt() bool { + if o != nil && !IsNil(o.ContractCreatedAt) { + return true + } + + return false +} + +// SetContractCreatedAt gets a reference to the given time.Time and assigns it to the ContractCreatedAt field. +func (o *LaunchInstanceCreatedResult) SetContractCreatedAt(v time.Time) { + o.ContractCreatedAt = &v +} + +// GetIso returns the Iso field value if set, zero value otherwise (both if not set or set to explicit null). +func (o *LaunchInstanceCreatedResult) GetIso() Iso { + if o == nil || IsNil(o.Iso.Get()) { + var ret Iso + return ret + } + return *o.Iso.Get() +} + +// GetIsoOk returns a tuple with the Iso field value if set, nil otherwise +// and a boolean to check if the value has been set. +// NOTE: If the value is an explicit nil, `nil, true` will be returned +func (o *LaunchInstanceCreatedResult) GetIsoOk() (*Iso, bool) { + if o == nil { + return nil, false + } + return o.Iso.Get(), o.Iso.IsSet() +} + +// HasIso returns a boolean if a field has been set. +func (o *LaunchInstanceCreatedResult) HasIso() bool { + if o != nil && o.Iso.IsSet() { + return true + } + + return false +} + +// SetIso gets a reference to the given NullableIso and assigns it to the Iso field. +func (o *LaunchInstanceCreatedResult) SetIso(v Iso) { + o.Iso.Set(&v) +} +// SetIsoNil sets the value for Iso to be an explicit nil +func (o *LaunchInstanceCreatedResult) SetIsoNil() { + o.Iso.Set(nil) +} + +// UnsetIso ensures that no value is present for Iso, not even an explicit nil +func (o *LaunchInstanceCreatedResult) UnsetIso() { + o.Iso.Unset() +} + +// GetMarketAppId returns the MarketAppId field value if set, zero value otherwise (both if not set or set to explicit null). +func (o *LaunchInstanceCreatedResult) GetMarketAppId() string { + if o == nil || IsNil(o.MarketAppId.Get()) { + var ret string + return ret + } + return *o.MarketAppId.Get() +} + +// GetMarketAppIdOk returns a tuple with the MarketAppId field value if set, nil otherwise +// and a boolean to check if the value has been set. +// NOTE: If the value is an explicit nil, `nil, true` will be returned +func (o *LaunchInstanceCreatedResult) GetMarketAppIdOk() (*string, bool) { + if o == nil { + return nil, false + } + return o.MarketAppId.Get(), o.MarketAppId.IsSet() +} + +// HasMarketAppId returns a boolean if a field has been set. +func (o *LaunchInstanceCreatedResult) HasMarketAppId() bool { + if o != nil && o.MarketAppId.IsSet() { + return true + } + + return false +} + +// SetMarketAppId gets a reference to the given NullableString and assigns it to the MarketAppId field. +func (o *LaunchInstanceCreatedResult) SetMarketAppId(v string) { + o.MarketAppId.Set(&v) +} +// SetMarketAppIdNil sets the value for MarketAppId to be an explicit nil +func (o *LaunchInstanceCreatedResult) SetMarketAppIdNil() { + o.MarketAppId.Set(nil) +} + +// UnsetMarketAppId ensures that no value is present for MarketAppId, not even an explicit nil +func (o *LaunchInstanceCreatedResult) UnsetMarketAppId() { + o.MarketAppId.Unset() +} + +func (o LaunchInstanceCreatedResult) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o LaunchInstanceCreatedResult) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.CustomerId) { + toSerialize["customerId"] = o.CustomerId + } + if !IsNil(o.Id) { + toSerialize["id"] = o.Id + } + if !IsNil(o.Resources) { + toSerialize["resources"] = o.Resources + } + if !IsNil(o.Region) { + toSerialize["region"] = o.Region + } + if !IsNil(o.Reference) { + toSerialize["reference"] = o.Reference + } + if !IsNil(o.OperatingSystem) { + toSerialize["operatingSystem"] = o.OperatingSystem + } + if !IsNil(o.State) { + toSerialize["state"] = o.State + } + if !IsNil(o.PublicIpV4) { + toSerialize["publicIpV4"] = o.PublicIpV4 + } + if !IsNil(o.Type) { + toSerialize["type"] = o.Type + } + if !IsNil(o.PrivateNetwork) { + toSerialize["privateNetwork"] = o.PrivateNetwork + } + if !IsNil(o.RootDiskSize) { + toSerialize["rootDiskSize"] = o.RootDiskSize + } + if !IsNil(o.RootDiskStorageType) { + toSerialize["rootDiskStorageType"] = o.RootDiskStorageType + } + if !IsNil(o.Ips) { + toSerialize["ips"] = o.Ips + } + if !IsNil(o.BillingFrequency) { + toSerialize["billingFrequency"] = o.BillingFrequency + } + if !IsNil(o.ContractTerm) { + toSerialize["contractTerm"] = o.ContractTerm + } + if !IsNil(o.ContractType) { + toSerialize["contractType"] = o.ContractType + } + if o.ContractEndsAt.IsSet() { + toSerialize["contractEndsAt"] = o.ContractEndsAt.Get() + } + if o.StartedAt.IsSet() { + toSerialize["startedAt"] = o.StartedAt.Get() + } + if !IsNil(o.ContractRenewalsAt) { + toSerialize["contractRenewalsAt"] = o.ContractRenewalsAt + } + if !IsNil(o.ContractCreatedAt) { + toSerialize["contractCreatedAt"] = o.ContractCreatedAt + } + if o.Iso.IsSet() { + toSerialize["iso"] = o.Iso.Get() + } + if o.MarketAppId.IsSet() { + toSerialize["marketAppId"] = o.MarketAppId.Get() + } + return toSerialize, nil +} + +type NullableLaunchInstanceCreatedResult struct { + value *LaunchInstanceCreatedResult + isSet bool +} + +func (v NullableLaunchInstanceCreatedResult) Get() *LaunchInstanceCreatedResult { + return v.value +} + +func (v *NullableLaunchInstanceCreatedResult) Set(val *LaunchInstanceCreatedResult) { + v.value = val + v.isSet = true +} + +func (v NullableLaunchInstanceCreatedResult) IsSet() bool { + return v.isSet +} + +func (v *NullableLaunchInstanceCreatedResult) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableLaunchInstanceCreatedResult(val *LaunchInstanceCreatedResult) *NullableLaunchInstanceCreatedResult { + return &NullableLaunchInstanceCreatedResult{value: val, isSet: true} +} + +func (v NullableLaunchInstanceCreatedResult) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableLaunchInstanceCreatedResult) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/publicCloud/model_launch_instance_opts.go b/publicCloud/model_launch_instance_opts.go new file mode 100644 index 0000000..fc95e39 --- /dev/null +++ b/publicCloud/model_launch_instance_opts.go @@ -0,0 +1,488 @@ +/* +LeaseWeb API for launching and managing Public Cloud instances + +> The base URL for this API is: **https://api.leaseweb.com/publicCloud/v1/_** This API provides ways to launch and manage Public Cloud instances.
BETA
This API is in BETA. Documentation might be incorrect or incomplete. Functionality might change with the final release.> + +API version: v1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package publicCloud + +import ( + "encoding/json" + "bytes" + "fmt" +) + +// checks if the LaunchInstanceOpts type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &LaunchInstanceOpts{} + +// LaunchInstanceOpts struct for LaunchInstanceOpts +type LaunchInstanceOpts struct { + // Region to launch the instance into + Region string `json:"region"` + // Instance type + Type *string `json:"type,omitempty"` + // Operating System ID + OperatingSystemId string `json:"operatingSystemId"` + // Market App ID that must be installed into the instance + MarketAppId *string `json:"marketAppId,omitempty"` + // An identifying name you can refer to the instance + Reference *string `json:"reference,omitempty"` + ContractType string `json:"contractType"` + // Contract commitment. Used only when contract type is MONTHLY + ContractTerm int32 `json:"contractTerm"` + // How often you wish to be charged. Used only when contract type is MONTHLY. '1' means every month, '3' every three months and so on. + BillingFrequency int32 `json:"billingFrequency"` + // The root disk's size in GB. Must be at least 5 GB for Linux and FreeBSD instances and 50 GB for Windows instances + RootDiskSize *int32 `json:"rootDiskSize,omitempty"` + // The root disk's storage type + RootDiskStorageType string `json:"rootDiskStorageType"` + // Public SSH key to be installed into the instance. Must be used only on Linux/FreeBSD instances + SshKey *string `json:"sshKey,omitempty"` +} + +type _LaunchInstanceOpts LaunchInstanceOpts + +// NewLaunchInstanceOpts instantiates a new LaunchInstanceOpts object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewLaunchInstanceOpts(region string, operatingSystemId string, contractType string, contractTerm int32, billingFrequency int32, rootDiskStorageType string) *LaunchInstanceOpts { + this := LaunchInstanceOpts{} + this.Region = region + this.OperatingSystemId = operatingSystemId + this.ContractType = contractType + this.ContractTerm = contractTerm + this.BillingFrequency = billingFrequency + this.RootDiskStorageType = rootDiskStorageType + return &this +} + +// NewLaunchInstanceOptsWithDefaults instantiates a new LaunchInstanceOpts object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewLaunchInstanceOptsWithDefaults() *LaunchInstanceOpts { + this := LaunchInstanceOpts{} + return &this +} + +// GetRegion returns the Region field value +func (o *LaunchInstanceOpts) GetRegion() string { + if o == nil { + var ret string + return ret + } + + return o.Region +} + +// GetRegionOk returns a tuple with the Region field value +// and a boolean to check if the value has been set. +func (o *LaunchInstanceOpts) GetRegionOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.Region, true +} + +// SetRegion sets field value +func (o *LaunchInstanceOpts) SetRegion(v string) { + o.Region = v +} + +// GetType returns the Type field value if set, zero value otherwise. +func (o *LaunchInstanceOpts) GetType() string { + if o == nil || IsNil(o.Type) { + var ret string + return ret + } + return *o.Type +} + +// GetTypeOk returns a tuple with the Type field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *LaunchInstanceOpts) GetTypeOk() (*string, bool) { + if o == nil || IsNil(o.Type) { + return nil, false + } + return o.Type, true +} + +// HasType returns a boolean if a field has been set. +func (o *LaunchInstanceOpts) HasType() bool { + if o != nil && !IsNil(o.Type) { + return true + } + + return false +} + +// SetType gets a reference to the given string and assigns it to the Type field. +func (o *LaunchInstanceOpts) SetType(v string) { + o.Type = &v +} + +// GetOperatingSystemId returns the OperatingSystemId field value +func (o *LaunchInstanceOpts) GetOperatingSystemId() string { + if o == nil { + var ret string + return ret + } + + return o.OperatingSystemId +} + +// GetOperatingSystemIdOk returns a tuple with the OperatingSystemId field value +// and a boolean to check if the value has been set. +func (o *LaunchInstanceOpts) GetOperatingSystemIdOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.OperatingSystemId, true +} + +// SetOperatingSystemId sets field value +func (o *LaunchInstanceOpts) SetOperatingSystemId(v string) { + o.OperatingSystemId = v +} + +// GetMarketAppId returns the MarketAppId field value if set, zero value otherwise. +func (o *LaunchInstanceOpts) GetMarketAppId() string { + if o == nil || IsNil(o.MarketAppId) { + var ret string + return ret + } + return *o.MarketAppId +} + +// GetMarketAppIdOk returns a tuple with the MarketAppId field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *LaunchInstanceOpts) GetMarketAppIdOk() (*string, bool) { + if o == nil || IsNil(o.MarketAppId) { + return nil, false + } + return o.MarketAppId, true +} + +// HasMarketAppId returns a boolean if a field has been set. +func (o *LaunchInstanceOpts) HasMarketAppId() bool { + if o != nil && !IsNil(o.MarketAppId) { + return true + } + + return false +} + +// SetMarketAppId gets a reference to the given string and assigns it to the MarketAppId field. +func (o *LaunchInstanceOpts) SetMarketAppId(v string) { + o.MarketAppId = &v +} + +// GetReference returns the Reference field value if set, zero value otherwise. +func (o *LaunchInstanceOpts) GetReference() string { + if o == nil || IsNil(o.Reference) { + var ret string + return ret + } + return *o.Reference +} + +// GetReferenceOk returns a tuple with the Reference field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *LaunchInstanceOpts) GetReferenceOk() (*string, bool) { + if o == nil || IsNil(o.Reference) { + return nil, false + } + return o.Reference, true +} + +// HasReference returns a boolean if a field has been set. +func (o *LaunchInstanceOpts) HasReference() bool { + if o != nil && !IsNil(o.Reference) { + return true + } + + return false +} + +// SetReference gets a reference to the given string and assigns it to the Reference field. +func (o *LaunchInstanceOpts) SetReference(v string) { + o.Reference = &v +} + +// GetContractType returns the ContractType field value +func (o *LaunchInstanceOpts) GetContractType() string { + if o == nil { + var ret string + return ret + } + + return o.ContractType +} + +// GetContractTypeOk returns a tuple with the ContractType field value +// and a boolean to check if the value has been set. +func (o *LaunchInstanceOpts) GetContractTypeOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.ContractType, true +} + +// SetContractType sets field value +func (o *LaunchInstanceOpts) SetContractType(v string) { + o.ContractType = v +} + +// GetContractTerm returns the ContractTerm field value +func (o *LaunchInstanceOpts) GetContractTerm() int32 { + if o == nil { + var ret int32 + return ret + } + + return o.ContractTerm +} + +// GetContractTermOk returns a tuple with the ContractTerm field value +// and a boolean to check if the value has been set. +func (o *LaunchInstanceOpts) GetContractTermOk() (*int32, bool) { + if o == nil { + return nil, false + } + return &o.ContractTerm, true +} + +// SetContractTerm sets field value +func (o *LaunchInstanceOpts) SetContractTerm(v int32) { + o.ContractTerm = v +} + +// GetBillingFrequency returns the BillingFrequency field value +func (o *LaunchInstanceOpts) GetBillingFrequency() int32 { + if o == nil { + var ret int32 + return ret + } + + return o.BillingFrequency +} + +// GetBillingFrequencyOk returns a tuple with the BillingFrequency field value +// and a boolean to check if the value has been set. +func (o *LaunchInstanceOpts) GetBillingFrequencyOk() (*int32, bool) { + if o == nil { + return nil, false + } + return &o.BillingFrequency, true +} + +// SetBillingFrequency sets field value +func (o *LaunchInstanceOpts) SetBillingFrequency(v int32) { + o.BillingFrequency = v +} + +// GetRootDiskSize returns the RootDiskSize field value if set, zero value otherwise. +func (o *LaunchInstanceOpts) GetRootDiskSize() int32 { + if o == nil || IsNil(o.RootDiskSize) { + var ret int32 + return ret + } + return *o.RootDiskSize +} + +// GetRootDiskSizeOk returns a tuple with the RootDiskSize field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *LaunchInstanceOpts) GetRootDiskSizeOk() (*int32, bool) { + if o == nil || IsNil(o.RootDiskSize) { + return nil, false + } + return o.RootDiskSize, true +} + +// HasRootDiskSize returns a boolean if a field has been set. +func (o *LaunchInstanceOpts) HasRootDiskSize() bool { + if o != nil && !IsNil(o.RootDiskSize) { + return true + } + + return false +} + +// SetRootDiskSize gets a reference to the given int32 and assigns it to the RootDiskSize field. +func (o *LaunchInstanceOpts) SetRootDiskSize(v int32) { + o.RootDiskSize = &v +} + +// GetRootDiskStorageType returns the RootDiskStorageType field value +func (o *LaunchInstanceOpts) GetRootDiskStorageType() string { + if o == nil { + var ret string + return ret + } + + return o.RootDiskStorageType +} + +// GetRootDiskStorageTypeOk returns a tuple with the RootDiskStorageType field value +// and a boolean to check if the value has been set. +func (o *LaunchInstanceOpts) GetRootDiskStorageTypeOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.RootDiskStorageType, true +} + +// SetRootDiskStorageType sets field value +func (o *LaunchInstanceOpts) SetRootDiskStorageType(v string) { + o.RootDiskStorageType = v +} + +// GetSshKey returns the SshKey field value if set, zero value otherwise. +func (o *LaunchInstanceOpts) GetSshKey() string { + if o == nil || IsNil(o.SshKey) { + var ret string + return ret + } + return *o.SshKey +} + +// GetSshKeyOk returns a tuple with the SshKey field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *LaunchInstanceOpts) GetSshKeyOk() (*string, bool) { + if o == nil || IsNil(o.SshKey) { + return nil, false + } + return o.SshKey, true +} + +// HasSshKey returns a boolean if a field has been set. +func (o *LaunchInstanceOpts) HasSshKey() bool { + if o != nil && !IsNil(o.SshKey) { + return true + } + + return false +} + +// SetSshKey gets a reference to the given string and assigns it to the SshKey field. +func (o *LaunchInstanceOpts) SetSshKey(v string) { + o.SshKey = &v +} + +func (o LaunchInstanceOpts) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o LaunchInstanceOpts) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + toSerialize["region"] = o.Region + if !IsNil(o.Type) { + toSerialize["type"] = o.Type + } + toSerialize["operatingSystemId"] = o.OperatingSystemId + if !IsNil(o.MarketAppId) { + toSerialize["marketAppId"] = o.MarketAppId + } + if !IsNil(o.Reference) { + toSerialize["reference"] = o.Reference + } + toSerialize["contractType"] = o.ContractType + toSerialize["contractTerm"] = o.ContractTerm + toSerialize["billingFrequency"] = o.BillingFrequency + if !IsNil(o.RootDiskSize) { + toSerialize["rootDiskSize"] = o.RootDiskSize + } + toSerialize["rootDiskStorageType"] = o.RootDiskStorageType + if !IsNil(o.SshKey) { + toSerialize["sshKey"] = o.SshKey + } + return toSerialize, nil +} + +func (o *LaunchInstanceOpts) UnmarshalJSON(data []byte) (err error) { + // This validates that all required properties are included in the JSON object + // by unmarshalling the object into a generic map with string keys and checking + // that every required field exists as a key in the generic map. + requiredProperties := []string{ + "region", + "operatingSystemId", + "contractType", + "contractTerm", + "billingFrequency", + "rootDiskStorageType", + } + + allProperties := make(map[string]interface{}) + + err = json.Unmarshal(data, &allProperties) + + if err != nil { + return err; + } + + for _, requiredProperty := range(requiredProperties) { + if _, exists := allProperties[requiredProperty]; !exists { + return fmt.Errorf("no value given for required property %v", requiredProperty) + } + } + + varLaunchInstanceOpts := _LaunchInstanceOpts{} + + decoder := json.NewDecoder(bytes.NewReader(data)) + decoder.DisallowUnknownFields() + err = decoder.Decode(&varLaunchInstanceOpts) + + if err != nil { + return err + } + + *o = LaunchInstanceOpts(varLaunchInstanceOpts) + + return err +} + +type NullableLaunchInstanceOpts struct { + value *LaunchInstanceOpts + isSet bool +} + +func (v NullableLaunchInstanceOpts) Get() *LaunchInstanceOpts { + return v.value +} + +func (v *NullableLaunchInstanceOpts) Set(val *LaunchInstanceOpts) { + v.value = val + v.isSet = true +} + +func (v NullableLaunchInstanceOpts) IsSet() bool { + return v.isSet +} + +func (v *NullableLaunchInstanceOpts) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableLaunchInstanceOpts(val *LaunchInstanceOpts) *NullableLaunchInstanceOpts { + return &NullableLaunchInstanceOpts{value: val, isSet: true} +} + +func (v NullableLaunchInstanceOpts) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableLaunchInstanceOpts) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/publicCloud/model_local.go b/publicCloud/model_local.go new file mode 100644 index 0000000..58d7c72 --- /dev/null +++ b/publicCloud/model_local.go @@ -0,0 +1,162 @@ +/* +LeaseWeb API for launching and managing Public Cloud instances + +> The base URL for this API is: **https://api.leaseweb.com/publicCloud/v1/_** This API provides ways to launch and manage Public Cloud instances.
BETA
This API is in BETA. Documentation might be incorrect or incomplete. Functionality might change with the final release.> + +API version: v1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package publicCloud + +import ( + "encoding/json" +) + +// checks if the Local type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &Local{} + +// Local struct for Local +type Local struct { + HourlyPrice *string `json:"hourlyPrice,omitempty"` + MonthlyPrice *string `json:"monthlyPrice,omitempty"` +} + +// NewLocal instantiates a new Local object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewLocal() *Local { + this := Local{} + return &this +} + +// NewLocalWithDefaults instantiates a new Local object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewLocalWithDefaults() *Local { + this := Local{} + return &this +} + +// GetHourlyPrice returns the HourlyPrice field value if set, zero value otherwise. +func (o *Local) GetHourlyPrice() string { + if o == nil || IsNil(o.HourlyPrice) { + var ret string + return ret + } + return *o.HourlyPrice +} + +// GetHourlyPriceOk returns a tuple with the HourlyPrice field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Local) GetHourlyPriceOk() (*string, bool) { + if o == nil || IsNil(o.HourlyPrice) { + return nil, false + } + return o.HourlyPrice, true +} + +// HasHourlyPrice returns a boolean if a field has been set. +func (o *Local) HasHourlyPrice() bool { + if o != nil && !IsNil(o.HourlyPrice) { + return true + } + + return false +} + +// SetHourlyPrice gets a reference to the given string and assigns it to the HourlyPrice field. +func (o *Local) SetHourlyPrice(v string) { + o.HourlyPrice = &v +} + +// GetMonthlyPrice returns the MonthlyPrice field value if set, zero value otherwise. +func (o *Local) GetMonthlyPrice() string { + if o == nil || IsNil(o.MonthlyPrice) { + var ret string + return ret + } + return *o.MonthlyPrice +} + +// GetMonthlyPriceOk returns a tuple with the MonthlyPrice field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Local) GetMonthlyPriceOk() (*string, bool) { + if o == nil || IsNil(o.MonthlyPrice) { + return nil, false + } + return o.MonthlyPrice, true +} + +// HasMonthlyPrice returns a boolean if a field has been set. +func (o *Local) HasMonthlyPrice() bool { + if o != nil && !IsNil(o.MonthlyPrice) { + return true + } + + return false +} + +// SetMonthlyPrice gets a reference to the given string and assigns it to the MonthlyPrice field. +func (o *Local) SetMonthlyPrice(v string) { + o.MonthlyPrice = &v +} + +func (o Local) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o Local) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.HourlyPrice) { + toSerialize["hourlyPrice"] = o.HourlyPrice + } + if !IsNil(o.MonthlyPrice) { + toSerialize["monthlyPrice"] = o.MonthlyPrice + } + return toSerialize, nil +} + +type NullableLocal struct { + value *Local + isSet bool +} + +func (v NullableLocal) Get() *Local { + return v.value +} + +func (v *NullableLocal) Set(val *Local) { + v.value = val + v.isSet = true +} + +func (v NullableLocal) IsSet() bool { + return v.isSet +} + +func (v *NullableLocal) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableLocal(val *Local) *NullableLocal { + return &NullableLocal{value: val, isSet: true} +} + +func (v NullableLocal) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableLocal) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/publicCloud/model_market_app.go b/publicCloud/model_market_app.go new file mode 100644 index 0000000..f4318d0 --- /dev/null +++ b/publicCloud/model_market_app.go @@ -0,0 +1,316 @@ +/* +LeaseWeb API for launching and managing Public Cloud instances + +> The base URL for this API is: **https://api.leaseweb.com/publicCloud/v1/_** This API provides ways to launch and manage Public Cloud instances.
BETA
This API is in BETA. Documentation might be incorrect or incomplete. Functionality might change with the final release.> + +API version: v1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package publicCloud + +import ( + "encoding/json" +) + +// checks if the MarketApp type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &MarketApp{} + +// MarketApp struct for MarketApp +type MarketApp struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Category *string `json:"category,omitempty"` + Version NullableString `json:"version,omitempty"` + Family *string `json:"family,omitempty"` + OperatingSystem *OperatingSystem `json:"operatingSystem,omitempty"` +} + +// NewMarketApp instantiates a new MarketApp object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewMarketApp() *MarketApp { + this := MarketApp{} + return &this +} + +// NewMarketAppWithDefaults instantiates a new MarketApp object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewMarketAppWithDefaults() *MarketApp { + this := MarketApp{} + return &this +} + +// GetId returns the Id field value if set, zero value otherwise. +func (o *MarketApp) GetId() string { + if o == nil || IsNil(o.Id) { + var ret string + return ret + } + return *o.Id +} + +// GetIdOk returns a tuple with the Id field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *MarketApp) GetIdOk() (*string, bool) { + if o == nil || IsNil(o.Id) { + return nil, false + } + return o.Id, true +} + +// HasId returns a boolean if a field has been set. +func (o *MarketApp) HasId() bool { + if o != nil && !IsNil(o.Id) { + return true + } + + return false +} + +// SetId gets a reference to the given string and assigns it to the Id field. +func (o *MarketApp) SetId(v string) { + o.Id = &v +} + +// GetName returns the Name field value if set, zero value otherwise. +func (o *MarketApp) GetName() string { + if o == nil || IsNil(o.Name) { + var ret string + return ret + } + return *o.Name +} + +// GetNameOk returns a tuple with the Name field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *MarketApp) GetNameOk() (*string, bool) { + if o == nil || IsNil(o.Name) { + return nil, false + } + return o.Name, true +} + +// HasName returns a boolean if a field has been set. +func (o *MarketApp) HasName() bool { + if o != nil && !IsNil(o.Name) { + return true + } + + return false +} + +// SetName gets a reference to the given string and assigns it to the Name field. +func (o *MarketApp) SetName(v string) { + o.Name = &v +} + +// GetCategory returns the Category field value if set, zero value otherwise. +func (o *MarketApp) GetCategory() string { + if o == nil || IsNil(o.Category) { + var ret string + return ret + } + return *o.Category +} + +// GetCategoryOk returns a tuple with the Category field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *MarketApp) GetCategoryOk() (*string, bool) { + if o == nil || IsNil(o.Category) { + return nil, false + } + return o.Category, true +} + +// HasCategory returns a boolean if a field has been set. +func (o *MarketApp) HasCategory() bool { + if o != nil && !IsNil(o.Category) { + return true + } + + return false +} + +// SetCategory gets a reference to the given string and assigns it to the Category field. +func (o *MarketApp) SetCategory(v string) { + o.Category = &v +} + +// GetVersion returns the Version field value if set, zero value otherwise (both if not set or set to explicit null). +func (o *MarketApp) GetVersion() string { + if o == nil || IsNil(o.Version.Get()) { + var ret string + return ret + } + return *o.Version.Get() +} + +// GetVersionOk returns a tuple with the Version field value if set, nil otherwise +// and a boolean to check if the value has been set. +// NOTE: If the value is an explicit nil, `nil, true` will be returned +func (o *MarketApp) GetVersionOk() (*string, bool) { + if o == nil { + return nil, false + } + return o.Version.Get(), o.Version.IsSet() +} + +// HasVersion returns a boolean if a field has been set. +func (o *MarketApp) HasVersion() bool { + if o != nil && o.Version.IsSet() { + return true + } + + return false +} + +// SetVersion gets a reference to the given NullableString and assigns it to the Version field. +func (o *MarketApp) SetVersion(v string) { + o.Version.Set(&v) +} +// SetVersionNil sets the value for Version to be an explicit nil +func (o *MarketApp) SetVersionNil() { + o.Version.Set(nil) +} + +// UnsetVersion ensures that no value is present for Version, not even an explicit nil +func (o *MarketApp) UnsetVersion() { + o.Version.Unset() +} + +// GetFamily returns the Family field value if set, zero value otherwise. +func (o *MarketApp) GetFamily() string { + if o == nil || IsNil(o.Family) { + var ret string + return ret + } + return *o.Family +} + +// GetFamilyOk returns a tuple with the Family field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *MarketApp) GetFamilyOk() (*string, bool) { + if o == nil || IsNil(o.Family) { + return nil, false + } + return o.Family, true +} + +// HasFamily returns a boolean if a field has been set. +func (o *MarketApp) HasFamily() bool { + if o != nil && !IsNil(o.Family) { + return true + } + + return false +} + +// SetFamily gets a reference to the given string and assigns it to the Family field. +func (o *MarketApp) SetFamily(v string) { + o.Family = &v +} + +// GetOperatingSystem returns the OperatingSystem field value if set, zero value otherwise. +func (o *MarketApp) GetOperatingSystem() OperatingSystem { + if o == nil || IsNil(o.OperatingSystem) { + var ret OperatingSystem + return ret + } + return *o.OperatingSystem +} + +// GetOperatingSystemOk returns a tuple with the OperatingSystem field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *MarketApp) GetOperatingSystemOk() (*OperatingSystem, bool) { + if o == nil || IsNil(o.OperatingSystem) { + return nil, false + } + return o.OperatingSystem, true +} + +// HasOperatingSystem returns a boolean if a field has been set. +func (o *MarketApp) HasOperatingSystem() bool { + if o != nil && !IsNil(o.OperatingSystem) { + return true + } + + return false +} + +// SetOperatingSystem gets a reference to the given OperatingSystem and assigns it to the OperatingSystem field. +func (o *MarketApp) SetOperatingSystem(v OperatingSystem) { + o.OperatingSystem = &v +} + +func (o MarketApp) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o MarketApp) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Id) { + toSerialize["id"] = o.Id + } + if !IsNil(o.Name) { + toSerialize["name"] = o.Name + } + if !IsNil(o.Category) { + toSerialize["category"] = o.Category + } + if o.Version.IsSet() { + toSerialize["version"] = o.Version.Get() + } + if !IsNil(o.Family) { + toSerialize["family"] = o.Family + } + if !IsNil(o.OperatingSystem) { + toSerialize["operatingSystem"] = o.OperatingSystem + } + return toSerialize, nil +} + +type NullableMarketApp struct { + value *MarketApp + isSet bool +} + +func (v NullableMarketApp) Get() *MarketApp { + return v.value +} + +func (v *NullableMarketApp) Set(val *MarketApp) { + v.value = val + v.isSet = true +} + +func (v NullableMarketApp) IsSet() bool { + return v.isSet +} + +func (v *NullableMarketApp) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableMarketApp(val *MarketApp) *NullableMarketApp { + return &NullableMarketApp{value: val, isSet: true} +} + +func (v NullableMarketApp) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableMarketApp) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/publicCloud/model_memory.go b/publicCloud/model_memory.go new file mode 100644 index 0000000..31987cb --- /dev/null +++ b/publicCloud/model_memory.go @@ -0,0 +1,162 @@ +/* +LeaseWeb API for launching and managing Public Cloud instances + +> The base URL for this API is: **https://api.leaseweb.com/publicCloud/v1/_** This API provides ways to launch and manage Public Cloud instances.
BETA
This API is in BETA. Documentation might be incorrect or incomplete. Functionality might change with the final release.> + +API version: v1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package publicCloud + +import ( + "encoding/json" +) + +// checks if the Memory type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &Memory{} + +// Memory Total memory in GiB +type Memory struct { + Value *float32 `json:"value,omitempty"` + Unit *string `json:"unit,omitempty"` +} + +// NewMemory instantiates a new Memory object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewMemory() *Memory { + this := Memory{} + return &this +} + +// NewMemoryWithDefaults instantiates a new Memory object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewMemoryWithDefaults() *Memory { + this := Memory{} + return &this +} + +// GetValue returns the Value field value if set, zero value otherwise. +func (o *Memory) GetValue() float32 { + if o == nil || IsNil(o.Value) { + var ret float32 + return ret + } + return *o.Value +} + +// GetValueOk returns a tuple with the Value field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Memory) GetValueOk() (*float32, bool) { + if o == nil || IsNil(o.Value) { + return nil, false + } + return o.Value, true +} + +// HasValue returns a boolean if a field has been set. +func (o *Memory) HasValue() bool { + if o != nil && !IsNil(o.Value) { + return true + } + + return false +} + +// SetValue gets a reference to the given float32 and assigns it to the Value field. +func (o *Memory) SetValue(v float32) { + o.Value = &v +} + +// GetUnit returns the Unit field value if set, zero value otherwise. +func (o *Memory) GetUnit() string { + if o == nil || IsNil(o.Unit) { + var ret string + return ret + } + return *o.Unit +} + +// GetUnitOk returns a tuple with the Unit field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Memory) GetUnitOk() (*string, bool) { + if o == nil || IsNil(o.Unit) { + return nil, false + } + return o.Unit, true +} + +// HasUnit returns a boolean if a field has been set. +func (o *Memory) HasUnit() bool { + if o != nil && !IsNil(o.Unit) { + return true + } + + return false +} + +// SetUnit gets a reference to the given string and assigns it to the Unit field. +func (o *Memory) SetUnit(v string) { + o.Unit = &v +} + +func (o Memory) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o Memory) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Value) { + toSerialize["value"] = o.Value + } + if !IsNil(o.Unit) { + toSerialize["unit"] = o.Unit + } + return toSerialize, nil +} + +type NullableMemory struct { + value *Memory + isSet bool +} + +func (v NullableMemory) Get() *Memory { + return v.value +} + +func (v *NullableMemory) Set(val *Memory) { + v.value = val + v.isSet = true +} + +func (v NullableMemory) IsSet() bool { + return v.isSet +} + +func (v *NullableMemory) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableMemory(val *Memory) *NullableMemory { + return &NullableMemory{value: val, isSet: true} +} + +func (v NullableMemory) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableMemory) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/publicCloud/model_operating_system.go b/publicCloud/model_operating_system.go new file mode 100644 index 0000000..66037da --- /dev/null +++ b/publicCloud/model_operating_system.go @@ -0,0 +1,379 @@ +/* +LeaseWeb API for launching and managing Public Cloud instances + +> The base URL for this API is: **https://api.leaseweb.com/publicCloud/v1/_** This API provides ways to launch and manage Public Cloud instances.
BETA
This API is in BETA. Documentation might be incorrect or incomplete. Functionality might change with the final release.> + +API version: v1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package publicCloud + +import ( + "encoding/json" +) + +// checks if the OperatingSystem type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &OperatingSystem{} + +// OperatingSystem struct for OperatingSystem +type OperatingSystem struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Version *string `json:"version,omitempty"` + Family *string `json:"family,omitempty"` + Flavour *string `json:"flavour,omitempty"` + Architecture *string `json:"architecture,omitempty"` + MarketApps []string `json:"marketApps,omitempty"` + // The supported storage types for the instance type + StorageTypes []string `json:"storageTypes,omitempty"` +} + +// NewOperatingSystem instantiates a new OperatingSystem object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewOperatingSystem() *OperatingSystem { + this := OperatingSystem{} + return &this +} + +// NewOperatingSystemWithDefaults instantiates a new OperatingSystem object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewOperatingSystemWithDefaults() *OperatingSystem { + this := OperatingSystem{} + return &this +} + +// GetId returns the Id field value if set, zero value otherwise. +func (o *OperatingSystem) GetId() string { + if o == nil || IsNil(o.Id) { + var ret string + return ret + } + return *o.Id +} + +// GetIdOk returns a tuple with the Id field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *OperatingSystem) GetIdOk() (*string, bool) { + if o == nil || IsNil(o.Id) { + return nil, false + } + return o.Id, true +} + +// HasId returns a boolean if a field has been set. +func (o *OperatingSystem) HasId() bool { + if o != nil && !IsNil(o.Id) { + return true + } + + return false +} + +// SetId gets a reference to the given string and assigns it to the Id field. +func (o *OperatingSystem) SetId(v string) { + o.Id = &v +} + +// GetName returns the Name field value if set, zero value otherwise. +func (o *OperatingSystem) GetName() string { + if o == nil || IsNil(o.Name) { + var ret string + return ret + } + return *o.Name +} + +// GetNameOk returns a tuple with the Name field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *OperatingSystem) GetNameOk() (*string, bool) { + if o == nil || IsNil(o.Name) { + return nil, false + } + return o.Name, true +} + +// HasName returns a boolean if a field has been set. +func (o *OperatingSystem) HasName() bool { + if o != nil && !IsNil(o.Name) { + return true + } + + return false +} + +// SetName gets a reference to the given string and assigns it to the Name field. +func (o *OperatingSystem) SetName(v string) { + o.Name = &v +} + +// GetVersion returns the Version field value if set, zero value otherwise. +func (o *OperatingSystem) GetVersion() string { + if o == nil || IsNil(o.Version) { + var ret string + return ret + } + return *o.Version +} + +// GetVersionOk returns a tuple with the Version field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *OperatingSystem) GetVersionOk() (*string, bool) { + if o == nil || IsNil(o.Version) { + return nil, false + } + return o.Version, true +} + +// HasVersion returns a boolean if a field has been set. +func (o *OperatingSystem) HasVersion() bool { + if o != nil && !IsNil(o.Version) { + return true + } + + return false +} + +// SetVersion gets a reference to the given string and assigns it to the Version field. +func (o *OperatingSystem) SetVersion(v string) { + o.Version = &v +} + +// GetFamily returns the Family field value if set, zero value otherwise. +func (o *OperatingSystem) GetFamily() string { + if o == nil || IsNil(o.Family) { + var ret string + return ret + } + return *o.Family +} + +// GetFamilyOk returns a tuple with the Family field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *OperatingSystem) GetFamilyOk() (*string, bool) { + if o == nil || IsNil(o.Family) { + return nil, false + } + return o.Family, true +} + +// HasFamily returns a boolean if a field has been set. +func (o *OperatingSystem) HasFamily() bool { + if o != nil && !IsNil(o.Family) { + return true + } + + return false +} + +// SetFamily gets a reference to the given string and assigns it to the Family field. +func (o *OperatingSystem) SetFamily(v string) { + o.Family = &v +} + +// GetFlavour returns the Flavour field value if set, zero value otherwise. +func (o *OperatingSystem) GetFlavour() string { + if o == nil || IsNil(o.Flavour) { + var ret string + return ret + } + return *o.Flavour +} + +// GetFlavourOk returns a tuple with the Flavour field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *OperatingSystem) GetFlavourOk() (*string, bool) { + if o == nil || IsNil(o.Flavour) { + return nil, false + } + return o.Flavour, true +} + +// HasFlavour returns a boolean if a field has been set. +func (o *OperatingSystem) HasFlavour() bool { + if o != nil && !IsNil(o.Flavour) { + return true + } + + return false +} + +// SetFlavour gets a reference to the given string and assigns it to the Flavour field. +func (o *OperatingSystem) SetFlavour(v string) { + o.Flavour = &v +} + +// GetArchitecture returns the Architecture field value if set, zero value otherwise. +func (o *OperatingSystem) GetArchitecture() string { + if o == nil || IsNil(o.Architecture) { + var ret string + return ret + } + return *o.Architecture +} + +// GetArchitectureOk returns a tuple with the Architecture field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *OperatingSystem) GetArchitectureOk() (*string, bool) { + if o == nil || IsNil(o.Architecture) { + return nil, false + } + return o.Architecture, true +} + +// HasArchitecture returns a boolean if a field has been set. +func (o *OperatingSystem) HasArchitecture() bool { + if o != nil && !IsNil(o.Architecture) { + return true + } + + return false +} + +// SetArchitecture gets a reference to the given string and assigns it to the Architecture field. +func (o *OperatingSystem) SetArchitecture(v string) { + o.Architecture = &v +} + +// GetMarketApps returns the MarketApps field value if set, zero value otherwise. +func (o *OperatingSystem) GetMarketApps() []string { + if o == nil || IsNil(o.MarketApps) { + var ret []string + return ret + } + return o.MarketApps +} + +// GetMarketAppsOk returns a tuple with the MarketApps field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *OperatingSystem) GetMarketAppsOk() ([]string, bool) { + if o == nil || IsNil(o.MarketApps) { + return nil, false + } + return o.MarketApps, true +} + +// HasMarketApps returns a boolean if a field has been set. +func (o *OperatingSystem) HasMarketApps() bool { + if o != nil && !IsNil(o.MarketApps) { + return true + } + + return false +} + +// SetMarketApps gets a reference to the given []string and assigns it to the MarketApps field. +func (o *OperatingSystem) SetMarketApps(v []string) { + o.MarketApps = v +} + +// GetStorageTypes returns the StorageTypes field value if set, zero value otherwise. +func (o *OperatingSystem) GetStorageTypes() []string { + if o == nil || IsNil(o.StorageTypes) { + var ret []string + return ret + } + return o.StorageTypes +} + +// GetStorageTypesOk returns a tuple with the StorageTypes field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *OperatingSystem) GetStorageTypesOk() ([]string, bool) { + if o == nil || IsNil(o.StorageTypes) { + return nil, false + } + return o.StorageTypes, true +} + +// HasStorageTypes returns a boolean if a field has been set. +func (o *OperatingSystem) HasStorageTypes() bool { + if o != nil && !IsNil(o.StorageTypes) { + return true + } + + return false +} + +// SetStorageTypes gets a reference to the given []string and assigns it to the StorageTypes field. +func (o *OperatingSystem) SetStorageTypes(v []string) { + o.StorageTypes = v +} + +func (o OperatingSystem) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o OperatingSystem) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Id) { + toSerialize["id"] = o.Id + } + if !IsNil(o.Name) { + toSerialize["name"] = o.Name + } + if !IsNil(o.Version) { + toSerialize["version"] = o.Version + } + if !IsNil(o.Family) { + toSerialize["family"] = o.Family + } + if !IsNil(o.Flavour) { + toSerialize["flavour"] = o.Flavour + } + if !IsNil(o.Architecture) { + toSerialize["architecture"] = o.Architecture + } + if !IsNil(o.MarketApps) { + toSerialize["marketApps"] = o.MarketApps + } + if !IsNil(o.StorageTypes) { + toSerialize["storageTypes"] = o.StorageTypes + } + return toSerialize, nil +} + +type NullableOperatingSystem struct { + value *OperatingSystem + isSet bool +} + +func (v NullableOperatingSystem) Get() *OperatingSystem { + return v.value +} + +func (v *NullableOperatingSystem) Set(val *OperatingSystem) { + v.value = val + v.isSet = true +} + +func (v NullableOperatingSystem) IsSet() bool { + return v.isSet +} + +func (v *NullableOperatingSystem) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableOperatingSystem(val *OperatingSystem) *NullableOperatingSystem { + return &NullableOperatingSystem{value: val, isSet: true} +} + +func (v NullableOperatingSystem) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableOperatingSystem) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/publicCloud/model_operating_system_detail.go b/publicCloud/model_operating_system_detail.go new file mode 100644 index 0000000..2117e16 --- /dev/null +++ b/publicCloud/model_operating_system_detail.go @@ -0,0 +1,380 @@ +/* +LeaseWeb API for launching and managing Public Cloud instances + +> The base URL for this API is: **https://api.leaseweb.com/publicCloud/v1/_** This API provides ways to launch and manage Public Cloud instances.
BETA
This API is in BETA. Documentation might be incorrect or incomplete. Functionality might change with the final release.> + +API version: v1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package publicCloud + +import ( + "encoding/json" +) + +// checks if the OperatingSystemDetail type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &OperatingSystemDetail{} + +// OperatingSystemDetail struct for OperatingSystemDetail +type OperatingSystemDetail struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Version *string `json:"version,omitempty"` + Family *string `json:"family,omitempty"` + Flavour *string `json:"flavour,omitempty"` + Architecture *string `json:"architecture,omitempty"` + // The marketplace app IDs used to reference to on other operations + MarketApps []string `json:"marketApps,omitempty"` + // The storage types supported by the operating systems + StorageTypes []string `json:"storageTypes,omitempty"` +} + +// NewOperatingSystemDetail instantiates a new OperatingSystemDetail object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewOperatingSystemDetail() *OperatingSystemDetail { + this := OperatingSystemDetail{} + return &this +} + +// NewOperatingSystemDetailWithDefaults instantiates a new OperatingSystemDetail object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewOperatingSystemDetailWithDefaults() *OperatingSystemDetail { + this := OperatingSystemDetail{} + return &this +} + +// GetId returns the Id field value if set, zero value otherwise. +func (o *OperatingSystemDetail) GetId() string { + if o == nil || IsNil(o.Id) { + var ret string + return ret + } + return *o.Id +} + +// GetIdOk returns a tuple with the Id field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *OperatingSystemDetail) GetIdOk() (*string, bool) { + if o == nil || IsNil(o.Id) { + return nil, false + } + return o.Id, true +} + +// HasId returns a boolean if a field has been set. +func (o *OperatingSystemDetail) HasId() bool { + if o != nil && !IsNil(o.Id) { + return true + } + + return false +} + +// SetId gets a reference to the given string and assigns it to the Id field. +func (o *OperatingSystemDetail) SetId(v string) { + o.Id = &v +} + +// GetName returns the Name field value if set, zero value otherwise. +func (o *OperatingSystemDetail) GetName() string { + if o == nil || IsNil(o.Name) { + var ret string + return ret + } + return *o.Name +} + +// GetNameOk returns a tuple with the Name field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *OperatingSystemDetail) GetNameOk() (*string, bool) { + if o == nil || IsNil(o.Name) { + return nil, false + } + return o.Name, true +} + +// HasName returns a boolean if a field has been set. +func (o *OperatingSystemDetail) HasName() bool { + if o != nil && !IsNil(o.Name) { + return true + } + + return false +} + +// SetName gets a reference to the given string and assigns it to the Name field. +func (o *OperatingSystemDetail) SetName(v string) { + o.Name = &v +} + +// GetVersion returns the Version field value if set, zero value otherwise. +func (o *OperatingSystemDetail) GetVersion() string { + if o == nil || IsNil(o.Version) { + var ret string + return ret + } + return *o.Version +} + +// GetVersionOk returns a tuple with the Version field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *OperatingSystemDetail) GetVersionOk() (*string, bool) { + if o == nil || IsNil(o.Version) { + return nil, false + } + return o.Version, true +} + +// HasVersion returns a boolean if a field has been set. +func (o *OperatingSystemDetail) HasVersion() bool { + if o != nil && !IsNil(o.Version) { + return true + } + + return false +} + +// SetVersion gets a reference to the given string and assigns it to the Version field. +func (o *OperatingSystemDetail) SetVersion(v string) { + o.Version = &v +} + +// GetFamily returns the Family field value if set, zero value otherwise. +func (o *OperatingSystemDetail) GetFamily() string { + if o == nil || IsNil(o.Family) { + var ret string + return ret + } + return *o.Family +} + +// GetFamilyOk returns a tuple with the Family field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *OperatingSystemDetail) GetFamilyOk() (*string, bool) { + if o == nil || IsNil(o.Family) { + return nil, false + } + return o.Family, true +} + +// HasFamily returns a boolean if a field has been set. +func (o *OperatingSystemDetail) HasFamily() bool { + if o != nil && !IsNil(o.Family) { + return true + } + + return false +} + +// SetFamily gets a reference to the given string and assigns it to the Family field. +func (o *OperatingSystemDetail) SetFamily(v string) { + o.Family = &v +} + +// GetFlavour returns the Flavour field value if set, zero value otherwise. +func (o *OperatingSystemDetail) GetFlavour() string { + if o == nil || IsNil(o.Flavour) { + var ret string + return ret + } + return *o.Flavour +} + +// GetFlavourOk returns a tuple with the Flavour field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *OperatingSystemDetail) GetFlavourOk() (*string, bool) { + if o == nil || IsNil(o.Flavour) { + return nil, false + } + return o.Flavour, true +} + +// HasFlavour returns a boolean if a field has been set. +func (o *OperatingSystemDetail) HasFlavour() bool { + if o != nil && !IsNil(o.Flavour) { + return true + } + + return false +} + +// SetFlavour gets a reference to the given string and assigns it to the Flavour field. +func (o *OperatingSystemDetail) SetFlavour(v string) { + o.Flavour = &v +} + +// GetArchitecture returns the Architecture field value if set, zero value otherwise. +func (o *OperatingSystemDetail) GetArchitecture() string { + if o == nil || IsNil(o.Architecture) { + var ret string + return ret + } + return *o.Architecture +} + +// GetArchitectureOk returns a tuple with the Architecture field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *OperatingSystemDetail) GetArchitectureOk() (*string, bool) { + if o == nil || IsNil(o.Architecture) { + return nil, false + } + return o.Architecture, true +} + +// HasArchitecture returns a boolean if a field has been set. +func (o *OperatingSystemDetail) HasArchitecture() bool { + if o != nil && !IsNil(o.Architecture) { + return true + } + + return false +} + +// SetArchitecture gets a reference to the given string and assigns it to the Architecture field. +func (o *OperatingSystemDetail) SetArchitecture(v string) { + o.Architecture = &v +} + +// GetMarketApps returns the MarketApps field value if set, zero value otherwise. +func (o *OperatingSystemDetail) GetMarketApps() []string { + if o == nil || IsNil(o.MarketApps) { + var ret []string + return ret + } + return o.MarketApps +} + +// GetMarketAppsOk returns a tuple with the MarketApps field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *OperatingSystemDetail) GetMarketAppsOk() ([]string, bool) { + if o == nil || IsNil(o.MarketApps) { + return nil, false + } + return o.MarketApps, true +} + +// HasMarketApps returns a boolean if a field has been set. +func (o *OperatingSystemDetail) HasMarketApps() bool { + if o != nil && !IsNil(o.MarketApps) { + return true + } + + return false +} + +// SetMarketApps gets a reference to the given []string and assigns it to the MarketApps field. +func (o *OperatingSystemDetail) SetMarketApps(v []string) { + o.MarketApps = v +} + +// GetStorageTypes returns the StorageTypes field value if set, zero value otherwise. +func (o *OperatingSystemDetail) GetStorageTypes() []string { + if o == nil || IsNil(o.StorageTypes) { + var ret []string + return ret + } + return o.StorageTypes +} + +// GetStorageTypesOk returns a tuple with the StorageTypes field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *OperatingSystemDetail) GetStorageTypesOk() ([]string, bool) { + if o == nil || IsNil(o.StorageTypes) { + return nil, false + } + return o.StorageTypes, true +} + +// HasStorageTypes returns a boolean if a field has been set. +func (o *OperatingSystemDetail) HasStorageTypes() bool { + if o != nil && !IsNil(o.StorageTypes) { + return true + } + + return false +} + +// SetStorageTypes gets a reference to the given []string and assigns it to the StorageTypes field. +func (o *OperatingSystemDetail) SetStorageTypes(v []string) { + o.StorageTypes = v +} + +func (o OperatingSystemDetail) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o OperatingSystemDetail) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Id) { + toSerialize["id"] = o.Id + } + if !IsNil(o.Name) { + toSerialize["name"] = o.Name + } + if !IsNil(o.Version) { + toSerialize["version"] = o.Version + } + if !IsNil(o.Family) { + toSerialize["family"] = o.Family + } + if !IsNil(o.Flavour) { + toSerialize["flavour"] = o.Flavour + } + if !IsNil(o.Architecture) { + toSerialize["architecture"] = o.Architecture + } + if !IsNil(o.MarketApps) { + toSerialize["marketApps"] = o.MarketApps + } + if !IsNil(o.StorageTypes) { + toSerialize["storageTypes"] = o.StorageTypes + } + return toSerialize, nil +} + +type NullableOperatingSystemDetail struct { + value *OperatingSystemDetail + isSet bool +} + +func (v NullableOperatingSystemDetail) Get() *OperatingSystemDetail { + return v.value +} + +func (v *NullableOperatingSystemDetail) Set(val *OperatingSystemDetail) { + v.value = val + v.isSet = true +} + +func (v NullableOperatingSystemDetail) IsSet() bool { + return v.isSet +} + +func (v *NullableOperatingSystemDetail) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableOperatingSystemDetail(val *OperatingSystemDetail) *NullableOperatingSystemDetail { + return &NullableOperatingSystemDetail{value: val, isSet: true} +} + +func (v NullableOperatingSystemDetail) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableOperatingSystemDetail) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/publicCloud/model_price.go b/publicCloud/model_price.go new file mode 100644 index 0000000..d4493d9 --- /dev/null +++ b/publicCloud/model_price.go @@ -0,0 +1,234 @@ +/* +LeaseWeb API for launching and managing Public Cloud instances + +> The base URL for this API is: **https://api.leaseweb.com/publicCloud/v1/_** This API provides ways to launch and manage Public Cloud instances.
BETA
This API is in BETA. Documentation might be incorrect or incomplete. Functionality might change with the final release.> + +API version: v1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package publicCloud + +import ( + "encoding/json" +) + +// checks if the Price type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &Price{} + +// Price struct for Price +type Price struct { + Currency *string `json:"currency,omitempty"` + CurrencySymbol *string `json:"currencySymbol,omitempty"` + Compute *Compute `json:"compute,omitempty"` + Storage *Storage `json:"storage,omitempty"` +} + +// NewPrice instantiates a new Price object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewPrice() *Price { + this := Price{} + return &this +} + +// NewPriceWithDefaults instantiates a new Price object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewPriceWithDefaults() *Price { + this := Price{} + return &this +} + +// GetCurrency returns the Currency field value if set, zero value otherwise. +func (o *Price) GetCurrency() string { + if o == nil || IsNil(o.Currency) { + var ret string + return ret + } + return *o.Currency +} + +// GetCurrencyOk returns a tuple with the Currency field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Price) GetCurrencyOk() (*string, bool) { + if o == nil || IsNil(o.Currency) { + return nil, false + } + return o.Currency, true +} + +// HasCurrency returns a boolean if a field has been set. +func (o *Price) HasCurrency() bool { + if o != nil && !IsNil(o.Currency) { + return true + } + + return false +} + +// SetCurrency gets a reference to the given string and assigns it to the Currency field. +func (o *Price) SetCurrency(v string) { + o.Currency = &v +} + +// GetCurrencySymbol returns the CurrencySymbol field value if set, zero value otherwise. +func (o *Price) GetCurrencySymbol() string { + if o == nil || IsNil(o.CurrencySymbol) { + var ret string + return ret + } + return *o.CurrencySymbol +} + +// GetCurrencySymbolOk returns a tuple with the CurrencySymbol field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Price) GetCurrencySymbolOk() (*string, bool) { + if o == nil || IsNil(o.CurrencySymbol) { + return nil, false + } + return o.CurrencySymbol, true +} + +// HasCurrencySymbol returns a boolean if a field has been set. +func (o *Price) HasCurrencySymbol() bool { + if o != nil && !IsNil(o.CurrencySymbol) { + return true + } + + return false +} + +// SetCurrencySymbol gets a reference to the given string and assigns it to the CurrencySymbol field. +func (o *Price) SetCurrencySymbol(v string) { + o.CurrencySymbol = &v +} + +// GetCompute returns the Compute field value if set, zero value otherwise. +func (o *Price) GetCompute() Compute { + if o == nil || IsNil(o.Compute) { + var ret Compute + return ret + } + return *o.Compute +} + +// GetComputeOk returns a tuple with the Compute field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Price) GetComputeOk() (*Compute, bool) { + if o == nil || IsNil(o.Compute) { + return nil, false + } + return o.Compute, true +} + +// HasCompute returns a boolean if a field has been set. +func (o *Price) HasCompute() bool { + if o != nil && !IsNil(o.Compute) { + return true + } + + return false +} + +// SetCompute gets a reference to the given Compute and assigns it to the Compute field. +func (o *Price) SetCompute(v Compute) { + o.Compute = &v +} + +// GetStorage returns the Storage field value if set, zero value otherwise. +func (o *Price) GetStorage() Storage { + if o == nil || IsNil(o.Storage) { + var ret Storage + return ret + } + return *o.Storage +} + +// GetStorageOk returns a tuple with the Storage field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Price) GetStorageOk() (*Storage, bool) { + if o == nil || IsNil(o.Storage) { + return nil, false + } + return o.Storage, true +} + +// HasStorage returns a boolean if a field has been set. +func (o *Price) HasStorage() bool { + if o != nil && !IsNil(o.Storage) { + return true + } + + return false +} + +// SetStorage gets a reference to the given Storage and assigns it to the Storage field. +func (o *Price) SetStorage(v Storage) { + o.Storage = &v +} + +func (o Price) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o Price) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Currency) { + toSerialize["currency"] = o.Currency + } + if !IsNil(o.CurrencySymbol) { + toSerialize["currencySymbol"] = o.CurrencySymbol + } + if !IsNil(o.Compute) { + toSerialize["compute"] = o.Compute + } + if !IsNil(o.Storage) { + toSerialize["storage"] = o.Storage + } + return toSerialize, nil +} + +type NullablePrice struct { + value *Price + isSet bool +} + +func (v NullablePrice) Get() *Price { + return v.value +} + +func (v *NullablePrice) Set(val *Price) { + v.value = val + v.isSet = true +} + +func (v NullablePrice) IsSet() bool { + return v.isSet +} + +func (v *NullablePrice) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullablePrice(val *Price) *NullablePrice { + return &NullablePrice{value: val, isSet: true} +} + +func (v NullablePrice) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullablePrice) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/publicCloud/model_private_network.go b/publicCloud/model_private_network.go new file mode 100644 index 0000000..6791a00 --- /dev/null +++ b/publicCloud/model_private_network.go @@ -0,0 +1,198 @@ +/* +LeaseWeb API for launching and managing Public Cloud instances + +> The base URL for this API is: **https://api.leaseweb.com/publicCloud/v1/_** This API provides ways to launch and manage Public Cloud instances.
BETA
This API is in BETA. Documentation might be incorrect or incomplete. Functionality might change with the final release.> + +API version: v1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package publicCloud + +import ( + "encoding/json" +) + +// checks if the PrivateNetwork type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &PrivateNetwork{} + +// PrivateNetwork struct for PrivateNetwork +type PrivateNetwork struct { + PrivateNetworkId *string `json:"privateNetworkId,omitempty"` + Status *string `json:"status,omitempty"` + Subnet *string `json:"subnet,omitempty"` +} + +// NewPrivateNetwork instantiates a new PrivateNetwork object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewPrivateNetwork() *PrivateNetwork { + this := PrivateNetwork{} + return &this +} + +// NewPrivateNetworkWithDefaults instantiates a new PrivateNetwork object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewPrivateNetworkWithDefaults() *PrivateNetwork { + this := PrivateNetwork{} + return &this +} + +// GetPrivateNetworkId returns the PrivateNetworkId field value if set, zero value otherwise. +func (o *PrivateNetwork) GetPrivateNetworkId() string { + if o == nil || IsNil(o.PrivateNetworkId) { + var ret string + return ret + } + return *o.PrivateNetworkId +} + +// GetPrivateNetworkIdOk returns a tuple with the PrivateNetworkId field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *PrivateNetwork) GetPrivateNetworkIdOk() (*string, bool) { + if o == nil || IsNil(o.PrivateNetworkId) { + return nil, false + } + return o.PrivateNetworkId, true +} + +// HasPrivateNetworkId returns a boolean if a field has been set. +func (o *PrivateNetwork) HasPrivateNetworkId() bool { + if o != nil && !IsNil(o.PrivateNetworkId) { + return true + } + + return false +} + +// SetPrivateNetworkId gets a reference to the given string and assigns it to the PrivateNetworkId field. +func (o *PrivateNetwork) SetPrivateNetworkId(v string) { + o.PrivateNetworkId = &v +} + +// GetStatus returns the Status field value if set, zero value otherwise. +func (o *PrivateNetwork) GetStatus() string { + if o == nil || IsNil(o.Status) { + var ret string + return ret + } + return *o.Status +} + +// GetStatusOk returns a tuple with the Status field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *PrivateNetwork) GetStatusOk() (*string, bool) { + if o == nil || IsNil(o.Status) { + return nil, false + } + return o.Status, true +} + +// HasStatus returns a boolean if a field has been set. +func (o *PrivateNetwork) HasStatus() bool { + if o != nil && !IsNil(o.Status) { + return true + } + + return false +} + +// SetStatus gets a reference to the given string and assigns it to the Status field. +func (o *PrivateNetwork) SetStatus(v string) { + o.Status = &v +} + +// GetSubnet returns the Subnet field value if set, zero value otherwise. +func (o *PrivateNetwork) GetSubnet() string { + if o == nil || IsNil(o.Subnet) { + var ret string + return ret + } + return *o.Subnet +} + +// GetSubnetOk returns a tuple with the Subnet field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *PrivateNetwork) GetSubnetOk() (*string, bool) { + if o == nil || IsNil(o.Subnet) { + return nil, false + } + return o.Subnet, true +} + +// HasSubnet returns a boolean if a field has been set. +func (o *PrivateNetwork) HasSubnet() bool { + if o != nil && !IsNil(o.Subnet) { + return true + } + + return false +} + +// SetSubnet gets a reference to the given string and assigns it to the Subnet field. +func (o *PrivateNetwork) SetSubnet(v string) { + o.Subnet = &v +} + +func (o PrivateNetwork) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o PrivateNetwork) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.PrivateNetworkId) { + toSerialize["privateNetworkId"] = o.PrivateNetworkId + } + if !IsNil(o.Status) { + toSerialize["status"] = o.Status + } + if !IsNil(o.Subnet) { + toSerialize["subnet"] = o.Subnet + } + return toSerialize, nil +} + +type NullablePrivateNetwork struct { + value *PrivateNetwork + isSet bool +} + +func (v NullablePrivateNetwork) Get() *PrivateNetwork { + return v.value +} + +func (v *NullablePrivateNetwork) Set(val *PrivateNetwork) { + v.value = val + v.isSet = true +} + +func (v NullablePrivateNetwork) IsSet() bool { + return v.isSet +} + +func (v *NullablePrivateNetwork) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullablePrivateNetwork(val *PrivateNetwork) *NullablePrivateNetwork { + return &NullablePrivateNetwork{value: val, isSet: true} +} + +func (v NullablePrivateNetwork) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullablePrivateNetwork) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/publicCloud/model_private_network_speed.go b/publicCloud/model_private_network_speed.go new file mode 100644 index 0000000..0d8c8de --- /dev/null +++ b/publicCloud/model_private_network_speed.go @@ -0,0 +1,162 @@ +/* +LeaseWeb API for launching and managing Public Cloud instances + +> The base URL for this API is: **https://api.leaseweb.com/publicCloud/v1/_** This API provides ways to launch and manage Public Cloud instances.
BETA
This API is in BETA. Documentation might be incorrect or incomplete. Functionality might change with the final release.> + +API version: v1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package publicCloud + +import ( + "encoding/json" +) + +// checks if the PrivateNetworkSpeed type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &PrivateNetworkSpeed{} + +// PrivateNetworkSpeed Private network speed in Gbps +type PrivateNetworkSpeed struct { + Value *int32 `json:"value,omitempty"` + Unit *string `json:"unit,omitempty"` +} + +// NewPrivateNetworkSpeed instantiates a new PrivateNetworkSpeed object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewPrivateNetworkSpeed() *PrivateNetworkSpeed { + this := PrivateNetworkSpeed{} + return &this +} + +// NewPrivateNetworkSpeedWithDefaults instantiates a new PrivateNetworkSpeed object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewPrivateNetworkSpeedWithDefaults() *PrivateNetworkSpeed { + this := PrivateNetworkSpeed{} + return &this +} + +// GetValue returns the Value field value if set, zero value otherwise. +func (o *PrivateNetworkSpeed) GetValue() int32 { + if o == nil || IsNil(o.Value) { + var ret int32 + return ret + } + return *o.Value +} + +// GetValueOk returns a tuple with the Value field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *PrivateNetworkSpeed) GetValueOk() (*int32, bool) { + if o == nil || IsNil(o.Value) { + return nil, false + } + return o.Value, true +} + +// HasValue returns a boolean if a field has been set. +func (o *PrivateNetworkSpeed) HasValue() bool { + if o != nil && !IsNil(o.Value) { + return true + } + + return false +} + +// SetValue gets a reference to the given int32 and assigns it to the Value field. +func (o *PrivateNetworkSpeed) SetValue(v int32) { + o.Value = &v +} + +// GetUnit returns the Unit field value if set, zero value otherwise. +func (o *PrivateNetworkSpeed) GetUnit() string { + if o == nil || IsNil(o.Unit) { + var ret string + return ret + } + return *o.Unit +} + +// GetUnitOk returns a tuple with the Unit field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *PrivateNetworkSpeed) GetUnitOk() (*string, bool) { + if o == nil || IsNil(o.Unit) { + return nil, false + } + return o.Unit, true +} + +// HasUnit returns a boolean if a field has been set. +func (o *PrivateNetworkSpeed) HasUnit() bool { + if o != nil && !IsNil(o.Unit) { + return true + } + + return false +} + +// SetUnit gets a reference to the given string and assigns it to the Unit field. +func (o *PrivateNetworkSpeed) SetUnit(v string) { + o.Unit = &v +} + +func (o PrivateNetworkSpeed) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o PrivateNetworkSpeed) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Value) { + toSerialize["value"] = o.Value + } + if !IsNil(o.Unit) { + toSerialize["unit"] = o.Unit + } + return toSerialize, nil +} + +type NullablePrivateNetworkSpeed struct { + value *PrivateNetworkSpeed + isSet bool +} + +func (v NullablePrivateNetworkSpeed) Get() *PrivateNetworkSpeed { + return v.value +} + +func (v *NullablePrivateNetworkSpeed) Set(val *PrivateNetworkSpeed) { + v.value = val + v.isSet = true +} + +func (v NullablePrivateNetworkSpeed) IsSet() bool { + return v.isSet +} + +func (v *NullablePrivateNetworkSpeed) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullablePrivateNetworkSpeed(val *PrivateNetworkSpeed) *NullablePrivateNetworkSpeed { + return &NullablePrivateNetworkSpeed{value: val, isSet: true} +} + +func (v NullablePrivateNetworkSpeed) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullablePrivateNetworkSpeed) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/publicCloud/model_public_network_speed.go b/publicCloud/model_public_network_speed.go new file mode 100644 index 0000000..92450f5 --- /dev/null +++ b/publicCloud/model_public_network_speed.go @@ -0,0 +1,162 @@ +/* +LeaseWeb API for launching and managing Public Cloud instances + +> The base URL for this API is: **https://api.leaseweb.com/publicCloud/v1/_** This API provides ways to launch and manage Public Cloud instances.
BETA
This API is in BETA. Documentation might be incorrect or incomplete. Functionality might change with the final release.> + +API version: v1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package publicCloud + +import ( + "encoding/json" +) + +// checks if the PublicNetworkSpeed type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &PublicNetworkSpeed{} + +// PublicNetworkSpeed Public network speed in Gbps +type PublicNetworkSpeed struct { + Value *int32 `json:"value,omitempty"` + Unit *string `json:"unit,omitempty"` +} + +// NewPublicNetworkSpeed instantiates a new PublicNetworkSpeed object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewPublicNetworkSpeed() *PublicNetworkSpeed { + this := PublicNetworkSpeed{} + return &this +} + +// NewPublicNetworkSpeedWithDefaults instantiates a new PublicNetworkSpeed object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewPublicNetworkSpeedWithDefaults() *PublicNetworkSpeed { + this := PublicNetworkSpeed{} + return &this +} + +// GetValue returns the Value field value if set, zero value otherwise. +func (o *PublicNetworkSpeed) GetValue() int32 { + if o == nil || IsNil(o.Value) { + var ret int32 + return ret + } + return *o.Value +} + +// GetValueOk returns a tuple with the Value field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *PublicNetworkSpeed) GetValueOk() (*int32, bool) { + if o == nil || IsNil(o.Value) { + return nil, false + } + return o.Value, true +} + +// HasValue returns a boolean if a field has been set. +func (o *PublicNetworkSpeed) HasValue() bool { + if o != nil && !IsNil(o.Value) { + return true + } + + return false +} + +// SetValue gets a reference to the given int32 and assigns it to the Value field. +func (o *PublicNetworkSpeed) SetValue(v int32) { + o.Value = &v +} + +// GetUnit returns the Unit field value if set, zero value otherwise. +func (o *PublicNetworkSpeed) GetUnit() string { + if o == nil || IsNil(o.Unit) { + var ret string + return ret + } + return *o.Unit +} + +// GetUnitOk returns a tuple with the Unit field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *PublicNetworkSpeed) GetUnitOk() (*string, bool) { + if o == nil || IsNil(o.Unit) { + return nil, false + } + return o.Unit, true +} + +// HasUnit returns a boolean if a field has been set. +func (o *PublicNetworkSpeed) HasUnit() bool { + if o != nil && !IsNil(o.Unit) { + return true + } + + return false +} + +// SetUnit gets a reference to the given string and assigns it to the Unit field. +func (o *PublicNetworkSpeed) SetUnit(v string) { + o.Unit = &v +} + +func (o PublicNetworkSpeed) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o PublicNetworkSpeed) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Value) { + toSerialize["value"] = o.Value + } + if !IsNil(o.Unit) { + toSerialize["unit"] = o.Unit + } + return toSerialize, nil +} + +type NullablePublicNetworkSpeed struct { + value *PublicNetworkSpeed + isSet bool +} + +func (v NullablePublicNetworkSpeed) Get() *PublicNetworkSpeed { + return v.value +} + +func (v *NullablePublicNetworkSpeed) Set(val *PublicNetworkSpeed) { + v.value = val + v.isSet = true +} + +func (v NullablePublicNetworkSpeed) IsSet() bool { + return v.isSet +} + +func (v *NullablePublicNetworkSpeed) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullablePublicNetworkSpeed(val *PublicNetworkSpeed) *NullablePublicNetworkSpeed { + return &NullablePublicNetworkSpeed{value: val, isSet: true} +} + +func (v NullablePublicNetworkSpeed) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullablePublicNetworkSpeed) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/publicCloud/model_region.go b/publicCloud/model_region.go new file mode 100644 index 0000000..8eca2e5 --- /dev/null +++ b/publicCloud/model_region.go @@ -0,0 +1,164 @@ +/* +LeaseWeb API for launching and managing Public Cloud instances + +> The base URL for this API is: **https://api.leaseweb.com/publicCloud/v1/_** This API provides ways to launch and manage Public Cloud instances.
BETA
This API is in BETA. Documentation might be incorrect or incomplete. Functionality might change with the final release.> + +API version: v1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package publicCloud + +import ( + "encoding/json" +) + +// checks if the Region type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &Region{} + +// Region struct for Region +type Region struct { + // The region's name. + Name *string `json:"name,omitempty"` + // The city where the region is located. + Location *string `json:"location,omitempty"` +} + +// NewRegion instantiates a new Region object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewRegion() *Region { + this := Region{} + return &this +} + +// NewRegionWithDefaults instantiates a new Region object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewRegionWithDefaults() *Region { + this := Region{} + return &this +} + +// GetName returns the Name field value if set, zero value otherwise. +func (o *Region) GetName() string { + if o == nil || IsNil(o.Name) { + var ret string + return ret + } + return *o.Name +} + +// GetNameOk returns a tuple with the Name field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Region) GetNameOk() (*string, bool) { + if o == nil || IsNil(o.Name) { + return nil, false + } + return o.Name, true +} + +// HasName returns a boolean if a field has been set. +func (o *Region) HasName() bool { + if o != nil && !IsNil(o.Name) { + return true + } + + return false +} + +// SetName gets a reference to the given string and assigns it to the Name field. +func (o *Region) SetName(v string) { + o.Name = &v +} + +// GetLocation returns the Location field value if set, zero value otherwise. +func (o *Region) GetLocation() string { + if o == nil || IsNil(o.Location) { + var ret string + return ret + } + return *o.Location +} + +// GetLocationOk returns a tuple with the Location field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Region) GetLocationOk() (*string, bool) { + if o == nil || IsNil(o.Location) { + return nil, false + } + return o.Location, true +} + +// HasLocation returns a boolean if a field has been set. +func (o *Region) HasLocation() bool { + if o != nil && !IsNil(o.Location) { + return true + } + + return false +} + +// SetLocation gets a reference to the given string and assigns it to the Location field. +func (o *Region) SetLocation(v string) { + o.Location = &v +} + +func (o Region) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o Region) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Name) { + toSerialize["name"] = o.Name + } + if !IsNil(o.Location) { + toSerialize["location"] = o.Location + } + return toSerialize, nil +} + +type NullableRegion struct { + value *Region + isSet bool +} + +func (v NullableRegion) Get() *Region { + return v.value +} + +func (v *NullableRegion) Set(val *Region) { + v.value = val + v.isSet = true +} + +func (v NullableRegion) IsSet() bool { + return v.isSet +} + +func (v *NullableRegion) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableRegion(val *Region) *NullableRegion { + return &NullableRegion{value: val, isSet: true} +} + +func (v NullableRegion) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableRegion) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/publicCloud/model_storage.go b/publicCloud/model_storage.go new file mode 100644 index 0000000..7233cca --- /dev/null +++ b/publicCloud/model_storage.go @@ -0,0 +1,162 @@ +/* +LeaseWeb API for launching and managing Public Cloud instances + +> The base URL for this API is: **https://api.leaseweb.com/publicCloud/v1/_** This API provides ways to launch and manage Public Cloud instances.
BETA
This API is in BETA. Documentation might be incorrect or incomplete. Functionality might change with the final release.> + +API version: v1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package publicCloud + +import ( + "encoding/json" +) + +// checks if the Storage type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &Storage{} + +// Storage struct for Storage +type Storage struct { + Local *Local `json:"local,omitempty"` + Central *Central `json:"central,omitempty"` +} + +// NewStorage instantiates a new Storage object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewStorage() *Storage { + this := Storage{} + return &this +} + +// NewStorageWithDefaults instantiates a new Storage object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewStorageWithDefaults() *Storage { + this := Storage{} + return &this +} + +// GetLocal returns the Local field value if set, zero value otherwise. +func (o *Storage) GetLocal() Local { + if o == nil || IsNil(o.Local) { + var ret Local + return ret + } + return *o.Local +} + +// GetLocalOk returns a tuple with the Local field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Storage) GetLocalOk() (*Local, bool) { + if o == nil || IsNil(o.Local) { + return nil, false + } + return o.Local, true +} + +// HasLocal returns a boolean if a field has been set. +func (o *Storage) HasLocal() bool { + if o != nil && !IsNil(o.Local) { + return true + } + + return false +} + +// SetLocal gets a reference to the given Local and assigns it to the Local field. +func (o *Storage) SetLocal(v Local) { + o.Local = &v +} + +// GetCentral returns the Central field value if set, zero value otherwise. +func (o *Storage) GetCentral() Central { + if o == nil || IsNil(o.Central) { + var ret Central + return ret + } + return *o.Central +} + +// GetCentralOk returns a tuple with the Central field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Storage) GetCentralOk() (*Central, bool) { + if o == nil || IsNil(o.Central) { + return nil, false + } + return o.Central, true +} + +// HasCentral returns a boolean if a field has been set. +func (o *Storage) HasCentral() bool { + if o != nil && !IsNil(o.Central) { + return true + } + + return false +} + +// SetCentral gets a reference to the given Central and assigns it to the Central field. +func (o *Storage) SetCentral(v Central) { + o.Central = &v +} + +func (o Storage) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o Storage) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Local) { + toSerialize["local"] = o.Local + } + if !IsNil(o.Central) { + toSerialize["central"] = o.Central + } + return toSerialize, nil +} + +type NullableStorage struct { + value *Storage + isSet bool +} + +func (v NullableStorage) Get() *Storage { + return v.value +} + +func (v *NullableStorage) Set(val *Storage) { + v.value = val + v.isSet = true +} + +func (v NullableStorage) IsSet() bool { + return v.isSet +} + +func (v *NullableStorage) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableStorage(val *Storage) *NullableStorage { + return &NullableStorage{value: val, isSet: true} +} + +func (v NullableStorage) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableStorage) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/publicCloud/model_store_credential_opts.go b/publicCloud/model_store_credential_opts.go new file mode 100644 index 0000000..767af35 --- /dev/null +++ b/publicCloud/model_store_credential_opts.go @@ -0,0 +1,216 @@ +/* +LeaseWeb API for launching and managing Public Cloud instances + +> The base URL for this API is: **https://api.leaseweb.com/publicCloud/v1/_** This API provides ways to launch and manage Public Cloud instances.
BETA
This API is in BETA. Documentation might be incorrect or incomplete. Functionality might change with the final release.> + +API version: v1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package publicCloud + +import ( + "encoding/json" + "bytes" + "fmt" +) + +// checks if the StoreCredentialOpts type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &StoreCredentialOpts{} + +// StoreCredentialOpts struct for StoreCredentialOpts +type StoreCredentialOpts struct { + Type CredentialType `json:"type"` + // Can contain only alphanumeric values and characters `@`, `.`, `-` and `_` + Username string `json:"username"` + // The password you'd like to store + Password string `json:"password"` +} + +type _StoreCredentialOpts StoreCredentialOpts + +// NewStoreCredentialOpts instantiates a new StoreCredentialOpts object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewStoreCredentialOpts(type_ CredentialType, username string, password string) *StoreCredentialOpts { + this := StoreCredentialOpts{} + this.Type = type_ + this.Username = username + this.Password = password + return &this +} + +// NewStoreCredentialOptsWithDefaults instantiates a new StoreCredentialOpts object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewStoreCredentialOptsWithDefaults() *StoreCredentialOpts { + this := StoreCredentialOpts{} + return &this +} + +// GetType returns the Type field value +func (o *StoreCredentialOpts) GetType() CredentialType { + if o == nil { + var ret CredentialType + return ret + } + + return o.Type +} + +// GetTypeOk returns a tuple with the Type field value +// and a boolean to check if the value has been set. +func (o *StoreCredentialOpts) GetTypeOk() (*CredentialType, bool) { + if o == nil { + return nil, false + } + return &o.Type, true +} + +// SetType sets field value +func (o *StoreCredentialOpts) SetType(v CredentialType) { + o.Type = v +} + +// GetUsername returns the Username field value +func (o *StoreCredentialOpts) GetUsername() string { + if o == nil { + var ret string + return ret + } + + return o.Username +} + +// GetUsernameOk returns a tuple with the Username field value +// and a boolean to check if the value has been set. +func (o *StoreCredentialOpts) GetUsernameOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.Username, true +} + +// SetUsername sets field value +func (o *StoreCredentialOpts) SetUsername(v string) { + o.Username = v +} + +// GetPassword returns the Password field value +func (o *StoreCredentialOpts) GetPassword() string { + if o == nil { + var ret string + return ret + } + + return o.Password +} + +// GetPasswordOk returns a tuple with the Password field value +// and a boolean to check if the value has been set. +func (o *StoreCredentialOpts) GetPasswordOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.Password, true +} + +// SetPassword sets field value +func (o *StoreCredentialOpts) SetPassword(v string) { + o.Password = v +} + +func (o StoreCredentialOpts) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o StoreCredentialOpts) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + toSerialize["type"] = o.Type + toSerialize["username"] = o.Username + toSerialize["password"] = o.Password + return toSerialize, nil +} + +func (o *StoreCredentialOpts) UnmarshalJSON(data []byte) (err error) { + // This validates that all required properties are included in the JSON object + // by unmarshalling the object into a generic map with string keys and checking + // that every required field exists as a key in the generic map. + requiredProperties := []string{ + "type", + "username", + "password", + } + + allProperties := make(map[string]interface{}) + + err = json.Unmarshal(data, &allProperties) + + if err != nil { + return err; + } + + for _, requiredProperty := range(requiredProperties) { + if _, exists := allProperties[requiredProperty]; !exists { + return fmt.Errorf("no value given for required property %v", requiredProperty) + } + } + + varStoreCredentialOpts := _StoreCredentialOpts{} + + decoder := json.NewDecoder(bytes.NewReader(data)) + decoder.DisallowUnknownFields() + err = decoder.Decode(&varStoreCredentialOpts) + + if err != nil { + return err + } + + *o = StoreCredentialOpts(varStoreCredentialOpts) + + return err +} + +type NullableStoreCredentialOpts struct { + value *StoreCredentialOpts + isSet bool +} + +func (v NullableStoreCredentialOpts) Get() *StoreCredentialOpts { + return v.value +} + +func (v *NullableStoreCredentialOpts) Set(val *StoreCredentialOpts) { + v.value = val + v.isSet = true +} + +func (v NullableStoreCredentialOpts) IsSet() bool { + return v.isSet +} + +func (v *NullableStoreCredentialOpts) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableStoreCredentialOpts(val *StoreCredentialOpts) *NullableStoreCredentialOpts { + return &NullableStoreCredentialOpts{value: val, isSet: true} +} + +func (v NullableStoreCredentialOpts) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableStoreCredentialOpts) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/publicCloud/model_store_credential_result.go b/publicCloud/model_store_credential_result.go new file mode 100644 index 0000000..1c54ba6 --- /dev/null +++ b/publicCloud/model_store_credential_result.go @@ -0,0 +1,200 @@ +/* +LeaseWeb API for launching and managing Public Cloud instances + +> The base URL for this API is: **https://api.leaseweb.com/publicCloud/v1/_** This API provides ways to launch and manage Public Cloud instances.
BETA
This API is in BETA. Documentation might be incorrect or incomplete. Functionality might change with the final release.> + +API version: v1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package publicCloud + +import ( + "encoding/json" +) + +// checks if the StoreCredentialResult type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &StoreCredentialResult{} + +// StoreCredentialResult struct for StoreCredentialResult +type StoreCredentialResult struct { + Type *CredentialType `json:"type,omitempty"` + // The provided username + Username *string `json:"username,omitempty"` + // The provided password + Password *string `json:"password,omitempty"` +} + +// NewStoreCredentialResult instantiates a new StoreCredentialResult object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewStoreCredentialResult() *StoreCredentialResult { + this := StoreCredentialResult{} + return &this +} + +// NewStoreCredentialResultWithDefaults instantiates a new StoreCredentialResult object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewStoreCredentialResultWithDefaults() *StoreCredentialResult { + this := StoreCredentialResult{} + return &this +} + +// GetType returns the Type field value if set, zero value otherwise. +func (o *StoreCredentialResult) GetType() CredentialType { + if o == nil || IsNil(o.Type) { + var ret CredentialType + return ret + } + return *o.Type +} + +// GetTypeOk returns a tuple with the Type field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *StoreCredentialResult) GetTypeOk() (*CredentialType, bool) { + if o == nil || IsNil(o.Type) { + return nil, false + } + return o.Type, true +} + +// HasType returns a boolean if a field has been set. +func (o *StoreCredentialResult) HasType() bool { + if o != nil && !IsNil(o.Type) { + return true + } + + return false +} + +// SetType gets a reference to the given CredentialType and assigns it to the Type field. +func (o *StoreCredentialResult) SetType(v CredentialType) { + o.Type = &v +} + +// GetUsername returns the Username field value if set, zero value otherwise. +func (o *StoreCredentialResult) GetUsername() string { + if o == nil || IsNil(o.Username) { + var ret string + return ret + } + return *o.Username +} + +// GetUsernameOk returns a tuple with the Username field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *StoreCredentialResult) GetUsernameOk() (*string, bool) { + if o == nil || IsNil(o.Username) { + return nil, false + } + return o.Username, true +} + +// HasUsername returns a boolean if a field has been set. +func (o *StoreCredentialResult) HasUsername() bool { + if o != nil && !IsNil(o.Username) { + return true + } + + return false +} + +// SetUsername gets a reference to the given string and assigns it to the Username field. +func (o *StoreCredentialResult) SetUsername(v string) { + o.Username = &v +} + +// GetPassword returns the Password field value if set, zero value otherwise. +func (o *StoreCredentialResult) GetPassword() string { + if o == nil || IsNil(o.Password) { + var ret string + return ret + } + return *o.Password +} + +// GetPasswordOk returns a tuple with the Password field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *StoreCredentialResult) GetPasswordOk() (*string, bool) { + if o == nil || IsNil(o.Password) { + return nil, false + } + return o.Password, true +} + +// HasPassword returns a boolean if a field has been set. +func (o *StoreCredentialResult) HasPassword() bool { + if o != nil && !IsNil(o.Password) { + return true + } + + return false +} + +// SetPassword gets a reference to the given string and assigns it to the Password field. +func (o *StoreCredentialResult) SetPassword(v string) { + o.Password = &v +} + +func (o StoreCredentialResult) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o StoreCredentialResult) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Type) { + toSerialize["type"] = o.Type + } + if !IsNil(o.Username) { + toSerialize["username"] = o.Username + } + if !IsNil(o.Password) { + toSerialize["password"] = o.Password + } + return toSerialize, nil +} + +type NullableStoreCredentialResult struct { + value *StoreCredentialResult + isSet bool +} + +func (v NullableStoreCredentialResult) Get() *StoreCredentialResult { + return v.value +} + +func (v *NullableStoreCredentialResult) Set(val *StoreCredentialResult) { + v.value = val + v.isSet = true +} + +func (v NullableStoreCredentialResult) IsSet() bool { + return v.isSet +} + +func (v *NullableStoreCredentialResult) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableStoreCredentialResult(val *StoreCredentialResult) *NullableStoreCredentialResult { + return &NullableStoreCredentialResult{value: val, isSet: true} +} + +func (v NullableStoreCredentialResult) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableStoreCredentialResult) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/publicCloud/model_tcp_udp_firewall_rule.go b/publicCloud/model_tcp_udp_firewall_rule.go new file mode 100644 index 0000000..01cb3e2 --- /dev/null +++ b/publicCloud/model_tcp_udp_firewall_rule.go @@ -0,0 +1,433 @@ +/* +LeaseWeb API for launching and managing Public Cloud instances + +> The base URL for this API is: **https://api.leaseweb.com/publicCloud/v1/_** This API provides ways to launch and manage Public Cloud instances.
BETA
This API is in BETA. Documentation might be incorrect or incomplete. Functionality might change with the final release.> + +API version: v1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package publicCloud + +import ( + "encoding/json" + "bytes" + "fmt" +) + +// checks if the TcpUdpFirewallRule type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &TcpUdpFirewallRule{} + +// TcpUdpFirewallRule struct for TcpUdpFirewallRule +type TcpUdpFirewallRule struct { + Id *string `json:"id,omitempty"` + Name NullableString `json:"name,omitempty"` + Cidr *string `json:"cidr,omitempty"` + Protocol *string `json:"protocol,omitempty"` + StartPort int32 `json:"startPort"` + // Value will be equals to the startPort when not provided + EndPort int32 `json:"endPort"` + IcmpType NullableInt32 `json:"icmpType,omitempty"` + IcmpCode NullableInt32 `json:"icmpCode,omitempty"` +} + +type _TcpUdpFirewallRule TcpUdpFirewallRule + +// NewTcpUdpFirewallRule instantiates a new TcpUdpFirewallRule object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewTcpUdpFirewallRule(startPort int32, endPort int32) *TcpUdpFirewallRule { + this := TcpUdpFirewallRule{} + this.StartPort = startPort + this.EndPort = endPort + return &this +} + +// NewTcpUdpFirewallRuleWithDefaults instantiates a new TcpUdpFirewallRule object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewTcpUdpFirewallRuleWithDefaults() *TcpUdpFirewallRule { + this := TcpUdpFirewallRule{} + return &this +} + +// GetId returns the Id field value if set, zero value otherwise. +func (o *TcpUdpFirewallRule) GetId() string { + if o == nil || IsNil(o.Id) { + var ret string + return ret + } + return *o.Id +} + +// GetIdOk returns a tuple with the Id field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *TcpUdpFirewallRule) GetIdOk() (*string, bool) { + if o == nil || IsNil(o.Id) { + return nil, false + } + return o.Id, true +} + +// HasId returns a boolean if a field has been set. +func (o *TcpUdpFirewallRule) HasId() bool { + if o != nil && !IsNil(o.Id) { + return true + } + + return false +} + +// SetId gets a reference to the given string and assigns it to the Id field. +func (o *TcpUdpFirewallRule) SetId(v string) { + o.Id = &v +} + +// GetName returns the Name field value if set, zero value otherwise (both if not set or set to explicit null). +func (o *TcpUdpFirewallRule) GetName() string { + if o == nil || IsNil(o.Name.Get()) { + var ret string + return ret + } + return *o.Name.Get() +} + +// GetNameOk returns a tuple with the Name field value if set, nil otherwise +// and a boolean to check if the value has been set. +// NOTE: If the value is an explicit nil, `nil, true` will be returned +func (o *TcpUdpFirewallRule) GetNameOk() (*string, bool) { + if o == nil { + return nil, false + } + return o.Name.Get(), o.Name.IsSet() +} + +// HasName returns a boolean if a field has been set. +func (o *TcpUdpFirewallRule) HasName() bool { + if o != nil && o.Name.IsSet() { + return true + } + + return false +} + +// SetName gets a reference to the given NullableString and assigns it to the Name field. +func (o *TcpUdpFirewallRule) SetName(v string) { + o.Name.Set(&v) +} +// SetNameNil sets the value for Name to be an explicit nil +func (o *TcpUdpFirewallRule) SetNameNil() { + o.Name.Set(nil) +} + +// UnsetName ensures that no value is present for Name, not even an explicit nil +func (o *TcpUdpFirewallRule) UnsetName() { + o.Name.Unset() +} + +// GetCidr returns the Cidr field value if set, zero value otherwise. +func (o *TcpUdpFirewallRule) GetCidr() string { + if o == nil || IsNil(o.Cidr) { + var ret string + return ret + } + return *o.Cidr +} + +// GetCidrOk returns a tuple with the Cidr field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *TcpUdpFirewallRule) GetCidrOk() (*string, bool) { + if o == nil || IsNil(o.Cidr) { + return nil, false + } + return o.Cidr, true +} + +// HasCidr returns a boolean if a field has been set. +func (o *TcpUdpFirewallRule) HasCidr() bool { + if o != nil && !IsNil(o.Cidr) { + return true + } + + return false +} + +// SetCidr gets a reference to the given string and assigns it to the Cidr field. +func (o *TcpUdpFirewallRule) SetCidr(v string) { + o.Cidr = &v +} + +// GetProtocol returns the Protocol field value if set, zero value otherwise. +func (o *TcpUdpFirewallRule) GetProtocol() string { + if o == nil || IsNil(o.Protocol) { + var ret string + return ret + } + return *o.Protocol +} + +// GetProtocolOk returns a tuple with the Protocol field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *TcpUdpFirewallRule) GetProtocolOk() (*string, bool) { + if o == nil || IsNil(o.Protocol) { + return nil, false + } + return o.Protocol, true +} + +// HasProtocol returns a boolean if a field has been set. +func (o *TcpUdpFirewallRule) HasProtocol() bool { + if o != nil && !IsNil(o.Protocol) { + return true + } + + return false +} + +// SetProtocol gets a reference to the given string and assigns it to the Protocol field. +func (o *TcpUdpFirewallRule) SetProtocol(v string) { + o.Protocol = &v +} + +// GetStartPort returns the StartPort field value +func (o *TcpUdpFirewallRule) GetStartPort() int32 { + if o == nil { + var ret int32 + return ret + } + + return o.StartPort +} + +// GetStartPortOk returns a tuple with the StartPort field value +// and a boolean to check if the value has been set. +func (o *TcpUdpFirewallRule) GetStartPortOk() (*int32, bool) { + if o == nil { + return nil, false + } + return &o.StartPort, true +} + +// SetStartPort sets field value +func (o *TcpUdpFirewallRule) SetStartPort(v int32) { + o.StartPort = v +} + +// GetEndPort returns the EndPort field value +func (o *TcpUdpFirewallRule) GetEndPort() int32 { + if o == nil { + var ret int32 + return ret + } + + return o.EndPort +} + +// GetEndPortOk returns a tuple with the EndPort field value +// and a boolean to check if the value has been set. +func (o *TcpUdpFirewallRule) GetEndPortOk() (*int32, bool) { + if o == nil { + return nil, false + } + return &o.EndPort, true +} + +// SetEndPort sets field value +func (o *TcpUdpFirewallRule) SetEndPort(v int32) { + o.EndPort = v +} + +// GetIcmpType returns the IcmpType field value if set, zero value otherwise (both if not set or set to explicit null). +func (o *TcpUdpFirewallRule) GetIcmpType() int32 { + if o == nil || IsNil(o.IcmpType.Get()) { + var ret int32 + return ret + } + return *o.IcmpType.Get() +} + +// GetIcmpTypeOk returns a tuple with the IcmpType field value if set, nil otherwise +// and a boolean to check if the value has been set. +// NOTE: If the value is an explicit nil, `nil, true` will be returned +func (o *TcpUdpFirewallRule) GetIcmpTypeOk() (*int32, bool) { + if o == nil { + return nil, false + } + return o.IcmpType.Get(), o.IcmpType.IsSet() +} + +// HasIcmpType returns a boolean if a field has been set. +func (o *TcpUdpFirewallRule) HasIcmpType() bool { + if o != nil && o.IcmpType.IsSet() { + return true + } + + return false +} + +// SetIcmpType gets a reference to the given NullableInt32 and assigns it to the IcmpType field. +func (o *TcpUdpFirewallRule) SetIcmpType(v int32) { + o.IcmpType.Set(&v) +} +// SetIcmpTypeNil sets the value for IcmpType to be an explicit nil +func (o *TcpUdpFirewallRule) SetIcmpTypeNil() { + o.IcmpType.Set(nil) +} + +// UnsetIcmpType ensures that no value is present for IcmpType, not even an explicit nil +func (o *TcpUdpFirewallRule) UnsetIcmpType() { + o.IcmpType.Unset() +} + +// GetIcmpCode returns the IcmpCode field value if set, zero value otherwise (both if not set or set to explicit null). +func (o *TcpUdpFirewallRule) GetIcmpCode() int32 { + if o == nil || IsNil(o.IcmpCode.Get()) { + var ret int32 + return ret + } + return *o.IcmpCode.Get() +} + +// GetIcmpCodeOk returns a tuple with the IcmpCode field value if set, nil otherwise +// and a boolean to check if the value has been set. +// NOTE: If the value is an explicit nil, `nil, true` will be returned +func (o *TcpUdpFirewallRule) GetIcmpCodeOk() (*int32, bool) { + if o == nil { + return nil, false + } + return o.IcmpCode.Get(), o.IcmpCode.IsSet() +} + +// HasIcmpCode returns a boolean if a field has been set. +func (o *TcpUdpFirewallRule) HasIcmpCode() bool { + if o != nil && o.IcmpCode.IsSet() { + return true + } + + return false +} + +// SetIcmpCode gets a reference to the given NullableInt32 and assigns it to the IcmpCode field. +func (o *TcpUdpFirewallRule) SetIcmpCode(v int32) { + o.IcmpCode.Set(&v) +} +// SetIcmpCodeNil sets the value for IcmpCode to be an explicit nil +func (o *TcpUdpFirewallRule) SetIcmpCodeNil() { + o.IcmpCode.Set(nil) +} + +// UnsetIcmpCode ensures that no value is present for IcmpCode, not even an explicit nil +func (o *TcpUdpFirewallRule) UnsetIcmpCode() { + o.IcmpCode.Unset() +} + +func (o TcpUdpFirewallRule) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o TcpUdpFirewallRule) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Id) { + toSerialize["id"] = o.Id + } + if o.Name.IsSet() { + toSerialize["name"] = o.Name.Get() + } + if !IsNil(o.Cidr) { + toSerialize["cidr"] = o.Cidr + } + if !IsNil(o.Protocol) { + toSerialize["protocol"] = o.Protocol + } + toSerialize["startPort"] = o.StartPort + toSerialize["endPort"] = o.EndPort + if o.IcmpType.IsSet() { + toSerialize["icmpType"] = o.IcmpType.Get() + } + if o.IcmpCode.IsSet() { + toSerialize["icmpCode"] = o.IcmpCode.Get() + } + return toSerialize, nil +} + +func (o *TcpUdpFirewallRule) UnmarshalJSON(data []byte) (err error) { + // This validates that all required properties are included in the JSON object + // by unmarshalling the object into a generic map with string keys and checking + // that every required field exists as a key in the generic map. + requiredProperties := []string{ + "startPort", + "endPort", + } + + allProperties := make(map[string]interface{}) + + err = json.Unmarshal(data, &allProperties) + + if err != nil { + return err; + } + + for _, requiredProperty := range(requiredProperties) { + if _, exists := allProperties[requiredProperty]; !exists { + return fmt.Errorf("no value given for required property %v", requiredProperty) + } + } + + varTcpUdpFirewallRule := _TcpUdpFirewallRule{} + + decoder := json.NewDecoder(bytes.NewReader(data)) + decoder.DisallowUnknownFields() + err = decoder.Decode(&varTcpUdpFirewallRule) + + if err != nil { + return err + } + + *o = TcpUdpFirewallRule(varTcpUdpFirewallRule) + + return err +} + +type NullableTcpUdpFirewallRule struct { + value *TcpUdpFirewallRule + isSet bool +} + +func (v NullableTcpUdpFirewallRule) Get() *TcpUdpFirewallRule { + return v.value +} + +func (v *NullableTcpUdpFirewallRule) Set(val *TcpUdpFirewallRule) { + v.value = val + v.isSet = true +} + +func (v NullableTcpUdpFirewallRule) IsSet() bool { + return v.isSet +} + +func (v *NullableTcpUdpFirewallRule) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableTcpUdpFirewallRule(val *TcpUdpFirewallRule) *NullableTcpUdpFirewallRule { + return &NullableTcpUdpFirewallRule{value: val, isSet: true} +} + +func (v NullableTcpUdpFirewallRule) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableTcpUdpFirewallRule) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/publicCloud/model_tier.go b/publicCloud/model_tier.go new file mode 100644 index 0000000..1392d3c --- /dev/null +++ b/publicCloud/model_tier.go @@ -0,0 +1,164 @@ +/* +LeaseWeb API for launching and managing Public Cloud instances + +> The base URL for this API is: **https://api.leaseweb.com/publicCloud/v1/_** This API provides ways to launch and manage Public Cloud instances.
BETA
This API is in BETA. Documentation might be incorrect or incomplete. Functionality might change with the final release.> + +API version: v1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package publicCloud + +import ( + "encoding/json" +) + +// checks if the Tier type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &Tier{} + +// Tier struct for Tier +type Tier struct { + // Traffic sent, in GB + Usage *float32 `json:"usage,omitempty"` + // Total price of the tier, based on the usage. The first tier is free, so this will be 0 for the first tier. From tier 1 onwards, the usage has costs. Each tier has it own price. + Price *float32 `json:"price,omitempty"` +} + +// NewTier instantiates a new Tier object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewTier() *Tier { + this := Tier{} + return &this +} + +// NewTierWithDefaults instantiates a new Tier object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewTierWithDefaults() *Tier { + this := Tier{} + return &this +} + +// GetUsage returns the Usage field value if set, zero value otherwise. +func (o *Tier) GetUsage() float32 { + if o == nil || IsNil(o.Usage) { + var ret float32 + return ret + } + return *o.Usage +} + +// GetUsageOk returns a tuple with the Usage field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Tier) GetUsageOk() (*float32, bool) { + if o == nil || IsNil(o.Usage) { + return nil, false + } + return o.Usage, true +} + +// HasUsage returns a boolean if a field has been set. +func (o *Tier) HasUsage() bool { + if o != nil && !IsNil(o.Usage) { + return true + } + + return false +} + +// SetUsage gets a reference to the given float32 and assigns it to the Usage field. +func (o *Tier) SetUsage(v float32) { + o.Usage = &v +} + +// GetPrice returns the Price field value if set, zero value otherwise. +func (o *Tier) GetPrice() float32 { + if o == nil || IsNil(o.Price) { + var ret float32 + return ret + } + return *o.Price +} + +// GetPriceOk returns a tuple with the Price field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Tier) GetPriceOk() (*float32, bool) { + if o == nil || IsNil(o.Price) { + return nil, false + } + return o.Price, true +} + +// HasPrice returns a boolean if a field has been set. +func (o *Tier) HasPrice() bool { + if o != nil && !IsNil(o.Price) { + return true + } + + return false +} + +// SetPrice gets a reference to the given float32 and assigns it to the Price field. +func (o *Tier) SetPrice(v float32) { + o.Price = &v +} + +func (o Tier) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o Tier) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Usage) { + toSerialize["usage"] = o.Usage + } + if !IsNil(o.Price) { + toSerialize["price"] = o.Price + } + return toSerialize, nil +} + +type NullableTier struct { + value *Tier + isSet bool +} + +func (v NullableTier) Get() *Tier { + return v.value +} + +func (v *NullableTier) Set(val *Tier) { + v.value = val + v.isSet = true +} + +func (v NullableTier) IsSet() bool { + return v.isSet +} + +func (v *NullableTier) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableTier(val *Tier) *NullableTier { + return &NullableTier{value: val, isSet: true} +} + +func (v NullableTier) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableTier) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/publicCloud/model_traffic.go b/publicCloud/model_traffic.go new file mode 100644 index 0000000..38143dd --- /dev/null +++ b/publicCloud/model_traffic.go @@ -0,0 +1,162 @@ +/* +LeaseWeb API for launching and managing Public Cloud instances + +> The base URL for this API is: **https://api.leaseweb.com/publicCloud/v1/_** This API provides ways to launch and manage Public Cloud instances.
BETA
This API is in BETA. Documentation might be incorrect or incomplete. Functionality might change with the final release.> + +API version: v1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package publicCloud + +import ( + "encoding/json" +) + +// checks if the Traffic type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &Traffic{} + +// Traffic Traffic billing information, in tiers. +type Traffic struct { + Unit *string `json:"unit,omitempty"` + Values *Values `json:"values,omitempty"` +} + +// NewTraffic instantiates a new Traffic object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewTraffic() *Traffic { + this := Traffic{} + return &this +} + +// NewTrafficWithDefaults instantiates a new Traffic object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewTrafficWithDefaults() *Traffic { + this := Traffic{} + return &this +} + +// GetUnit returns the Unit field value if set, zero value otherwise. +func (o *Traffic) GetUnit() string { + if o == nil || IsNil(o.Unit) { + var ret string + return ret + } + return *o.Unit +} + +// GetUnitOk returns a tuple with the Unit field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Traffic) GetUnitOk() (*string, bool) { + if o == nil || IsNil(o.Unit) { + return nil, false + } + return o.Unit, true +} + +// HasUnit returns a boolean if a field has been set. +func (o *Traffic) HasUnit() bool { + if o != nil && !IsNil(o.Unit) { + return true + } + + return false +} + +// SetUnit gets a reference to the given string and assigns it to the Unit field. +func (o *Traffic) SetUnit(v string) { + o.Unit = &v +} + +// GetValues returns the Values field value if set, zero value otherwise. +func (o *Traffic) GetValues() Values { + if o == nil || IsNil(o.Values) { + var ret Values + return ret + } + return *o.Values +} + +// GetValuesOk returns a tuple with the Values field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Traffic) GetValuesOk() (*Values, bool) { + if o == nil || IsNil(o.Values) { + return nil, false + } + return o.Values, true +} + +// HasValues returns a boolean if a field has been set. +func (o *Traffic) HasValues() bool { + if o != nil && !IsNil(o.Values) { + return true + } + + return false +} + +// SetValues gets a reference to the given Values and assigns it to the Values field. +func (o *Traffic) SetValues(v Values) { + o.Values = &v +} + +func (o Traffic) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o Traffic) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Unit) { + toSerialize["unit"] = o.Unit + } + if !IsNil(o.Values) { + toSerialize["values"] = o.Values + } + return toSerialize, nil +} + +type NullableTraffic struct { + value *Traffic + isSet bool +} + +func (v NullableTraffic) Get() *Traffic { + return v.value +} + +func (v *NullableTraffic) Set(val *Traffic) { + v.value = val + v.isSet = true +} + +func (v NullableTraffic) IsSet() bool { + return v.isSet +} + +func (v *NullableTraffic) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableTraffic(val *Traffic) *NullableTraffic { + return &NullableTraffic{value: val, isSet: true} +} + +func (v NullableTraffic) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableTraffic) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/publicCloud/model_update_credential_opts.go b/publicCloud/model_update_credential_opts.go new file mode 100644 index 0000000..ca3dc66 --- /dev/null +++ b/publicCloud/model_update_credential_opts.go @@ -0,0 +1,159 @@ +/* +LeaseWeb API for launching and managing Public Cloud instances + +> The base URL for this API is: **https://api.leaseweb.com/publicCloud/v1/_** This API provides ways to launch and manage Public Cloud instances.
BETA
This API is in BETA. Documentation might be incorrect or incomplete. Functionality might change with the final release.> + +API version: v1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package publicCloud + +import ( + "encoding/json" + "bytes" + "fmt" +) + +// checks if the UpdateCredentialOpts type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &UpdateCredentialOpts{} + +// UpdateCredentialOpts struct for UpdateCredentialOpts +type UpdateCredentialOpts struct { + // The new password + Password string `json:"password"` +} + +type _UpdateCredentialOpts UpdateCredentialOpts + +// NewUpdateCredentialOpts instantiates a new UpdateCredentialOpts object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewUpdateCredentialOpts(password string) *UpdateCredentialOpts { + this := UpdateCredentialOpts{} + this.Password = password + return &this +} + +// NewUpdateCredentialOptsWithDefaults instantiates a new UpdateCredentialOpts object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewUpdateCredentialOptsWithDefaults() *UpdateCredentialOpts { + this := UpdateCredentialOpts{} + return &this +} + +// GetPassword returns the Password field value +func (o *UpdateCredentialOpts) GetPassword() string { + if o == nil { + var ret string + return ret + } + + return o.Password +} + +// GetPasswordOk returns a tuple with the Password field value +// and a boolean to check if the value has been set. +func (o *UpdateCredentialOpts) GetPasswordOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.Password, true +} + +// SetPassword sets field value +func (o *UpdateCredentialOpts) SetPassword(v string) { + o.Password = v +} + +func (o UpdateCredentialOpts) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o UpdateCredentialOpts) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + toSerialize["password"] = o.Password + return toSerialize, nil +} + +func (o *UpdateCredentialOpts) UnmarshalJSON(data []byte) (err error) { + // This validates that all required properties are included in the JSON object + // by unmarshalling the object into a generic map with string keys and checking + // that every required field exists as a key in the generic map. + requiredProperties := []string{ + "password", + } + + allProperties := make(map[string]interface{}) + + err = json.Unmarshal(data, &allProperties) + + if err != nil { + return err; + } + + for _, requiredProperty := range(requiredProperties) { + if _, exists := allProperties[requiredProperty]; !exists { + return fmt.Errorf("no value given for required property %v", requiredProperty) + } + } + + varUpdateCredentialOpts := _UpdateCredentialOpts{} + + decoder := json.NewDecoder(bytes.NewReader(data)) + decoder.DisallowUnknownFields() + err = decoder.Decode(&varUpdateCredentialOpts) + + if err != nil { + return err + } + + *o = UpdateCredentialOpts(varUpdateCredentialOpts) + + return err +} + +type NullableUpdateCredentialOpts struct { + value *UpdateCredentialOpts + isSet bool +} + +func (v NullableUpdateCredentialOpts) Get() *UpdateCredentialOpts { + return v.value +} + +func (v *NullableUpdateCredentialOpts) Set(val *UpdateCredentialOpts) { + v.value = val + v.isSet = true +} + +func (v NullableUpdateCredentialOpts) IsSet() bool { + return v.isSet +} + +func (v *NullableUpdateCredentialOpts) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableUpdateCredentialOpts(val *UpdateCredentialOpts) *NullableUpdateCredentialOpts { + return &NullableUpdateCredentialOpts{value: val, isSet: true} +} + +func (v NullableUpdateCredentialOpts) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableUpdateCredentialOpts) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/publicCloud/model_update_credential_result.go b/publicCloud/model_update_credential_result.go new file mode 100644 index 0000000..375cf4f --- /dev/null +++ b/publicCloud/model_update_credential_result.go @@ -0,0 +1,200 @@ +/* +LeaseWeb API for launching and managing Public Cloud instances + +> The base URL for this API is: **https://api.leaseweb.com/publicCloud/v1/_** This API provides ways to launch and manage Public Cloud instances.
BETA
This API is in BETA. Documentation might be incorrect or incomplete. Functionality might change with the final release.> + +API version: v1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package publicCloud + +import ( + "encoding/json" +) + +// checks if the UpdateCredentialResult type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &UpdateCredentialResult{} + +// UpdateCredentialResult struct for UpdateCredentialResult +type UpdateCredentialResult struct { + Type *CredentialType `json:"type,omitempty"` + // The provided username + Username *string `json:"username,omitempty"` + // The provided password + Password *string `json:"password,omitempty"` +} + +// NewUpdateCredentialResult instantiates a new UpdateCredentialResult object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewUpdateCredentialResult() *UpdateCredentialResult { + this := UpdateCredentialResult{} + return &this +} + +// NewUpdateCredentialResultWithDefaults instantiates a new UpdateCredentialResult object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewUpdateCredentialResultWithDefaults() *UpdateCredentialResult { + this := UpdateCredentialResult{} + return &this +} + +// GetType returns the Type field value if set, zero value otherwise. +func (o *UpdateCredentialResult) GetType() CredentialType { + if o == nil || IsNil(o.Type) { + var ret CredentialType + return ret + } + return *o.Type +} + +// GetTypeOk returns a tuple with the Type field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *UpdateCredentialResult) GetTypeOk() (*CredentialType, bool) { + if o == nil || IsNil(o.Type) { + return nil, false + } + return o.Type, true +} + +// HasType returns a boolean if a field has been set. +func (o *UpdateCredentialResult) HasType() bool { + if o != nil && !IsNil(o.Type) { + return true + } + + return false +} + +// SetType gets a reference to the given CredentialType and assigns it to the Type field. +func (o *UpdateCredentialResult) SetType(v CredentialType) { + o.Type = &v +} + +// GetUsername returns the Username field value if set, zero value otherwise. +func (o *UpdateCredentialResult) GetUsername() string { + if o == nil || IsNil(o.Username) { + var ret string + return ret + } + return *o.Username +} + +// GetUsernameOk returns a tuple with the Username field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *UpdateCredentialResult) GetUsernameOk() (*string, bool) { + if o == nil || IsNil(o.Username) { + return nil, false + } + return o.Username, true +} + +// HasUsername returns a boolean if a field has been set. +func (o *UpdateCredentialResult) HasUsername() bool { + if o != nil && !IsNil(o.Username) { + return true + } + + return false +} + +// SetUsername gets a reference to the given string and assigns it to the Username field. +func (o *UpdateCredentialResult) SetUsername(v string) { + o.Username = &v +} + +// GetPassword returns the Password field value if set, zero value otherwise. +func (o *UpdateCredentialResult) GetPassword() string { + if o == nil || IsNil(o.Password) { + var ret string + return ret + } + return *o.Password +} + +// GetPasswordOk returns a tuple with the Password field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *UpdateCredentialResult) GetPasswordOk() (*string, bool) { + if o == nil || IsNil(o.Password) { + return nil, false + } + return o.Password, true +} + +// HasPassword returns a boolean if a field has been set. +func (o *UpdateCredentialResult) HasPassword() bool { + if o != nil && !IsNil(o.Password) { + return true + } + + return false +} + +// SetPassword gets a reference to the given string and assigns it to the Password field. +func (o *UpdateCredentialResult) SetPassword(v string) { + o.Password = &v +} + +func (o UpdateCredentialResult) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o UpdateCredentialResult) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Type) { + toSerialize["type"] = o.Type + } + if !IsNil(o.Username) { + toSerialize["username"] = o.Username + } + if !IsNil(o.Password) { + toSerialize["password"] = o.Password + } + return toSerialize, nil +} + +type NullableUpdateCredentialResult struct { + value *UpdateCredentialResult + isSet bool +} + +func (v NullableUpdateCredentialResult) Get() *UpdateCredentialResult { + return v.value +} + +func (v *NullableUpdateCredentialResult) Set(val *UpdateCredentialResult) { + v.value = val + v.isSet = true +} + +func (v NullableUpdateCredentialResult) IsSet() bool { + return v.isSet +} + +func (v *NullableUpdateCredentialResult) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableUpdateCredentialResult(val *UpdateCredentialResult) *NullableUpdateCredentialResult { + return &NullableUpdateCredentialResult{value: val, isSet: true} +} + +func (v NullableUpdateCredentialResult) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableUpdateCredentialResult) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/publicCloud/model_update_instance_opts.go b/publicCloud/model_update_instance_opts.go new file mode 100644 index 0000000..8b332e8 --- /dev/null +++ b/publicCloud/model_update_instance_opts.go @@ -0,0 +1,311 @@ +/* +LeaseWeb API for launching and managing Public Cloud instances + +> The base URL for this API is: **https://api.leaseweb.com/publicCloud/v1/_** This API provides ways to launch and manage Public Cloud instances.
BETA
This API is in BETA. Documentation might be incorrect or incomplete. Functionality might change with the final release.> + +API version: v1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package publicCloud + +import ( + "encoding/json" +) + +// checks if the UpdateInstanceOpts type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &UpdateInstanceOpts{} + +// UpdateInstanceOpts struct for UpdateInstanceOpts +type UpdateInstanceOpts struct { + // Instance type + Type *string `json:"type,omitempty"` + // An identifying name you can refer to the instance + Reference *string `json:"reference,omitempty"` + ContractType *string `json:"contractType,omitempty"` + // Contract commitment. Can only be used when updating the contract type from HOURLY and MONTHLY. + ContractTerm *int32 `json:"contractTerm,omitempty"` + // How often you wish to be charged. Can only be used when updating the contract type from HOURLY to MONTHLY. '1' means every month, '3' every three months and so on. + BillingFrequency *int32 `json:"billingFrequency,omitempty"` + // The root disk's size in GB. Must be at least 5 GB for Linux and FreeBSD instances and 50 GB for Windows instances + RootDiskSize *int32 `json:"rootDiskSize,omitempty"` +} + +// NewUpdateInstanceOpts instantiates a new UpdateInstanceOpts object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewUpdateInstanceOpts() *UpdateInstanceOpts { + this := UpdateInstanceOpts{} + return &this +} + +// NewUpdateInstanceOptsWithDefaults instantiates a new UpdateInstanceOpts object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewUpdateInstanceOptsWithDefaults() *UpdateInstanceOpts { + this := UpdateInstanceOpts{} + return &this +} + +// GetType returns the Type field value if set, zero value otherwise. +func (o *UpdateInstanceOpts) GetType() string { + if o == nil || IsNil(o.Type) { + var ret string + return ret + } + return *o.Type +} + +// GetTypeOk returns a tuple with the Type field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *UpdateInstanceOpts) GetTypeOk() (*string, bool) { + if o == nil || IsNil(o.Type) { + return nil, false + } + return o.Type, true +} + +// HasType returns a boolean if a field has been set. +func (o *UpdateInstanceOpts) HasType() bool { + if o != nil && !IsNil(o.Type) { + return true + } + + return false +} + +// SetType gets a reference to the given string and assigns it to the Type field. +func (o *UpdateInstanceOpts) SetType(v string) { + o.Type = &v +} + +// GetReference returns the Reference field value if set, zero value otherwise. +func (o *UpdateInstanceOpts) GetReference() string { + if o == nil || IsNil(o.Reference) { + var ret string + return ret + } + return *o.Reference +} + +// GetReferenceOk returns a tuple with the Reference field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *UpdateInstanceOpts) GetReferenceOk() (*string, bool) { + if o == nil || IsNil(o.Reference) { + return nil, false + } + return o.Reference, true +} + +// HasReference returns a boolean if a field has been set. +func (o *UpdateInstanceOpts) HasReference() bool { + if o != nil && !IsNil(o.Reference) { + return true + } + + return false +} + +// SetReference gets a reference to the given string and assigns it to the Reference field. +func (o *UpdateInstanceOpts) SetReference(v string) { + o.Reference = &v +} + +// GetContractType returns the ContractType field value if set, zero value otherwise. +func (o *UpdateInstanceOpts) GetContractType() string { + if o == nil || IsNil(o.ContractType) { + var ret string + return ret + } + return *o.ContractType +} + +// GetContractTypeOk returns a tuple with the ContractType field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *UpdateInstanceOpts) GetContractTypeOk() (*string, bool) { + if o == nil || IsNil(o.ContractType) { + return nil, false + } + return o.ContractType, true +} + +// HasContractType returns a boolean if a field has been set. +func (o *UpdateInstanceOpts) HasContractType() bool { + if o != nil && !IsNil(o.ContractType) { + return true + } + + return false +} + +// SetContractType gets a reference to the given string and assigns it to the ContractType field. +func (o *UpdateInstanceOpts) SetContractType(v string) { + o.ContractType = &v +} + +// GetContractTerm returns the ContractTerm field value if set, zero value otherwise. +func (o *UpdateInstanceOpts) GetContractTerm() int32 { + if o == nil || IsNil(o.ContractTerm) { + var ret int32 + return ret + } + return *o.ContractTerm +} + +// GetContractTermOk returns a tuple with the ContractTerm field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *UpdateInstanceOpts) GetContractTermOk() (*int32, bool) { + if o == nil || IsNil(o.ContractTerm) { + return nil, false + } + return o.ContractTerm, true +} + +// HasContractTerm returns a boolean if a field has been set. +func (o *UpdateInstanceOpts) HasContractTerm() bool { + if o != nil && !IsNil(o.ContractTerm) { + return true + } + + return false +} + +// SetContractTerm gets a reference to the given int32 and assigns it to the ContractTerm field. +func (o *UpdateInstanceOpts) SetContractTerm(v int32) { + o.ContractTerm = &v +} + +// GetBillingFrequency returns the BillingFrequency field value if set, zero value otherwise. +func (o *UpdateInstanceOpts) GetBillingFrequency() int32 { + if o == nil || IsNil(o.BillingFrequency) { + var ret int32 + return ret + } + return *o.BillingFrequency +} + +// GetBillingFrequencyOk returns a tuple with the BillingFrequency field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *UpdateInstanceOpts) GetBillingFrequencyOk() (*int32, bool) { + if o == nil || IsNil(o.BillingFrequency) { + return nil, false + } + return o.BillingFrequency, true +} + +// HasBillingFrequency returns a boolean if a field has been set. +func (o *UpdateInstanceOpts) HasBillingFrequency() bool { + if o != nil && !IsNil(o.BillingFrequency) { + return true + } + + return false +} + +// SetBillingFrequency gets a reference to the given int32 and assigns it to the BillingFrequency field. +func (o *UpdateInstanceOpts) SetBillingFrequency(v int32) { + o.BillingFrequency = &v +} + +// GetRootDiskSize returns the RootDiskSize field value if set, zero value otherwise. +func (o *UpdateInstanceOpts) GetRootDiskSize() int32 { + if o == nil || IsNil(o.RootDiskSize) { + var ret int32 + return ret + } + return *o.RootDiskSize +} + +// GetRootDiskSizeOk returns a tuple with the RootDiskSize field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *UpdateInstanceOpts) GetRootDiskSizeOk() (*int32, bool) { + if o == nil || IsNil(o.RootDiskSize) { + return nil, false + } + return o.RootDiskSize, true +} + +// HasRootDiskSize returns a boolean if a field has been set. +func (o *UpdateInstanceOpts) HasRootDiskSize() bool { + if o != nil && !IsNil(o.RootDiskSize) { + return true + } + + return false +} + +// SetRootDiskSize gets a reference to the given int32 and assigns it to the RootDiskSize field. +func (o *UpdateInstanceOpts) SetRootDiskSize(v int32) { + o.RootDiskSize = &v +} + +func (o UpdateInstanceOpts) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o UpdateInstanceOpts) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Type) { + toSerialize["type"] = o.Type + } + if !IsNil(o.Reference) { + toSerialize["reference"] = o.Reference + } + if !IsNil(o.ContractType) { + toSerialize["contractType"] = o.ContractType + } + if !IsNil(o.ContractTerm) { + toSerialize["contractTerm"] = o.ContractTerm + } + if !IsNil(o.BillingFrequency) { + toSerialize["billingFrequency"] = o.BillingFrequency + } + if !IsNil(o.RootDiskSize) { + toSerialize["rootDiskSize"] = o.RootDiskSize + } + return toSerialize, nil +} + +type NullableUpdateInstanceOpts struct { + value *UpdateInstanceOpts + isSet bool +} + +func (v NullableUpdateInstanceOpts) Get() *UpdateInstanceOpts { + return v.value +} + +func (v *NullableUpdateInstanceOpts) Set(val *UpdateInstanceOpts) { + v.value = val + v.isSet = true +} + +func (v NullableUpdateInstanceOpts) IsSet() bool { + return v.isSet +} + +func (v *NullableUpdateInstanceOpts) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableUpdateInstanceOpts(val *UpdateInstanceOpts) *NullableUpdateInstanceOpts { + return &NullableUpdateInstanceOpts{value: val, isSet: true} +} + +func (v NullableUpdateInstanceOpts) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableUpdateInstanceOpts) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/publicCloud/model_update_instance_result.go b/publicCloud/model_update_instance_result.go new file mode 100644 index 0000000..2cf012c --- /dev/null +++ b/publicCloud/model_update_instance_result.go @@ -0,0 +1,919 @@ +/* +LeaseWeb API for launching and managing Public Cloud instances + +> The base URL for this API is: **https://api.leaseweb.com/publicCloud/v1/_** This API provides ways to launch and manage Public Cloud instances.
BETA
This API is in BETA. Documentation might be incorrect or incomplete. Functionality might change with the final release.> + +API version: v1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package publicCloud + +import ( + "encoding/json" + "time" +) + +// checks if the UpdateInstanceResult type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &UpdateInstanceResult{} + +// UpdateInstanceResult struct for UpdateInstanceResult +type UpdateInstanceResult struct { + // The customer's equipment ID + EquipmentId *string `json:"equipmentId,omitempty"` + // The customer's ID + CustomerId *string `json:"customerId,omitempty"` + SalesOrgId *string `json:"salesOrgId,omitempty"` + // The instance's identifier + Id *string `json:"id,omitempty"` + // Instance type + Type *string `json:"type,omitempty"` + // The region where the instance has been launched into + Region *string `json:"region,omitempty"` + // The identifying name set to the instance + Reference *string `json:"reference,omitempty"` + OperatingSystem *OperatingSystem `json:"operatingSystem,omitempty"` + Resources *InstanceResources `json:"resources,omitempty"` + State *string `json:"state,omitempty"` + PublicIpV4 *bool `json:"publicIpV4,omitempty"` + PrivateNetwork *bool `json:"privateNetwork,omitempty"` + StartedAt NullableTime `json:"startedAt,omitempty"` + RootDiskSize *int32 `json:"rootDiskSize,omitempty"` + Ips []Ip `json:"ips,omitempty"` + BillingFrequency *int32 `json:"billingFrequency,omitempty"` + ContractTerm *int32 `json:"contractTerm,omitempty"` + ContractType *ContractType `json:"contractType,omitempty"` + ContractEndsAt NullableTime `json:"contractEndsAt,omitempty"` + ContractRenewalsAt *time.Time `json:"contractRenewalsAt,omitempty"` + ContractCreatedAt *time.Time `json:"contractCreatedAt,omitempty"` + Iso NullableString `json:"iso,omitempty"` +} + +// NewUpdateInstanceResult instantiates a new UpdateInstanceResult object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewUpdateInstanceResult() *UpdateInstanceResult { + this := UpdateInstanceResult{} + return &this +} + +// NewUpdateInstanceResultWithDefaults instantiates a new UpdateInstanceResult object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewUpdateInstanceResultWithDefaults() *UpdateInstanceResult { + this := UpdateInstanceResult{} + return &this +} + +// GetEquipmentId returns the EquipmentId field value if set, zero value otherwise. +func (o *UpdateInstanceResult) GetEquipmentId() string { + if o == nil || IsNil(o.EquipmentId) { + var ret string + return ret + } + return *o.EquipmentId +} + +// GetEquipmentIdOk returns a tuple with the EquipmentId field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *UpdateInstanceResult) GetEquipmentIdOk() (*string, bool) { + if o == nil || IsNil(o.EquipmentId) { + return nil, false + } + return o.EquipmentId, true +} + +// HasEquipmentId returns a boolean if a field has been set. +func (o *UpdateInstanceResult) HasEquipmentId() bool { + if o != nil && !IsNil(o.EquipmentId) { + return true + } + + return false +} + +// SetEquipmentId gets a reference to the given string and assigns it to the EquipmentId field. +func (o *UpdateInstanceResult) SetEquipmentId(v string) { + o.EquipmentId = &v +} + +// GetCustomerId returns the CustomerId field value if set, zero value otherwise. +func (o *UpdateInstanceResult) GetCustomerId() string { + if o == nil || IsNil(o.CustomerId) { + var ret string + return ret + } + return *o.CustomerId +} + +// GetCustomerIdOk returns a tuple with the CustomerId field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *UpdateInstanceResult) GetCustomerIdOk() (*string, bool) { + if o == nil || IsNil(o.CustomerId) { + return nil, false + } + return o.CustomerId, true +} + +// HasCustomerId returns a boolean if a field has been set. +func (o *UpdateInstanceResult) HasCustomerId() bool { + if o != nil && !IsNil(o.CustomerId) { + return true + } + + return false +} + +// SetCustomerId gets a reference to the given string and assigns it to the CustomerId field. +func (o *UpdateInstanceResult) SetCustomerId(v string) { + o.CustomerId = &v +} + +// GetSalesOrgId returns the SalesOrgId field value if set, zero value otherwise. +func (o *UpdateInstanceResult) GetSalesOrgId() string { + if o == nil || IsNil(o.SalesOrgId) { + var ret string + return ret + } + return *o.SalesOrgId +} + +// GetSalesOrgIdOk returns a tuple with the SalesOrgId field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *UpdateInstanceResult) GetSalesOrgIdOk() (*string, bool) { + if o == nil || IsNil(o.SalesOrgId) { + return nil, false + } + return o.SalesOrgId, true +} + +// HasSalesOrgId returns a boolean if a field has been set. +func (o *UpdateInstanceResult) HasSalesOrgId() bool { + if o != nil && !IsNil(o.SalesOrgId) { + return true + } + + return false +} + +// SetSalesOrgId gets a reference to the given string and assigns it to the SalesOrgId field. +func (o *UpdateInstanceResult) SetSalesOrgId(v string) { + o.SalesOrgId = &v +} + +// GetId returns the Id field value if set, zero value otherwise. +func (o *UpdateInstanceResult) GetId() string { + if o == nil || IsNil(o.Id) { + var ret string + return ret + } + return *o.Id +} + +// GetIdOk returns a tuple with the Id field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *UpdateInstanceResult) GetIdOk() (*string, bool) { + if o == nil || IsNil(o.Id) { + return nil, false + } + return o.Id, true +} + +// HasId returns a boolean if a field has been set. +func (o *UpdateInstanceResult) HasId() bool { + if o != nil && !IsNil(o.Id) { + return true + } + + return false +} + +// SetId gets a reference to the given string and assigns it to the Id field. +func (o *UpdateInstanceResult) SetId(v string) { + o.Id = &v +} + +// GetType returns the Type field value if set, zero value otherwise. +func (o *UpdateInstanceResult) GetType() string { + if o == nil || IsNil(o.Type) { + var ret string + return ret + } + return *o.Type +} + +// GetTypeOk returns a tuple with the Type field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *UpdateInstanceResult) GetTypeOk() (*string, bool) { + if o == nil || IsNil(o.Type) { + return nil, false + } + return o.Type, true +} + +// HasType returns a boolean if a field has been set. +func (o *UpdateInstanceResult) HasType() bool { + if o != nil && !IsNil(o.Type) { + return true + } + + return false +} + +// SetType gets a reference to the given string and assigns it to the Type field. +func (o *UpdateInstanceResult) SetType(v string) { + o.Type = &v +} + +// GetRegion returns the Region field value if set, zero value otherwise. +func (o *UpdateInstanceResult) GetRegion() string { + if o == nil || IsNil(o.Region) { + var ret string + return ret + } + return *o.Region +} + +// GetRegionOk returns a tuple with the Region field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *UpdateInstanceResult) GetRegionOk() (*string, bool) { + if o == nil || IsNil(o.Region) { + return nil, false + } + return o.Region, true +} + +// HasRegion returns a boolean if a field has been set. +func (o *UpdateInstanceResult) HasRegion() bool { + if o != nil && !IsNil(o.Region) { + return true + } + + return false +} + +// SetRegion gets a reference to the given string and assigns it to the Region field. +func (o *UpdateInstanceResult) SetRegion(v string) { + o.Region = &v +} + +// GetReference returns the Reference field value if set, zero value otherwise. +func (o *UpdateInstanceResult) GetReference() string { + if o == nil || IsNil(o.Reference) { + var ret string + return ret + } + return *o.Reference +} + +// GetReferenceOk returns a tuple with the Reference field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *UpdateInstanceResult) GetReferenceOk() (*string, bool) { + if o == nil || IsNil(o.Reference) { + return nil, false + } + return o.Reference, true +} + +// HasReference returns a boolean if a field has been set. +func (o *UpdateInstanceResult) HasReference() bool { + if o != nil && !IsNil(o.Reference) { + return true + } + + return false +} + +// SetReference gets a reference to the given string and assigns it to the Reference field. +func (o *UpdateInstanceResult) SetReference(v string) { + o.Reference = &v +} + +// GetOperatingSystem returns the OperatingSystem field value if set, zero value otherwise. +func (o *UpdateInstanceResult) GetOperatingSystem() OperatingSystem { + if o == nil || IsNil(o.OperatingSystem) { + var ret OperatingSystem + return ret + } + return *o.OperatingSystem +} + +// GetOperatingSystemOk returns a tuple with the OperatingSystem field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *UpdateInstanceResult) GetOperatingSystemOk() (*OperatingSystem, bool) { + if o == nil || IsNil(o.OperatingSystem) { + return nil, false + } + return o.OperatingSystem, true +} + +// HasOperatingSystem returns a boolean if a field has been set. +func (o *UpdateInstanceResult) HasOperatingSystem() bool { + if o != nil && !IsNil(o.OperatingSystem) { + return true + } + + return false +} + +// SetOperatingSystem gets a reference to the given OperatingSystem and assigns it to the OperatingSystem field. +func (o *UpdateInstanceResult) SetOperatingSystem(v OperatingSystem) { + o.OperatingSystem = &v +} + +// GetResources returns the Resources field value if set, zero value otherwise. +func (o *UpdateInstanceResult) GetResources() InstanceResources { + if o == nil || IsNil(o.Resources) { + var ret InstanceResources + return ret + } + return *o.Resources +} + +// GetResourcesOk returns a tuple with the Resources field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *UpdateInstanceResult) GetResourcesOk() (*InstanceResources, bool) { + if o == nil || IsNil(o.Resources) { + return nil, false + } + return o.Resources, true +} + +// HasResources returns a boolean if a field has been set. +func (o *UpdateInstanceResult) HasResources() bool { + if o != nil && !IsNil(o.Resources) { + return true + } + + return false +} + +// SetResources gets a reference to the given InstanceResources and assigns it to the Resources field. +func (o *UpdateInstanceResult) SetResources(v InstanceResources) { + o.Resources = &v +} + +// GetState returns the State field value if set, zero value otherwise. +func (o *UpdateInstanceResult) GetState() string { + if o == nil || IsNil(o.State) { + var ret string + return ret + } + return *o.State +} + +// GetStateOk returns a tuple with the State field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *UpdateInstanceResult) GetStateOk() (*string, bool) { + if o == nil || IsNil(o.State) { + return nil, false + } + return o.State, true +} + +// HasState returns a boolean if a field has been set. +func (o *UpdateInstanceResult) HasState() bool { + if o != nil && !IsNil(o.State) { + return true + } + + return false +} + +// SetState gets a reference to the given string and assigns it to the State field. +func (o *UpdateInstanceResult) SetState(v string) { + o.State = &v +} + +// GetPublicIpV4 returns the PublicIpV4 field value if set, zero value otherwise. +func (o *UpdateInstanceResult) GetPublicIpV4() bool { + if o == nil || IsNil(o.PublicIpV4) { + var ret bool + return ret + } + return *o.PublicIpV4 +} + +// GetPublicIpV4Ok returns a tuple with the PublicIpV4 field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *UpdateInstanceResult) GetPublicIpV4Ok() (*bool, bool) { + if o == nil || IsNil(o.PublicIpV4) { + return nil, false + } + return o.PublicIpV4, true +} + +// HasPublicIpV4 returns a boolean if a field has been set. +func (o *UpdateInstanceResult) HasPublicIpV4() bool { + if o != nil && !IsNil(o.PublicIpV4) { + return true + } + + return false +} + +// SetPublicIpV4 gets a reference to the given bool and assigns it to the PublicIpV4 field. +func (o *UpdateInstanceResult) SetPublicIpV4(v bool) { + o.PublicIpV4 = &v +} + +// GetPrivateNetwork returns the PrivateNetwork field value if set, zero value otherwise. +func (o *UpdateInstanceResult) GetPrivateNetwork() bool { + if o == nil || IsNil(o.PrivateNetwork) { + var ret bool + return ret + } + return *o.PrivateNetwork +} + +// GetPrivateNetworkOk returns a tuple with the PrivateNetwork field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *UpdateInstanceResult) GetPrivateNetworkOk() (*bool, bool) { + if o == nil || IsNil(o.PrivateNetwork) { + return nil, false + } + return o.PrivateNetwork, true +} + +// HasPrivateNetwork returns a boolean if a field has been set. +func (o *UpdateInstanceResult) HasPrivateNetwork() bool { + if o != nil && !IsNil(o.PrivateNetwork) { + return true + } + + return false +} + +// SetPrivateNetwork gets a reference to the given bool and assigns it to the PrivateNetwork field. +func (o *UpdateInstanceResult) SetPrivateNetwork(v bool) { + o.PrivateNetwork = &v +} + +// GetStartedAt returns the StartedAt field value if set, zero value otherwise (both if not set or set to explicit null). +func (o *UpdateInstanceResult) GetStartedAt() time.Time { + if o == nil || IsNil(o.StartedAt.Get()) { + var ret time.Time + return ret + } + return *o.StartedAt.Get() +} + +// GetStartedAtOk returns a tuple with the StartedAt field value if set, nil otherwise +// and a boolean to check if the value has been set. +// NOTE: If the value is an explicit nil, `nil, true` will be returned +func (o *UpdateInstanceResult) GetStartedAtOk() (*time.Time, bool) { + if o == nil { + return nil, false + } + return o.StartedAt.Get(), o.StartedAt.IsSet() +} + +// HasStartedAt returns a boolean if a field has been set. +func (o *UpdateInstanceResult) HasStartedAt() bool { + if o != nil && o.StartedAt.IsSet() { + return true + } + + return false +} + +// SetStartedAt gets a reference to the given NullableTime and assigns it to the StartedAt field. +func (o *UpdateInstanceResult) SetStartedAt(v time.Time) { + o.StartedAt.Set(&v) +} +// SetStartedAtNil sets the value for StartedAt to be an explicit nil +func (o *UpdateInstanceResult) SetStartedAtNil() { + o.StartedAt.Set(nil) +} + +// UnsetStartedAt ensures that no value is present for StartedAt, not even an explicit nil +func (o *UpdateInstanceResult) UnsetStartedAt() { + o.StartedAt.Unset() +} + +// GetRootDiskSize returns the RootDiskSize field value if set, zero value otherwise. +func (o *UpdateInstanceResult) GetRootDiskSize() int32 { + if o == nil || IsNil(o.RootDiskSize) { + var ret int32 + return ret + } + return *o.RootDiskSize +} + +// GetRootDiskSizeOk returns a tuple with the RootDiskSize field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *UpdateInstanceResult) GetRootDiskSizeOk() (*int32, bool) { + if o == nil || IsNil(o.RootDiskSize) { + return nil, false + } + return o.RootDiskSize, true +} + +// HasRootDiskSize returns a boolean if a field has been set. +func (o *UpdateInstanceResult) HasRootDiskSize() bool { + if o != nil && !IsNil(o.RootDiskSize) { + return true + } + + return false +} + +// SetRootDiskSize gets a reference to the given int32 and assigns it to the RootDiskSize field. +func (o *UpdateInstanceResult) SetRootDiskSize(v int32) { + o.RootDiskSize = &v +} + +// GetIps returns the Ips field value if set, zero value otherwise. +func (o *UpdateInstanceResult) GetIps() []Ip { + if o == nil || IsNil(o.Ips) { + var ret []Ip + return ret + } + return o.Ips +} + +// GetIpsOk returns a tuple with the Ips field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *UpdateInstanceResult) GetIpsOk() ([]Ip, bool) { + if o == nil || IsNil(o.Ips) { + return nil, false + } + return o.Ips, true +} + +// HasIps returns a boolean if a field has been set. +func (o *UpdateInstanceResult) HasIps() bool { + if o != nil && !IsNil(o.Ips) { + return true + } + + return false +} + +// SetIps gets a reference to the given []Ip and assigns it to the Ips field. +func (o *UpdateInstanceResult) SetIps(v []Ip) { + o.Ips = v +} + +// GetBillingFrequency returns the BillingFrequency field value if set, zero value otherwise. +func (o *UpdateInstanceResult) GetBillingFrequency() int32 { + if o == nil || IsNil(o.BillingFrequency) { + var ret int32 + return ret + } + return *o.BillingFrequency +} + +// GetBillingFrequencyOk returns a tuple with the BillingFrequency field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *UpdateInstanceResult) GetBillingFrequencyOk() (*int32, bool) { + if o == nil || IsNil(o.BillingFrequency) { + return nil, false + } + return o.BillingFrequency, true +} + +// HasBillingFrequency returns a boolean if a field has been set. +func (o *UpdateInstanceResult) HasBillingFrequency() bool { + if o != nil && !IsNil(o.BillingFrequency) { + return true + } + + return false +} + +// SetBillingFrequency gets a reference to the given int32 and assigns it to the BillingFrequency field. +func (o *UpdateInstanceResult) SetBillingFrequency(v int32) { + o.BillingFrequency = &v +} + +// GetContractTerm returns the ContractTerm field value if set, zero value otherwise. +func (o *UpdateInstanceResult) GetContractTerm() int32 { + if o == nil || IsNil(o.ContractTerm) { + var ret int32 + return ret + } + return *o.ContractTerm +} + +// GetContractTermOk returns a tuple with the ContractTerm field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *UpdateInstanceResult) GetContractTermOk() (*int32, bool) { + if o == nil || IsNil(o.ContractTerm) { + return nil, false + } + return o.ContractTerm, true +} + +// HasContractTerm returns a boolean if a field has been set. +func (o *UpdateInstanceResult) HasContractTerm() bool { + if o != nil && !IsNil(o.ContractTerm) { + return true + } + + return false +} + +// SetContractTerm gets a reference to the given int32 and assigns it to the ContractTerm field. +func (o *UpdateInstanceResult) SetContractTerm(v int32) { + o.ContractTerm = &v +} + +// GetContractType returns the ContractType field value if set, zero value otherwise. +func (o *UpdateInstanceResult) GetContractType() ContractType { + if o == nil || IsNil(o.ContractType) { + var ret ContractType + return ret + } + return *o.ContractType +} + +// GetContractTypeOk returns a tuple with the ContractType field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *UpdateInstanceResult) GetContractTypeOk() (*ContractType, bool) { + if o == nil || IsNil(o.ContractType) { + return nil, false + } + return o.ContractType, true +} + +// HasContractType returns a boolean if a field has been set. +func (o *UpdateInstanceResult) HasContractType() bool { + if o != nil && !IsNil(o.ContractType) { + return true + } + + return false +} + +// SetContractType gets a reference to the given ContractType and assigns it to the ContractType field. +func (o *UpdateInstanceResult) SetContractType(v ContractType) { + o.ContractType = &v +} + +// GetContractEndsAt returns the ContractEndsAt field value if set, zero value otherwise (both if not set or set to explicit null). +func (o *UpdateInstanceResult) GetContractEndsAt() time.Time { + if o == nil || IsNil(o.ContractEndsAt.Get()) { + var ret time.Time + return ret + } + return *o.ContractEndsAt.Get() +} + +// GetContractEndsAtOk returns a tuple with the ContractEndsAt field value if set, nil otherwise +// and a boolean to check if the value has been set. +// NOTE: If the value is an explicit nil, `nil, true` will be returned +func (o *UpdateInstanceResult) GetContractEndsAtOk() (*time.Time, bool) { + if o == nil { + return nil, false + } + return o.ContractEndsAt.Get(), o.ContractEndsAt.IsSet() +} + +// HasContractEndsAt returns a boolean if a field has been set. +func (o *UpdateInstanceResult) HasContractEndsAt() bool { + if o != nil && o.ContractEndsAt.IsSet() { + return true + } + + return false +} + +// SetContractEndsAt gets a reference to the given NullableTime and assigns it to the ContractEndsAt field. +func (o *UpdateInstanceResult) SetContractEndsAt(v time.Time) { + o.ContractEndsAt.Set(&v) +} +// SetContractEndsAtNil sets the value for ContractEndsAt to be an explicit nil +func (o *UpdateInstanceResult) SetContractEndsAtNil() { + o.ContractEndsAt.Set(nil) +} + +// UnsetContractEndsAt ensures that no value is present for ContractEndsAt, not even an explicit nil +func (o *UpdateInstanceResult) UnsetContractEndsAt() { + o.ContractEndsAt.Unset() +} + +// GetContractRenewalsAt returns the ContractRenewalsAt field value if set, zero value otherwise. +func (o *UpdateInstanceResult) GetContractRenewalsAt() time.Time { + if o == nil || IsNil(o.ContractRenewalsAt) { + var ret time.Time + return ret + } + return *o.ContractRenewalsAt +} + +// GetContractRenewalsAtOk returns a tuple with the ContractRenewalsAt field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *UpdateInstanceResult) GetContractRenewalsAtOk() (*time.Time, bool) { + if o == nil || IsNil(o.ContractRenewalsAt) { + return nil, false + } + return o.ContractRenewalsAt, true +} + +// HasContractRenewalsAt returns a boolean if a field has been set. +func (o *UpdateInstanceResult) HasContractRenewalsAt() bool { + if o != nil && !IsNil(o.ContractRenewalsAt) { + return true + } + + return false +} + +// SetContractRenewalsAt gets a reference to the given time.Time and assigns it to the ContractRenewalsAt field. +func (o *UpdateInstanceResult) SetContractRenewalsAt(v time.Time) { + o.ContractRenewalsAt = &v +} + +// GetContractCreatedAt returns the ContractCreatedAt field value if set, zero value otherwise. +func (o *UpdateInstanceResult) GetContractCreatedAt() time.Time { + if o == nil || IsNil(o.ContractCreatedAt) { + var ret time.Time + return ret + } + return *o.ContractCreatedAt +} + +// GetContractCreatedAtOk returns a tuple with the ContractCreatedAt field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *UpdateInstanceResult) GetContractCreatedAtOk() (*time.Time, bool) { + if o == nil || IsNil(o.ContractCreatedAt) { + return nil, false + } + return o.ContractCreatedAt, true +} + +// HasContractCreatedAt returns a boolean if a field has been set. +func (o *UpdateInstanceResult) HasContractCreatedAt() bool { + if o != nil && !IsNil(o.ContractCreatedAt) { + return true + } + + return false +} + +// SetContractCreatedAt gets a reference to the given time.Time and assigns it to the ContractCreatedAt field. +func (o *UpdateInstanceResult) SetContractCreatedAt(v time.Time) { + o.ContractCreatedAt = &v +} + +// GetIso returns the Iso field value if set, zero value otherwise (both if not set or set to explicit null). +func (o *UpdateInstanceResult) GetIso() string { + if o == nil || IsNil(o.Iso.Get()) { + var ret string + return ret + } + return *o.Iso.Get() +} + +// GetIsoOk returns a tuple with the Iso field value if set, nil otherwise +// and a boolean to check if the value has been set. +// NOTE: If the value is an explicit nil, `nil, true` will be returned +func (o *UpdateInstanceResult) GetIsoOk() (*string, bool) { + if o == nil { + return nil, false + } + return o.Iso.Get(), o.Iso.IsSet() +} + +// HasIso returns a boolean if a field has been set. +func (o *UpdateInstanceResult) HasIso() bool { + if o != nil && o.Iso.IsSet() { + return true + } + + return false +} + +// SetIso gets a reference to the given NullableString and assigns it to the Iso field. +func (o *UpdateInstanceResult) SetIso(v string) { + o.Iso.Set(&v) +} +// SetIsoNil sets the value for Iso to be an explicit nil +func (o *UpdateInstanceResult) SetIsoNil() { + o.Iso.Set(nil) +} + +// UnsetIso ensures that no value is present for Iso, not even an explicit nil +func (o *UpdateInstanceResult) UnsetIso() { + o.Iso.Unset() +} + +func (o UpdateInstanceResult) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o UpdateInstanceResult) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.EquipmentId) { + toSerialize["equipmentId"] = o.EquipmentId + } + if !IsNil(o.CustomerId) { + toSerialize["customerId"] = o.CustomerId + } + if !IsNil(o.SalesOrgId) { + toSerialize["salesOrgId"] = o.SalesOrgId + } + if !IsNil(o.Id) { + toSerialize["id"] = o.Id + } + if !IsNil(o.Type) { + toSerialize["type"] = o.Type + } + if !IsNil(o.Region) { + toSerialize["region"] = o.Region + } + if !IsNil(o.Reference) { + toSerialize["reference"] = o.Reference + } + if !IsNil(o.OperatingSystem) { + toSerialize["operatingSystem"] = o.OperatingSystem + } + if !IsNil(o.Resources) { + toSerialize["resources"] = o.Resources + } + if !IsNil(o.State) { + toSerialize["state"] = o.State + } + if !IsNil(o.PublicIpV4) { + toSerialize["publicIpV4"] = o.PublicIpV4 + } + if !IsNil(o.PrivateNetwork) { + toSerialize["privateNetwork"] = o.PrivateNetwork + } + if o.StartedAt.IsSet() { + toSerialize["startedAt"] = o.StartedAt.Get() + } + if !IsNil(o.RootDiskSize) { + toSerialize["rootDiskSize"] = o.RootDiskSize + } + if !IsNil(o.Ips) { + toSerialize["ips"] = o.Ips + } + if !IsNil(o.BillingFrequency) { + toSerialize["billingFrequency"] = o.BillingFrequency + } + if !IsNil(o.ContractTerm) { + toSerialize["contractTerm"] = o.ContractTerm + } + if !IsNil(o.ContractType) { + toSerialize["contractType"] = o.ContractType + } + if o.ContractEndsAt.IsSet() { + toSerialize["contractEndsAt"] = o.ContractEndsAt.Get() + } + if !IsNil(o.ContractRenewalsAt) { + toSerialize["contractRenewalsAt"] = o.ContractRenewalsAt + } + if !IsNil(o.ContractCreatedAt) { + toSerialize["contractCreatedAt"] = o.ContractCreatedAt + } + if o.Iso.IsSet() { + toSerialize["iso"] = o.Iso.Get() + } + return toSerialize, nil +} + +type NullableUpdateInstanceResult struct { + value *UpdateInstanceResult + isSet bool +} + +func (v NullableUpdateInstanceResult) Get() *UpdateInstanceResult { + return v.value +} + +func (v *NullableUpdateInstanceResult) Set(val *UpdateInstanceResult) { + v.value = val + v.isSet = true +} + +func (v NullableUpdateInstanceResult) IsSet() bool { + return v.isSet +} + +func (v *NullableUpdateInstanceResult) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableUpdateInstanceResult(val *UpdateInstanceResult) *NullableUpdateInstanceResult { + return &NullableUpdateInstanceResult{value: val, isSet: true} +} + +func (v NullableUpdateInstanceResult) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableUpdateInstanceResult) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/publicCloud/model_update_instance_type.go b/publicCloud/model_update_instance_type.go new file mode 100644 index 0000000..ac177da --- /dev/null +++ b/publicCloud/model_update_instance_type.go @@ -0,0 +1,237 @@ +/* +LeaseWeb API for launching and managing Public Cloud instances + +> The base URL for this API is: **https://api.leaseweb.com/publicCloud/v1/_** This API provides ways to launch and manage Public Cloud instances.
BETA
This API is in BETA. Documentation might be incorrect or incomplete. Functionality might change with the final release.> + +API version: v1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package publicCloud + +import ( + "encoding/json" +) + +// checks if the UpdateInstanceType type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &UpdateInstanceType{} + +// UpdateInstanceType struct for UpdateInstanceType +type UpdateInstanceType struct { + // Instance type's name + Name *string `json:"name,omitempty"` + Resources *InstanceResources `json:"resources,omitempty"` + Prices *map[string]Price `json:"prices,omitempty"` + // The supported storage types for the instance type + StorageTypes []string `json:"storageTypes,omitempty"` +} + +// NewUpdateInstanceType instantiates a new UpdateInstanceType object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewUpdateInstanceType() *UpdateInstanceType { + this := UpdateInstanceType{} + return &this +} + +// NewUpdateInstanceTypeWithDefaults instantiates a new UpdateInstanceType object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewUpdateInstanceTypeWithDefaults() *UpdateInstanceType { + this := UpdateInstanceType{} + return &this +} + +// GetName returns the Name field value if set, zero value otherwise. +func (o *UpdateInstanceType) GetName() string { + if o == nil || IsNil(o.Name) { + var ret string + return ret + } + return *o.Name +} + +// GetNameOk returns a tuple with the Name field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *UpdateInstanceType) GetNameOk() (*string, bool) { + if o == nil || IsNil(o.Name) { + return nil, false + } + return o.Name, true +} + +// HasName returns a boolean if a field has been set. +func (o *UpdateInstanceType) HasName() bool { + if o != nil && !IsNil(o.Name) { + return true + } + + return false +} + +// SetName gets a reference to the given string and assigns it to the Name field. +func (o *UpdateInstanceType) SetName(v string) { + o.Name = &v +} + +// GetResources returns the Resources field value if set, zero value otherwise. +func (o *UpdateInstanceType) GetResources() InstanceResources { + if o == nil || IsNil(o.Resources) { + var ret InstanceResources + return ret + } + return *o.Resources +} + +// GetResourcesOk returns a tuple with the Resources field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *UpdateInstanceType) GetResourcesOk() (*InstanceResources, bool) { + if o == nil || IsNil(o.Resources) { + return nil, false + } + return o.Resources, true +} + +// HasResources returns a boolean if a field has been set. +func (o *UpdateInstanceType) HasResources() bool { + if o != nil && !IsNil(o.Resources) { + return true + } + + return false +} + +// SetResources gets a reference to the given InstanceResources and assigns it to the Resources field. +func (o *UpdateInstanceType) SetResources(v InstanceResources) { + o.Resources = &v +} + +// GetPrices returns the Prices field value if set, zero value otherwise. +func (o *UpdateInstanceType) GetPrices() map[string]Price { + if o == nil || IsNil(o.Prices) { + var ret map[string]Price + return ret + } + return *o.Prices +} + +// GetPricesOk returns a tuple with the Prices field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *UpdateInstanceType) GetPricesOk() (*map[string]Price, bool) { + if o == nil || IsNil(o.Prices) { + return nil, false + } + return o.Prices, true +} + +// HasPrices returns a boolean if a field has been set. +func (o *UpdateInstanceType) HasPrices() bool { + if o != nil && !IsNil(o.Prices) { + return true + } + + return false +} + +// SetPrices gets a reference to the given map[string]Price and assigns it to the Prices field. +func (o *UpdateInstanceType) SetPrices(v map[string]Price) { + o.Prices = &v +} + +// GetStorageTypes returns the StorageTypes field value if set, zero value otherwise (both if not set or set to explicit null). +func (o *UpdateInstanceType) GetStorageTypes() []string { + if o == nil { + var ret []string + return ret + } + return o.StorageTypes +} + +// GetStorageTypesOk returns a tuple with the StorageTypes field value if set, nil otherwise +// and a boolean to check if the value has been set. +// NOTE: If the value is an explicit nil, `nil, true` will be returned +func (o *UpdateInstanceType) GetStorageTypesOk() ([]string, bool) { + if o == nil || IsNil(o.StorageTypes) { + return nil, false + } + return o.StorageTypes, true +} + +// HasStorageTypes returns a boolean if a field has been set. +func (o *UpdateInstanceType) HasStorageTypes() bool { + if o != nil && !IsNil(o.StorageTypes) { + return true + } + + return false +} + +// SetStorageTypes gets a reference to the given []string and assigns it to the StorageTypes field. +func (o *UpdateInstanceType) SetStorageTypes(v []string) { + o.StorageTypes = v +} + +func (o UpdateInstanceType) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o UpdateInstanceType) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Name) { + toSerialize["name"] = o.Name + } + if !IsNil(o.Resources) { + toSerialize["resources"] = o.Resources + } + if !IsNil(o.Prices) { + toSerialize["prices"] = o.Prices + } + if o.StorageTypes != nil { + toSerialize["storageTypes"] = o.StorageTypes + } + return toSerialize, nil +} + +type NullableUpdateInstanceType struct { + value *UpdateInstanceType + isSet bool +} + +func (v NullableUpdateInstanceType) Get() *UpdateInstanceType { + return v.value +} + +func (v *NullableUpdateInstanceType) Set(val *UpdateInstanceType) { + v.value = val + v.isSet = true +} + +func (v NullableUpdateInstanceType) IsSet() bool { + return v.isSet +} + +func (v *NullableUpdateInstanceType) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableUpdateInstanceType(val *UpdateInstanceType) *NullableUpdateInstanceType { + return &NullableUpdateInstanceType{value: val, isSet: true} +} + +func (v NullableUpdateInstanceType) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableUpdateInstanceType) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/publicCloud/model_values.go b/publicCloud/model_values.go new file mode 100644 index 0000000..0633bb6 --- /dev/null +++ b/publicCloud/model_values.go @@ -0,0 +1,234 @@ +/* +LeaseWeb API for launching and managing Public Cloud instances + +> The base URL for this API is: **https://api.leaseweb.com/publicCloud/v1/_** This API provides ways to launch and manage Public Cloud instances.
BETA
This API is in BETA. Documentation might be incorrect or incomplete. Functionality might change with the final release.> + +API version: v1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package publicCloud + +import ( + "encoding/json" +) + +// checks if the Values type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &Values{} + +// Values struct for Values +type Values struct { + Tier0 *Tier `json:"tier_0,omitempty"` + Tier1 *Tier `json:"tier_1,omitempty"` + Tier2 *Tier `json:"tier_2,omitempty"` + Tier3 *Tier `json:"tier_3,omitempty"` +} + +// NewValues instantiates a new Values object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewValues() *Values { + this := Values{} + return &this +} + +// NewValuesWithDefaults instantiates a new Values object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewValuesWithDefaults() *Values { + this := Values{} + return &this +} + +// GetTier0 returns the Tier0 field value if set, zero value otherwise. +func (o *Values) GetTier0() Tier { + if o == nil || IsNil(o.Tier0) { + var ret Tier + return ret + } + return *o.Tier0 +} + +// GetTier0Ok returns a tuple with the Tier0 field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Values) GetTier0Ok() (*Tier, bool) { + if o == nil || IsNil(o.Tier0) { + return nil, false + } + return o.Tier0, true +} + +// HasTier0 returns a boolean if a field has been set. +func (o *Values) HasTier0() bool { + if o != nil && !IsNil(o.Tier0) { + return true + } + + return false +} + +// SetTier0 gets a reference to the given Tier and assigns it to the Tier0 field. +func (o *Values) SetTier0(v Tier) { + o.Tier0 = &v +} + +// GetTier1 returns the Tier1 field value if set, zero value otherwise. +func (o *Values) GetTier1() Tier { + if o == nil || IsNil(o.Tier1) { + var ret Tier + return ret + } + return *o.Tier1 +} + +// GetTier1Ok returns a tuple with the Tier1 field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Values) GetTier1Ok() (*Tier, bool) { + if o == nil || IsNil(o.Tier1) { + return nil, false + } + return o.Tier1, true +} + +// HasTier1 returns a boolean if a field has been set. +func (o *Values) HasTier1() bool { + if o != nil && !IsNil(o.Tier1) { + return true + } + + return false +} + +// SetTier1 gets a reference to the given Tier and assigns it to the Tier1 field. +func (o *Values) SetTier1(v Tier) { + o.Tier1 = &v +} + +// GetTier2 returns the Tier2 field value if set, zero value otherwise. +func (o *Values) GetTier2() Tier { + if o == nil || IsNil(o.Tier2) { + var ret Tier + return ret + } + return *o.Tier2 +} + +// GetTier2Ok returns a tuple with the Tier2 field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Values) GetTier2Ok() (*Tier, bool) { + if o == nil || IsNil(o.Tier2) { + return nil, false + } + return o.Tier2, true +} + +// HasTier2 returns a boolean if a field has been set. +func (o *Values) HasTier2() bool { + if o != nil && !IsNil(o.Tier2) { + return true + } + + return false +} + +// SetTier2 gets a reference to the given Tier and assigns it to the Tier2 field. +func (o *Values) SetTier2(v Tier) { + o.Tier2 = &v +} + +// GetTier3 returns the Tier3 field value if set, zero value otherwise. +func (o *Values) GetTier3() Tier { + if o == nil || IsNil(o.Tier3) { + var ret Tier + return ret + } + return *o.Tier3 +} + +// GetTier3Ok returns a tuple with the Tier3 field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Values) GetTier3Ok() (*Tier, bool) { + if o == nil || IsNil(o.Tier3) { + return nil, false + } + return o.Tier3, true +} + +// HasTier3 returns a boolean if a field has been set. +func (o *Values) HasTier3() bool { + if o != nil && !IsNil(o.Tier3) { + return true + } + + return false +} + +// SetTier3 gets a reference to the given Tier and assigns it to the Tier3 field. +func (o *Values) SetTier3(v Tier) { + o.Tier3 = &v +} + +func (o Values) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o Values) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Tier0) { + toSerialize["tier_0"] = o.Tier0 + } + if !IsNil(o.Tier1) { + toSerialize["tier_1"] = o.Tier1 + } + if !IsNil(o.Tier2) { + toSerialize["tier_2"] = o.Tier2 + } + if !IsNil(o.Tier3) { + toSerialize["tier_3"] = o.Tier3 + } + return toSerialize, nil +} + +type NullableValues struct { + value *Values + isSet bool +} + +func (v NullableValues) Get() *Values { + return v.value +} + +func (v *NullableValues) Set(val *Values) { + v.value = val + v.isSet = true +} + +func (v NullableValues) IsSet() bool { + return v.isSet +} + +func (v *NullableValues) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableValues(val *Values) *NullableValues { + return &NullableValues{value: val, isSet: true} +} + +func (v NullableValues) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableValues) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/publicCloud/response.go b/publicCloud/response.go new file mode 100644 index 0000000..b63c70f --- /dev/null +++ b/publicCloud/response.go @@ -0,0 +1,47 @@ +/* +LeaseWeb API for launching and managing Public Cloud instances + +> The base URL for this API is: **https://api.leaseweb.com/publicCloud/v1/_** This API provides ways to launch and manage Public Cloud instances.
BETA
This API is in BETA. Documentation might be incorrect or incomplete. Functionality might change with the final release.> + +API version: v1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package publicCloud + +import ( + "net/http" +) + +// APIResponse stores the API response returned by the server. +type APIResponse struct { + *http.Response `json:"-"` + Message string `json:"message,omitempty"` + // Operation is the name of the OpenAPI operation. + Operation string `json:"operation,omitempty"` + // RequestURL is the request URL. This value is always available, even if the + // embedded *http.Response is nil. + RequestURL string `json:"url,omitempty"` + // Method is the HTTP method used for the request. This value is always + // available, even if the embedded *http.Response is nil. + Method string `json:"method,omitempty"` + // Payload holds the contents of the response body (which may be nil or empty). + // This is provided here as the raw response.Body() reader will have already + // been drained. + Payload []byte `json:"-"` +} + +// NewAPIResponse returns a new APIResponse object. +func NewAPIResponse(r *http.Response) *APIResponse { + + response := &APIResponse{Response: r} + return response +} + +// NewAPIResponseWithError returns a new APIResponse object with the provided error message. +func NewAPIResponseWithError(errorMessage string) *APIResponse { + + response := &APIResponse{Message: errorMessage} + return response +} diff --git a/publicCloud/test/api_public_cloud_test.go b/publicCloud/test/api_public_cloud_test.go new file mode 100644 index 0000000..280f0dc --- /dev/null +++ b/publicCloud/test/api_public_cloud_test.go @@ -0,0 +1,456 @@ +/* +LeaseWeb API for launching and managing Public Cloud instances + +Testing PublicCloudAPIService + +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); + +package publicCloud + +import ( + "context" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "testing" + openapiclient "github.com/leaseweb/leaseweb-go-sdk/publicCloud" +) + +func Test_publicCloud_PublicCloudAPIService(t *testing.T) { + + configuration := openapiclient.NewConfiguration() + apiClient := openapiclient.NewAPIClient(configuration) + + t.Run("Test PublicCloudAPIService AttachIso", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var instanceId string + + httpRes, err := apiClient.PublicCloudAPI.AttachIso(context.Background(), instanceId).Execute() + + require.Nil(t, err) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test PublicCloudAPIService CancelInstanceTermination", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var instanceId string + + httpRes, err := apiClient.PublicCloudAPI.CancelInstanceTermination(context.Background(), instanceId).Execute() + + require.Nil(t, err) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test PublicCloudAPIService CreateFirewallRules", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var instanceId string + + resp, httpRes, err := apiClient.PublicCloudAPI.CreateFirewallRules(context.Background(), instanceId).Execute() + + require.Nil(t, err) + require.NotNil(t, resp) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test PublicCloudAPIService CredentialsDelete", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var instanceId string + + httpRes, err := apiClient.PublicCloudAPI.CredentialsDelete(context.Background(), instanceId).Execute() + + require.Nil(t, err) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test PublicCloudAPIService DeleteCredential", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var instanceId string + var type_ string + var username string + + httpRes, err := apiClient.PublicCloudAPI.DeleteCredential(context.Background(), instanceId, type_, username).Execute() + + require.Nil(t, err) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test PublicCloudAPIService DeleteFirewallRules", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var instanceId string + + resp, httpRes, err := apiClient.PublicCloudAPI.DeleteFirewallRules(context.Background(), instanceId).Execute() + + require.Nil(t, err) + require.NotNil(t, resp) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test PublicCloudAPIService DetachIso", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var instanceId string + + httpRes, err := apiClient.PublicCloudAPI.DetachIso(context.Background(), instanceId).Execute() + + require.Nil(t, err) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test PublicCloudAPIService EditFirewallRules", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var instanceId string + + resp, httpRes, err := apiClient.PublicCloudAPI.EditFirewallRules(context.Background(), instanceId).Execute() + + require.Nil(t, err) + require.NotNil(t, resp) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test PublicCloudAPIService GetConsoleAccessToInstance", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var instanceId string + + resp, httpRes, err := apiClient.PublicCloudAPI.GetConsoleAccessToInstance(context.Background(), instanceId).Execute() + + require.Nil(t, err) + require.NotNil(t, resp) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test PublicCloudAPIService GetCredential", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var instanceId string + var type_ string + var username string + + resp, httpRes, err := apiClient.PublicCloudAPI.GetCredential(context.Background(), instanceId, type_, username).Execute() + + require.Nil(t, err) + require.NotNil(t, resp) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test PublicCloudAPIService GetCredentialList", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var instanceId string + + resp, httpRes, err := apiClient.PublicCloudAPI.GetCredentialList(context.Background(), instanceId).Execute() + + require.Nil(t, err) + require.NotNil(t, resp) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test PublicCloudAPIService GetCredentialListByType", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var instanceId string + var type_ string + + resp, httpRes, err := apiClient.PublicCloudAPI.GetCredentialListByType(context.Background(), instanceId, type_).Execute() + + require.Nil(t, err) + require.NotNil(t, resp) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test PublicCloudAPIService GetExpenses", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var equipmentId string + + resp, httpRes, err := apiClient.PublicCloudAPI.GetExpenses(context.Background(), equipmentId).Execute() + + require.Nil(t, err) + require.NotNil(t, resp) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test PublicCloudAPIService GetFirewallRuleList", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var instanceId string + + resp, httpRes, err := apiClient.PublicCloudAPI.GetFirewallRuleList(context.Background(), instanceId).Execute() + + require.Nil(t, err) + require.NotNil(t, resp) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test PublicCloudAPIService GetInstance", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var instanceId string + + resp, httpRes, err := apiClient.PublicCloudAPI.GetInstance(context.Background(), instanceId).Execute() + + require.Nil(t, err) + require.NotNil(t, resp) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test PublicCloudAPIService GetInstanceTypeList", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + resp, httpRes, err := apiClient.PublicCloudAPI.GetInstanceTypeList(context.Background()).Execute() + + require.Nil(t, err) + require.NotNil(t, resp) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test PublicCloudAPIService GetIsoList", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + resp, httpRes, err := apiClient.PublicCloudAPI.GetIsoList(context.Background()).Execute() + + require.Nil(t, err) + require.NotNil(t, resp) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test PublicCloudAPIService GetMarketAppList", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + resp, httpRes, err := apiClient.PublicCloudAPI.GetMarketAppList(context.Background()).Execute() + + require.Nil(t, err) + require.NotNil(t, resp) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test PublicCloudAPIService GetOperatingSystemList", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + resp, httpRes, err := apiClient.PublicCloudAPI.GetOperatingSystemList(context.Background()).Execute() + + require.Nil(t, err) + require.NotNil(t, resp) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test PublicCloudAPIService GetReinstallOsList", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var instanceId string + + resp, httpRes, err := apiClient.PublicCloudAPI.GetReinstallOsList(context.Background(), instanceId).Execute() + + require.Nil(t, err) + require.NotNil(t, resp) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test PublicCloudAPIService GetUpdateInstanceTypeList", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var instanceId string + + resp, httpRes, err := apiClient.PublicCloudAPI.GetUpdateInstanceTypeList(context.Background(), instanceId).Execute() + + require.Nil(t, err) + require.NotNil(t, resp) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test PublicCloudAPIService InstanceList", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + resp, httpRes, err := apiClient.PublicCloudAPI.InstanceList(context.Background()).Execute() + + require.Nil(t, err) + require.NotNil(t, resp) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test PublicCloudAPIService LaunchInstance", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + resp, httpRes, err := apiClient.PublicCloudAPI.LaunchInstance(context.Background()).Execute() + + require.Nil(t, err) + require.NotNil(t, resp) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test PublicCloudAPIService RebootInstance", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var instanceId string + + httpRes, err := apiClient.PublicCloudAPI.RebootInstance(context.Background(), instanceId).Execute() + + require.Nil(t, err) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test PublicCloudAPIService RegionsList", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + resp, httpRes, err := apiClient.PublicCloudAPI.RegionsList(context.Background()).Execute() + + require.Nil(t, err) + require.NotNil(t, resp) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test PublicCloudAPIService ResetPassword", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var instanceId string + + httpRes, err := apiClient.PublicCloudAPI.ResetPassword(context.Background(), instanceId).Execute() + + require.Nil(t, err) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test PublicCloudAPIService StartInstance", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var instanceId string + + httpRes, err := apiClient.PublicCloudAPI.StartInstance(context.Background(), instanceId).Execute() + + require.Nil(t, err) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test PublicCloudAPIService StopInstance", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var instanceId string + + httpRes, err := apiClient.PublicCloudAPI.StopInstance(context.Background(), instanceId).Execute() + + require.Nil(t, err) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test PublicCloudAPIService StoreCredential", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var instanceId string + + resp, httpRes, err := apiClient.PublicCloudAPI.StoreCredential(context.Background(), instanceId).Execute() + + require.Nil(t, err) + require.NotNil(t, resp) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test PublicCloudAPIService TerminateInstance", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var instanceId string + + httpRes, err := apiClient.PublicCloudAPI.TerminateInstance(context.Background(), instanceId).Execute() + + require.Nil(t, err) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test PublicCloudAPIService UpdateCredential", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var instanceId string + var type_ string + var username string + + resp, httpRes, err := apiClient.PublicCloudAPI.UpdateCredential(context.Background(), instanceId, type_, username).Execute() + + require.Nil(t, err) + require.NotNil(t, resp) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test PublicCloudAPIService UpdateInstance", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var instanceId string + + resp, httpRes, err := apiClient.PublicCloudAPI.UpdateInstance(context.Background(), instanceId).Execute() + + require.Nil(t, err) + require.NotNil(t, resp) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + +} diff --git a/publicCloud/utils.go b/publicCloud/utils.go new file mode 100644 index 0000000..9f5fcf0 --- /dev/null +++ b/publicCloud/utils.go @@ -0,0 +1,347 @@ +/* +LeaseWeb API for launching and managing Public Cloud instances + +> The base URL for this API is: **https://api.leaseweb.com/publicCloud/v1/_** This API provides ways to launch and manage Public Cloud instances.
BETA
This API is in BETA. Documentation might be incorrect or incomplete. Functionality might change with the final release.> + +API version: v1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package publicCloud + +import ( + "encoding/json" + "reflect" + "time" +) + +// PtrBool is a helper routine that returns a pointer to given boolean value. +func PtrBool(v bool) *bool { return &v } + +// PtrInt is a helper routine that returns a pointer to given integer value. +func PtrInt(v int) *int { return &v } + +// PtrInt32 is a helper routine that returns a pointer to given integer value. +func PtrInt32(v int32) *int32 { return &v } + +// PtrInt64 is a helper routine that returns a pointer to given integer value. +func PtrInt64(v int64) *int64 { return &v } + +// PtrFloat32 is a helper routine that returns a pointer to given float value. +func PtrFloat32(v float32) *float32 { return &v } + +// PtrFloat64 is a helper routine that returns a pointer to given float value. +func PtrFloat64(v float64) *float64 { return &v } + +// PtrString is a helper routine that returns a pointer to given string value. +func PtrString(v string) *string { return &v } + +// PtrTime is helper routine that returns a pointer to given Time value. +func PtrTime(v time.Time) *time.Time { return &v } + +type NullableBool struct { + value *bool + isSet bool +} + +func (v NullableBool) Get() *bool { + return v.value +} + +func (v *NullableBool) Set(val *bool) { + v.value = val + v.isSet = true +} + +func (v NullableBool) IsSet() bool { + return v.isSet +} + +func (v *NullableBool) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableBool(val *bool) *NullableBool { + return &NullableBool{value: val, isSet: true} +} + +func (v NullableBool) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableBool) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + +type NullableInt struct { + value *int + isSet bool +} + +func (v NullableInt) Get() *int { + return v.value +} + +func (v *NullableInt) Set(val *int) { + v.value = val + v.isSet = true +} + +func (v NullableInt) IsSet() bool { + return v.isSet +} + +func (v *NullableInt) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableInt(val *int) *NullableInt { + return &NullableInt{value: val, isSet: true} +} + +func (v NullableInt) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableInt) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + +type NullableInt32 struct { + value *int32 + isSet bool +} + +func (v NullableInt32) Get() *int32 { + return v.value +} + +func (v *NullableInt32) Set(val *int32) { + v.value = val + v.isSet = true +} + +func (v NullableInt32) IsSet() bool { + return v.isSet +} + +func (v *NullableInt32) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableInt32(val *int32) *NullableInt32 { + return &NullableInt32{value: val, isSet: true} +} + +func (v NullableInt32) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableInt32) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + +type NullableInt64 struct { + value *int64 + isSet bool +} + +func (v NullableInt64) Get() *int64 { + return v.value +} + +func (v *NullableInt64) Set(val *int64) { + v.value = val + v.isSet = true +} + +func (v NullableInt64) IsSet() bool { + return v.isSet +} + +func (v *NullableInt64) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableInt64(val *int64) *NullableInt64 { + return &NullableInt64{value: val, isSet: true} +} + +func (v NullableInt64) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableInt64) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + +type NullableFloat32 struct { + value *float32 + isSet bool +} + +func (v NullableFloat32) Get() *float32 { + return v.value +} + +func (v *NullableFloat32) Set(val *float32) { + v.value = val + v.isSet = true +} + +func (v NullableFloat32) IsSet() bool { + return v.isSet +} + +func (v *NullableFloat32) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableFloat32(val *float32) *NullableFloat32 { + return &NullableFloat32{value: val, isSet: true} +} + +func (v NullableFloat32) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableFloat32) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + +type NullableFloat64 struct { + value *float64 + isSet bool +} + +func (v NullableFloat64) Get() *float64 { + return v.value +} + +func (v *NullableFloat64) Set(val *float64) { + v.value = val + v.isSet = true +} + +func (v NullableFloat64) IsSet() bool { + return v.isSet +} + +func (v *NullableFloat64) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableFloat64(val *float64) *NullableFloat64 { + return &NullableFloat64{value: val, isSet: true} +} + +func (v NullableFloat64) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableFloat64) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + +type NullableString struct { + value *string + isSet bool +} + +func (v NullableString) Get() *string { + return v.value +} + +func (v *NullableString) Set(val *string) { + v.value = val + v.isSet = true +} + +func (v NullableString) IsSet() bool { + return v.isSet +} + +func (v *NullableString) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableString(val *string) *NullableString { + return &NullableString{value: val, isSet: true} +} + +func (v NullableString) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableString) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + +type NullableTime struct { + value *time.Time + isSet bool +} + +func (v NullableTime) Get() *time.Time { + return v.value +} + +func (v *NullableTime) Set(val *time.Time) { + v.value = val + v.isSet = true +} + +func (v NullableTime) IsSet() bool { + return v.isSet +} + +func (v *NullableTime) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableTime(val *time.Time) *NullableTime { + return &NullableTime{value: val, isSet: true} +} + +func (v NullableTime) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableTime) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + +// IsNil checks if an input is nil +func IsNil(i interface{}) bool { + if i == nil { + return true + } + switch reflect.TypeOf(i).Kind() { + case reflect.Chan, reflect.Func, reflect.Map, reflect.Ptr, reflect.UnsafePointer, reflect.Interface, reflect.Slice: + return reflect.ValueOf(i).IsNil() + case reflect.Array: + return reflect.ValueOf(i).IsZero() + } + return false +} + +type MappedNullable interface { + ToMap() (map[string]interface{}, error) +} diff --git a/remote_management.go b/remote_management.go deleted file mode 100644 index 8252368..0000000 --- a/remote_management.go +++ /dev/null @@ -1,43 +0,0 @@ -package leaseweb - -import ( - "context" - "net/http" - - "github.com/LeaseWeb/leaseweb-go-sdk/options" -) - -const REMOTE_MANAGEMENT_API_VERSION = "v2" - -type RemoteManagementApi struct{} - -type RemoteManagementProfiles struct { - Metadata Metadata `json:"_metadata"` - Profiles []RemoteManagementProfile `json:"profiles"` -} - -type RemoteManagementProfile struct { - DataCenter string `json:"datacenter"` - File string `json:"file"` - SatelliteDataCenters []string `json:"satelliteDatacenters"` -} - -func (rma RemoteManagementApi) getPath(endpoint string) string { - return "/bareMetals/" + REMOTE_MANAGEMENT_API_VERSION + endpoint -} - -func (rma RemoteManagementApi) ChangeCredentials(ctx context.Context, password string) error { - payload := map[string]string{password: password} - path := rma.getPath("/remoteManagement/changeCredentials") - return doRequest(ctx, http.MethodPost, path, "", nil, payload) -} - -func (rma RemoteManagementApi) ListProfiles(ctx context.Context, opts PaginationOptions) (*RemoteManagementProfiles, error) { - path := rma.getPath("/remoteManagement/profiles") - result := &RemoteManagementProfiles{} - query := options.Encode(opts) - if err := doRequest(ctx, http.MethodGet, path, query, result); err != nil { - return nil, err - } - return result, nil -} diff --git a/remote_management_test.go b/remote_management_test.go deleted file mode 100644 index 0e36c11..0000000 --- a/remote_management_test.go +++ /dev/null @@ -1,274 +0,0 @@ -package leaseweb - -import ( - "context" - "fmt" - "net/http" - "testing" - - "github.com/stretchr/testify/assert" -) - -func TestRemoteManagementChangeCredentials(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusNoContent) - }) - defer teardown() - - remoteManagementApi := RemoteManagementApi{} - ctx := context.Background() - err := remoteManagementApi.ChangeCredentials(ctx, "new password") - - assert := assert.New(t) - assert.Nil(err) -} - -func TestRemoteManagementTestChangeCredentialsServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, RemoteManagementApi{}.ChangeCredentials(ctx, "new password") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, RemoteManagementApi{}.ChangeCredentials(ctx, "new password") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The server encountered an unexpected condition that prevented it from fulfilling the request."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, RemoteManagementApi{}.ChangeCredentials(ctx, "new password") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The server encountered an unexpected condition that prevented it from fulfilling the request.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, RemoteManagementApi{}.ChangeCredentials(ctx, "new password") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestRemoteManagementListProfiles(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{"_metadata":{"limit": 10, "offset": 0, "totalCount": 2}, "profiles": [ - { - "datacenter": "AMS-01", - "satelliteDatacenters": [ - "AMS-10", - "AMS-11", - "AMS-12" - ], - "file": "https://api.leaseweb.com/bareMetals/v2/remoteManagement/profiles/lsw-rmvpn-AMS-01.ovpn" - }, - { - "datacenter": "AMS-02", - "satelliteDatacenters": [ - "AMS-13", - "AMS-15" - ], - "file": "https://api.leaseweb.com/bareMetals/v2/remoteManagement/profiles/lsw-rmvpn-AMS-02.ovpn" - } - ]}`) - }) - defer teardown() - - remoteManagementApi := RemoteManagementApi{} - ctx := context.Background() - response, err := remoteManagementApi.ListProfiles(ctx, PaginationOptions{}) - - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 2) - assert.Equal(response.Metadata.Offset, 0) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.Profiles), 2) - - profile1 := response.Profiles[0] - assert.Equal(profile1.DataCenter, "AMS-01") - assert.Equal(profile1.File, "https://api.leaseweb.com/bareMetals/v2/remoteManagement/profiles/lsw-rmvpn-AMS-01.ovpn") - assert.Equal(len(profile1.SatelliteDataCenters), 3) - assert.Equal(profile1.SatelliteDataCenters[0], "AMS-10") - assert.Equal(profile1.SatelliteDataCenters[1], "AMS-11") - assert.Equal(profile1.SatelliteDataCenters[2], "AMS-12") - - profile2 := response.Profiles[1] - assert.Equal(profile2.DataCenter, "AMS-02") - assert.Equal(profile2.File, "https://api.leaseweb.com/bareMetals/v2/remoteManagement/profiles/lsw-rmvpn-AMS-02.ovpn") - assert.Equal(len(profile2.SatelliteDataCenters), 2) - assert.Equal(profile2.SatelliteDataCenters[0], "AMS-13") - assert.Equal(profile2.SatelliteDataCenters[1], "AMS-15") -} - -func TestRemoteManagementListProfilesPaginate(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{"_metadata":{"limit": 10, "offset": 1, "totalCount": 11}, "profiles": [ - { - "datacenter": "AMS-02", - "satelliteDatacenters": [ - "AMS-13", - "AMS-15" - ], - "file": "https://api.leaseweb.com/bareMetals/v2/remoteManagement/profiles/lsw-rmvpn-AMS-02.ovpn" - } - ]}`) - }) - defer teardown() - - remoteManagementApi := RemoteManagementApi{} - ctx := context.Background() - opts := PaginationOptions{ - Limit: Int(1), - } - response, err := remoteManagementApi.ListProfiles(ctx, opts) - - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 11) - assert.Equal(response.Metadata.Offset, 1) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.Profiles), 1) - - profile1 := response.Profiles[0] - assert.Equal(profile1.DataCenter, "AMS-02") - assert.Equal(profile1.File, "https://api.leaseweb.com/bareMetals/v2/remoteManagement/profiles/lsw-rmvpn-AMS-02.ovpn") - assert.Equal(len(profile1.SatelliteDataCenters), 2) - assert.Equal(profile1.SatelliteDataCenters[0], "AMS-13") - assert.Equal(profile1.SatelliteDataCenters[1], "AMS-15") -} - -func TestRemoteManagementTestListProfilesServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return RemoteManagementApi{}.ListProfiles(ctx, PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "403", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return RemoteManagementApi{}.ListProfiles(ctx, PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "403", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "500", "errorMessage": "The server encountered an unexpected condition that prevented it from fulfilling the request."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return RemoteManagementApi{}.ListProfiles(ctx, PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "500", - Message: "The server encountered an unexpected condition that prevented it from fulfilling the request.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "503", "errorMessage": "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return RemoteManagementApi{}.ListProfiles(ctx, PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "503", - Message: "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} diff --git a/rest.go b/rest.go deleted file mode 100644 index 05f7d83..0000000 --- a/rest.go +++ /dev/null @@ -1,159 +0,0 @@ -package leaseweb - -import ( - "context" - "encoding/json" - "io" - "net/http" - "strconv" - "strings" -) - -var lswClient *leasewebClient - -const DEFAULT_BASE_URL = "https://api.leaseweb.com" -const DEFAULT_VERSION = "dev" -const DEFAULT_USER_AGENT = "leaseweb-go-sdk/" + DEFAULT_VERSION - -type leasewebClient struct { - apiKey string - baseUrl string - client *http.Client - userAgent string -} - -type ApiContext struct { - Method string - Url string -} - -type ApiError struct { - ApiContext - Code string `json:"errorCode"` - Message string `json:"errorMessage"` - Details map[string][]string `json:"errorDetails"` - CorrelationId string `json:"correlationId"` - UserMessage string `json:"userMessage"` - Reference string `json:"reference"` -} - -func (erra *ApiError) Error() string { - return "leaseweb: " + erra.Message - -} - -type DecodingError struct { - ApiContext - Err error -} - -func (errd *DecodingError) Error() string { - return "leaseweb: decoding JSON response body failed (" + errd.Err.Error() + ")" -} - -type EncodingError struct { - ApiContext - Err error -} - -func (erre *EncodingError) Error() string { - return "leaseweb: encoding JSON request body failed (" + erre.Err.Error() + ")" -} - -func InitLeasewebClient(key string) { - lswClient = &leasewebClient{ - client: &http.Client{}, - apiKey: key, - userAgent: DEFAULT_USER_AGENT, - } -} -func SetUserAgent(userAgent string) { - lswClient.userAgent = userAgent -} - -func SetBaseUrl(baseUrl string) { - lswClient.baseUrl = baseUrl -} -func getUserAgent() string { - if lswClient.userAgent != "" { - return DEFAULT_USER_AGENT + " " + lswClient.userAgent - } - return DEFAULT_USER_AGENT -} - -func getBaseUrl() string { - if lswClient.baseUrl != "" { - return lswClient.baseUrl - } - return DEFAULT_BASE_URL -} - -func doRequest(ctx context.Context, method, path, query string, args ...interface{}) error { - url := getBaseUrl() + path - if query != "" { - url += "?" + query - } - - apiContext := ApiContext{method, url} - - var tmpPayload io.Reader - if method == http.MethodPost || method == http.MethodPut { - if len(args) > 1 { - b, err := json.Marshal(args[1]) - if err != nil { - return &EncodingError{apiContext, err} - } - tmpPayload = strings.NewReader(string(b)) - } - } - - req, err := http.NewRequestWithContext(ctx, method, url, tmpPayload) - if err != nil { - return err - } - - if method == http.MethodPost || method == http.MethodPut { - req.Header.Set("Content-Type", "application/json") - } - - req.Header.Add("x-lsw-auth", lswClient.apiKey) - req.Header.Set("User-Agent", getUserAgent()) - resp, err := lswClient.client.Do(req) - if err != nil { - return err - } - defer resp.Body.Close() - - if resp.StatusCode == http.StatusNoContent { - return nil - } - - respBody, err := io.ReadAll(resp.Body) - if err != nil { - return err - } - - statusOK := resp.StatusCode >= 200 && resp.StatusCode < 300 - if !statusOK { - statusCode, statusMessage, ok := strings.Cut(resp.Status, " ") - if !ok { - statusCode = strconv.Itoa(resp.StatusCode) - statusMessage = "An error occurred" - } - - apiErr := &ApiError{ - ApiContext: apiContext, - Code: statusCode, - Message: statusMessage, - } - json.Unmarshal(respBody, apiErr) - return apiErr - } - - if len(args) > 0 { - if err = json.Unmarshal(respBody, &args[0]); err != nil { - return &DecodingError{apiContext, err} - } - } - return nil -} diff --git a/rest_test.go b/rest_test.go deleted file mode 100644 index b4939dc..0000000 --- a/rest_test.go +++ /dev/null @@ -1,82 +0,0 @@ -package leaseweb - -import ( - "crypto/tls" - "net/http" - "net/http/httptest" - "net/url" - "os" - "testing" - - "github.com/stretchr/testify/assert" -) - -var ctx = ctxT{} -var testApiKey = "test-api-key" - -type serverErrorTest struct { - Title string - MockServer func(http.ResponseWriter, *http.Request) - FunctionCall func() (interface{}, error) - ExpectedError ApiError -} - -type ctxT struct { - ts *httptest.Server - oldHost string - oldHttpClient *http.Client -} - -func assertServerErrorTests(t *testing.T, serverErrorTests []serverErrorTest) { - for _, serverErrorTest := range serverErrorTests { - setup(serverErrorTest.MockServer) - defer teardown() - resp, err := serverErrorTest.FunctionCall() - assert := assert.New(t) - assert.Empty(resp) - assert.NotNil(err) - assert.Equal(err.Error(), "leaseweb: "+serverErrorTest.ExpectedError.Message) - lswErr, ok := err.(*ApiError) - assert.Equal(true, ok) - assert.Equal(lswErr.Message, serverErrorTest.ExpectedError.Message) - assert.Equal(lswErr.CorrelationId, serverErrorTest.ExpectedError.CorrelationId) - assert.Equal(lswErr.Code, serverErrorTest.ExpectedError.Code) - assert.Equal(lswErr.Reference, serverErrorTest.ExpectedError.Reference) - assert.Equal(lswErr.UserMessage, serverErrorTest.ExpectedError.UserMessage) - assert.Equal(lswErr.Details, serverErrorTest.ExpectedError.Details) - } -} - -func setup(handler http.HandlerFunc) *httptest.Server { - ts := httptest.NewTLSServer(handler) - ctx.ts = ts - _url, err := url.Parse(ts.URL) - if err != nil { - panic(err) - } - - ctx.oldHost = lswClient.baseUrl - ctx.oldHttpClient = lswClient.client - - lswClient.baseUrl = "https://" + _url.Host - lswClient.client = &http.Client{ - Transport: &http.Transport{ - TLSClientConfig: &tls.Config{ - InsecureSkipVerify: true, - }, - }, - } - - return ts -} - -func teardown() { - ctx.ts.Close() - lswClient.baseUrl = ctx.oldHost - lswClient.client = ctx.oldHttpClient -} - -func TestMain(m *testing.M) { - InitLeasewebClient(testApiKey) - os.Exit(m.Run()) -} diff --git a/services.go b/services.go deleted file mode 100644 index 028471e..0000000 --- a/services.go +++ /dev/null @@ -1,103 +0,0 @@ -package leaseweb - -import ( - "context" - "encoding/json" - "net/http" - - "github.com/LeaseWeb/leaseweb-go-sdk/options" -) - -const SERVICES_API_VERSION = "v1" - -type ServicesApi struct{} - -type Services struct { - Services []Service `json:"services"` - Metadata Metadata `json:"metadata"` -} - -type Service struct { - // TODO; - // "attributes": {} - BillingCycle string `json:"billingCycle"` - Cancellable bool `json:"cancellable"` - ContractId string `json:"contractId"` - ContractTerm string `json:"contractTerm"` - ContractTermEndDate string `json:"contractTermEndDate"` - Currency string `json:"currency"` - DeliveryDate string `json:"deliveryDate"` - DeliveryEstimate string `json:"deliveryEstimate"` - EndDate string `json:"endDate"` - EquipmentId string `json:"equipmentId"` - Id string `json:"id"` - OrderDate string `json:"orderDate"` - PricePerFrequency json.Number `json:"pricePerFrequency"` - ProductId string `json:"productId"` - Reference string `json:"reference"` - StartDate string `json:"startDate"` - Status string `json:"status"` - Uncancellable bool `json:"uncancellable"` -} - -type ServicesCancellationReasons struct { - CancellationReasons []ServicesCancellationReason `json:"cancellationReasons"` -} - -type ServicesCancellationReason struct { - Reason string `json:"reason"` - ReasonCode string `json:"reasonCode"` -} - -type ServicesListOptions struct { - PaginationOptions - ProductId *string `param:"productId"` - Reference *string `param:"reference"` - EquipmentId *string `param:"equipmentId"` -} - -func (sa ServicesApi) getPath(endpoint string) string { - return "/services/" + SERVICES_API_VERSION + endpoint -} - -func (sa ServicesApi) List(ctx context.Context, opts ServicesListOptions) (*Services, error) { - path := sa.getPath("/services") - query := options.Encode(opts) - result := &Services{} - if err := doRequest(ctx, http.MethodGet, path, query, result); err != nil { - return nil, err - } - return result, nil -} - -func (sa ServicesApi) ListCancellationReasons(ctx context.Context) (*ServicesCancellationReasons, error) { - path := sa.getPath("/services/cancellationReasons") - result := &ServicesCancellationReasons{} - if err := doRequest(ctx, http.MethodGet, path, "", result); err != nil { - return nil, err - } - return result, nil -} - -func (sa ServicesApi) Get(ctx context.Context, id string) (*Service, error) { - path := sa.getPath("/services/" + id) - result := &Service{} - if err := doRequest(ctx, http.MethodGet, path, "", result); err != nil { - return nil, err - } - return result, nil -} - -func (sa ServicesApi) Cancel(ctx context.Context, id, reason, reasonCode string) error { - payload := map[string]string{ - "reason": reason, - "reasonCode": reasonCode, - } - path := sa.getPath("/services/" + id + "/cancel") - return doRequest(ctx, http.MethodPost, path, "", nil, payload) -} - -func (sa ServicesApi) Uncancel(ctx context.Context, id string) error { - path := sa.getPath("/services/" + id + "/uncancel") - return doRequest(ctx, http.MethodPost, path, "") -} diff --git a/services_test.go b/services_test.go deleted file mode 100644 index f8114dd..0000000 --- a/services_test.go +++ /dev/null @@ -1,695 +0,0 @@ -package leaseweb - -import ( - "context" - "fmt" - "net/http" - "testing" - - "github.com/stretchr/testify/assert" -) - -func TestServicesList(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "metadata": { - "limit": 10, - "offset": 0, - "totalCount": 2 - }, - "services": [ - { - "billingCycle": "1 MONTH", - "cancellable": false, - "contractId": "00000110", - "contractTerm": "1 YEAR", - "contractTermEndDate": "2020-01-31T00:00:00+00:00", - "currency": "EUR", - "deliveryDate": "2019-01-01T00:00:00+00:00", - "deliveryEstimate": "5 - 7 business days", - "endDate": "2020-01-31T00:00:00+00:00", - "equipmentId": "12345678", - "id": "10000000000010", - "orderDate": "2019-01-01T00:00:00+00:00", - "pricePerFrequency": 396.01, - "productId": "DEDICATED_SERVER", - "reference": "this is a reference", - "startDate": "2019-01-01T00:00:00+00:00", - "status": "ACTIVE", - "uncancellable": true - }, - { - "billingCycle": "1 YEAR", - "cancellable": true, - "contractId": "00000110", - "contractTerm": "1 YEAR", - "contractTermEndDate": "2020-01-31T00:00:00+00:00", - "currency": "EUR", - "deliveryDate": "2019-01-01T00:00:00+00:00", - "deliveryEstimate": "5 - 7 business days", - "id": "10000000000011", - "orderDate": "2019-01-01T00:00:00+00:00", - "pricePerFrequency": 139.99, - "productId": "DOMAIN", - "startDate": "2019-01-01T00:00:00+00:00", - "status": "ACTIVE", - "uncancellable": false - } - ] - }`) - }) - defer teardown() - - ctx := context.Background() - response, err := ServicesApi{}.List(ctx, ServicesListOptions{}) - - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 2) - assert.Equal(response.Metadata.Offset, 0) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.Services), 2) - - service1 := response.Services[0] - assert.Equal(service1.BillingCycle, "1 MONTH") - assert.Equal(service1.Cancellable, false) - assert.Equal(service1.ContractId, "00000110") - assert.Equal(service1.ContractTerm, "1 YEAR") - assert.Equal(service1.ContractTermEndDate, "2020-01-31T00:00:00+00:00") - assert.Equal(service1.Currency, "EUR") - assert.Equal(service1.DeliveryDate, "2019-01-01T00:00:00+00:00") - assert.Equal(service1.DeliveryEstimate, "5 - 7 business days") - assert.Equal(service1.EndDate, "2020-01-31T00:00:00+00:00") - assert.Equal(service1.EquipmentId, "12345678") - assert.Equal(service1.Id, "10000000000010") - assert.Equal(service1.OrderDate, "2019-01-01T00:00:00+00:00") - assert.Equal(service1.PricePerFrequency.String(), "396.01") - assert.Equal(service1.ProductId, "DEDICATED_SERVER") - assert.Equal(service1.Reference, "this is a reference") - assert.Equal(service1.StartDate, "2019-01-01T00:00:00+00:00") - assert.Equal(service1.Status, "ACTIVE") - assert.Equal(service1.Uncancellable, true) - - service2 := response.Services[1] - assert.Equal(service2.BillingCycle, "1 YEAR") - assert.Equal(service2.Cancellable, true) - assert.Equal(service2.ContractId, "00000110") - assert.Equal(service2.ContractTerm, "1 YEAR") - assert.Equal(service2.ContractTermEndDate, "2020-01-31T00:00:00+00:00") - assert.Equal(service2.Currency, "EUR") - assert.Equal(service2.DeliveryDate, "2019-01-01T00:00:00+00:00") - assert.Equal(service2.DeliveryEstimate, "5 - 7 business days") - assert.Equal(service2.Id, "10000000000011") - assert.Equal(service2.OrderDate, "2019-01-01T00:00:00+00:00") - assert.Equal(service2.PricePerFrequency.String(), "139.99") - assert.Equal(service2.ProductId, "DOMAIN") - assert.Equal(service2.StartDate, "2019-01-01T00:00:00+00:00") - assert.Equal(service2.Status, "ACTIVE") - assert.Equal(service2.Uncancellable, false) -} - -func TestServicesListPaginate(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "metadata": { - "limit": 10, - "offset": 1, - "totalCount": 11 - }, - "services": [ - { - "billingCycle": "1 MONTH", - "cancellable": false, - "contractId": "00000110", - "contractTerm": "1 YEAR", - "contractTermEndDate": "2020-01-31T00:00:00+00:00", - "currency": "EUR", - "deliveryDate": "2019-01-01T00:00:00+00:00", - "deliveryEstimate": "5 - 7 business days", - "endDate": "2020-01-31T00:00:00+00:00", - "equipmentId": "12345678", - "id": "10000000000010", - "orderDate": "2019-01-01T00:00:00+00:00", - "pricePerFrequency": 396.01, - "productId": "DEDICATED_SERVER", - "reference": "this is a reference", - "startDate": "2019-01-01T00:00:00+00:00", - "status": "ACTIVE", - "uncancellable": true - } - ] - }`) - }) - defer teardown() - - ctx := context.Background() - opts := ServicesListOptions{ - PaginationOptions: PaginationOptions{ - Limit: Int(1), - }, - } - response, err := ServicesApi{}.List(ctx, opts) - - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 11) - assert.Equal(response.Metadata.Offset, 1) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.Services), 1) - - service1 := response.Services[0] - assert.Equal(service1.BillingCycle, "1 MONTH") - assert.Equal(service1.Cancellable, false) - assert.Equal(service1.ContractId, "00000110") - assert.Equal(service1.ContractTerm, "1 YEAR") - assert.Equal(service1.ContractTermEndDate, "2020-01-31T00:00:00+00:00") - assert.Equal(service1.Currency, "EUR") - assert.Equal(service1.DeliveryDate, "2019-01-01T00:00:00+00:00") - assert.Equal(service1.DeliveryEstimate, "5 - 7 business days") - assert.Equal(service1.EndDate, "2020-01-31T00:00:00+00:00") - assert.Equal(service1.EquipmentId, "12345678") - assert.Equal(service1.Id, "10000000000010") - assert.Equal(service1.OrderDate, "2019-01-01T00:00:00+00:00") - assert.Equal(service1.PricePerFrequency.String(), "396.01") - assert.Equal(service1.ProductId, "DEDICATED_SERVER") - assert.Equal(service1.Reference, "this is a reference") - assert.Equal(service1.StartDate, "2019-01-01T00:00:00+00:00") - assert.Equal(service1.Status, "ACTIVE") - assert.Equal(service1.Uncancellable, true) -} - -func TestServicesListServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return ServicesApi{}.List(ctx, ServicesListOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "ACCESS_DENIED", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return ServicesApi{}.List(ctx, ServicesListOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "ACCESS_DENIED", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "SERVER_ERROR", "errorMessage": "The server encountered an unexpected condition that prevented it from fulfilling the request."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return ServicesApi{}.List(ctx, ServicesListOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "SERVER_ERROR", - Message: "The server encountered an unexpected condition that prevented it from fulfilling the request.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "TEMPORARILY_UNAVAILABLE", "errorMessage": "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return ServicesApi{}.List(ctx, ServicesListOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "TEMPORARILY_UNAVAILABLE", - Message: "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestServicesListCancellationReasons(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "cancellationReasons": [ - { - "reason": "I no longer need it", - "reasonCode": "CANCEL_NO_NEED" - }, - { - "reason": "I was using it for trial only", - "reasonCode": "CANCEL_TRIAL_ONLY" - }, - { - "reason": "I purchased another service at Leaseweb", - "reasonCode": "CANCEL_PURCHASED_OTHER" - } - ] - }`) - }) - defer teardown() - - ctx := context.Background() - response, err := ServicesApi{}.ListCancellationReasons(ctx) - - assert := assert.New(t) - assert.Nil(err) - Reason1 := response.CancellationReasons[0] - assert.Equal(Reason1.Reason, "I no longer need it") - assert.Equal(Reason1.ReasonCode, "CANCEL_NO_NEED") - Reason2 := response.CancellationReasons[1] - assert.Equal(Reason2.Reason, "I was using it for trial only") - assert.Equal(Reason2.ReasonCode, "CANCEL_TRIAL_ONLY") - Reason3 := response.CancellationReasons[2] - assert.Equal(Reason3.Reason, "I purchased another service at Leaseweb") - assert.Equal(Reason3.ReasonCode, "CANCEL_PURCHASED_OTHER") -} - -func TestServicesListCancellationReasonsServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return ServicesApi{}.ListCancellationReasons(ctx) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "ACCESS_DENIED", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return ServicesApi{}.ListCancellationReasons(ctx) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "ACCESS_DENIED", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "SERVER_ERROR", "errorMessage": "The server encountered an unexpected condition that prevented it from fulfilling the request."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return ServicesApi{}.ListCancellationReasons(ctx) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "SERVER_ERROR", - Message: "The server encountered an unexpected condition that prevented it from fulfilling the request.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "TEMPORARILY_UNAVAILABLE", "errorMessage": "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return ServicesApi{}.ListCancellationReasons(ctx) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "TEMPORARILY_UNAVAILABLE", - Message: "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestServicesGet(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "billingCycle": "1 MONTH", - "cancellable": false, - "contractId": "00000110", - "contractTerm": "1 YEAR", - "contractTermEndDate": "2020-01-31T00:00:00+00:00", - "currency": "EUR", - "deliveryDate": "2019-01-01T00:00:00+00:00", - "deliveryEstimate": "5 - 7 business days", - "endDate": "2020-01-31T00:00:00+00:00", - "equipmentId": "12345678", - "id": "10000000000010", - "orderDate": "2019-01-01T00:00:00+00:00", - "pricePerFrequency": 396.01, - "productId": "DEDICATED_SERVER", - "reference": "this is a reference", - "startDate": "2019-01-01T00:00:00+00:00", - "status": "ACTIVE", - "uncancellable": true - }`) - }) - defer teardown() - - ctx := context.Background() - Service, err := ServicesApi{}.Get(ctx, "12345") - - assert := assert.New(t) - assert.Nil(err) - - assert.Equal(Service.BillingCycle, "1 MONTH") - assert.Equal(Service.Cancellable, false) - assert.Equal(Service.ContractId, "00000110") - assert.Equal(Service.ContractTerm, "1 YEAR") - assert.Equal(Service.ContractTermEndDate, "2020-01-31T00:00:00+00:00") - assert.Equal(Service.Currency, "EUR") - assert.Equal(Service.DeliveryDate, "2019-01-01T00:00:00+00:00") - assert.Equal(Service.DeliveryEstimate, "5 - 7 business days") - assert.Equal(Service.EndDate, "2020-01-31T00:00:00+00:00") - assert.Equal(Service.EquipmentId, "12345678") - assert.Equal(Service.Id, "10000000000010") - assert.Equal(Service.OrderDate, "2019-01-01T00:00:00+00:00") - assert.Equal(Service.PricePerFrequency.String(), "396.01") - assert.Equal(Service.ProductId, "DEDICATED_SERVER") - assert.Equal(Service.Reference, "this is a reference") - assert.Equal(Service.StartDate, "2019-01-01T00:00:00+00:00") - assert.Equal(Service.Status, "ACTIVE") - assert.Equal(Service.Uncancellable, true) -} - -func TestServicesGetServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return ServicesApi{}.Get(ctx, "12345") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "ACCESS_DENIED", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return ServicesApi{}.Get(ctx, "12345") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "ACCESS_DENIED", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "SERVER_ERROR", "errorMessage": "The server encountered an unexpected condition that prevented it from fulfilling the request."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return ServicesApi{}.Get(ctx, "12345") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "SERVER_ERROR", - Message: "The server encountered an unexpected condition that prevented it from fulfilling the request.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "TEMPORARILY_UNAVAILABLE", "errorMessage": "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return ServicesApi{}.Get(ctx, "12345") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "TEMPORARILY_UNAVAILABLE", - Message: "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestServicesCancel(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusNoContent) - }) - defer teardown() - - ctx := context.Background() - err := ServicesApi{}.Cancel(ctx, "12345", "reason", "reason code") - - assert := assert.New(t) - assert.Nil(err) -} - -func TestServicesCancelServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, ServicesApi{}.Cancel(ctx, "12345", "reason", "reason code") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "ACCESS_DENIED", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, ServicesApi{}.Cancel(ctx, "12345", "reason", "reason code") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "ACCESS_DENIED", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "SERVER_ERROR", "errorMessage": "The server encountered an unexpected condition that prevented it from fulfilling the request."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, ServicesApi{}.Cancel(ctx, "12345", "reason", "reason code") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "SERVER_ERROR", - Message: "The server encountered an unexpected condition that prevented it from fulfilling the request.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "TEMPORARILY_UNAVAILABLE", "errorMessage": "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, ServicesApi{}.Cancel(ctx, "12345", "reason", "reason code") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "TEMPORARILY_UNAVAILABLE", - Message: "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestServicesUncancel(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusNoContent) - }) - defer teardown() - - ctx := context.Background() - err := ServicesApi{}.Uncancel(ctx, "12345") - - assert := assert.New(t) - assert.Nil(err) -} - -func TestServicesUncancelServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, ServicesApi{}.Uncancel(ctx, "12345") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "ACCESS_DENIED", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, ServicesApi{}.Uncancel(ctx, "12345") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "ACCESS_DENIED", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "SERVER_ERROR", "errorMessage": "The server encountered an unexpected condition that prevented it from fulfilling the request."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, ServicesApi{}.Uncancel(ctx, "12345") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "SERVER_ERROR", - Message: "The server encountered an unexpected condition that prevented it from fulfilling the request.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "TEMPORARILY_UNAVAILABLE", "errorMessage": "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, ServicesApi{}.Uncancel(ctx, "12345") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "TEMPORARILY_UNAVAILABLE", - Message: "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} diff --git a/shared_type.go b/shared_type.go deleted file mode 100644 index ccf796d..0000000 --- a/shared_type.go +++ /dev/null @@ -1,277 +0,0 @@ -package leaseweb - -import "encoding/json" - -type Credentials struct { - Credentials []Credential `json:"credentials"` - Metadata Metadata `json:"_metadata"` -} - -type Credential struct { - Type string `json:"type"` - Username string `json:"username"` - Password string `json:"password"` - Domain string `json:"domain"` -} - -type Ips struct { - Ips []Ip `json:"ips"` - Metadata Metadata `json:"_metadata"` -} - -type Ip struct { - FloatingIp bool `json:"floatingIp"` - Gateway string `json:"gateway"` - Ip string `json:"ip"` - MainIp bool `json:"mainIp"` - NetworkType string `json:"networkType"` - NullRouted bool `json:"nullRouted"` - ReverseLookup string `json:"reverseLookup"` - Version json.Number `json:"version"` - Type string `json:"type"` - PrefixLength json.Number `json:"prefixLength"` - Primary bool `json:"primary"` - UnnullingAllowed bool `json:"unnullingAllowed"` - EquipmentId string `json:"equipmentId"` - DDOS IpDdos `json:"ddos"` - AssignedContract IpAssignedContract `json:"assignedContract"` - Subnet IpSubnet `json:"subnet"` -} - -type IpDdos struct { - DetectionProfile string `json:"detectionProfile"` - ProtectionType string `json:"protectionType"` -} - -type IpSubnet struct { - Id string `json:"id"` - NetworkIp string `json:"networkIp"` - PrefixLength json.Number `json:"prefixLength"` - Gateway string `json:"gateway"` -} - -type IpAssignedContract struct { - Id string `json:"id"` -} - -type NetworkInterfaces struct { - Internal NetworkInterface `json:"internal"` - Public NetworkInterface `json:"public"` - RemoteManagement NetworkInterface `json:"remoteManagement"` -} - -type NetworkInterface struct { - Gateway string `json:"gateway"` - Ip string `json:"ip"` - Mac string `json:"mac"` - NullRouted bool `json:"nullRouted"` - LocationId string `json:"locationId"` - Ports []Port `json:"ports"` -} - -type NullRoutes struct { - NullRoutes []NullRoute `json:"nullroutes"` - Metadata Metadata `json:"_metadata"` -} - -type NullRoute struct { - Id string `json:"id"` - Ip string `json:"ip"` - NulledAt string `json:"nulledAt"` - NulledBy string `json:"nulledBy"` - NullLevel json.Number `json:"nullLevel"` - AutomatedUnnullingAt string `json:"automatedUnnullingAt"` - UnnulledAt string `json:"unnulledAt"` - UnnulledBy string `json:"unnulledBy"` - TicketId string `json:"ticketId"` - Comment string `json:"comment"` - EquipmentId string `json:"equipmentId"` - AssignedContract IpAssignedContract `json:"assignedContract"` -} - -type BandWidthMetrics struct { - Metric BandWidthMetric `json:"metrics"` - Metadata MetricMetadata `json:"_metadata"` -} - -type BandWidthMetric struct { - UpPublic BasicMetric `json:"UP_PUBLIC"` - DownPublic BasicMetric `json:"DOWN_PUBLIC"` -} - -type DataTrafficMetricsV1 struct { - Metric struct { - UpPublic BasicMetric `json:"UP_PUBLIC"` - DownPublic BasicMetric `json:"DOWN_PUBLIC"` - } `json:"metrics"` - Metadata MetricMetadata `json:"_metadata"` -} - -type DataTrafficMetricsV2 struct { - Metric struct { - UpPublic BasicMetric `json:"DATATRAFFIC_UP"` - DownPublic BasicMetric `json:"DATATRAFFIC_DOWN"` - } `json:"metrics"` - Metadata MetricMetadata `json:"_metadata"` -} - -type Metadata struct { - Limit int `json:"limit"` - Offset int `json:"offset"` - TotalCount int `json:"totalCount"` -} - -type TimestampValuePair struct { - Timestamp string `json:"timestamp"` - Value json.Number `json:"value"` -} - -type BasicMetric struct { - Unit string `json:"unit"` - Values []TimestampValuePair `json:"values"` -} - -type MetricMetadata struct { - From string `json:"from"` - To string `json:"to"` - Granularity string `json:"granularity"` - Aggregation string `json:"aggregation"` -} - -type NetworkTraffic struct { - Type string `json:"type"` - TrafficType string `json:"trafficType"` - DataTrafficUnit string `json:"datatrafficUnit"` - DataTrafficLimit json.Number `json:"datatrafficLimit"` - ConnectivityType string `json:"connectivityType"` -} - -type FeatureAvailability struct { - Automation bool `json:"automation"` - IpmiReboot bool `json:"ipmiReboot"` - PowerCycle bool `json:"powerCycle"` - PrivateNetwork bool `json:"privateNetwork"` - RemoteManagement bool `json:"remoteManagement"` -} - -type Location struct { - Rack string `json:"rack"` - Site string `json:"site"` - Suite string `json:"suite"` - Unit string `json:"unit"` -} - -type Port struct { - Name string `json:"name"` - Port string `json:"port"` -} - -type Contract struct { - BillingCycle json.Number `json:"billingCycle"` - BillingFrequency string `json:"billingFrequency"` - ContractTerm json.Number `json:"contractTerm"` - ContractType string `json:"ContractType"` - Currency string `json:"currency"` - EndsAt string `json:"endsAt"` - StartsAt string `json:"startsAt"` - CustomerId string `json:"customerId"` - DeliveryStatus string `json:"deliveryStatus"` - Id string `json:"id"` - Reference string `json:"reference"` - SalesOrgId string `json:"salesOrgId"` - NetworkTraffic NetworkTraffic `json:"networkTraffic"` - PricePerFrequency json.Number `json:"pricePerFrequency"` - PrivateNetworks []PrivateNetwork `json:"privateNetworks"` - Sla string `json:"sla"` - Status string `json:"status"` - SoftwareLicenses []SoftwareLicense `json:"softwareLicenses"` - AggregationPackId string `json:"aggregationPackId"` - Subnets []string `json:"subnets"` -} - -type PrivateNetwork struct { - Id string `json:"id"` - LinkSpeed json.Number `json:"linkSpeed"` - Status string `json:"status"` - Subnet string `json:"subnet"` - VLanId string `json:"vlanId"` - EquipmentCount json.Number `json:"equipmentCount"` - Name string `json:"name"` - CreatedAt string `json:"createdAt"` - UpdatedAt string `json:"updatedAt"` - Servers []string `json:"servers"` -} - -type SoftwareLicense struct { - Currency string `json:"currency"` - Name string `json:"name"` - Price json.Number `json:"price"` -} - -type DdosNotificationSetting struct { - Nulling string `json:"nulling"` - Scrubbing string `json:"scrubbing"` -} - -type BandWidthNotificationSettings struct { - Settings []NotificationSetting `json:"bandwidthNotificationSettings"` - Metadata Metadata `json:"_metadata"` -} - -type DataTrafficNotificationSettings struct { - Settings []NotificationSetting `json:"datatrafficNotificationSettings"` - Metadata Metadata `json:"_metadata"` -} - -type NotificationSetting struct { - Actions []NotificationSettingAction `json:"actions"` - Frequency string `json:"frequency"` - Id string `json:"id"` - LastCheckedAt string `json:"lastCheckedAt"` - Threshold json.Number `json:"threshold"` - ThresholdExceededAt string `json:"thresholdExceededAt"` - Unit string `json:"unit"` -} - -type NotificationSettingAction struct { - LastTriggeredAt string `json:"lastTriggeredAt"` - Type string `json:"type"` -} - -type Hardware struct { - Cpu struct { - Cores json.Number `json:"cores"` - } `json:"cpu"` - - Memory struct { - Unit string `json:"unit"` - Amount json.Number `json:"amount"` - } `json:"memory"` - - Storage struct { - Unit string `json:"unit"` - Amount json.Number `json:"amount"` - } `json:"storage"` -} - -type PowerStatus struct { - Ipmi struct { - Status string `json:"status"` - } `json:"ipmi"` - - Pdu struct { - Status string `json:"status"` - } `json:"pdu"` -} - -type PaginationOptions struct { - Limit *int `param:"limit"` - Offset *int `param:"offset"` -} - -type MetricsOptions struct { - Granularity *string `param:"granularity"` - Aggregation *string `param:"aggregation"` - From *string `param:"from"` - To *string `param:"to"` -} diff --git a/virtual_server.go b/virtual_server.go deleted file mode 100644 index 00f2997..0000000 --- a/virtual_server.go +++ /dev/null @@ -1,172 +0,0 @@ -package leaseweb - -import ( - "context" - "net/http" - - "github.com/LeaseWeb/leaseweb-go-sdk/options" -) - -const VIRTUAL_SERVER_API_VERSION = "v2" - -type VirtualServerApi struct{} - -type VirtualServers struct { - VirtualServers []VirtualServer `json:"virtualServers"` - Metadata Metadata `json:"_metadata"` -} - -type VirtualServer struct { - Id string `json:"id"` - Reference string `json:"reference"` - CustomerId string `json:"customerId"` - DataCenter string `json:"dataCenter"` - CloudServerId string `json:"cloudServerId"` - State string `json:"state"` - FirewallState string `json:"firewallState"` - Template string `json:"template"` - ServiceOffering string `json:"serviceOffering"` - Sla string `json:"sla"` - Iso VirtualServerIso `json:"iso"` - Contract Contract `json:"contract"` - Ips []Ip `json:"ips"` - Hardware Hardware `json:"hardware"` -} - -type VirtualServerIso struct { - Id string `json:"id"` - Name string `json:"name"` - DisplayName string `json:"displayName"` -} - -type VirtualServerResult struct { - Id string `json:"id"` - Name string `json:"name"` - Status string `json:"status"` - CreatedAt string `json:"createdAt"` -} - -type VirtualServerTemplates struct { - Templates []VirtualServerTemplate `json:"templates"` - Metadata Metadata `json:"_metadata"` -} - -type VirtualServerTemplate struct { - Id string `json:"id"` - Name string `json:"name"` -} - -func (vsa VirtualServerApi) getPath(endpoint string) string { - return "/cloud/" + VIRTUAL_SERVER_API_VERSION + endpoint -} - -func (vsa VirtualServerApi) List(ctx context.Context, opts PaginationOptions) (*VirtualServers, error) { - path := vsa.getPath("/virtualServers") - query := options.Encode(opts) - result := &VirtualServers{} - if err := doRequest(ctx, http.MethodGet, path, query, result); err != nil { - return nil, err - } - return result, nil -} - -func (vsa VirtualServerApi) Get(ctx context.Context, virtualServerId string) (*VirtualServer, error) { - path := vsa.getPath("/virtualServers/" + virtualServerId) - result := &VirtualServer{} - if err := doRequest(ctx, http.MethodGet, path, "", result); err != nil { - return nil, err - } - return result, nil -} - -func (vsa VirtualServerApi) Update(ctx context.Context, virtualServerId, reference string) (*VirtualServer, error) { - payload := map[string]string{"reference": reference} - path := vsa.getPath("/virtualServers/" + virtualServerId) - result := &VirtualServer{} - if err := doRequest(ctx, http.MethodPut, path, "", result, payload); err != nil { - return nil, err - } - return result, nil -} - -func (vsa VirtualServerApi) PowerOn(ctx context.Context, virtualServerId string) (*VirtualServerResult, error) { - path := vsa.getPath("/virtualServers/" + virtualServerId + "/powerOn") - result := &VirtualServerResult{} - if err := doRequest(ctx, http.MethodPost, path, "", result); err != nil { - return nil, err - } - return result, nil -} - -func (vsa VirtualServerApi) PowerOff(ctx context.Context, virtualServerId string) (*VirtualServerResult, error) { - path := vsa.getPath("/virtualServers/" + virtualServerId + "/powerOff") - result := &VirtualServerResult{} - if err := doRequest(ctx, http.MethodPost, path, "", result); err != nil { - return nil, err - } - return result, nil -} - -func (vsa VirtualServerApi) Reboot(ctx context.Context, virtualServerId string) (*VirtualServerResult, error) { - path := vsa.getPath("/virtualServers/" + virtualServerId + "/reboot") - result := &VirtualServerResult{} - if err := doRequest(ctx, http.MethodPost, path, "", result); err != nil { - return nil, err - } - return result, nil -} - -func (vsa VirtualServerApi) Reinstall(ctx context.Context, virtualServerId, operatingSystemId string) (*VirtualServerResult, error) { - payload := map[string]string{"operatingSystemId": operatingSystemId} - path := vsa.getPath("/virtualServers/" + virtualServerId + "/reinstall") - result := &VirtualServerResult{} - if err := doRequest(ctx, http.MethodPost, path, "", result, payload); err != nil { - return nil, err - } - return result, nil -} - -func (vsa VirtualServerApi) UpdateCredential(ctx context.Context, virtualServerId, username, credentialType, password string) error { - payload := map[string]string{"username": username, "type": credentialType, "password": password} - path := vsa.getPath("/virtualServers/" + virtualServerId + "/credentials") - return doRequest(ctx, http.MethodPut, path, "", nil, payload) -} - -func (vsa VirtualServerApi) ListCredentials(ctx context.Context, virtualServerId, credentialType string, opts PaginationOptions) (*Credentials, error) { - path := vsa.getPath("/virtualServers/" + virtualServerId + "/credentials/" + credentialType) - query := options.Encode(opts) - result := &Credentials{} - if err := doRequest(ctx, http.MethodGet, path, query, result); err != nil { - return nil, err - } - return result, nil -} - -func (vsa VirtualServerApi) GetCredential(ctx context.Context, virtualServerId, username, credentialType string) (*Credential, error) { - path := vsa.getPath("/virtualServers/" + virtualServerId + "/credentials/" + credentialType + "/" + username) - result := &Credential{} - if err := doRequest(ctx, http.MethodGet, path, "", result); err != nil { - return nil, err - } - return result, nil -} - -func (vsa VirtualServerApi) GetDataTrafficMetrics(ctx context.Context, virtualServerId string, opts MetricsOptions) (*DataTrafficMetricsV2, error) { - path := vsa.getPath("/virtualServers/" + virtualServerId + "/metrics/datatraffic") - query := options.Encode(opts) - result := &DataTrafficMetricsV2{} - if err := doRequest(ctx, http.MethodGet, path, query, result); err != nil { - return nil, err - } - return result, nil -} - -func (vsa VirtualServerApi) ListTemplates(ctx context.Context, virtualServerId string, opts PaginationOptions) (*VirtualServerTemplates, error) { - path := vsa.getPath("/virtualServers/" + virtualServerId + "/templates") - result := &VirtualServerTemplates{} - query := options.Encode(opts) - if err := doRequest(ctx, http.MethodGet, path, query, result); err != nil { - return nil, err - } - return result, nil -} diff --git a/virtual_server_test.go b/virtual_server_test.go deleted file mode 100644 index ad24161..0000000 --- a/virtual_server_test.go +++ /dev/null @@ -1,1914 +0,0 @@ -package leaseweb - -import ( - "context" - "fmt" - "net/http" - "testing" - - "github.com/stretchr/testify/assert" -) - -func TestVirtualServerList(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "virtualServers": [ - { - "id": "222903", - "reference": "Web server", - "customerId": "1301178860", - "dataCenter": "AMS-01", - "cloudServerId": null, - "state": "STOPPED", - "firewallState": "DISABLED", - "template": "Ubuntu 14.04 64 40 20140707T1340", - "serviceOffering": "S", - "sla": "Bronze", - "contract": { - "id": "30000778", - "startsAt": "2016-02-01T00:00:00+0200", - "endsAt": "2017-01-31T00:00:00+0200", - "billingCycle": 12, - "billingFrequency": "MONTH", - "pricePerFrequency": 4.7, - "currency": "EUR" - }, - "hardware": { - "cpu": { - "cores": 1 - }, - "memory": { - "unit": "MB", - "amount": 1024 - }, - "storage": { - "unit": "GB", - "amount": 40 - } - }, - "iso": null, - "ips": [ - { - "ip": "10.11.116.130", - "version": 4, - "type": "PUBLIC" - } - ] - }, - { - "id": "301708", - "reference": null, - "customerId": "1301178860", - "dataCenter": "AMS-01", - "cloudServerId": null, - "state": "STOPPED", - "firewallState": "ENABLED", - "template": "CentOS 7.0 64 60 20140711T1039", - "serviceOffering": "M", - "sla": "Bronze", - "contract": { - "id": "30000779", - "startsAt": "2016-02-01T00:00:00+0200", - "endsAt": "2017-01-31T00:00:00+0200", - "billingCycle": 12, - "billingFrequency": "MONTH", - "pricePerFrequency": 4.7, - "currency": "EUR" - }, - "hardware": { - "cpu": { - "cores": 2 - }, - "memory": { - "unit": "MB", - "amount": 2048 - }, - "storage": { - "unit": "GB", - "amount": 60 - } - }, - "iso": { - "id": "9eadbe14-69be-4dee-8f56-5ebb23bb3c33", - "name": "Knoppix", - "displayName": "Knoppix" - }, - "ips": [ - { - "ip": "10.11.116.132", - "version": 4, - "type": "PUBLIC" - } - ] - } - ], - "_metadata": { - "totalCount": 2, - "offset": 0, - "limit": 10 - } - }`) - }) - defer teardown() - - ctx := context.Background() - response, err := VirtualServerApi{}.List(ctx, PaginationOptions{}) - - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 2) - assert.Equal(response.Metadata.Offset, 0) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.VirtualServers), 2) - - virtualServer1 := response.VirtualServers[0] - assert.Empty(virtualServer1.CloudServerId) - assert.Equal(virtualServer1.CustomerId, "1301178860") - assert.Equal(virtualServer1.DataCenter, "AMS-01") - assert.Equal(virtualServer1.FirewallState, "DISABLED") - assert.Equal(virtualServer1.Id, "222903") - assert.Empty(virtualServer1.Iso) - assert.Equal(virtualServer1.Ips[0].Ip, "10.11.116.130") - assert.Equal(virtualServer1.Ips[0].Version.String(), "4") - assert.Equal(virtualServer1.Ips[0].Type, "PUBLIC") - assert.Equal(virtualServer1.Contract.BillingCycle.String(), "12") - assert.Equal(virtualServer1.Contract.BillingFrequency, "MONTH") - assert.Equal(virtualServer1.Contract.Currency, "EUR") - assert.Equal(virtualServer1.Contract.EndsAt, "2017-01-31T00:00:00+0200") - assert.Equal(virtualServer1.Contract.Id, "30000778") - assert.Equal(virtualServer1.Contract.PricePerFrequency.String(), "4.7") - assert.Equal(virtualServer1.Contract.StartsAt, "2016-02-01T00:00:00+0200") - assert.Equal(virtualServer1.Hardware.Cpu.Cores.String(), "1") - assert.Equal(virtualServer1.Hardware.Memory.Amount.String(), "1024") - assert.Equal(virtualServer1.Hardware.Memory.Unit, "MB") - assert.Equal(virtualServer1.Hardware.Storage.Amount.String(), "40") - assert.Equal(virtualServer1.Hardware.Storage.Unit, "GB") - assert.Equal(virtualServer1.Reference, "Web server") - assert.Equal(virtualServer1.ServiceOffering, "S") - assert.Equal(virtualServer1.Sla, "Bronze") - assert.Equal(virtualServer1.State, "STOPPED") - assert.Equal(virtualServer1.Template, "Ubuntu 14.04 64 40 20140707T1340") - - virtualServer2 := response.VirtualServers[1] - assert.Empty(virtualServer2.CloudServerId) - assert.Equal(virtualServer2.CustomerId, "1301178860") - assert.Equal(virtualServer2.DataCenter, "AMS-01") - assert.Equal(virtualServer2.FirewallState, "ENABLED") - assert.Equal(virtualServer2.Id, "301708") - assert.Empty(virtualServer2.Reference) - assert.Equal(virtualServer2.ServiceOffering, "M") - assert.Equal(virtualServer2.Sla, "Bronze") - assert.Equal(virtualServer2.State, "STOPPED") - assert.Equal(virtualServer2.Template, "CentOS 7.0 64 60 20140711T1039") - assert.Equal(virtualServer2.Iso.Id, "9eadbe14-69be-4dee-8f56-5ebb23bb3c33") - assert.Equal(virtualServer2.Iso.Name, "Knoppix") - assert.Equal(virtualServer2.Iso.DisplayName, "Knoppix") - assert.Equal(virtualServer2.Ips[0].Ip, "10.11.116.132") - assert.Equal(virtualServer2.Ips[0].Version.String(), "4") - assert.Equal(virtualServer2.Ips[0].Type, "PUBLIC") - assert.Equal(virtualServer2.Contract.BillingCycle.String(), "12") - assert.Equal(virtualServer2.Contract.BillingFrequency, "MONTH") - assert.Equal(virtualServer2.Contract.Currency, "EUR") - assert.Equal(virtualServer2.Contract.EndsAt, "2017-01-31T00:00:00+0200") - assert.Equal(virtualServer2.Contract.Id, "30000779") - assert.Equal(virtualServer2.Contract.PricePerFrequency.String(), "4.7") - assert.Equal(virtualServer2.Contract.StartsAt, "2016-02-01T00:00:00+0200") - assert.Equal(virtualServer2.Hardware.Cpu.Cores.String(), "2") - assert.Equal(virtualServer2.Hardware.Memory.Amount.String(), "2048") - assert.Equal(virtualServer2.Hardware.Memory.Unit, "MB") - assert.Equal(virtualServer2.Hardware.Storage.Amount.String(), "60") - assert.Equal(virtualServer2.Hardware.Storage.Unit, "GB") -} - -func TestVirtualServerListPaginate(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "virtualServers": [ - { - "id": "222903", - "reference": "Web server", - "customerId": "1301178860", - "dataCenter": "AMS-01", - "cloudServerId": null, - "state": "STOPPED", - "firewallState": "DISABLED", - "template": "Ubuntu 14.04 64 40 20140707T1340", - "serviceOffering": "S", - "sla": "Bronze", - "contract": { - "id": "30000778", - "startsAt": "2016-02-01T00:00:00+0200", - "endsAt": "2017-01-31T00:00:00+0200", - "billingCycle": 12, - "billingFrequency": "MONTH", - "pricePerFrequency": 4.7, - "currency": "EUR" - }, - "hardware": { - "cpu": { - "cores": 1 - }, - "memory": { - "unit": "MB", - "amount": 1024 - }, - "storage": { - "unit": "GB", - "amount": 40 - } - }, - "iso": null, - "ips": [ - { - "ip": "10.11.116.130", - "version": 4, - "type": "PUBLIC" - } - ] - } - ], - "_metadata": { - "totalCount": 11, - "offset": 1, - "limit": 10 - } - }`) - }) - defer teardown() - - ctx := context.Background() - opts := PaginationOptions{ - Limit: Int(1), - } - response, err := VirtualServerApi{}.List(ctx, opts) - - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 11) - assert.Equal(response.Metadata.Offset, 1) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.VirtualServers), 1) - - virtualServer1 := response.VirtualServers[0] - assert.Empty(virtualServer1.CloudServerId) - assert.Equal(virtualServer1.CustomerId, "1301178860") - assert.Equal(virtualServer1.DataCenter, "AMS-01") - assert.Equal(virtualServer1.FirewallState, "DISABLED") - assert.Equal(virtualServer1.Id, "222903") - assert.Empty(virtualServer1.Iso) - assert.Equal(virtualServer1.Ips[0].Ip, "10.11.116.130") - assert.Equal(virtualServer1.Ips[0].Version.String(), "4") - assert.Equal(virtualServer1.Ips[0].Type, "PUBLIC") - assert.Equal(virtualServer1.Contract.BillingCycle.String(), "12") - assert.Equal(virtualServer1.Contract.BillingFrequency, "MONTH") - assert.Equal(virtualServer1.Contract.Currency, "EUR") - assert.Equal(virtualServer1.Contract.EndsAt, "2017-01-31T00:00:00+0200") - assert.Equal(virtualServer1.Contract.Id, "30000778") - assert.Equal(virtualServer1.Contract.PricePerFrequency.String(), "4.7") - assert.Equal(virtualServer1.Contract.StartsAt, "2016-02-01T00:00:00+0200") - assert.Equal(virtualServer1.Hardware.Cpu.Cores.String(), "1") - assert.Equal(virtualServer1.Hardware.Memory.Amount.String(), "1024") - assert.Equal(virtualServer1.Hardware.Memory.Unit, "MB") - assert.Equal(virtualServer1.Hardware.Storage.Amount.String(), "40") - assert.Equal(virtualServer1.Hardware.Storage.Unit, "GB") - assert.Equal(virtualServer1.Reference, "Web server") - assert.Equal(virtualServer1.ServiceOffering, "S") - assert.Equal(virtualServer1.Sla, "Bronze") - assert.Equal(virtualServer1.State, "STOPPED") - assert.Equal(virtualServer1.Template, "Ubuntu 14.04 64 40 20140707T1340") -} - -func TestVirtualServerListServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return VirtualServerApi{}.List(ctx, PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "ACCESS_DENIED", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return VirtualServerApi{}.List(ctx, PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "ACCESS_DENIED", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "SERVER_ERROR", "errorMessage": "The server encountered an unexpected condition that prevented it from fulfilling the request."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return VirtualServerApi{}.List(ctx, PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "SERVER_ERROR", - Message: "The server encountered an unexpected condition that prevented it from fulfilling the request.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "TEMPORARILY_UNAVAILABLE", "errorMessage": "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return VirtualServerApi{}.List(ctx, PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "TEMPORARILY_UNAVAILABLE", - Message: "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestVirtualServerGet(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "id": "222903", - "reference": "Web server", - "customerId": "1301178860", - "dataCenter": "AMS-01", - "cloudServerId": null, - "state": "STOPPED", - "firewallState": "DISABLED", - "template": "Ubuntu 14.04 64 40 20140707T1340", - "serviceOffering": "S", - "sla": "Bronze", - "contract": { - "id": "30000778", - "startsAt": "2016-02-01T00:00:00+0200", - "endsAt": "2017-01-31T00:00:00+0200", - "billingCycle": 12, - "billingFrequency": "MONTH", - "pricePerFrequency": 4.7, - "currency": "EUR" - }, - "hardware": { - "cpu": { - "cores": 1 - }, - "memory": { - "unit": "MB", - "amount": 1024 - }, - "storage": { - "unit": "GB", - "amount": 40 - } - }, - "iso": null, - "ips": [ - { - "ip": "10.11.116.130", - "version": 4, - "type": "PUBLIC" - } - ] - }`) - }) - defer teardown() - - ctx := context.Background() - virtualServer, err := VirtualServerApi{}.Get(ctx, "123456") - - assert := assert.New(t) - assert.Nil(err) - assert.Empty(virtualServer.CloudServerId) - assert.Equal(virtualServer.CustomerId, "1301178860") - assert.Equal(virtualServer.DataCenter, "AMS-01") - assert.Equal(virtualServer.FirewallState, "DISABLED") - assert.Equal(virtualServer.Id, "222903") - assert.Empty(virtualServer.Iso) - assert.Equal(virtualServer.Ips[0].Ip, "10.11.116.130") - assert.Equal(virtualServer.Ips[0].Version.String(), "4") - assert.Equal(virtualServer.Ips[0].Type, "PUBLIC") - assert.Equal(virtualServer.Contract.BillingCycle.String(), "12") - assert.Equal(virtualServer.Contract.BillingFrequency, "MONTH") - assert.Equal(virtualServer.Contract.Currency, "EUR") - assert.Equal(virtualServer.Contract.EndsAt, "2017-01-31T00:00:00+0200") - assert.Equal(virtualServer.Contract.Id, "30000778") - assert.Equal(virtualServer.Contract.PricePerFrequency.String(), "4.7") - assert.Equal(virtualServer.Contract.StartsAt, "2016-02-01T00:00:00+0200") - assert.Equal(virtualServer.Hardware.Cpu.Cores.String(), "1") - assert.Equal(virtualServer.Hardware.Memory.Amount.String(), "1024") - assert.Equal(virtualServer.Hardware.Memory.Unit, "MB") - assert.Equal(virtualServer.Hardware.Storage.Amount.String(), "40") - assert.Equal(virtualServer.Hardware.Storage.Unit, "GB") - assert.Equal(virtualServer.Reference, "Web server") - assert.Equal(virtualServer.ServiceOffering, "S") - assert.Equal(virtualServer.Sla, "Bronze") - assert.Equal(virtualServer.State, "STOPPED") - assert.Equal(virtualServer.Template, "Ubuntu 14.04 64 40 20140707T1340") -} - -func TestVirtualServerGetServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return VirtualServerApi{}.Get(ctx, "123456") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "ACCESS_DENIED", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return VirtualServerApi{}.Get(ctx, "123456") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "ACCESS_DENIED", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "404", "errorMessage": "Resource '218030' was not found"}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return VirtualServerApi{}.Get(ctx, "123456") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "404", - Message: "Resource '218030' was not found", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "SERVER_ERROR", "errorMessage": "The server encountered an unexpected condition that prevented it from fulfilling the request."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return VirtualServerApi{}.Get(ctx, "123456") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "SERVER_ERROR", - Message: "The server encountered an unexpected condition that prevented it from fulfilling the request.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "TEMPORARILY_UNAVAILABLE", "errorMessage": "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return VirtualServerApi{}.Get(ctx, "123456") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "TEMPORARILY_UNAVAILABLE", - Message: "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestVirtualServerUpdate(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "id": "222903", - "reference": "Web server", - "customerId": "1301178860", - "dataCenter": "AMS-01", - "cloudServerId": null, - "state": "STOPPED", - "firewallState": "DISABLED", - "template": "Ubuntu 14.04 64 40 20140707T1340", - "serviceOffering": "S", - "sla": "Bronze", - "contract": { - "id": "30000778", - "startsAt": "2016-02-01T00:00:00+0200", - "endsAt": "2017-01-31T00:00:00+0200", - "billingCycle": 12, - "billingFrequency": "MONTH", - "pricePerFrequency": 4.7, - "currency": "EUR" - }, - "hardware": { - "cpu": { - "cores": 1 - }, - "memory": { - "unit": "MB", - "amount": 1024 - }, - "storage": { - "unit": "GB", - "amount": 40 - } - }, - "iso": null, - "ips": [ - { - "ip": "10.11.116.130", - "version": 4, - "type": "PUBLIC" - } - ] - }`) - }) - defer teardown() - - ctx := context.Background() - virtualServer, err := VirtualServerApi{}.Update(ctx, "123456", "Web server") - - assert := assert.New(t) - assert.Nil(err) - assert.Empty(virtualServer.CloudServerId) - assert.Equal(virtualServer.CustomerId, "1301178860") - assert.Equal(virtualServer.DataCenter, "AMS-01") - assert.Equal(virtualServer.FirewallState, "DISABLED") - assert.Equal(virtualServer.Id, "222903") - assert.Empty(virtualServer.Iso) - assert.Equal(virtualServer.Ips[0].Ip, "10.11.116.130") - assert.Equal(virtualServer.Ips[0].Version.String(), "4") - assert.Equal(virtualServer.Ips[0].Type, "PUBLIC") - assert.Equal(virtualServer.Contract.BillingCycle.String(), "12") - assert.Equal(virtualServer.Contract.BillingFrequency, "MONTH") - assert.Equal(virtualServer.Contract.Currency, "EUR") - assert.Equal(virtualServer.Contract.EndsAt, "2017-01-31T00:00:00+0200") - assert.Equal(virtualServer.Contract.Id, "30000778") - assert.Equal(virtualServer.Contract.PricePerFrequency.String(), "4.7") - assert.Equal(virtualServer.Contract.StartsAt, "2016-02-01T00:00:00+0200") - assert.Equal(virtualServer.Hardware.Cpu.Cores.String(), "1") - assert.Equal(virtualServer.Hardware.Memory.Amount.String(), "1024") - assert.Equal(virtualServer.Hardware.Memory.Unit, "MB") - assert.Equal(virtualServer.Hardware.Storage.Amount.String(), "40") - assert.Equal(virtualServer.Hardware.Storage.Unit, "GB") - assert.Equal(virtualServer.Reference, "Web server") - assert.Equal(virtualServer.ServiceOffering, "S") - assert.Equal(virtualServer.Sla, "Bronze") - assert.Equal(virtualServer.State, "STOPPED") - assert.Equal(virtualServer.Template, "Ubuntu 14.04 64 40 20140707T1340") -} - -func TestVirtualServerUpdateServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return VirtualServerApi{}.Update(ctx, "123456", "Web server") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "ACCESS_DENIED", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return VirtualServerApi{}.Update(ctx, "123456", "Web server") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "ACCESS_DENIED", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "404", "errorMessage": "Resource '218030' was not found"}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return VirtualServerApi{}.Update(ctx, "123456", "Web server") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "404", - Message: "Resource '218030' was not found", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "SERVER_ERROR", "errorMessage": "The server encountered an unexpected condition that prevented it from fulfilling the request."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return VirtualServerApi{}.Update(ctx, "123456", "Web server") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "SERVER_ERROR", - Message: "The server encountered an unexpected condition that prevented it from fulfilling the request.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "TEMPORARILY_UNAVAILABLE", "errorMessage": "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return VirtualServerApi{}.Update(ctx, "123456", "Web server") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "TEMPORARILY_UNAVAILABLE", - Message: "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestVirtualServerPowerOff(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "id": "cs01.237daad0-2aed-4260-b0e4-488d9cd55607", - "name": "virtualServers.powerOff", - "status": "PENDING", - "createdAt": "2016-12-31T01:00:59+00:00" - }`) - }) - defer teardown() - - ctx := context.Background() - resp, err := VirtualServerApi{}.PowerOff(ctx, "123456") - - assert := assert.New(t) - assert.Nil(err) - assert.Equal(resp.Id, "cs01.237daad0-2aed-4260-b0e4-488d9cd55607") - assert.Equal(resp.Name, "virtualServers.powerOff") - assert.Equal(resp.Status, "PENDING") - assert.Equal(resp.CreatedAt, "2016-12-31T01:00:59+00:00") -} - -func TestVirtualServerPowerOffServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return VirtualServerApi{}.PowerOff(ctx, "123456") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "ACCESS_DENIED", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return VirtualServerApi{}.PowerOff(ctx, "123456") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "ACCESS_DENIED", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "404", "errorMessage": "Resource '218030' was not found"}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return VirtualServerApi{}.PowerOff(ctx, "123456") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "404", - Message: "Resource '218030' was not found", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "SERVER_ERROR", "errorMessage": "The server encountered an unexpected condition that prevented it from fulfilling the request."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return VirtualServerApi{}.PowerOff(ctx, "123456") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "SERVER_ERROR", - Message: "The server encountered an unexpected condition that prevented it from fulfilling the request.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "TEMPORARILY_UNAVAILABLE", "errorMessage": "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return VirtualServerApi{}.PowerOff(ctx, "123456") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "TEMPORARILY_UNAVAILABLE", - Message: "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestVirtualServerPowerOn(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "id": "cs01.237daad0-2aed-4260-b0e4-488d9cd55607", - "name": "virtualServers.powerOn", - "status": "PENDING", - "createdAt": "2016-12-31T01:00:59+00:00" - }`) - }) - defer teardown() - - ctx := context.Background() - resp, err := VirtualServerApi{}.PowerOn(ctx, "123456") - - assert := assert.New(t) - assert.Nil(err) - assert.Equal(resp.Id, "cs01.237daad0-2aed-4260-b0e4-488d9cd55607") - assert.Equal(resp.Name, "virtualServers.powerOn") - assert.Equal(resp.Status, "PENDING") - assert.Equal(resp.CreatedAt, "2016-12-31T01:00:59+00:00") -} - -func TestVirtualServerPowerOnServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return VirtualServerApi{}.PowerOn(ctx, "123456") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "ACCESS_DENIED", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return VirtualServerApi{}.PowerOn(ctx, "123456") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "ACCESS_DENIED", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "404", "errorMessage": "Resource '218030' was not found"}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return VirtualServerApi{}.PowerOn(ctx, "123456") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "404", - Message: "Resource '218030' was not found", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "SERVER_ERROR", "errorMessage": "The server encountered an unexpected condition that prevented it from fulfilling the request."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return VirtualServerApi{}.PowerOn(ctx, "123456") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "SERVER_ERROR", - Message: "The server encountered an unexpected condition that prevented it from fulfilling the request.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "TEMPORARILY_UNAVAILABLE", "errorMessage": "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return VirtualServerApi{}.PowerOn(ctx, "123456") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "TEMPORARILY_UNAVAILABLE", - Message: "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestVirtualServerReboot(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "id": "cs01.237daad0-2aed-4260-b0e4-488d9cd55607", - "name": "virtualServers.reboot", - "status": "PENDING", - "createdAt": "2016-12-31T01:00:59+00:00" - }`) - }) - defer teardown() - - ctx := context.Background() - resp, err := VirtualServerApi{}.Reboot(ctx, "123456") - - assert := assert.New(t) - assert.Nil(err) - assert.Equal(resp.Id, "cs01.237daad0-2aed-4260-b0e4-488d9cd55607") - assert.Equal(resp.Name, "virtualServers.reboot") - assert.Equal(resp.Status, "PENDING") - assert.Equal(resp.CreatedAt, "2016-12-31T01:00:59+00:00") -} - -func TestVirtualServerRebootServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return VirtualServerApi{}.Reboot(ctx, "123456") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "ACCESS_DENIED", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return VirtualServerApi{}.Reboot(ctx, "123456") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "ACCESS_DENIED", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "404", "errorMessage": "Resource '218030' was not found"}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return VirtualServerApi{}.Reboot(ctx, "123456") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "404", - Message: "Resource '218030' was not found", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "SERVER_ERROR", "errorMessage": "The server encountered an unexpected condition that prevented it from fulfilling the request."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return VirtualServerApi{}.Reboot(ctx, "123456") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "SERVER_ERROR", - Message: "The server encountered an unexpected condition that prevented it from fulfilling the request.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "TEMPORARILY_UNAVAILABLE", "errorMessage": "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return VirtualServerApi{}.Reboot(ctx, "123456") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "TEMPORARILY_UNAVAILABLE", - Message: "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestVirtualServerReinstall(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "id": "cs01.237daad0-2aed-4260-b0e4-488d9cd55607", - "name": "virtualServers.reinstall", - "status": "PENDING", - "createdAt": "2016-12-31T01:00:59+00:00" - }`) - }) - defer teardown() - - ctx := context.Background() - resp, err := VirtualServerApi{}.Reinstall(ctx, "123456", "CENTOS_7_64_PLESK") - - assert := assert.New(t) - assert.Nil(err) - assert.Equal(resp.Id, "cs01.237daad0-2aed-4260-b0e4-488d9cd55607") - assert.Equal(resp.Name, "virtualServers.reinstall") - assert.Equal(resp.Status, "PENDING") - assert.Equal(resp.CreatedAt, "2016-12-31T01:00:59+00:00") -} - -func TestVirtualServerReinstallServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return VirtualServerApi{}.Reinstall(ctx, "123456", "CENTOS_7_64_PLESK") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "ACCESS_DENIED", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return VirtualServerApi{}.Reinstall(ctx, "123456", "CENTOS_7_64_PLESK") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "ACCESS_DENIED", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "404", "errorMessage": "Resource '218030' was not found"}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return VirtualServerApi{}.Reinstall(ctx, "123456", "CENTOS_7_64_PLESK") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "404", - Message: "Resource '218030' was not found", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "SERVER_ERROR", "errorMessage": "The server encountered an unexpected condition that prevented it from fulfilling the request."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return VirtualServerApi{}.Reinstall(ctx, "123456", "CENTOS_7_64_PLESK") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "SERVER_ERROR", - Message: "The server encountered an unexpected condition that prevented it from fulfilling the request.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPost, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "TEMPORARILY_UNAVAILABLE", "errorMessage": "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return VirtualServerApi{}.Reinstall(ctx, "123456", "CENTOS_7_64_PLESK") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "TEMPORARILY_UNAVAILABLE", - Message: "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestVirtualServerUpdateCredential(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "password": "new password", - "type": "OPERATING_SYSTEM", - "username": "admin" - }`) - }) - defer teardown() - - ctx := context.Background() - err := VirtualServerApi{}.UpdateCredential(ctx, "12345", "OPERATING_SYSTEM", "admin", "new password") - assert := assert.New(t) - assert.Nil(err) -} - -func TestVirtualServerUpdateCredentialServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, VirtualServerApi{}.UpdateCredential(ctx, "12345", "OPERATING_SYSTEM", "admin", "new password") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "ACCESS_DENIED", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, VirtualServerApi{}.UpdateCredential(ctx, "12345", "OPERATING_SYSTEM", "admin", "new password") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "ACCESS_DENIED", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "404", "errorMessage": "Resource '218030' was not found"}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, VirtualServerApi{}.UpdateCredential(ctx, "12345", "OPERATING_SYSTEM", "admin", "new password") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "404", - Message: "Resource '218030' was not found", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "SERVER_ERROR", "errorMessage": "The server encountered an unexpected condition that prevented it from fulfilling the request."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, VirtualServerApi{}.UpdateCredential(ctx, "12345", "OPERATING_SYSTEM", "admin", "new password") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "SERVER_ERROR", - Message: "The server encountered an unexpected condition that prevented it from fulfilling the request.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodPut, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "TEMPORARILY_UNAVAILABLE", "errorMessage": "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return nil, VirtualServerApi{}.UpdateCredential(ctx, "12345", "OPERATING_SYSTEM", "admin", "new password") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "TEMPORARILY_UNAVAILABLE", - Message: "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestVirtualServerListCredentials(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "_metadata": { - "limit": 10, - "offset": 0, - "totalCount": 2 - }, - "credentials": [ - { - "type": "OPERATING_SYSTEM", - "username": "root" - }, - { - "type": "OPERATING_SYSTEM", - "username": "user" - } - ] - }`) - }) - defer teardown() - - ctx := context.Background() - response, err := VirtualServerApi{}.ListCredentials(ctx, "99944", "OPERATING_SYSTEM", PaginationOptions{}) - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 2) - assert.Equal(response.Metadata.Offset, 0) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.Credentials), 2) - - assert.Equal(response.Credentials[0].Type, "OPERATING_SYSTEM") - assert.Equal(response.Credentials[0].Username, "root") - assert.Equal(response.Credentials[1].Type, "OPERATING_SYSTEM") - assert.Equal(response.Credentials[1].Username, "user") -} - -func TestVirtualServerListCredentialsPaginate(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "_metadata": { - "limit": 10, - "offset": 1, - "totalCount": 11 - }, - "credentials": [ - { - "type": "OPERATING_SYSTEM", - "username": "root" - } - ] - }`) - }) - defer teardown() - - ctx := context.Background() - opts := PaginationOptions{ - Limit: Int(1), - } - response, err := VirtualServerApi{}.ListCredentials(ctx, "99944", "OPERATING_SYSTEM", opts) - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 11) - assert.Equal(response.Metadata.Offset, 1) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.Credentials), 1) - - assert.Equal(response.Credentials[0].Type, "OPERATING_SYSTEM") - assert.Equal(response.Credentials[0].Username, "root") -} - -func TestVirtualServerListCredentialsServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return VirtualServerApi{}.ListCredentials(ctx, "99944", "OPERATING_SYSTEM", PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "ACCESS_DENIED", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return VirtualServerApi{}.ListCredentials(ctx, "99944", "OPERATING_SYSTEM", PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "ACCESS_DENIED", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "SERVER_ERROR", "errorMessage": "The server encountered an unexpected condition that prevented it from fulfilling the request."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return VirtualServerApi{}.ListCredentials(ctx, "99944", "OPERATING_SYSTEM", PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "SERVER_ERROR", - Message: "The server encountered an unexpected condition that prevented it from fulfilling the request.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "TEMPORARILY_UNAVAILABLE", "errorMessage": "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return VirtualServerApi{}.ListCredentials(ctx, "99944", "OPERATING_SYSTEM", PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "TEMPORARILY_UNAVAILABLE", - Message: "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestVirtualServerGetCredential(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "type": "OPERATING_SYSTEM", - "username": "root", - "password": "password123" - }`) - }) - defer teardown() - - ctx := context.Background() - response, err := VirtualServerApi{}.GetCredential(ctx, "99944", "OPERATING_SYSTEM", "root") - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Type, "OPERATING_SYSTEM") - assert.Equal(response.Username, "root") - assert.Equal(response.Password, "password123") -} - -func TestVirtualServerGetCredentialServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return VirtualServerApi{}.GetCredential(ctx, "99944", "OPERATING_SYSTEM", "root") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "ACCESS_DENIED", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return VirtualServerApi{}.GetCredential(ctx, "99944", "OPERATING_SYSTEM", "root") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "ACCESS_DENIED", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "SERVER_ERROR", "errorMessage": "The server encountered an unexpected condition that prevented it from fulfilling the request."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return VirtualServerApi{}.GetCredential(ctx, "99944", "OPERATING_SYSTEM", "root") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "SERVER_ERROR", - Message: "The server encountered an unexpected condition that prevented it from fulfilling the request.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "TEMPORARILY_UNAVAILABLE", "errorMessage": "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return VirtualServerApi{}.GetCredential(ctx, "99944", "OPERATING_SYSTEM", "root") - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "TEMPORARILY_UNAVAILABLE", - Message: "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestVirtualServerGetDataTrafficMetrics(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "_metadata": { - "aggregation": "SUM", - "from": "2016-10-20T09:00:00Z", - "granularity": "DAY", - "to": "2016-10-20T11:00:00Z" - }, - "metrics": { - "DATATRAFFIC_DOWN": { - "unit": "B", - "values": [ - { - "timestamp": "2016-10-20T09:00:00Z", - "value": 900 - }, - { - "timestamp": "2016-10-20T10:00:00Z", - "value": 2500 - } - ] - }, - "DATATRAFFIC_UP": { - "unit": "B", - "values": [ - { - "timestamp": "2016-10-20T09:00:00Z", - "value": 90 - }, - { - "timestamp": "2016-10-20T10:00:00Z", - "value": 250 - } - ] - } - } - }`) - }) - defer teardown() - - ctx := context.Background() - opts := MetricsOptions{ - Granularity: String("DAY"), - Aggregation: String("SUM"), - From: String("2016-10-20T09:00:00Z"), - To: String("2016-10-20T11:00:00Z"), - } - Metric, err := VirtualServerApi{}.GetDataTrafficMetrics(ctx, "12345", opts) - assert := assert.New(t) - assert.Nil(err) - assert.Equal(Metric.Metadata.Aggregation, "SUM") - assert.Equal(Metric.Metadata.From, "2016-10-20T09:00:00Z") - assert.Equal(Metric.Metadata.To, "2016-10-20T11:00:00Z") - assert.Equal(Metric.Metadata.Granularity, "DAY") - assert.Equal(Metric.Metric.DownPublic.Unit, "B") - assert.Equal(Metric.Metric.DownPublic.Values[0].Value.String(), "900") - assert.Equal(Metric.Metric.DownPublic.Values[0].Timestamp, "2016-10-20T09:00:00Z") - assert.Equal(Metric.Metric.DownPublic.Values[1].Value.String(), "2500") - assert.Equal(Metric.Metric.DownPublic.Values[1].Timestamp, "2016-10-20T10:00:00Z") - - assert.Equal(Metric.Metric.UpPublic.Unit, "B") - assert.Equal(Metric.Metric.UpPublic.Values[0].Value.String(), "90") - assert.Equal(Metric.Metric.UpPublic.Values[0].Timestamp, "2016-10-20T09:00:00Z") - assert.Equal(Metric.Metric.UpPublic.Values[1].Value.String(), "250") - assert.Equal(Metric.Metric.UpPublic.Values[1].Timestamp, "2016-10-20T10:00:00Z") -} - -func TestVirtualServerGetDataTrafficMetricsServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - opts := MetricsOptions{ - Granularity: String("DAY"), - Aggregation: String("SUM"), - From: String("2016-10-20T09:00:00Z"), - To: String("2016-10-20T11:00:00Z"), - } - return VirtualServerApi{}.GetDataTrafficMetrics(ctx, "12345", opts) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "ACCESS_DENIED", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - opts := MetricsOptions{ - Granularity: String("DAY"), - Aggregation: String("SUM"), - From: String("2016-10-20T09:00:00Z"), - To: String("2016-10-20T11:00:00Z"), - } - return VirtualServerApi{}.GetDataTrafficMetrics(ctx, "12345", opts) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "ACCESS_DENIED", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 404", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "404", "errorMessage": "Resource '218030' was not found"}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - opts := MetricsOptions{ - Granularity: String("DAY"), - Aggregation: String("SUM"), - From: String("2016-10-20T09:00:00Z"), - To: String("2016-10-20T11:00:00Z"), - } - return VirtualServerApi{}.GetDataTrafficMetrics(ctx, "12345", opts) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "404", - Message: "Resource '218030' was not found", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "SERVER_ERROR", "errorMessage": "The server encountered an unexpected condition that prevented it from fulfilling the request."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - opts := MetricsOptions{ - Granularity: String("DAY"), - Aggregation: String("SUM"), - From: String("2016-10-20T09:00:00Z"), - To: String("2016-10-20T11:00:00Z"), - } - return VirtualServerApi{}.GetDataTrafficMetrics(ctx, "12345", opts) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "SERVER_ERROR", - Message: "The server encountered an unexpected condition that prevented it from fulfilling the request.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "TEMPORARILY_UNAVAILABLE", "errorMessage": "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - opts := MetricsOptions{ - Granularity: String("DAY"), - Aggregation: String("SUM"), - From: String("2016-10-20T09:00:00Z"), - To: String("2016-10-20T11:00:00Z"), - } - return VirtualServerApi{}.GetDataTrafficMetrics(ctx, "12345", opts) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "TEMPORARILY_UNAVAILABLE", - Message: "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -} - -func TestVirtualServerListTemplates(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "_metadata": { - "totalCount": 2, - "limit": 10, - "offset": 0 - }, - "templates": [ - { - "id": "WINDOWS_SERVER_2012_R2_STANDARD_64", - "name": "Windows Server 2012 R2 Standard (64-bit)" - }, - { - "id": "CENTOS_7_64_PLESK", - "name": "CentOS 7 (64-bit) Plesk" - } - ] - }`) - }) - defer teardown() - - ctx := context.Background() - response, err := VirtualServerApi{}.ListTemplates(ctx, "12345", PaginationOptions{}) - - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 2) - assert.Equal(response.Metadata.Offset, 0) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.Templates), 2) - - assert.Equal(response.Templates[0].Id, "WINDOWS_SERVER_2012_R2_STANDARD_64") - assert.Equal(response.Templates[0].Name, "Windows Server 2012 R2 Standard (64-bit)") - assert.Equal(response.Templates[1].Id, "CENTOS_7_64_PLESK") - assert.Equal(response.Templates[1].Name, "CentOS 7 (64-bit) Plesk") -} - -func TestVirtualServerListTemplatesPaginate(t *testing.T) { - setup(func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - fmt.Fprintf(w, `{ - "_metadata": { - "totalCount": 11, - "limit": 10, - "offset": 1 - }, - "templates": [ - { - "id": "WINDOWS_SERVER_2012_R2_STANDARD_64", - "name": "Windows Server 2012 R2 Standard (64-bit)" - } - ] - }`) - }) - defer teardown() - - ctx := context.Background() - opts := PaginationOptions{ - Limit: Int(1), - } - response, err := VirtualServerApi{}.ListTemplates(ctx, "12345", opts) - - assert := assert.New(t) - assert.Nil(err) - assert.Equal(response.Metadata.TotalCount, 11) - assert.Equal(response.Metadata.Offset, 1) - assert.Equal(response.Metadata.Limit, 10) - assert.Equal(len(response.Templates), 1) - - assert.Equal(response.Templates[0].Id, "WINDOWS_SERVER_2012_R2_STANDARD_64") - assert.Equal(response.Templates[0].Name, "Windows Server 2012 R2 Standard (64-bit)") -} - -func TestVirtualServerListTemplatesServerErrors(t *testing.T) { - serverErrorTests := []serverErrorTest{ - { - Title: "error 401", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "401", "errorMessage": "You are not authorized to view this resource."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return VirtualServerApi{}.ListTemplates(ctx, "12345", PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "401", - Message: "You are not authorized to view this resource.", - }, - }, - { - Title: "error 403", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusForbidden) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "ACCESS_DENIED", "errorMessage": "The access token is expired or invalid."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return VirtualServerApi{}.ListTemplates(ctx, "12345", PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "ACCESS_DENIED", - Message: "The access token is expired or invalid.", - }, - }, - { - Title: "error 500", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "SERVER_ERROR", "errorMessage": "The server encountered an unexpected condition that prevented it from fulfilling the request."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return VirtualServerApi{}.ListTemplates(ctx, "12345", PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "SERVER_ERROR", - Message: "The server encountered an unexpected condition that prevented it from fulfilling the request.", - }, - }, - { - Title: "error 503", - MockServer: func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - assert.Equal(t, testApiKey, r.Header.Get("x-lsw-auth")) - w.WriteHeader(http.StatusServiceUnavailable) - fmt.Fprintf(w, `{"correlationId":"289346a1-3eaf-4da4-b707-62ef12eb08be", "errorCode": "TEMPORARILY_UNAVAILABLE", "errorMessage": "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."}`) - }, - FunctionCall: func() (interface{}, error) { - ctx := context.Background() - return VirtualServerApi{}.ListTemplates(ctx, "12345", PaginationOptions{}) - }, - ExpectedError: ApiError{ - CorrelationId: "289346a1-3eaf-4da4-b707-62ef12eb08be", - Code: "TEMPORARILY_UNAVAILABLE", - Message: "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.", - }, - }, - } - assertServerErrorTests(t, serverErrorTests) -}