Skip to content

Commit fb6c14f

Browse files
committed
pass the shared Index structure to the goa Server
1 parent d989619 commit fb6c14f

File tree

4 files changed

+14
-23
lines changed

4 files changed

+14
-23
lines changed

main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ func loop() {
401401
r.POST("/update", updateHandler)
402402

403403
// Mount goa handlers
404-
goa := v2.Server(config.GetDataDir().String())
404+
goa := v2.Server(config.GetDataDir().String(), Index)
405405
r.Any("/v2/*path", gin.WrapH(goa))
406406

407407
go func() {

main_test.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929

3030
"github.com/arduino/arduino-create-agent/config"
3131
"github.com/arduino/arduino-create-agent/gen/tools"
32+
"github.com/arduino/arduino-create-agent/index"
3233
"github.com/arduino/arduino-create-agent/upload"
3334
v2 "github.com/arduino/arduino-create-agent/v2"
3435
"github.com/gin-gonic/gin"
@@ -87,8 +88,13 @@ func TestUploadHandlerAgainstEvilFileNames(t *testing.T) {
8788
}
8889

8990
func TestInstallToolV2(t *testing.T) {
91+
92+
indexURL := "https://downloads.arduino.cc/packages/package_staging_index.json"
93+
// Instantiate Index
94+
Index := index.Init(indexURL, config.GetDataDir())
95+
9096
r := gin.New()
91-
goa := v2.Server(config.GetDataDir().String())
97+
goa := v2.Server(config.GetDataDir().String(), Index)
9298
r.Any("/v2/*path", gin.WrapH(goa))
9399
ts := httptest.NewServer(r)
94100

v2/http.go

+4-16
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,10 @@ import (
1919
"context"
2020
"encoding/json"
2121
"net/http"
22-
"path/filepath"
2322

24-
indexessvr "github.com/arduino/arduino-create-agent/gen/http/indexes/server"
2523
toolssvr "github.com/arduino/arduino-create-agent/gen/http/tools/server"
26-
indexessvc "github.com/arduino/arduino-create-agent/gen/indexes"
2724
toolssvc "github.com/arduino/arduino-create-agent/gen/tools"
25+
"github.com/arduino/arduino-create-agent/index"
2826
"github.com/arduino/arduino-create-agent/v2/pkgs"
2927
"github.com/sirupsen/logrus"
3028
goahttp "goa.design/goa/v3/http"
@@ -33,28 +31,18 @@ import (
3331
)
3432

3533
// Server is the actual server
36-
func Server(home string) http.Handler {
34+
func Server(directory string, index *index.IndexResource) http.Handler {
3735
mux := goahttp.NewMuxer()
3836

3937
// Instantiate logger
4038
logger := logrus.New()
4139
logger.SetLevel(logrus.DebugLevel)
4240
logAdapter := LogAdapter{Logger: logger}
4341

44-
// Mount indexes
45-
indexesSvc := pkgs.Indexes{
46-
Log: logger,
47-
Folder: filepath.Join(home, "indexes"),
48-
}
49-
indexesEndpoints := indexessvc.NewEndpoints(&indexesSvc)
50-
indexesServer := indexessvr.New(indexesEndpoints, mux, goahttp.RequestDecoder,
51-
goahttp.ResponseEncoder, errorHandler(logger), nil)
52-
indexessvr.Mount(mux, indexesServer)
53-
5442
// Mount tools
5543
toolsSvc := pkgs.Tools{
56-
Folder: home,
57-
Indexes: &indexesSvc,
44+
Folder: directory,
45+
Index: index,
5846
}
5947
toolsEndpoints := toolssvc.NewEndpoints(&toolsSvc)
6048
toolsServer := toolssvr.New(toolsEndpoints, mux, CustomRequestDecoder, goahttp.ResponseEncoder, errorHandler(logger), nil)

v2/pkgs/tools.go

+2-5
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,9 @@ import (
4747
// └── 1.7.0
4848
// └── bossac
4949
//
50-
// It requires an Indexes client to list and read package index files: use the Indexes struct
50+
// It requires an Index Resource to search for tools
5151
type Tools struct {
52-
Indexes interface {
53-
List(context.Context) ([]string, error)
54-
Get(context.Context, string) (Index, error)
55-
}
52+
Index *index.IndexResource
5653
Folder string
5754
}
5855

0 commit comments

Comments
 (0)