Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Changelog
All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
## [v0.6.x] - 2025-08-15
### Added
- Cloud stack environment delete variables
- SRS list domains
- SRS list contacts
-
### Fixed
- Added handling of null json types to maybe bool, which will evaluate to false, since they are falsy in js
- Updated dependencies
- Fixes in DNS handling - split out Get and Search endpoints - lament the pagination.



## [v0.6.0] - 2025-06-17
### Fixed
Expand All @@ -9,6 +21,7 @@ All notable changes to this project will be documented in this file. The format
- Update pr make file to use golangci-lint GitHub action.
- Split url helpers and type helpers in to their own packages.


## [v0.5.0] - 2025-06-12
### Added
- Added support for all endpoints under `/server/firewall/`.
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/cloud/db/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type (
Database models.Database `json:"return"`
models.APIResponse
}
// ListResponse is the returned response from the List endpoint.
// ListResponse is the returned response from the ListDomains endpoint.
ListResponse struct {
Return struct {
Databases []models.Database `json:"data"`
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/cloud/db/user/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
)

type (
// ListResponse is the returned response from the List endpoint.
// ListResponse is the returned response from the ListDomains endpoint.
ListResponse struct {
Return struct {
Users []models.DatabaseUser `json:"data"`
Expand Down
45 changes: 45 additions & 0 deletions pkg/api/cloud/stack/environment/delete.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package environment

import (
"context"
"fmt"
"net/url"

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

// Update applies updates to the stacks environment.

Check failure on line 11 in pkg/api/cloud/stack/environment/delete.go

View workflow job for this annotation

GitHub Actions / go-lint

exported: comment on exported method Client.Delete should be of the form "Delete ..." (revive)
func (s *Client) Delete(ctx context.Context, request DeleteRequest) (response DeleteResponse, err error) {
uri := "cloud/stack/environment/delete.json"
keys := []string{
"client_id",
"server",
"project",
"service",
}

values := url.Values{}
values.Add("client_id", s.client.ClientID)
values.Add("server", request.ServerName)
values.Add("project", request.Project)
values.Add("service", request.Service)

args := make([]string, len(request.EnvironmentVariables))
i := 0
for x, v := range request.EnvironmentVariables {
args[i] = fmt.Sprintf("variables[%d][name]", x)
values.Add(args[i], v.Name)
i++
}

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

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

return response, nil
}
8 changes: 8 additions & 0 deletions pkg/api/cloud/stack/environment/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,12 @@ type (
Service string `json:"service"`
EnvironmentVariables []models.EnvironmentVariable
}

// DeleteRequest is a request to remove variables from a stack environment.
DeleteRequest struct {
ServerName string `json:"server"`
Project string `json:"project"`
Service string `json:"service"`
EnvironmentVariables []models.EnvironmentVariable
}
)
13 changes: 11 additions & 2 deletions pkg/api/cloud/stack/environment/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,26 @@ package environment
import "github.com/sitehostnz/gosh/pkg/models"

type (
// GetResponse is the response that returns a stacks environment variables.
// GetResponse is the response contains the results of a call to get an environment.
// It contains the environment details and variables.
GetResponse struct {
EnvironmentVariables []models.EnvironmentVariable `json:"return"`
models.APIResponse
}

// UpdateResponse is the result of updating an environment on a stack.
// UpdateResponse is the result of adding or updating variables in a stack environment.
UpdateResponse struct {
Return struct {
models.Job `json:"job"`
} `json:"return"`
models.APIResponse
}

// DeleteResponse is the result of deleting variables from a stack environment.
DeleteResponse struct {
Return struct {
models.Job `json:"job"`
} `json:"return"`
models.APIResponse
}
)
10 changes: 5 additions & 5 deletions pkg/api/cloud/stack/environment/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"net/url"
"strings"

"github.com/sitehostnz/gosh/pkg/net"
)
Expand Down Expand Up @@ -31,11 +32,10 @@ func (s *Client) Update(ctx context.Context, request UpdateRequest) (response Up
values.Add(args[i], v.Name)
i++

if v.Content != "" {
args[i] = fmt.Sprintf("variables[%d][content]", x)
values.Add(args[i], v.Content)
i++
}
// we're allowed empty strings here now, as properties need to be explicitly removed
args[i] = fmt.Sprintf("variables[%d][content]", x)
values.Add(args[i], strings.TrimSpace(v.Content))
i++
}

req, err := s.client.NewRequest("POST", uri, net.Encode(values, append(keys, args...)))
Expand Down
47 changes: 37 additions & 10 deletions pkg/api/dns/zoneget.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,35 @@

import (
"context"
"net/url"

"github.com/sitehostnz/gosh/pkg/net"
"net/url"

Check failure on line 6 in pkg/api/dns/zoneget.go

View workflow job for this annotation

GitHub Actions / go-lint

File is not properly formatted (gci)
)

// GetZone searches for a domain in the DNS made easy service
// by sending a request with a query containing the domain name.
// If the response contains any matching domain, it returns it as part of the GetZoneResponse.
// If the response is empty, a control to handle this case is missing and should be added.
func (s *Client) GetZone(ctx context.Context, request GetZoneRequest) (response GetZoneResponse, err error) {

Check failure on line 10 in pkg/api/dns/zoneget.go

View workflow job for this annotation

GitHub Actions / go-lint

File is not properly formatted (gofumpt)
resp, err := s.SearchZone(ctx, SearchZoneRequest{
Query: request.DomainName,
Limit: 1,
})

if err != nil {
return response, err
}

response.APIResponse = resp.APIResponse

// iterate over the domains to find the one we are looking for.
// Since we've set a limit ths should be one...
if len(resp.Return) > 0 {
response.Return = resp.Return[0]
}
return response, nil
}

// SearchZone searches for a domain in the DNS service
// by sending a request with a query containing the domain name.
// Matching domains are included in the SearchZoneResponse.
func (s *Client) SearchZone(ctx context.Context, request SearchZoneRequest) (response SearchZoneResponse, err error) {
u := "dns/search_domains.json"

keys := []string{
Expand All @@ -21,18 +40,26 @@

values := url.Values{}
values.Add("client_id", s.client.ClientID)
values.Add("query[domain]", request.DomainName)
values.Add("query[domain]", request.Query)

// would like to do this, but it's kinda not... working
//if request.Offset > 0 {

Check failure on line 46 in pkg/api/dns/zoneget.go

View workflow job for this annotation

GitHub Actions / go-lint

commentFormatting: put a space between `//` and comment text (gocritic)
// keys = append(keys, "offset[offset]")
// values.Add("offset[offset]", strconv.Itoa(request.Offset))
//}
//
//if request.Limit > 0 {
// keys = append(keys, "offset[limit]")
// values.Add("offset[limit]", strconv.Itoa(request.Limit))
//}

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

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

// TODO add control for empty response

return response, nil
}
6 changes: 6 additions & 0 deletions pkg/api/dns/zonerequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
DomainName string `json:"name"`
}

SearchZoneRequest struct {

Check failure on line 9 in pkg/api/dns/zonerequest.go

View workflow job for this annotation

GitHub Actions / go-lint

exported: exported type SearchZoneRequest should have comment or be unexported (revive)
Query string `json:"query"`
Offset int `json:"offset"`
Limit int `json:"limit"`
}

// CreateZoneRequest represents a request to create a DNSZone (domain).
CreateZoneRequest struct {
DomainName string `json:"name"`
Expand Down
11 changes: 9 additions & 2 deletions pkg/api/dns/zoneresponse.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,18 @@
models.APIResponse
}

// GetZoneResponse represents a request to get a DNSZone (domain).
GetZoneResponse struct {
// SearchZoneResponse represents a request to search for a Domain (domain).
SearchZoneResponse struct {
Return []struct {
Name string `json:"name"`
} `json:"return"`
models.APIResponse
}

GetZoneResponse struct {

Check failure on line 39 in pkg/api/dns/zoneresponse.go

View workflow job for this annotation

GitHub Actions / go-lint

exported: exported type GetZoneResponse should have comment or be unexported (revive)
Return struct {
Name string `json:"name"`
} `json:"return"`
models.APIResponse
}
)
1 change: 1 addition & 0 deletions pkg/api/srs/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package srs

Check failure on line 1 in pkg/api/srs/doc.go

View workflow job for this annotation

GitHub Actions / go-lint

package-comments: should have a package comment (revive)
20 changes: 20 additions & 0 deletions pkg/api/srs/list_contacts.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package srs

import (
"context"
)

// ListContacts the domain name contacts

Check failure on line 7 in pkg/api/srs/list_contacts.go

View workflow job for this annotation

GitHub Actions / go-lint

Comment should end in a period (godot)
func (s *Client) ListContacts(ctx context.Context) (response ListContactsResponse, err error) {
u := "srs/list_contacts.json"
req, err := s.client.NewRequest("GET", u, "")
if err != nil {
return response, err
}

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

return response, nil
}
20 changes: 20 additions & 0 deletions pkg/api/srs/list_domains.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package srs

import (
"context"
)

// ListDomains the registered domain names

Check failure on line 7 in pkg/api/srs/list_domains.go

View workflow job for this annotation

GitHub Actions / go-lint

Comment should end in a period (godot)
func (s *Client) ListDomains(ctx context.Context) (response ListDomainsResponse, err error) {
u := "srs/list_domains.json"
req, err := s.client.NewRequest("GET", u, "")
if err != nil {
return response, err
}

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

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

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

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

// New is used to instantiate the Client struct.
func New(c *api.Client) *Client {
return &Client{
client: c,
}
}
7 changes: 7 additions & 0 deletions pkg/api/srs/request.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package srs

//type (

Check failure on line 3 in pkg/api/srs/request.go

View workflow job for this annotation

GitHub Actions / go-lint

commentFormatting: put a space between `//` and comment text (gocritic)
// ListRequest struct {
// // Domain string `json:"domain"`
// }
//)
19 changes: 19 additions & 0 deletions pkg/api/srs/response.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package srs

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

type (
ListDomainsResponse struct {
Return struct {
models.Pagination
Domains []models.Domain `json:"data"`
} `json:"return"`
models.APIResponse
}

ListContactsResponse struct {
DomainContacts []models.DomainContact `json:"return"`

models.APIResponse
}
)
Loading
Loading