Skip to content

Commit 9a500b4

Browse files
authoredOct 10, 2023
Implement HEAD handler for v2/pkgs/tools/installed (required by frontend) (#844)
* add tests * implement HEAD method (is used by the frontend). Without this the server returns 405 when called with HEAD to `v2/pkgs/tools/installed` This breaks the install of the tools
1 parent 15fcb43 commit 9a500b4

18 files changed

+270
-30
lines changed
 

‎design/pkgs.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ var _ = Service("tools", func() {
2828
})
2929
})
3030

31+
Method("installedhead", func() {
32+
HTTP(func() {
33+
HEAD("/pkgs/tools/installed")
34+
Response(StatusOK)
35+
})
36+
})
37+
3138
Method("installed", func() {
3239
Result(CollectionOf(Tool))
3340
HTTP(func() {

‎gen/http/cli/arduino_create_agent/cli.go

Lines changed: 21 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎gen/http/openapi.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

‎gen/http/openapi.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,16 @@ paths:
6161
$ref: '#/definitions/ToolsInstallResponseBody'
6262
schemes:
6363
- http
64+
head:
65+
tags:
66+
- tools
67+
summary: installedhead tools
68+
operationId: tools#installedhead
69+
responses:
70+
"200":
71+
description: OK response.
72+
schemes:
73+
- http
6474
/pkgs/tools/installed/{packager}/{name}/{version}:
6575
delete:
6676
tags:

‎gen/http/openapi3.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

‎gen/http/openapi3.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@ paths:
5353
- name: bossac
5454
packager: arduino
5555
version: 1.7.0-arduino3
56+
head:
57+
tags:
58+
- tools
59+
summary: installedhead tools
60+
operationId: tools#installedhead
61+
responses:
62+
"200":
63+
description: OK response.
5664
post:
5765
tags:
5866
- tools

‎gen/http/tools/client/client.go

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎gen/http/tools/client/encode_decode.go

Lines changed: 42 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎gen/http/tools/client/paths.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎gen/http/tools/server/encode_decode.go

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎gen/http/tools/server/paths.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎gen/http/tools/server/server.go

Lines changed: 58 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎gen/tools/client.go

Lines changed: 17 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎gen/tools/endpoints.go

Lines changed: 19 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎gen/tools/service.go

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎main_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,3 +168,19 @@ func TestInstallToolV2(t *testing.T) {
168168
})
169169
}
170170
}
171+
172+
func TestInstalledHead(t *testing.T) {
173+
indexURL := "https://downloads.arduino.cc/packages/package_staging_index.json"
174+
// Instantiate Index
175+
Index := index.Init(indexURL, config.GetDataDir())
176+
177+
r := gin.New()
178+
goa := v2.Server(config.GetDataDir().String(), Index)
179+
r.Any("/v2/*path", gin.WrapH(goa))
180+
ts := httptest.NewServer(r)
181+
182+
resp, err := http.Head(ts.URL + "/v2/pkgs/tools/installed")
183+
require.NoError(t, err)
184+
require.NotEqual(t, resp.StatusCode, http.StatusMethodNotAllowed)
185+
require.Equal(t, resp.StatusCode, http.StatusOK)
186+
}

‎v2/pkgs/tools.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,14 @@ func New(index *index.Resource, folder string) *Tools {
6464
}
6565
}
6666

67+
// Installedhead is here only because it was required by the front-end.
68+
// Probably when we bumped GOA something changed:
69+
// Before that the frontend was able to perform the HEAD request to `v2/pkgs/tools/installed`.
70+
// After the bump we have to implement it explicitly. Currently I do not know a better way in achieving the same result.
71+
func (t *Tools) Installedhead(ctx context.Context) (err error) {
72+
return nil
73+
}
74+
6775
// Available crawles the downloaded package index files and returns a list of tools that can be installed.
6876
func (t *Tools) Available(ctx context.Context) (res tools.ToolCollection, err error) {
6977
body, err := t.index.Read()

‎v2/pkgs/tools_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,22 @@ func TestEvilFilename(t *testing.T) {
185185
}
186186
}
187187

188+
func TestInstalledHead(t *testing.T) {
189+
// Initialize indexes with a temp folder
190+
tmp := t.TempDir()
191+
192+
indexURL := "https://downloads.arduino.cc/packages/package_staging_index.json"
193+
// Instantiate Index
194+
Index := index.Init(indexURL, config.GetDataDir())
195+
196+
service := pkgs.New(Index, tmp)
197+
198+
ctx := context.Background()
199+
200+
err := service.Installedhead(ctx)
201+
require.NoError(t, err)
202+
}
203+
188204
func strpoint(s string) *string {
189205
return &s
190206
}

0 commit comments

Comments
 (0)
Please sign in to comment.