Compare commits

..

8 Commits

Author SHA1 Message Date
amery 0233245c5b m/eu/k8s_token [DO-NOT-MERGE]
Signed-off-by: Alejandro Mery <amery@jpi.io>
2024-03-02 21:05:30 +00:00
amery fcb3f2e106 import m tree [DO-NOT-MERGE]
Signed-off-by: Alejandro Mery <amery@jpi.io>
2024-03-02 21:05:30 +00:00
amery 5e4adbfee5 Merge branch 'pr-amery-k8s_token' into next-amery 2024-03-02 21:04:54 +00:00
amery 3a19922b34 cluster: introduce Region.Cluster and m/{region}/k8s_token
Signed-off-by: Alejandro Mery <amery@jpi.io>
2024-03-02 20:59:01 +00:00
amery d51275fb1e cluster: extend usage of the ZoneRegionsFileName constant
Signed-off-by: Alejandro Mery <amery@jpi.io>
2024-03-02 20:59:01 +00:00
amery e97aaf9c8c Merge branch 'pr-amery-ceph' into next-amery 2024-03-02 19:18:37 +00:00
amery 5aab1a3303 ceph: prevent osd label update on startup
Signed-off-by: Alejandro Mery <amery@jpi.io>
2024-03-02 19:15:59 +00:00
amery 3c24e24d71 wireguard: switch from gcfg to asciigoat.org/ini/basic
Signed-off-by: Alejandro Mery <amery@jpi.io>
2024-03-02 18:58:39 +00:00
69 changed files with 931 additions and 164 deletions
-1
View File
@@ -1,2 +1 @@
.tmp
.version
+155
View File
@@ -0,0 +1,155 @@
dir: m
name: m
domain: jpi.cloud
ceph_fsid: 28180b9b-6d5d-4be0-bb5b-e4b04bf03804
regions:
- name: eu
cluster: K102eb227eec765a3389ba82944c0c78ab1f14f3b4383831f47416598e54d64abbb::server:567b2023506e45f7ec0009a991824f1c
regions:
- de
- nl
- name: earth
regions:
- europe
- us
- name: europe
regions:
- eu
- uk
zones:
- id: 1
name: ssd-lon
regions:
- uk
machines:
- id: 3
public:
- 63.250.53.5
- 2602:ff16:7:0:1:66:0:1
rings:
- ring: 0
enabled: true
keys:
privatekey: WJY1yrd14c0gY4qqq1O8BPck46TVYebXrT+OoMbEqG8=
publickey: aDXNwapVjufcuQKfBN+waJObe1TaeeaSNl1suA0u+00=
- ring: 1
enabled: true
keys:
privatekey: 2CDO+x8HVKfw1/iqC2WkwIEQyWZsC9XPW1otqxarR0o=
publickey: untmMfW2W4OiMgG/6nAysoivXtDh7cZ9/rxhgJ4OlC4=
- id: 4
ceph_monitor: true
public:
- 63.250.53.164
- 2602:ff16:7:0:1:50:0:1
rings:
- ring: 1
enabled: true
keys:
privatekey: wE05rSTPSlX9CUdyglpRsNqMVdh8bZSvmUlalGXArEE=
publickey: f7AcZy4H2qfi7BRtRA82VdJAqc+IXU90k88GKBp9piM=
- id: 5
public:
- 63.250.53.135
- 2602:ff16:7:0:1:156:0:1
rings:
- ring: 1
enabled: true
keys:
privatekey: oMLrZ8ZmNeWrVroGTh9lx9cJC1enWCF5VfIkv8t+jmk=
publickey: 9cUNKM8TPbD8BRjV7TG9/BuTq+2JO8KyrPCx69KW+Bk=
- id: 7
public:
- 107.155.122.3
- 2602:ff16:7:0:1:6d:0:1
rings:
- ring: 1
enabled: true
keys:
privatekey: iN4Rc3J36APlkIP/ksSpHIwAuxC/ehYLwGQ5va1AhG8=
publickey: XGVXDmxQajHpsgpzgrp+r/ZWxZUaodTpvGBJuLlZ0n4=
- id: 2
name: ssd-ams
regions:
- nl
machines:
- id: 3
public:
- 89.233.107.128
- 2602:ff16:9:0:1:1a7:0:1
rings:
- ring: 0
enabled: true
keys:
privatekey: oHVQY976pFH1lAhCrz9c40vR/e5PIXw7ZXv6pU6A5Ho=
publickey: y/Gkid2Mjxo1WO9Zi7mh+DETNYKT/AAc3K3bvr9xp3c=
- ring: 1
enabled: true
keys:
privatekey: 6I/ZMxaWUTbNc+SIGkNKxgovONqv6EAvg7NeeTRrR1c=
publickey: 9i0XI358OOYYoxoxV5lX8siqE8uiEwCsuWLo6LoFu0Y=
- id: 4
ceph_monitor: true
public:
- 89.233.107.251
- 2602:ff16:9:0:1:130:0:1
rings:
- ring: 1
enabled: true
keys:
privatekey: SPBd5Ka29ZecKYy7BW85rW7FO9dwKwoUHlSibybPG1s=
publickey: QpJupYlnJc7wc3+gAlEmbFMonsqpVnYRy7f/gnPqqBw=
- id: 5
inactive: true
public:
- 89.233.107.107
- 2602:ff16:9:0:1:74:0:1
rings:
- ring: 1
enabled: true
keys:
privatekey: mJaFvu9TBwE2i0rjhfhvpB3xZmp++3BVwa7QAvWXImY=
publickey: HDLVEwLv0uugyZ9C1C9ZWuiaWQ1qIqqe/DAUxYI0whM=
- id: 3
name: htz-fsn
regions:
- de
machines:
- id: 1
ceph_monitor: true
public:
- 157.90.209.125
- 2a01:4f8:252:168f::2
rings:
- ring: 0
enabled: true
keys:
privatekey: AMz/pCgOMVh1/2rT9uCFMox+LQgH5FrE4xUeqSs0x0M=
publickey: K9LYog8vtRFN4nW6dJWMQ9trmRrYuLpbu/Ze5kIiBGw=
- ring: 1
enabled: true
keys:
privatekey: 2JpA1G0Dp+sEuDhKnzToz0h76o2iLP+S7Qb9itlgXVA=
publickey: qWmYfgeRAQ563gWLdeYs65XjGJTSE+W8WTbpLZ0e1CQ=
- id: 4
name: ssd-nyc
regions:
- us
machines:
- id: 3
inactive: true
ceph_monitor: true
public:
- 208.87.134.41
- 2602:ff16:3:0:1:4fa:0:1
rings:
- ring: 0
enabled: true
keys:
privatekey: YNDxj+QSO3p5pXw9h7lBx0cLM0kJDv3v7BYLfc8TR3I=
publickey: 1UFgleUufTszPM1voIcwVhd0DpYZ1HwV05U6p3IS2DE=
- ring: 1
enabled: true
keys:
privatekey: APXGKqOxx1gOr587FSN3O3gRGpkGgSjt6zGlTu49UlU=
publickey: av8ni/9ZUyozabzqTjIy1sOnSJuQ9p63Tu9ECVmHB2I=
+2 -5
View File
@@ -2,8 +2,6 @@
package main
import (
_ "embed"
"github.com/spf13/cobra"
)
@@ -14,9 +12,8 @@ const (
var (
rootCmd = &cobra.Command{
Use: CmdName,
Short: "control tool for jpi.cloud",
Version: version,
Use: CmdName,
Short: "control tool for jpi.cloud",
}
)
-31
View File
@@ -1,31 +0,0 @@
package main
import (
_ "embed"
"fmt"
"os"
"github.com/spf13/cobra"
)
//go:generate sh -c "git describe | tr -d '\r\n' > .version"
//go:embed .version
var version string
var versionCmd = &cobra.Command{
Use: "version",
Short: "Returns jpictl's version",
Args: cobra.NoArgs,
Run: func(_ *cobra.Command, _ []string) {
_, _ = fmt.Fprintf(os.Stdout, "%s\n", version)
},
}
func init() {
if version == "" {
version = "undetermined"
}
rootCmd.AddCommand(versionCmd)
}
-2
View File
@@ -17,7 +17,6 @@ require (
github.com/spf13/cobra v1.8.0
golang.org/x/crypto v0.20.0
golang.org/x/net v0.21.0
gopkg.in/gcfg.v1 v1.2.3
gopkg.in/yaml.v3 v3.0.1
)
@@ -50,5 +49,4 @@ require (
golang.org/x/sys v0.17.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/tools v0.18.0 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
)
-4
View File
@@ -115,10 +115,6 @@ golang.org/x/tools v0.18.0 h1:k8NLag8AGHnn+PHbl7g43CtqZAwG60vZkLqgyZgIHgQ=
golang.org/x/tools v0.18.0/go.mod h1:GL7B4CwcLLeo59yx/9UWWuNOW1n3VZ4f5axWfML7Lcg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/gcfg.v1 v1.2.3 h1:m8OOJ4ccYHnx2f4gQwpno8nAX5OGOh7RLaaz0pj3Ogs=
gopkg.in/gcfg.v1 v1.2.3/go.mod h1:yesOnuUOFQAhST5vPY4nbZsb/huCgGGXlipJsBn0b3o=
gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME=
gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
+5
View File
@@ -0,0 +1,5 @@
[global]
fsid = 28180b9b-6d5d-4be0-bb5b-e4b04bf03804
mon_initial_members = ssd-lon-4, ssd-ams-4, htz-fsn-1, ssd-nyc-3
mon_host = 10.16.0.4, 10.32.0.4, 10.48.0.1, 10.64.0.3
cluster_network = 10.0.0.0/8
+2
View File
@@ -0,0 +1,2 @@
europe
us
+1
View File
@@ -0,0 +1 @@
K102eb227eec765a3389ba82944c0c78ab1f14f3b4383831f47416598e54d64abbb::server:567b2023506e45f7ec0009a991824f1c
+2
View File
@@ -0,0 +1,2 @@
de
nl
+2
View File
@@ -0,0 +1,2 @@
eu
uk
+24
View File
@@ -0,0 +1,24 @@
127.0.0.1 localhost
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
10.16.0.3 ssd-lon-3
10.16.0.4 ssd-lon-4 ssd-lon-ceph ssd-lon-k3s
10.16.0.5 ssd-lon-5
10.16.0.7 ssd-lon-7
10.32.0.3 ssd-ams-3
10.32.0.4 ssd-ams-4 ssd-ams-ceph ssd-ams-k3s
10.32.0.5 ssd-ams-5
10.48.0.1 htz-fsn-1 htz-fsn-ceph htz-fsn-k3s ceph k3s
10.64.0.3 ssd-nyc-3 ssd-nyc-ceph ssd-nyc-k3s
10.0.1.3 ssd-lon-3-0
10.0.2.3 ssd-ams-3-0
10.0.3.1 htz-fsn-1-0
10.0.4.3 ssd-nyc-3-0
+23
View File
@@ -0,0 +1,23 @@
[Interface]
# Name: htz-fsn-1-0
Address = 10.0.3.1
PrivateKey = AMz/pCgOMVh1/2rT9uCFMox+LQgH5FrE4xUeqSs0x0M=
ListenPort = 51800
[Peer]
# Name: ssd-lon-3-0
PublicKey = aDXNwapVjufcuQKfBN+waJObe1TaeeaSNl1suA0u+00=
Endpoint = ssd-lon-3.m.jpi.cloud:51800
AllowedIPs = 10.16.0.0/12, 10.0.1.3/32
[Peer]
# Name: ssd-ams-3-0
PublicKey = y/Gkid2Mjxo1WO9Zi7mh+DETNYKT/AAc3K3bvr9xp3c=
Endpoint = ssd-ams-3.m.jpi.cloud:51800
AllowedIPs = 10.32.0.0/12, 10.0.2.3/32
[Peer]
# Name: ssd-nyc-3-0
PublicKey = 1UFgleUufTszPM1voIcwVhd0DpYZ1HwV05U6p3IS2DE=
Endpoint = ssd-nyc-3.m.jpi.cloud:51800
AllowedIPs = 10.64.0.0/12, 10.0.4.3/32
+1
View File
@@ -0,0 +1 @@
AMz/pCgOMVh1/2rT9uCFMox+LQgH5FrE4xUeqSs0x0M=
+1
View File
@@ -0,0 +1 @@
K9LYog8vtRFN4nW6dJWMQ9trmRrYuLpbu/Ze5kIiBGw=
+5
View File
@@ -0,0 +1,5 @@
[Interface]
# Name: htz-fsn-1-1
Address = 10.48.0.1
PrivateKey = 2JpA1G0Dp+sEuDhKnzToz0h76o2iLP+S7Qb9itlgXVA=
ListenPort = 51810
+1
View File
@@ -0,0 +1 @@
2JpA1G0Dp+sEuDhKnzToz0h76o2iLP+S7Qb9itlgXVA=
+1
View File
@@ -0,0 +1 @@
qWmYfgeRAQ563gWLdeYs65XjGJTSE+W8WTbpLZ0e1CQ=
+1
View File
@@ -0,0 +1 @@
de
+1
View File
@@ -0,0 +1 @@
nl
+24
View File
@@ -0,0 +1,24 @@
127.0.0.1 localhost
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
10.16.0.3 ssd-lon-3
10.16.0.4 ssd-lon-4 ssd-lon-ceph ssd-lon-k3s
10.16.0.5 ssd-lon-5
10.16.0.7 ssd-lon-7
10.32.0.3 ssd-ams-3
10.32.0.4 ssd-ams-4 ssd-ams-ceph ssd-ams-k3s ceph k3s
10.32.0.5 ssd-ams-5
10.48.0.1 htz-fsn-1 htz-fsn-ceph htz-fsn-k3s
10.64.0.3 ssd-nyc-3 ssd-nyc-ceph ssd-nyc-k3s
10.0.1.3 ssd-lon-3-0
10.0.2.3 ssd-ams-3-0
10.0.3.1 htz-fsn-1-0
10.0.4.3 ssd-nyc-3-0
+23
View File
@@ -0,0 +1,23 @@
[Interface]
# Name: ssd-ams-3-0
Address = 10.0.2.3
PrivateKey = oHVQY976pFH1lAhCrz9c40vR/e5PIXw7ZXv6pU6A5Ho=
ListenPort = 51800
[Peer]
# Name: ssd-lon-3-0
PublicKey = aDXNwapVjufcuQKfBN+waJObe1TaeeaSNl1suA0u+00=
Endpoint = ssd-lon-3.m.jpi.cloud:51800
AllowedIPs = 10.16.0.0/12, 10.0.1.3/32
[Peer]
# Name: htz-fsn-1-0
PublicKey = K9LYog8vtRFN4nW6dJWMQ9trmRrYuLpbu/Ze5kIiBGw=
Endpoint = htz-fsn-1.m.jpi.cloud:51800
AllowedIPs = 10.48.0.0/12, 10.0.3.1/32
[Peer]
# Name: ssd-nyc-3-0
PublicKey = 1UFgleUufTszPM1voIcwVhd0DpYZ1HwV05U6p3IS2DE=
Endpoint = ssd-nyc-3.m.jpi.cloud:51800
AllowedIPs = 10.64.0.0/12, 10.0.4.3/32
+1
View File
@@ -0,0 +1 @@
oHVQY976pFH1lAhCrz9c40vR/e5PIXw7ZXv6pU6A5Ho=
+1
View File
@@ -0,0 +1 @@
y/Gkid2Mjxo1WO9Zi7mh+DETNYKT/AAc3K3bvr9xp3c=
+17
View File
@@ -0,0 +1,17 @@
[Interface]
# Name: ssd-ams-3-1
Address = 10.32.0.3
PrivateKey = 6I/ZMxaWUTbNc+SIGkNKxgovONqv6EAvg7NeeTRrR1c=
ListenPort = 51810
[Peer]
# Name: ssd-ams-4-1
PublicKey = QpJupYlnJc7wc3+gAlEmbFMonsqpVnYRy7f/gnPqqBw=
Endpoint = ssd-ams-4.m.jpi.cloud:51810
AllowedIPs = 10.32.0.4/32
[Peer]
# Name: ssd-ams-5-1
PublicKey = HDLVEwLv0uugyZ9C1C9ZWuiaWQ1qIqqe/DAUxYI0whM=
Endpoint = ssd-ams-5.m.jpi.cloud:51810
AllowedIPs = 10.32.0.5/32
+1
View File
@@ -0,0 +1 @@
6I/ZMxaWUTbNc+SIGkNKxgovONqv6EAvg7NeeTRrR1c=
+1
View File
@@ -0,0 +1 @@
9i0XI358OOYYoxoxV5lX8siqE8uiEwCsuWLo6LoFu0Y=
+24
View File
@@ -0,0 +1,24 @@
127.0.0.1 localhost
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
10.16.0.3 ssd-lon-3
10.16.0.4 ssd-lon-4 ssd-lon-ceph ssd-lon-k3s
10.16.0.5 ssd-lon-5
10.16.0.7 ssd-lon-7
10.32.0.3 ssd-ams-3
10.32.0.4 ssd-ams-4 ssd-ams-ceph ssd-ams-k3s ceph k3s
10.32.0.5 ssd-ams-5
10.48.0.1 htz-fsn-1 htz-fsn-ceph htz-fsn-k3s
10.64.0.3 ssd-nyc-3 ssd-nyc-ceph ssd-nyc-k3s
10.0.1.3 ssd-lon-3-0
10.0.2.3 ssd-ams-3-0
10.0.3.1 htz-fsn-1-0
10.0.4.3 ssd-nyc-3-0
+17
View File
@@ -0,0 +1,17 @@
[Interface]
# Name: ssd-ams-4-1
Address = 10.32.0.4
PrivateKey = SPBd5Ka29ZecKYy7BW85rW7FO9dwKwoUHlSibybPG1s=
ListenPort = 51810
[Peer]
# Name: ssd-ams-3-1
PublicKey = 9i0XI358OOYYoxoxV5lX8siqE8uiEwCsuWLo6LoFu0Y=
Endpoint = ssd-ams-3.m.jpi.cloud:51810
AllowedIPs = 10.32.0.3/32, 10.16.0.0/12, 10.48.0.0/12, 10.64.0.0/12, 10.0.1.3/32, 10.0.2.3/32, 10.0.3.1/32, 10.0.4.3/32
[Peer]
# Name: ssd-ams-5-1
PublicKey = HDLVEwLv0uugyZ9C1C9ZWuiaWQ1qIqqe/DAUxYI0whM=
Endpoint = ssd-ams-5.m.jpi.cloud:51810
AllowedIPs = 10.32.0.5/32
+1
View File
@@ -0,0 +1 @@
SPBd5Ka29ZecKYy7BW85rW7FO9dwKwoUHlSibybPG1s=
+1
View File
@@ -0,0 +1 @@
QpJupYlnJc7wc3+gAlEmbFMonsqpVnYRy7f/gnPqqBw=
+24
View File
@@ -0,0 +1,24 @@
127.0.0.1 localhost
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
10.16.0.3 ssd-lon-3
10.16.0.4 ssd-lon-4 ssd-lon-ceph ssd-lon-k3s
10.16.0.5 ssd-lon-5
10.16.0.7 ssd-lon-7
10.32.0.3 ssd-ams-3
10.32.0.4 ssd-ams-4 ssd-ams-ceph ssd-ams-k3s ceph k3s
10.32.0.5 ssd-ams-5
10.48.0.1 htz-fsn-1 htz-fsn-ceph htz-fsn-k3s
10.64.0.3 ssd-nyc-3 ssd-nyc-ceph ssd-nyc-k3s
10.0.1.3 ssd-lon-3-0
10.0.2.3 ssd-ams-3-0
10.0.3.1 htz-fsn-1-0
10.0.4.3 ssd-nyc-3-0
+1
View File
@@ -0,0 +1 @@
none
+17
View File
@@ -0,0 +1,17 @@
[Interface]
# Name: ssd-ams-5-1
Address = 10.32.0.5
PrivateKey = mJaFvu9TBwE2i0rjhfhvpB3xZmp++3BVwa7QAvWXImY=
ListenPort = 51810
[Peer]
# Name: ssd-ams-3-1
PublicKey = 9i0XI358OOYYoxoxV5lX8siqE8uiEwCsuWLo6LoFu0Y=
Endpoint = ssd-ams-3.m.jpi.cloud:51810
AllowedIPs = 10.32.0.3/32, 10.16.0.0/12, 10.48.0.0/12, 10.64.0.0/12, 10.0.1.3/32, 10.0.2.3/32, 10.0.3.1/32, 10.0.4.3/32
[Peer]
# Name: ssd-ams-4-1
PublicKey = QpJupYlnJc7wc3+gAlEmbFMonsqpVnYRy7f/gnPqqBw=
Endpoint = ssd-ams-4.m.jpi.cloud:51810
AllowedIPs = 10.32.0.4/32
+1
View File
@@ -0,0 +1 @@
mJaFvu9TBwE2i0rjhfhvpB3xZmp++3BVwa7QAvWXImY=
+1
View File
@@ -0,0 +1 @@
HDLVEwLv0uugyZ9C1C9ZWuiaWQ1qIqqe/DAUxYI0whM=
+1
View File
@@ -0,0 +1 @@
uk
+24
View File
@@ -0,0 +1,24 @@
127.0.0.1 localhost
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
10.16.0.3 ssd-lon-3
10.16.0.4 ssd-lon-4 ssd-lon-ceph ssd-lon-k3s ceph k3s
10.16.0.5 ssd-lon-5
10.16.0.7 ssd-lon-7
10.32.0.3 ssd-ams-3
10.32.0.4 ssd-ams-4 ssd-ams-ceph ssd-ams-k3s
10.32.0.5 ssd-ams-5
10.48.0.1 htz-fsn-1 htz-fsn-ceph htz-fsn-k3s
10.64.0.3 ssd-nyc-3 ssd-nyc-ceph ssd-nyc-k3s
10.0.1.3 ssd-lon-3-0
10.0.2.3 ssd-ams-3-0
10.0.3.1 htz-fsn-1-0
10.0.4.3 ssd-nyc-3-0
+23
View File
@@ -0,0 +1,23 @@
[Interface]
# Name: ssd-lon-3-0
Address = 10.0.1.3
PrivateKey = WJY1yrd14c0gY4qqq1O8BPck46TVYebXrT+OoMbEqG8=
ListenPort = 51800
[Peer]
# Name: ssd-ams-3-0
PublicKey = y/Gkid2Mjxo1WO9Zi7mh+DETNYKT/AAc3K3bvr9xp3c=
Endpoint = ssd-ams-3.m.jpi.cloud:51800
AllowedIPs = 10.32.0.0/12, 10.0.2.3/32
[Peer]
# Name: htz-fsn-1-0
PublicKey = K9LYog8vtRFN4nW6dJWMQ9trmRrYuLpbu/Ze5kIiBGw=
Endpoint = htz-fsn-1.m.jpi.cloud:51800
AllowedIPs = 10.48.0.0/12, 10.0.3.1/32
[Peer]
# Name: ssd-nyc-3-0
PublicKey = 1UFgleUufTszPM1voIcwVhd0DpYZ1HwV05U6p3IS2DE=
Endpoint = ssd-nyc-3.m.jpi.cloud:51800
AllowedIPs = 10.64.0.0/12, 10.0.4.3/32
+1
View File
@@ -0,0 +1 @@
WJY1yrd14c0gY4qqq1O8BPck46TVYebXrT+OoMbEqG8=
+1
View File
@@ -0,0 +1 @@
aDXNwapVjufcuQKfBN+waJObe1TaeeaSNl1suA0u+00=
+23
View File
@@ -0,0 +1,23 @@
[Interface]
# Name: ssd-lon-3-1
Address = 10.16.0.3
PrivateKey = 2CDO+x8HVKfw1/iqC2WkwIEQyWZsC9XPW1otqxarR0o=
ListenPort = 51810
[Peer]
# Name: ssd-lon-4-1
PublicKey = f7AcZy4H2qfi7BRtRA82VdJAqc+IXU90k88GKBp9piM=
Endpoint = ssd-lon-4.m.jpi.cloud:51810
AllowedIPs = 10.16.0.4/32
[Peer]
# Name: ssd-lon-5-1
PublicKey = 9cUNKM8TPbD8BRjV7TG9/BuTq+2JO8KyrPCx69KW+Bk=
Endpoint = ssd-lon-5.m.jpi.cloud:51810
AllowedIPs = 10.16.0.5/32
[Peer]
# Name: ssd-lon-7-1
PublicKey = XGVXDmxQajHpsgpzgrp+r/ZWxZUaodTpvGBJuLlZ0n4=
Endpoint = ssd-lon-7.m.jpi.cloud:51810
AllowedIPs = 10.16.0.7/32
+1
View File
@@ -0,0 +1 @@
2CDO+x8HVKfw1/iqC2WkwIEQyWZsC9XPW1otqxarR0o=
+1
View File
@@ -0,0 +1 @@
untmMfW2W4OiMgG/6nAysoivXtDh7cZ9/rxhgJ4OlC4=
+24
View File
@@ -0,0 +1,24 @@
127.0.0.1 localhost
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
10.16.0.3 ssd-lon-3
10.16.0.4 ssd-lon-4 ssd-lon-ceph ssd-lon-k3s ceph k3s
10.16.0.5 ssd-lon-5
10.16.0.7 ssd-lon-7
10.32.0.3 ssd-ams-3
10.32.0.4 ssd-ams-4 ssd-ams-ceph ssd-ams-k3s
10.32.0.5 ssd-ams-5
10.48.0.1 htz-fsn-1 htz-fsn-ceph htz-fsn-k3s
10.64.0.3 ssd-nyc-3 ssd-nyc-ceph ssd-nyc-k3s
10.0.1.3 ssd-lon-3-0
10.0.2.3 ssd-ams-3-0
10.0.3.1 htz-fsn-1-0
10.0.4.3 ssd-nyc-3-0
+23
View File
@@ -0,0 +1,23 @@
[Interface]
# Name: ssd-lon-4-1
Address = 10.16.0.4
PrivateKey = wE05rSTPSlX9CUdyglpRsNqMVdh8bZSvmUlalGXArEE=
ListenPort = 51810
[Peer]
# Name: ssd-lon-3-1
PublicKey = untmMfW2W4OiMgG/6nAysoivXtDh7cZ9/rxhgJ4OlC4=
Endpoint = ssd-lon-3.m.jpi.cloud:51810
AllowedIPs = 10.16.0.3/32, 10.32.0.0/12, 10.48.0.0/12, 10.64.0.0/12, 10.0.1.3/32, 10.0.2.3/32, 10.0.3.1/32, 10.0.4.3/32
[Peer]
# Name: ssd-lon-5-1
PublicKey = 9cUNKM8TPbD8BRjV7TG9/BuTq+2JO8KyrPCx69KW+Bk=
Endpoint = ssd-lon-5.m.jpi.cloud:51810
AllowedIPs = 10.16.0.5/32
[Peer]
# Name: ssd-lon-7-1
PublicKey = XGVXDmxQajHpsgpzgrp+r/ZWxZUaodTpvGBJuLlZ0n4=
Endpoint = ssd-lon-7.m.jpi.cloud:51810
AllowedIPs = 10.16.0.7/32
+1
View File
@@ -0,0 +1 @@
wE05rSTPSlX9CUdyglpRsNqMVdh8bZSvmUlalGXArEE=
+1
View File
@@ -0,0 +1 @@
f7AcZy4H2qfi7BRtRA82VdJAqc+IXU90k88GKBp9piM=
+24
View File
@@ -0,0 +1,24 @@
127.0.0.1 localhost
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
10.16.0.3 ssd-lon-3
10.16.0.4 ssd-lon-4 ssd-lon-ceph ssd-lon-k3s ceph k3s
10.16.0.5 ssd-lon-5
10.16.0.7 ssd-lon-7
10.32.0.3 ssd-ams-3
10.32.0.4 ssd-ams-4 ssd-ams-ceph ssd-ams-k3s
10.32.0.5 ssd-ams-5
10.48.0.1 htz-fsn-1 htz-fsn-ceph htz-fsn-k3s
10.64.0.3 ssd-nyc-3 ssd-nyc-ceph ssd-nyc-k3s
10.0.1.3 ssd-lon-3-0
10.0.2.3 ssd-ams-3-0
10.0.3.1 htz-fsn-1-0
10.0.4.3 ssd-nyc-3-0
+23
View File
@@ -0,0 +1,23 @@
[Interface]
# Name: ssd-lon-5-1
Address = 10.16.0.5
PrivateKey = oMLrZ8ZmNeWrVroGTh9lx9cJC1enWCF5VfIkv8t+jmk=
ListenPort = 51810
[Peer]
# Name: ssd-lon-3-1
PublicKey = untmMfW2W4OiMgG/6nAysoivXtDh7cZ9/rxhgJ4OlC4=
Endpoint = ssd-lon-3.m.jpi.cloud:51810
AllowedIPs = 10.16.0.3/32, 10.32.0.0/12, 10.48.0.0/12, 10.64.0.0/12, 10.0.1.3/32, 10.0.2.3/32, 10.0.3.1/32, 10.0.4.3/32
[Peer]
# Name: ssd-lon-4-1
PublicKey = f7AcZy4H2qfi7BRtRA82VdJAqc+IXU90k88GKBp9piM=
Endpoint = ssd-lon-4.m.jpi.cloud:51810
AllowedIPs = 10.16.0.4/32
[Peer]
# Name: ssd-lon-7-1
PublicKey = XGVXDmxQajHpsgpzgrp+r/ZWxZUaodTpvGBJuLlZ0n4=
Endpoint = ssd-lon-7.m.jpi.cloud:51810
AllowedIPs = 10.16.0.7/32
+1
View File
@@ -0,0 +1 @@
oMLrZ8ZmNeWrVroGTh9lx9cJC1enWCF5VfIkv8t+jmk=
+1
View File
@@ -0,0 +1 @@
9cUNKM8TPbD8BRjV7TG9/BuTq+2JO8KyrPCx69KW+Bk=
+24
View File
@@ -0,0 +1,24 @@
127.0.0.1 localhost
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
10.16.0.3 ssd-lon-3
10.16.0.4 ssd-lon-4 ssd-lon-ceph ssd-lon-k3s ceph k3s
10.16.0.5 ssd-lon-5
10.16.0.7 ssd-lon-7
10.32.0.3 ssd-ams-3
10.32.0.4 ssd-ams-4 ssd-ams-ceph ssd-ams-k3s
10.32.0.5 ssd-ams-5
10.48.0.1 htz-fsn-1 htz-fsn-ceph htz-fsn-k3s
10.64.0.3 ssd-nyc-3 ssd-nyc-ceph ssd-nyc-k3s
10.0.1.3 ssd-lon-3-0
10.0.2.3 ssd-ams-3-0
10.0.3.1 htz-fsn-1-0
10.0.4.3 ssd-nyc-3-0
+23
View File
@@ -0,0 +1,23 @@
[Interface]
# Name: ssd-lon-7-1
Address = 10.16.0.7
PrivateKey = iN4Rc3J36APlkIP/ksSpHIwAuxC/ehYLwGQ5va1AhG8=
ListenPort = 51810
[Peer]
# Name: ssd-lon-3-1
PublicKey = untmMfW2W4OiMgG/6nAysoivXtDh7cZ9/rxhgJ4OlC4=
Endpoint = ssd-lon-3.m.jpi.cloud:51810
AllowedIPs = 10.16.0.3/32, 10.32.0.0/12, 10.48.0.0/12, 10.64.0.0/12, 10.0.1.3/32, 10.0.2.3/32, 10.0.3.1/32, 10.0.4.3/32
[Peer]
# Name: ssd-lon-4-1
PublicKey = f7AcZy4H2qfi7BRtRA82VdJAqc+IXU90k88GKBp9piM=
Endpoint = ssd-lon-4.m.jpi.cloud:51810
AllowedIPs = 10.16.0.4/32
[Peer]
# Name: ssd-lon-5-1
PublicKey = 9cUNKM8TPbD8BRjV7TG9/BuTq+2JO8KyrPCx69KW+Bk=
Endpoint = ssd-lon-5.m.jpi.cloud:51810
AllowedIPs = 10.16.0.5/32
+1
View File
@@ -0,0 +1 @@
iN4Rc3J36APlkIP/ksSpHIwAuxC/ehYLwGQ5va1AhG8=
+1
View File
@@ -0,0 +1 @@
XGVXDmxQajHpsgpzgrp+r/ZWxZUaodTpvGBJuLlZ0n4=
+1
View File
@@ -0,0 +1 @@
us
+24
View File
@@ -0,0 +1,24 @@
127.0.0.1 localhost
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
10.16.0.3 ssd-lon-3
10.16.0.4 ssd-lon-4 ssd-lon-ceph ssd-lon-k3s
10.16.0.5 ssd-lon-5
10.16.0.7 ssd-lon-7
10.32.0.3 ssd-ams-3
10.32.0.4 ssd-ams-4 ssd-ams-ceph ssd-ams-k3s
10.32.0.5 ssd-ams-5
10.48.0.1 htz-fsn-1 htz-fsn-ceph htz-fsn-k3s
10.64.0.3 ssd-nyc-3 ssd-nyc-ceph ssd-nyc-k3s ceph k3s
10.0.1.3 ssd-lon-3-0
10.0.2.3 ssd-ams-3-0
10.0.3.1 htz-fsn-1-0
10.0.4.3 ssd-nyc-3-0
+1
View File
@@ -0,0 +1 @@
none
+23
View File
@@ -0,0 +1,23 @@
[Interface]
# Name: ssd-nyc-3-0
Address = 10.0.4.3
PrivateKey = YNDxj+QSO3p5pXw9h7lBx0cLM0kJDv3v7BYLfc8TR3I=
ListenPort = 51800
[Peer]
# Name: ssd-lon-3-0
PublicKey = aDXNwapVjufcuQKfBN+waJObe1TaeeaSNl1suA0u+00=
Endpoint = ssd-lon-3.m.jpi.cloud:51800
AllowedIPs = 10.16.0.0/12, 10.0.1.3/32
[Peer]
# Name: ssd-ams-3-0
PublicKey = y/Gkid2Mjxo1WO9Zi7mh+DETNYKT/AAc3K3bvr9xp3c=
Endpoint = ssd-ams-3.m.jpi.cloud:51800
AllowedIPs = 10.32.0.0/12, 10.0.2.3/32
[Peer]
# Name: htz-fsn-1-0
PublicKey = K9LYog8vtRFN4nW6dJWMQ9trmRrYuLpbu/Ze5kIiBGw=
Endpoint = htz-fsn-1.m.jpi.cloud:51800
AllowedIPs = 10.48.0.0/12, 10.0.3.1/32
+1
View File
@@ -0,0 +1 @@
YNDxj+QSO3p5pXw9h7lBx0cLM0kJDv3v7BYLfc8TR3I=
+1
View File
@@ -0,0 +1 @@
1UFgleUufTszPM1voIcwVhd0DpYZ1HwV05U6p3IS2DE=
+5
View File
@@ -0,0 +1,5 @@
[Interface]
# Name: ssd-nyc-3-1
Address = 10.64.0.3
PrivateKey = APXGKqOxx1gOr587FSN3O3gRGpkGgSjt6zGlTu49UlU=
ListenPort = 51810
+1
View File
@@ -0,0 +1 @@
APXGKqOxx1gOr587FSN3O3gRGpkGgSjt6zGlTu49UlU=
+1
View File
@@ -0,0 +1 @@
av8ni/9ZUyozabzqTjIy1sOnSJuQ9p63Tu9ECVmHB2I=
+28
View File
@@ -12,6 +12,10 @@ const (
// ZoneRegionsFileName indicates the file containing
// region names as references
ZoneRegionsFileName = "regions"
// RegionClusterTokenFileName contains the kubernetes
// token of the cluster this region represents
RegionClusterTokenFileName = "k8s_token"
)
func (m *Cluster) scan(opts *ScanOptions) error {
@@ -186,6 +190,8 @@ func (z *Zone) scan() error {
switch {
case name == ZoneRegionsFileName:
err = z.loadRegions()
case name == RegionClusterTokenFileName:
err = z.loadClusterToken()
case e.IsDir():
err = z.scanSubdirectory(name)
default:
@@ -218,6 +224,28 @@ func (z *Zone) loadRegions() error {
return err
}
func (z *Zone) loadClusterToken() error {
filename := path.Join(z.Name, RegionClusterTokenFileName)
lines, err := z.zones.ReadLines(filename)
if err == nil {
var token string
for _, s := range lines {
if s != "" {
token = s
break
}
}
err = z.zones.setRegionClusterToken(z.Name, token)
if err != nil {
err = core.Wrap(err, filename)
}
}
return err
}
func (z *Zone) scanSubdirectory(name string) error {
m := &Machine{
zone: z,
+63 -9
View File
@@ -16,6 +16,7 @@ type Region struct {
zones []*Zone
Name string
Cluster *string `json:",omitempty" yaml:",omitempty"`
Regions []string `json:",omitempty" yaml:",omitempty"`
}
@@ -106,6 +107,26 @@ func (m *Cluster) setRegionZones(name string, zones ...*Zone) {
})
}
func (m *Cluster) setRegionClusterToken(name string, token string) error {
for i := range m.Regions {
r := &m.Regions[i]
if r.Name == name {
// found
r.Cluster = &token
return nil
}
}
// new
m.Regions = append(m.Regions, Region{
m: m,
Name: name,
Cluster: &token,
})
return nil
}
func (m *Cluster) appendRegionRegions(name string, subs ...string) {
for i := range m.Regions {
r := &m.Regions[i]
@@ -191,7 +212,7 @@ func (z *Zone) SyncRegions() error {
}
func (z *Zone) syncZoneRegions() error {
name := filepath.Join(z.Name, "regions")
name := filepath.Join(z.Name, ZoneRegionsFileName)
if len(z.Regions) > 0 {
var buf bytes.Buffer
@@ -210,9 +231,25 @@ func (z *Zone) syncZoneRegions() error {
// SyncRegions writes to the file system the regions covered
// by this meta-region
func (r *Region) SyncRegions() error {
name := filepath.Join(r.Name, "regions")
if err := r.syncRegionsFile(); err != nil {
return err
}
if len(r.Regions) > 0 {
return r.syncClusterFile()
}
func (r *Region) mkdir() error {
return r.m.MkdirAll(r.Name)
}
func (r *Region) syncRegionsFile() error {
var err error
name := filepath.Join(r.Name, ZoneRegionsFileName)
if len(r.Regions) == 0 {
err = r.m.RemoveFile(name)
} else if err = r.mkdir(); err == nil {
var buf bytes.Buffer
for _, s := range r.Regions {
@@ -220,12 +257,29 @@ func (r *Region) SyncRegions() error {
_, _ = buf.WriteRune('\n')
}
if err := r.m.MkdirAll(r.Name); err != nil {
return err
}
return r.m.WriteStringFile(buf.String(), name)
err = r.m.WriteStringFile(buf.String(), name)
}
return r.m.RemoveFile(name)
return err
}
func (r *Region) syncClusterFile() error {
var err error
name := filepath.Join(r.Name, RegionClusterTokenFileName)
if r.Cluster == nil {
err = r.m.RemoveFile(name)
} else if err = r.mkdir(); err == nil {
var buf bytes.Buffer
_, _ = buf.WriteString(*r.Cluster)
if buf.Len() > 0 {
_, _ = buf.WriteRune('\n')
}
err = r.m.WriteStringFile(buf.String(), name)
}
return err
}
+9 -112
View File
@@ -2,7 +2,6 @@ package wireguard
import (
"bytes"
"errors"
"fmt"
"io"
"net/netip"
@@ -10,8 +9,8 @@ import (
"strings"
"text/template"
"asciigoat.org/ini/basic"
"darvaza.org/core"
"gopkg.in/gcfg.v1"
)
var configTemplate = template.Must(template.New("config").Funcs(template.FuncMap{
@@ -132,100 +131,6 @@ func (ep *EndpointAddress) FromString(s string) error {
return nil
}
type intermediateConfig struct {
Interface interfaceConfig
Peer peersConfig
}
func (v *intermediateConfig) Export() (*Config, error) {
var out Config
var err error
// Interface
out.Interface, err = v.Interface.Export()
if err != nil {
return nil, err
}
// Peers
peers, ok := v.PeersCount()
if !ok {
return nil, errors.New("inconsistent Peer data")
}
for i := 0; i < peers; i++ {
p, err := v.ExportPeer(i)
if err != nil {
err = core.Wrap(err, "Peer[%v]:", i)
return nil, err
}
out.Peer = append(out.Peer, p)
}
return &out, nil
}
type interfaceConfig struct {
Address netip.Addr
PrivateKey string
ListenPort uint16
}
func (p interfaceConfig) Export() (InterfaceConfig, error) {
var err error
out := InterfaceConfig{
Address: p.Address,
ListenPort: p.ListenPort,
}
if p.PrivateKey != "" {
out.PrivateKey, err = PrivateKeyFromBase64(p.PrivateKey)
if err != nil {
err = core.Wrap(err, "PrivateKey")
return InterfaceConfig{}, err
}
}
return out, nil
}
type peersConfig struct {
PublicKey []string
Endpoint []string
AllowedIPs []string
}
func (v *intermediateConfig) ExportPeer(i int) (PeerConfig, error) {
var out PeerConfig
// Endpoint
s := v.Peer.Endpoint[i]
err := out.Endpoint.FromString(s)
if err != nil {
err = core.Wrap(err, "Endpoint")
return out, err
}
// PublicKey
out.PublicKey, err = PublicKeyFromBase64(v.Peer.PublicKey[i])
if err != nil {
err = core.Wrap(err, "PublicKey")
return out, err
}
// AllowedIPs
s = v.Peer.AllowedIPs[i]
out.AllowedIPs, err = parseAllowedIPs(s)
if err != nil {
err = core.Wrap(err, "AllowedIPs")
return out, err
}
return out, nil
}
func parseAllowedIPs(data string) ([]netip.Prefix, error) {
var out []netip.Prefix
@@ -242,25 +147,17 @@ func parseAllowedIPs(data string) ([]netip.Prefix, error) {
return out, nil
}
func (v *intermediateConfig) PeersCount() (int, bool) {
c0 := len(v.Peer.Endpoint)
c1 := len(v.Peer.PublicKey)
c2 := len(v.Peer.AllowedIPs)
if c0 != c1 || c1 != c2 {
return 0, false
}
return c0, true
}
// NewConfigFromReader parses a wgN.conf file
func NewConfigFromReader(r io.Reader) (*Config, error) {
temp := &intermediateConfig{}
if err := gcfg.ReadInto(temp, r); err != nil {
doc, err := basic.Decode(r)
if err != nil {
return nil, err
}
return temp.Export()
cfg, err := newConfigFromDocument(doc)
if err != nil {
return nil, err
}
return cfg, nil
}
+169
View File
@@ -0,0 +1,169 @@
package wireguard
import (
"io/fs"
"strconv"
"asciigoat.org/ini/basic"
"darvaza.org/core"
)
type sectionHandler func(*Config, *basic.Section) error
var sectionMap = map[string]func(*Config, *basic.Section) error{
"Interface": loadInterfaceConfSection,
"Peer": loadPeerConfSection,
}
func loadConfSection(out *Config, src *basic.Section) error {
h, ok := sectionMap[src.Key]
if !ok {
return core.Wrap(fs.ErrInvalid, "unknown section %q", src.Key)
}
return h(out, src)
}
func loadInterfaceConfSection(out *Config, src *basic.Section) error {
var cfg InterfaceConfig
for _, field := range src.Fields {
if err := loadInterfaceConfField(&cfg, field); err != nil {
return core.Wrap(err, "Interface")
}
}
out.Interface = cfg
return nil
}
func loadPeerConfSection(out *Config, src *basic.Section) error {
var cfg PeerConfig
for _, field := range src.Fields {
if err := loadPeerConfField(&cfg, field); err != nil {
return core.Wrap(err, "Peer[%v]", len(out.Peer))
}
}
out.Peer = append(out.Peer, cfg)
return nil
}
// revive:disable:cyclomatic
// revive:disable:cognitive-complexity
func loadInterfaceConfField(cfg *InterfaceConfig, field basic.Field) error {
// revive:enable:cyclomatic
// revive:enable:cognitive-complexity
// TODO: refactor when asciigoat's ini parser learns to do reflection
switch field.Key {
case "Address":
if !core.IsZero(cfg.Address) {
return core.Wrap(fs.ErrInvalid, "duplicate field %q", field.Key)
}
err := cfg.Address.UnmarshalText([]byte(field.Value))
switch {
case err != nil:
return core.Wrap(err, field.Key)
default:
return nil
}
case "PrivateKey":
if !core.IsZero(cfg.PrivateKey) {
return core.Wrap(fs.ErrInvalid, "duplicate field %q", field.Key)
}
err := cfg.PrivateKey.UnmarshalText([]byte(field.Value))
switch {
case err != nil:
return core.Wrap(err, field.Key)
default:
return nil
}
case "ListenPort":
if cfg.ListenPort > 0 {
return core.Wrap(fs.ErrInvalid, "duplicate field %q", field.Key)
}
u64, err := strconv.ParseUint(field.Value, 10, 16)
switch {
case err != nil:
return core.Wrap(err, field.Key)
case u64 == 0:
return core.Wrap(fs.ErrInvalid, "invalid %q value", field.Key)
default:
cfg.ListenPort = uint16(u64)
return nil
}
default:
return core.Wrap(fs.ErrInvalid, "unknown field %q", field.Key)
}
}
// revive:disable:cyclomatic
// revive:disable:cognitive-complexity
func loadPeerConfField(cfg *PeerConfig, field basic.Field) error {
// revive:enable:cyclomatic
// revive:enable:cognitive-complexity
switch field.Key {
case "PublicKey":
if !core.IsZero(cfg.PublicKey) {
return core.Wrap(fs.ErrInvalid, "duplicate field %q", field.Key)
}
err := cfg.PublicKey.UnmarshalText([]byte(field.Value))
switch {
case err != nil:
return core.Wrap(err, field.Key)
default:
return nil
}
case "Endpoint":
if cfg.Endpoint.String() != "" {
return core.Wrap(fs.ErrInvalid, "duplicate field %q", field.Key)
}
err := cfg.Endpoint.UnmarshalText([]byte(field.Value))
switch {
case err != nil:
return core.Wrap(err, field.Key)
default:
return nil
}
case "AllowedIPs":
s, err := parseAllowedIPs(field.Value)
switch {
case err != nil:
return core.Wrap(err, field.Key)
case len(s) > 0:
cfg.AllowedIPs = append(cfg.AllowedIPs, s...)
return nil
}
default:
return core.Wrap(fs.ErrInvalid, "unknown field %q", field.Key)
}
return nil
}
func newConfigFromDocument(doc *basic.Document) (*Config, error) {
var out Config
if len(doc.Global) > 0 {
err := core.Wrap(fs.ErrInvalid, "fields before the first section")
return nil, err
}
for i := range doc.Sections {
src := &doc.Sections[i]
if err := loadConfSection(&out, src); err != nil {
return nil, err
}
}
return &out, nil
}