Skip to content

Commit

Permalink
Merge pull request #60 from vst/58-add-external-id-to-host-definition…
Browse files Browse the repository at this point in the history
…-in-configuration

External ID and Extra Data Fields for Host Spec
  • Loading branch information
vst authored Apr 8, 2024
2 parents fedc233 + b6996b0 commit 17190d3
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 1 deletion.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,18 @@ hosts:
destination: [email protected]
## SSH options (optional)
options: ["-i", "/keys/hebele.pri"]
## External identifier of the host (optional)
id: 20b88669-743f-4ae5-9823-5aacc2df7086
## External URL for the host (optional)
url: https://internal.documentation/hosts/somehost
## List of tags for the host (optional)
tags:
- oranges
- strawberries
## Arbitrary JSON data for the host (optional)
data:
owner: Client-1
cost: 50
- name: otherhost
url: https://internal.documentation/hosts/otherhost
tags:
Expand Down
6 changes: 6 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,18 @@ hosts:
destination: [email protected]
## SSH options (optional)
options: ["-i", "/keys/hebele.pri"]
## External identifier of the host (optional)
id: 20b88669-743f-4ae5-9823-5aacc2df7086
## External URL for the host (optional)
url: https://internal.documentation/hosts/somehost
## List of tags for the host (optional)
tags:
- oranges
- strawberries
## Arbitrary JSON data for the host (optional)
data:
owner: Client-1
cost: 50
- name: otherhost
url: https://internal.documentation/hosts/otherhost
tags:
Expand Down
10 changes: 9 additions & 1 deletion src/Lhp/Cli.hs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,15 @@ doCompile cpath dests par = do
Left err -> BLC.hPutStrLn stderr (Aeson.encode err) >> pure (ExitFailure 1)
Right sr -> BLC.putStrLn (Aeson.encode sr) >> pure ExitSuccess
where
_mkHost d = Types.Host {Types._hostName = d, Types._hostSsh = Nothing, Types._hostUrl = Nothing, Types._hostTags = []}
_mkHost d =
Types.Host
{ Types._hostName = d
, Types._hostSsh = Nothing
, Types._hostId = Nothing
, Types._hostUrl = Nothing
, Types._hostTags = []
, Types._hostData = Aeson.Null
}


-- ** schema
Expand Down
4 changes: 4 additions & 0 deletions src/Lhp/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@ instance ADC.HasCodec Report where
data Host = Host
{ _hostName :: !T.Text
, _hostSsh :: !(Maybe SshConfig)
, _hostId :: !(Maybe T.Text)
, _hostUrl :: !(Maybe T.Text)
, _hostTags :: ![T.Text]
, _hostData :: !Aeson.Value
}
deriving (Eq, Generic, Show)
deriving (Aeson.FromJSON, Aeson.ToJSON) via (ADC.Autodocodec Host)
Expand All @@ -62,8 +64,10 @@ instance ADC.HasCodec Host where
Host
<$> ADC.requiredField "name" "Name of the host." ADC..= _hostName
<*> ADC.optionalField "ssh" "SSH configuration." ADC..= _hostSsh
<*> ADC.optionalField "id" "External identifier of the host." ADC..= _hostId
<*> ADC.optionalField "url" "URL to external host information." ADC..= _hostUrl
<*> ADC.optionalFieldWithDefault "tags" [] "Arbitrary tags for the host." ADC..= _hostTags
<*> ADC.optionalFieldWithDefault "data" Aeson.Null "Arbitrary data for the host." ADC..= _hostData


-- * Host Report
Expand Down
18 changes: 18 additions & 0 deletions website/src/components/report/ShowHostDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ export function ShowHostDetails({ host }: { host: LhpHostReport }) {
🔗
</Link>
)}
{host.host.id && (
<Chip
onClick={() => {
navigator.clipboard.writeText(host.host.id || '');
toast('External host identifier is copied to clipboard.');
}}
>
<span className="cursor-pointer">{host.host.id}</span>
</Chip>
)}
</div>

<div className="align-items flex flex-row items-center space-x-4">
Expand Down Expand Up @@ -139,6 +149,14 @@ export function ShowHostDetails({ host }: { host: LhpHostReport }) {

<KVBox title="Systemd Timers" kvs={host.systemdTimers.map((x) => ({ key: x, value: '✅' }))} />
</div>

<Card radius="sm" shadow="sm">
<CardHeader className="text-lg font-bold">Extra Host Data</CardHeader>

<CardBody>
<pre>{host.host.data ? JSON.stringify(host.host.data || '#N/A', null, 2) : '#N/A'}</pre>
</CardBody>
</Card>
</div>
);
}
2 changes: 2 additions & 0 deletions website/src/lib/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ export const LHP_PATROL_REPORT_SCHEMA = {
host: {
$comment: 'Host descriptor.\nHost Descriptor\nHost',
properties: {
data: { $comment: 'Arbitrary data for the host.' },
id: { $comment: 'External identifier of the host.', type: 'string' },
name: { $comment: 'Name of the host.', type: 'string' },
ssh: {
$comment: 'SSH configuration.\nSSH Configuration\nSshConfig',
Expand Down

0 comments on commit 17190d3

Please sign in to comment.