Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature:Postgres commands through http #893

Merged
merged 8 commits into from Apr 7, 2022

Conversation

rugwirobaker
Copy link
Contributor

@rugwirobaker rugwirobaker commented Mar 30, 2022

  • Add postgres http client
  • List postgres resources(users, databases) through http
  • Attaching and detaching now goes over http
  • Delete the old ssh commands code
  • Limit this feature to v0.0.19 of postgres-ha

This PR goes hand in hand with fly-apps/postgres-ha#64

Copy link
Contributor

@davissp14 davissp14 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, looks great! Just a few notes.

cmd/postgres.go Outdated
if !isPostgresApp(&app.ImageDetails) {
return fmt.Errorf("%s is not a postgres app", cmdCtx.AppName)
}
// if !isPostgresApp(&app.ImageDetails) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we checking this somewhere else?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@davissp14 I only removed this temporary for testing, cause pg apps deployed with fly deploy fail to pass this checks

cmd/postgres.go Outdated
}

pgCmd := NewPostgresCmd(cmdCtx, app, dialer)
// pgCmd := NewPostgresCmd(cmdCtx, app, dialer)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can probably just remove the commented code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah will do, Just wanted to get a quick reaction before going to far with it.

}
defer res.Body.Close()

if res.Status > "299" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are the expected status codes? Also, looks like you're comparing an int with a string here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True I'll work on it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will we be working with any valid status codes, other than 200 and 201?

pkg/flypg/pg.go Outdated
return false, nil
}

func (c *Client) GrantAccess(ctx context.Context, dbName, userName string) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be coupled with CreateUser. Given the complexity surrounding user permissions, we shouldn't expose this as its own endpoint.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense

pkg/flypg/pg.go Outdated
return nil
}

func (c *Client) RevokeAccess(ctx context.Context, dbName, userName string) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be coupled with DeleteUser. Like GrantAccess, let's not expose this as its own endpoint.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do

Copy link
Contributor

@davissp14 davissp14 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work! We just need to ensure that the version is bumped in postgres-ha before this gets merged.

@rugwirobaker rugwirobaker merged commit e4a3a01 into master Apr 7, 2022
@rugwirobaker rugwirobaker deleted the patch/pg-operations-http branch April 7, 2022 15:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants