Skip to content

Commit

Permalink
archerctl: added filter for project_id and service_id
Browse files Browse the repository at this point in the history
  • Loading branch information
notandy committed Jun 20, 2024
1 parent c1ed9f8 commit d693351
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
21 changes: 15 additions & 6 deletions internal/client/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,25 +37,34 @@ var EndpointOptions struct {
}

type EndpointList struct {
Tags []string `long:"tags" description:"List endpoints which have all given tag(s) (repeat option for multiple tags)"`
AnyTags []string `long:"any-tags" description:"List endpoints which have any given tag(s) (repeat option for multiple tags)"`
NotTags []string `long:"not-tags" description:"Exclude endpoints which have all given tag(s) (repeat option for multiple tags)"`
NotAnyTags []string `long:"not-any-tags" description:"Exclude endpoints which have any given tag(s) (repeat option for multiple tags)"`
Tags []string `long:"tags" description:"List endpoints which have all given tag(s) (repeat option for multiple tags)"`
AnyTags []string `long:"any-tags" description:"List endpoints which have any given tag(s) (repeat option for multiple tags)"`
NotTags []string `long:"not-tags" description:"Exclude endpoints which have all given tag(s) (repeat option for multiple tags)"`
NotAnyTags []string `long:"not-any-tags" description:"Exclude endpoints which have any given tag(s) (repeat option for multiple tags)"`
Project *string `short:"p" long:"project" description:"List endpoints in the given project (ID)"`
Service *strfmt.UUID `short:"s" long:"service" description:"List endpoints for the given service (ID)"`
}

func (*EndpointList) Execute(_ []string) error {
params := endpoint.NewGetEndpointParams().
WithTags(EndpointOptions.EndpointList.Tags).
WithTagsAny(EndpointOptions.EndpointList.AnyTags).
WithNotTags(EndpointOptions.EndpointList.NotTags).
WithNotTagsAny(EndpointOptions.EndpointList.NotAnyTags)
WithNotTagsAny(EndpointOptions.EndpointList.NotAnyTags).
WithProjectID(EndpointOptions.EndpointList.Project)
resp, err := ArcherClient.Endpoint.GetEndpoint(params, nil)
if err != nil {
return err
}

DefaultColumns = []string{"id", "name", "service_id", "target.port", "status", "ip_address"}
return WriteTable(resp.GetPayload().Items)
var items []*models.Endpoint
for _, item := range resp.GetPayload().Items {
if EndpointOptions.EndpointList.Service == nil || item.ServiceID == *EndpointOptions.EndpointList.Service {
items = append(items, item)
}
}
return WriteTable(items)
}

type EndpointShow struct {
Expand Down
12 changes: 7 additions & 5 deletions internal/client/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,20 @@ var ServiceOptions struct {
}

type ServiceList struct {
Tags []string `long:"tags" description:"List endpoints which have all given tag(s) (repeat option for multiple tags)"`
AnyTags []string `long:"any-tags" description:"List endpoints which have any given tag(s) (repeat option for multiple tags)"`
NotTags []string `long:"not-tags" description:"Exclude endpoints which have all given tag(s) (repeat option for multiple tags)"`
NotAnyTags []string `long:"not-any-tags" description:"Exclude endpoints which have any given tag(s) (repeat option for multiple tags)"`
Tags []string `long:"tags" description:"List services which have all given tag(s) (repeat option for multiple tags)"`
AnyTags []string `long:"any-tags" description:"List services which have any given tag(s) (repeat option for multiple tags)"`
NotTags []string `long:"not-tags" description:"Exclude services which have all given tag(s) (repeat option for multiple tags)"`
NotAnyTags []string `long:"not-any-tags" description:"Exclude services which have any given tag(s) (repeat option for multiple tags)"`
Project *string `short:"p" long:"project" description:"List services in the given project (ID)"`
}

func (*ServiceList) Execute(_ []string) error {
params := service.NewGetServiceParams().
WithTags(ServiceOptions.ServiceList.Tags).
WithTagsAny(ServiceOptions.ServiceList.AnyTags).
WithNotTags(ServiceOptions.ServiceList.NotTags).
WithNotTagsAny(ServiceOptions.ServiceList.NotAnyTags)
WithNotTagsAny(ServiceOptions.ServiceList.NotAnyTags).
WithProjectID(ServiceOptions.ServiceList.Project)
resp, err := ArcherClient.Service.GetService(params, nil)
if err != nil {
return err
Expand Down

0 comments on commit d693351

Please sign in to comment.