Skip to content

Commit 221d159

Browse files
authored
docs: add missing import (#5500)
1 parent fd03db4 commit 221d159

File tree

1 file changed

+30
-28
lines changed

1 file changed

+30
-28
lines changed

docs/registry/txt.md

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -115,37 +115,39 @@ In some cases you might need to edit registry TXT records. The following example
115115
package main
116116

117117
import (
118-
"fmt"
119-
"sigs.k8s.io/external-dns/endpoint"
118+
b64 "encoding/base64"
119+
"fmt"
120+
121+
"sigs.k8s.io/external-dns/endpoint"
120122
)
121123

122124
func main() {
123-
keys := []string{
124-
"ZPitL0NGVQBZbTD6DwXJzD8RiStSazzYXQsdUowLURY=", // safe base64 url encoded 44 bytes and 32 when decoded
125-
"01234567890123456789012345678901", // plain txt 32 bytes
126-
"passphrasewhichneedstobe32bytes!", // plain txt 32 bytes
127-
}
128-
129-
for _, k := range keys {
130-
key := []byte(k)
131-
if len(key) != 32 {
132-
// if key is not a plain txt let's decode
133-
var err error
134-
if key, err = b64.StdEncoding.DecodeString(string(key)); err != nil || len(key) != 32 {
135-
fmt.Errorf("the AES Encryption key must have a length of 32 byte")
136-
}
137-
}
138-
encrypted, _ := endpoint.EncryptText(
139-
"heritage=external-dns,external-dns/owner=example,external-dns/resource=ingress/default/example",
140-
key,
141-
nil,
142-
)
143-
decrypted, _, err := endpoint.DecryptText(encrypted, key)
144-
if err != nil {
145-
fmt.Println("Error decrypting:", err, "for key:", k)
146-
}
147-
fmt.Println(decrypted)
148-
}
125+
keys := []string{
126+
"ZPitL0NGVQBZbTD6DwXJzD8RiStSazzYXQsdUowLURY=", // safe base64 url encoded 44 bytes and 32 when decoded
127+
"01234567890123456789012345678901", // plain txt 32 bytes
128+
"passphrasewhichneedstobe32bytes!", // plain txt 32 bytes
129+
}
130+
131+
for _, k := range keys {
132+
key := []byte(k)
133+
if len(key) != 32 {
134+
// if key is not a plain txt let's decode
135+
var err error
136+
if key, err = b64.StdEncoding.DecodeString(string(key)); err != nil || len(key) != 32 {
137+
fmt.Errorf("the AES Encryption key must have a length of 32 byte")
138+
}
139+
}
140+
encrypted, _ := endpoint.EncryptText(
141+
"heritage=external-dns,external-dns/owner=example,external-dns/resource=ingress/default/example",
142+
key,
143+
nil,
144+
)
145+
decrypted, _, err := endpoint.DecryptText(encrypted, key)
146+
if err != nil {
147+
fmt.Println("Error decrypting:", err, "for key:", k)
148+
}
149+
fmt.Println(decrypted)
150+
}
149151
}
150152
```
151153

0 commit comments

Comments
 (0)