Compare commits

...

5 Commits

Author SHA1 Message Date
guardrails[bot]
26a7186f40 docs(readme): add GuardRails badge 2018-10-19 09:53:10 +00:00
Manfred Touron
41eeb364f8 Ignore some circle CI tests 2018-08-18 23:43:48 +02:00
Manfred Touron
a22f8f0b7b Merge pull request #58 from adyxax/master
Added `hostgroup update` and `usergroup update` features
2018-04-06 09:34:17 +02:00
Julien Dessaux
bd1c3609a7 Added hostgroup update and usergroup update features 2018-04-05 16:25:43 +02:00
Manfred Touron
c5e75df64f Post-release version bump 2018-04-02 22:36:07 +02:00
5 changed files with 98 additions and 8 deletions

View File

@@ -1,5 +1,9 @@
# Changelog
## master (unreleased)
* No entry
## v1.8.0 (2018-04-02)
* The default created user now has the same username as the user starting sshportal (was hardcoded "admin")

View File

@@ -414,4 +414,4 @@ This is totally experimental for now, so please file issues to let me know what
## License
[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fmoul%2Fsshportal.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fmoul%2Fsshportal?ref=badge_large)
[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fmoul%2Fsshportal.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fmoul%2Fsshportal?ref=badge_large) [![GuardRails badge](https://badges.production.guardrails.io/moul/sshportal.svg)](https://www.guardrails.io)

View File

@@ -64,12 +64,16 @@ ssh sshportal -l admin config backup --indent --ignore-events > backup-2
diff backup-1.clean backup-2.clean
)
# bastion
ssh sshportal -l admin host create --name=testserver toto@testserver:2222
out="$(ssh sshportal -l testserver echo hello | head -n 1)"
test "$out" = '{"User":"toto","Environ":null,"Command":["echo","hello"]}'
if [ "$CIRCLECI" = "true" ]; then
echo "Strage behavior with cross-container communication on CircleCI, skipping some tests..."
else
# bastion
ssh sshportal -l admin host create --name=testserver toto@testserver:2222
out="$(ssh sshportal -l testserver echo hello | head -n 1)"
test "$out" = '{"User":"toto","Environ":null,"Command":["echo","hello"]}'
out="$(TEST_A=1 TEST_B=2 TEST_C=3 TEST_D=4 TEST_E=5 TEST_F=6 TEST_G=7 TEST_H=8 TEST_I=9 ssh sshportal -l testserver echo hello | head -n 1)"
test "$out" = '{"User":"toto","Environ":["TEST_A=1","TEST_B=2","TEST_C=3","TEST_D=4","TEST_E=5","TEST_F=6","TEST_G=7","TEST_H=8","TEST_I=9"],"Command":["echo","hello"]}'
out="$(TEST_A=1 TEST_B=2 TEST_C=3 TEST_D=4 TEST_E=5 TEST_F=6 TEST_G=7 TEST_H=8 TEST_I=9 ssh sshportal -l testserver echo hello | head -n 1)"
test "$out" = '{"User":"toto","Environ":["TEST_A=1","TEST_B=2","TEST_C=3","TEST_D=4","TEST_E=5","TEST_F=6","TEST_G=7","TEST_H=8","TEST_I=9"],"Command":["echo","hello"]}'
fi
# TODO: test more cases (forwards, scp, sftp, interactive, pty, stdin, exit code, ...)

View File

@@ -18,7 +18,7 @@ import (
var (
// Version should be updated by hand at each release
Version = "1.8.0"
Version = "1.8.0+dev"
// GitTag will be overwritten automatically by the build system
GitTag string
// GitSha will be overwritten automatically by the build system

View File

@@ -1095,6 +1095,47 @@ GLOBAL OPTIONS:
return HostGroupsByIdentifiers(db, c.Args()).Delete(&HostGroup{}).Error
},
}, {
Name: "update",
Usage: "Updates a host group",
ArgsUsage: "HOSTGROUP...",
Flags: []cli.Flag{
cli.StringFlag{Name: "name", Usage: "Assigns a new name to the host group"},
cli.StringFlag{Name: "comment", Usage: "Adds a comment"},
},
Action: func(c *cli.Context) error {
if c.NArg() < 1 {
return cli.ShowSubcommandHelp(c)
}
if err := myself.CheckRoles([]string{"admin"}); err != nil {
return err
}
var hostgroups []HostGroup
if err := HostGroupsByIdentifiers(db, c.Args()).Find(&hostgroups).Error; err != nil {
return err
}
if len(hostgroups) > 1 && c.String("name") != "" {
return fmt.Errorf("cannot set --name when editing multiple hostgroups at once")
}
tx := db.Begin()
for _, hostgroup := range hostgroups {
model := tx.Model(&hostgroup)
// simple fields
for _, fieldname := range []string{"name", "comment"} {
if c.String(fieldname) != "" {
if err := model.Update(fieldname, c.String(fieldname)).Error; err != nil {
tx.Rollback()
return err
}
}
}
}
return tx.Commit().Error
},
},
},
}, {
@@ -1804,6 +1845,47 @@ GLOBAL OPTIONS:
return UserGroupsByIdentifiers(db, c.Args()).Delete(&UserGroup{}).Error
},
}, {
Name: "update",
Usage: "Updates a user group",
ArgsUsage: "USERGROUP...",
Flags: []cli.Flag{
cli.StringFlag{Name: "name", Usage: "Assigns a new name to the user group"},
cli.StringFlag{Name: "comment", Usage: "Adds a comment"},
},
Action: func(c *cli.Context) error {
if c.NArg() < 1 {
return cli.ShowSubcommandHelp(c)
}
if err := myself.CheckRoles([]string{"admin"}); err != nil {
return err
}
var usergroups []UserGroup
if err := UserGroupsByIdentifiers(db, c.Args()).Find(&usergroups).Error; err != nil {
return err
}
if len(usergroups) > 1 && c.String("name") != "" {
return fmt.Errorf("cannot set --name when editing multiple usergroups at once")
}
tx := db.Begin()
for _, usergroup := range usergroups {
model := tx.Model(&usergroup)
// simple fields
for _, fieldname := range []string{"name", "comment"} {
if c.String(fieldname) != "" {
if err := model.Update(fieldname, c.String(fieldname)).Error; err != nil {
tx.Rollback()
return err
}
}
}
}
return tx.Commit().Error
},
},
},
}, {