MCPcopy
hub / github.com/nektos/act / StartHandler

Function StartHandler

pkg/artifactcache/handler.go:48–127  ·  view source on GitHub ↗
(dir, customExternalURL string, outboundIP string, port uint16, logger logrus.FieldLogger)

Source from the content-addressed store, hash-verified

46}
47
48func StartHandler(dir, customExternalURL string, outboundIP string, port uint16, logger logrus.FieldLogger) (*Handler, error) {
49 h := &Handler{}
50
51 if logger == nil {
52 discard := logrus.New()
53 discard.Out = io.Discard
54 logger = discard
55 }
56 logger = logger.WithField("module", "artifactcache")
57 h.logger = logger
58
59 if dir == "" {
60 home, err := os.UserHomeDir()
61 if err != nil {
62 return nil, err
63 }
64 dir = filepath.Join(home, ".cache", "actcache")
65 }
66 if err := os.MkdirAll(dir, 0o755); err != nil {
67 return nil, err
68 }
69
70 h.dir = dir
71
72 storage, err := NewStorage(filepath.Join(dir, "cache"))
73 if err != nil {
74 return nil, err
75 }
76 h.storage = storage
77
78 if customExternalURL != "" {
79 h.customExternalURL = customExternalURL
80 }
81
82 if outboundIP != "" {
83 h.outboundIP = outboundIP
84 } else if ip := common.GetOutboundIP(); ip == nil {
85 return nil, fmt.Errorf("unable to determine outbound IP address")
86 } else {
87 h.outboundIP = ip.String()
88 }
89
90 tokenBytes := make([]byte, 16)
91 if _, err := rand.Read(tokenBytes); err != nil {
92 return nil, fmt.Errorf("generate auth token: %w", err)
93 }
94 h.token = hex.EncodeToString(tokenBytes)
95
96 router := httprouter.New()
97 base := "/" + h.token + apiPath
98 router.GET(base+"/cache", h.middleware(h.find))
99 router.POST(base+"/caches", h.middleware(h.reserve))
100 router.PATCH(base+"/caches/:id", h.middleware(h.upload))
101 router.POST(base+"/caches/:id", h.middleware(h.commit))
102 router.GET(base+"/artifacts/:id", h.middleware(h.get))
103 router.POST(base+"/clean", h.middleware(h.clean))
104
105 h.router = router

Callers 6

newRunCommandFunction · 0.92
TestHandlerFunction · 0.85
TestHandler_gcCacheFunction · 0.85
TestHandler_BindAddressFunction · 0.85

Calls 8

middlewareMethod · 0.95
gcCacheMethod · 0.95
GetOutboundIPFunction · 0.92
NewStorageFunction · 0.85
makeFunction · 0.85
ReadMethod · 0.80
ServeMethod · 0.80
StringMethod · 0.45

Tested by 5

TestHandlerFunction · 0.68
TestHandler_gcCacheFunction · 0.68
TestHandler_BindAddressFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…