This commit is contained in:
KasimBaybikov
2023-05-04 10:08:25 +03:00
parent 9bad8a6947
commit 8ca233dd32
288 changed files with 6645 additions and 11464 deletions

View File

@@ -1,24 +0,0 @@
package locations
/*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>
Kasim Baybikov, <kmbaybikov@basistech.ru>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
const locationsListAPI = "/restmachine/cloudapi/locations/list"
const locationURLAPI = "/restmachine/cloudapi/locations/getUrl"

View File

@@ -38,20 +38,21 @@ import (
"github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/locations"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/flattens"
)
func flattenLocationsList(ll LocationsList) []map[string]interface{} {
func flattenLocationsList(ll locations.ListLocations) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
for _, l := range ll {
temp := map[string]interface{}{
"ckey": l.CKey,
"meta": flattens.FlattenMeta(l.Meta),
"flag": l.Flag,
"gid": l.GridID,
"guid": l.Guid,
"id": l.Id,
"gid": l.GID,
"guid": l.GUID,
"id": l.ID,
"location_code": l.LocationCode,
"name": l.Name,
}
@@ -64,7 +65,6 @@ func flattenLocationsList(ll LocationsList) []map[string]interface{} {
func dataSourceLocationsListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
locations, err := utilityLocationsListCheckPresence(ctx, d, m)
if err != nil {
return diag.FromErr(err)
}

View File

@@ -34,6 +34,7 @@ package locations
import (
"context"
"strings"
"github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
@@ -50,6 +51,8 @@ func dataSourceLocationUrlRead(ctx context.Context, d *schema.ResourceData, m in
id := uuid.New()
d.SetId(id.String())
url = strings.ReplaceAll(url, "\\", "")
url = strings.ReplaceAll(url, "\"", "")
d.Set("url", url)
return nil

View File

@@ -34,8 +34,6 @@ package locations
import (
"context"
"encoding/json"
"net/url"
log "github.com/sirupsen/logrus"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
@@ -45,16 +43,10 @@ func utilityLocationUrlCheckPresence(ctx context.Context, m interface{}) (string
c := m.(*controller.ControllerCfg)
log.Debugf("utilityLocationUrlCheckPresence: load locations list")
locationUrl, err := c.DecortAPICall(ctx, "POST", locationURLAPI, &url.Values{})
locationUrl, err := c.CloudAPI().Locations().GetURL(ctx)
if err != nil {
return "", err
}
location := new(string)
err = json.Unmarshal([]byte(locationUrl), location)
if err != nil {
return "", err
}
return *location, nil
return locationUrl, nil
}

View File

@@ -34,35 +34,27 @@ package locations
import (
"context"
"encoding/json"
"net/url"
"strconv"
log "github.com/sirupsen/logrus"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/locations"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func utilityLocationsListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (LocationsList, error) {
locationsList := LocationsList{}
func utilityLocationsListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (locations.ListLocations, error) {
c := m.(*controller.ControllerCfg)
urlValues := &url.Values{}
req := locations.ListRequest{}
if page, ok := d.GetOk("page"); ok {
urlValues.Add("page", strconv.Itoa(page.(int)))
req.Page = uint64(page.(int))
}
if size, ok := d.GetOk("size"); ok {
urlValues.Add("size", strconv.Itoa(size.(int)))
req.Size = uint64(size.(int))
}
log.Debugf("utilityLocationsListCheckPresence: load locations list")
locationsListRaw, err := c.DecortAPICall(ctx, "POST", locationsListAPI, urlValues)
if err != nil {
return nil, err
}
err = json.Unmarshal([]byte(locationsListRaw), &locationsList)
locationsList, err := c.CloudAPI().Locations().List(ctx, req)
if err != nil {
return nil, err
}