diff --git a/api/connectionmanager/client.go b/api/connectionmanager/client.go index 2026c2c..84435ff 100644 --- a/api/connectionmanager/client.go +++ b/api/connectionmanager/client.go @@ -8,7 +8,6 @@ package connectionmanager import ( "net/url" - "time" "github.com/SSHcom/privx-sdk-go/api/filters" "github.com/SSHcom/privx-sdk-go/api/response" @@ -67,15 +66,6 @@ func (c *ConnectionManager) SearchConnections(search *ConnectionSearch, opts ... connections := &response.ResultSet[Connection]{} params := url.Values{} - // Define default connected start time if empty (similar on how UI is handling start time). - if search != nil && search.Connected == nil { - search = &ConnectionSearch{ - Connected: &TimestampSearch{ - Start: time.Now().UTC().AddDate(0, 0, -8).Format("2006-01-02T15:04:05.000Z"), - }, - } - } - // Set default options, which will be overwritten by opts if defined. options := append([]filters.Option{ filters.Paging(0, 25), diff --git a/api/monitor/client.go b/api/monitor/client.go index 5a92f6c..bf9ddfc 100644 --- a/api/monitor/client.go +++ b/api/monitor/client.go @@ -9,7 +9,6 @@ package monitor import ( "encoding/json" "net/url" - "time" "github.com/SSHcom/privx-sdk-go/api/filters" "github.com/SSHcom/privx-sdk-go/api/response" @@ -44,13 +43,6 @@ func (c *Monitor) SearchAuditEvents(search *AuditEventSearch, opts ...filters.Op events := &response.ResultSet[AuditEvent]{} params := url.Values{} - // Define default start time if empty (similar on how UI is handling start time). - if search != nil && search.StartTime == "" { - search = &AuditEventSearch{ - StartTime: time.Now().UTC().AddDate(0, 0, -8).Format("2006-01-02T15:04:05.000Z"), - } - } - // Set default options, which will be overwritten by opts if defined. options := append([]filters.Option{ filters.Paging(0, 25), diff --git a/common/model.go b/common/model.go deleted file mode 100644 index 7c1d066..0000000 --- a/common/model.go +++ /dev/null @@ -1,22 +0,0 @@ -package common - -import "time" - -// KeyValue key value definition -type KeyValue struct { - Key string `json:"k"` - Value string `json:"v"` -} - -// ServiceStatus service status definition -type ServiceStatus struct { - Variant string `json:"variant,omitempty"` - Version string `json:"version,omitempty"` - APIVersion string `json:"api_version,omitempty"` - Status string `json:"status,omitempty"` - StatusMessage string `json:"status_message,omitempty"` - ApplicationID string `json:"app_id,omitempty"` - ServerMode string `json:"server-mode,omitempty"` - StatusDetails []KeyValue `json:"status_details,omitempty"` - StartTime time.Time `json:"start_time,omitempty"` -} diff --git a/styleguide.md b/styleguide.md new file mode 100644 index 0000000..79eaf55 --- /dev/null +++ b/styleguide.md @@ -0,0 +1,79 @@ +# PrivX SDK Style Guide + +The are a few guidelines to follow when developing or contributing to the PrivX Go SDK. +This documentation should help to point out those guidelines and read before opening a pull request in order to keep the SDK consistent. + +# Table of content +- [Creating And Initializing New Client](#creating-and-initializing-new-client) +- [Adding New Handlers And Models](#adding-new-handlers-and-models) + - [Naming Conventions for Handler Functions](#naming-conventions-for-handler-functions) + - [Parameter Ordering in Handler Functions](#parameter-ordering-in-handler-functions) + - [Return Types for Handler Functions](#return-types-for-handler-functions) + +## Creating And Initializing New Client + +When adding a new client (service) to the SDK, this should be done in the `api` directory. +The package name should be the service name that is new and is not yet defined in the `api` directory. +Create a new directory inside `api` with the name of the service and the corresponding files `model.go` which should contain any struct definitions and a `client.go` file containing the API methods and the client constructor. + +The client should be initialized as follow: +```go +type Client struct { + api restapi.Connector +} + +func New(api restapi.Connector) *Client { + return &Client{api: api} +} +``` + +There is no need to add the service name to any struct or constructor. +It will be verbose enough when the client is eventually imported and initialized. + +```go +// initializing new client +client := rolestore.New(api) +``` + +## Adding New Handlers And Models + +### Naming Conventions for Handler Functions + +Handler function names should follow a consistent structure: +* Start with a verb describing the action +* Follow the verb with the subject (the source of the endpoint) + +Example: +``` + func (c *HostStore) GetHosts() {...} // (get multiple entries) + func (c *HostStore) GetHost() {...} // (get one entry) + func (c *HostStore) CreateHost() {...} + func (c *HostStore) DeleteHost() {...} + func (c *HostStore) UpdateHost() {...} + func (c *HostStore) SearchHosts() {...} +``` + +### Parameter Ordering in Handler Functions + +When a function requires parameters, they should be ordered as follows: +* The ID (or multiple IDs, if applicable) of the source must always come first +* Any additional parameters with basic types (e.g., string, int) should follow the IDs +* If required, a structured request body should come after basic-type parameters +* End with variadic options, e.g., opts ...filters.Option + +Example: +``` + func (c *HostStore) UpdateHost(hostID string, host *Host, opts ...filters.Option) {...} +``` + +### Return Types for Handler Functions + +For handlers returning multiple entries, always use the generic `ResultSet` type from the `response` package which has the Count and Item fields defined. + +Example: +``` +func (c *HostStore) GetHosts(...) (*response.ResultSet[Host], error) +``` +This standardizes response behavior across all handlers, addressing inconsistencies in earlier SDK versions. Avoid returning raw slices like `[]Host`. + +For handlers that return an ID (e.g., when creating entries), use the `Identifier` type from the `response` package.