Skip to content

Commit

Permalink
cleanup hzctl and move cmd and http client into hzctl pkg
Browse files Browse the repository at this point in the history
  • Loading branch information
jlarfors committed Mar 12, 2024
1 parent 0ab27c8 commit 4ac4179
Show file tree
Hide file tree
Showing 20 changed files with 225 additions and 318 deletions.
36 changes: 0 additions & 36 deletions cmd/hzctl/auth.go

This file was deleted.

20 changes: 0 additions & 20 deletions cmd/hzctl/context.go

This file was deleted.

29 changes: 0 additions & 29 deletions cmd/hzctl/context_list.go

This file was deleted.

7 changes: 7 additions & 0 deletions cmd/hzctl/hzctl.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package main

import "github.com/verifa/horizon/pkg/hzctl/cmd"

func main() {
cmd.Execute()
}
80 changes: 0 additions & 80 deletions cmd/hzctl/root.go

This file was deleted.

36 changes: 10 additions & 26 deletions pkg/hz/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,22 @@ type ObjectKeyer interface {

func validateKeyStrict(key ObjectKeyer) error {
var errs error
if key.ObjectGroup() == "" {
isEmptyOrStar := func(s string) bool {
return s == "" || s == "*"
}
if isEmptyOrStar(key.ObjectGroup()) {
errs = errors.Join(errs, fmt.Errorf("group is required"))
}
if key.ObjectVersion() == "" {
if isEmptyOrStar(key.ObjectVersion()) {
errs = errors.Join(errs, fmt.Errorf("version is required"))
}
if key.ObjectKind() == "" {
if isEmptyOrStar(key.ObjectKind()) {
errs = errors.Join(errs, fmt.Errorf("kind is required"))
}
if key.ObjectAccount() == "" {
if isEmptyOrStar(key.ObjectAccount()) {
errs = errors.Join(errs, fmt.Errorf("account is required"))
}
if key.ObjectName() == "" {
if isEmptyOrStar(key.ObjectName()) {
errs = errors.Join(errs, fmt.Errorf("name is required"))
}
return errs
Expand Down Expand Up @@ -92,27 +95,8 @@ func KeyFromObject(obj ObjectKeyer) string {
// This is useful when you want to ensure the key is concrete when performing
// operations on specific objects (e.g. get, create, apply).
func KeyFromObjectStrict(obj ObjectKeyer) (string, error) {
var errs error
isEmptyOrStar := func(s string) bool {
return s == "" || s == "*"
}
if isEmptyOrStar(obj.ObjectGroup()) {
errs = errors.Join(errs, fmt.Errorf("group is required"))
}
if isEmptyOrStar(obj.ObjectVersion()) {
errs = errors.Join(errs, fmt.Errorf("version is required"))
}
if isEmptyOrStar(obj.ObjectKind()) {
errs = errors.Join(errs, fmt.Errorf("kind is required"))
}
if isEmptyOrStar(obj.ObjectAccount()) {
errs = errors.Join(errs, fmt.Errorf("account is required"))
}
if isEmptyOrStar(obj.ObjectName()) {
errs = errors.Join(errs, fmt.Errorf("name is required"))
}
if errs != nil {
return "", errs
if err := validateKeyStrict(obj); err != nil {
return "", err
}
return KeyFromObject(obj), nil
}
Expand Down
Loading

0 comments on commit 4ac4179

Please sign in to comment.