Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for customToken #173

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions api/ingest-tokens.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,26 +81,30 @@ func toIngestToken(data ingestTokenData) *IngestToken {
}
}

// Deprecated: Should no longer be used. https://github.com/CrowdStrike/logscale-go-api-client-example
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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be a breaking change for Go API users.

Could we rename it to AddV2 and call it from ingest_tokens_add.go and Add() to keep the signature? @SaaldjorMike

func (i *IngestTokens) Add(repositoryName string, tokenName string, parser string) (*IngestToken, error) {
	return i.AddV2(repositoryName, tokenName, parser, "")
}

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
Token string
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)
Expand Down
11 changes: 8 additions & 3 deletions cmd/humioctl/ingest_tokens_add.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import (
)

func newIngestTokensAddCmd() *cobra.Command {
var parserName string
var parserName string
var customToken string

cmd := &cobra.Command{
Use: "add [flags] <repo> <token-name>",
Expand All @@ -30,21 +31,25 @@ 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)
},
}

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
}