Skip to content

Commit ee849ab

Browse files
committed
feat: new binary name
1 parent cad54a9 commit ee849ab

File tree

4 files changed

+51
-40
lines changed

4 files changed

+51
-40
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@
1313

1414
.idea/
1515
/goacmedns-register
16+
/goacmedns

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ check:
1212
golangci-lint run
1313

1414
build:
15-
go build -ldflags "-s -w" -trimpath ./cmd/goacmedns-register/
15+
go build -ldflags "-s -w" -trimpath ./cmd/goacmedns/

README.md

Lines changed: 49 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,35 @@
11
# goacmedns
22

3-
A Go library to handle [acme-dns](https://github.com/joohoi/acme-dns) client
4-
communication and persistent account storage.
3+
A Go library to handle [acme-dns](https://github.com/joohoi/acme-dns) client communication and persistent account storage.
54

65
[![CI Status](https://github.com/nrdcg/goacmedns/workflows/Go/badge.svg)](https://github.com/nrdcg/goacmedns/actions?query=workflow%3AGo)
76
[![Lint Status](https://github.com/nrdcg/goacmedns/workflows/golangci-lint/badge.svg)](https://github.com/nrdcg/goacmedns/actions?query=workflow%3Agolangci-lint)
87
[![Go Report Card](https://goreportcard.com/badge/github.com/nrdcg/goacmedns)](https://goreportcard.com/report/github.com/nrdcg/goacmedns)
98

10-
You may also be interested in a Python equivalent,
11-
[pyacmedns](https://github.com/joohoi/pyacmedns/).
9+
You may also be interested in a Python equivalent [pyacmedns](https://github.com/joohoi/pyacmedns/).
1210

13-
# Installation
11+
## Installation
1412

15-
Once you have [installed Go](https://golang.org/doc/install) 1.15+ you can
16-
install `goacmedns` with `go get`:
13+
Once you have [installed Go](https://golang.org/doc/install) 1.21+ you can install `goacmedns` with `go install`:
1714

18-
go get github.com/nrdcg/goacmedns/...
15+
```bash
16+
go install github.com/nrdcg/goacmedns/cmd/goacmedns@latest
17+
```
1918

20-
# Usage
19+
## Usage
2120

22-
The following is a short example of using the library to update a TXT record
23-
served by an `acme-dns` instance.
21+
The following is a short example of using the library to update a TXT record served by an `acme-dns` instance.
2422

2523
```go
2624
package main
2725

2826
import (
27+
"context"
28+
"errors"
2929
"log"
3030

3131
"github.com/nrdcg/goacmedns"
32+
"github.com/nrdcg/goacmedns/storage"
3233
)
3334

3435
const (
@@ -41,53 +42,62 @@ var (
4142

4243
func main() {
4344
// Initialize the client. Point it towards your acme-dns instance.
44-
client := goacmedns.NewClient("https://auth.acme-dns.io")
45-
// Initialize the storage. If the file does not exist, it will be
46-
// automatically created.
47-
storage := goacmedns.NewFileStorage("/tmp/storage.json", 0600)
48-
49-
// Check if credentials were previously saved for your domain
50-
account, err := storage.Fetch(domain)
51-
if err != nil && err != goacmedns.ErrDomainNotFound {
52-
log.Fatal(err)
53-
} else if err == goacmedns.ErrDomainNotFound {
54-
// The account did not exist. Let's create a new one
55-
// The whitelisted networks parameter is optional and can be nil
56-
newAcct, err := client.RegisterAccount(whitelistedNetworks)
45+
client, err := goacmedns.NewClient("https://auth.acme-dns.io")
46+
47+
ctx := context.Background()
48+
49+
// Initialize the storage.
50+
// If the file does not exist, it will be automatically created.
51+
st := storage.NewFile("/tmp/storage.json", 0600)
52+
53+
// Check if credentials were previously saved for your domain.
54+
account, err := st.Fetch(ctx, domain)
55+
if err != nil {
56+
if !errors.Is(err, storage.ErrDomainNotFound) {
57+
log.Fatal(err)
58+
}
59+
60+
// The account did not exist.
61+
// Let's create a new one The whitelisted networks parameter is optional and can be nil.
62+
newAcct, err := client.RegisterAccount(ctx, whitelistedNetworks)
5763
if err != nil {
5864
log.Fatal(err)
5965
}
66+
6067
// Save it
61-
err = storage.Put(domain, newAcct)
68+
err = st.Put(ctx, domain, newAcct)
6269
if err != nil {
6370
log.Fatalf("Failed to put account in storage: %v", err)
6471
}
65-
err = storage.Save()
72+
73+
err = st.Save(ctx)
6674
if err != nil {
6775
log.Fatalf("Failed to save storage: %v", err)
6876
}
77+
6978
account = newAcct
7079
}
7180

72-
// Update the acme-dns TXT record
73-
err = client.UpdateTXTRecord(account, "___validation_token_recieved_from_the_ca___")
81+
// Update the acme-dns TXT record.
82+
err = client.UpdateTXTRecord(ctx, account, "___validation_token_recieved_from_the_ca___")
7483
if err != nil {
7584
log.Fatal(err)
7685
}
7786
}
7887
```
7988

80-
# Pre-Registration
89+
## Pre-Registration
8190

82-
When using `goacmedns` with an ACME client hook it may be desirable to do the
83-
initial ACME-DNS account creation and CNAME delegation ahead of time The
84-
`goacmedns-register` command line utility provides an easy way to do this:
91+
When using `goacmedns` with an ACME client hook
92+
it may be desirable to do the initial ACME-DNS account creation and CNAME delegation ahead of time.
8593

86-
go install github.com/nrdcg/goacmedns/...
87-
goacmedns-register -api http://10.0.0.1:4443 -domain example.com -allowFrom 192.168.100.1/24,1.2.3.4/32,2002:c0a8:2a00::0/40 -storage /tmp/example.storage.json
94+
The `goacmedns` command line utility provides an easy way to do this:
95+
96+
```bash
97+
go install github.com/nrdcg/goacmedns/cmd/goacmedns@latest
98+
99+
goacmedns -api http://10.0.0.1:4443 -domain example.com -allowFrom 192.168.100.1/24,1.2.3.4/32,2002:c0a8:2a00::0/40 -storage /tmp/example.storage.json
100+
```
88101

89-
This will register an account for `example.com` that is only usable from the
90-
specified CIDR `-allowFrom` networks with the ACME-DNS server at
91-
`http://10.0.0.1:4443`, saving the account details in
92-
`/tmp/example.storage.json` and printing the required CNAME record for the
93-
`example.com` DNS zone to stdout.
102+
This will register an account for `example.com` that is only usable from the specified CIDR `-allowFrom` networks with the ACME-DNS server at `http://10.0.0.1:4443`,
103+
saving the account details in `/tmp/example.storage.json` and printing the required CNAME record for the `example.com` DNS zone to stdout.
File renamed without changes.

0 commit comments

Comments
 (0)