Skip to content

Commit

Permalink
chore: use get project endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
avallete committed Oct 5, 2024
1 parent 2ccb192 commit 813bc64
Show file tree
Hide file tree
Showing 5 changed files with 148 additions and 209 deletions.
82 changes: 25 additions & 57 deletions api/beta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,31 @@ paths:
security:
- bearer: []
/v1/projects/{ref}:
get:
operationId: v1-get-project
summary: Gets a specific project status that belongs to the authenticated user
parameters:
- name: ref
required: true
in: path
description: Project ref
schema:
minLength: 20
maxLength: 20
type: string
responses:
'200':
description: ''
content:
application/json:
schema:
$ref: '#/components/schemas/V1ProjectResponse'
'500':
description: Failed to retrieve project status
tags:
- Projects
security:
- bearer: []
delete:
operationId: v1-delete-a-project
summary: Deletes the given project
Expand Down Expand Up @@ -1726,32 +1751,6 @@ paths:
- Auth
security:
- bearer: []
/v1/projects/{ref}/status:
get:
operationId: v1-get-project-status
summary: Gets a specific project status that belongs to the authenticated user
parameters:
- name: ref
required: true
in: path
description: Project ref
schema:
minLength: 20
maxLength: 20
type: string
responses:
'200':
description: ''
content:
application/json:
schema:
$ref: '#/components/schemas/StatusResponse'
'500':
description: Failed to retrieve project status
tags:
- Projects
security:
- bearer: []
/v1/projects/{ref}/database/query:
post:
operationId: v1-run-a-query
Expand Down Expand Up @@ -3129,37 +3128,6 @@ components:
- id
- ref
- name
StatusResponse:
type: object
properties:
id:
type: number
ref:
type: string
name:
type: string
status:
enum:
- ACTIVE_HEALTHY
- ACTIVE_UNHEALTHY
- COMING_UP
- GOING_DOWN
- INACTIVE
- INIT_FAILED
- REMOVED
- RESTARTING
- UNKNOWN
- UPGRADING
- PAUSING
- RESTORING
- RESTORE_FAILED
- PAUSE_FAILED
type: string
required:
- id
- ref
- name
- status
SecretResponse:
type: object
properties:
Expand Down
6 changes: 3 additions & 3 deletions internal/link/link.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,17 +240,17 @@ func updatePoolerConfig(config api.SupavisorConfigResponse) {
}

func checkRemoteProjectStatus(ctx context.Context, projectRef string) error {
resp, err := utils.GetSupabase().V1GetProjectStatusWithResponse(ctx, projectRef)
resp, err := utils.GetSupabase().V1GetProjectWithResponse(ctx, projectRef)
if err != nil {
return errors.Errorf("failed to retrieve remote project status: %w", err)
}
if resp.JSON200 == nil {
return errors.New("Unexpected error retrieving remote project status: " + string(resp.Body))
}
if resp.JSON200.Status == api.StatusResponseStatusINACTIVE {
if resp.JSON200.Status == api.V1ProjectResponseStatusINACTIVE {
return errors.New(fmt.Sprintf("Project is paused. An admin must unpause it from the Supabase dashboard at %s", utils.Aqua(fmt.Sprintf("%s/project/%s", utils.GetSupabaseDashboardURL(), projectRef))))
}
if resp.JSON200.Status != api.StatusResponseStatusACTIVEHEALTHY {
if resp.JSON200.Status != api.V1ProjectResponseStatusACTIVEHEALTHY {
fmt.Fprintf(os.Stderr, "%s: Project status is %s instead of Active Healthy. Some operations might fail.\n", utils.Yellow("Warning"), resp.JSON200.Status)
}
return nil
Expand Down
16 changes: 8 additions & 8 deletions internal/link/link_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ func TestLinkCommand(t *testing.T) {
defer gock.OffAll()
// Mock project status
gock.New(utils.DefaultApiHost).
Get("/v1/projects/" + project + "/status").
Get("/v1/projects/" + project).
Reply(200).
JSON(api.StatusResponse{Status: api.StatusResponseStatusACTIVEHEALTHY})
JSON(api.V1ProjectResponse{Status: api.V1ProjectResponseStatusACTIVEHEALTHY})
gock.New(utils.DefaultApiHost).
Get("/v1/projects/" + project + "/api-keys").
Reply(200).
Expand Down Expand Up @@ -126,9 +126,9 @@ func TestLinkCommand(t *testing.T) {
defer gock.OffAll()
// Mock project status
gock.New(utils.DefaultApiHost).
Get("/v1/projects/" + project + "/status").
Get("/v1/projects/" + project).
Reply(200).
JSON(api.StatusResponse{Status: api.StatusResponseStatusACTIVEHEALTHY})
JSON(api.V1ProjectResponse{Status: api.V1ProjectResponseStatusACTIVEHEALTHY})
gock.New(utils.DefaultApiHost).
Get("/v1/projects/" + project + "/api-keys").
Reply(200).
Expand Down Expand Up @@ -171,9 +171,9 @@ func TestLinkCommand(t *testing.T) {
defer gock.OffAll()
// Mock project status
gock.New(utils.DefaultApiHost).
Get("/v1/projects/" + project + "/status").
Get("/v1/projects/" + project).
Reply(200).
JSON(api.StatusResponse{Status: api.StatusResponseStatusACTIVEHEALTHY})
JSON(api.V1ProjectResponse{Status: api.V1ProjectResponseStatusACTIVEHEALTHY})
gock.New(utils.DefaultApiHost).
Get("/v1/projects/" + project + "/api-keys").
Reply(200).
Expand Down Expand Up @@ -215,9 +215,9 @@ func TestLinkCommand(t *testing.T) {
defer gock.OffAll()
// Mock project status
gock.New(utils.DefaultApiHost).
Get("/v1/projects/" + project + "/status").
Get("/v1/projects/" + project).
Reply(200).
JSON(api.StatusResponse{Status: api.StatusResponseStatusINACTIVE})
JSON(api.V1ProjectResponse{Status: api.V1ProjectResponseStatusINACTIVE})
// Run test
err := Run(context.Background(), project, fsys)
// Check error
Expand Down
Loading

0 comments on commit 813bc64

Please sign in to comment.