Skip to content

Commit

Permalink
Merge pull request #137 from humio/mike/fix_token_rotation_deprecation
Browse files Browse the repository at this point in the history
Fix deprecated ingest token api usage
  • Loading branch information
SaaldjorMike committed Sep 21, 2023
2 parents 8009620 + 79afad9 commit 79e72c0
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions api/ingest-tokens.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,15 @@ func toIngestToken(data ingestTokenData) *IngestToken {
}
}

func (i *IngestTokens) Add(repositoryName string, tokenName string, parserName string) (*IngestToken, error) {
func (i *IngestTokens) Add(repositoryName string, tokenName string, parser string) (*IngestToken, error) {
variables := map[string]interface{}{
"tokenName": graphql.String(tokenName),
"repositoryName": graphql.String(repositoryName),
"parserName": (*graphql.String)(nil),
"parser": (*graphql.String)(nil),
}

if parserName != "" {
variables["parserName"] = graphql.String(parserName)
if parser != "" {
variables["parser"] = graphql.String(parser)
}

var mutation struct {
Expand All @@ -95,7 +95,7 @@ func (i *IngestTokens) Add(repositoryName string, tokenName string, parserName s
Parser struct {
Name string
}
} `graphql:"addIngestTokenV3(input: { repositoryName: $repositoryName, name: $tokenName, parser: $parserName})"`
} `graphql:"addIngestTokenV3(input: { repositoryName: $repositoryName, name: $tokenName, parser: $parser})"`
}

err := i.client.Mutate(&mutation, variables)
Expand All @@ -112,8 +112,8 @@ func (i *IngestTokens) Add(repositoryName string, tokenName string, parserName s
return &ingestToken, nil
}

func (i *IngestTokens) Update(repositoryName string, tokenName string, parserName string) (*IngestToken, error) {
if parserName == "" {
func (i *IngestTokens) Update(repositoryName string, tokenName string, parser string) (*IngestToken, error) {
if parser == "" {
var mutation struct {
Result struct {
// We have to make a selection, so just take __typename
Expand All @@ -135,17 +135,13 @@ func (i *IngestTokens) Update(repositoryName string, tokenName string, parserNam
Result struct {
// We have to make a selection, so just take __typename
Typename graphql.String `graphql:"__typename"`
} `graphql:"assignParserToIngestToken(input: { repositoryName: $repositoryName, tokenName: $tokenName, parserId: $parserId })"`
} `graphql:"assignParserToIngestTokenV2(input: { repositoryName: $repositoryName, tokenName: $tokenName, parser: $parser })"`
}

parser, err := i.client.Parsers().Get(repositoryName, parserName)
if err != nil {
return nil, fmt.Errorf("unable to look up parser id for parser name %q: %w", parserName, err)
}
variables := map[string]interface{}{
"tokenName": graphql.String(tokenName),
"repositoryName": graphql.String(repositoryName),
"parserId": graphql.String(parser.ID),
"parser": graphql.String(parser),
}

err2 := i.client.Mutate(&mutation, variables)
Expand Down

0 comments on commit 79e72c0

Please sign in to comment.