From 61df7eadab16109a1543b1404552e03725886954 Mon Sep 17 00:00:00 2001 From: Tuan Anh Nguyen Date: Fri, 30 Aug 2024 11:59:50 +0700 Subject: [PATCH] add support for customToken Signed-off-by: Tuan Anh Nguyen --- api/ingest-tokens.go | 9 +++++++-- cmd/humioctl/ingest_tokens_add.go | 11 ++++++++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/api/ingest-tokens.go b/api/ingest-tokens.go index 28da72ac..ce0d9310 100644 --- a/api/ingest-tokens.go +++ b/api/ingest-tokens.go @@ -76,17 +76,22 @@ func toIngestToken(data ingestTokenData) *IngestToken { } } -func (i *IngestTokens) Add(repositoryName string, tokenName string, parser string) (*IngestToken, error) { +func (i *IngestTokens) Add(repositoryName string, tokenName string, parser string, customToken string) (*IngestToken, error) { variables := map[string]interface{}{ "tokenName": graphql.String(tokenName), "repositoryName": graphql.String(repositoryName), "parser": (*graphql.String)(nil), + "customToken": (*graphql.String)(nil), } if parser != "" { variables["parser"] = graphql.String(parser) } + if customToken != "" { + variables["customToken"] = graphql.String(customToken) + } + var mutation struct { IngestToken struct { Name string @@ -94,7 +99,7 @@ func (i *IngestTokens) Add(repositoryName string, tokenName string, parser strin Parser struct { Name string } - } `graphql:"addIngestTokenV3(input: { repositoryName: $repositoryName, name: $tokenName, parser: $parser})"` + } `graphql:"addIngestTokenV3(input: { repositoryName: $repositoryName, name: $tokenName, parser: $parser, customToken: $customToken})"` } err := i.client.Mutate(&mutation, variables) diff --git a/cmd/humioctl/ingest_tokens_add.go b/cmd/humioctl/ingest_tokens_add.go index cb171487..fb477cbd 100644 --- a/cmd/humioctl/ingest_tokens_add.go +++ b/cmd/humioctl/ingest_tokens_add.go @@ -21,7 +21,8 @@ import ( ) func newIngestTokensAddCmd() *cobra.Command { - var parserName string + var parserName string + var customToken string cmd := &cobra.Command{ Use: "add [flags] ", @@ -30,14 +31,17 @@ func newIngestTokensAddCmd() *cobra.Command { You can associate a parser with the ingest token using the --parser flag. Assigning a parser will make all data sent to Humio using this ingest token -use the assigned parser at ingest time.`, +use the assigned parser at ingest time. + +You can specify a custom token value using the --custom-token flag. +This requires special permissions and root privileges`, Args: cobra.ExactArgs(2), Run: func(cmd *cobra.Command, args []string) { repo := args[0] name := args[1] client := NewApiClient(cmd) - ingestToken, err := client.IngestTokens().Add(repo, name, parserName) + ingestToken, err := client.IngestTokens().Add(repo, name, parserName, customToken) exitOnError(cmd, err, "Error adding ingest token") fmt.Fprintf(cmd.OutOrStdout(), "Added ingest token %q with parser %q: %s\n", ingestToken.Name, valueOrEmpty(ingestToken.AssignedParser), ingestToken.Token) @@ -45,6 +49,7 @@ use the assigned parser at ingest time.`, } cmd.Flags().StringVarP(&parserName, "parser", "p", "", "Assigns the a parser to the ingest token.") + cmd.Flags().StringVarP(&customToken, "custom-token", "", "", "Specifies a custom value for the ingest token.") return cmd }