Skip to content

Commit

Permalink
Fix ingest token usage
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasmalkmus committed Mar 5, 2021
1 parent 46e9793 commit 50b710a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 16 deletions.
31 changes: 18 additions & 13 deletions cmd/axiom/ingest/ingest.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/spf13/cobra"

"github.com/axiomhq/cli/internal/cmdutil"
"github.com/axiomhq/cli/internal/config"
"github.com/axiomhq/cli/pkg/utils"
)

Expand Down Expand Up @@ -139,22 +140,26 @@ func complete(ctx context.Context, opts *options) error {
return nil
}

client, err := opts.Client()
if err != nil {
return err
}
// Just fetch a list of available datasets if a Personal Access Token is
// used.
datasetNames := make([]string, 0)
if dep, ok := opts.Config.GetActiveDeployment(); ok && dep.TokenType == config.Personal {
client, err := opts.Client()
if err != nil {
return err
}

stop := opts.IO.StartActivityIndicator()
datasets, err := client.Datasets.List(ctx)
if err != nil {
stop := opts.IO.StartActivityIndicator()
datasets, err := client.Datasets.List(ctx)
if err != nil {
stop()
return err
}
stop()
return err
}
stop()

datasetNames := make([]string, len(datasets))
for i, dataset := range datasets {
datasetNames[i] = dataset.Name
for i, dataset := range datasets {
datasetNames[i] = dataset.Name
}
}

return survey.AskOne(&survey.Select{
Expand Down
5 changes: 5 additions & 0 deletions internal/cmdutil/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ func NeedsValidDeployment(f *Factory, alias *string) RunFunc {
// available on the configured deployment.
func NeedsDatasets(f *Factory) RunFunc {
return func(cmd *cobra.Command, _ []string) error {
// Skip if token is not a Personal Access Token.
if dep, ok := f.Config.GetActiveDeployment(); ok && dep.TokenType != config.Personal {
return nil
}

client, err := f.Client()
if err != nil {
return err
Expand Down
6 changes: 3 additions & 3 deletions pkg/iofmt/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ type RowBuilderFunc func(TableRowBuilder, int)
// and footer builder functions are optional. The length of the slice must be
// given.
func FormatToTable(io *terminal.IO, l int, header, footer HeaderBuilderFunc, contentRow RowBuilderFunc) error {
tp := terminal.NewTablePrinter(io)

if contentRow == nil {
return errors.New("missing table row content")
}

tp := terminal.NewTablePrinter(io)

if header != nil {
header(io.Out(), tp)

Expand All @@ -49,7 +49,7 @@ func FormatToTable(io *terminal.IO, l int, header, footer HeaderBuilderFunc, con
tp.EndRow()
}
} else {
contentRow(tp, -1)
contentRow(tp, 0)
tp.EndRow()
}

Expand Down

0 comments on commit 50b710a

Please sign in to comment.