|
| 1 | +// Copyright (c) 2026 Keymaster Team |
| 2 | +// Keymaster - SSH key management system |
| 3 | +// This source code is licensed under the MIT license found in the LICENSE file. |
| 4 | +package client |
| 5 | + |
| 6 | +import ( |
| 7 | + "context" |
| 8 | + "log" |
| 9 | + "time" |
| 10 | + |
| 11 | + "github.com/toeirei/keymaster/internal/core" |
| 12 | +) |
| 13 | + |
| 14 | +type Client struct { |
| 15 | + config Config |
| 16 | + store core.Store |
| 17 | + // NOTE: |
| 18 | + // log != audit_log |
| 19 | + // log is not meant for cli out |
| 20 | + log *log.Logger |
| 21 | +} |
| 22 | + |
| 23 | +// --- Mock types that will later be imported or defined seperately --- |
| 24 | +type ID int |
| 25 | +type PublicKey struct{} |
| 26 | +type Target struct{} |
| 27 | +type Account struct{} |
| 28 | +type DeployProgress struct { |
| 29 | + Done bool |
| 30 | + // ... |
| 31 | +} |
| 32 | +type OnboardHostProgress struct { |
| 33 | + Done bool |
| 34 | + // ... |
| 35 | +} |
| 36 | +type DecommisionTargetProgress struct { |
| 37 | + Done bool |
| 38 | + // ... |
| 39 | +} |
| 40 | +type DecommisionAccountProgress struct { |
| 41 | + Done bool |
| 42 | + // ... |
| 43 | +} |
| 44 | + |
| 45 | +// --- Lifecycle & Initialization --- |
| 46 | + |
| 47 | +// connect to db, |
| 48 | +// auto migrate db to current version, |
| 49 | +// initialize store, |
| 50 | +// maybe run some offline chores |
| 51 | +func New(config Config, logger *log.Logger) (*Client, error) |
| 52 | + |
| 53 | +// cleans up and closes all open connections, |
| 54 | +// maybe be an ******* and set c to nil |
| 55 | +func (c *Client) Close(ctx context.Context) error |
| 56 | + |
| 57 | +// --- PublicKey Management --- |
| 58 | + |
| 59 | +func (c *Client) CreatePublicKey(ctx context.Context, identity string, tags []string) (ID, error) |
| 60 | +func (c *Client) GetPublicKey(ctx context.Context, id ID) (PublicKey, error) |
| 61 | +func (c *Client) GetPublicKeys(ctx context.Context, id ...ID) ([]PublicKey, error) |
| 62 | +func (c *Client) ListPublicKeys(ctx context.Context, tagFilter string) ([]PublicKey, error) |
| 63 | +func (c *Client) UpdatePublicKeyTags(ctx context.Context, id ID, tags []string) error |
| 64 | +func (c *Client) DeletePublicKeys(ctx context.Context, id ...ID) error |
| 65 | + |
| 66 | +// --- Target Management --- |
| 67 | + |
| 68 | +func (c *Client) CreateTarget(ctx context.Context, host string, port int /* , gateway string, plugin string */) (ID, error) |
| 69 | +func (c *Client) GetTarget(ctx context.Context, id ID) (Target, error) |
| 70 | +func (c *Client) GetTargets(ctx context.Context, id ...ID) ([]Target, error) |
| 71 | +func (c *Client) ListTargets(ctx context.Context) ([]Target, error) |
| 72 | +func (c *Client) UpdateTarget(ctx context.Context, id ID, target Target) error |
| 73 | +func (c *Client) DeleteTargets(ctx context.Context, id ...ID) error |
| 74 | + |
| 75 | +// --- Account Management --- |
| 76 | + |
| 77 | +func (c *Client) CreateAccount(ctx context.Context, targetID ID, name string, deploymentKey string) (ID, error) |
| 78 | +func (c *Client) GetAccount(ctx context.Context, id ID) (Account, error) |
| 79 | +func (c *Client) ListAccountsByTarget(ctx context.Context, targetID ID) ([]Account, error) |
| 80 | +func (c *Client) GetDirtyAccounts(ctx context.Context) ([]Account, error) |
| 81 | + |
| 82 | +// --- Tag to Account Management --- |
| 83 | + |
| 84 | +// LinkTagToAccount maps a tag filter (e.g. "device:mobile&company:telekom") to an account |
| 85 | +func (c *Client) LinkTagAccount(ctx context.Context, accountID ID, filter string, expiresAt time.Time) (ID, error) |
| 86 | +func (c *Client) UnLinkTagAccount(ctx context.Context, linkIDs ...ID) error |
| 87 | +func (c *Client) ResolvePublicKeysForAccount(ctx context.Context, accountID ID) ([]PublicKey, error) |
| 88 | +func (c *Client) ResolveAccountsForPublicKey(ctx context.Context, publicKeyID ID) ([]Account, error) |
| 89 | + |
| 90 | +// --- Onboarding & Decommision --- |
| 91 | + |
| 92 | +func (c *Client) OnboardHost(ctx context.Context, host string, port int /* , gateway string, plugin string */, accountName string, deploymentKey string) (chan OnboardHostProgress, error) |
| 93 | +func (c *Client) DecommisionTarget(ctx context.Context, id ID) (chan DecommisionTargetProgress, error) |
| 94 | +func (c *Client) DecommisionAccount(ctx context.Context, id ID) (chan DecommisionAccountProgress, error) |
| 95 | + |
| 96 | +// --- Deploy stuff --- |
| 97 | + |
| 98 | +// Deploy handles the plugin-based deployment to the target |
| 99 | +func (c *Client) DeployPublicKeys(ctx context.Context, publicKeyID ...ID) (chan DeployProgress, error) |
| 100 | +func (c *Client) DeployTargets(ctx context.Context, targetID ...ID) (chan DeployProgress, error) |
| 101 | +func (c *Client) DeployAccounts(ctx context.Context, accountID ...ID) (chan DeployProgress, error) |
| 102 | +func (c *Client) DeployAll(ctx context.Context) (chan DeployProgress, error) |
0 commit comments