tangled
alpha
login
or
join now
quietengineer.fyi
/
pdsadmin
0
fork
atom
Go implementation of pdsadmin cli
0
fork
atom
overview
issues
1
pulls
pipelines
feat: add requestCrawl command
quietengineer.fyi
10 months ago
dcfe53b1
2aa10ca7
+99
2 changed files
expand all
collapse all
unified
split
pdsadmin
cmd
requestCrawl.go
sample.config.yaml
+97
pdsadmin/cmd/requestCrawl.go
···
1
1
+
/*
2
2
+
Copyright © 2025 QuietEngineer <qtengineer@proton.me>
3
3
+
4
4
+
Permission is hereby granted, free of charge, to any person obtaining a copy
5
5
+
of this software and associated documentation files (the "Software"), to deal
6
6
+
in the Software without restriction, including without limitation the rights
7
7
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
8
+
copies of the Software, and to permit persons to whom the Software is
9
9
+
furnished to do so, subject to the following conditions:
10
10
+
11
11
+
The above copyright notice and this permission notice shall be included in
12
12
+
all copies or substantial portions of the Software.
13
13
+
14
14
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
15
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
16
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
17
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
18
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
19
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
20
+
THE SOFTWARE.
21
21
+
*/
22
22
+
package cmd
23
23
+
24
24
+
import (
25
25
+
"bytes"
26
26
+
"encoding/json"
27
27
+
"fmt"
28
28
+
"io"
29
29
+
"net/http"
30
30
+
"os"
31
31
+
"strings"
32
32
+
33
33
+
"github.com/spf13/cobra"
34
34
+
"github.com/spf13/viper"
35
35
+
)
36
36
+
37
37
+
type SyncRequestCrawl_Input struct {
38
38
+
// hostname: Hostname of the current service (eg, PDS) that is requesting to be crawled.
39
39
+
Hostname string `json:"hostname"`
40
40
+
}
41
41
+
42
42
+
// requestCrawlCmd represents the requestCrawl command
43
43
+
var requestCrawlCmd = &cobra.Command{
44
44
+
Use: "requestCrawl",
45
45
+
Short: "Request a crawl from a relay host",
46
46
+
Example: `pdsadmin requestCrawl bsky.network
47
47
+
pdsadmin requestCrawl bsky.network,second-relay.example.com`,
48
48
+
Args: cobra.MaximumNArgs(1),
49
49
+
Run: func(cmd *cobra.Command, args []string) {
50
50
+
var relayHosts []string
51
51
+
if len(args) == 1 {
52
52
+
relayHosts = strings.Split(args[0], ",")
53
53
+
} else {
54
54
+
relayHosts = viper.GetStringSlice("crawlers")
55
55
+
}
56
56
+
if len(relayHosts) == 0 {
57
57
+
fmt.Println("ERROR: missing RELAY HOST parameter")
58
58
+
os.Exit(1)
59
59
+
}
60
60
+
61
61
+
client := &http.Client{}
62
62
+
for _, host := range relayHosts {
63
63
+
if host == "" {
64
64
+
continue
65
65
+
}
66
66
+
fmt.Printf("Requesting crawl from %s\n", host)
67
67
+
if !strings.HasPrefix(host, "https:") && !strings.HasPrefix(host, "http:") {
68
68
+
host = fmt.Sprintf("https://%s", host)
69
69
+
}
70
70
+
body := SyncRequestCrawl_Input{
71
71
+
Hostname: viper.GetString("hostname"),
72
72
+
}
73
73
+
jsonBody, err := json.Marshal(body)
74
74
+
if err != nil {
75
75
+
fmt.Printf("could not create json body: %s\n", err)
76
76
+
continue
77
77
+
}
78
78
+
bodyReader := bytes.NewReader(jsonBody)
79
79
+
80
80
+
res, err := client.Post(fmt.Sprintf("%s/xrpc/com.atproto.sync.requestCrawl", host), "application/json", bodyReader)
81
81
+
if err != nil {
82
82
+
fmt.Printf("error making http request: %s\n", err)
83
83
+
continue
84
84
+
}
85
85
+
86
86
+
if _, err := io.ReadAll(res.Body); err != nil {
87
87
+
fmt.Printf("could not read response body: %s\n", err)
88
88
+
continue
89
89
+
}
90
90
+
}
91
91
+
fmt.Println("done")
92
92
+
},
93
93
+
}
94
94
+
95
95
+
func init() {
96
96
+
rootCmd.AddCommand(requestCrawlCmd)
97
97
+
}
+2
pdsadmin/sample.config.yaml
···
1
1
admin_password: a_secure_password
2
2
hostname: pds.example.com # without protocol (https) or path
3
3
+
crawlers:
4
4
+
- bsky.network