Skip to content

Commit

Permalink
Added api for downloading the script (#56)
Browse files Browse the repository at this point in the history
* Added api for downloading the script

Signed-off-by: vviveksharma <[email protected]>

* added the review comments

Signed-off-by: vviveksharma <[email protected]>

* added review comments

Signed-off-by: vviveksharma <[email protected]>

* added the product features as well

Signed-off-by: vviveksharma <[email protected]>

* added docs

Signed-off-by: vviveksharma <[email protected]>

* refactored the code

Signed-off-by: vviveksharma <[email protected]>

* added the latest changes

Signed-off-by: vviveksharma <[email protected]>

* latest code

Signed-off-by: vviveksharma <[email protected]>

* made new apis for install files

Signed-off-by: vviveksharma <[email protected]>

* updated docs

Signed-off-by: vviveksharma <[email protected]>

* refactored changes

Signed-off-by: vviveksharma <[email protected]>

* added new file names

Signed-off-by: vviveksharma <[email protected]>

---------

Signed-off-by: vviveksharma <[email protected]>
  • Loading branch information
vviveksharma authored Jul 16, 2024
1 parent d3aaee3 commit 32977b5
Show file tree
Hide file tree
Showing 16 changed files with 1,828 additions and 9 deletions.
73 changes: 71 additions & 2 deletions docs/OmnitruckApi_docs.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Code generated by swaggo/swag. DO NOT EDIT.

// Package docs Code generated by swaggo/swag. DO NOT EDIT
package docs

import "github.com/swaggo/swag"
Expand Down Expand Up @@ -42,6 +41,74 @@ const docTemplateOmnitruckApi = `{
}
}
},
"/install.ps1": {
"get": {
"description": "The ` + "`" + `ACCEPT` + "`" + ` HTTP header with a value of ` + "`" + `text/plain` + "`" + ` must be provided in the request for a text response to be returned",
"parameters": [
{
"type": "string",
"description": "License ID",
"name": "license_id",
"in": "query"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "object",
"additionalProperties": true
}
},
"403": {
"description": "Forbidden",
"schema": {
"$ref": "#/definitions/ErrorResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/ErrorResponse"
}
}
}
}
},
"/install.sh": {
"get": {
"description": "The ` + "`" + `ACCEPT` + "`" + ` HTTP header with a value of ` + "`" + `application/x-sh` + "`" + ` must be provided in the request for a shell script response to be returned",
"parameters": [
{
"type": "string",
"description": "License ID",
"name": "license_id",
"in": "query"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "object",
"additionalProperties": true
}
},
"403": {
"description": "Forbidden",
"schema": {
"$ref": "#/definitions/ErrorResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/ErrorResponse"
}
}
}
}
},
"/platforms": {
"get": {
"description": "Returns a valid list of valid platform keys along with full friendly names.\nAny of these platform keys can be used in the p query string value in various endpoints below.",
Expand Down Expand Up @@ -636,6 +703,8 @@ var SwaggerInfoOmnitruckApi = &swag.Spec{
Description: "Licensed Omnitruck API",
InfoInstanceName: "OmnitruckApi",
SwaggerTemplate: docTemplateOmnitruckApi,
LeftDelim: "{{",
RightDelim: "}}",
}

func init() {
Expand Down
68 changes: 68 additions & 0 deletions docs/OmnitruckApi_swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,74 @@
}
}
},
"/install.ps1": {
"get": {
"description": "The `ACCEPT` HTTP header with a value of `text/plain` must be provided in the request for a text response to be returned",
"parameters": [
{
"type": "string",
"description": "License ID",
"name": "license_id",
"in": "query"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "object",
"additionalProperties": true
}
},
"403": {
"description": "Forbidden",
"schema": {
"$ref": "#/definitions/ErrorResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/ErrorResponse"
}
}
}
}
},
"/install.sh": {
"get": {
"description": "The `ACCEPT` HTTP header with a value of `application/x-sh` must be provided in the request for a shell script response to be returned",
"parameters": [
{
"type": "string",
"description": "License ID",
"name": "license_id",
"in": "query"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "object",
"additionalProperties": true
}
},
"403": {
"description": "Forbidden",
"schema": {
"$ref": "#/definitions/ErrorResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/ErrorResponse"
}
}
}
}
},
"/platforms": {
"get": {
"description": "Returns a valid list of valid platform keys along with full friendly names.\nAny of these platform keys can be used in the p query string value in various endpoints below.",
Expand Down
46 changes: 46 additions & 0 deletions docs/OmnitruckApi_swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,52 @@ paths:
description: Internal Server Error
schema:
$ref: '#/definitions/ErrorResponse'
/install.ps1:
get:
description: The `ACCEPT` HTTP header with a value of `text/plain` must be provided
in the request for a text response to be returned
parameters:
- description: License ID
in: query
name: license_id
type: string
responses:
"200":
description: OK
schema:
additionalProperties: true
type: object
"403":
description: Forbidden
schema:
$ref: '#/definitions/ErrorResponse'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/ErrorResponse'
/install.sh:
get:
description: The `ACCEPT` HTTP header with a value of `application/x-sh` must
be provided in the request for a shell script response to be returned
parameters:
- description: License ID
in: query
name: license_id
type: string
responses:
"200":
description: OK
schema:
additionalProperties: true
type: object
"403":
description: Forbidden
schema:
$ref: '#/definitions/ErrorResponse'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/ErrorResponse'
/platforms:
get:
description: |-
Expand Down
6 changes: 6 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ require (
require (
github.com/KyleBanks/depth v1.2.1 // indirect
github.com/andybalholm/brotli v1.1.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect
github.com/go-openapi/jsonpointer v0.21.0 // indirect
github.com/go-openapi/jsonreference v0.21.0 // indirect
github.com/go-openapi/spec v0.21.0 // indirect
Expand All @@ -40,11 +41,16 @@ require (
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/swaggo/files/v2 v2.0.0 // indirect
github.com/urfave/cli/v2 v2.3.0 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasthttp v1.55.0 // indirect
github.com/valyala/tcplisten v1.0.0 // indirect
golang.org/x/sys v0.21.0 // indirect
golang.org/x/text v0.16.0 // indirect
golang.org/x/tools v0.22.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)
13 changes: 13 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/KyleBanks/depth v1.2.1 h1:5h8fQADFrWtarTdtDudMmGsC7GPbOAu6RVB3ffsVFHc=
github.com/KyleBanks/depth v1.2.1/go.mod h1:jzSb9d0L43HxTQfT+oSA1EEp2q+ne2uh6XgeJcm8brE=
github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1U3M=
github.com/andybalholm/brotli v1.1.0/go.mod h1:sms7XGricyQI9K10gOSf56VKKWS4oLer58Q+mhRPtnY=
github.com/aws/aws-sdk-go v1.54.7 h1:k1wJ+NMOsXgq/Lsa0y1mS0DFoDeHFPcz2OjCq5H5Mjg=
github.com/aws/aws-sdk-go v1.54.7/go.mod h1:eRwEWoyTWFMVYVQzKMNHWP5/RV4xIUGMQfXQHfHkpNU=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/cpuguy83/go-md2man/v2 v2.0.4 h1:wfIWP927BUkWJb2NmU/kNDYIBTh/ziUX91+lVfRxZq4=
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
Expand Down Expand Up @@ -62,7 +65,10 @@ github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM=
Expand All @@ -77,6 +83,8 @@ github.com/swaggo/files/v2 v2.0.0 h1:hmAt8Dkynw7Ssz46F6pn8ok6YmGZqHSVLZ+HQM7i0kw
github.com/swaggo/files/v2 v2.0.0/go.mod h1:24kk2Y9NYEJ5lHuCra6iVwkMjIekMCaFq/0JQj66kyM=
github.com/swaggo/swag v1.16.3 h1:PnCYjPCah8FK4I26l2F/KQ4yz3sILcVUN3cTlBFA9Pg=
github.com/swaggo/swag v1.16.3/go.mod h1:DImHIuOFXKpMFAQjcC7FG4m3Dg4+QuUgUzJmKjI/gRk=
github.com/urfave/cli/v2 v2.3.0 h1:qph92Y649prgesehzOrQjdWyxFOp/QVM+6imKHad91M=
github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasthttp v1.55.0 h1:Zkefzgt6a7+bVKHnu/YaYSOPfNYNisSVBo/unVCf8k8=
Expand All @@ -92,14 +100,19 @@ golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws=
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4=
golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI=
golang.org/x/tools v0.22.0 h1:gqSGLZqv+AI9lIQzniJ0nZDRG5GBPsSi+DRNHWNz6yA=
golang.org/x/tools v0.22.0/go.mod h1:aCwcsjqvq7Yqt6TNyX7QMU2enbQ/Gt0bo6krSeEri+c=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
sigs.k8s.io/yaml v1.3.0 h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo=
sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8=
5 changes: 5 additions & 0 deletions models/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,8 @@ type RelatedProducts struct {
Bom string `json:"bom"`
Products map[string]string `json:"products"`
}

type ScriptParams struct {
BaseUrl string `json:"base_url"`
LicenseId string `json:"licenseId"`
}
55 changes: 54 additions & 1 deletion services/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ func (server *ApiService) buildRouter() {
server.App.Get("/:channel/:product/download", requestid.New(), server.productDownloadHandler)
server.App.Get("/relatedProducts", requestid.New(), server.relatedProductsHandler)
server.App.Get("/:channel/:product/fileName", requestid.New(), server.fileNameHandler)

server.App.Get("/install.sh", requestid.New(), server.downloadLinuxScript)
server.App.Get("/install.ps1", requestid.New(), server.downloadWindowsScript)
}

func (server *ApiService) docsHandler(baseUrl string) func(*fiber.Ctx) error {
Expand Down Expand Up @@ -648,3 +649,55 @@ func (server *ApiService) isOsVersion(params *omnitruck.RequestParams, c *fiber.
}
return fiber.NewError(fiber.StatusBadRequest, errMsg)
}

// @description The `ACCEPT` HTTP header with a value of `application/x-sh` must be provided in the request for a shell script response to be returned
// @Param license_id query string false "License ID"
// @Success 200 {object} map[string]interface{}
// @Failure 403 {object} services.ErrorResponse
// @Failure 500 {object} services.ErrorResponse
// @Router /install.sh [get]
func (server *ApiService) downloadLinuxScript(c *fiber.Ctx) error {
params := getRequestParams(c)
c.Set("Content-Type", "application/x-sh")
err, ok := server.ValidateRequest(params, c)
if !ok {
server.logCtx(c).Error("Validation of download linux script API failed: ", err)
return err
}
if server.Mode == Opensource {
params.LicenseId = ""
}
filePath := "../templates/install.sh.tmpl"
resp, err := server.TemplateRenderer.GetScript(c.Hostname(), params, filePath)
if err != nil {
return err
}
c.Set("Content-Disposition", "attachment;filename=install.sh")
return c.SendString(resp)
}

// @description The `ACCEPT` HTTP header with a value of `text/plain` must be provided in the request for a text response to be returned
// @Param license_id query string false "License ID"
// @Success 200 {object} map[string]interface{}
// @Failure 403 {object} services.ErrorResponse
// @Failure 500 {object} services.ErrorResponse
// @Router /install.ps1 [get]
func (server *ApiService) downloadWindowsScript(c *fiber.Ctx) error {
params := getRequestParams(c)
c.Set("Content-Type", "text/plain")
err, ok := server.ValidateRequest(params, c)
if !ok {
server.logCtx(c).Error("Validation of download windows script API failed: ", err)
return err
}
if server.Mode == Opensource {
params.LicenseId = ""
}
filePath := "../templates/install.ps1.tmpl"
resp, err := server.TemplateRenderer.GetScript(c.Hostname(), params, filePath)
if err != nil {
return err
}
c.Set("Content-Disposition", "attachment;filename=install.ps1")
return c.SendString(resp)
}
Loading

0 comments on commit 32977b5

Please sign in to comment.