Skip to content

Implement HEAD handler for v2/pkgs/tools/installed (required by frontend) #844

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions design/pkgs.go
Original file line number Diff line number Diff line change
@@ -28,6 +28,13 @@ var _ = Service("tools", func() {
})
})

Method("installedhead", func() {
HTTP(func() {
HEAD("/pkgs/tools/installed")
Response(StatusOK)
})
})

Method("installed", func() {
Result(CollectionOf(Tool))
HTTP(func() {
22 changes: 21 additions & 1 deletion gen/http/cli/arduino_create_agent/cli.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion gen/http/openapi.json

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions gen/http/openapi.yaml
Original file line number Diff line number Diff line change
@@ -61,6 +61,16 @@ paths:
$ref: '#/definitions/ToolsInstallResponseBody'
schemes:
- http
head:
tags:
- tools
summary: installedhead tools
operationId: tools#installedhead
responses:
"200":
description: OK response.
schemes:
- http
/pkgs/tools/installed/{packager}/{name}/{version}:
delete:
tags:
2 changes: 1 addition & 1 deletion gen/http/openapi3.json

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions gen/http/openapi3.yaml
Original file line number Diff line number Diff line change
@@ -53,6 +53,14 @@ paths:
- name: bossac
packager: arduino
version: 1.7.0-arduino3
head:
tags:
- tools
summary: installedhead tools
operationId: tools#installedhead
responses:
"200":
description: OK response.
post:
tags:
- tools
24 changes: 24 additions & 0 deletions gen/http/tools/client/client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 42 additions & 0 deletions gen/http/tools/client/encode_decode.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions gen/http/tools/client/paths.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions gen/http/tools/server/encode_decode.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions gen/http/tools/server/paths.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

67 changes: 58 additions & 9 deletions gen/http/tools/server/server.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 17 additions & 9 deletions gen/tools/client.go
27 changes: 19 additions & 8 deletions gen/tools/endpoints.go
4 changes: 3 additions & 1 deletion gen/tools/service.go
16 changes: 16 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
@@ -168,3 +168,19 @@ func TestInstallToolV2(t *testing.T) {
})
}
}

func TestInstalledHead(t *testing.T) {
indexURL := "https://downloads.arduino.cc/packages/package_staging_index.json"
// Instantiate Index
Index := index.Init(indexURL, config.GetDataDir())

r := gin.New()
goa := v2.Server(config.GetDataDir().String(), Index)
r.Any("/v2/*path", gin.WrapH(goa))
ts := httptest.NewServer(r)

resp, err := http.Head(ts.URL + "/v2/pkgs/tools/installed")
require.NoError(t, err)
require.NotEqual(t, resp.StatusCode, http.StatusMethodNotAllowed)
require.Equal(t, resp.StatusCode, http.StatusOK)
}
8 changes: 8 additions & 0 deletions v2/pkgs/tools.go
Original file line number Diff line number Diff line change
@@ -64,6 +64,14 @@ func New(index *index.Resource, folder string) *Tools {
}
}

// Installedhead is here only because it was required by the front-end.
// Probably when we bumped GOA something changed:
// Before that the frontend was able to perform the HEAD request to `v2/pkgs/tools/installed`.
// After the bump we have to implement it explicitly. Currently I do not know a better way in achieving the same result.
func (t *Tools) Installedhead(ctx context.Context) (err error) {
return nil
}

// Available crawles the downloaded package index files and returns a list of tools that can be installed.
func (t *Tools) Available(ctx context.Context) (res tools.ToolCollection, err error) {
body, err := t.index.Read()
16 changes: 16 additions & 0 deletions v2/pkgs/tools_test.go
Original file line number Diff line number Diff line change
@@ -185,6 +185,22 @@ func TestEvilFilename(t *testing.T) {
}
}

func TestInstalledHead(t *testing.T) {
// Initialize indexes with a temp folder
tmp := t.TempDir()

indexURL := "https://downloads.arduino.cc/packages/package_staging_index.json"
// Instantiate Index
Index := index.Init(indexURL, config.GetDataDir())

service := pkgs.New(Index, tmp)

ctx := context.Background()

err := service.Installedhead(ctx)
require.NoError(t, err)
}

func strpoint(s string) *string {
return &s
}