Skip to content

Commit

Permalink
Merge pull request #47 from iljaSL/api-endpoint/get-host
Browse files Browse the repository at this point in the history
add a new API endpoint, get host
  • Loading branch information
kimmokssh committed Mar 15, 2021
2 parents b1e9a26 + b64b18e commit ba782d6
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 8 deletions.
18 changes: 18 additions & 0 deletions api/hoststore/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
package hoststore

import (
"net/url"

"github.com/SSHcom/privx-sdk-go/restapi"
)

Expand All @@ -15,12 +17,28 @@ type HostStore struct {
api restapi.Connector
}

type hostResult struct {
Count int `json:"count"`
Items []Host `json:"items"`
}

// New creates a new host-store client instance
// See http://apispecs.ssh.com/#swagger-ui-4 for details about api
func New(api restapi.Connector) *HostStore {
return &HostStore{api: api}
}

// Host returns existing single host
func (store *HostStore) Host(id string) (host *Host, err error) {
host = new(Host)

_, err = store.api.
URL("/host-store/api/v1/hosts/%s", url.PathEscape(id)).
Get(host)

return
}

// RegisterHost append a target to PrivX
func (store *HostStore) RegisterHost(host Host) (string, error) {
var id struct {
Expand Down
56 changes: 48 additions & 8 deletions api/hoststore/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,58 @@ type Service struct {

// Principal of the target host
type Principal struct {
ID string `json:"principal"`
Roles []rolestore.RoleRef `json:"roles"`
Source Source `json:"source"`
ID string `json:"principal"`
Roles []rolestore.RoleRef `json:"roles"`
Source Source `json:"source"`
UseUserAccount bool `json:"use_user_account"`
Passphrase string `json:"passphrase"`
Applications []string `json:"applications"`
}

// SSHPublicKey host public keys
type SSHPublicKey struct {
Key string `json:"key,omitempty"`
Fingerprint string `json:"fingerprint,omitempty"`
}

// Status of the secret object
type Status struct {
K string `json:"k,omitempty"`
V string `json:"v,omitempty"`
}

// Host defines PrivX target
type Host struct {
ID string `json:"id,omitempty"`
Name string `json:"common_name,omitempty"`
Addresses []Address `json:"addresses,omitempty"`
Services []Service `json:"services,omitempty"`
Principals []Principal `json:"principals,omitempty"`
ID string `json:"id,omitempty"`
AccessGroupID string `json:"access_group_id,omitempty"`
ExternalID string `json:"external_id,omitempty"`
InstanceID string `json:"instance_id,omitempty"`
SourceID string `json:"source_id,omitempty"`
Name string `json:"common_name,omitempty"`
ContactAdress string `json:"contact_address,omitempty"`
CloudProvider string `json:"cloud_provider,omitempty"`
CloudProviderRegion string `json:"cloud_provider_region,omitempty"`
Created string `json:"created,omitempty"`
Updated string `json:"updated,omitempty"`
UpdatedBy string `json:"updated_by,omitempty"`
DistinguishedName string `json:"distinguished_name,omitempty"`
Organization string `json:"organization,omitempty"`
OrganizationUnit string `json:"organizational_unit,omitempty"`
Zone string `json:"zone,omitempty"`
HostType string `json:"host_type,omitempty"`
HostClassification string `json:"host_classification,omitempty"`
Comment string `json:"comment,omitempty"`
Deployable bool `json:"deployable,omitempty"`
Tofu bool `json:"tofu,omitempty"`
StandAlone bool `json:"stand_alone_host,omitempty"`
Audit bool `json:"audit_enabled,omitempty"`
Scope []string `json:"scope,omitempty"`
Tags []string `json:"tags,omitempty"`
Addresses []Address `json:"addresses,omitempty"`
Services []Service `json:"services,omitempty"`
Principals []Principal `json:"principals,omitempty"`
PublicKeys []SSHPublicKey `json:"ssh_host_public_keys,omitempty"`
Status []Status `json:"status,omitempty"`
}

// Service creates a corresponding service definition
Expand Down

0 comments on commit ba782d6

Please sign in to comment.