Skip to content

Commit

Permalink
added group, version, separator to constants
Browse files Browse the repository at this point in the history
  • Loading branch information
ca7alindev committed May 30, 2024
1 parent 6ddab61 commit 8f51f82
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
10 changes: 7 additions & 3 deletions internal/client/magento.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import (
"github.com/go-resty/resty/v2"
)

const (
separator = "/"
)

// Desired represents the desired state of a resource.
type Desired struct {
ID string `json:"id"`
Expand All @@ -20,7 +24,7 @@ func GetResourceByID(c *Client, id string) (*Desired, error) {
if id == "" {
return nil, errors.New("resource with ID" + id + " in " + c.Path + " not found")
}
resp, _ := c.Create().R().Get(c.Path + "/" + id)
resp, _ := c.Create().R().Get(c.Path + separator + id)
if resp.StatusCode() != http.StatusOK {
return nil, errors.New("resource in " + c.Path + " not found")
}
Expand Down Expand Up @@ -59,7 +63,7 @@ func UpdateResourceByID(c *Client, id string, observed map[string]interface{}) e
requestBody := map[string]interface{}{
strings.ToLower(observed["kind"].(string)): observed["spec"].(map[string]interface{})["forProvider"],
}
_, err := c.Create().R().SetBody(requestBody).Put(c.Path + "/" + id)
_, err := c.Create().R().SetBody(requestBody).Put(c.Path + separator + id)
if err != nil {
return err
}
Expand All @@ -69,7 +73,7 @@ func UpdateResourceByID(c *Client, id string, observed map[string]interface{}) e

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

Expand Down
4 changes: 3 additions & 1 deletion internal/controller/magento.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ const (
api = "/rest"
id = "external-id"
separator = "/"
group = "magento.web7.md"
version = "v1alpha1"
)

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

// isValidGVK returns true if the GroupVersionKind is a valid Magento API resource.
func isValidGVK(gvk schema.GroupVersionKind) bool {
return gvk.Group == "magento.web7.md" && gvk.Version == "v1alpha1" &&
return gvk.Group == group && gvk.Version == version &&
!strings.Contains(gvk.Kind, "Options") && !strings.Contains(gvk.Kind, "List") &&
!strings.Contains(gvk.Kind, "Event") && !strings.Contains(gvk.Kind, "Config")
}
Expand Down

0 comments on commit 8f51f82

Please sign in to comment.