|
| 1 | +/* |
| 2 | +Copyright © 2023 VMware, Inc. All Rights Reserved. |
| 3 | +SPDX-License-Identifier: MPL-2.0 |
| 4 | +*/ |
| 5 | + |
| 6 | +package clustergroupdataprotectionclient |
| 7 | + |
| 8 | +import ( |
| 9 | + "net/url" |
| 10 | + |
| 11 | + "github.com/vmware/terraform-provider-tanzu-mission-control/internal/client/transport" |
| 12 | + "github.com/vmware/terraform-provider-tanzu-mission-control/internal/helper" |
| 13 | + dataprotectionclustergroupmodels "github.com/vmware/terraform-provider-tanzu-mission-control/internal/models/dataprotection/clustergroup/dataprotection" |
| 14 | +) |
| 15 | + |
| 16 | +const ( |
| 17 | + apiVersionAndGroup = "v1alpha1/clustergroups" |
| 18 | + dataProtectionPath = "dataprotection" |
| 19 | +) |
| 20 | + |
| 21 | +// New creates a new data protection resource service API client. |
| 22 | +func New(transport *transport.Client) ClientService { |
| 23 | + return &Client{Client: transport} |
| 24 | +} |
| 25 | + |
| 26 | +/* |
| 27 | +Client for data protection resource service API. |
| 28 | +*/ |
| 29 | +type Client struct { |
| 30 | + *transport.Client |
| 31 | +} |
| 32 | + |
| 33 | +// ClientService is the interface for Client methods. |
| 34 | +type ClientService interface { |
| 35 | + ClusterGroupDataProtectionResourceServiceCreate(request *dataprotectionclustergroupmodels.VmwareTanzuManageV1alpha1ClusterGroupDataprotectionCreateDataProtectionRequest) (*dataprotectionclustergroupmodels.VmwareTanzuManageV1alpha1ClusterGroupDataprotectionCreateDataProtectionResponse, error) |
| 36 | + |
| 37 | + ClusterGroupDataProtectionResourceServiceDelete(fn *dataprotectionclustergroupmodels.VmwareTanzuManageV1alpha1ClusterGroupDataprotectionFullName, destroyBackups bool) error |
| 38 | + |
| 39 | + ClusterGroupDataProtectionResourceServiceList(fn *dataprotectionclustergroupmodels.VmwareTanzuManageV1alpha1ClusterGroupDataprotectionFullName) (*dataprotectionclustergroupmodels.VmwareTanzuManageV1alpha1ClusterGroupDataprotectionListDataProtectionsResponse, error) |
| 40 | + |
| 41 | + ClusterGroupDataProtectionResourceServiceUpdate(request *dataprotectionclustergroupmodels.VmwareTanzuManageV1alpha1ClusterGroupDataprotectionCreateDataProtectionRequest) (*dataprotectionclustergroupmodels.VmwareTanzuManageV1alpha1ClusterGroupDataprotectionCreateDataProtectionResponse, error) |
| 42 | +} |
| 43 | + |
| 44 | +/* |
| 45 | +ClusterGroupDataProtectionResourceServiceCreate enables data protection on a cluster. |
| 46 | +*/ |
| 47 | +func (c *Client) ClusterGroupDataProtectionResourceServiceCreate(request *dataprotectionclustergroupmodels.VmwareTanzuManageV1alpha1ClusterGroupDataprotectionCreateDataProtectionRequest, |
| 48 | +) (*dataprotectionclustergroupmodels.VmwareTanzuManageV1alpha1ClusterGroupDataprotectionCreateDataProtectionResponse, error) { |
| 49 | + response := &dataprotectionclustergroupmodels.VmwareTanzuManageV1alpha1ClusterGroupDataprotectionCreateDataProtectionResponse{} |
| 50 | + requestURL := helper.ConstructRequestURL(apiVersionAndGroup, request.DataProtection.FullName.ClusterGroupName, dataProtectionPath).String() |
| 51 | + err := c.Create(requestURL, request, response) |
| 52 | + |
| 53 | + return response, err |
| 54 | +} |
| 55 | + |
| 56 | +/* |
| 57 | +ClusterGroupDataProtectionResourceServiceDelete disables data protection on a cluster group. |
| 58 | +*/ |
| 59 | +func (c *Client) ClusterGroupDataProtectionResourceServiceDelete(fn *dataprotectionclustergroupmodels.VmwareTanzuManageV1alpha1ClusterGroupDataprotectionFullName, deleteBackups bool) error { |
| 60 | + requestURL := helper.ConstructRequestURL(apiVersionAndGroup, fn.ClusterGroupName, dataProtectionPath) |
| 61 | + queryParams := url.Values{} |
| 62 | + |
| 63 | + //queryParams.Add("fullName.clusterGroupName", fn.ClusterGroupName) |
| 64 | + //queryParams.Add("delete_backups", strconv.FormatBool(deleteBackups)) |
| 65 | + |
| 66 | + requestURL = requestURL.AppendQueryParams(queryParams) |
| 67 | + |
| 68 | + return c.Delete(requestURL.String()) |
| 69 | +} |
| 70 | + |
| 71 | +/* |
| 72 | +ClusterGroupDataProtectionResourceServiceList gets data protection details. |
| 73 | +*/ |
| 74 | +func (c *Client) ClusterGroupDataProtectionResourceServiceList(fn *dataprotectionclustergroupmodels.VmwareTanzuManageV1alpha1ClusterGroupDataprotectionFullName) (*dataprotectionclustergroupmodels.VmwareTanzuManageV1alpha1ClusterGroupDataprotectionListDataProtectionsResponse, error) { |
| 75 | + requestURL := helper.ConstructRequestURL(apiVersionAndGroup, fn.ClusterGroupName, dataProtectionPath) |
| 76 | + queryParams := url.Values{} |
| 77 | + |
| 78 | + /*if fn.ManagementClusterName != "" { |
| 79 | + queryParams.Add("searchScope.managementClusterName", fn.ManagementClusterName) |
| 80 | + } |
| 81 | +
|
| 82 | + if fn.ProvisionerName != "" { |
| 83 | + queryParams.Add("searchScope.provisionerName", fn.ProvisionerName) |
| 84 | + }*/ |
| 85 | + |
| 86 | + if len(queryParams) > 0 { |
| 87 | + requestURL = requestURL.AppendQueryParams(queryParams) |
| 88 | + } |
| 89 | + |
| 90 | + resp := &dataprotectionclustergroupmodels.VmwareTanzuManageV1alpha1ClusterGroupDataprotectionListDataProtectionsResponse{} |
| 91 | + err := c.Get(requestURL.String(), resp) |
| 92 | + |
| 93 | + return resp, err |
| 94 | +} |
| 95 | + |
| 96 | +/* |
| 97 | +ClusterGroupDataProtectionResourceServiceUpdate updates a data protection configuration on a cluster. |
| 98 | +*/ |
| 99 | +func (c *Client) ClusterGroupDataProtectionResourceServiceUpdate(request *dataprotectionclustergroupmodels.VmwareTanzuManageV1alpha1ClusterGroupDataprotectionCreateDataProtectionRequest, |
| 100 | +) (*dataprotectionclustergroupmodels.VmwareTanzuManageV1alpha1ClusterGroupDataprotectionCreateDataProtectionResponse, error) { |
| 101 | + response := &dataprotectionclustergroupmodels.VmwareTanzuManageV1alpha1ClusterGroupDataprotectionCreateDataProtectionResponse{} |
| 102 | + requestURL := helper.ConstructRequestURL(apiVersionAndGroup, request.DataProtection.FullName.ClusterGroupName, dataProtectionPath).String() |
| 103 | + err := c.Update(requestURL, request, response) |
| 104 | + |
| 105 | + return response, err |
| 106 | +} |
0 commit comments