Skip to content
Merged
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
4 changes: 0 additions & 4 deletions cmd/support-bundle/commands/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,9 @@ func NewGenerateCommand(supportBundle *cli.Cli) *cobra.Command {
cmd.Flags().BoolVarP(&opts.ConfirmUploadPrompt, "yes-upload", "u", false, "If present, auto-confirm any upload prompts")
cmd.Flags().BoolVar(&opts.DenyUploadPrompt, "no-upload", false, "If present, auto-deny any upload prompts")

cmd.Flags().StringVar(&opts.CustomerID, "customer-id", "", "Replicated Customer ID")
cmd.Flags().StringVar(&opts.Endpoint, "endpoint", cli.DefaultEndpoint, "Customer API Endpoint")

cmd.Flags().StringVar(&opts.ChannelID, "channel-id", "", "Replicated ChannelID to attempt to get a collector definition from")
cmd.Flags().StringVar(&opts.WatchID, "watch-id", "", "Replicated WatchID to attempt to get a collector definition from")

cmd.Flags().MarkDeprecated("customer-id", "This argument is no longer supported. Consider using \"channel-id\"")

//--out - works, and its totally interactive and everything,
// and the bundle just gets dumped to stdout.
Expand Down
12 changes: 4 additions & 8 deletions pkg/analyze/analyze/analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ type Analyze struct {
Specs []string
SkipDefault bool
BundleRootSubpath string
CustomerID string // deprecated
ChannelID string
Endpoint string

Expand All @@ -60,7 +59,6 @@ func New(v *viper.Viper, logger log.Logger, resolver *resolver.Resolver, getter
Specs: v.GetStringSlice("spec"),
SkipDefault: v.GetBool("skip-default"),
BundleRootSubpath: v.GetString("bundle-root-subpath"),
CustomerID: v.GetString("customer-id"),
Endpoint: v.GetString("endpoint"),

// analyze
Expand Down Expand Up @@ -133,18 +131,16 @@ func (a *Analyze) Execute(ctx context.Context, bundlePath string) ([]api.Result,
}

input := resolver.Input{
Files: a.SpecFiles,
Inline: a.Specs,
CustomerID: a.CustomerID,
ChannelID: a.ChannelID,
Endpoint: endpoint,
Files: a.SpecFiles,
Inline: a.Specs,
ChannelID: a.ChannelID,
Endpoint: endpoint,
}
spec, err := a.Resolver.ResolveSpec(ctx, input, a.SkipDefault)
debug.Log(
"phase", "resolve",
"files", a.SpecFiles,
"inline", a.Specs,
"customerID", a.CustomerID,
"channelID", a.ChannelID,
"endpoint", endpoint,
"error", err)
Expand Down
3 changes: 0 additions & 3 deletions pkg/analyze/cli/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,6 @@ func RunCmd() *cobra.Command {
cmd.Flags().Bool("skip-default", false, "Skip the default analyze spec")
cmd.Flags().String("bundle-root-subpath", "", "The subpath within the archive at which the bundle root resides")

cmd.Flags().String("customer-id", "", "Replicated Customer ID")
cmd.Flags().MarkDeprecated("customer-id", "This argument is no longer supported. Consider using \"channel-id\"")

cmd.Flags().String("channel-id", "", "Replicated ChannelID to attempt to get a collector definition from")
cmd.Flags().String("endpoint", collectcli.DefaultEndpoint, "Endpoint to fetch collector definitions fom")

Expand Down
34 changes: 6 additions & 28 deletions pkg/analyze/resolver/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
multierror "github.com/hashicorp/go-multierror"
"github.com/pkg/errors"
"github.com/replicatedcom/support-bundle/pkg/analyze/api"
"github.com/replicatedcom/support-bundle/pkg/collect/graphql"
"github.com/replicatedcom/support-bundle/pkg/collect/marketapi"
"github.com/spf13/afero"
)

Expand All @@ -20,11 +20,10 @@ type Resolver struct {
}

type Input struct {
Files []string
Inline []string
CustomerID string
ChannelID string
Endpoint string
Files []string
Inline []string
ChannelID string
Endpoint string
}

func New(logger log.Logger, fs afero.Fs) *Resolver {
Expand Down Expand Up @@ -77,29 +76,8 @@ func (r *Resolver) ResolveSpec(ctx context.Context, input Input, skipDefault boo
}
}

if input.CustomerID != "" {
client := graphql.NewClient(input.Endpoint, http.DefaultClient)
inline, errI := client.GetCustomerSpec(input.CustomerID)
debug.Log(
"phase", "doc.customer.retrieve",
"error", errI)
if errI != nil {
err = multierror.Append(err, errors.Wrap(errI, "retrieve customer doc"))
} else {
doc, errI := api.DeserializeDoc([]byte(inline))
debug.Log(
"phase", "doc.customer.deserialize",
"error", errI)
if errI != nil {
err = multierror.Append(err, errors.Wrap(errI, "deserialize customer doc"))
} else {
resolved = mergeDocs(resolved, doc)
}
}
}

if input.ChannelID != "" {
client := graphql.NewClient(input.Endpoint, http.DefaultClient)
client := marketapi.NewClient(input.Endpoint, http.DefaultClient)
inline, errI := client.GetChannelSpec(input.ChannelID)
debug.Log(
"phase", "doc.channel.retrieve",
Expand Down
12 changes: 0 additions & 12 deletions pkg/collect/bundle/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,3 @@ func ChannelJSONSpec(channelID string) types.Spec {
},
}
}

func WatchJSONSpec(watchID string) types.Spec {
return types.Spec{
SpecShared: types.SpecShared{
Description: "Troubleshoot Watch Metadata",
OutputDir: "/",
},
WatchMeta: &types.WatchMetaOptions{
WatchID: watchID,
},
}
}
97 changes: 9 additions & 88 deletions pkg/collect/cli/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ import (

"github.com/pkg/errors"
"github.com/replicatedcom/support-bundle/pkg/collect/bundle"
"github.com/replicatedcom/support-bundle/pkg/collect/graphql"
"github.com/replicatedcom/support-bundle/pkg/collect/lifecycle"
"github.com/replicatedcom/support-bundle/pkg/collect/marketapi"
"github.com/replicatedcom/support-bundle/pkg/collect/spec"
"github.com/replicatedcom/support-bundle/pkg/collect/types"
"github.com/replicatedcom/support-bundle/pkg/util"
jww "github.com/spf13/jwalterweatherman"
)

const (
DefaultEndpoint = "https://pg.replicated.com/graphql"
DefaultEndpoint = "https://api.replicated.com/market"
DefaultGenerateTimeoutSeconds = 60
)

Expand All @@ -32,7 +32,6 @@ type GenerateOptions struct {
Quiet bool
Endpoint string
ChannelID string
WatchID string

CustomerID string // Deprecated

Expand All @@ -58,41 +57,20 @@ func (cli *Cli) Generate(opts GenerateOptions) error {
endpoint = DefaultEndpoint
}

graphQLClient := graphql.NewClient(endpoint, http.DefaultClient)
marketapiClient := marketapi.NewClient(endpoint, http.DefaultClient)
specs, err := resolveLocalSpecs(opts)
if err != nil {
return errors.Wrap(err, "resolve specs")
}

var customerDoc *types.Doc
var channelDoc *types.Doc
var watchDoc *types.Doc
expectedDefaultTasks := 1 // there is always at least 1 for the version

// this next if statement and included scope is deprecated
if opts.CustomerID != "" {
jww.DEBUG.Printf("Getting spec with customer id %s", opts.CustomerID)

customerDoc, err = getCustomerDoc(graphQLClient, opts.CustomerID)
if err != nil {
return errors.Wrap(err, "get customer specs")
}
specs = append(specs, customerDoc.Collect.V1...)
specs = append(specs, bundle.CustomerJSONSpec(opts.CustomerID))

if !opts.SkipDefault && types.GetUseDefaults(customerDoc.Lifecycle) {
defaultSpecs, err := bundle.DefaultSpecs()
if err != nil {
return errors.Wrap(err, "get default spec")
}
specs = append(specs, defaultSpecs...)
}

expectedDefaultTasks++
} else if opts.ChannelID != "" {
if opts.ChannelID != "" {
jww.DEBUG.Printf("Getting spec with channel id %s", opts.ChannelID)

channelDoc, err = getChannelDoc(graphQLClient, opts.ChannelID)
channelDoc, err = getChannelDoc(marketapiClient, opts.ChannelID)
if err != nil {
return errors.Wrap(err, "get channel spec")
}
Expand All @@ -107,26 +85,6 @@ func (cli *Cli) Generate(opts GenerateOptions) error {
specs = append(specs, defaultSpecs...)
}

expectedDefaultTasks++
} else if opts.WatchID != "" {
jww.DEBUG.Printf("Getting spec with watch id %s", opts.WatchID)

watchDoc, err = getWatchDoc(graphQLClient, opts.WatchID)
if err != nil {
return errors.Wrap(err, "get watch spec")
}

specs = append(specs, watchDoc.Collect.V1...)
specs = append(specs, bundle.WatchJSONSpec(opts.WatchID))

if !opts.SkipDefault && types.GetUseDefaults(watchDoc.Lifecycle) {
defaultSpecs, err := bundle.DefaultSpecs()
if err != nil {
return errors.Wrap(err, "get default spec")
}
specs = append(specs, defaultSpecs...)
}

expectedDefaultTasks++
}

Expand All @@ -144,30 +102,22 @@ func (cli *Cli) Generate(opts GenerateOptions) error {
BundleTasks: tasks,
GenerateTimeout: timeoutSeconds,
GenerateBundlePath: opts.BundlePath,
GraphQLClient: graphQLClient,
UploadCustomerID: opts.CustomerID,
MarketAPIClient: marketapiClient,
UploadChannelID: opts.ChannelID,
UploadWatchID: opts.WatchID,
ConfirmUploadPrompt: opts.ConfirmUploadPrompt,
DenyUploadPrompt: opts.DenyUploadPrompt,
Quiet: opts.Quiet,
}

lifecycleTasks := types.DefaultLifecycleTasks

if opts.WatchID != "" {
lifecycleTasks = types.DefaultWatchLifecycleTasks
}

if channelDoc != nil && channelDoc.Lifecycle != nil {
lifecycleTasks = channelDoc.Lifecycle
} else if customerDoc != nil && customerDoc.Lifecycle != nil {
lifecycleTasks = customerDoc.Lifecycle
} else if watchDoc != nil && watchDoc.Lifecycle != nil {
lifecycleTasks = watchDoc.Lifecycle
}

if opts.CustomerID == "" && opts.ChannelID == "" && opts.WatchID == "" {
if opts.CustomerID == "" && opts.ChannelID == "" {
lifecycleTasks = types.GenerateOnlyLifecycleTasks
}

Expand Down Expand Up @@ -219,23 +169,8 @@ func resolveLocalSpecs(opts GenerateOptions) ([]types.Spec, error) {
return specs, nil
}

// getCustomerDoc is deprecated
func getCustomerDoc(gqlClient *graphql.Client, customerID string) (*types.Doc, error) {
remoteSpecBody, err := gqlClient.GetCustomerSpec(customerID)
if err != nil {
return nil, errors.Wrap(err, "get remote spec")
}

customerDoc, err := spec.Unmarshal(remoteSpecBody)
if err != nil {
return nil, errors.Wrap(err, "parse customer spec")
}

return customerDoc, nil
}

func getChannelDoc(gqlClient *graphql.Client, channelID string) (*types.Doc, error) {
remoteSpecBody, err := gqlClient.GetChannelSpec(channelID)
func getChannelDoc(client *marketapi.Client, channelID string) (*types.Doc, error) {
remoteSpecBody, err := client.GetChannelSpec(channelID)
if err != nil {
return nil, errors.Wrap(err, "get remote spec")
}
Expand All @@ -247,17 +182,3 @@ func getChannelDoc(gqlClient *graphql.Client, channelID string) (*types.Doc, err

return channelDoc, nil
}

func getWatchDoc(gqlClient *graphql.Client, watchID string) (*types.Doc, error) {
remoteSpecBody, err := gqlClient.GetWatchSpec(watchID)
if err != nil {
return nil, errors.Wrap(err, "get remote spec")
}

watchDoc, err := spec.Unmarshal(remoteSpecBody)
if err != nil {
return nil, errors.Wrap(err, "parse watch spec")
}

return watchDoc, nil
}
Loading