Skip to content

Commit

Permalink
Add enable/disable automatic search option on repos and view (#163)
Browse files Browse the repository at this point in the history
  • Loading branch information
brads-au committed Jun 25, 2024
1 parent 9b1db68 commit 284f2be
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 17 deletions.
17 changes: 17 additions & 0 deletions api/repositories.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type Repository struct {
StorageRetentionSizeGB float64 `graphql:"storageSizeBasedRetention"`
SpaceUsed int64 `graphql:"compressedByteSize"`
S3ArchivingConfiguration humiographql.S3Configuration `graphql:"s3ArchivingConfiguration"`
AutomaticSearch bool `graphql:"automaticSearch"`
}

func (c *Client) Repositories() *Repositories { return &Repositories{client: c} }
Expand Down Expand Up @@ -329,3 +330,19 @@ func (r *Repositories) UpdateS3ArchivingConfiguration(name string, bucket string

return r.client.Mutate(&mutation, variables)
}

func (r *Repositories) UpdateAutomaticSearch(name string, automaticSearch bool) error {
var mutation struct {
SetAutomaticSearching struct {
// We have to make a selection, so just take __typename
Typename graphql.String `graphql:"__typename"`
} `graphql:"setAutomaticSearching(name: $name, automaticSearch: $automaticSearch)"`
}

variables := map[string]interface{}{
"name": graphql.String(name),
"automaticSearch": graphql.Boolean(automaticSearch),
}

return r.client.Mutate(&mutation, variables)
}
42 changes: 31 additions & 11 deletions api/views.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ type ViewConnection struct {
}

type ViewQueryData struct {
Name string
Description string
ViewInfo struct {
Name string
Description string
AutomaticSearch bool
ViewInfo struct {
Connections []struct {
Repository struct{ Name string }
Filter string
Expand All @@ -28,9 +29,10 @@ type ViewQueryData struct {
}

type View struct {
Name string
Description string
Connections []ViewConnection
Name string
Description string
Connections []ViewConnection
AutomaticSearch bool
}

func (c *Client) Views() *Views { return &Views{client: c} }
Expand Down Expand Up @@ -58,17 +60,19 @@ func (c *Views) Get(name string) (*View, error) {
}

view := View{
Name: query.Result.Name,
Description: query.Result.Description,
Connections: connections,
Name: query.Result.Name,
Description: query.Result.Description,
Connections: connections,
AutomaticSearch: query.Result.AutomaticSearch,
}

return &view, nil
}

type ViewListItem struct {
Name string
Typename string `graphql:"__typename"`
Name string
Typename string `graphql:"__typename"`
AutomaticSearch bool
}

func (c *Views) List() ([]ViewListItem, error) {
Expand Down Expand Up @@ -152,3 +156,19 @@ func (c *Views) UpdateDescription(name string, description string) error {

return c.client.Mutate(&mutation, variables)
}

func (c *Views) UpdateAutomaticSearch(name string, automaticSearch bool) error {
var mutation struct {
SetAutomaticSearching struct {
// We have to make a selection, so just take __typename
Typename graphql.String `graphql:"__typename"`
} `graphql:"setAutomaticSearching(name: $name, automaticSearch: $automaticSearch)"`
}

variables := map[string]interface{}{
"name": graphql.String(name),
"automaticSearch": graphql.Boolean(automaticSearch),
}

return c.client.Mutate(&mutation, variables)
}
1 change: 1 addition & 0 deletions cmd/humioctl/repos.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func printRepoDetailsTable(cmd *cobra.Command, repo api.Repository) {
{format.String("S3 Archiving Bucket"), format.String(repo.S3ArchivingConfiguration.Bucket)},
{format.String("S3 Archiving Region"), format.String(repo.S3ArchivingConfiguration.Region)},
{format.String("S3 Archiving Format"), format.String(repo.S3ArchivingConfiguration.Format)},
{format.String("Automatic Search"), format.Bool(repo.AutomaticSearch)},
}

printDetailsTable(cmd, details)
Expand Down
17 changes: 15 additions & 2 deletions cmd/humioctl/repos_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
)

func newReposUpdateCmd() *cobra.Command {
var allowDataDeletionFlag, enableS3ArchivingFlag, disableS3ArchivingFlag bool
var allowDataDeletionFlag, enableS3ArchivingFlag, disableS3ArchivingFlag, enableAutomaticSearchFlag, disableAutomaticSearchFlag bool
var descriptionFlag, s3ArchivingBucketFlag, s3ArchivingRegionFlag, s3ArchivingFormatFlag stringPtrFlag
var retentionTimeFlag, ingestSizeBasedRetentionFlag, storageSizeBasedRetentionFlag float64PtrFlag

Expand All @@ -34,7 +34,8 @@ func newReposUpdateCmd() *cobra.Command {
client := NewApiClient(cmd)

if descriptionFlag.value == nil && retentionTimeFlag.value == nil && ingestSizeBasedRetentionFlag.value == nil && storageSizeBasedRetentionFlag.value == nil &&
!enableS3ArchivingFlag && !disableS3ArchivingFlag && s3ArchivingBucketFlag.value == nil && s3ArchivingRegionFlag.value == nil && s3ArchivingFormatFlag.value == nil {
!enableS3ArchivingFlag && !disableS3ArchivingFlag && s3ArchivingBucketFlag.value == nil && s3ArchivingRegionFlag.value == nil && s3ArchivingFormatFlag.value == nil &&
!enableAutomaticSearchFlag && !disableAutomaticSearchFlag {
exitOnError(cmd, fmt.Errorf("you must specify at least one flag to update"), "Nothing specified to update")
}
if descriptionFlag.value != nil {
Expand Down Expand Up @@ -69,6 +70,15 @@ func newReposUpdateCmd() *cobra.Command {
exitOnError(cmd, err, "Error enabling S3 archiving")
}

if disableAutomaticSearchFlag {
err := client.Repositories().UpdateAutomaticSearch(repoName, false)
exitOnError(cmd, err, "Error disabling automatic search")
}
if enableAutomaticSearchFlag {
err := client.Repositories().UpdateAutomaticSearch(repoName, true)
exitOnError(cmd, err, "Error enabling automatic search")
}

fmt.Fprintf(cmd.OutOrStdout(), "Successfully updated repository %q\n", repoName)
},
}
Expand All @@ -85,6 +95,9 @@ func newReposUpdateCmd() *cobra.Command {
cmd.Flags().Var(&s3ArchivingFormatFlag, "s3-archiving-format", "The S3 archiving format to be used for S3 Archiving. Formats: RAW, NDJSON")
cmd.MarkFlagsRequiredTogether("s3-archiving-bucket", "s3-archiving-region", "s3-archiving-format")
cmd.MarkFlagsMutuallyExclusive("enable-s3-archiving", "disable-s3-archiving")
cmd.Flags().BoolVar(&enableAutomaticSearchFlag, "enable-automatic-search", false, "Enable automatic search for the repository.")
cmd.Flags().BoolVar(&disableAutomaticSearchFlag, "disable-automatic-search", false, "Disable automatic search for the repository.")
cmd.MarkFlagsMutuallyExclusive("enable-automatic-search", "disable-automatic-search")

return &cmd
}
8 changes: 5 additions & 3 deletions cmd/humioctl/views_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,16 @@ func newViewsListCmd() *cobra.Command {
for i, view := range views {
if viewOnly {
if view.Typename == viewTypeName {
rows[i] = []format.Value{format.String(view.Name)}
rows[i] = []format.Value{format.String(view.Name),
format.Bool(view.AutomaticSearch)}
}
} else {
rows[i] = []format.Value{format.String(view.Name)}
rows[i] = []format.Value{format.String(view.Name),
format.Bool(view.AutomaticSearch)}
}
}

printOverviewTable(cmd, []string{"Name"}, rows)
printOverviewTable(cmd, []string{"Name", "Automatic Search"}, rows)
},
}

Expand Down
16 changes: 15 additions & 1 deletion cmd/humioctl/views_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import (
)

func newViewsUpdateCmd() *cobra.Command {
var enableAutomaticSearchFlag, disableAutomaticSearchFlag bool

connsFlag := []string{}
connections := []api.ViewConnectionInput{}
description := ""
Expand All @@ -47,7 +49,7 @@ namely "repo1" and "repo2":
viewName := args[0]
client := NewApiClient(cmd)

if len(connsFlag) == 0 && description == "" {
if len(connsFlag) == 0 && description == "" && !enableAutomaticSearchFlag && !disableAutomaticSearchFlag {
exitOnError(cmd, fmt.Errorf("you must specify at least one flag"), "Nothing specified to update")
}

Expand Down Expand Up @@ -77,12 +79,24 @@ namely "repo1" and "repo2":
exitOnError(cmd, err, "Error updating view description")
}

if disableAutomaticSearchFlag {
err := client.Views().UpdateAutomaticSearch(viewName, false)
exitOnError(cmd, err, "Error disabling automatic search")
}
if enableAutomaticSearchFlag {
err := client.Views().UpdateAutomaticSearch(viewName, true)
exitOnError(cmd, err, "Error enabling automatic search")
}

fmt.Fprintf(cmd.OutOrStdout(), "Successfully updated view %q\n", viewName)
},
}

cmd.Flags().StringArrayVar(&connsFlag, "connection", connsFlag, "Sets a repository connection with the chosen filter in format: <repoName>=<filterString>")
cmd.Flags().StringVar(&description, "description", description, "Sets the view description.")
cmd.Flags().BoolVar(&enableAutomaticSearchFlag, "enable-automatic-search", false, "Enable automatic search for the view.")
cmd.Flags().BoolVar(&disableAutomaticSearchFlag, "disable-automatic-search", false, "Disable automatic search for the view.")
cmd.MarkFlagsMutuallyExclusive("enable-automatic-search", "disable-automatic-search")

return &cmd
}

0 comments on commit 284f2be

Please sign in to comment.