# =cert <domain>: live TLS certificate expiry, issuer, SANs, chain, protocol.
# Network call: opens ONE TLS connection to port 443 of the typed host. The
# script runs openssl s_client | x509 itself (argv lists, no shell), because a
# bridge command cannot use a shell. It accepts a plain public hostname only:
# no scheme, path, port, IP address or spaces, nothing starting with a dash,
# and nothing that resolves to a private, loopback or link-local address. It
# connects to the exact address it checked.
#
# Sample data: `=cert demo` always shows a fabricated certificate. With no host
# typed the list opens on a "Try with sample data" row followed by the same
# rows. Every sample row says SAMPLE DATA. A typed host that fails gets honest
# error rows, never sample data.
schema_version: 1
runtime: bridge
id: cert
chip: cert
title: TLS certificate
icon: lock
description: "Network call: days left, issuer, SANs, chain and protocol of a live TLS certificate. =cert demo shows sample data"
placeholder_examples: ["sparcle.app", "github.com", "demo"]
emits: Generic

bridge:
  command:
    macos: "python3 {{scripts_dir}}/bolt-cert.py {{target}}"
    linux: "python3 {{scripts_dir}}/bolt-cert.py {{target}}"
    windows: "python {{scripts_dir}}/bolt-cert.py {{target}}"
  parse: json
  timeout_seconds: 25

args:
  - { name: target, from: "query.word(0)", default: "" }

presentation:
  widget: list
  title_field: title
  subtitle_field: subtitle
  right_widget:
    kind: entity_preview
    mode: selected_row
    bind:
      title: "{{row.host}}"
      subtitle: "{{row.title}}"
      fields:
        - { label: Days left, value: "{{row.days}}" }
        - { label: Expires, value: "{{row.expires}}" }
        - { label: Issuer, value: "{{row.issuer}}" }
        - { label: Protocol, value: "{{row.protocol}}" }
        - { label: Checked, value: "{{row.validation}}" }
      body: "{{row.body}}"
      actions: [copy-value, copy-host]

actions:
  - { id: copy-value, kind: composer, target: row, label: Copy value, insert: "{{row.value}}" }
  - { id: copy-host, kind: composer, target: row, label: Copy host, insert: "{{row.host}}" }
