From 1306f0ea399764acdfe2ee1c0765436b5d6c7131 Mon Sep 17 00:00:00 2001 From: Umberto Baldi Date: Mon, 9 Oct 2023 19:31:46 +0200 Subject: [PATCH 1/2] add tests --- main_test.go | 16 ++++++++++++++++ v2/pkgs/tools_test.go | 16 ++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/main_test.go b/main_test.go index 57c5b2f8e..9dc5faa5c 100644 --- a/main_test.go +++ b/main_test.go @@ -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) +} diff --git a/v2/pkgs/tools_test.go b/v2/pkgs/tools_test.go index 44070c686..fb3f67df8 100644 --- a/v2/pkgs/tools_test.go +++ b/v2/pkgs/tools_test.go @@ -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 } From c4cebc95c1ed4c5f9c125f1c319e517a502999be Mon Sep 17 00:00:00 2001 From: Umberto Baldi Date: Mon, 9 Oct 2023 19:04:43 +0200 Subject: [PATCH 2/2] 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 --- design/pkgs.go | 7 +++ gen/http/cli/arduino_create_agent/cli.go | 22 +++++++- gen/http/openapi.json | 2 +- gen/http/openapi.yaml | 10 ++++ gen/http/openapi3.json | 2 +- gen/http/openapi3.yaml | 8 +++ gen/http/tools/client/client.go | 24 +++++++++ gen/http/tools/client/encode_decode.go | 42 +++++++++++++++ gen/http/tools/client/paths.go | 5 ++ gen/http/tools/server/encode_decode.go | 9 ++++ gen/http/tools/server/paths.go | 5 ++ gen/http/tools/server/server.go | 67 ++++++++++++++++++++---- gen/tools/client.go | 26 +++++---- gen/tools/endpoints.go | 27 +++++++--- gen/tools/service.go | 4 +- v2/pkgs/tools.go | 8 +++ 16 files changed, 238 insertions(+), 30 deletions(-) diff --git a/design/pkgs.go b/design/pkgs.go index b059e0ddf..21c30d217 100644 --- a/design/pkgs.go +++ b/design/pkgs.go @@ -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() { diff --git a/gen/http/cli/arduino_create_agent/cli.go b/gen/http/cli/arduino_create_agent/cli.go index 2593ad816..2c454dd65 100644 --- a/gen/http/cli/arduino_create_agent/cli.go +++ b/gen/http/cli/arduino_create_agent/cli.go @@ -22,7 +22,7 @@ import ( // // command (subcommand1|subcommand2|...) func UsageCommands() string { - return `tools (available|installed|install|remove) + return `tools (available|installedhead|installed|install|remove) ` } @@ -46,6 +46,8 @@ func ParseEndpoint( toolsAvailableFlags = flag.NewFlagSet("available", flag.ExitOnError) + toolsInstalledheadFlags = flag.NewFlagSet("installedhead", flag.ExitOnError) + toolsInstalledFlags = flag.NewFlagSet("installed", flag.ExitOnError) toolsInstallFlags = flag.NewFlagSet("install", flag.ExitOnError) @@ -59,6 +61,7 @@ func ParseEndpoint( ) toolsFlags.Usage = toolsUsage toolsAvailableFlags.Usage = toolsAvailableUsage + toolsInstalledheadFlags.Usage = toolsInstalledheadUsage toolsInstalledFlags.Usage = toolsInstalledUsage toolsInstallFlags.Usage = toolsInstallUsage toolsRemoveFlags.Usage = toolsRemoveUsage @@ -100,6 +103,9 @@ func ParseEndpoint( case "available": epf = toolsAvailableFlags + case "installedhead": + epf = toolsInstalledheadFlags + case "installed": epf = toolsInstalledFlags @@ -137,6 +143,9 @@ func ParseEndpoint( case "available": endpoint = c.Available() data = nil + case "installedhead": + endpoint = c.Installedhead() + data = nil case "installed": endpoint = c.Installed() data = nil @@ -164,6 +173,7 @@ Usage: COMMAND: available: Available implements available. + installedhead: Installedhead implements installedhead. installed: Installed implements installed. install: Install implements install. remove: Remove implements remove. @@ -182,6 +192,16 @@ Example: `, os.Args[0]) } +func toolsInstalledheadUsage() { + fmt.Fprintf(os.Stderr, `%[1]s [flags] tools installedhead + +Installedhead implements installedhead. + +Example: + %[1]s tools installedhead +`, os.Args[0]) +} + func toolsInstalledUsage() { fmt.Fprintf(os.Stderr, `%[1]s [flags] tools installed diff --git a/gen/http/openapi.json b/gen/http/openapi.json index a8e08e509..d392f1816 100644 --- a/gen/http/openapi.json +++ b/gen/http/openapi.json @@ -1 +1 @@ -{"swagger":"2.0","info":{"title":"Arduino Create Agent","description":"A companion of Arduino Create. \n\tAllows the website to perform operations on the user computer, \n\tsuch as detecting which boards are connected and upload sketches on them.","version":""},"host":"localhost:80","basePath":"/v2","consumes":["application/json","plain/text"],"produces":["application/json","application/xml","application/gob"],"paths":{"/pkgs/tools/available":{"get":{"tags":["tools"],"summary":"available tools","operationId":"tools#available","responses":{"200":{"description":"OK response.","schema":{"$ref":"#/definitions/ToolsToolResponseCollection"}}},"schemes":["http"]}},"/pkgs/tools/installed":{"get":{"tags":["tools"],"summary":"installed tools","operationId":"tools#installed","responses":{"200":{"description":"OK response.","schema":{"$ref":"#/definitions/ToolsToolResponseCollection"}}},"schemes":["http"]},"post":{"tags":["tools"],"summary":"install tools","operationId":"tools#install","parameters":[{"name":"InstallRequestBody","in":"body","required":true,"schema":{"$ref":"#/definitions/ToolsInstallRequestBody","required":["name","version","packager"]}}],"responses":{"200":{"description":"OK response.","schema":{"$ref":"#/definitions/ToolsInstallResponseBody"}}},"schemes":["http"]}},"/pkgs/tools/installed/{packager}/{name}/{version}":{"delete":{"tags":["tools"],"summary":"remove tools","operationId":"tools#remove","parameters":[{"name":"packager","in":"path","description":"The packager of the tool","required":true,"type":"string"},{"name":"name","in":"path","description":"The name of the tool","required":true,"type":"string"},{"name":"version","in":"path","description":"The version of the tool","required":true,"type":"string"},{"name":"RemoveRequestBody","in":"body","required":true,"schema":{"$ref":"#/definitions/ToolsRemoveRequestBody"}}],"responses":{"200":{"description":"OK response.","schema":{"$ref":"#/definitions/ToolsRemoveResponseBody"}}},"schemes":["http"]}}},"definitions":{"ToolResponse":{"title":"Mediatype identifier: application/vnd.arduino.tool; view=default","type":"object","properties":{"name":{"type":"string","description":"The name of the tool","example":"bossac"},"packager":{"type":"string","description":"The packager of the tool","example":"arduino"},"version":{"type":"string","description":"The version of the tool","example":"1.7.0-arduino3"}},"description":"A tool is an executable program that can upload sketches. (default view)","example":{"name":"bossac","packager":"arduino","version":"1.7.0-arduino3"},"required":["name","version","packager"]},"ToolsInstallRequestBody":{"title":"ToolsInstallRequestBody","type":"object","properties":{"checksum":{"type":"string","description":"A checksum of the archive. Mandatory when url is present. \n\tThis ensures that the package is downloaded correcly.","example":"SHA-256:1ae54999c1f97234a5c603eb99ad39313b11746a4ca517269a9285afa05f9100"},"name":{"type":"string","description":"The name of the tool","example":"bossac"},"packager":{"type":"string","description":"The packager of the tool","example":"arduino"},"signature":{"type":"string","description":"The signature used to sign the url. Mandatory when url is present.\n\tThis ensure the security of the file downloaded","example":"382898a97b5a86edd74208f10107d2fecbf7059ffe9cc856e045266fb4db4e98802728a0859cfdcda1c0b9075ec01e42dbea1f430b813530d5a6ae1766dfbba64c3e689b59758062dc2ab2e32b2a3491dc2b9a80b9cda4ae514fbe0ec5af210111b6896976053ab76bac55bcecfcececa68adfa3299e3cde6b7f117b3552a7d80ca419374bb497e3c3f12b640cf5b20875416b45e662fc6150b99b178f8e41d6982b4c0a255925ea39773683f9aa9201dc5768b6fc857c87ff602b6a93452a541b8ec10ca07f166e61a9e9d91f0a6090bd2038ed4427af6251039fb9fe8eb62ec30d7b0f3df38bc9de7204dec478fb86f8eb3f71543710790ee169dce039d3e0"},"url":{"type":"string","description":"The url where the package can be found. Optional. \n\tIf present checksum must also be present.","example":"http://downloads.arduino.cc/tools/bossac-1.7.0-arduino3-linux64.tar.gz"},"version":{"type":"string","description":"The version of the tool","example":"1.7.0-arduino3"}},"example":{"checksum":"SHA-256:1ae54999c1f97234a5c603eb99ad39313b11746a4ca517269a9285afa05f9100","name":"bossac","packager":"arduino","signature":"382898a97b5a86edd74208f10107d2fecbf7059ffe9cc856e045266fb4db4e98802728a0859cfdcda1c0b9075ec01e42dbea1f430b813530d5a6ae1766dfbba64c3e689b59758062dc2ab2e32b2a3491dc2b9a80b9cda4ae514fbe0ec5af210111b6896976053ab76bac55bcecfcececa68adfa3299e3cde6b7f117b3552a7d80ca419374bb497e3c3f12b640cf5b20875416b45e662fc6150b99b178f8e41d6982b4c0a255925ea39773683f9aa9201dc5768b6fc857c87ff602b6a93452a541b8ec10ca07f166e61a9e9d91f0a6090bd2038ed4427af6251039fb9fe8eb62ec30d7b0f3df38bc9de7204dec478fb86f8eb3f71543710790ee169dce039d3e0","url":"http://downloads.arduino.cc/tools/bossac-1.7.0-arduino3-linux64.tar.gz","version":"1.7.0-arduino3"},"required":["name","version","packager"]},"ToolsInstallResponseBody":{"title":"Mediatype identifier: application/vnd.arduino.operation; view=default","type":"object","properties":{"status":{"type":"string","description":"The status of the operation","example":"ok"}},"description":"InstallResponseBody result type (default view)","example":{"status":"ok"},"required":["status"]},"ToolsRemoveRequestBody":{"title":"ToolsRemoveRequestBody","type":"object","properties":{"checksum":{"type":"string","description":"A checksum of the archive. Mandatory when url is present. \n\tThis ensures that the package is downloaded correcly.","example":"SHA-256:1ae54999c1f97234a5c603eb99ad39313b11746a4ca517269a9285afa05f9100"},"signature":{"type":"string","description":"The signature used to sign the url. Mandatory when url is present.\n\tThis ensure the security of the file downloaded","example":"382898a97b5a86edd74208f10107d2fecbf7059ffe9cc856e045266fb4db4e98802728a0859cfdcda1c0b9075ec01e42dbea1f430b813530d5a6ae1766dfbba64c3e689b59758062dc2ab2e32b2a3491dc2b9a80b9cda4ae514fbe0ec5af210111b6896976053ab76bac55bcecfcececa68adfa3299e3cde6b7f117b3552a7d80ca419374bb497e3c3f12b640cf5b20875416b45e662fc6150b99b178f8e41d6982b4c0a255925ea39773683f9aa9201dc5768b6fc857c87ff602b6a93452a541b8ec10ca07f166e61a9e9d91f0a6090bd2038ed4427af6251039fb9fe8eb62ec30d7b0f3df38bc9de7204dec478fb86f8eb3f71543710790ee169dce039d3e0"},"url":{"type":"string","description":"The url where the package can be found. Optional. \n\tIf present checksum must also be present.","example":"http://downloads.arduino.cc/tools/bossac-1.7.0-arduino3-linux64.tar.gz"}},"example":{"checksum":"SHA-256:1ae54999c1f97234a5c603eb99ad39313b11746a4ca517269a9285afa05f9100","signature":"382898a97b5a86edd74208f10107d2fecbf7059ffe9cc856e045266fb4db4e98802728a0859cfdcda1c0b9075ec01e42dbea1f430b813530d5a6ae1766dfbba64c3e689b59758062dc2ab2e32b2a3491dc2b9a80b9cda4ae514fbe0ec5af210111b6896976053ab76bac55bcecfcececa68adfa3299e3cde6b7f117b3552a7d80ca419374bb497e3c3f12b640cf5b20875416b45e662fc6150b99b178f8e41d6982b4c0a255925ea39773683f9aa9201dc5768b6fc857c87ff602b6a93452a541b8ec10ca07f166e61a9e9d91f0a6090bd2038ed4427af6251039fb9fe8eb62ec30d7b0f3df38bc9de7204dec478fb86f8eb3f71543710790ee169dce039d3e0","url":"http://downloads.arduino.cc/tools/bossac-1.7.0-arduino3-linux64.tar.gz"}},"ToolsRemoveResponseBody":{"title":"Mediatype identifier: application/vnd.arduino.operation; view=default","type":"object","properties":{"status":{"type":"string","description":"The status of the operation","example":"ok"}},"description":"RemoveResponseBody result type (default view)","example":{"status":"ok"},"required":["status"]},"ToolsToolResponseCollection":{"title":"Mediatype identifier: application/vnd.arduino.tool; type=collection; view=default","type":"array","items":{"$ref":"#/definitions/ToolResponse"},"description":"AvailableResponseBody is the result type for an array of ToolResponse (default view)","example":[{"name":"bossac","packager":"arduino","version":"1.7.0-arduino3"},{"name":"bossac","packager":"arduino","version":"1.7.0-arduino3"},{"name":"bossac","packager":"arduino","version":"1.7.0-arduino3"},{"name":"bossac","packager":"arduino","version":"1.7.0-arduino3"}]}}} \ No newline at end of file +{"swagger":"2.0","info":{"title":"Arduino Create Agent","description":"A companion of Arduino Create. \n\tAllows the website to perform operations on the user computer, \n\tsuch as detecting which boards are connected and upload sketches on them.","version":""},"host":"localhost:80","basePath":"/v2","consumes":["application/json","plain/text"],"produces":["application/json","application/xml","application/gob"],"paths":{"/pkgs/tools/available":{"get":{"tags":["tools"],"summary":"available tools","operationId":"tools#available","responses":{"200":{"description":"OK response.","schema":{"$ref":"#/definitions/ToolsToolResponseCollection"}}},"schemes":["http"]}},"/pkgs/tools/installed":{"get":{"tags":["tools"],"summary":"installed tools","operationId":"tools#installed","responses":{"200":{"description":"OK response.","schema":{"$ref":"#/definitions/ToolsToolResponseCollection"}}},"schemes":["http"]},"post":{"tags":["tools"],"summary":"install tools","operationId":"tools#install","parameters":[{"name":"InstallRequestBody","in":"body","required":true,"schema":{"$ref":"#/definitions/ToolsInstallRequestBody","required":["name","version","packager"]}}],"responses":{"200":{"description":"OK response.","schema":{"$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":["tools"],"summary":"remove tools","operationId":"tools#remove","parameters":[{"name":"packager","in":"path","description":"The packager of the tool","required":true,"type":"string"},{"name":"name","in":"path","description":"The name of the tool","required":true,"type":"string"},{"name":"version","in":"path","description":"The version of the tool","required":true,"type":"string"},{"name":"RemoveRequestBody","in":"body","required":true,"schema":{"$ref":"#/definitions/ToolsRemoveRequestBody"}}],"responses":{"200":{"description":"OK response.","schema":{"$ref":"#/definitions/ToolsRemoveResponseBody"}}},"schemes":["http"]}}},"definitions":{"ToolResponse":{"title":"Mediatype identifier: application/vnd.arduino.tool; view=default","type":"object","properties":{"name":{"type":"string","description":"The name of the tool","example":"bossac"},"packager":{"type":"string","description":"The packager of the tool","example":"arduino"},"version":{"type":"string","description":"The version of the tool","example":"1.7.0-arduino3"}},"description":"A tool is an executable program that can upload sketches. (default view)","example":{"name":"bossac","packager":"arduino","version":"1.7.0-arduino3"},"required":["name","version","packager"]},"ToolsInstallRequestBody":{"title":"ToolsInstallRequestBody","type":"object","properties":{"checksum":{"type":"string","description":"A checksum of the archive. Mandatory when url is present. \n\tThis ensures that the package is downloaded correcly.","example":"SHA-256:1ae54999c1f97234a5c603eb99ad39313b11746a4ca517269a9285afa05f9100"},"name":{"type":"string","description":"The name of the tool","example":"bossac"},"packager":{"type":"string","description":"The packager of the tool","example":"arduino"},"signature":{"type":"string","description":"The signature used to sign the url. Mandatory when url is present.\n\tThis ensure the security of the file downloaded","example":"382898a97b5a86edd74208f10107d2fecbf7059ffe9cc856e045266fb4db4e98802728a0859cfdcda1c0b9075ec01e42dbea1f430b813530d5a6ae1766dfbba64c3e689b59758062dc2ab2e32b2a3491dc2b9a80b9cda4ae514fbe0ec5af210111b6896976053ab76bac55bcecfcececa68adfa3299e3cde6b7f117b3552a7d80ca419374bb497e3c3f12b640cf5b20875416b45e662fc6150b99b178f8e41d6982b4c0a255925ea39773683f9aa9201dc5768b6fc857c87ff602b6a93452a541b8ec10ca07f166e61a9e9d91f0a6090bd2038ed4427af6251039fb9fe8eb62ec30d7b0f3df38bc9de7204dec478fb86f8eb3f71543710790ee169dce039d3e0"},"url":{"type":"string","description":"The url where the package can be found. Optional. \n\tIf present checksum must also be present.","example":"http://downloads.arduino.cc/tools/bossac-1.7.0-arduino3-linux64.tar.gz"},"version":{"type":"string","description":"The version of the tool","example":"1.7.0-arduino3"}},"example":{"checksum":"SHA-256:1ae54999c1f97234a5c603eb99ad39313b11746a4ca517269a9285afa05f9100","name":"bossac","packager":"arduino","signature":"382898a97b5a86edd74208f10107d2fecbf7059ffe9cc856e045266fb4db4e98802728a0859cfdcda1c0b9075ec01e42dbea1f430b813530d5a6ae1766dfbba64c3e689b59758062dc2ab2e32b2a3491dc2b9a80b9cda4ae514fbe0ec5af210111b6896976053ab76bac55bcecfcececa68adfa3299e3cde6b7f117b3552a7d80ca419374bb497e3c3f12b640cf5b20875416b45e662fc6150b99b178f8e41d6982b4c0a255925ea39773683f9aa9201dc5768b6fc857c87ff602b6a93452a541b8ec10ca07f166e61a9e9d91f0a6090bd2038ed4427af6251039fb9fe8eb62ec30d7b0f3df38bc9de7204dec478fb86f8eb3f71543710790ee169dce039d3e0","url":"http://downloads.arduino.cc/tools/bossac-1.7.0-arduino3-linux64.tar.gz","version":"1.7.0-arduino3"},"required":["name","version","packager"]},"ToolsInstallResponseBody":{"title":"Mediatype identifier: application/vnd.arduino.operation; view=default","type":"object","properties":{"status":{"type":"string","description":"The status of the operation","example":"ok"}},"description":"InstallResponseBody result type (default view)","example":{"status":"ok"},"required":["status"]},"ToolsRemoveRequestBody":{"title":"ToolsRemoveRequestBody","type":"object","properties":{"checksum":{"type":"string","description":"A checksum of the archive. Mandatory when url is present. \n\tThis ensures that the package is downloaded correcly.","example":"SHA-256:1ae54999c1f97234a5c603eb99ad39313b11746a4ca517269a9285afa05f9100"},"signature":{"type":"string","description":"The signature used to sign the url. Mandatory when url is present.\n\tThis ensure the security of the file downloaded","example":"382898a97b5a86edd74208f10107d2fecbf7059ffe9cc856e045266fb4db4e98802728a0859cfdcda1c0b9075ec01e42dbea1f430b813530d5a6ae1766dfbba64c3e689b59758062dc2ab2e32b2a3491dc2b9a80b9cda4ae514fbe0ec5af210111b6896976053ab76bac55bcecfcececa68adfa3299e3cde6b7f117b3552a7d80ca419374bb497e3c3f12b640cf5b20875416b45e662fc6150b99b178f8e41d6982b4c0a255925ea39773683f9aa9201dc5768b6fc857c87ff602b6a93452a541b8ec10ca07f166e61a9e9d91f0a6090bd2038ed4427af6251039fb9fe8eb62ec30d7b0f3df38bc9de7204dec478fb86f8eb3f71543710790ee169dce039d3e0"},"url":{"type":"string","description":"The url where the package can be found. Optional. \n\tIf present checksum must also be present.","example":"http://downloads.arduino.cc/tools/bossac-1.7.0-arduino3-linux64.tar.gz"}},"example":{"checksum":"SHA-256:1ae54999c1f97234a5c603eb99ad39313b11746a4ca517269a9285afa05f9100","signature":"382898a97b5a86edd74208f10107d2fecbf7059ffe9cc856e045266fb4db4e98802728a0859cfdcda1c0b9075ec01e42dbea1f430b813530d5a6ae1766dfbba64c3e689b59758062dc2ab2e32b2a3491dc2b9a80b9cda4ae514fbe0ec5af210111b6896976053ab76bac55bcecfcececa68adfa3299e3cde6b7f117b3552a7d80ca419374bb497e3c3f12b640cf5b20875416b45e662fc6150b99b178f8e41d6982b4c0a255925ea39773683f9aa9201dc5768b6fc857c87ff602b6a93452a541b8ec10ca07f166e61a9e9d91f0a6090bd2038ed4427af6251039fb9fe8eb62ec30d7b0f3df38bc9de7204dec478fb86f8eb3f71543710790ee169dce039d3e0","url":"http://downloads.arduino.cc/tools/bossac-1.7.0-arduino3-linux64.tar.gz"}},"ToolsRemoveResponseBody":{"title":"Mediatype identifier: application/vnd.arduino.operation; view=default","type":"object","properties":{"status":{"type":"string","description":"The status of the operation","example":"ok"}},"description":"RemoveResponseBody result type (default view)","example":{"status":"ok"},"required":["status"]},"ToolsToolResponseCollection":{"title":"Mediatype identifier: application/vnd.arduino.tool; type=collection; view=default","type":"array","items":{"$ref":"#/definitions/ToolResponse"},"description":"AvailableResponseBody is the result type for an array of ToolResponse (default view)","example":[{"name":"bossac","packager":"arduino","version":"1.7.0-arduino3"},{"name":"bossac","packager":"arduino","version":"1.7.0-arduino3"},{"name":"bossac","packager":"arduino","version":"1.7.0-arduino3"},{"name":"bossac","packager":"arduino","version":"1.7.0-arduino3"}]}}} \ No newline at end of file diff --git a/gen/http/openapi.yaml b/gen/http/openapi.yaml index ac98393fc..7712e82ff 100644 --- a/gen/http/openapi.yaml +++ b/gen/http/openapi.yaml @@ -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: diff --git a/gen/http/openapi3.json b/gen/http/openapi3.json index b02a940bd..11e9b8177 100644 --- a/gen/http/openapi3.json +++ b/gen/http/openapi3.json @@ -1 +1 @@ -{"openapi":"3.0.3","info":{"title":"Arduino Create Agent","description":"A companion of Arduino Create. \n\tAllows the website to perform operations on the user computer, \n\tsuch as detecting which boards are connected and upload sketches on them.","version":"1.0"},"servers":[{"url":"http://localhost:80","description":"Default server for arduino-create-agent"}],"paths":{"/v2/pkgs/tools/available":{"get":{"tags":["tools"],"summary":"available tools","operationId":"tools#available","responses":{"200":{"description":"OK response.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ToolCollection"},"example":[{"name":"bossac","packager":"arduino","version":"1.7.0-arduino3"},{"name":"bossac","packager":"arduino","version":"1.7.0-arduino3"},{"name":"bossac","packager":"arduino","version":"1.7.0-arduino3"}]}}}}}},"/v2/pkgs/tools/installed":{"get":{"tags":["tools"],"summary":"installed tools","operationId":"tools#installed","responses":{"200":{"description":"OK response.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ToolCollection"},"example":[{"name":"bossac","packager":"arduino","version":"1.7.0-arduino3"},{"name":"bossac","packager":"arduino","version":"1.7.0-arduino3"},{"name":"bossac","packager":"arduino","version":"1.7.0-arduino3"}]}}}}},"post":{"tags":["tools"],"summary":"install tools","operationId":"tools#install","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/InstallRequestBody"},"example":{"checksum":"SHA-256:1ae54999c1f97234a5c603eb99ad39313b11746a4ca517269a9285afa05f9100","name":"bossac","packager":"arduino","signature":"382898a97b5a86edd74208f10107d2fecbf7059ffe9cc856e045266fb4db4e98802728a0859cfdcda1c0b9075ec01e42dbea1f430b813530d5a6ae1766dfbba64c3e689b59758062dc2ab2e32b2a3491dc2b9a80b9cda4ae514fbe0ec5af210111b6896976053ab76bac55bcecfcececa68adfa3299e3cde6b7f117b3552a7d80ca419374bb497e3c3f12b640cf5b20875416b45e662fc6150b99b178f8e41d6982b4c0a255925ea39773683f9aa9201dc5768b6fc857c87ff602b6a93452a541b8ec10ca07f166e61a9e9d91f0a6090bd2038ed4427af6251039fb9fe8eb62ec30d7b0f3df38bc9de7204dec478fb86f8eb3f71543710790ee169dce039d3e0","url":"http://downloads.arduino.cc/tools/bossac-1.7.0-arduino3-linux64.tar.gz","version":"1.7.0-arduino3"}}}},"responses":{"200":{"description":"OK response.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Operation"},"example":{"status":"ok"}}}}}}},"/v2/pkgs/tools/installed/{packager}/{name}/{version}":{"delete":{"tags":["tools"],"summary":"remove tools","operationId":"tools#remove","parameters":[{"name":"packager","in":"path","description":"The packager of the tool","required":true,"schema":{"type":"string","description":"The packager of the tool","example":"arduino"},"example":"arduino"},{"name":"name","in":"path","description":"The name of the tool","required":true,"schema":{"type":"string","description":"The name of the tool","example":"bossac"},"example":"bossac"},{"name":"version","in":"path","description":"The version of the tool","required":true,"schema":{"type":"string","description":"The version of the tool","example":"1.7.0-arduino3"},"example":"1.7.0-arduino3"}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/RemoveRequestBody"},"example":{"checksum":"SHA-256:1ae54999c1f97234a5c603eb99ad39313b11746a4ca517269a9285afa05f9100","signature":"382898a97b5a86edd74208f10107d2fecbf7059ffe9cc856e045266fb4db4e98802728a0859cfdcda1c0b9075ec01e42dbea1f430b813530d5a6ae1766dfbba64c3e689b59758062dc2ab2e32b2a3491dc2b9a80b9cda4ae514fbe0ec5af210111b6896976053ab76bac55bcecfcececa68adfa3299e3cde6b7f117b3552a7d80ca419374bb497e3c3f12b640cf5b20875416b45e662fc6150b99b178f8e41d6982b4c0a255925ea39773683f9aa9201dc5768b6fc857c87ff602b6a93452a541b8ec10ca07f166e61a9e9d91f0a6090bd2038ed4427af6251039fb9fe8eb62ec30d7b0f3df38bc9de7204dec478fb86f8eb3f71543710790ee169dce039d3e0","url":"http://downloads.arduino.cc/tools/bossac-1.7.0-arduino3-linux64.tar.gz"}}}},"responses":{"200":{"description":"OK response.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Operation"},"example":{"status":"ok"}}}}}}}},"components":{"schemas":{"ArduinoTool":{"type":"object","properties":{"name":{"type":"string","description":"The name of the tool","example":"bossac"},"packager":{"type":"string","description":"The packager of the tool","example":"arduino"},"version":{"type":"string","description":"The version of the tool","example":"1.7.0-arduino3"}},"description":"A tool is an executable program that can upload sketches.","example":{"name":"bossac","packager":"arduino","version":"1.7.0-arduino3"},"required":["name","version","packager"]},"InstallRequestBody":{"type":"object","properties":{"checksum":{"type":"string","description":"A checksum of the archive. Mandatory when url is present. \n\tThis ensures that the package is downloaded correcly.","example":"SHA-256:1ae54999c1f97234a5c603eb99ad39313b11746a4ca517269a9285afa05f9100"},"name":{"type":"string","description":"The name of the tool","example":"bossac"},"packager":{"type":"string","description":"The packager of the tool","example":"arduino"},"signature":{"type":"string","description":"The signature used to sign the url. Mandatory when url is present.\n\tThis ensure the security of the file downloaded","example":"382898a97b5a86edd74208f10107d2fecbf7059ffe9cc856e045266fb4db4e98802728a0859cfdcda1c0b9075ec01e42dbea1f430b813530d5a6ae1766dfbba64c3e689b59758062dc2ab2e32b2a3491dc2b9a80b9cda4ae514fbe0ec5af210111b6896976053ab76bac55bcecfcececa68adfa3299e3cde6b7f117b3552a7d80ca419374bb497e3c3f12b640cf5b20875416b45e662fc6150b99b178f8e41d6982b4c0a255925ea39773683f9aa9201dc5768b6fc857c87ff602b6a93452a541b8ec10ca07f166e61a9e9d91f0a6090bd2038ed4427af6251039fb9fe8eb62ec30d7b0f3df38bc9de7204dec478fb86f8eb3f71543710790ee169dce039d3e0"},"url":{"type":"string","description":"The url where the package can be found. Optional. \n\tIf present checksum must also be present.","example":"http://downloads.arduino.cc/tools/bossac-1.7.0-arduino3-linux64.tar.gz"},"version":{"type":"string","description":"The version of the tool","example":"1.7.0-arduino3"}},"example":{"checksum":"SHA-256:1ae54999c1f97234a5c603eb99ad39313b11746a4ca517269a9285afa05f9100","name":"bossac","packager":"arduino","signature":"382898a97b5a86edd74208f10107d2fecbf7059ffe9cc856e045266fb4db4e98802728a0859cfdcda1c0b9075ec01e42dbea1f430b813530d5a6ae1766dfbba64c3e689b59758062dc2ab2e32b2a3491dc2b9a80b9cda4ae514fbe0ec5af210111b6896976053ab76bac55bcecfcececa68adfa3299e3cde6b7f117b3552a7d80ca419374bb497e3c3f12b640cf5b20875416b45e662fc6150b99b178f8e41d6982b4c0a255925ea39773683f9aa9201dc5768b6fc857c87ff602b6a93452a541b8ec10ca07f166e61a9e9d91f0a6090bd2038ed4427af6251039fb9fe8eb62ec30d7b0f3df38bc9de7204dec478fb86f8eb3f71543710790ee169dce039d3e0","url":"http://downloads.arduino.cc/tools/bossac-1.7.0-arduino3-linux64.tar.gz","version":"1.7.0-arduino3"},"required":["name","version","packager"]},"Operation":{"type":"object","properties":{"status":{"type":"string","description":"The status of the operation","example":"ok"}},"example":{"status":"ok"},"required":["status"]},"RemoveRequestBody":{"type":"object","properties":{"checksum":{"type":"string","description":"A checksum of the archive. Mandatory when url is present. \n\tThis ensures that the package is downloaded correcly.","example":"SHA-256:1ae54999c1f97234a5c603eb99ad39313b11746a4ca517269a9285afa05f9100"},"signature":{"type":"string","description":"The signature used to sign the url. Mandatory when url is present.\n\tThis ensure the security of the file downloaded","example":"382898a97b5a86edd74208f10107d2fecbf7059ffe9cc856e045266fb4db4e98802728a0859cfdcda1c0b9075ec01e42dbea1f430b813530d5a6ae1766dfbba64c3e689b59758062dc2ab2e32b2a3491dc2b9a80b9cda4ae514fbe0ec5af210111b6896976053ab76bac55bcecfcececa68adfa3299e3cde6b7f117b3552a7d80ca419374bb497e3c3f12b640cf5b20875416b45e662fc6150b99b178f8e41d6982b4c0a255925ea39773683f9aa9201dc5768b6fc857c87ff602b6a93452a541b8ec10ca07f166e61a9e9d91f0a6090bd2038ed4427af6251039fb9fe8eb62ec30d7b0f3df38bc9de7204dec478fb86f8eb3f71543710790ee169dce039d3e0"},"url":{"type":"string","description":"The url where the package can be found. Optional. \n\tIf present checksum must also be present.","example":"http://downloads.arduino.cc/tools/bossac-1.7.0-arduino3-linux64.tar.gz"}},"example":{"checksum":"SHA-256:1ae54999c1f97234a5c603eb99ad39313b11746a4ca517269a9285afa05f9100","signature":"382898a97b5a86edd74208f10107d2fecbf7059ffe9cc856e045266fb4db4e98802728a0859cfdcda1c0b9075ec01e42dbea1f430b813530d5a6ae1766dfbba64c3e689b59758062dc2ab2e32b2a3491dc2b9a80b9cda4ae514fbe0ec5af210111b6896976053ab76bac55bcecfcececa68adfa3299e3cde6b7f117b3552a7d80ca419374bb497e3c3f12b640cf5b20875416b45e662fc6150b99b178f8e41d6982b4c0a255925ea39773683f9aa9201dc5768b6fc857c87ff602b6a93452a541b8ec10ca07f166e61a9e9d91f0a6090bd2038ed4427af6251039fb9fe8eb62ec30d7b0f3df38bc9de7204dec478fb86f8eb3f71543710790ee169dce039d3e0","url":"http://downloads.arduino.cc/tools/bossac-1.7.0-arduino3-linux64.tar.gz"}},"ToolCollection":{"type":"array","items":{"$ref":"#/components/schemas/ArduinoTool"},"example":[{"name":"bossac","packager":"arduino","version":"1.7.0-arduino3"},{"name":"bossac","packager":"arduino","version":"1.7.0-arduino3"},{"name":"bossac","packager":"arduino","version":"1.7.0-arduino3"},{"name":"bossac","packager":"arduino","version":"1.7.0-arduino3"}]}}},"tags":[{"name":"tools","description":"The tools service manages the available and installed tools"}]} \ No newline at end of file +{"openapi":"3.0.3","info":{"title":"Arduino Create Agent","description":"A companion of Arduino Create. \n\tAllows the website to perform operations on the user computer, \n\tsuch as detecting which boards are connected and upload sketches on them.","version":"1.0"},"servers":[{"url":"http://localhost:80","description":"Default server for arduino-create-agent"}],"paths":{"/v2/pkgs/tools/available":{"get":{"tags":["tools"],"summary":"available tools","operationId":"tools#available","responses":{"200":{"description":"OK response.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ToolCollection"},"example":[{"name":"bossac","packager":"arduino","version":"1.7.0-arduino3"},{"name":"bossac","packager":"arduino","version":"1.7.0-arduino3"},{"name":"bossac","packager":"arduino","version":"1.7.0-arduino3"}]}}}}}},"/v2/pkgs/tools/installed":{"get":{"tags":["tools"],"summary":"installed tools","operationId":"tools#installed","responses":{"200":{"description":"OK response.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ToolCollection"},"example":[{"name":"bossac","packager":"arduino","version":"1.7.0-arduino3"},{"name":"bossac","packager":"arduino","version":"1.7.0-arduino3"},{"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"],"summary":"install tools","operationId":"tools#install","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/InstallRequestBody"},"example":{"checksum":"SHA-256:1ae54999c1f97234a5c603eb99ad39313b11746a4ca517269a9285afa05f9100","name":"bossac","packager":"arduino","signature":"382898a97b5a86edd74208f10107d2fecbf7059ffe9cc856e045266fb4db4e98802728a0859cfdcda1c0b9075ec01e42dbea1f430b813530d5a6ae1766dfbba64c3e689b59758062dc2ab2e32b2a3491dc2b9a80b9cda4ae514fbe0ec5af210111b6896976053ab76bac55bcecfcececa68adfa3299e3cde6b7f117b3552a7d80ca419374bb497e3c3f12b640cf5b20875416b45e662fc6150b99b178f8e41d6982b4c0a255925ea39773683f9aa9201dc5768b6fc857c87ff602b6a93452a541b8ec10ca07f166e61a9e9d91f0a6090bd2038ed4427af6251039fb9fe8eb62ec30d7b0f3df38bc9de7204dec478fb86f8eb3f71543710790ee169dce039d3e0","url":"http://downloads.arduino.cc/tools/bossac-1.7.0-arduino3-linux64.tar.gz","version":"1.7.0-arduino3"}}}},"responses":{"200":{"description":"OK response.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Operation"},"example":{"status":"ok"}}}}}}},"/v2/pkgs/tools/installed/{packager}/{name}/{version}":{"delete":{"tags":["tools"],"summary":"remove tools","operationId":"tools#remove","parameters":[{"name":"packager","in":"path","description":"The packager of the tool","required":true,"schema":{"type":"string","description":"The packager of the tool","example":"arduino"},"example":"arduino"},{"name":"name","in":"path","description":"The name of the tool","required":true,"schema":{"type":"string","description":"The name of the tool","example":"bossac"},"example":"bossac"},{"name":"version","in":"path","description":"The version of the tool","required":true,"schema":{"type":"string","description":"The version of the tool","example":"1.7.0-arduino3"},"example":"1.7.0-arduino3"}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/RemoveRequestBody"},"example":{"checksum":"SHA-256:1ae54999c1f97234a5c603eb99ad39313b11746a4ca517269a9285afa05f9100","signature":"382898a97b5a86edd74208f10107d2fecbf7059ffe9cc856e045266fb4db4e98802728a0859cfdcda1c0b9075ec01e42dbea1f430b813530d5a6ae1766dfbba64c3e689b59758062dc2ab2e32b2a3491dc2b9a80b9cda4ae514fbe0ec5af210111b6896976053ab76bac55bcecfcececa68adfa3299e3cde6b7f117b3552a7d80ca419374bb497e3c3f12b640cf5b20875416b45e662fc6150b99b178f8e41d6982b4c0a255925ea39773683f9aa9201dc5768b6fc857c87ff602b6a93452a541b8ec10ca07f166e61a9e9d91f0a6090bd2038ed4427af6251039fb9fe8eb62ec30d7b0f3df38bc9de7204dec478fb86f8eb3f71543710790ee169dce039d3e0","url":"http://downloads.arduino.cc/tools/bossac-1.7.0-arduino3-linux64.tar.gz"}}}},"responses":{"200":{"description":"OK response.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Operation"},"example":{"status":"ok"}}}}}}}},"components":{"schemas":{"ArduinoTool":{"type":"object","properties":{"name":{"type":"string","description":"The name of the tool","example":"bossac"},"packager":{"type":"string","description":"The packager of the tool","example":"arduino"},"version":{"type":"string","description":"The version of the tool","example":"1.7.0-arduino3"}},"description":"A tool is an executable program that can upload sketches.","example":{"name":"bossac","packager":"arduino","version":"1.7.0-arduino3"},"required":["name","version","packager"]},"InstallRequestBody":{"type":"object","properties":{"checksum":{"type":"string","description":"A checksum of the archive. Mandatory when url is present. \n\tThis ensures that the package is downloaded correcly.","example":"SHA-256:1ae54999c1f97234a5c603eb99ad39313b11746a4ca517269a9285afa05f9100"},"name":{"type":"string","description":"The name of the tool","example":"bossac"},"packager":{"type":"string","description":"The packager of the tool","example":"arduino"},"signature":{"type":"string","description":"The signature used to sign the url. Mandatory when url is present.\n\tThis ensure the security of the file downloaded","example":"382898a97b5a86edd74208f10107d2fecbf7059ffe9cc856e045266fb4db4e98802728a0859cfdcda1c0b9075ec01e42dbea1f430b813530d5a6ae1766dfbba64c3e689b59758062dc2ab2e32b2a3491dc2b9a80b9cda4ae514fbe0ec5af210111b6896976053ab76bac55bcecfcececa68adfa3299e3cde6b7f117b3552a7d80ca419374bb497e3c3f12b640cf5b20875416b45e662fc6150b99b178f8e41d6982b4c0a255925ea39773683f9aa9201dc5768b6fc857c87ff602b6a93452a541b8ec10ca07f166e61a9e9d91f0a6090bd2038ed4427af6251039fb9fe8eb62ec30d7b0f3df38bc9de7204dec478fb86f8eb3f71543710790ee169dce039d3e0"},"url":{"type":"string","description":"The url where the package can be found. Optional. \n\tIf present checksum must also be present.","example":"http://downloads.arduino.cc/tools/bossac-1.7.0-arduino3-linux64.tar.gz"},"version":{"type":"string","description":"The version of the tool","example":"1.7.0-arduino3"}},"example":{"checksum":"SHA-256:1ae54999c1f97234a5c603eb99ad39313b11746a4ca517269a9285afa05f9100","name":"bossac","packager":"arduino","signature":"382898a97b5a86edd74208f10107d2fecbf7059ffe9cc856e045266fb4db4e98802728a0859cfdcda1c0b9075ec01e42dbea1f430b813530d5a6ae1766dfbba64c3e689b59758062dc2ab2e32b2a3491dc2b9a80b9cda4ae514fbe0ec5af210111b6896976053ab76bac55bcecfcececa68adfa3299e3cde6b7f117b3552a7d80ca419374bb497e3c3f12b640cf5b20875416b45e662fc6150b99b178f8e41d6982b4c0a255925ea39773683f9aa9201dc5768b6fc857c87ff602b6a93452a541b8ec10ca07f166e61a9e9d91f0a6090bd2038ed4427af6251039fb9fe8eb62ec30d7b0f3df38bc9de7204dec478fb86f8eb3f71543710790ee169dce039d3e0","url":"http://downloads.arduino.cc/tools/bossac-1.7.0-arduino3-linux64.tar.gz","version":"1.7.0-arduino3"},"required":["name","version","packager"]},"Operation":{"type":"object","properties":{"status":{"type":"string","description":"The status of the operation","example":"ok"}},"example":{"status":"ok"},"required":["status"]},"RemoveRequestBody":{"type":"object","properties":{"checksum":{"type":"string","description":"A checksum of the archive. Mandatory when url is present. \n\tThis ensures that the package is downloaded correcly.","example":"SHA-256:1ae54999c1f97234a5c603eb99ad39313b11746a4ca517269a9285afa05f9100"},"signature":{"type":"string","description":"The signature used to sign the url. Mandatory when url is present.\n\tThis ensure the security of the file downloaded","example":"382898a97b5a86edd74208f10107d2fecbf7059ffe9cc856e045266fb4db4e98802728a0859cfdcda1c0b9075ec01e42dbea1f430b813530d5a6ae1766dfbba64c3e689b59758062dc2ab2e32b2a3491dc2b9a80b9cda4ae514fbe0ec5af210111b6896976053ab76bac55bcecfcececa68adfa3299e3cde6b7f117b3552a7d80ca419374bb497e3c3f12b640cf5b20875416b45e662fc6150b99b178f8e41d6982b4c0a255925ea39773683f9aa9201dc5768b6fc857c87ff602b6a93452a541b8ec10ca07f166e61a9e9d91f0a6090bd2038ed4427af6251039fb9fe8eb62ec30d7b0f3df38bc9de7204dec478fb86f8eb3f71543710790ee169dce039d3e0"},"url":{"type":"string","description":"The url where the package can be found. Optional. \n\tIf present checksum must also be present.","example":"http://downloads.arduino.cc/tools/bossac-1.7.0-arduino3-linux64.tar.gz"}},"example":{"checksum":"SHA-256:1ae54999c1f97234a5c603eb99ad39313b11746a4ca517269a9285afa05f9100","signature":"382898a97b5a86edd74208f10107d2fecbf7059ffe9cc856e045266fb4db4e98802728a0859cfdcda1c0b9075ec01e42dbea1f430b813530d5a6ae1766dfbba64c3e689b59758062dc2ab2e32b2a3491dc2b9a80b9cda4ae514fbe0ec5af210111b6896976053ab76bac55bcecfcececa68adfa3299e3cde6b7f117b3552a7d80ca419374bb497e3c3f12b640cf5b20875416b45e662fc6150b99b178f8e41d6982b4c0a255925ea39773683f9aa9201dc5768b6fc857c87ff602b6a93452a541b8ec10ca07f166e61a9e9d91f0a6090bd2038ed4427af6251039fb9fe8eb62ec30d7b0f3df38bc9de7204dec478fb86f8eb3f71543710790ee169dce039d3e0","url":"http://downloads.arduino.cc/tools/bossac-1.7.0-arduino3-linux64.tar.gz"}},"ToolCollection":{"type":"array","items":{"$ref":"#/components/schemas/ArduinoTool"},"example":[{"name":"bossac","packager":"arduino","version":"1.7.0-arduino3"},{"name":"bossac","packager":"arduino","version":"1.7.0-arduino3"},{"name":"bossac","packager":"arduino","version":"1.7.0-arduino3"},{"name":"bossac","packager":"arduino","version":"1.7.0-arduino3"}]}}},"tags":[{"name":"tools","description":"The tools service manages the available and installed tools"}]} \ No newline at end of file diff --git a/gen/http/openapi3.yaml b/gen/http/openapi3.yaml index a39c969b2..d1ad450ef 100644 --- a/gen/http/openapi3.yaml +++ b/gen/http/openapi3.yaml @@ -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 diff --git a/gen/http/tools/client/client.go b/gen/http/tools/client/client.go index 102996f83..28f7cb610 100644 --- a/gen/http/tools/client/client.go +++ b/gen/http/tools/client/client.go @@ -21,6 +21,10 @@ type Client struct { // endpoint. AvailableDoer goahttp.Doer + // Installedhead Doer is the HTTP client used to make requests to the + // installedhead endpoint. + InstalledheadDoer goahttp.Doer + // Installed Doer is the HTTP client used to make requests to the installed // endpoint. InstalledDoer goahttp.Doer @@ -53,6 +57,7 @@ func NewClient( ) *Client { return &Client{ AvailableDoer: doer, + InstalledheadDoer: doer, InstalledDoer: doer, InstallDoer: doer, RemoveDoer: doer, @@ -83,6 +88,25 @@ func (c *Client) Available() goa.Endpoint { } } +// Installedhead returns an endpoint that makes HTTP requests to the tools +// service installedhead server. +func (c *Client) Installedhead() goa.Endpoint { + var ( + decodeResponse = DecodeInstalledheadResponse(c.decoder, c.RestoreResponseBody) + ) + return func(ctx context.Context, v any) (any, error) { + req, err := c.BuildInstalledheadRequest(ctx, v) + if err != nil { + return nil, err + } + resp, err := c.InstalledheadDoer.Do(req) + if err != nil { + return nil, goahttp.ErrRequestError("tools", "installedhead", err) + } + return decodeResponse(resp) + } +} + // Installed returns an endpoint that makes HTTP requests to the tools service // installed server. func (c *Client) Installed() goa.Endpoint { diff --git a/gen/http/tools/client/encode_decode.go b/gen/http/tools/client/encode_decode.go index b767f5765..f4dd88c7c 100644 --- a/gen/http/tools/client/encode_decode.go +++ b/gen/http/tools/client/encode_decode.go @@ -76,6 +76,48 @@ func DecodeAvailableResponse(decoder func(*http.Response) goahttp.Decoder, resto } } +// BuildInstalledheadRequest instantiates a HTTP request object with method and +// path set to call the "tools" service "installedhead" endpoint +func (c *Client) BuildInstalledheadRequest(ctx context.Context, v any) (*http.Request, error) { + u := &url.URL{Scheme: c.scheme, Host: c.host, Path: InstalledheadToolsPath()} + req, err := http.NewRequest("HEAD", u.String(), nil) + if err != nil { + return nil, goahttp.ErrInvalidURL("tools", "installedhead", u.String(), err) + } + if ctx != nil { + req = req.WithContext(ctx) + } + + return req, nil +} + +// DecodeInstalledheadResponse returns a decoder for responses returned by the +// tools installedhead endpoint. restoreBody controls whether the response body +// should be restored after having been read. +func DecodeInstalledheadResponse(decoder func(*http.Response) goahttp.Decoder, restoreBody bool) func(*http.Response) (any, error) { + return func(resp *http.Response) (any, error) { + if restoreBody { + b, err := io.ReadAll(resp.Body) + if err != nil { + return nil, err + } + resp.Body = io.NopCloser(bytes.NewBuffer(b)) + defer func() { + resp.Body = io.NopCloser(bytes.NewBuffer(b)) + }() + } else { + defer resp.Body.Close() + } + switch resp.StatusCode { + case http.StatusOK: + return nil, nil + default: + body, _ := io.ReadAll(resp.Body) + return nil, goahttp.ErrInvalidResponse("tools", "installedhead", resp.StatusCode, string(body)) + } + } +} + // BuildInstalledRequest instantiates a HTTP request object with method and // path set to call the "tools" service "installed" endpoint func (c *Client) BuildInstalledRequest(ctx context.Context, v any) (*http.Request, error) { diff --git a/gen/http/tools/client/paths.go b/gen/http/tools/client/paths.go index cab4d5fd6..d7708d868 100644 --- a/gen/http/tools/client/paths.go +++ b/gen/http/tools/client/paths.go @@ -16,6 +16,11 @@ func AvailableToolsPath() string { return "/v2/pkgs/tools/available" } +// InstalledheadToolsPath returns the URL path to the tools service installedhead HTTP endpoint. +func InstalledheadToolsPath() string { + return "/v2/pkgs/tools/installed" +} + // InstalledToolsPath returns the URL path to the tools service installed HTTP endpoint. func InstalledToolsPath() string { return "/v2/pkgs/tools/installed" diff --git a/gen/http/tools/server/encode_decode.go b/gen/http/tools/server/encode_decode.go index 694d68cf6..4985ce456 100644 --- a/gen/http/tools/server/encode_decode.go +++ b/gen/http/tools/server/encode_decode.go @@ -29,6 +29,15 @@ func EncodeAvailableResponse(encoder func(context.Context, http.ResponseWriter) } } +// EncodeInstalledheadResponse returns an encoder for responses returned by the +// tools installedhead endpoint. +func EncodeInstalledheadResponse(encoder func(context.Context, http.ResponseWriter) goahttp.Encoder) func(context.Context, http.ResponseWriter, any) error { + return func(ctx context.Context, w http.ResponseWriter, v any) error { + w.WriteHeader(http.StatusOK) + return nil + } +} + // EncodeInstalledResponse returns an encoder for responses returned by the // tools installed endpoint. func EncodeInstalledResponse(encoder func(context.Context, http.ResponseWriter) goahttp.Encoder) func(context.Context, http.ResponseWriter, any) error { diff --git a/gen/http/tools/server/paths.go b/gen/http/tools/server/paths.go index cb63e280e..65a0debb6 100644 --- a/gen/http/tools/server/paths.go +++ b/gen/http/tools/server/paths.go @@ -16,6 +16,11 @@ func AvailableToolsPath() string { return "/v2/pkgs/tools/available" } +// InstalledheadToolsPath returns the URL path to the tools service installedhead HTTP endpoint. +func InstalledheadToolsPath() string { + return "/v2/pkgs/tools/installed" +} + // InstalledToolsPath returns the URL path to the tools service installed HTTP endpoint. func InstalledToolsPath() string { return "/v2/pkgs/tools/installed" diff --git a/gen/http/tools/server/server.go b/gen/http/tools/server/server.go index 5ee51a660..0ef0943c6 100644 --- a/gen/http/tools/server/server.go +++ b/gen/http/tools/server/server.go @@ -18,11 +18,12 @@ import ( // Server lists the tools service endpoint HTTP handlers. type Server struct { - Mounts []*MountPoint - Available http.Handler - Installed http.Handler - Install http.Handler - Remove http.Handler + Mounts []*MountPoint + Available http.Handler + Installedhead http.Handler + Installed http.Handler + Install http.Handler + Remove http.Handler } // MountPoint holds information about the mounted endpoints. @@ -53,14 +54,16 @@ func New( return &Server{ Mounts: []*MountPoint{ {"Available", "GET", "/v2/pkgs/tools/available"}, + {"Installedhead", "HEAD", "/v2/pkgs/tools/installed"}, {"Installed", "GET", "/v2/pkgs/tools/installed"}, {"Install", "POST", "/v2/pkgs/tools/installed"}, {"Remove", "DELETE", "/v2/pkgs/tools/installed/{packager}/{name}/{version}"}, }, - Available: NewAvailableHandler(e.Available, mux, decoder, encoder, errhandler, formatter), - Installed: NewInstalledHandler(e.Installed, mux, decoder, encoder, errhandler, formatter), - Install: NewInstallHandler(e.Install, mux, decoder, encoder, errhandler, formatter), - Remove: NewRemoveHandler(e.Remove, mux, decoder, encoder, errhandler, formatter), + Available: NewAvailableHandler(e.Available, mux, decoder, encoder, errhandler, formatter), + Installedhead: NewInstalledheadHandler(e.Installedhead, mux, decoder, encoder, errhandler, formatter), + Installed: NewInstalledHandler(e.Installed, mux, decoder, encoder, errhandler, formatter), + Install: NewInstallHandler(e.Install, mux, decoder, encoder, errhandler, formatter), + Remove: NewRemoveHandler(e.Remove, mux, decoder, encoder, errhandler, formatter), } } @@ -70,6 +73,7 @@ func (s *Server) Service() string { return "tools" } // Use wraps the server handlers with the given middleware. func (s *Server) Use(m func(http.Handler) http.Handler) { s.Available = m(s.Available) + s.Installedhead = m(s.Installedhead) s.Installed = m(s.Installed) s.Install = m(s.Install) s.Remove = m(s.Remove) @@ -81,6 +85,7 @@ func (s *Server) MethodNames() []string { return tools.MethodNames[:] } // Mount configures the mux to serve the tools endpoints. func Mount(mux goahttp.Muxer, h *Server) { MountAvailableHandler(mux, h.Available) + MountInstalledheadHandler(mux, h.Installedhead) MountInstalledHandler(mux, h.Installed) MountInstallHandler(mux, h.Install) MountRemoveHandler(mux, h.Remove) @@ -135,6 +140,50 @@ func NewAvailableHandler( }) } +// MountInstalledheadHandler configures the mux to serve the "tools" service +// "installedhead" endpoint. +func MountInstalledheadHandler(mux goahttp.Muxer, h http.Handler) { + f, ok := h.(http.HandlerFunc) + if !ok { + f = func(w http.ResponseWriter, r *http.Request) { + h.ServeHTTP(w, r) + } + } + mux.Handle("HEAD", "/v2/pkgs/tools/installed", f) +} + +// NewInstalledheadHandler creates a HTTP handler which loads the HTTP request +// and calls the "tools" service "installedhead" endpoint. +func NewInstalledheadHandler( + endpoint goa.Endpoint, + mux goahttp.Muxer, + decoder func(*http.Request) goahttp.Decoder, + encoder func(context.Context, http.ResponseWriter) goahttp.Encoder, + errhandler func(context.Context, http.ResponseWriter, error), + formatter func(ctx context.Context, err error) goahttp.Statuser, +) http.Handler { + var ( + encodeResponse = EncodeInstalledheadResponse(encoder) + encodeError = goahttp.ErrorEncoder(encoder, formatter) + ) + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + ctx := context.WithValue(r.Context(), goahttp.AcceptTypeKey, r.Header.Get("Accept")) + ctx = context.WithValue(ctx, goa.MethodKey, "installedhead") + ctx = context.WithValue(ctx, goa.ServiceKey, "tools") + var err error + res, err := endpoint(ctx, nil) + if err != nil { + if err := encodeError(ctx, w, err); err != nil { + errhandler(ctx, w, err) + } + return + } + if err := encodeResponse(ctx, w, res); err != nil { + errhandler(ctx, w, err) + } + }) +} + // MountInstalledHandler configures the mux to serve the "tools" service // "installed" endpoint. func MountInstalledHandler(mux goahttp.Muxer, h http.Handler) { diff --git a/gen/tools/client.go b/gen/tools/client.go index 6596aa6a3..8cff1c868 100644 --- a/gen/tools/client.go +++ b/gen/tools/client.go @@ -15,19 +15,21 @@ import ( // Client is the "tools" service client. type Client struct { - AvailableEndpoint goa.Endpoint - InstalledEndpoint goa.Endpoint - InstallEndpoint goa.Endpoint - RemoveEndpoint goa.Endpoint + AvailableEndpoint goa.Endpoint + InstalledheadEndpoint goa.Endpoint + InstalledEndpoint goa.Endpoint + InstallEndpoint goa.Endpoint + RemoveEndpoint goa.Endpoint } // NewClient initializes a "tools" service client given the endpoints. -func NewClient(available, installed, install, remove goa.Endpoint) *Client { +func NewClient(available, installedhead, installed, install, remove goa.Endpoint) *Client { return &Client{ - AvailableEndpoint: available, - InstalledEndpoint: installed, - InstallEndpoint: install, - RemoveEndpoint: remove, + AvailableEndpoint: available, + InstalledheadEndpoint: installedhead, + InstalledEndpoint: installed, + InstallEndpoint: install, + RemoveEndpoint: remove, } } @@ -41,6 +43,12 @@ func (c *Client) Available(ctx context.Context) (res ToolCollection, err error) return ires.(ToolCollection), nil } +// Installedhead calls the "installedhead" endpoint of the "tools" service. +func (c *Client) Installedhead(ctx context.Context) (err error) { + _, err = c.InstalledheadEndpoint(ctx, nil) + return +} + // Installed calls the "installed" endpoint of the "tools" service. func (c *Client) Installed(ctx context.Context) (res ToolCollection, err error) { var ires any diff --git a/gen/tools/endpoints.go b/gen/tools/endpoints.go index 0d38ae1bd..bb26433ba 100644 --- a/gen/tools/endpoints.go +++ b/gen/tools/endpoints.go @@ -15,25 +15,28 @@ import ( // Endpoints wraps the "tools" service endpoints. type Endpoints struct { - Available goa.Endpoint - Installed goa.Endpoint - Install goa.Endpoint - Remove goa.Endpoint + Available goa.Endpoint + Installedhead goa.Endpoint + Installed goa.Endpoint + Install goa.Endpoint + Remove goa.Endpoint } // NewEndpoints wraps the methods of the "tools" service with endpoints. func NewEndpoints(s Service) *Endpoints { return &Endpoints{ - Available: NewAvailableEndpoint(s), - Installed: NewInstalledEndpoint(s), - Install: NewInstallEndpoint(s), - Remove: NewRemoveEndpoint(s), + Available: NewAvailableEndpoint(s), + Installedhead: NewInstalledheadEndpoint(s), + Installed: NewInstalledEndpoint(s), + Install: NewInstallEndpoint(s), + Remove: NewRemoveEndpoint(s), } } // Use applies the given middleware to all the "tools" service endpoints. func (e *Endpoints) Use(m func(goa.Endpoint) goa.Endpoint) { e.Available = m(e.Available) + e.Installedhead = m(e.Installedhead) e.Installed = m(e.Installed) e.Install = m(e.Install) e.Remove = m(e.Remove) @@ -52,6 +55,14 @@ func NewAvailableEndpoint(s Service) goa.Endpoint { } } +// NewInstalledheadEndpoint returns an endpoint function that calls the method +// "installedhead" of service "tools". +func NewInstalledheadEndpoint(s Service) goa.Endpoint { + return func(ctx context.Context, req any) (any, error) { + return nil, s.Installedhead(ctx) + } +} + // NewInstalledEndpoint returns an endpoint function that calls the method // "installed" of service "tools". func NewInstalledEndpoint(s Service) goa.Endpoint { diff --git a/gen/tools/service.go b/gen/tools/service.go index 8165af903..acc2f7fbc 100644 --- a/gen/tools/service.go +++ b/gen/tools/service.go @@ -18,6 +18,8 @@ import ( type Service interface { // Available implements available. Available(context.Context) (res ToolCollection, err error) + // Installedhead implements installedhead. + Installedhead(context.Context) (err error) // Installed implements installed. Installed(context.Context) (res ToolCollection, err error) // Install implements install. @@ -34,7 +36,7 @@ const ServiceName = "tools" // MethodNames lists the service method names as defined in the design. These // are the same values that are set in the endpoint request contexts under the // MethodKey key. -var MethodNames = [4]string{"available", "installed", "install", "remove"} +var MethodNames = [5]string{"available", "installedhead", "installed", "install", "remove"} // Operation is the result type of the tools service install method. type Operation struct { diff --git a/v2/pkgs/tools.go b/v2/pkgs/tools.go index f9636f077..d8423b140 100644 --- a/v2/pkgs/tools.go +++ b/v2/pkgs/tools.go @@ -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()