Skip to content

Commit

Permalink
APPS-9858 Add method to obtain websocket URL to exec into components
Browse files Browse the repository at this point in the history
  • Loading branch information
blesswinsamuel committed Nov 8, 2024
1 parent ebeee16 commit bee6fd1
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type AppsService interface {
CreateDeployment(ctx context.Context, appID string, create ...*DeploymentCreateRequest) (*Deployment, *Response, error)

GetLogs(ctx context.Context, appID, deploymentID, component string, logType AppLogType, follow bool, tailLines int) (*AppLogs, *Response, error)
GetExec(ctx context.Context, appID, deploymentID, component string) (*AppExec, *Response, error)

ListRegions(ctx context.Context) ([]*AppRegion, *Response, error)

Expand Down Expand Up @@ -77,6 +78,11 @@ type AppLogs struct {
HistoricURLs []string `json:"historic_urls"`
}

// AppExec represents the websocket URL used for sending/receiving console input and output.
type AppExec struct {
URL string `json:"url"`
}

// AppUpdateRequest represents a request to update an app.
type AppUpdateRequest struct {
Spec *AppSpec `json:"spec"`
Expand Down Expand Up @@ -368,6 +374,27 @@ func (s *AppsServiceOp) GetLogs(ctx context.Context, appID, deploymentID, compon
return logs, resp, nil
}

// GetExec retrieves the websocket URL used for sending/receiving console input and output.
func (s *AppsServiceOp) GetExec(ctx context.Context, appID, deploymentID, component string) (*AppExec, *Response, error) {
var url string
if deploymentID == "" {
url = fmt.Sprintf("%s/%s/components/%s/exec", appsBasePath, appID, component)
} else {
url = fmt.Sprintf("%s/%s/deployments/%s/components/%s/exec", appsBasePath, appID, deploymentID, component)
}

req, err := s.client.NewRequest(ctx, http.MethodGet, url, nil)
if err != nil {
return nil, nil, err
}
logs := new(AppExec)
resp, err := s.client.Do(ctx, req, logs)
if err != nil {
return nil, resp, err
}
return logs, resp, nil
}

// ListRegions lists all regions supported by App Platform.
func (s *AppsServiceOp) ListRegions(ctx context.Context) ([]*AppRegion, *Response, error) {
path := fmt.Sprintf("%s/regions", appsBasePath)
Expand Down

0 comments on commit bee6fd1

Please sign in to comment.