2023-07-27 20:17:41 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"github.com/openziti/zrok/environment"
|
2023-11-21 20:27:17 +01:00
|
|
|
"github.com/openziti/zrok/sdk/golang/sdk"
|
2023-07-27 20:17:41 +02:00
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
2023-07-27 20:31:15 +02:00
|
|
|
const MAX_PASTE_SIZE = 64 * 1024
|
|
|
|
|
2023-07-27 20:17:41 +02:00
|
|
|
func main() {
|
|
|
|
if len(os.Args) < 2 {
|
|
|
|
panic("usage: pastefrom <shrToken>")
|
|
|
|
}
|
|
|
|
shrToken := os.Args[1]
|
|
|
|
|
|
|
|
root, err := environment.LoadRoot()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
acc, err := sdk.CreateAccess(root, &sdk.AccessRequest{ShareToken: shrToken})
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
defer func() {
|
|
|
|
if err := sdk.DeleteAccess(root, acc); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
conn, err := sdk.NewDialer(shrToken, root)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
defer func() {
|
|
|
|
_ = conn.Close()
|
|
|
|
}()
|
|
|
|
|
2023-07-27 20:31:15 +02:00
|
|
|
buf := make([]byte, MAX_PASTE_SIZE)
|
2023-07-27 20:17:41 +02:00
|
|
|
n, err := conn.Read(buf)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2023-07-31 19:53:49 +02:00
|
|
|
fmt.Printf(string(buf[:n]))
|
2023-07-27 20:17:41 +02:00
|
|
|
}
|