refactor: expose generated code and client business logic to share with Kapacitor (#103)
* refactor: take clients out of internal * refactor: move stdio to pkg * Move internal/api to api * refactor: final changes for Kapacitor to access shared functionality * chore: regenerate mocks * fix: bad automated refactor * chore: extra formatting not caught by make fmt
This commit is contained in:
58
clients/bucket_schema/update.go
Normal file
58
clients/bucket_schema/update.go
Normal file
@ -0,0 +1,58 @@
|
||||
package bucket_schema
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/influxdata/influx-cli/v2/api"
|
||||
"github.com/influxdata/influx-cli/v2/clients"
|
||||
)
|
||||
|
||||
type UpdateParams struct {
|
||||
clients.OrgBucketParams
|
||||
Name string
|
||||
ID string
|
||||
Stdin io.Reader
|
||||
ColumnsFile string
|
||||
ColumnsFormat ColumnsFormat
|
||||
ExtendedOutput bool
|
||||
}
|
||||
|
||||
func (c Client) Update(ctx context.Context, params UpdateParams) error {
|
||||
cols, err := c.readColumns(params.Stdin, params.ColumnsFormat, params.ColumnsFile)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ids, err := c.resolveOrgBucketIds(ctx, params.OrgBucketParams)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var id string
|
||||
if params.ID == "" && params.Name == "" {
|
||||
return errors.New("measurement id or name required")
|
||||
} else if params.ID != "" {
|
||||
id = params.ID
|
||||
} else {
|
||||
id, err = c.resolveMeasurement(ctx, *ids, params.Name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
res, err := c.UpdateMeasurementSchema(ctx, ids.BucketID, id).
|
||||
OrgID(ids.OrgID).
|
||||
MeasurementSchemaUpdateRequest(api.MeasurementSchemaUpdateRequest{
|
||||
Columns: cols,
|
||||
}).
|
||||
Execute()
|
||||
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to update measurement schema: %w", err)
|
||||
}
|
||||
|
||||
return c.printMeasurements(ids.BucketID, []api.MeasurementSchema{res}, params.ExtendedOutput)
|
||||
}
|
||||
Reference in New Issue
Block a user