Skip to content

Commit

Permalink
Add new methods to the client and update component creation
Browse files Browse the repository at this point in the history
  • Loading branch information
htahir1 committed Oct 28, 2024
1 parent 9938db7 commit 3bdb02d
Show file tree
Hide file tree
Showing 11 changed files with 248 additions and 488 deletions.
39 changes: 34 additions & 5 deletions internal/provider/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"io"
"net/http"
"net/url"
"log"
)

type ListParams struct {
Expand Down Expand Up @@ -193,10 +192,8 @@ func (c *Client) ListStacks(params *ListParams) (*Page[StackResponse], error) {

// Component operations...
func (c *Client) CreateComponent(workspace string, component ComponentRequest) (*ComponentResponse, error) {
// Ensure workspace and user are set in the request
component.Workspace = workspace

resp, err := c.doRequest("POST", fmt.Sprintf("/api/v1/workspaces/%s/components", workspace), component)
endpoint := fmt.Sprintf("/api/v1/workspaces/%s/components", workspace)
resp, err := c.doRequest("POST", endpoint, component)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -379,3 +376,35 @@ func (c *Client) GetServiceConnectorByName(workspace, name string) (*ServiceConn

return &connectors.Items[0], nil
}

// Add this new method to the Client
func (c *Client) GetWorkspaceByName(name string) (*WorkspaceResponse, error) {
resp, err := c.doRequest("GET", fmt.Sprintf("/api/v1/workspaces/%s", name), nil)
if err != nil {
return nil, err
}
defer resp.Body.Close()

var result WorkspaceResponse
if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
return nil, fmt.Errorf("error decoding response: %v", err)
}

return &result, nil
}

// Add this method to get the current user
func (c *Client) GetCurrentUser() (*UserResponse, error) {
resp, err := c.doRequest("GET", "/api/v1/current-user", nil)
if err != nil {
return nil, err
}
defer resp.Body.Close()

var result UserResponse
if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
return nil, fmt.Errorf("error decoding user response: %v", err)
}
return &result, nil
}

115 changes: 0 additions & 115 deletions internal/provider/data_source_service_connector.go

This file was deleted.

81 changes: 0 additions & 81 deletions internal/provider/data_source_stack.go

This file was deleted.

131 changes: 0 additions & 131 deletions internal/provider/data_source_stack_component.go

This file was deleted.

Loading

0 comments on commit 3bdb02d

Please sign in to comment.