Skip to content

Commit

Permalink
Cleanup client packages code where it could send bad data and cause a…
Browse files Browse the repository at this point in the history
… crash. (#144)

Add disablerepo as an option to install/update as well. There are times you need to skip a broken repo definition.

Regen all protoes
  • Loading branch information
sfc-gh-jchacon authored Jun 28, 2022
1 parent 21f6ceb commit 6cd231d
Show file tree
Hide file tree
Showing 15 changed files with 180 additions and 114 deletions.
2 changes: 1 addition & 1 deletion proxy/proxy.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion proxy/testdata/testservice.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion services/ansible/ansible.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion services/exec/exec.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion services/fdb/fdb.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion services/healthcheck/healthcheck.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion services/localfile/localfile.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 25 additions & 4 deletions services/packages/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ type installCmd struct {
func (*installCmd) Name() string { return "install" }
func (*installCmd) Synopsis() string { return "Install a new package" }
func (*installCmd) Usage() string {
return `install:
return `install [--package_system=P] --name=X --version=Y [--repo=Z]:
Install a new package on the remote machine.
`
}
Expand All @@ -110,6 +110,15 @@ func (i *installCmd) Execute(ctx context.Context, f *flag.FlagSet, args ...inter
return subcommands.ExitFailure
}

if f.NArg() != 0 {
fmt.Fprintln(os.Stderr, "All options are set via flags")
return subcommands.ExitFailure
}
if i.name == "" || i.version == "" {
fmt.Fprintln(os.Stderr, "Both --name and --version must be filled in")
return subcommands.ExitFailure
}

state := args[0].(*util.ExecuteState)
c := pb.NewPackagesClientProxy(state.Conn)

Expand Down Expand Up @@ -152,7 +161,7 @@ type updateCmd struct {
func (*updateCmd) Name() string { return "update" }
func (*updateCmd) Synopsis() string { return "Update an existing package" }
func (*updateCmd) Usage() string {
return `update:
return `update [--package_system=P] --name=X --old_version=Y --new_version=Z [--repo=A]:
Update a package on the remote machine. The package must already be installed at a known version.
`
}
Expand All @@ -166,6 +175,10 @@ func (u *updateCmd) SetFlags(f *flag.FlagSet) {
}

func (u *updateCmd) Execute(ctx context.Context, f *flag.FlagSet, args ...interface{}) subcommands.ExitStatus {
if f.NArg() != 0 {
fmt.Fprintln(os.Stderr, "All options are set via flags")
return subcommands.ExitFailure
}
if u.name == "" || u.oldVersion == "" || u.newVersion == "" {
fmt.Fprintln(os.Stderr, "--name, --old_version and --new_version must be supplied")
return subcommands.ExitFailure
Expand Down Expand Up @@ -216,7 +229,7 @@ type listCmd struct {
func (*listCmd) Name() string { return "list" }
func (*listCmd) Synopsis() string { return "List installed packages" }
func (*listCmd) Usage() string {
return `list:
return `list [--package_system=P]:
List the installed packages on the remote machine.
`
}
Expand All @@ -226,6 +239,10 @@ func (l *listCmd) SetFlags(f *flag.FlagSet) {
}

func (l *listCmd) Execute(ctx context.Context, f *flag.FlagSet, args ...interface{}) subcommands.ExitStatus {
if f.NArg() != 0 {
fmt.Fprintln(os.Stderr, "All options are set via flags")
return subcommands.ExitFailure
}
ps, err := flagToType(l.packageSystem)
if err != nil {
fmt.Fprintf(os.Stderr, "Can't parse package system for --package-system: %s invalid\n", l.packageSystem)
Expand Down Expand Up @@ -270,7 +287,7 @@ type repoListCmd struct {
func (*repoListCmd) Name() string { return "repolist" }
func (*repoListCmd) Synopsis() string { return "List repos defined on machine" }
func (*repoListCmd) Usage() string {
return `repolist:
return `repolist [--package_system=P]:
List the repos defined on the remote machine.
`
}
Expand All @@ -281,6 +298,10 @@ func (r *repoListCmd) SetFlags(f *flag.FlagSet) {
}

func (r *repoListCmd) Execute(ctx context.Context, f *flag.FlagSet, args ...interface{}) subcommands.ExitStatus {
if f.NArg() != 0 {
fmt.Fprintln(os.Stderr, "All options are set via flags")
return subcommands.ExitFailure
}
ps, err := flagToType(r.packageSystem)
if err != nil {
fmt.Fprintf(os.Stderr, "Can't parse package system for --package-system: %s invalid\n", r.packageSystem)
Expand Down
Loading

0 comments on commit 6cd231d

Please sign in to comment.