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

Dev updates #25

Closed
wants to merge 29 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
4e48a13
feat: Add ability to create, get and delete SSH Keys
MatthewPierson Mar 12, 2024
4a77c55
Merge pull request #22 from MatthewPierson/feat/add_ssh_keys
tommysitehost Mar 12, 2024
c96d66f
chore: Update changelog
MatthewPierson Mar 12, 2024
0d602e6
Merge pull request #23 from MatthewPierson/feat/add_ssh_keys
tommysitehost Mar 12, 2024
bc7cf2f
fix: Add update support for SSH Keys
MatthewPierson Mar 12, 2024
aa2f56c
chore: Update changelog
MatthewPierson Mar 12, 2024
f068555
Merge pull request #24 from MatthewPierson/feat/add_ssh_keys
tommysitehost Mar 12, 2024
ac0e2c3
linty fresh and clean
yakmoose Mar 12, 2023
e6cc0d6
double image endpoints on clouds
yakmoose Mar 13, 2023
abd1dc9
work on cloud db handlers
yakmoose Mar 13, 2023
ce7cbf0
work on cloud db handlers
yakmoose Mar 13, 2023
f66ddcc
add getter for databases
yakmoose Mar 13, 2023
322ff32
add in database functions
yakmoose Mar 13, 2023
ed51ef1
update the change log
yakmoose Mar 13, 2023
fa84bb9
add a little constant for job types
yakmoose Mar 13, 2023
a9b8000
commmiting the right file this time
yakmoose Mar 13, 2023
c3551d0
fix the spelling
yakmoose Mar 13, 2023
0678513
Changelog
yakmoose Mar 15, 2023
c8deeb9
more clean ups, mainly formatting, and ssh user stuff
yakmoose Mar 23, 2023
3e3535a
add in some updates for handling api responses
yakmoose May 1, 2023
decac33
add in db user and grant endpoints
yakmoose Jul 25, 2023
a3c3de8
clean up the stuff
yakmoose Jul 26, 2023
666f965
minor fixes to domain listing/getting
yakmoose Jul 29, 2023
c7b3d1c
work on getting images etc...
yakmoose Jul 30, 2023
bb73626
updates to environment and grant handling
yakmoose Aug 2, 2023
351eef9
work on zone updates etc
yakmoose May 12, 2024
4e36725
bumps?
yakmoose May 13, 2024
6039154
merge and clean up
yakmoose May 14, 2024
2bff46c
Add fixes to random api return types
yakmoose May 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add in db user and grant endpoints
  • Loading branch information
yakmoose committed May 13, 2024
commit decac33b4cc2bdd20aea3f8a35ae544c0011ad66
211 changes: 211 additions & 0 deletions go.sum

Large diffs are not rendered by default.

43 changes: 43 additions & 0 deletions pkg/api/cloud/db/grant/add.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package grant

import (
"context"
"net/url"

"github.com/sitehostnz/gosh/pkg/utils"
)

// Add creates a new grant for the given database/host/user
func (s *Client) Add(ctx context.Context, request AddRequest) (response AddResponse, err error) {
uri := "cloud/db/grant/add.json"
keys := []string{
"client_id",
"server_name",
"mysql_host",
"database",
"username",
"grants[]",
}

values := url.Values{}
values.Add("client_id", s.client.ClientID)
values.Add("server_name", request.ServerName)
values.Add("mysql_host", request.MySQLHost)
values.Add("username", request.Username)
values.Add("database", request.Database)

for _, grant := range request.Grants {
values.Add("grants[]", grant)
}

req, err := s.client.NewRequest("POST", uri, utils.Encode(values, keys))
if err != nil {
return response, err
}

if err := s.client.Do(ctx, req, &response); err != nil {
return response, err
}

return response, nil
}
38 changes: 38 additions & 0 deletions pkg/api/cloud/db/grant/delete.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package grant

import (
"context"
"net/url"

"github.com/sitehostnz/gosh/pkg/utils"
)

// Delete deletes the grant from the specific database/host/user
func (s *Client) Delete(ctx context.Context, request DeleteRequest) (response DeleteResponse, err error) {
uri := "cloud/db/grant/delete.json"
keys := []string{
"client_id",
"server_name",
"mysql_host",
"database",
"username",
}

values := url.Values{}
values.Add("client_id", s.client.ClientID)
values.Add("server_name", request.ServerName)
values.Add("mysql_host", request.MySQLHost)
values.Add("username", request.Username)
values.Add("database", request.Database)

req, err := s.client.NewRequest("POST", uri, utils.Encode(values, keys))
if err != nil {
return response, err
}

if err := s.client.Do(ctx, req, &response); err != nil {
return response, err
}

return response, nil
}
19 changes: 19 additions & 0 deletions pkg/api/cloud/db/grant/models.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package grant

import (
"github.com/sitehostnz/gosh/pkg/api"
)

type (
// Client is a Service to work with API Jobs.
Client struct {
client *api.Client
}
)

// New is an initialisation function.
func New(c *api.Client) *Client {
return &Client{
client: c,
}
}
26 changes: 26 additions & 0 deletions pkg/api/cloud/db/grant/request.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package grant

type (
AddRequest struct {
ServerName string `json:"server_name"`
MySQLHost string `json:"mysql_host"`
Username string `json:"username"`
Database string `json:"database"`
Grants []string `json:"grants"`
}

UpdateRequest struct {
ServerName string `json:"server_name"`
MySQLHost string `json:"mysql_host"`
Username string `json:"username"`
Database string `json:"database"`
Grants []string `json:"grants"`
}

DeleteRequest struct {
ServerName string `json:"server_name"`
MySQLHost string `json:"mysql_host"`
Username string `json:"username"`
Database string `json:"database"`
}
)
24 changes: 24 additions & 0 deletions pkg/api/cloud/db/grant/response.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package grant

import "github.com/sitehostnz/gosh/pkg/models"

type (
AddResponse struct {
Return struct {
JobID string `json:"job_id"`
} `json:"return"`
models.APIResponse
}
UpdateResponse struct {
Return struct {
JobID string `json:"job_id"`
} `json:"return"`
models.APIResponse
}
DeleteResponse struct {
Return struct {
JobID string `json:"job_id"`
} `json:"return"`
models.APIResponse
}
)
43 changes: 43 additions & 0 deletions pkg/api/cloud/db/grant/update.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package grant

import (
"context"
"net/url"

"github.com/sitehostnz/gosh/pkg/utils"
)

// Update updates the grants for a specific db/user/host
func (s *Client) Update(ctx context.Context, request UpdateRequest) (response UpdateResponse, err error) {
uri := "cloud/db/grant/update.json"
keys := []string{
"client_id",
"server_name",
"mysql_host",
"database",
"username",
"grants[]",
}

values := url.Values{}
values.Add("client_id", s.client.ClientID)
values.Add("server_name", request.ServerName)
values.Add("mysql_host", request.MySQLHost)
values.Add("username", request.Username)
values.Add("database", request.Database)

for _, grant := range request.Grants {
values.Add("grants[]", grant)
}

req, err := s.client.NewRequest("POST", uri, utils.Encode(values, keys))
if err != nil {
return response, err
}

if err := s.client.Do(ctx, req, &response); err != nil {
return response, err
}

return response, nil
}
46 changes: 46 additions & 0 deletions pkg/api/cloud/db/user/add.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package user

import (
"context"
"net/url"

"github.com/sitehostnz/gosh/pkg/utils"
)

// Add creates a new cloud database.
func (s *Client) Add(ctx context.Context, request AddRequest) (response AddResponse, err error) {
uri := "cloud/db/user/add.json"
keys := []string{
"client_id",
"server_name",
"mysql_host",
"username",
"password",
}

values := url.Values{}
values.Add("client_id", s.client.ClientID)
values.Add("server_name", request.ServerName)
values.Add("mysql_host", request.MySQLHost)
values.Add("username", request.Username)
values.Add("password", request.Password)

// suspect these are required at the same time, so lets not deal with this here?
// feels cleaner to handle a grant independantly
//if request.Database != "" {
// values.Add("database", request.Database)
//}
//if request.Grants != nil {
//}

req, err := s.client.NewRequest("POST", uri, utils.Encode(values, keys))
if err != nil {
return response, err
}

if err := s.client.Do(ctx, req, &response); err != nil {
return response, err
}

return response, nil
}
36 changes: 36 additions & 0 deletions pkg/api/cloud/db/user/delete.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package user

import (
"context"
"net/url"

"github.com/sitehostnz/gosh/pkg/utils"
)

// Delete removes the cloud database user
func (s *Client) Delete(ctx context.Context, request DeleteRequest) (response DeleteResponse, err error) {
uri := "cloud/db/user/delete.json"
keys := []string{
"client_id",
"server_name",
"mysql_host",
"username",
}

values := url.Values{}
values.Add("client_id", s.client.ClientID)
values.Add("server_name", request.ServerName)
values.Add("mysql_host", request.MySQLHost)
values.Add("username", request.Username)

req, err := s.client.NewRequest("POST", uri, utils.Encode(values, keys))
if err != nil {
return response, err
}

if err := s.client.Do(ctx, req, &response); err != nil {
return response, err
}

return response, nil
}
39 changes: 39 additions & 0 deletions pkg/api/cloud/db/user/get.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package user

import (
"context"

"github.com/sitehostnz/gosh/pkg/utils"
)

// Get fetches a cloud db.
func (s *Client) Get(ctx context.Context, request GetRequest) (response GetResponse, err error) {
uri := "cloud/db/user/get.json"
keys := []string{
"apikey",
"client_id",
"server_name",
"mysql_host",
"username",
}

req, err := s.client.NewRequest("GET", uri, "")
if err != nil {
return response, err
}

v := req.URL.Query()
v.Add("api_key", s.client.APIKey)
v.Add("client_id", s.client.ClientID)
v.Add("server_name", request.ServerName)
v.Add("mysql_host", request.MySQLHost)
v.Add("username", request.Username)

req.URL.RawQuery = utils.Encode(v, keys)

if err := s.client.Do(ctx, req, &response); err != nil {
return response, err
}

return response, nil
}
27 changes: 27 additions & 0 deletions pkg/api/cloud/db/user/list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package user

import (
"context"
"github.com/sitehostnz/gosh/pkg/utils"
)

// List returns a list of cloud databases, specific to the customer.
func (s *Client) List(ctx context.Context, opt ListOptions) (response ListResponse, err error) {
uri := "cloud/db/user/list_all.json"

path, err := utils.AddOptions(uri, opt)
if err != nil {
return response, err
}

req, err := s.client.NewRequest("GET", path, "")
if err != nil {
return response, err
}

if err := s.client.Do(ctx, req, &response); err != nil {
return response, err
}

return response, nil
}
19 changes: 19 additions & 0 deletions pkg/api/cloud/db/user/models.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package user

import (
"github.com/sitehostnz/gosh/pkg/api"
)

type (
// Client is a Service to work with API Jobs.
Client struct {
client *api.Client
}
)

// New is an initialisation function.
func New(c *api.Client) *Client {
return &Client{
client: c,
}
}
Loading