_acme-challenge record

master
Joshua Herring 1 month ago
parent 3a9175e5d7
commit 4e87b79ccf

@ -46,6 +46,11 @@ type model struct {
Host string Host string
LocalFilepath string LocalFilepath string
DestinationFilepath string DestinationFilepath string
CloudflareAPIToken string
ZoneID string
RecordName string
RecordValue string
} }
func (m model) DebugState() { func (m model) DebugState() {
@ -64,12 +69,17 @@ func (m *model) ReadForm() {
m.Host = m.form.GetString("host") m.Host = m.form.GetString("host")
m.LocalFilepath = m.form.GetString("local_filepath") m.LocalFilepath = m.form.GetString("local_filepath")
m.DestinationFilepath = m.form.GetString("destination_filepath") m.DestinationFilepath = m.form.GetString("destination_filepath")
m.CloudflareAPIToken = m.form.GetString("cloudflare_api_token")
m.ZoneID = m.form.GetString("zone_id")
m.RecordName = m.form.GetString("record_name")
m.RecordValue = m.form.GetString("record_value")
} }
func newModel() model { func newModel() model {
items := []list.Item{ items := []list.Item{
CommandItem{ItemTitle: "Run Command", ItemDescription: "Run a command on the remote host"}, CommandItem{ItemTitle: "Run Command", ItemDescription: "Run a command on the remote host"},
CommandItem{ItemTitle: "Upload File", ItemDescription: "Upload a file to the remote host"}, CommandItem{ItemTitle: "Upload File", ItemDescription: "Upload a file to the remote host"},
CommandItem{ItemTitle: "SSL DNS Challenge", ItemDescription: "Set an _acme-challenge TXT record"},
} }
l := list.New(items, list.NewDefaultDelegate(), 80, 20) l := list.New(items, list.NewDefaultDelegate(), 80, 20)
l.Title = "Commands" l.Title = "Commands"
@ -91,7 +101,7 @@ func execCommand(choice int, m model) tea.Cmd {
Username: m.Username, Username: m.Username,
Host: m.Host, Host: m.Host,
}, &buf, &buf) }, &buf, &buf)
} else { } else if choice == 1 {
err = commands.UploadFile(commands.UploadFileArgs{ err = commands.UploadFile(commands.UploadFileArgs{
LocalFilepath: m.LocalFilepath, LocalFilepath: m.LocalFilepath,
DestinationFilepath: m.DestinationFilepath, DestinationFilepath: m.DestinationFilepath,
@ -99,6 +109,13 @@ func execCommand(choice int, m model) tea.Cmd {
Username: m.Username, Username: m.Username,
Host: m.Host, Host: m.Host,
}, &buf, &buf) }, &buf, &buf)
} else {
err = commands.SetAcmeRecord(commands.SetAcmeRecordArgs{
APIToken: m.CloudflareAPIToken,
ZoneID: m.ZoneID,
RecordName: m.RecordName,
RecordValue: m.RecordValue,
}, &buf, &buf)
} }
if err != nil { if err != nil {
fmt.Fprintf(&buf, "\nError: %v", err) fmt.Fprintf(&buf, "\nError: %v", err)
@ -126,7 +143,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
huh.NewInput().Title("Host").Key("host").Value(&m.Host), huh.NewInput().Title("Host").Key("host").Value(&m.Host),
), ),
) )
} else { } else if m.choice == 1 {
m.form = huh.NewForm( m.form = huh.NewForm(
huh.NewGroup( huh.NewGroup(
huh.NewInput().Title("Local Filepath").Key("local_filepath").Value(&m.LocalFilepath), huh.NewInput().Title("Local Filepath").Key("local_filepath").Value(&m.LocalFilepath),
@ -136,6 +153,15 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
huh.NewInput().Title("Host").Key("host").Value(&m.Host), huh.NewInput().Title("Host").Key("host").Value(&m.Host),
), ),
) )
} else {
m.form = huh.NewForm(
huh.NewGroup(
huh.NewInput().Title("Cloudflare API Token").Key("cloudflare_api_token").Value(&m.CloudflareAPIToken),
huh.NewInput().Title("Zone ID").Key("zone_id").Value(&m.ZoneID),
huh.NewInput().Title("Record Name").Key("record_name").Value(&m.RecordName),
huh.NewInput().Title("Record Value").Key("record_value").Value(&m.RecordValue),
),
)
} }
return m, m.form.Init() return m, m.form.Init()
} }

Loading…
Cancel
Save