Skip to content

Commit

Permalink
upgraded dependencies; reorganized commands to add more explain com…
Browse files Browse the repository at this point in the history
…mands
  • Loading branch information
joreiche committed Feb 7, 2024
1 parent 4e92af1 commit 750d06c
Show file tree
Hide file tree
Showing 11 changed files with 152 additions and 163 deletions.
13 changes: 5 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@ module github.com/threagile/threagile
go 1.20

require (
github.com/chzyer/readline v1.5.1
github.com/gin-gonic/gin v1.9.1
github.com/google/uuid v1.6.0
github.com/jung-kurt/gofpdf v1.16.2
github.com/mattn/go-shellwords v1.0.12
github.com/mpvl/unique v0.0.0-20150818121801-cbe035fff7de
github.com/spf13/pflag v1.0.5
github.com/wcharczuk/go-chart v2.0.1+incompatible
github.com/xuri/excelize/v2 v2.8.0
golang.org/x/crypto v0.18.0
golang.org/x/crypto v0.19.0
gopkg.in/yaml.v3 v3.0.1
)

require (
github.com/buildkite/shellwords v0.0.0-20180315110454-59467a9b8e10 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect
github.com/chzyer/readline v1.5.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-playground/locales v0.14.1 // indirect
Expand All @@ -26,8 +26,7 @@ require (
github.com/google/go-cmp v0.5.9 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/leodido/go-urn v1.3.0 // indirect
github.com/mattn/go-shellwords v1.0.12 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
Expand All @@ -36,10 +35,8 @@ require (
github.com/richardlehane/mscfb v1.0.4 // indirect
github.com/richardlehane/msoleps v1.0.3 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
golang.org/x/mod v0.14.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/sys v0.17.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/tools v0.17.0 // indirect
)

require (
Expand Down
21 changes: 8 additions & 13 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ github.com/akedrou/textdiff v0.0.0-20230423230343-2ebdcebdccc1/go.mod h1:PJwvxBp
github.com/blend/go-sdk v1.20220411.3 h1:GFV4/FQX5UzXLPwWV03gP811pj7B8J2sbuq+GJQofXc=
github.com/blend/go-sdk v1.20220411.3/go.mod h1:7lnH8fTi6U4i1fArEXRyOIY2E1X4MALg09qsQqY1+ak=
github.com/boombuler/barcode v1.0.0/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8=
github.com/buildkite/shellwords v0.0.0-20180315110454-59467a9b8e10 h1:XwHQ5xDtYPdtBbVPyRO6UZoWZe8/mbKUb076f8x7RvI=
github.com/buildkite/shellwords v0.0.0-20180315110454-59467a9b8e10/go.mod h1:gv0DYOzHEsKgo31lTCDGauIg4DTTGn41Bzp+t3wSOlk=
github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM=
github.com/bytedance/sonic v1.10.0-rc/go.mod h1:ElCzW+ufi8qKqNW0FY314xriJhyJhuoJ3gFZdAHF7NM=
github.com/bytedance/sonic v1.10.2 h1:GQebETVBxYB7JGWJtLBi07OVzWwt+8dWA00gEVW2ZFE=
Expand All @@ -16,9 +14,11 @@ github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d/go.mod h1:8EPpV
github.com/chenzhuoyu/iasm v0.9.0/go.mod h1:Xjy2NpN3h7aUqeqM+woSuuvxmIe6+DDsiNLIrkAmYog=
github.com/chenzhuoyu/iasm v0.9.1 h1:tUHQJXo3NhBqw6s33wkGn9SP3bvrWLdlVIJ3hQBL7P0=
github.com/chenzhuoyu/iasm v0.9.1/go.mod h1:Xjy2NpN3h7aUqeqM+woSuuvxmIe6+DDsiNLIrkAmYog=
github.com/chzyer/logex v1.2.1 h1:XHDu3E6q+gdHgsdTPH6ImJMIp436vR6MPtH8gP05QzM=
github.com/chzyer/logex v1.2.1/go.mod h1:JLbx6lG2kDbNRFnfkgvh4eRJRPX1QCoOIWomwysCBrQ=
github.com/chzyer/readline v1.5.1 h1:upd/6fQk4src78LMRzh5vItIt361/o4uq553V8B5sGI=
github.com/chzyer/readline v1.5.1/go.mod h1:Eh+b79XXUwfKfcPLepksvw2tcLE/Ct21YObkaSkeBlk=
github.com/chzyer/test v1.0.0 h1:p3BQDXSxOhOG0P9z6/hGnII4LGiEPOYBhs8asl/fC04=
github.com/chzyer/test v1.0.0/go.mod h1:2JlltgoNkt4TW/z9V/IzDdFaMTM2JPIi26O1pF38GC8=
github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand All @@ -35,8 +35,6 @@ github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/o
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
github.com/go-playground/validator/v10 v10.16.0 h1:x+plE831WK4vaKHO/jpgUGsvLKIqRRkz6M78GuJAfGE=
github.com/go-playground/validator/v10 v10.16.0/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU=
github.com/go-playground/validator/v10 v10.17.0 h1:SmVVlfAOtlZncTxRuinDPomC2DkXJ4E5T9gDA0AIH74=
github.com/go-playground/validator/v10 v10.17.0/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU=
github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
Expand All @@ -46,8 +44,6 @@ github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGw
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/uuid v1.5.0 h1:1p67kYwdtXjb0gL0BPiP1Av9wiZPo5A8z2cWkTZ+eyU=
github.com/google/uuid v1.5.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
Expand All @@ -61,10 +57,10 @@ github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa02
github.com/klauspost/cpuid/v2 v2.2.6 h1:ndNyv040zDGIDh8thGkXYjnFtiN02M1PVVF+JE/48xc=
github.com/klauspost/cpuid/v2 v2.2.6/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws=
github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M=
github.com/leodido/go-urn v1.2.4 h1:XlAE/cm/ms7TE/VMVoduSpNBoyc2dOxHs5MZSwAN63Q=
github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4=
github.com/leodido/go-urn v1.3.0 h1:jX8FDLfW4ThVXctBNZ+3cIWnCSnrACDV73r76dy0aQQ=
github.com/leodido/go-urn v1.3.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-shellwords v1.0.12 h1:M2zGm7EW6UQJvDeQxo4T51eKPurbeFbe8WtebGE2xrk=
Expand Down Expand Up @@ -108,7 +104,6 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
Expand All @@ -134,14 +129,14 @@ golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5y
golang.org/x/crypto v0.12.0/go.mod h1:NF0Gs7EO5K4qLn+Ylc+fih8BSTeIjAP05siRnAh98yw=
golang.org/x/crypto v0.18.0 h1:PGVlW0xEltQnzFZ55hkuX5+KLyrMYhHld1YHO4AKcdc=
golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg=
golang.org/x/crypto v0.19.0 h1:ENy+Az/9Y1vSrlrvBSyna3PITt4tiZLf7sgCjZBX7Wo=
golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU=
golang.org/x/image v0.0.0-20190910094157-69e4b8554b2a/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/image v0.11.0/go.mod h1:bglhjqbqVuEb9e9+eNR45Jfu7D+T4Qan+NhQk8Ck2P8=
golang.org/x/image v0.15.0 h1:kOELfmgrmJlw4Cdb7g/QGuB3CvDrXbqEIww/pNtNBm8=
golang.org/x/image v0.15.0/go.mod h1:HUYqC05R2ZcZ3ejNQsIHQDQiwWM4JBqmm6MKANTp4LE=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.14.0 h1:dGoOF9QVLYng8IHTm7BAyWqCqSheQ5pYWGhzW00YJr0=
golang.org/x/mod v0.14.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
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-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
Expand All @@ -165,6 +160,8 @@ golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU=
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y=
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
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/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
Expand All @@ -182,8 +179,6 @@ golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGm
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
golang.org/x/tools v0.17.0 h1:FvmRgNOcs3kOa+T20R1uhfP9F6HgG2mfxDv1vrx1Htc=
golang.org/x/tools v0.17.0/go.mod h1:xsh6VxdV005rRVaS6SSAf9oiAqljS7UZUacMZ8Bnsps=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I=
google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/threagile/threagile/pkg/examples"
)

func (what *Threagile) initExamples() *Threagile {
func (what *Threagile) initCreate() *Threagile {
what.rootCmd.AddCommand(&cobra.Command{
Use: common.CreateExampleModelCommand,
Short: "Create example threagile model",
Expand Down
41 changes: 41 additions & 0 deletions internal/threagile/execute.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
Copyright © 2023 NAME HERE <EMAIL ADDRESS>
*/

package threagile

import (
"fmt"

"github.com/spf13/cobra"

"github.com/threagile/threagile/pkg/common"
"github.com/threagile/threagile/pkg/macros"
"github.com/threagile/threagile/pkg/model"
)

func (what *Threagile) initExecute() *Threagile {
what.rootCmd.AddCommand(&cobra.Command{
Use: "execute-model-macro",
Short: "Execute model macro",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
cfg := what.readConfig(cmd, what.buildTimestamp)
progressReporter := common.DefaultProgressReporter{Verbose: cfg.Verbose}

r, err := model.ReadAndAnalyzeModel(*cfg, progressReporter)
if err != nil {
return fmt.Errorf("unable to read and analyze model: %v", err)
}

macrosId := args[0]
err = macros.ExecuteModelMacro(r.ModelInput, cfg.InputFile, r.ParsedModel, macrosId)
if err != nil {
return fmt.Errorf("unable to execute model macro: %v", err)
}
return nil
},
})

return what
}
75 changes: 35 additions & 40 deletions internal/threagile/macros.go → internal/threagile/explain.go
Original file line number Diff line number Diff line change
@@ -1,44 +1,43 @@
/*
Copyright © 2023 NAME HERE <EMAIL ADDRESS>
*/

package threagile

import (
"fmt"

"github.com/spf13/cobra"

"github.com/threagile/threagile/pkg/common"
"github.com/threagile/threagile/pkg/docs"
"github.com/threagile/threagile/pkg/macros"
"github.com/threagile/threagile/pkg/model"
"github.com/threagile/threagile/pkg/security/risks"
"github.com/threagile/threagile/pkg/security/types"
"strings"
)

func (what *Threagile) initMacros() *Threagile {
func (what *Threagile) initExplain() *Threagile {
what.rootCmd.AddCommand(&cobra.Command{
Use: common.ListModelMacrosCommand,
Short: "Print model macros",
Run: func(cmd *cobra.Command, args []string) {
Use: common.ExplainRiskRulesCommand,
Short: "Detailed explanation of all the risk rules",
RunE: func(cmd *cobra.Command, args []string) error {
cmd.Println(docs.Logo + "\n\n" + fmt.Sprintf(docs.VersionText, what.buildTimestamp))
cmd.Println("The following model macros are available (can be extended via custom model macros):")
cmd.Println()
/* TODO finish plugin stuff
cmd.Println("Custom model macros:")
for _, macros := range macros.ListCustomMacros() {
details := macros.GetMacroDetails()
cmd.Println(details.ID, "-->", details.Title)
}
cmd.Println("Explanation for risk rules:")
cmd.Println()
*/
cmd.Println("----------------------")
cmd.Println("Built-in model macros:")
cmd.Println("Custom risk rules:")
cmd.Println("----------------------")
for _, macros := range macros.ListBuiltInMacros() {
details := macros.GetMacroDetails()
cmd.Println(details.ID, "-->", details.Title)
customRiskRules := model.LoadCustomRiskRules(strings.Split(what.flags.customRiskRulesPluginFlag, ","), common.DefaultProgressReporter{Verbose: what.flags.verboseFlag})
for _, customRule := range customRiskRules {
cmd.Printf("%v: %v\n", customRule.Category.Id, customRule.Category.Description)
}
cmd.Println()
cmd.Println("--------------------")
cmd.Println("Built-in risk rules:")
cmd.Println("--------------------")
cmd.Println()
for _, rule := range risks.GetBuiltInRiskRules() {
cmd.Printf("%v: %v\n", rule.Category().Id, rule.Category().Description)
}
cmd.Println()

return nil
},
})

Expand Down Expand Up @@ -70,24 +69,20 @@ func (what *Threagile) initMacros() *Threagile {
})

what.rootCmd.AddCommand(&cobra.Command{
Use: "execute-model-macro",
Short: "Execute model macro",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
cfg := what.readConfig(cmd, what.buildTimestamp)
progressReporter := common.DefaultProgressReporter{Verbose: cfg.Verbose}

r, err := model.ReadAndAnalyzeModel(*cfg, progressReporter)
if err != nil {
return fmt.Errorf("unable to read and analyze model: %v", err)
}

macrosId := args[0]
err = macros.ExecuteModelMacro(r.ModelInput, cfg.InputFile, r.ParsedModel, macrosId)
if err != nil {
return fmt.Errorf("unable to execute model macro: %v", err)
Use: common.ExplainTypesCommand,
Short: "Print type information (enum values to be used in models)",
Run: func(cmd *cobra.Command, args []string) {
cmd.Println(docs.Logo + "\n\n" + fmt.Sprintf(docs.VersionText, what.buildTimestamp))
fmt.Println("Explanation for the types:")
cmd.Println()
cmd.Println("The following types are available (can be extended for custom rules):")
cmd.Println()
for name, values := range types.GetBuiltinTypeValues() {
cmd.Println(name)
for _, candidate := range values {
cmd.Printf("\t %v: %v\n", candidate, candidate.Explain())
}
}
return nil
},
})

Expand Down
62 changes: 35 additions & 27 deletions internal/threagile/rules.go → internal/threagile/list.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
/*
Copyright © 2023 NAME HERE <EMAIL ADDRESS>
*/

package threagile

import (
"fmt"
"strings"

"github.com/spf13/cobra"
"github.com/threagile/threagile/pkg/common"
"github.com/threagile/threagile/pkg/docs"
"github.com/threagile/threagile/pkg/macros"
"github.com/threagile/threagile/pkg/model"
"github.com/threagile/threagile/pkg/security/risks"

"github.com/spf13/cobra"

"github.com/threagile/threagile/pkg/docs"
"github.com/threagile/threagile/pkg/security/types"
"strings"
)

func (what *Threagile) initRules() *Threagile {
func (what *Threagile) initList() *Threagile {
what.rootCmd.AddCommand(&cobra.Command{
Use: common.ListRiskRulesCommand,
Short: "Print available risk rules",
Expand Down Expand Up @@ -46,30 +41,43 @@ func (what *Threagile) initRules() *Threagile {
})

what.rootCmd.AddCommand(&cobra.Command{
Use: common.ExplainRiskRulesCommand,
Short: "Detailed explanation of all the risk rules",
RunE: func(cmd *cobra.Command, args []string) error {
Use: common.ListModelMacrosCommand,
Short: "Print model macros",
Run: func(cmd *cobra.Command, args []string) {
cmd.Println(docs.Logo + "\n\n" + fmt.Sprintf(docs.VersionText, what.buildTimestamp))
cmd.Println("Explanation for risk rules:")
cmd.Println("The following model macros are available (can be extended via custom model macros):")
cmd.Println()
/* TODO finish plugin stuff
cmd.Println("Custom model macros:")
for _, macros := range macros.ListCustomMacros() {
details := macros.GetMacroDetails()
cmd.Println(details.ID, "-->", details.Title)
}
cmd.Println()
*/
cmd.Println("----------------------")
cmd.Println("Custom risk rules:")
cmd.Println("Built-in model macros:")
cmd.Println("----------------------")
customRiskRules := model.LoadCustomRiskRules(strings.Split(what.flags.customRiskRulesPluginFlag, ","), common.DefaultProgressReporter{Verbose: what.flags.verboseFlag})
for _, customRule := range customRiskRules {
cmd.Printf("%v: %v\n", customRule.Category.Id, customRule.Category.Description)
for _, macros := range macros.ListBuiltInMacros() {
details := macros.GetMacroDetails()
cmd.Println(details.ID, "-->", details.Title)
}
cmd.Println()
cmd.Println("--------------------")
cmd.Println("Built-in risk rules:")
cmd.Println("--------------------")
},
})

what.rootCmd.AddCommand(&cobra.Command{
Use: common.ListTypesCommand,
Short: "Print type information (enum values to be used in models)",
Run: func(cmd *cobra.Command, args []string) {
cmd.Println(docs.Logo + "\n\n" + fmt.Sprintf(docs.VersionText, what.buildTimestamp))
cmd.Println()
for _, rule := range risks.GetBuiltInRiskRules() {
cmd.Printf("%v: %v\n", rule.Category().Id, rule.Category().Description)
}
cmd.Println()

return nil
cmd.Println("The following types are available (can be extended for custom rules):")
cmd.Println()
for name, values := range types.GetBuiltinTypeValues() {
cmd.Println(fmt.Sprintf(" %v: %v", name, values))
}
},
})

Expand Down
Loading

0 comments on commit 750d06c

Please sign in to comment.