functionbuilder
This commit is contained in:
57
build/app/cmd/export-xlsx-server/main.go
Normal file
57
build/app/cmd/export-xlsx-server/main.go
Normal file
@@ -0,0 +1,57 @@
|
||||
// Code generated by go-swagger; DO NOT EDIT.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/go-openapi/loads"
|
||||
flags "github.com/jessevdk/go-flags"
|
||||
|
||||
"app/restapi"
|
||||
"app/restapi/operations"
|
||||
)
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Make sure not to overwrite this file after you generated it because all your edits would be lost!
|
||||
|
||||
func main() {
|
||||
|
||||
swaggerSpec, err := loads.Embedded(restapi.SwaggerJSON, restapi.FlatSwaggerJSON)
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
||||
api := operations.NewExportXlsxAPI(swaggerSpec)
|
||||
server := restapi.NewServer(api)
|
||||
defer server.Shutdown()
|
||||
|
||||
parser := flags.NewParser(server, flags.Default)
|
||||
parser.ShortDescription = "export-xlsx"
|
||||
parser.LongDescription = "Transform json input to xlsx spreadsheet"
|
||||
server.ConfigureFlags()
|
||||
for _, optsGroup := range api.CommandLineOptionsGroups {
|
||||
_, err := parser.AddGroup(optsGroup.ShortDescription, optsGroup.LongDescription, optsGroup.Options)
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
}
|
||||
|
||||
if _, err := parser.Parse(); err != nil {
|
||||
code := 1
|
||||
if fe, ok := err.(*flags.Error); ok {
|
||||
if fe.Type == flags.ErrHelp {
|
||||
code = 0
|
||||
}
|
||||
}
|
||||
os.Exit(code)
|
||||
}
|
||||
|
||||
server.ConfigureAPI()
|
||||
|
||||
if err := server.Serve(); err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
||||
}
|
43
build/app/go.mod
Normal file
43
build/app/go.mod
Normal file
@@ -0,0 +1,43 @@
|
||||
module app
|
||||
|
||||
go 1.18
|
||||
|
||||
require (
|
||||
github.com/Masterminds/sprig v2.22.0+incompatible
|
||||
github.com/direktiv/apps/go v0.0.0-20220729073403-d70407c25d70
|
||||
github.com/go-openapi/errors v0.20.2
|
||||
github.com/go-openapi/loads v0.21.1
|
||||
github.com/go-openapi/runtime v0.24.1
|
||||
github.com/go-openapi/spec v0.20.6
|
||||
github.com/go-openapi/strfmt v0.21.3
|
||||
github.com/go-openapi/swag v0.21.1
|
||||
github.com/go-openapi/validate v0.22.0
|
||||
github.com/jessevdk/go-flags v1.5.0
|
||||
github.com/mattn/go-shellwords v1.0.12
|
||||
golang.org/x/net v0.0.0-20220728211354-c7608f3a8462
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/Masterminds/goutils v1.1.1 // indirect
|
||||
github.com/Masterminds/semver v1.5.0 // indirect
|
||||
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d // indirect
|
||||
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d // indirect
|
||||
github.com/docker/go-units v0.4.0 // indirect
|
||||
github.com/go-openapi/analysis v0.21.2 // indirect
|
||||
github.com/go-openapi/jsonpointer v0.19.5 // indirect
|
||||
github.com/go-openapi/jsonreference v0.20.0 // indirect
|
||||
github.com/google/uuid v1.1.1 // indirect
|
||||
github.com/huandu/xstrings v1.3.2 // indirect
|
||||
github.com/imdario/mergo v0.3.13 // indirect
|
||||
github.com/josharian/intern v1.0.0 // indirect
|
||||
github.com/mailru/easyjson v0.7.7 // indirect
|
||||
github.com/mitchellh/copystructure v1.2.0 // indirect
|
||||
github.com/mitchellh/mapstructure v1.4.3 // indirect
|
||||
github.com/mitchellh/reflectwalk v1.0.2 // indirect
|
||||
github.com/oklog/ulid v1.3.1 // indirect
|
||||
github.com/rs/zerolog v1.26.1 // indirect
|
||||
go.mongodb.org/mongo-driver v1.10.0 // indirect
|
||||
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d // indirect
|
||||
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10 // indirect
|
||||
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||
)
|
247
build/app/go.sum
Normal file
247
build/app/go.sum
Normal file
@@ -0,0 +1,247 @@
|
||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
github.com/Masterminds/goutils v1.1.1 h1:5nUrii3FMTL5diU80unEVvNevw1nH4+ZV4DSLVJLSYI=
|
||||
github.com/Masterminds/goutils v1.1.1/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU=
|
||||
github.com/Masterminds/semver v1.5.0 h1:H65muMkzWKEuNDnfl9d70GUjFniHKHRbFPGBuZ3QEww=
|
||||
github.com/Masterminds/semver v1.5.0/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y=
|
||||
github.com/Masterminds/sprig v2.22.0+incompatible h1:z4yfnGrZ7netVz+0EDJ0Wi+5VZCSYp4Z0m2dk6cEM60=
|
||||
github.com/Masterminds/sprig v2.22.0+incompatible/go.mod h1:y6hNFY5UBTIWBxnzTeuNhlNS5hqE0NB0E6fgfo2Br3o=
|
||||
github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0=
|
||||
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE=
|
||||
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d h1:licZJFw2RwpHMqeKTCYkitsPqHNxTmd4SNR5r94FGM8=
|
||||
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d/go.mod h1:asat636LX7Bqt5lYEZ27JNDcqxfjdBQuJ/MM4CN/Lzo=
|
||||
github.com/asaskevich/govalidator v0.0.0-20200907205600-7a23bdc65eef/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw=
|
||||
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d h1:Byv0BzEl3/e6D5CLfI0j/7hiIEtvGVFPCZ7Ei2oq8iQ=
|
||||
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw=
|
||||
github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
|
||||
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
||||
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=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/direktiv/apps/go v0.0.0-20220729073403-d70407c25d70 h1:uaQ+hwOuyy7D9JedUCfFk6ZFQHQgt2bbPq6A8n+YSck=
|
||||
github.com/direktiv/apps/go v0.0.0-20220729073403-d70407c25d70/go.mod h1:TKm203MbCOuIB6KTyvhp96Wfl6VV7srBtg6mB/w8e2A=
|
||||
github.com/docker/go-units v0.4.0 h1:3uh0PgVws3nIA0Q+MwDC8yjEPf9zjRfZZWXZYDct3Tw=
|
||||
github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
|
||||
github.com/go-openapi/analysis v0.21.2 h1:hXFrOYFHUAMQdu6zwAiKKJHJQ8kqZs1ux/ru1P1wLJU=
|
||||
github.com/go-openapi/analysis v0.21.2/go.mod h1:HZwRk4RRisyG8vx2Oe6aqeSQcoxRp47Xkp3+K6q+LdY=
|
||||
github.com/go-openapi/errors v0.19.8/go.mod h1:cM//ZKUKyO06HSwqAelJ5NsEMMcpa6VpXe8DOa1Mi1M=
|
||||
github.com/go-openapi/errors v0.19.9/go.mod h1:cM//ZKUKyO06HSwqAelJ5NsEMMcpa6VpXe8DOa1Mi1M=
|
||||
github.com/go-openapi/errors v0.20.2 h1:dxy7PGTqEh94zj2E3h1cUmQQWiM1+aeCROfAr02EmK8=
|
||||
github.com/go-openapi/errors v0.20.2/go.mod h1:cM//ZKUKyO06HSwqAelJ5NsEMMcpa6VpXe8DOa1Mi1M=
|
||||
github.com/go-openapi/jsonpointer v0.19.3/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg=
|
||||
github.com/go-openapi/jsonpointer v0.19.5 h1:gZr+CIYByUqjcgeLXnQu2gHYQC9o73G2XUeOFYEICuY=
|
||||
github.com/go-openapi/jsonpointer v0.19.5/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg=
|
||||
github.com/go-openapi/jsonreference v0.19.6/go.mod h1:diGHMEHg2IqXZGKxqyvWdfWU/aim5Dprw5bqpKkTvns=
|
||||
github.com/go-openapi/jsonreference v0.20.0 h1:MYlu0sBgChmCfJxxUKZ8g1cPWFOB37YSZqewK7OKeyA=
|
||||
github.com/go-openapi/jsonreference v0.20.0/go.mod h1:Ag74Ico3lPc+zR+qjn4XBUmXymS4zJbYVCZmcgkasdo=
|
||||
github.com/go-openapi/loads v0.21.1 h1:Wb3nVZpdEzDTcly8S4HMkey6fjARRzb7iEaySimlDW0=
|
||||
github.com/go-openapi/loads v0.21.1/go.mod h1:/DtAMXXneXFjbQMGEtbamCZb+4x7eGwkvZCvBmwUG+g=
|
||||
github.com/go-openapi/runtime v0.24.1 h1:Sml5cgQKGYQHF+M7yYSHaH1eOjvTykrddTE/KtQVjqo=
|
||||
github.com/go-openapi/runtime v0.24.1/go.mod h1:AKurw9fNre+h3ELZfk6ILsfvPN+bvvlaU/M9q/r9hpk=
|
||||
github.com/go-openapi/spec v0.20.4/go.mod h1:faYFR1CvsJZ0mNsmsphTMSoRrNV3TEDoAM7FOEWeq8I=
|
||||
github.com/go-openapi/spec v0.20.6 h1:ich1RQ3WDbfoeTqTAb+5EIxNmpKVJZWBNah9RAT0jIQ=
|
||||
github.com/go-openapi/spec v0.20.6/go.mod h1:2OpW+JddWPrpXSCIX8eOx7lZ5iyuWj3RYR6VaaBKcWA=
|
||||
github.com/go-openapi/strfmt v0.21.0/go.mod h1:ZRQ409bWMj+SOgXofQAGTIo2Ebu72Gs+WaRADcS5iNg=
|
||||
github.com/go-openapi/strfmt v0.21.1/go.mod h1:I/XVKeLc5+MM5oPNN7P6urMOpuLXEcNrCX/rPGuWb0k=
|
||||
github.com/go-openapi/strfmt v0.21.2/go.mod h1:I/XVKeLc5+MM5oPNN7P6urMOpuLXEcNrCX/rPGuWb0k=
|
||||
github.com/go-openapi/strfmt v0.21.3 h1:xwhj5X6CjXEZZHMWy1zKJxvW9AfHC9pkyUjLvHtKG7o=
|
||||
github.com/go-openapi/strfmt v0.21.3/go.mod h1:k+RzNO0Da+k3FrrynSNN8F7n/peCmQQqbbXjtDfvmGg=
|
||||
github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk=
|
||||
github.com/go-openapi/swag v0.19.15/go.mod h1:QYRuS/SOXUCsnplDa677K7+DxSOj6IPNl/eQntq43wQ=
|
||||
github.com/go-openapi/swag v0.21.1 h1:wm0rhTb5z7qpJRHBdPOMuY4QjVUMbF6/kwoYeRAOrKU=
|
||||
github.com/go-openapi/swag v0.21.1/go.mod h1:QYRuS/SOXUCsnplDa677K7+DxSOj6IPNl/eQntq43wQ=
|
||||
github.com/go-openapi/validate v0.21.0/go.mod h1:rjnrwK57VJ7A8xqfpAOEKRH8yQSGUriMu5/zuPSQ1hg=
|
||||
github.com/go-openapi/validate v0.22.0 h1:b0QecH6VslW/TxtpKgzpO1SNG7GU2FsaqKdP1E2T50Y=
|
||||
github.com/go-openapi/validate v0.22.0/go.mod h1:rjnrwK57VJ7A8xqfpAOEKRH8yQSGUriMu5/zuPSQ1hg=
|
||||
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
|
||||
github.com/go-stack/stack v1.8.1/go.mod h1:dcoOX6HbPZSZptuspn9bctJ+N/CnF5gGygcUP3XYfe4=
|
||||
github.com/gobuffalo/attrs v0.0.0-20190224210810-a9411de4debd/go.mod h1:4duuawTqi2wkkpB4ePgWMaai6/Kc6WEz83bhFwpHzj0=
|
||||
github.com/gobuffalo/depgen v0.0.0-20190329151759-d478694a28d3/go.mod h1:3STtPUQYuzV0gBVOY3vy6CfMm/ljR4pABfrTeHNLHUY=
|
||||
github.com/gobuffalo/depgen v0.1.0/go.mod h1:+ifsuy7fhi15RWncXQQKjWS9JPkdah5sZvtHc2RXGlg=
|
||||
github.com/gobuffalo/envy v1.6.15/go.mod h1:n7DRkBerg/aorDM8kbduw5dN3oXGswK5liaSCx4T5NI=
|
||||
github.com/gobuffalo/envy v1.7.0/go.mod h1:n7DRkBerg/aorDM8kbduw5dN3oXGswK5liaSCx4T5NI=
|
||||
github.com/gobuffalo/flect v0.1.0/go.mod h1:d2ehjJqGOH/Kjqcoz+F7jHTBbmDb38yXA598Hb50EGs=
|
||||
github.com/gobuffalo/flect v0.1.1/go.mod h1:8JCgGVbRjJhVgD6399mQr4fx5rRfGKVzFjbj6RE/9UI=
|
||||
github.com/gobuffalo/flect v0.1.3/go.mod h1:8JCgGVbRjJhVgD6399mQr4fx5rRfGKVzFjbj6RE/9UI=
|
||||
github.com/gobuffalo/genny v0.0.0-20190329151137-27723ad26ef9/go.mod h1:rWs4Z12d1Zbf19rlsn0nurr75KqhYp52EAGGxTbBhNk=
|
||||
github.com/gobuffalo/genny v0.0.0-20190403191548-3ca520ef0d9e/go.mod h1:80lIj3kVJWwOrXWWMRzzdhW3DsrdjILVil/SFKBzF28=
|
||||
github.com/gobuffalo/genny v0.1.0/go.mod h1:XidbUqzak3lHdS//TPu2OgiFB+51Ur5f7CSnXZ/JDvo=
|
||||
github.com/gobuffalo/genny v0.1.1/go.mod h1:5TExbEyY48pfunL4QSXxlDOmdsD44RRq4mVZ0Ex28Xk=
|
||||
github.com/gobuffalo/gitgen v0.0.0-20190315122116-cc086187d211/go.mod h1:vEHJk/E9DmhejeLeNt7UVvlSGv3ziL+djtTr3yyzcOw=
|
||||
github.com/gobuffalo/gogen v0.0.0-20190315121717-8f38393713f5/go.mod h1:V9QVDIxsgKNZs6L2IYiGR8datgMhB577vzTDqypH360=
|
||||
github.com/gobuffalo/gogen v0.1.0/go.mod h1:8NTelM5qd8RZ15VjQTFkAW6qOMx5wBbW4dSCS3BY8gg=
|
||||
github.com/gobuffalo/gogen v0.1.1/go.mod h1:y8iBtmHmGc4qa3urIyo1shvOD8JftTtfcKi+71xfDNE=
|
||||
github.com/gobuffalo/logger v0.0.0-20190315122211-86e12af44bc2/go.mod h1:QdxcLw541hSGtBnhUc4gaNIXRjiDppFGaDqzbrBd3v8=
|
||||
github.com/gobuffalo/mapi v1.0.1/go.mod h1:4VAGh89y6rVOvm5A8fKFxYG+wIW6LO1FMTG9hnKStFc=
|
||||
github.com/gobuffalo/mapi v1.0.2/go.mod h1:4VAGh89y6rVOvm5A8fKFxYG+wIW6LO1FMTG9hnKStFc=
|
||||
github.com/gobuffalo/packd v0.0.0-20190315124812-a385830c7fc0/go.mod h1:M2Juc+hhDXf/PnmBANFCqx4DM3wRbgDvnVWeG2RIxq4=
|
||||
github.com/gobuffalo/packd v0.1.0/go.mod h1:M2Juc+hhDXf/PnmBANFCqx4DM3wRbgDvnVWeG2RIxq4=
|
||||
github.com/gobuffalo/packr/v2 v2.0.9/go.mod h1:emmyGweYTm6Kdper+iywB6YK5YzuKchGtJQZ0Odn4pQ=
|
||||
github.com/gobuffalo/packr/v2 v2.2.0/go.mod h1:CaAwI0GPIAv+5wKLtv8Afwl+Cm78K/I/VCm/3ptBN+0=
|
||||
github.com/gobuffalo/syncx v0.0.0-20190224160051-33c29581e754/go.mod h1:HhnNqWY95UYwwW3uSASeV7vtgYkT2t16hJgV3AEPUpw=
|
||||
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
|
||||
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||
github.com/google/go-cmp v0.5.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM=
|
||||
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY=
|
||||
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/huandu/xstrings v1.3.2 h1:L18LIDzqlW6xN2rEkpdV8+oL/IXWJ1APd+vsdYy4Wdw=
|
||||
github.com/huandu/xstrings v1.3.2/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
|
||||
github.com/imdario/mergo v0.3.13 h1:lFzP57bqS/wsqKssCGmtLAb8A0wKjLGrve2q3PPVcBk=
|
||||
github.com/imdario/mergo v0.3.13/go.mod h1:4lJ1jqUDcsbIECGy0RUJAXNIhg+6ocWgb1ALK2O4oXg=
|
||||
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
|
||||
github.com/jessevdk/go-flags v1.5.0 h1:1jKYvbxEjfUl0fmqTCOfonvskHHXMjBySTLW4y9LFvc=
|
||||
github.com/jessevdk/go-flags v1.5.0/go.mod h1:Fw0T6WPc1dYxT4mKEZRfG5kJhaTDP9pj1c2EWnYs/m4=
|
||||
github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
|
||||
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
|
||||
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
|
||||
github.com/karrick/godirwalk v1.8.0/go.mod h1:H5KPZjojv4lE+QYImBI8xVtrBRgYrIVsaRPx4tDPEn4=
|
||||
github.com/karrick/godirwalk v1.10.3/go.mod h1:RoGL9dQei4vP9ilrpETWE8CLOZ1kiN0LhBygSwrAsHA=
|
||||
github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk=
|
||||
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
||||
github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||
github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
|
||||
github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
|
||||
github.com/mailru/easyjson v0.7.6/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
|
||||
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
|
||||
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
|
||||
github.com/markbates/oncer v0.0.0-20181203154359-bf2de49a0be2/go.mod h1:Ld9puTsIW75CHf65OeIOkyKbteujpZVXDpWK6YGZbxE=
|
||||
github.com/markbates/safe v1.0.1/go.mod h1:nAqgmRi7cY2nqMc92/bSEeQA+R4OheNU2T1kNSCBdG0=
|
||||
github.com/mattn/go-shellwords v1.0.12 h1:M2zGm7EW6UQJvDeQxo4T51eKPurbeFbe8WtebGE2xrk=
|
||||
github.com/mattn/go-shellwords v1.0.12/go.mod h1:EZzvwXDESEeg03EKmM+RmDnNOPKG4lLtQsUlTZDWQ8Y=
|
||||
github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa15WveJJGw=
|
||||
github.com/mitchellh/copystructure v1.2.0/go.mod h1:qLl+cE2AmVv+CoeAwDPye/v+N2HKCj9FbZEVFJRxO9s=
|
||||
github.com/mitchellh/mapstructure v1.3.3/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
|
||||
github.com/mitchellh/mapstructure v1.4.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
|
||||
github.com/mitchellh/mapstructure v1.4.3 h1:OVowDSCllw/YjdLkam3/sm7wEtOy59d8ndGgCcyj8cs=
|
||||
github.com/mitchellh/mapstructure v1.4.3/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
|
||||
github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zxSIeXaQ=
|
||||
github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
|
||||
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc=
|
||||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
|
||||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
|
||||
github.com/oklog/ulid v1.3.1 h1:EGfNDEx6MqHz8B3uNV6QAib1UR2Lm97sHi3ocA6ESJ4=
|
||||
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
|
||||
github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc=
|
||||
github.com/pelletier/go-toml v1.7.0/go.mod h1:vwGMzjaWMwyfHwgIBhI2YUM4fB6nL6lVAvS1LBMMhTE=
|
||||
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/rogpeppe/go-internal v1.1.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
|
||||
github.com/rogpeppe/go-internal v1.2.2/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
|
||||
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
|
||||
github.com/rs/xid v1.3.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
|
||||
github.com/rs/zerolog v1.26.1 h1:/ihwxqH+4z8UxyI70wM1z9yCvkWcfz/a3mj48k/Zngc=
|
||||
github.com/rs/zerolog v1.26.1/go.mod h1:/wSSJWX7lVrsOwlbyTRSOJvqRlc+WjWlfes+CiJ+tmc=
|
||||
github.com/sirupsen/logrus v1.4.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
|
||||
github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q=
|
||||
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
|
||||
github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
|
||||
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
|
||||
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||
github.com/tidwall/pretty v1.0.0 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4=
|
||||
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
|
||||
github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI=
|
||||
github.com/xdg-go/scram v1.0.2/go.mod h1:1WAq6h33pAW+iRreB34OORO2Nf7qel3VV3fjBj+hCSs=
|
||||
github.com/xdg-go/scram v1.1.1/go.mod h1:RaEWvsqvNKKvBPvcKeFjrG2cJqOkHTiyTpzz23ni57g=
|
||||
github.com/xdg-go/stringprep v1.0.2/go.mod h1:8F9zXuvzgwmyT5DUm4GUfZGDdT3W+LCvS6+da4O5kxM=
|
||||
github.com/xdg-go/stringprep v1.0.3/go.mod h1:W3f5j4i+9rC0kuIEJL0ky1VpHXQU3ocBgklLGvcBnW8=
|
||||
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7JulP+udvsHwJoVG1YGAP6VLg4y9I5dyZdqmA=
|
||||
github.com/yuin/goldmark v1.4.0/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
|
||||
go.mongodb.org/mongo-driver v1.7.3/go.mod h1:NqaYOwnXWr5Pm7AOpO5QFxKJ503nbMse/R79oO62zWg=
|
||||
go.mongodb.org/mongo-driver v1.7.5/go.mod h1:VXEWRZ6URJIkUq2SCAyapmhH0ZLRBP+FT4xhp5Zvxng=
|
||||
go.mongodb.org/mongo-driver v1.8.3/go.mod h1:0sQWfOeY63QTntERDJJ/0SuKK0T1uVSgKCuAROlKEPY=
|
||||
go.mongodb.org/mongo-driver v1.10.0 h1:UtV6N5k14upNp4LTduX0QCufG124fSu25Wz9tu94GLg=
|
||||
go.mongodb.org/mongo-driver v1.10.0/go.mod h1:wsihk0Kdgv8Kqu1Anit4sfK+22vSFbUrAVEYRhCXrA8=
|
||||
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20190422162423-af44ce270edf/go.mod h1:WFFai1msRO1wXaEeE5yQxYXgSfI8pQAWXbQop6sCtWE=
|
||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20201216223049-8b5274cf687f/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
|
||||
golang.org/x/crypto v0.0.0-20211215165025-cf75a172585e/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8=
|
||||
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d h1:sK3txAijHtOK88l68nt020reeT1ZdKLIYetKl95FzVY=
|
||||
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/net v0.0.0-20210421230115-4e50805a0758/go.mod h1:72T/g9IO56b78aLF+1Kcs5dz7/ng1VjMUvfKvpfy+jM=
|
||||
golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
|
||||
golang.org/x/net v0.0.0-20220728211354-c7608f3a8462 h1:UreQrH7DbFXSi9ZFox6FNT3WBooWmdANpU+IfkT1T4I=
|
||||
golang.org/x/net v0.0.0-20220728211354-c7608f3a8462/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=
|
||||
golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20190412183630-56d357773e84/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190403152447-81d4e9dc473e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190419153524-e8e3143a4f4a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190531175056-4c3a928424d2/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210420072515-93ed5bcd2bfe/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10 h1:WIoqL4EROvwiPdUtaip4VcDdpZ4kha7wBWZrbVKCIZg=
|
||||
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20190329151228-23e29df326fe/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||
golang.org/x/tools v0.0.0-20190416151739-9c9e1878f421/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||
golang.org/x/tools v0.0.0-20190420181800-aa740d480789/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||
golang.org/x/tools v0.0.0-20190531172133-b3315ee88b7d/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
|
||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.1.7/go.mod h1:LGqMHiF4EqQNHR1JncWGqT5BVaXmza+X+BDGol+dOxo=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=
|
||||
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
|
||||
gopkg.in/yaml.v2 v2.2.2/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.0-20200605160147-a5ece683394c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.0/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=
|
88
build/app/models/error.go
Normal file
88
build/app/models/error.go
Normal file
@@ -0,0 +1,88 @@
|
||||
// Code generated by go-swagger; DO NOT EDIT.
|
||||
|
||||
package models
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/go-openapi/errors"
|
||||
"github.com/go-openapi/strfmt"
|
||||
"github.com/go-openapi/swag"
|
||||
"github.com/go-openapi/validate"
|
||||
)
|
||||
|
||||
// Error error
|
||||
//
|
||||
// swagger:model error
|
||||
type Error struct {
|
||||
|
||||
// error code
|
||||
// Required: true
|
||||
ErrorCode *string `json:"errorCode"`
|
||||
|
||||
// error message
|
||||
// Required: true
|
||||
ErrorMessage *string `json:"errorMessage"`
|
||||
}
|
||||
|
||||
// Validate validates this error
|
||||
func (m *Error) Validate(formats strfmt.Registry) error {
|
||||
var res []error
|
||||
|
||||
if err := m.validateErrorCode(formats); err != nil {
|
||||
res = append(res, err)
|
||||
}
|
||||
|
||||
if err := m.validateErrorMessage(formats); err != nil {
|
||||
res = append(res, err)
|
||||
}
|
||||
|
||||
if len(res) > 0 {
|
||||
return errors.CompositeValidationError(res...)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Error) validateErrorCode(formats strfmt.Registry) error {
|
||||
|
||||
if err := validate.Required("errorCode", "body", m.ErrorCode); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Error) validateErrorMessage(formats strfmt.Registry) error {
|
||||
|
||||
if err := validate.Required("errorMessage", "body", m.ErrorMessage); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// ContextValidate validates this error based on context it is used
|
||||
func (m *Error) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// MarshalBinary interface implementation
|
||||
func (m *Error) MarshalBinary() ([]byte, error) {
|
||||
if m == nil {
|
||||
return nil, nil
|
||||
}
|
||||
return swag.WriteJSON(m)
|
||||
}
|
||||
|
||||
// UnmarshalBinary interface implementation
|
||||
func (m *Error) UnmarshalBinary(b []byte) error {
|
||||
var res Error
|
||||
if err := swag.ReadJSON(b, &res); err != nil {
|
||||
return err
|
||||
}
|
||||
*m = res
|
||||
return nil
|
||||
}
|
50
build/app/models/post_o_k_body.go
Normal file
50
build/app/models/post_o_k_body.go
Normal file
@@ -0,0 +1,50 @@
|
||||
// Code generated by go-swagger; DO NOT EDIT.
|
||||
|
||||
package models
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/go-openapi/strfmt"
|
||||
"github.com/go-openapi/swag"
|
||||
)
|
||||
|
||||
// PostOKBody post o k body
|
||||
//
|
||||
// swagger:model postOKBody
|
||||
type PostOKBody struct {
|
||||
|
||||
// export excel
|
||||
ExportExcel string `json:"export-excel,omitempty"`
|
||||
}
|
||||
|
||||
// Validate validates this post o k body
|
||||
func (m *PostOKBody) Validate(formats strfmt.Registry) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// ContextValidate validates this post o k body based on context it is used
|
||||
func (m *PostOKBody) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// MarshalBinary interface implementation
|
||||
func (m *PostOKBody) MarshalBinary() ([]byte, error) {
|
||||
if m == nil {
|
||||
return nil, nil
|
||||
}
|
||||
return swag.WriteJSON(m)
|
||||
}
|
||||
|
||||
// UnmarshalBinary interface implementation
|
||||
func (m *PostOKBody) UnmarshalBinary(b []byte) error {
|
||||
var res PostOKBody
|
||||
if err := swag.ReadJSON(b, &res); err != nil {
|
||||
return err
|
||||
}
|
||||
*m = res
|
||||
return nil
|
||||
}
|
53
build/app/models/post_params_body.go
Normal file
53
build/app/models/post_params_body.go
Normal file
@@ -0,0 +1,53 @@
|
||||
// Code generated by go-swagger; DO NOT EDIT.
|
||||
|
||||
package models
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/go-openapi/strfmt"
|
||||
"github.com/go-openapi/swag"
|
||||
)
|
||||
|
||||
// PostParamsBody post params body
|
||||
//
|
||||
// swagger:model postParamsBody
|
||||
type PostParamsBody struct {
|
||||
|
||||
// the filename of the output spreadsheet
|
||||
OutFilename *string `json:"out-filename,omitempty"`
|
||||
|
||||
// Label for the worksheet created in the spreadsheet
|
||||
WorksheetName *string `json:"worksheet-name,omitempty"`
|
||||
}
|
||||
|
||||
// Validate validates this post params body
|
||||
func (m *PostParamsBody) Validate(formats strfmt.Registry) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// ContextValidate validates this post params body based on context it is used
|
||||
func (m *PostParamsBody) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// MarshalBinary interface implementation
|
||||
func (m *PostParamsBody) MarshalBinary() ([]byte, error) {
|
||||
if m == nil {
|
||||
return nil, nil
|
||||
}
|
||||
return swag.WriteJSON(m)
|
||||
}
|
||||
|
||||
// UnmarshalBinary interface implementation
|
||||
func (m *PostParamsBody) UnmarshalBinary(b []byte) error {
|
||||
var res PostParamsBody
|
||||
if err := swag.ReadJSON(b, &res); err != nil {
|
||||
return err
|
||||
}
|
||||
*m = res
|
||||
return nil
|
||||
}
|
170
build/app/restapi/configure_export_xlsx.go
Normal file
170
build/app/restapi/configure_export_xlsx.go
Normal file
@@ -0,0 +1,170 @@
|
||||
// This file is safe to edit. Once it exists it will not be overwritten
|
||||
|
||||
package restapi
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
"github.com/go-openapi/errors"
|
||||
"github.com/go-openapi/runtime"
|
||||
"github.com/go-openapi/runtime/middleware"
|
||||
|
||||
"app/restapi/operations"
|
||||
)
|
||||
|
||||
//go:generate swagger generate server --target ../../app --name ExportXlsx --spec ../../../swagger.yaml --template-dir /home/nathan/direktiv/export-xlsx/build/templates --principal interface{}
|
||||
|
||||
func configureFlags(api *operations.ExportXlsxAPI) {
|
||||
// api.CommandLineOptionsGroups = []swag.CommandLineOptionsGroup{ ... }
|
||||
}
|
||||
|
||||
func errorAsJSON(err errors.Error) []byte {
|
||||
b, _ := json.Marshal(struct {
|
||||
Code int32 `json:"errorCode"`
|
||||
Message string `json:"errorMessage"`
|
||||
}{err.Code(), err.Error()})
|
||||
return b
|
||||
}
|
||||
|
||||
func asHTTPCode(input int) int {
|
||||
if input >= 600 {
|
||||
return errors.DefaultHTTPCode
|
||||
}
|
||||
return input
|
||||
}
|
||||
|
||||
func flattenComposite(errs *errors.CompositeError) *errors.CompositeError {
|
||||
var res []error
|
||||
for _, er := range errs.Errors {
|
||||
switch e := er.(type) {
|
||||
case *errors.CompositeError:
|
||||
if len(e.Errors) > 0 {
|
||||
flat := flattenComposite(e)
|
||||
if len(flat.Errors) > 0 {
|
||||
res = append(res, flat.Errors...)
|
||||
}
|
||||
}
|
||||
default:
|
||||
if e != nil {
|
||||
res = append(res, e)
|
||||
}
|
||||
}
|
||||
}
|
||||
return errors.CompositeValidationError(res...)
|
||||
}
|
||||
|
||||
func addErrorHeaders(rw http.ResponseWriter, code, message string) {
|
||||
|
||||
rw.Header().Add("Direktiv-ErrorCode", code)
|
||||
rw.Header().Add("Direktiv-ErrorMessage", message)
|
||||
|
||||
}
|
||||
|
||||
// modified version of the openapi error function
|
||||
// https://github.com/go-openapi/errors/blob/8b5b7790aa74a2148bf29be0d24e1f455fdbc706/api.go
|
||||
func serveError(rw http.ResponseWriter, r *http.Request, err error) {
|
||||
|
||||
rw.Header().Set("Content-Type", "application/json")
|
||||
switch e := err.(type) {
|
||||
case *errors.CompositeError:
|
||||
er := flattenComposite(e)
|
||||
// strips composite errors to first element only
|
||||
if len(er.Errors) > 0 {
|
||||
serveError(rw, r, er.Errors[0])
|
||||
} else {
|
||||
// guard against empty CompositeError (invalid construct)
|
||||
serveError(rw, r, nil)
|
||||
}
|
||||
case *errors.MethodNotAllowedError:
|
||||
rw.Header().Add("Allow", strings.Join(err.(*errors.MethodNotAllowedError).Allowed, ","))
|
||||
rw.WriteHeader(asHTTPCode(int(e.Code())))
|
||||
addErrorHeaders(rw, "io.direktiv.method", err.Error())
|
||||
if r == nil || r.Method != http.MethodHead {
|
||||
_, _ = rw.Write(errorAsJSON(e))
|
||||
}
|
||||
case errors.Error:
|
||||
value := reflect.ValueOf(e)
|
||||
if value.Kind() == reflect.Ptr && value.IsNil() {
|
||||
rw.WriteHeader(http.StatusInternalServerError)
|
||||
_, _ = rw.Write(errorAsJSON(errors.New(http.StatusInternalServerError, "Unknown error")))
|
||||
return
|
||||
}
|
||||
addErrorHeaders(rw, "io.direktiv.unfit", fmt.Sprintf("%s (%v)", e.Error(), e.Code()))
|
||||
rw.WriteHeader(asHTTPCode(int(e.Code())))
|
||||
if r == nil || r.Method != http.MethodHead {
|
||||
_, _ = rw.Write(errorAsJSON(e))
|
||||
}
|
||||
case nil:
|
||||
addErrorHeaders(rw, "io.direktiv.unknown", "Unknown error")
|
||||
rw.WriteHeader(http.StatusInternalServerError)
|
||||
_, _ = rw.Write(errorAsJSON(errors.New(http.StatusInternalServerError, "Unknown error")))
|
||||
default:
|
||||
addErrorHeaders(rw, "io.direktiv.error", err.Error())
|
||||
rw.WriteHeader(http.StatusInternalServerError)
|
||||
if r == nil || r.Method != http.MethodHead {
|
||||
_, _ = rw.Write(errorAsJSON(errors.New(http.StatusInternalServerError, err.Error())))
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func configureAPI(api *operations.ExportXlsxAPI) http.Handler {
|
||||
// configure the api here
|
||||
api.ServeError = serveError
|
||||
|
||||
// Set your custom logger if needed. Default one is log.Printf
|
||||
// Expected interface func(string, ...interface{})
|
||||
//
|
||||
// Example:
|
||||
// api.Logger = log.Printf
|
||||
|
||||
api.UseSwaggerUI()
|
||||
// To continue using redoc as your UI, uncomment the following line
|
||||
// api.UseRedoc()
|
||||
|
||||
api.JSONConsumer = runtime.JSONConsumer()
|
||||
|
||||
api.JSONProducer = runtime.JSONProducer()
|
||||
|
||||
api.DeleteHandler = operations.DeleteHandlerFunc(func(params operations.DeleteParams) middleware.Responder {
|
||||
return operations.DeleteDirektivHandle(params)
|
||||
})
|
||||
api.PostHandler = operations.PostHandlerFunc(func(params operations.PostParams) middleware.Responder {
|
||||
return operations.PostDirektivHandle(params)
|
||||
})
|
||||
|
||||
api.PreServerShutdown = func() {}
|
||||
|
||||
api.ServerShutdown = func() {}
|
||||
|
||||
return setupGlobalMiddleware(api.Serve(setupMiddlewares))
|
||||
}
|
||||
|
||||
// The TLS configuration before HTTPS server starts.
|
||||
func configureTLS(tlsConfig *tls.Config) {
|
||||
// Make all necessary changes to the TLS configuration here.
|
||||
}
|
||||
|
||||
// As soon as server is initialized but not run yet, this function will be called.
|
||||
// If you need to modify a config, store server instance to stop it individually later, this is the place.
|
||||
// This function can be called multiple times, depending on the number of serving schemes.
|
||||
// scheme value will be set accordingly: "http", "https" or "unix".
|
||||
func configureServer(s *http.Server, scheme, addr string) {
|
||||
}
|
||||
|
||||
// The middleware configuration is for the handler executors. These do not apply to the swagger.json document.
|
||||
// The middleware executes after routing but before authentication, binding and validation.
|
||||
func setupMiddlewares(handler http.Handler) http.Handler {
|
||||
return handler
|
||||
}
|
||||
|
||||
// The middleware configuration happens before anything, this middleware also applies to serving the swagger.json document.
|
||||
// So this is a good place to plug in a panic handling middleware, logging and metrics.
|
||||
func setupGlobalMiddleware(handler http.Handler) http.Handler {
|
||||
return handler
|
||||
}
|
19
build/app/restapi/doc.go
Normal file
19
build/app/restapi/doc.go
Normal file
@@ -0,0 +1,19 @@
|
||||
// Code generated by go-swagger; DO NOT EDIT.
|
||||
|
||||
// Package restapi export-xlsx
|
||||
//
|
||||
// Transform json input to xlsx spreadsheet
|
||||
// Schemes:
|
||||
// http
|
||||
// Host: localhost
|
||||
// BasePath: /
|
||||
// Version: 1.0
|
||||
//
|
||||
// Consumes:
|
||||
// - application/json
|
||||
//
|
||||
// Produces:
|
||||
// - application/json
|
||||
//
|
||||
// swagger:meta
|
||||
package restapi
|
382
build/app/restapi/embedded_spec.go
Normal file
382
build/app/restapi/embedded_spec.go
Normal file
@@ -0,0 +1,382 @@
|
||||
// Code generated by go-swagger; DO NOT EDIT.
|
||||
|
||||
package restapi
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
)
|
||||
|
||||
var (
|
||||
// SwaggerJSON embedded version of the swagger document used at generation time
|
||||
SwaggerJSON json.RawMessage
|
||||
// FlatSwaggerJSON embedded flattened version of the swagger document used at generation time
|
||||
FlatSwaggerJSON json.RawMessage
|
||||
)
|
||||
|
||||
func init() {
|
||||
SwaggerJSON = json.RawMessage([]byte(`{
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"schemes": [
|
||||
"http"
|
||||
],
|
||||
"swagger": "2.0",
|
||||
"info": {
|
||||
"description": "Transform json input to xlsx spreadsheet",
|
||||
"title": "export-xlsx",
|
||||
"version": "1.0",
|
||||
"x-direktiv-meta": {
|
||||
"categories": [
|
||||
"unknown"
|
||||
],
|
||||
"container": "registry.coadcorp.com/export-xlsx:1.0",
|
||||
"issues": "https://git.coadcorp.com/nathan/export-xlsx/issues",
|
||||
"license": "[Apache-2.0](https://www.apache.org/licenses/LICENSE-2.0)",
|
||||
"long-description": "Transform json input to excel spreadsheet via json2excel command",
|
||||
"maintainer": "[nathan.coad@dell.com](nathan.coad@dell.com)",
|
||||
"url": "https://git.coadcorp.com/nathan/export-xls"
|
||||
}
|
||||
},
|
||||
"paths": {
|
||||
"/": {
|
||||
"post": {
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"default": "development",
|
||||
"description": "direktiv action id is an UUID. \nFor development it can be set to 'development'\n",
|
||||
"name": "Direktiv-ActionID",
|
||||
"in": "header"
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"default": "/tmp",
|
||||
"description": "direktiv temp dir is the working directory for that request\nFor development it can be set to e.g. '/tmp'\n",
|
||||
"name": "Direktiv-TempDir",
|
||||
"in": "header"
|
||||
},
|
||||
{
|
||||
"name": "body",
|
||||
"in": "body",
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"out-filename": {
|
||||
"description": "the filename of the output spreadsheet",
|
||||
"type": "string",
|
||||
"default": "output.xlsx"
|
||||
},
|
||||
"worksheet-name": {
|
||||
"description": "Label for the worksheet created in the spreadsheet",
|
||||
"type": "string",
|
||||
"default": "Sheet1"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "List of executed commands.",
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"export-excel": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
},
|
||||
"examples": {
|
||||
"export-excel": "JVBERi0xLjUKJdDUxdgKNSAwIG9iago8PAov=="
|
||||
}
|
||||
},
|
||||
"default": {
|
||||
"description": "generic error response",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/error"
|
||||
},
|
||||
"headers": {
|
||||
"Direktiv-ErrorCode": {
|
||||
"type": "string"
|
||||
},
|
||||
"Direktiv-ErrorMessage": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"x-direktiv": {
|
||||
"cmds": [
|
||||
{
|
||||
"action": "exec",
|
||||
"exec": "/bin/json2excel -inFile input.json -worksheetName \"{{ .WorksheetName }}\" -outputFilename '{{ .OutFilename }}'",
|
||||
"print": true,
|
||||
"silent": false
|
||||
},
|
||||
{
|
||||
"action": "exec",
|
||||
"exec": "base64 -w 0 /tmp/{{ .OutFilename }}"
|
||||
}
|
||||
],
|
||||
"output": "{\n \"export-excel\": {{ (index . 1).result | toJson }}\n}\n"
|
||||
},
|
||||
"x-direktiv-errors": {
|
||||
"io.direktiv.command.error": "Command execution failed",
|
||||
"io.direktiv.output.error": "Template error for output generation of the service",
|
||||
"io.direktiv.ri.error": "Can not create information object from request"
|
||||
},
|
||||
"x-direktiv-examples": [
|
||||
{
|
||||
"content": "- id: export-xlsx\n type: action\n action:\n function: export-xlsx\n input: \n files:\n - name: input.json\n data: |\n jq(.input) \n worksheet-name: \"TestSpreadsheet\"\n out-filename: example.xlsx",
|
||||
"title": "Basic"
|
||||
}
|
||||
],
|
||||
"x-direktiv-function": "functions:\n- id: export-xlsx\n image: registry.coadcorp.com/export-xlsx:1.0\n type: knative-workflow",
|
||||
"x-direktiv-secrets": [
|
||||
{
|
||||
"description": "This is a secret value",
|
||||
"name": "export-xlsxSecret"
|
||||
}
|
||||
]
|
||||
},
|
||||
"delete": {
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "On cancel Direktiv sends a DELETE request to\nthe action with id in the header\n",
|
||||
"name": "Direktiv-ActionID",
|
||||
"in": "header"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": ""
|
||||
}
|
||||
},
|
||||
"x-direktiv": {
|
||||
"cancel": "echo 'cancel {{ .DirektivActionID }}'"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"definitions": {
|
||||
"direktivFile": {
|
||||
"type": "object",
|
||||
"x-go-type": {
|
||||
"import": {
|
||||
"package": "github.com/direktiv/apps/go/pkg/apps"
|
||||
},
|
||||
"type": "DirektivFile"
|
||||
}
|
||||
},
|
||||
"error": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"errorCode",
|
||||
"errorMessage"
|
||||
],
|
||||
"properties": {
|
||||
"errorCode": {
|
||||
"type": "string"
|
||||
},
|
||||
"errorMessage": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}`))
|
||||
FlatSwaggerJSON = json.RawMessage([]byte(`{
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"schemes": [
|
||||
"http"
|
||||
],
|
||||
"swagger": "2.0",
|
||||
"info": {
|
||||
"description": "Transform json input to xlsx spreadsheet",
|
||||
"title": "export-xlsx",
|
||||
"version": "1.0",
|
||||
"x-direktiv-meta": {
|
||||
"categories": [
|
||||
"unknown"
|
||||
],
|
||||
"container": "registry.coadcorp.com/export-xlsx:1.0",
|
||||
"issues": "https://git.coadcorp.com/nathan/export-xlsx/issues",
|
||||
"license": "[Apache-2.0](https://www.apache.org/licenses/LICENSE-2.0)",
|
||||
"long-description": "Transform json input to excel spreadsheet via json2excel command",
|
||||
"maintainer": "[nathan.coad@dell.com](nathan.coad@dell.com)",
|
||||
"url": "https://git.coadcorp.com/nathan/export-xls"
|
||||
}
|
||||
},
|
||||
"paths": {
|
||||
"/": {
|
||||
"post": {
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"default": "development",
|
||||
"description": "direktiv action id is an UUID. \nFor development it can be set to 'development'\n",
|
||||
"name": "Direktiv-ActionID",
|
||||
"in": "header"
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"default": "/tmp",
|
||||
"description": "direktiv temp dir is the working directory for that request\nFor development it can be set to e.g. '/tmp'\n",
|
||||
"name": "Direktiv-TempDir",
|
||||
"in": "header"
|
||||
},
|
||||
{
|
||||
"name": "body",
|
||||
"in": "body",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/postParamsBody"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "List of executed commands.",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/postOKBody"
|
||||
},
|
||||
"examples": {
|
||||
"export-excel": "JVBERi0xLjUKJdDUxdgKNSAwIG9iago8PAov=="
|
||||
}
|
||||
},
|
||||
"default": {
|
||||
"description": "generic error response",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/error"
|
||||
},
|
||||
"headers": {
|
||||
"Direktiv-ErrorCode": {
|
||||
"type": "string"
|
||||
},
|
||||
"Direktiv-ErrorMessage": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"x-direktiv": {
|
||||
"cmds": [
|
||||
{
|
||||
"action": "exec",
|
||||
"exec": "/bin/json2excel -inFile input.json -worksheetName \"{{ .WorksheetName }}\" -outputFilename '{{ .OutFilename }}'",
|
||||
"print": true,
|
||||
"silent": false
|
||||
},
|
||||
{
|
||||
"action": "exec",
|
||||
"exec": "base64 -w 0 /tmp/{{ .OutFilename }}"
|
||||
}
|
||||
],
|
||||
"output": "{\n \"export-excel\": {{ (index . 1).result | toJson }}\n}\n"
|
||||
},
|
||||
"x-direktiv-errors": {
|
||||
"io.direktiv.command.error": "Command execution failed",
|
||||
"io.direktiv.output.error": "Template error for output generation of the service",
|
||||
"io.direktiv.ri.error": "Can not create information object from request"
|
||||
},
|
||||
"x-direktiv-examples": [
|
||||
{
|
||||
"content": "- id: export-xlsx\n type: action\n action:\n function: export-xlsx\n input: \n files:\n - name: input.json\n data: |\n jq(.input) \n worksheet-name: \"TestSpreadsheet\"\n out-filename: example.xlsx",
|
||||
"title": "Basic"
|
||||
}
|
||||
],
|
||||
"x-direktiv-function": "functions:\n- id: export-xlsx\n image: registry.coadcorp.com/export-xlsx:1.0\n type: knative-workflow",
|
||||
"x-direktiv-secrets": [
|
||||
{
|
||||
"description": "This is a secret value",
|
||||
"name": "export-xlsxSecret"
|
||||
}
|
||||
]
|
||||
},
|
||||
"delete": {
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "On cancel Direktiv sends a DELETE request to\nthe action with id in the header\n",
|
||||
"name": "Direktiv-ActionID",
|
||||
"in": "header"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": ""
|
||||
}
|
||||
},
|
||||
"x-direktiv": {
|
||||
"cancel": "echo 'cancel {{ .DirektivActionID }}'"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"definitions": {
|
||||
"direktivFile": {
|
||||
"type": "object",
|
||||
"x-go-type": {
|
||||
"import": {
|
||||
"package": "github.com/direktiv/apps/go/pkg/apps"
|
||||
},
|
||||
"type": "DirektivFile"
|
||||
}
|
||||
},
|
||||
"error": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"errorCode",
|
||||
"errorMessage"
|
||||
],
|
||||
"properties": {
|
||||
"errorCode": {
|
||||
"type": "string"
|
||||
},
|
||||
"errorMessage": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"postOKBody": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"export-excel": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false,
|
||||
"x-go-gen-location": "operations"
|
||||
},
|
||||
"postParamsBody": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"out-filename": {
|
||||
"description": "the filename of the output spreadsheet",
|
||||
"type": "string",
|
||||
"default": "output.xlsx"
|
||||
},
|
||||
"worksheet-name": {
|
||||
"description": "Label for the worksheet created in the spreadsheet",
|
||||
"type": "string",
|
||||
"default": "Sheet1"
|
||||
}
|
||||
},
|
||||
"x-go-gen-location": "operations"
|
||||
}
|
||||
}
|
||||
}`))
|
||||
}
|
56
build/app/restapi/operations/delete.go
Normal file
56
build/app/restapi/operations/delete.go
Normal file
@@ -0,0 +1,56 @@
|
||||
// Code generated by go-swagger; DO NOT EDIT.
|
||||
|
||||
package operations
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the generate command
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/go-openapi/runtime/middleware"
|
||||
)
|
||||
|
||||
// DeleteHandlerFunc turns a function with the right signature into a delete handler
|
||||
type DeleteHandlerFunc func(DeleteParams) middleware.Responder
|
||||
|
||||
// Handle executing the request and returning a response
|
||||
func (fn DeleteHandlerFunc) Handle(params DeleteParams) middleware.Responder {
|
||||
return fn(params)
|
||||
}
|
||||
|
||||
// DeleteHandler interface for that can handle valid delete params
|
||||
type DeleteHandler interface {
|
||||
Handle(DeleteParams) middleware.Responder
|
||||
}
|
||||
|
||||
// NewDelete creates a new http.Handler for the delete operation
|
||||
func NewDelete(ctx *middleware.Context, handler DeleteHandler) *Delete {
|
||||
return &Delete{Context: ctx, Handler: handler}
|
||||
}
|
||||
|
||||
/* Delete swagger:route DELETE / delete
|
||||
|
||||
Delete delete API
|
||||
|
||||
*/
|
||||
type Delete struct {
|
||||
Context *middleware.Context
|
||||
Handler DeleteHandler
|
||||
}
|
||||
|
||||
func (o *Delete) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
|
||||
route, rCtx, _ := o.Context.RouteInfo(r)
|
||||
if rCtx != nil {
|
||||
*r = *rCtx
|
||||
}
|
||||
var Params = NewDeleteParams()
|
||||
if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params
|
||||
o.Context.Respond(rw, r, route.Produces, route, err)
|
||||
return
|
||||
}
|
||||
|
||||
res := o.Handler.Handle(Params) // actually handle the request
|
||||
o.Context.Respond(rw, r, route.Produces, route, res)
|
||||
|
||||
}
|
74
build/app/restapi/operations/delete_parameters.go
Normal file
74
build/app/restapi/operations/delete_parameters.go
Normal file
@@ -0,0 +1,74 @@
|
||||
// Code generated by go-swagger; DO NOT EDIT.
|
||||
|
||||
package operations
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/go-openapi/errors"
|
||||
"github.com/go-openapi/runtime/middleware"
|
||||
"github.com/go-openapi/strfmt"
|
||||
)
|
||||
|
||||
// NewDeleteParams creates a new DeleteParams object
|
||||
//
|
||||
// There are no default values defined in the spec.
|
||||
func NewDeleteParams() DeleteParams {
|
||||
|
||||
return DeleteParams{}
|
||||
}
|
||||
|
||||
// DeleteParams contains all the bound params for the delete operation
|
||||
// typically these are obtained from a http.Request
|
||||
//
|
||||
// swagger:parameters Delete
|
||||
type DeleteParams struct {
|
||||
|
||||
// HTTP Request Object
|
||||
HTTPRequest *http.Request `json:"-"`
|
||||
|
||||
/*On cancel Direktiv sends a DELETE request to
|
||||
the action with id in the header
|
||||
|
||||
In: header
|
||||
*/
|
||||
DirektivActionID *string
|
||||
}
|
||||
|
||||
// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface
|
||||
// for simple values it will use straight method calls.
|
||||
//
|
||||
// To ensure default values, the struct must have been initialized with NewDeleteParams() beforehand.
|
||||
func (o *DeleteParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {
|
||||
var res []error
|
||||
|
||||
o.HTTPRequest = r
|
||||
|
||||
if err := o.bindDirektivActionID(r.Header[http.CanonicalHeaderKey("Direktiv-ActionID")], true, route.Formats); err != nil {
|
||||
res = append(res, err)
|
||||
}
|
||||
if len(res) > 0 {
|
||||
return errors.CompositeValidationError(res...)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// bindDirektivActionID binds and validates parameter DirektivActionID from header.
|
||||
func (o *DeleteParams) bindDirektivActionID(rawData []string, hasKey bool, formats strfmt.Registry) error {
|
||||
var raw string
|
||||
if len(rawData) > 0 {
|
||||
raw = rawData[len(rawData)-1]
|
||||
}
|
||||
|
||||
// Required: false
|
||||
|
||||
if raw == "" { // empty values pass all other validations
|
||||
return nil
|
||||
}
|
||||
o.DirektivActionID = &raw
|
||||
|
||||
return nil
|
||||
}
|
36
build/app/restapi/operations/delete_responses.go
Normal file
36
build/app/restapi/operations/delete_responses.go
Normal file
@@ -0,0 +1,36 @@
|
||||
// Code generated by go-swagger; DO NOT EDIT.
|
||||
|
||||
package operations
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/go-openapi/runtime"
|
||||
)
|
||||
|
||||
// DeleteOKCode is the HTTP code returned for type DeleteOK
|
||||
const DeleteOKCode int = 200
|
||||
|
||||
/*DeleteOK delete o k
|
||||
|
||||
swagger:response deleteOK
|
||||
*/
|
||||
type DeleteOK struct {
|
||||
}
|
||||
|
||||
// NewDeleteOK creates DeleteOK with default headers values
|
||||
func NewDeleteOK() *DeleteOK {
|
||||
|
||||
return &DeleteOK{}
|
||||
}
|
||||
|
||||
// WriteResponse to the client
|
||||
func (o *DeleteOK) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) {
|
||||
|
||||
rw.Header().Del(runtime.HeaderContentType) //Remove Content-Type on empty responses
|
||||
|
||||
rw.WriteHeader(200)
|
||||
}
|
58
build/app/restapi/operations/direktiv_delete.go
Normal file
58
build/app/restapi/operations/direktiv_delete.go
Normal file
@@ -0,0 +1,58 @@
|
||||
package operations
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/direktiv/apps/go/pkg/apps"
|
||||
"github.com/go-openapi/runtime/middleware"
|
||||
)
|
||||
|
||||
func DeleteDirektivHandle(params DeleteParams) middleware.Responder {
|
||||
|
||||
actionId := *params.DirektivActionID
|
||||
// defer sm.Delete(actionId)
|
||||
|
||||
if actionId == "" {
|
||||
return NewDeleteOK()
|
||||
}
|
||||
|
||||
ri, err := apps.RequestinfoFromRequest(params.HTTPRequest)
|
||||
if err != nil {
|
||||
fmt.Println("can not create ri from request")
|
||||
return NewDeleteOK()
|
||||
}
|
||||
|
||||
// cancel, ok := sm.Load(actionId)
|
||||
ci, ok := sm.Load(actionId)
|
||||
if !ok {
|
||||
ri.Logger().Infof("can not load context for action id1", err)
|
||||
return NewDeleteOK()
|
||||
}
|
||||
|
||||
cinfo, ok := ci.(*ctxInfo)
|
||||
if !ok {
|
||||
ri.Logger().Infof("can not load context for action id2")
|
||||
return NewDeleteOK()
|
||||
}
|
||||
|
||||
// set to cancelled
|
||||
cinfo.cancelled = true
|
||||
|
||||
ri.Logger().Infof("cancelling action id %v", actionId)
|
||||
cinfo.cf()
|
||||
|
||||
cmd, err := templateString("echo 'cancel {{ .DirektivActionID }}'", params)
|
||||
if err != nil {
|
||||
ri.Logger().Infof("can not template cancel command: %v", err)
|
||||
return NewDeleteOK()
|
||||
}
|
||||
|
||||
_, err = runCmd(context.Background(), cmd, []string{}, "", false, true, ri)
|
||||
if err != nil {
|
||||
ri.Logger().Infof("error running cancel function: %v", err)
|
||||
}
|
||||
|
||||
return NewDeleteOK()
|
||||
|
||||
}
|
279
build/app/restapi/operations/direktiv_helper.go
Normal file
279
build/app/restapi/operations/direktiv_helper.go
Normal file
@@ -0,0 +1,279 @@
|
||||
package operations
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"html"
|
||||
"html/template"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/cookiejar"
|
||||
"net/url"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/Masterminds/sprig"
|
||||
"github.com/direktiv/apps/go/pkg/apps"
|
||||
"github.com/mattn/go-shellwords"
|
||||
"golang.org/x/net/publicsuffix"
|
||||
)
|
||||
|
||||
func fileExists(file string) bool {
|
||||
_, err := os.Open(file)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func file64(path string) string {
|
||||
|
||||
b, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return err.Error()
|
||||
}
|
||||
|
||||
return base64.StdEncoding.EncodeToString(b)
|
||||
|
||||
}
|
||||
|
||||
func deref(dd interface{}) interface{} {
|
||||
switch p := dd.(type) {
|
||||
case *string:
|
||||
return *p
|
||||
case *int:
|
||||
return *p
|
||||
default:
|
||||
return p
|
||||
}
|
||||
}
|
||||
|
||||
func templateString(tmplIn string, data interface{}) (string, error) {
|
||||
|
||||
tmpl, err := template.New("base").Funcs(sprig.FuncMap()).Funcs(template.FuncMap{
|
||||
"fileExists": fileExists,
|
||||
"deref": deref,
|
||||
"file64": file64,
|
||||
}).Parse(tmplIn)
|
||||
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
var b bytes.Buffer
|
||||
err = tmpl.Execute(&b, data)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
v := b.String()
|
||||
if v == "<no value>" {
|
||||
v = ""
|
||||
}
|
||||
|
||||
return html.UnescapeString(v), nil
|
||||
|
||||
}
|
||||
|
||||
func convertTemplateToBool(template string, data interface{}, defaultValue bool) bool {
|
||||
|
||||
out, err := templateString(template, data)
|
||||
if err != nil {
|
||||
return defaultValue
|
||||
}
|
||||
|
||||
ins, err := strconv.ParseBool(out)
|
||||
if err != nil {
|
||||
return defaultValue
|
||||
}
|
||||
|
||||
return ins
|
||||
|
||||
}
|
||||
|
||||
func runCmd(ctx context.Context, cmdString string, envs []string,
|
||||
output string, silent, print bool, ri *apps.RequestInfo) (map[string]interface{}, error) {
|
||||
|
||||
ir := make(map[string]interface{})
|
||||
ir[successKey] = false
|
||||
|
||||
a, err := shellwords.Parse(cmdString)
|
||||
if err != nil {
|
||||
ir[resultKey] = err.Error()
|
||||
return ir, err
|
||||
}
|
||||
|
||||
if len(a) == 0 {
|
||||
return ir, fmt.Errorf("command '%v' parsed to empty array", cmdString)
|
||||
}
|
||||
|
||||
// get the binary and args
|
||||
bin := a[0]
|
||||
argsIn := []string{}
|
||||
if len(a) > 1 {
|
||||
argsIn = a[1:]
|
||||
}
|
||||
|
||||
logger := io.Discard
|
||||
stdo := io.Discard
|
||||
if !silent {
|
||||
logger = ri.LogWriter()
|
||||
stdo = os.Stdout
|
||||
}
|
||||
|
||||
var o bytes.Buffer
|
||||
var oerr bytes.Buffer
|
||||
|
||||
mwStdout := io.MultiWriter(stdo, &o, logger)
|
||||
mwStdErr := io.MultiWriter(os.Stdout, &oerr, logger)
|
||||
|
||||
cmd := exec.CommandContext(ctx, bin, argsIn...)
|
||||
cmd.Stdout = mwStdout
|
||||
cmd.Stderr = mwStdErr
|
||||
cmd.Dir = ri.Dir()
|
||||
|
||||
// change HOME
|
||||
curEnvs := append(os.Environ(), fmt.Sprintf("HOME=%s", ri.Dir()))
|
||||
cmd.Env = append(curEnvs, envs...)
|
||||
|
||||
if print {
|
||||
ri.Logger().Infof("running command %v", cmd)
|
||||
}
|
||||
|
||||
err = cmd.Run()
|
||||
if err != nil {
|
||||
ir[resultKey] = string(oerr.String())
|
||||
if oerr.String() == "" {
|
||||
ir[resultKey] = err.Error()
|
||||
} else {
|
||||
ri.Logger().Errorf(oerr.String())
|
||||
err = fmt.Errorf(oerr.String())
|
||||
}
|
||||
return ir, err
|
||||
}
|
||||
|
||||
// successful here
|
||||
ir[successKey] = true
|
||||
|
||||
// output check
|
||||
b := o.Bytes()
|
||||
if output != "" {
|
||||
b, err = os.ReadFile(output)
|
||||
if err != nil {
|
||||
ir[resultKey] = err.Error()
|
||||
return ir, err
|
||||
}
|
||||
}
|
||||
|
||||
var rj interface{}
|
||||
err = json.Unmarshal(b, &rj)
|
||||
if err != nil {
|
||||
rj = apps.ToJSON(string(b))
|
||||
}
|
||||
ir[resultKey] = rj
|
||||
|
||||
return ir, nil
|
||||
|
||||
}
|
||||
|
||||
func doHttpRequest(debug bool, method, u, user, pwd string,
|
||||
headers map[string]string, insecure, errNo200 bool,
|
||||
data []byte) (map[string]interface{}, error) {
|
||||
|
||||
ir := make(map[string]interface{})
|
||||
ir[successKey] = false
|
||||
|
||||
urlParsed, err := url.Parse(u)
|
||||
if err != nil {
|
||||
ir[resultKey] = err.Error()
|
||||
return ir, err
|
||||
}
|
||||
|
||||
v, err := url.ParseQuery(urlParsed.RawQuery)
|
||||
if err != nil {
|
||||
ir[resultKey] = err.Error()
|
||||
return ir, err
|
||||
}
|
||||
|
||||
urlParsed.RawQuery = v.Encode()
|
||||
|
||||
req, err := http.NewRequest(strings.ToUpper(method), urlParsed.String(), bytes.NewReader(data))
|
||||
if err != nil {
|
||||
ir[resultKey] = err.Error()
|
||||
return ir, err
|
||||
}
|
||||
req.Close = true
|
||||
|
||||
for k, v := range headers {
|
||||
req.Header.Add(k, v)
|
||||
}
|
||||
|
||||
if user != "" {
|
||||
req.SetBasicAuth(user, pwd)
|
||||
}
|
||||
|
||||
jar, err := cookiejar.New(&cookiejar.Options{
|
||||
PublicSuffixList: publicsuffix.List,
|
||||
})
|
||||
cr := http.DefaultTransport.(*http.Transport).Clone()
|
||||
cr.TLSClientConfig = &tls.Config{
|
||||
InsecureSkipVerify: insecure,
|
||||
}
|
||||
|
||||
client := &http.Client{
|
||||
Jar: jar,
|
||||
Transport: cr,
|
||||
}
|
||||
|
||||
if debug {
|
||||
fmt.Printf("method: %s, insecure: %v\n", method, insecure)
|
||||
fmt.Printf("url: %s\n", req.URL.String())
|
||||
fmt.Println("Headers:")
|
||||
for k, v := range headers {
|
||||
fmt.Printf("%v = %v\n", k, v)
|
||||
}
|
||||
}
|
||||
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
ir[resultKey] = err.Error()
|
||||
return ir, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
b, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
ir[resultKey] = err.Error()
|
||||
return ir, err
|
||||
}
|
||||
|
||||
if errNo200 && (resp.StatusCode < 200 || resp.StatusCode > 299) {
|
||||
err = fmt.Errorf("response status is not between 200-299: %v (%v)", resp.StatusCode, resp.Status)
|
||||
ir[resultKey] = err.Error()
|
||||
return ir, err
|
||||
}
|
||||
|
||||
// from here on it is successful
|
||||
ir[successKey] = true
|
||||
ir[statusKey] = resp.Status
|
||||
ir[codeKey] = resp.StatusCode
|
||||
ir[headersKey] = resp.Header
|
||||
|
||||
var rj interface{}
|
||||
err = json.Unmarshal(b, &rj)
|
||||
ir[resultKey] = rj
|
||||
|
||||
// if the response is not json, base64 the result
|
||||
if err != nil {
|
||||
ir[resultKey] = base64.StdEncoding.EncodeToString(b)
|
||||
}
|
||||
|
||||
return ir, nil
|
||||
|
||||
}
|
251
build/app/restapi/operations/direktiv_post.go
Normal file
251
build/app/restapi/operations/direktiv_post.go
Normal file
@@ -0,0 +1,251 @@
|
||||
package operations
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/direktiv/apps/go/pkg/apps"
|
||||
"github.com/go-openapi/runtime/middleware"
|
||||
"github.com/go-openapi/strfmt"
|
||||
|
||||
"app/models"
|
||||
)
|
||||
|
||||
const (
|
||||
successKey = "success"
|
||||
resultKey = "result"
|
||||
|
||||
// http related
|
||||
statusKey = "status"
|
||||
codeKey = "code"
|
||||
headersKey = "headers"
|
||||
)
|
||||
|
||||
var sm sync.Map
|
||||
|
||||
const (
|
||||
cmdErr = "io.direktiv.command.error"
|
||||
outErr = "io.direktiv.output.error"
|
||||
riErr = "io.direktiv.ri.error"
|
||||
)
|
||||
|
||||
type accParams struct {
|
||||
PostParams
|
||||
Commands []interface{}
|
||||
DirektivDir string
|
||||
}
|
||||
|
||||
type accParamsTemplate struct {
|
||||
models.PostParamsBody
|
||||
Commands []interface{}
|
||||
DirektivDir string
|
||||
}
|
||||
|
||||
type ctxInfo struct {
|
||||
cf context.CancelFunc
|
||||
cancelled bool
|
||||
}
|
||||
|
||||
func PostDirektivHandle(params PostParams) middleware.Responder {
|
||||
resp := &models.PostOKBody{}
|
||||
|
||||
var (
|
||||
err error
|
||||
ret interface{}
|
||||
cont bool
|
||||
)
|
||||
|
||||
ri, err := apps.RequestinfoFromRequest(params.HTTPRequest)
|
||||
if err != nil {
|
||||
return generateError(riErr, err)
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(params.HTTPRequest.Context())
|
||||
|
||||
sm.Store(*params.DirektivActionID, &ctxInfo{
|
||||
cancel,
|
||||
false,
|
||||
})
|
||||
|
||||
defer sm.Delete(*params.DirektivActionID)
|
||||
|
||||
var responses []interface{}
|
||||
|
||||
var paramsCollector []interface{}
|
||||
accParams := accParams{
|
||||
params,
|
||||
nil,
|
||||
ri.Dir(),
|
||||
}
|
||||
|
||||
ret, err = runCommand0(ctx, accParams, ri)
|
||||
|
||||
responses = append(responses, ret)
|
||||
|
||||
// if foreach returns an error there is no continue
|
||||
//
|
||||
// default we do not continue
|
||||
cont = convertTemplateToBool("<no value>", accParams, false)
|
||||
// cont = convertTemplateToBool("<no value>", accParams, true)
|
||||
//
|
||||
|
||||
if err != nil && !cont {
|
||||
|
||||
errName := cmdErr
|
||||
|
||||
// if the delete function added the cancel tag
|
||||
ci, ok := sm.Load(*params.DirektivActionID)
|
||||
if ok {
|
||||
cinfo, ok := ci.(*ctxInfo)
|
||||
if ok && cinfo.cancelled {
|
||||
errName = "direktiv.actionCancelled"
|
||||
err = fmt.Errorf("action got cancel request")
|
||||
}
|
||||
}
|
||||
|
||||
return generateError(errName, err)
|
||||
}
|
||||
|
||||
paramsCollector = append(paramsCollector, ret)
|
||||
accParams.Commands = paramsCollector
|
||||
|
||||
ret, err = runCommand1(ctx, accParams, ri)
|
||||
|
||||
responses = append(responses, ret)
|
||||
|
||||
// if foreach returns an error there is no continue
|
||||
//
|
||||
// default we do not continue
|
||||
cont = convertTemplateToBool("<no value>", accParams, false)
|
||||
// cont = convertTemplateToBool("<no value>", accParams, true)
|
||||
//
|
||||
|
||||
if err != nil && !cont {
|
||||
|
||||
errName := cmdErr
|
||||
|
||||
// if the delete function added the cancel tag
|
||||
ci, ok := sm.Load(*params.DirektivActionID)
|
||||
if ok {
|
||||
cinfo, ok := ci.(*ctxInfo)
|
||||
if ok && cinfo.cancelled {
|
||||
errName = "direktiv.actionCancelled"
|
||||
err = fmt.Errorf("action got cancel request")
|
||||
}
|
||||
}
|
||||
|
||||
return generateError(errName, err)
|
||||
}
|
||||
|
||||
paramsCollector = append(paramsCollector, ret)
|
||||
accParams.Commands = paramsCollector
|
||||
|
||||
s, err := templateString(`{
|
||||
"export-excel": {{ (index . 1).result | toJson }}
|
||||
}
|
||||
`, responses)
|
||||
if err != nil {
|
||||
return generateError(outErr, err)
|
||||
}
|
||||
|
||||
responseBytes := []byte(s)
|
||||
|
||||
// validate
|
||||
resp.UnmarshalBinary(responseBytes)
|
||||
err = resp.Validate(strfmt.Default)
|
||||
|
||||
if err != nil {
|
||||
return generateError(outErr, err)
|
||||
}
|
||||
|
||||
return NewPostOK().WithPayload(resp)
|
||||
}
|
||||
|
||||
// exec
|
||||
func runCommand0(ctx context.Context,
|
||||
params accParams, ri *apps.RequestInfo) (map[string]interface{}, error) {
|
||||
|
||||
ir := make(map[string]interface{})
|
||||
ir[successKey] = false
|
||||
|
||||
at := accParamsTemplate{
|
||||
*params.Body,
|
||||
params.Commands,
|
||||
params.DirektivDir,
|
||||
}
|
||||
|
||||
cmd, err := templateString(`/bin/json2excel -inFile input.json -worksheetName "{{ .WorksheetName }}" -outputFilename '{{ .OutFilename }}'`, at)
|
||||
if err != nil {
|
||||
ri.Logger().Infof("error executing command: %v", err)
|
||||
ir[resultKey] = err.Error()
|
||||
return ir, err
|
||||
}
|
||||
cmd = strings.Replace(cmd, "\n", "", -1)
|
||||
|
||||
silent := convertTemplateToBool("false", at, false)
|
||||
print := convertTemplateToBool("true", at, true)
|
||||
output := ""
|
||||
|
||||
envs := []string{}
|
||||
|
||||
return runCmd(ctx, cmd, envs, output, silent, print, ri)
|
||||
|
||||
}
|
||||
|
||||
// end commands
|
||||
|
||||
// exec
|
||||
func runCommand1(ctx context.Context,
|
||||
params accParams, ri *apps.RequestInfo) (map[string]interface{}, error) {
|
||||
|
||||
ir := make(map[string]interface{})
|
||||
ir[successKey] = false
|
||||
|
||||
at := accParamsTemplate{
|
||||
*params.Body,
|
||||
params.Commands,
|
||||
params.DirektivDir,
|
||||
}
|
||||
|
||||
cmd, err := templateString(`base64 -w 0 /tmp/{{ .OutFilename }}`, at)
|
||||
if err != nil {
|
||||
ri.Logger().Infof("error executing command: %v", err)
|
||||
ir[resultKey] = err.Error()
|
||||
return ir, err
|
||||
}
|
||||
cmd = strings.Replace(cmd, "\n", "", -1)
|
||||
|
||||
silent := convertTemplateToBool("<no value>", at, false)
|
||||
print := convertTemplateToBool("<no value>", at, true)
|
||||
output := ""
|
||||
|
||||
envs := []string{}
|
||||
|
||||
return runCmd(ctx, cmd, envs, output, silent, print, ri)
|
||||
|
||||
}
|
||||
|
||||
// end commands
|
||||
|
||||
func generateError(code string, err error) *PostDefault {
|
||||
|
||||
d := NewPostDefault(0).WithDirektivErrorCode(code).
|
||||
WithDirektivErrorMessage(err.Error())
|
||||
|
||||
errString := err.Error()
|
||||
|
||||
errResp := models.Error{
|
||||
ErrorCode: &code,
|
||||
ErrorMessage: &errString,
|
||||
}
|
||||
|
||||
d.SetPayload(&errResp)
|
||||
|
||||
return d
|
||||
}
|
||||
|
||||
func HandleShutdown() {
|
||||
// nothing for generated functions
|
||||
}
|
313
build/app/restapi/operations/export_xlsx_api.go
Normal file
313
build/app/restapi/operations/export_xlsx_api.go
Normal file
@@ -0,0 +1,313 @@
|
||||
// Code generated by go-swagger; DO NOT EDIT.
|
||||
|
||||
package operations
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/go-openapi/errors"
|
||||
"github.com/go-openapi/loads"
|
||||
"github.com/go-openapi/runtime"
|
||||
"github.com/go-openapi/runtime/middleware"
|
||||
"github.com/go-openapi/runtime/security"
|
||||
"github.com/go-openapi/spec"
|
||||
"github.com/go-openapi/strfmt"
|
||||
"github.com/go-openapi/swag"
|
||||
)
|
||||
|
||||
// NewExportXlsxAPI creates a new ExportXlsx instance
|
||||
func NewExportXlsxAPI(spec *loads.Document) *ExportXlsxAPI {
|
||||
return &ExportXlsxAPI{
|
||||
handlers: make(map[string]map[string]http.Handler),
|
||||
formats: strfmt.Default,
|
||||
defaultConsumes: "application/json",
|
||||
defaultProduces: "application/json",
|
||||
customConsumers: make(map[string]runtime.Consumer),
|
||||
customProducers: make(map[string]runtime.Producer),
|
||||
PreServerShutdown: func() {},
|
||||
ServerShutdown: func() {},
|
||||
spec: spec,
|
||||
useSwaggerUI: false,
|
||||
ServeError: errors.ServeError,
|
||||
BasicAuthenticator: security.BasicAuth,
|
||||
APIKeyAuthenticator: security.APIKeyAuth,
|
||||
BearerAuthenticator: security.BearerAuth,
|
||||
|
||||
JSONConsumer: runtime.JSONConsumer(),
|
||||
|
||||
JSONProducer: runtime.JSONProducer(),
|
||||
|
||||
DeleteHandler: DeleteHandlerFunc(func(params DeleteParams) middleware.Responder {
|
||||
return middleware.NotImplemented("operation Delete has not yet been implemented")
|
||||
}),
|
||||
PostHandler: PostHandlerFunc(func(params PostParams) middleware.Responder {
|
||||
return middleware.NotImplemented("operation Post has not yet been implemented")
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
/*ExportXlsxAPI Transform json input to xlsx spreadsheet */
|
||||
type ExportXlsxAPI struct {
|
||||
spec *loads.Document
|
||||
context *middleware.Context
|
||||
handlers map[string]map[string]http.Handler
|
||||
formats strfmt.Registry
|
||||
customConsumers map[string]runtime.Consumer
|
||||
customProducers map[string]runtime.Producer
|
||||
defaultConsumes string
|
||||
defaultProduces string
|
||||
Middleware func(middleware.Builder) http.Handler
|
||||
useSwaggerUI bool
|
||||
|
||||
// BasicAuthenticator generates a runtime.Authenticator from the supplied basic auth function.
|
||||
// It has a default implementation in the security package, however you can replace it for your particular usage.
|
||||
BasicAuthenticator func(security.UserPassAuthentication) runtime.Authenticator
|
||||
|
||||
// APIKeyAuthenticator generates a runtime.Authenticator from the supplied token auth function.
|
||||
// It has a default implementation in the security package, however you can replace it for your particular usage.
|
||||
APIKeyAuthenticator func(string, string, security.TokenAuthentication) runtime.Authenticator
|
||||
|
||||
// BearerAuthenticator generates a runtime.Authenticator from the supplied bearer token auth function.
|
||||
// It has a default implementation in the security package, however you can replace it for your particular usage.
|
||||
BearerAuthenticator func(string, security.ScopedTokenAuthentication) runtime.Authenticator
|
||||
|
||||
// JSONConsumer registers a consumer for the following mime types:
|
||||
// - application/json
|
||||
JSONConsumer runtime.Consumer
|
||||
|
||||
// JSONProducer registers a producer for the following mime types:
|
||||
// - application/json
|
||||
JSONProducer runtime.Producer
|
||||
|
||||
// DeleteHandler sets the operation handler for the delete operation
|
||||
DeleteHandler DeleteHandler
|
||||
// PostHandler sets the operation handler for the post operation
|
||||
PostHandler PostHandler
|
||||
|
||||
// ServeError is called when an error is received, there is a default handler
|
||||
// but you can set your own with this
|
||||
ServeError func(http.ResponseWriter, *http.Request, error)
|
||||
|
||||
// PreServerShutdown is called before the HTTP(S) server is shutdown
|
||||
// This allows for custom functions to get executed before the HTTP(S) server stops accepting traffic
|
||||
PreServerShutdown func()
|
||||
|
||||
// ServerShutdown is called when the HTTP(S) server is shut down and done
|
||||
// handling all active connections and does not accept connections any more
|
||||
ServerShutdown func()
|
||||
|
||||
// Custom command line argument groups with their descriptions
|
||||
CommandLineOptionsGroups []swag.CommandLineOptionsGroup
|
||||
|
||||
// User defined logger function.
|
||||
Logger func(string, ...interface{})
|
||||
}
|
||||
|
||||
// UseRedoc for documentation at /docs
|
||||
func (o *ExportXlsxAPI) UseRedoc() {
|
||||
o.useSwaggerUI = false
|
||||
}
|
||||
|
||||
// UseSwaggerUI for documentation at /docs
|
||||
func (o *ExportXlsxAPI) UseSwaggerUI() {
|
||||
o.useSwaggerUI = true
|
||||
}
|
||||
|
||||
// SetDefaultProduces sets the default produces media type
|
||||
func (o *ExportXlsxAPI) SetDefaultProduces(mediaType string) {
|
||||
o.defaultProduces = mediaType
|
||||
}
|
||||
|
||||
// SetDefaultConsumes returns the default consumes media type
|
||||
func (o *ExportXlsxAPI) SetDefaultConsumes(mediaType string) {
|
||||
o.defaultConsumes = mediaType
|
||||
}
|
||||
|
||||
// SetSpec sets a spec that will be served for the clients.
|
||||
func (o *ExportXlsxAPI) SetSpec(spec *loads.Document) {
|
||||
o.spec = spec
|
||||
}
|
||||
|
||||
// DefaultProduces returns the default produces media type
|
||||
func (o *ExportXlsxAPI) DefaultProduces() string {
|
||||
return o.defaultProduces
|
||||
}
|
||||
|
||||
// DefaultConsumes returns the default consumes media type
|
||||
func (o *ExportXlsxAPI) DefaultConsumes() string {
|
||||
return o.defaultConsumes
|
||||
}
|
||||
|
||||
// Formats returns the registered string formats
|
||||
func (o *ExportXlsxAPI) Formats() strfmt.Registry {
|
||||
return o.formats
|
||||
}
|
||||
|
||||
// RegisterFormat registers a custom format validator
|
||||
func (o *ExportXlsxAPI) RegisterFormat(name string, format strfmt.Format, validator strfmt.Validator) {
|
||||
o.formats.Add(name, format, validator)
|
||||
}
|
||||
|
||||
// Validate validates the registrations in the ExportXlsxAPI
|
||||
func (o *ExportXlsxAPI) Validate() error {
|
||||
var unregistered []string
|
||||
|
||||
if o.JSONConsumer == nil {
|
||||
unregistered = append(unregistered, "JSONConsumer")
|
||||
}
|
||||
|
||||
if o.JSONProducer == nil {
|
||||
unregistered = append(unregistered, "JSONProducer")
|
||||
}
|
||||
|
||||
if o.DeleteHandler == nil {
|
||||
unregistered = append(unregistered, "DeleteHandler")
|
||||
}
|
||||
if o.PostHandler == nil {
|
||||
unregistered = append(unregistered, "PostHandler")
|
||||
}
|
||||
|
||||
if len(unregistered) > 0 {
|
||||
return fmt.Errorf("missing registration: %s", strings.Join(unregistered, ", "))
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// ServeErrorFor gets a error handler for a given operation id
|
||||
func (o *ExportXlsxAPI) ServeErrorFor(operationID string) func(http.ResponseWriter, *http.Request, error) {
|
||||
return o.ServeError
|
||||
}
|
||||
|
||||
// AuthenticatorsFor gets the authenticators for the specified security schemes
|
||||
func (o *ExportXlsxAPI) AuthenticatorsFor(schemes map[string]spec.SecurityScheme) map[string]runtime.Authenticator {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Authorizer returns the registered authorizer
|
||||
func (o *ExportXlsxAPI) Authorizer() runtime.Authorizer {
|
||||
return nil
|
||||
}
|
||||
|
||||
// ConsumersFor gets the consumers for the specified media types.
|
||||
// MIME type parameters are ignored here.
|
||||
func (o *ExportXlsxAPI) ConsumersFor(mediaTypes []string) map[string]runtime.Consumer {
|
||||
result := make(map[string]runtime.Consumer, len(mediaTypes))
|
||||
for _, mt := range mediaTypes {
|
||||
switch mt {
|
||||
case "application/json":
|
||||
result["application/json"] = o.JSONConsumer
|
||||
}
|
||||
|
||||
if c, ok := o.customConsumers[mt]; ok {
|
||||
result[mt] = c
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// ProducersFor gets the producers for the specified media types.
|
||||
// MIME type parameters are ignored here.
|
||||
func (o *ExportXlsxAPI) ProducersFor(mediaTypes []string) map[string]runtime.Producer {
|
||||
result := make(map[string]runtime.Producer, len(mediaTypes))
|
||||
for _, mt := range mediaTypes {
|
||||
switch mt {
|
||||
case "application/json":
|
||||
result["application/json"] = o.JSONProducer
|
||||
}
|
||||
|
||||
if p, ok := o.customProducers[mt]; ok {
|
||||
result[mt] = p
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// HandlerFor gets a http.Handler for the provided operation method and path
|
||||
func (o *ExportXlsxAPI) HandlerFor(method, path string) (http.Handler, bool) {
|
||||
if o.handlers == nil {
|
||||
return nil, false
|
||||
}
|
||||
um := strings.ToUpper(method)
|
||||
if _, ok := o.handlers[um]; !ok {
|
||||
return nil, false
|
||||
}
|
||||
if path == "/" {
|
||||
path = ""
|
||||
}
|
||||
h, ok := o.handlers[um][path]
|
||||
return h, ok
|
||||
}
|
||||
|
||||
// Context returns the middleware context for the export xlsx API
|
||||
func (o *ExportXlsxAPI) Context() *middleware.Context {
|
||||
if o.context == nil {
|
||||
o.context = middleware.NewRoutableContext(o.spec, o, nil)
|
||||
}
|
||||
|
||||
return o.context
|
||||
}
|
||||
|
||||
func (o *ExportXlsxAPI) initHandlerCache() {
|
||||
o.Context() // don't care about the result, just that the initialization happened
|
||||
if o.handlers == nil {
|
||||
o.handlers = make(map[string]map[string]http.Handler)
|
||||
}
|
||||
|
||||
if o.handlers["DELETE"] == nil {
|
||||
o.handlers["DELETE"] = make(map[string]http.Handler)
|
||||
}
|
||||
o.handlers["DELETE"][""] = NewDelete(o.context, o.DeleteHandler)
|
||||
if o.handlers["POST"] == nil {
|
||||
o.handlers["POST"] = make(map[string]http.Handler)
|
||||
}
|
||||
o.handlers["POST"][""] = NewPost(o.context, o.PostHandler)
|
||||
}
|
||||
|
||||
// Serve creates a http handler to serve the API over HTTP
|
||||
// can be used directly in http.ListenAndServe(":8000", api.Serve(nil))
|
||||
func (o *ExportXlsxAPI) Serve(builder middleware.Builder) http.Handler {
|
||||
o.Init()
|
||||
|
||||
if o.Middleware != nil {
|
||||
return o.Middleware(builder)
|
||||
}
|
||||
if o.useSwaggerUI {
|
||||
return o.context.APIHandlerSwaggerUI(builder)
|
||||
}
|
||||
return o.context.APIHandler(builder)
|
||||
}
|
||||
|
||||
// Init allows you to just initialize the handler cache, you can then recompose the middleware as you see fit
|
||||
func (o *ExportXlsxAPI) Init() {
|
||||
if len(o.handlers) == 0 {
|
||||
o.initHandlerCache()
|
||||
}
|
||||
}
|
||||
|
||||
// RegisterConsumer allows you to add (or override) a consumer for a media type.
|
||||
func (o *ExportXlsxAPI) RegisterConsumer(mediaType string, consumer runtime.Consumer) {
|
||||
o.customConsumers[mediaType] = consumer
|
||||
}
|
||||
|
||||
// RegisterProducer allows you to add (or override) a producer for a media type.
|
||||
func (o *ExportXlsxAPI) RegisterProducer(mediaType string, producer runtime.Producer) {
|
||||
o.customProducers[mediaType] = producer
|
||||
}
|
||||
|
||||
// AddMiddlewareFor adds a http middleware to existing handler
|
||||
func (o *ExportXlsxAPI) AddMiddlewareFor(method, path string, builder middleware.Builder) {
|
||||
um := strings.ToUpper(method)
|
||||
if path == "/" {
|
||||
path = ""
|
||||
}
|
||||
o.Init()
|
||||
if h, ok := o.handlers[um][path]; ok {
|
||||
o.handlers[method][path] = builder(h)
|
||||
}
|
||||
}
|
56
build/app/restapi/operations/post.go
Normal file
56
build/app/restapi/operations/post.go
Normal file
@@ -0,0 +1,56 @@
|
||||
// Code generated by go-swagger; DO NOT EDIT.
|
||||
|
||||
package operations
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the generate command
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/go-openapi/runtime/middleware"
|
||||
)
|
||||
|
||||
// PostHandlerFunc turns a function with the right signature into a post handler
|
||||
type PostHandlerFunc func(PostParams) middleware.Responder
|
||||
|
||||
// Handle executing the request and returning a response
|
||||
func (fn PostHandlerFunc) Handle(params PostParams) middleware.Responder {
|
||||
return fn(params)
|
||||
}
|
||||
|
||||
// PostHandler interface for that can handle valid post params
|
||||
type PostHandler interface {
|
||||
Handle(PostParams) middleware.Responder
|
||||
}
|
||||
|
||||
// NewPost creates a new http.Handler for the post operation
|
||||
func NewPost(ctx *middleware.Context, handler PostHandler) *Post {
|
||||
return &Post{Context: ctx, Handler: handler}
|
||||
}
|
||||
|
||||
/* Post swagger:route POST / post
|
||||
|
||||
Post post API
|
||||
|
||||
*/
|
||||
type Post struct {
|
||||
Context *middleware.Context
|
||||
Handler PostHandler
|
||||
}
|
||||
|
||||
func (o *Post) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
|
||||
route, rCtx, _ := o.Context.RouteInfo(r)
|
||||
if rCtx != nil {
|
||||
*r = *rCtx
|
||||
}
|
||||
var Params = NewPostParams()
|
||||
if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params
|
||||
o.Context.Respond(rw, r, route.Produces, route, err)
|
||||
return
|
||||
}
|
||||
|
||||
res := o.Handler.Handle(Params) // actually handle the request
|
||||
o.Context.Respond(rw, r, route.Produces, route, res)
|
||||
|
||||
}
|
149
build/app/restapi/operations/post_parameters.go
Normal file
149
build/app/restapi/operations/post_parameters.go
Normal file
@@ -0,0 +1,149 @@
|
||||
// Code generated by go-swagger; DO NOT EDIT.
|
||||
|
||||
package operations
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"github.com/go-openapi/errors"
|
||||
"github.com/go-openapi/runtime"
|
||||
"github.com/go-openapi/runtime/middleware"
|
||||
"github.com/go-openapi/strfmt"
|
||||
"github.com/go-openapi/validate"
|
||||
|
||||
"app/models"
|
||||
)
|
||||
|
||||
// NewPostParams creates a new PostParams object
|
||||
// with the default values initialized.
|
||||
func NewPostParams() PostParams {
|
||||
|
||||
var (
|
||||
// initialize parameters with default values
|
||||
|
||||
direktivActionIDDefault = string("development")
|
||||
direktivTempDirDefault = string("/tmp")
|
||||
)
|
||||
|
||||
return PostParams{
|
||||
DirektivActionID: &direktivActionIDDefault,
|
||||
|
||||
DirektivTempDir: &direktivTempDirDefault,
|
||||
}
|
||||
}
|
||||
|
||||
// PostParams contains all the bound params for the post operation
|
||||
// typically these are obtained from a http.Request
|
||||
//
|
||||
// swagger:parameters Post
|
||||
type PostParams struct {
|
||||
|
||||
// HTTP Request Object
|
||||
HTTPRequest *http.Request `json:"-"`
|
||||
|
||||
/*direktiv action id is an UUID.
|
||||
For development it can be set to 'development'
|
||||
|
||||
In: header
|
||||
Default: "development"
|
||||
*/
|
||||
DirektivActionID *string
|
||||
/*direktiv temp dir is the working directory for that request
|
||||
For development it can be set to e.g. '/tmp'
|
||||
|
||||
In: header
|
||||
Default: "/tmp"
|
||||
*/
|
||||
DirektivTempDir *string
|
||||
/*
|
||||
In: body
|
||||
*/
|
||||
Body *models.PostParamsBody
|
||||
}
|
||||
|
||||
// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface
|
||||
// for simple values it will use straight method calls.
|
||||
//
|
||||
// To ensure default values, the struct must have been initialized with NewPostParams() beforehand.
|
||||
func (o *PostParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {
|
||||
var res []error
|
||||
|
||||
o.HTTPRequest = r
|
||||
|
||||
if err := o.bindDirektivActionID(r.Header[http.CanonicalHeaderKey("Direktiv-ActionID")], true, route.Formats); err != nil {
|
||||
res = append(res, err)
|
||||
}
|
||||
|
||||
if err := o.bindDirektivTempDir(r.Header[http.CanonicalHeaderKey("Direktiv-TempDir")], true, route.Formats); err != nil {
|
||||
res = append(res, err)
|
||||
}
|
||||
|
||||
if runtime.HasBody(r) {
|
||||
defer r.Body.Close()
|
||||
var body models.PostParamsBody
|
||||
if err := route.Consumer.Consume(r.Body, &body); err != nil {
|
||||
res = append(res, errors.NewParseError("body", "body", "", err))
|
||||
} else {
|
||||
// validate body object
|
||||
if err := body.Validate(route.Formats); err != nil {
|
||||
res = append(res, err)
|
||||
}
|
||||
|
||||
// direktiv: add request to context so we can use in validate
|
||||
baseCtx := context.WithValue(r.Context(), "req", r)
|
||||
|
||||
ctx := validate.WithOperationRequest(baseCtx)
|
||||
if err := body.ContextValidate(ctx, route.Formats); err != nil {
|
||||
res = append(res, err)
|
||||
}
|
||||
|
||||
if len(res) == 0 {
|
||||
o.Body = &body
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(res) > 0 {
|
||||
return errors.CompositeValidationError(res...)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// bindDirektivActionID binds and validates parameter DirektivActionID from header.
|
||||
func (o *PostParams) bindDirektivActionID(rawData []string, hasKey bool, formats strfmt.Registry) error {
|
||||
var raw string
|
||||
if len(rawData) > 0 {
|
||||
raw = rawData[len(rawData)-1]
|
||||
}
|
||||
|
||||
// Required: false
|
||||
|
||||
if raw == "" { // empty values pass all other validations
|
||||
// Default values have been previously initialized by NewPostParams()
|
||||
return nil
|
||||
}
|
||||
o.DirektivActionID = &raw
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// bindDirektivTempDir binds and validates parameter DirektivTempDir from header.
|
||||
func (o *PostParams) bindDirektivTempDir(rawData []string, hasKey bool, formats strfmt.Registry) error {
|
||||
var raw string
|
||||
if len(rawData) > 0 {
|
||||
raw = rawData[len(rawData)-1]
|
||||
}
|
||||
|
||||
// Required: false
|
||||
|
||||
if raw == "" { // empty values pass all other validations
|
||||
// Default values have been previously initialized by NewPostParams()
|
||||
return nil
|
||||
}
|
||||
o.DirektivTempDir = &raw
|
||||
|
||||
return nil
|
||||
}
|
160
build/app/restapi/operations/post_responses.go
Normal file
160
build/app/restapi/operations/post_responses.go
Normal file
@@ -0,0 +1,160 @@
|
||||
// Code generated by go-swagger; DO NOT EDIT.
|
||||
|
||||
package operations
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/go-openapi/runtime"
|
||||
|
||||
"app/models"
|
||||
)
|
||||
|
||||
// PostOKCode is the HTTP code returned for type PostOK
|
||||
const PostOKCode int = 200
|
||||
|
||||
/*PostOK List of executed commands.
|
||||
|
||||
swagger:response postOK
|
||||
*/
|
||||
type PostOK struct {
|
||||
|
||||
/*
|
||||
In: Body
|
||||
*/
|
||||
Payload *models.PostOKBody `json:"body,omitempty"`
|
||||
}
|
||||
|
||||
// NewPostOK creates PostOK with default headers values
|
||||
func NewPostOK() *PostOK {
|
||||
|
||||
return &PostOK{}
|
||||
}
|
||||
|
||||
// WithPayload adds the payload to the post o k response
|
||||
func (o *PostOK) WithPayload(payload *models.PostOKBody) *PostOK {
|
||||
o.Payload = payload
|
||||
return o
|
||||
}
|
||||
|
||||
// SetPayload sets the payload to the post o k response
|
||||
func (o *PostOK) SetPayload(payload *models.PostOKBody) {
|
||||
o.Payload = payload
|
||||
}
|
||||
|
||||
// WriteResponse to the client
|
||||
func (o *PostOK) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) {
|
||||
|
||||
rw.WriteHeader(200)
|
||||
if o.Payload != nil {
|
||||
payload := o.Payload
|
||||
if err := producer.Produce(rw, payload); err != nil {
|
||||
panic(err) // let the recovery middleware deal with this
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*PostDefault generic error response
|
||||
|
||||
swagger:response postDefault
|
||||
*/
|
||||
type PostDefault struct {
|
||||
_statusCode int
|
||||
/*
|
||||
|
||||
*/
|
||||
DirektivErrorCode string `json:"Direktiv-ErrorCode"`
|
||||
/*
|
||||
|
||||
*/
|
||||
DirektivErrorMessage string `json:"Direktiv-ErrorMessage"`
|
||||
|
||||
/*
|
||||
In: Body
|
||||
*/
|
||||
Payload *models.Error `json:"body,omitempty"`
|
||||
}
|
||||
|
||||
// NewPostDefault creates PostDefault with default headers values
|
||||
func NewPostDefault(code int) *PostDefault {
|
||||
if code <= 0 {
|
||||
code = 500
|
||||
}
|
||||
|
||||
return &PostDefault{
|
||||
_statusCode: code,
|
||||
}
|
||||
}
|
||||
|
||||
// WithStatusCode adds the status to the post default response
|
||||
func (o *PostDefault) WithStatusCode(code int) *PostDefault {
|
||||
o._statusCode = code
|
||||
return o
|
||||
}
|
||||
|
||||
// SetStatusCode sets the status to the post default response
|
||||
func (o *PostDefault) SetStatusCode(code int) {
|
||||
o._statusCode = code
|
||||
}
|
||||
|
||||
// WithDirektivErrorCode adds the direktivErrorCode to the post default response
|
||||
func (o *PostDefault) WithDirektivErrorCode(direktivErrorCode string) *PostDefault {
|
||||
o.DirektivErrorCode = direktivErrorCode
|
||||
return o
|
||||
}
|
||||
|
||||
// SetDirektivErrorCode sets the direktivErrorCode to the post default response
|
||||
func (o *PostDefault) SetDirektivErrorCode(direktivErrorCode string) {
|
||||
o.DirektivErrorCode = direktivErrorCode
|
||||
}
|
||||
|
||||
// WithDirektivErrorMessage adds the direktivErrorMessage to the post default response
|
||||
func (o *PostDefault) WithDirektivErrorMessage(direktivErrorMessage string) *PostDefault {
|
||||
o.DirektivErrorMessage = direktivErrorMessage
|
||||
return o
|
||||
}
|
||||
|
||||
// SetDirektivErrorMessage sets the direktivErrorMessage to the post default response
|
||||
func (o *PostDefault) SetDirektivErrorMessage(direktivErrorMessage string) {
|
||||
o.DirektivErrorMessage = direktivErrorMessage
|
||||
}
|
||||
|
||||
// WithPayload adds the payload to the post default response
|
||||
func (o *PostDefault) WithPayload(payload *models.Error) *PostDefault {
|
||||
o.Payload = payload
|
||||
return o
|
||||
}
|
||||
|
||||
// SetPayload sets the payload to the post default response
|
||||
func (o *PostDefault) SetPayload(payload *models.Error) {
|
||||
o.Payload = payload
|
||||
}
|
||||
|
||||
// WriteResponse to the client
|
||||
func (o *PostDefault) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) {
|
||||
|
||||
// response header Direktiv-ErrorCode
|
||||
|
||||
direktivErrorCode := o.DirektivErrorCode
|
||||
if direktivErrorCode != "" {
|
||||
rw.Header().Set("Direktiv-ErrorCode", direktivErrorCode)
|
||||
}
|
||||
|
||||
// response header Direktiv-ErrorMessage
|
||||
|
||||
direktivErrorMessage := o.DirektivErrorMessage
|
||||
if direktivErrorMessage != "" {
|
||||
rw.Header().Set("Direktiv-ErrorMessage", direktivErrorMessage)
|
||||
}
|
||||
|
||||
rw.WriteHeader(o._statusCode)
|
||||
if o.Payload != nil {
|
||||
payload := o.Payload
|
||||
if err := producer.Produce(rw, payload); err != nil {
|
||||
panic(err) // let the recovery middleware deal with this
|
||||
}
|
||||
}
|
||||
}
|
513
build/app/restapi/server.go
Normal file
513
build/app/restapi/server.go
Normal file
@@ -0,0 +1,513 @@
|
||||
// Code generated by go-swagger; DO NOT EDIT.
|
||||
|
||||
package restapi
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"crypto/x509"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/signal"
|
||||
"strconv"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/go-openapi/runtime/flagext"
|
||||
"github.com/go-openapi/swag"
|
||||
flags "github.com/jessevdk/go-flags"
|
||||
"golang.org/x/net/netutil"
|
||||
|
||||
"app/restapi/operations"
|
||||
)
|
||||
|
||||
const (
|
||||
schemeHTTP = "http"
|
||||
schemeHTTPS = "https"
|
||||
schemeUnix = "unix"
|
||||
)
|
||||
|
||||
var defaultSchemes []string
|
||||
|
||||
func init() {
|
||||
defaultSchemes = []string{
|
||||
schemeHTTP,
|
||||
}
|
||||
}
|
||||
|
||||
// NewServer creates a new api export xlsx server but does not configure it
|
||||
func NewServer(api *operations.ExportXlsxAPI) *Server {
|
||||
s := new(Server)
|
||||
|
||||
s.shutdown = make(chan struct{})
|
||||
s.api = api
|
||||
s.interrupt = make(chan os.Signal, 1)
|
||||
return s
|
||||
}
|
||||
|
||||
// ConfigureAPI configures the API and handlers.
|
||||
func (s *Server) ConfigureAPI() {
|
||||
if s.api != nil {
|
||||
s.handler = configureAPI(s.api)
|
||||
}
|
||||
|
||||
s.ReadTimeout = 86400 * time.Second
|
||||
s.WriteTimeout = 86400 * time.Second
|
||||
}
|
||||
|
||||
// ConfigureFlags configures the additional flags defined by the handlers. Needs to be called before the parser.Parse
|
||||
func (s *Server) ConfigureFlags() {
|
||||
if s.api != nil {
|
||||
configureFlags(s.api)
|
||||
}
|
||||
}
|
||||
|
||||
// Server for the export xlsx API
|
||||
type Server struct {
|
||||
EnabledListeners []string `long:"scheme" description:"the listeners to enable, this can be repeated and defaults to the schemes in the swagger spec"`
|
||||
CleanupTimeout time.Duration `long:"cleanup-timeout" description:"grace period for which to wait before killing idle connections" default:"10s"`
|
||||
GracefulTimeout time.Duration `long:"graceful-timeout" description:"grace period for which to wait before shutting down the server" default:"15s"`
|
||||
MaxHeaderSize flagext.ByteSize `long:"max-header-size" description:"controls the maximum number of bytes the server will read parsing the request header's keys and values, including the request line. It does not limit the size of the request body." default:"1MiB"`
|
||||
|
||||
SocketPath flags.Filename `long:"socket-path" description:"the unix socket to listen on" default:"/var/run/export-xlsx.sock"`
|
||||
domainSocketL net.Listener
|
||||
|
||||
Host string `long:"host" description:"the IP to listen on" default:"localhost" env:"HOST"`
|
||||
Port int `long:"port" description:"the port to listen on for insecure connections, defaults to a random value" env:"PORT"`
|
||||
ListenLimit int `long:"listen-limit" description:"limit the number of outstanding requests"`
|
||||
KeepAlive time.Duration `long:"keep-alive" description:"sets the TCP keep-alive timeouts on accepted connections. It prunes dead TCP connections ( e.g. closing laptop mid-download)" default:"3m"`
|
||||
ReadTimeout time.Duration `long:"read-timeout" description:"maximum duration before timing out read of the request" default:"30s"`
|
||||
WriteTimeout time.Duration `long:"write-timeout" description:"maximum duration before timing out write of the response" default:"60s"`
|
||||
httpServerL net.Listener
|
||||
|
||||
TLSHost string `long:"tls-host" description:"the IP to listen on for tls, when not specified it's the same as --host" env:"TLS_HOST"`
|
||||
TLSPort int `long:"tls-port" description:"the port to listen on for secure connections, defaults to a random value" env:"TLS_PORT"`
|
||||
TLSCertificate flags.Filename `long:"tls-certificate" description:"the certificate to use for secure connections" env:"TLS_CERTIFICATE"`
|
||||
TLSCertificateKey flags.Filename `long:"tls-key" description:"the private key to use for secure connections" env:"TLS_PRIVATE_KEY"`
|
||||
TLSCACertificate flags.Filename `long:"tls-ca" description:"the certificate authority file to be used with mutual tls auth" env:"TLS_CA_CERTIFICATE"`
|
||||
TLSListenLimit int `long:"tls-listen-limit" description:"limit the number of outstanding requests"`
|
||||
TLSKeepAlive time.Duration `long:"tls-keep-alive" description:"sets the TCP keep-alive timeouts on accepted connections. It prunes dead TCP connections ( e.g. closing laptop mid-download)"`
|
||||
TLSReadTimeout time.Duration `long:"tls-read-timeout" description:"maximum duration before timing out read of the request"`
|
||||
TLSWriteTimeout time.Duration `long:"tls-write-timeout" description:"maximum duration before timing out write of the response"`
|
||||
httpsServerL net.Listener
|
||||
|
||||
api *operations.ExportXlsxAPI
|
||||
handler http.Handler
|
||||
hasListeners bool
|
||||
shutdown chan struct{}
|
||||
shuttingDown int32
|
||||
interrupted bool
|
||||
interrupt chan os.Signal
|
||||
}
|
||||
|
||||
// Logf logs message either via defined user logger or via system one if no user logger is defined.
|
||||
func (s *Server) Logf(f string, args ...interface{}) {
|
||||
if s.api != nil && s.api.Logger != nil {
|
||||
s.api.Logger(f, args...)
|
||||
} else {
|
||||
log.Printf(f, args...)
|
||||
}
|
||||
}
|
||||
|
||||
// Fatalf logs message either via defined user logger or via system one if no user logger is defined.
|
||||
// Exits with non-zero status after printing
|
||||
func (s *Server) Fatalf(f string, args ...interface{}) {
|
||||
if s.api != nil && s.api.Logger != nil {
|
||||
s.api.Logger(f, args...)
|
||||
os.Exit(1)
|
||||
} else {
|
||||
log.Fatalf(f, args...)
|
||||
}
|
||||
}
|
||||
|
||||
// SetAPI configures the server with the specified API. Needs to be called before Serve
|
||||
func (s *Server) SetAPI(api *operations.ExportXlsxAPI) {
|
||||
if api == nil {
|
||||
s.api = nil
|
||||
s.handler = nil
|
||||
return
|
||||
}
|
||||
|
||||
s.api = api
|
||||
s.handler = configureAPI(api)
|
||||
}
|
||||
|
||||
func (s *Server) hasScheme(scheme string) bool {
|
||||
schemes := s.EnabledListeners
|
||||
if len(schemes) == 0 {
|
||||
schemes = defaultSchemes
|
||||
}
|
||||
|
||||
for _, v := range schemes {
|
||||
if v == scheme {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Serve the api
|
||||
func (s *Server) Serve() (err error) {
|
||||
|
||||
if !s.hasListeners {
|
||||
if err = s.Listen(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// set default handler, if none is set
|
||||
if s.handler == nil {
|
||||
if s.api == nil {
|
||||
return errors.New("can't create the default handler, as no api is set")
|
||||
}
|
||||
|
||||
s.SetHandler(s.api.Serve(nil))
|
||||
}
|
||||
|
||||
wg := new(sync.WaitGroup)
|
||||
once := new(sync.Once)
|
||||
signalNotify(s.interrupt)
|
||||
go handleInterrupt(once, s)
|
||||
|
||||
servers := []*http.Server{}
|
||||
|
||||
if s.hasScheme(schemeUnix) {
|
||||
domainSocket := new(http.Server)
|
||||
domainSocket.MaxHeaderBytes = int(s.MaxHeaderSize)
|
||||
domainSocket.Handler = s.handler
|
||||
if int64(s.CleanupTimeout) > 0 {
|
||||
domainSocket.IdleTimeout = s.CleanupTimeout
|
||||
}
|
||||
|
||||
configureServer(domainSocket, "unix", string(s.SocketPath))
|
||||
|
||||
servers = append(servers, domainSocket)
|
||||
wg.Add(1)
|
||||
s.Logf("Serving export xlsx at unix://%s", s.SocketPath)
|
||||
go func(l net.Listener) {
|
||||
defer wg.Done()
|
||||
if err := domainSocket.Serve(l); err != nil && err != http.ErrServerClosed {
|
||||
s.Fatalf("%v", err)
|
||||
}
|
||||
s.Logf("Stopped serving export xlsx at unix://%s", s.SocketPath)
|
||||
}(s.domainSocketL)
|
||||
}
|
||||
|
||||
if s.hasScheme(schemeHTTP) {
|
||||
httpServer := new(http.Server)
|
||||
httpServer.MaxHeaderBytes = int(s.MaxHeaderSize)
|
||||
httpServer.ReadTimeout = s.ReadTimeout
|
||||
httpServer.WriteTimeout = s.WriteTimeout
|
||||
httpServer.SetKeepAlivesEnabled(int64(s.KeepAlive) > 0)
|
||||
if s.ListenLimit > 0 {
|
||||
s.httpServerL = netutil.LimitListener(s.httpServerL, s.ListenLimit)
|
||||
}
|
||||
|
||||
if int64(s.CleanupTimeout) > 0 {
|
||||
httpServer.IdleTimeout = s.CleanupTimeout
|
||||
}
|
||||
|
||||
httpServer.Handler = s.handler
|
||||
|
||||
configureServer(httpServer, "http", s.httpServerL.Addr().String())
|
||||
|
||||
servers = append(servers, httpServer)
|
||||
wg.Add(1)
|
||||
s.Logf("Serving export xlsx at http://%s", s.httpServerL.Addr())
|
||||
go func(l net.Listener) {
|
||||
defer wg.Done()
|
||||
if err := httpServer.Serve(l); err != nil && err != http.ErrServerClosed {
|
||||
s.Fatalf("%v", err)
|
||||
}
|
||||
s.Logf("Stopped serving export xlsx at http://%s", l.Addr())
|
||||
}(s.httpServerL)
|
||||
}
|
||||
|
||||
if s.hasScheme(schemeHTTPS) {
|
||||
httpsServer := new(http.Server)
|
||||
httpsServer.MaxHeaderBytes = int(s.MaxHeaderSize)
|
||||
httpsServer.ReadTimeout = s.TLSReadTimeout
|
||||
httpsServer.WriteTimeout = s.TLSWriteTimeout
|
||||
httpsServer.SetKeepAlivesEnabled(int64(s.TLSKeepAlive) > 0)
|
||||
if s.TLSListenLimit > 0 {
|
||||
s.httpsServerL = netutil.LimitListener(s.httpsServerL, s.TLSListenLimit)
|
||||
}
|
||||
if int64(s.CleanupTimeout) > 0 {
|
||||
httpsServer.IdleTimeout = s.CleanupTimeout
|
||||
}
|
||||
httpsServer.Handler = s.handler
|
||||
|
||||
// Inspired by https://blog.bracebin.com/achieving-perfect-ssl-labs-score-with-go
|
||||
httpsServer.TLSConfig = &tls.Config{
|
||||
// Causes servers to use Go's default ciphersuite preferences,
|
||||
// which are tuned to avoid attacks. Does nothing on clients.
|
||||
PreferServerCipherSuites: true,
|
||||
// Only use curves which have assembly implementations
|
||||
// https://github.com/golang/go/tree/master/src/crypto/elliptic
|
||||
CurvePreferences: []tls.CurveID{tls.CurveP256},
|
||||
// Use modern tls mode https://wiki.mozilla.org/Security/Server_Side_TLS#Modern_compatibility
|
||||
NextProtos: []string{"h2", "http/1.1"},
|
||||
// https://www.owasp.org/index.php/Transport_Layer_Protection_Cheat_Sheet#Rule_-_Only_Support_Strong_Protocols
|
||||
MinVersion: tls.VersionTLS12,
|
||||
// These ciphersuites support Forward Secrecy: https://en.wikipedia.org/wiki/Forward_secrecy
|
||||
CipherSuites: []uint16{
|
||||
tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
|
||||
tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
|
||||
tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
|
||||
tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
|
||||
tls.TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305,
|
||||
tls.TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305,
|
||||
},
|
||||
}
|
||||
|
||||
// build standard config from server options
|
||||
if s.TLSCertificate != "" && s.TLSCertificateKey != "" {
|
||||
httpsServer.TLSConfig.Certificates = make([]tls.Certificate, 1)
|
||||
httpsServer.TLSConfig.Certificates[0], err = tls.LoadX509KeyPair(string(s.TLSCertificate), string(s.TLSCertificateKey))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if s.TLSCACertificate != "" {
|
||||
// include specified CA certificate
|
||||
caCert, caCertErr := ioutil.ReadFile(string(s.TLSCACertificate))
|
||||
if caCertErr != nil {
|
||||
return caCertErr
|
||||
}
|
||||
caCertPool := x509.NewCertPool()
|
||||
ok := caCertPool.AppendCertsFromPEM(caCert)
|
||||
if !ok {
|
||||
return fmt.Errorf("cannot parse CA certificate")
|
||||
}
|
||||
httpsServer.TLSConfig.ClientCAs = caCertPool
|
||||
httpsServer.TLSConfig.ClientAuth = tls.RequireAndVerifyClientCert
|
||||
}
|
||||
|
||||
// call custom TLS configurator
|
||||
configureTLS(httpsServer.TLSConfig)
|
||||
|
||||
if len(httpsServer.TLSConfig.Certificates) == 0 && httpsServer.TLSConfig.GetCertificate == nil {
|
||||
// after standard and custom config are passed, this ends up with no certificate
|
||||
if s.TLSCertificate == "" {
|
||||
if s.TLSCertificateKey == "" {
|
||||
s.Fatalf("the required flags `--tls-certificate` and `--tls-key` were not specified")
|
||||
}
|
||||
s.Fatalf("the required flag `--tls-certificate` was not specified")
|
||||
}
|
||||
if s.TLSCertificateKey == "" {
|
||||
s.Fatalf("the required flag `--tls-key` was not specified")
|
||||
}
|
||||
// this happens with a wrong custom TLS configurator
|
||||
s.Fatalf("no certificate was configured for TLS")
|
||||
}
|
||||
|
||||
configureServer(httpsServer, "https", s.httpsServerL.Addr().String())
|
||||
|
||||
servers = append(servers, httpsServer)
|
||||
wg.Add(1)
|
||||
s.Logf("Serving export xlsx at https://%s", s.httpsServerL.Addr())
|
||||
go func(l net.Listener) {
|
||||
defer wg.Done()
|
||||
if err := httpsServer.Serve(l); err != nil && err != http.ErrServerClosed {
|
||||
s.Fatalf("%v", err)
|
||||
}
|
||||
s.Logf("Stopped serving export xlsx at https://%s", l.Addr())
|
||||
}(tls.NewListener(s.httpsServerL, httpsServer.TLSConfig))
|
||||
}
|
||||
|
||||
wg.Add(1)
|
||||
go s.handleShutdown(wg, &servers)
|
||||
|
||||
wg.Wait()
|
||||
return nil
|
||||
}
|
||||
|
||||
// Listen creates the listeners for the server
|
||||
func (s *Server) Listen() error {
|
||||
if s.hasListeners { // already done this
|
||||
return nil
|
||||
}
|
||||
|
||||
if s.hasScheme(schemeHTTPS) {
|
||||
// Use http host if https host wasn't defined
|
||||
if s.TLSHost == "" {
|
||||
s.TLSHost = s.Host
|
||||
}
|
||||
// Use http listen limit if https listen limit wasn't defined
|
||||
if s.TLSListenLimit == 0 {
|
||||
s.TLSListenLimit = s.ListenLimit
|
||||
}
|
||||
// Use http tcp keep alive if https tcp keep alive wasn't defined
|
||||
if int64(s.TLSKeepAlive) == 0 {
|
||||
s.TLSKeepAlive = s.KeepAlive
|
||||
}
|
||||
// Use http read timeout if https read timeout wasn't defined
|
||||
if int64(s.TLSReadTimeout) == 0 {
|
||||
s.TLSReadTimeout = s.ReadTimeout
|
||||
}
|
||||
// Use http write timeout if https write timeout wasn't defined
|
||||
if int64(s.TLSWriteTimeout) == 0 {
|
||||
s.TLSWriteTimeout = s.WriteTimeout
|
||||
}
|
||||
}
|
||||
|
||||
if s.hasScheme(schemeUnix) {
|
||||
domSockListener, err := net.Listen("unix", string(s.SocketPath))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
s.domainSocketL = domSockListener
|
||||
}
|
||||
|
||||
if s.hasScheme(schemeHTTP) {
|
||||
listener, err := net.Listen("tcp", net.JoinHostPort(s.Host, strconv.Itoa(s.Port)))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
h, p, err := swag.SplitHostPort(listener.Addr().String())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
s.Host = h
|
||||
s.Port = p
|
||||
s.httpServerL = listener
|
||||
}
|
||||
|
||||
if s.hasScheme(schemeHTTPS) {
|
||||
tlsListener, err := net.Listen("tcp", net.JoinHostPort(s.TLSHost, strconv.Itoa(s.TLSPort)))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
sh, sp, err := swag.SplitHostPort(tlsListener.Addr().String())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
s.TLSHost = sh
|
||||
s.TLSPort = sp
|
||||
s.httpsServerL = tlsListener
|
||||
}
|
||||
|
||||
s.hasListeners = true
|
||||
return nil
|
||||
}
|
||||
|
||||
// Shutdown server and clean up resources
|
||||
func (s *Server) Shutdown() error {
|
||||
if atomic.CompareAndSwapInt32(&s.shuttingDown, 0, 1) {
|
||||
close(s.shutdown)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Server) handleShutdown(wg *sync.WaitGroup, serversPtr *[]*http.Server) {
|
||||
// wg.Done must occur last, after s.api.ServerShutdown()
|
||||
// (to preserve old behaviour)
|
||||
defer wg.Done()
|
||||
|
||||
<-s.shutdown
|
||||
|
||||
servers := *serversPtr
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.TODO(), s.GracefulTimeout)
|
||||
defer cancel()
|
||||
|
||||
// first execute the pre-shutdown hook
|
||||
s.api.PreServerShutdown()
|
||||
|
||||
shutdownChan := make(chan bool)
|
||||
for i := range servers {
|
||||
server := servers[i]
|
||||
go func() {
|
||||
var success bool
|
||||
defer func() {
|
||||
shutdownChan <- success
|
||||
}()
|
||||
if err := server.Shutdown(ctx); err != nil {
|
||||
// Error from closing listeners, or context timeout:
|
||||
s.Logf("HTTP server Shutdown: %v", err)
|
||||
} else {
|
||||
success = true
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
// Wait until all listeners have successfully shut down before calling ServerShutdown
|
||||
success := true
|
||||
for range servers {
|
||||
success = success && <-shutdownChan
|
||||
}
|
||||
if success {
|
||||
s.api.ServerShutdown()
|
||||
}
|
||||
}
|
||||
|
||||
// GetHandler returns a handler useful for testing
|
||||
func (s *Server) GetHandler() http.Handler {
|
||||
return s.handler
|
||||
}
|
||||
|
||||
// SetHandler allows for setting a http handler on this server
|
||||
func (s *Server) SetHandler(handler http.Handler) {
|
||||
s.handler = handler
|
||||
}
|
||||
|
||||
// UnixListener returns the domain socket listener
|
||||
func (s *Server) UnixListener() (net.Listener, error) {
|
||||
if !s.hasListeners {
|
||||
if err := s.Listen(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return s.domainSocketL, nil
|
||||
}
|
||||
|
||||
// HTTPListener returns the http listener
|
||||
func (s *Server) HTTPListener() (net.Listener, error) {
|
||||
if !s.hasListeners {
|
||||
if err := s.Listen(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return s.httpServerL, nil
|
||||
}
|
||||
|
||||
// TLSListener returns the https listener
|
||||
func (s *Server) TLSListener() (net.Listener, error) {
|
||||
if !s.hasListeners {
|
||||
if err := s.Listen(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return s.httpsServerL, nil
|
||||
}
|
||||
|
||||
func handleInterrupt(once *sync.Once, s *Server) {
|
||||
once.Do(func() {
|
||||
for range s.interrupt {
|
||||
if s.interrupted {
|
||||
s.Logf("Server already shutting down")
|
||||
continue
|
||||
}
|
||||
s.interrupted = true
|
||||
s.Logf("Shutting down... ")
|
||||
operations.HandleShutdown()
|
||||
if err := s.Shutdown(); err != nil {
|
||||
s.Logf("HTTP server Shutdown: %v", err)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func signalNotify(interrupt chan<- os.Signal) {
|
||||
signal.Notify(interrupt, syscall.SIGINT, syscall.SIGTERM)
|
||||
}
|
Reference in New Issue
Block a user