Skip to content

Commit 8f51f82

Browse files
committed
added group, version, separator to constants
1 parent 6ddab61 commit 8f51f82

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

internal/client/magento.go

+7-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ import (
99
"github.com/go-resty/resty/v2"
1010
)
1111

12+
const (
13+
separator = "/"
14+
)
15+
1216
// Desired represents the desired state of a resource.
1317
type Desired struct {
1418
ID string `json:"id"`
@@ -20,7 +24,7 @@ func GetResourceByID(c *Client, id string) (*Desired, error) {
2024
if id == "" {
2125
return nil, errors.New("resource with ID" + id + " in " + c.Path + " not found")
2226
}
23-
resp, _ := c.Create().R().Get(c.Path + "/" + id)
27+
resp, _ := c.Create().R().Get(c.Path + separator + id)
2428
if resp.StatusCode() != http.StatusOK {
2529
return nil, errors.New("resource in " + c.Path + " not found")
2630
}
@@ -59,7 +63,7 @@ func UpdateResourceByID(c *Client, id string, observed map[string]interface{}) e
5963
requestBody := map[string]interface{}{
6064
strings.ToLower(observed["kind"].(string)): observed["spec"].(map[string]interface{})["forProvider"],
6165
}
62-
_, err := c.Create().R().SetBody(requestBody).Put(c.Path + "/" + id)
66+
_, err := c.Create().R().SetBody(requestBody).Put(c.Path + separator + id)
6367
if err != nil {
6468
return err
6569
}
@@ -69,7 +73,7 @@ func UpdateResourceByID(c *Client, id string, observed map[string]interface{}) e
6973

7074
// DeleteResourceByID deletes a resource by its ID at specified api endpoint.
7175
func DeleteResourceByID(c *Client, id string) error {
72-
_, err := c.Create().R().Delete(c.Path + "/" + id)
76+
_, err := c.Create().R().Delete(c.Path + separator + id)
7377
return err
7478
}
7579

internal/controller/magento.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ const (
5151
api = "/rest"
5252
id = "external-id"
5353
separator = "/"
54+
group = "magento.web7.md"
55+
version = "v1alpha1"
5456
)
5557

5658
// MagentoService is a service that can connect to Magento API.
@@ -93,7 +95,7 @@ var (
9395

9496
// isValidGVK returns true if the GroupVersionKind is a valid Magento API resource.
9597
func isValidGVK(gvk schema.GroupVersionKind) bool {
96-
return gvk.Group == "magento.web7.md" && gvk.Version == "v1alpha1" &&
98+
return gvk.Group == group && gvk.Version == version &&
9799
!strings.Contains(gvk.Kind, "Options") && !strings.Contains(gvk.Kind, "List") &&
98100
!strings.Contains(gvk.Kind, "Event") && !strings.Contains(gvk.Kind, "Config")
99101
}

0 commit comments

Comments
 (0)