basic.go 882 B

123456789101112131415161718192021222324252627282930313233343536
  1. package main
  2. import (
  3. "fmt"
  4. "net"
  5. "net/http"
  6. "os"
  7. "path/filepath"
  8. "time"
  9. )
  10. func main() {
  11. p, err := filepath.Abs(filepath.Join("run", "docker", "plugins"))
  12. if err != nil {
  13. panic(err)
  14. }
  15. if err := os.MkdirAll(p, 0o755); err != nil {
  16. panic(err)
  17. }
  18. l, err := net.Listen("unix", filepath.Join(p, "basic.sock"))
  19. if err != nil {
  20. panic(err)
  21. }
  22. mux := http.NewServeMux()
  23. server := http.Server{
  24. Addr: l.Addr().String(),
  25. Handler: http.NewServeMux(),
  26. ReadHeaderTimeout: 2 * time.Second, // This server is not for production code; picked an arbitrary timeout to statisfy gosec (G112: Potential Slowloris Attack)
  27. }
  28. mux.HandleFunc("/Plugin.Activate", func(w http.ResponseWriter, r *http.Request) {
  29. w.Header().Set("Content-Type", "application/vnd.docker.plugins.v1.1+json")
  30. fmt.Println(w, `{"Implements": ["dummy"]}`)
  31. })
  32. server.Serve(l)
  33. }