-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- added proper logic using goqu plugin for sanitising input - updated example to make it work
- Loading branch information
Showing
15 changed files
with
289 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package analyse | ||
|
||
import ( | ||
"github.com/salsadigitalauorg/shipshape/pkg/breach" | ||
"github.com/salsadigitalauorg/shipshape/pkg/data" | ||
"github.com/salsadigitalauorg/shipshape/pkg/fact" | ||
"github.com/salsadigitalauorg/shipshape/pkg/result" | ||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
type NotEmpty struct { | ||
// Common fields. | ||
Id string `yaml:"name"` | ||
Description string `yaml:"description"` | ||
InputName string `yaml:"input"` | ||
Severity string `yaml:"severity"` | ||
breach.BreachTemplate `yaml:"breach-format"` | ||
Result result.Result | ||
input fact.Facter | ||
} | ||
|
||
//go:generate go run ../../cmd/gen.go analyse-plugin --plugin=NotEmpty --package=analyse | ||
|
||
func init() { | ||
Registry["not-empty"] = func(id string) Analyser { return NewNotEmpty(id) } | ||
} | ||
|
||
func (p *NotEmpty) PluginName() string { | ||
return "not-empty" | ||
} | ||
|
||
func (p *NotEmpty) Analyse() { | ||
log.WithField("input-format", p.input.GetFormat()).Debug("analysing") | ||
switch p.input.GetFormat() { | ||
case fact.FormatMapNestedString: | ||
inputData := data.AsNestedStringMap(p.input.GetData()) | ||
log.WithField("inputData", inputData).Debug("analysing") | ||
if len(inputData) == 0 { | ||
return | ||
} | ||
for k, kvs := range inputData { | ||
for subK, v := range kvs { | ||
breach.EvaluateTemplate(p, &breach.KeyValueBreach{ | ||
Key: k, | ||
ValueLabel: subK, | ||
Value: v, | ||
}) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,54 @@ | ||
package connection | ||
|
||
import ( | ||
"errors" | ||
"database/sql" | ||
"fmt" | ||
|
||
"github.com/salsadigitalauorg/shipshape/pkg/command" | ||
"github.com/doug-martin/goqu/v9" | ||
_ "github.com/doug-martin/goqu/v9/dialect/mysql" | ||
"github.com/go-sql-driver/mysql" | ||
) | ||
|
||
type Mysql struct { | ||
// Common fields. | ||
Name string `yaml:"name"` | ||
|
||
// Plugin fields. | ||
Connection string `yaml:"connection"` | ||
DbHost string `yaml:"db-host"` | ||
DbPort string `yaml:"db-port"` | ||
DbUser string `yaml:"db-user"` | ||
DbPass string `yaml:"db-pass"` | ||
DbName string `yaml:"db-name"` | ||
Query string `yaml:"query"` | ||
Host string `yaml:"host"` | ||
Port string `yaml:"port"` | ||
User string `yaml:"user"` | ||
Password string `yaml:"password"` | ||
Database string `yaml:"database"` | ||
Db *goqu.Database | ||
} | ||
|
||
//go:generate go run ../../cmd/gen.go connection-plugin --plugin=Mysql | ||
|
||
func init() { | ||
Registry["mysql"] = func(n string) Connectioner { return &Mysql{Name: n} } | ||
} | ||
|
||
func (p *Mysql) PluginName() string { | ||
return "mysql" | ||
} | ||
|
||
func (p *Mysql) Run() ([]byte, error) { | ||
cmdArgs := []string{ | ||
"-h", p.DbHost, | ||
"-P", p.DbPort, | ||
"-u", p.DbUser, | ||
"-p" + p.DbPass, | ||
p.DbName, | ||
p.Query, | ||
if p.Port == "" { | ||
p.Port = "3306" | ||
} | ||
|
||
cn := GetInstance(p.Connection) | ||
if cn != nil { | ||
// We currently only support docker connections. | ||
if cn.PluginName() != "docker.exec" { | ||
return nil, errors.New("unsupported connection") | ||
} | ||
cfg := mysql.NewConfig() | ||
cfg.User = p.User | ||
cfg.Passwd = p.Password | ||
cfg.Net = "tcp" | ||
cfg.Addr = fmt.Sprintf("%s:%s", p.Host, p.Port) | ||
cfg.DBName = p.Database | ||
|
||
dockerConn := cn.(*DockerExec) | ||
dockerConn.Command = append([]string{"mysql"}, cmdArgs...) | ||
return dockerConn.Run() | ||
mysqlDb, err := sql.Open("mysql", cfg.FormatDSN()) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return command.ShellCommander("mysql", cmdArgs...).Output() | ||
dialect := goqu.Dialect("mysql") | ||
p.Db = dialect.DB(mysqlDb) | ||
return nil, nil | ||
} |
Oops, something went wrong.