Skip to content

Commit

Permalink
fix(hooks): Fix hooks url and add import
Browse files Browse the repository at this point in the history
  • Loading branch information
EldoranDev committed Dec 18, 2023
1 parent 9380576 commit 68f0067
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
6 changes: 3 additions & 3 deletions internal/client/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (c *client) GetHooks() ([]*Hook, error) {
func (c *client) GetHook(ID string) (*Hook, error) {
req, err := http.NewRequest(
http.MethodGet,
fmt.Sprintf("%s/webhooks-srv/webhook?id=%s", c.HostUrl, ID),
fmt.Sprintf("%s/webhook-srv/webhook?id=%s", c.HostUrl, ID),
nil,
)

Expand Down Expand Up @@ -85,7 +85,7 @@ func (c *client) UpsertHook(hook Hook) (*Hook, error) {

req, err := http.NewRequest(
http.MethodPost,
fmt.Sprintf("%s/webhooks-srv/webhook", c.HostUrl),
fmt.Sprintf("%s/webhook-srv/webhook", c.HostUrl),
bytes.NewReader(rb),
)

Expand Down Expand Up @@ -113,7 +113,7 @@ func (c *client) UpsertHook(hook Hook) (*Hook, error) {
func (c *client) DeleteHook(ID string) error {
req, err := http.NewRequest(
http.MethodDelete,
fmt.Sprintf("%s/webhooks-srv/webhook/%s", c.HostUrl, ID),
fmt.Sprintf("%s/webhook-srv/webhook/%s", c.HostUrl, ID),
nil,
)

Expand Down
23 changes: 23 additions & 0 deletions internal/provider/resource_hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type hookResource struct {
}

var _ resource.Resource = (*hookResource)(nil)
var _ resource.ResourceWithImportState = (*hookResource)(nil)

func NewHookResource() resource.Resource {
return &hookResource{}
Expand Down Expand Up @@ -270,3 +271,25 @@ func (r hookResource) Delete(ctx context.Context, req resource.DeleteRequest, re

resp.State.RemoveResource(ctx)
}

func (r hookResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
var state Hook

hook, err := r.provider.client.GetHook(req.ID)
if err != nil {
resp.Diagnostics.AddError("Error importing App", err.Error())
return
}

state.ID = types.StringValue(hook.Id)
state.Url = hook.URL
state.Events = hook.Events
state.LastUpdate = types.StringValue(hook.UpdatedTime)
state.AuthType = hook.AuthType

state.APIKeyDetails.APIKeyPlaceholder = hook.ApiKeyDetails.APIKeyPlaceholder
state.APIKeyDetails.APIKeyPlacement = hook.ApiKeyDetails.APIKeyPlacement
state.APIKeyDetails.APIKey = hook.ApiKeyDetails.APIKey

resp.State.Set(ctx, state)
}

0 comments on commit 68f0067

Please sign in to comment.