(cmd *cobra.Command, args []string)
| 37 | } |
| 38 | |
| 39 | func installPlugin(cmd *cobra.Command, args []string) error { |
| 40 | cqDir, err := cmd.Flags().GetString("cq-dir") |
| 41 | if err != nil { |
| 42 | return err |
| 43 | } |
| 44 | |
| 45 | ctx := cmd.Context() |
| 46 | log.Info().Strs("args", args).Msg("Loading spec(s)") |
| 47 | fmt.Printf("Loading spec(s) from %s\n", strings.Join(args, ", ")) |
| 48 | specReader, err := specs.NewRelaxedSpecReader(args) |
| 49 | if err != nil { |
| 50 | return fmt.Errorf("failed to load spec(s) from %s. Error: %w", strings.Join(args, ", "), err) |
| 51 | } |
| 52 | sources := specReader.Sources |
| 53 | destinations := specReader.Destinations |
| 54 | transformers := specReader.Transformers |
| 55 | |
| 56 | authToken, err := auth.GetAuthTokenIfNeeded(log.Logger, sources, destinations, transformers) |
| 57 | if err != nil { |
| 58 | return fmt.Errorf("failed to get auth token: %w", err) |
| 59 | } |
| 60 | teamName, err := auth.GetTeamForToken(ctx, authToken) |
| 61 | if err != nil { |
| 62 | return fmt.Errorf("failed to get team name: %w", err) |
| 63 | } |
| 64 | |
| 65 | pluginVersionWarner, _ := managedplugin.NewPluginVersionWarner(log.Logger, authToken.Value) |
| 66 | specs.WarnOnOutdatedVersions(ctx, pluginVersionWarner, sources, destinations, transformers) |
| 67 | |
| 68 | opts := []managedplugin.Option{ |
| 69 | managedplugin.WithNoExec(), |
| 70 | managedplugin.WithLogger(log.Logger), |
| 71 | managedplugin.WithAuthToken(authToken.Value), |
| 72 | managedplugin.WithTeamName(teamName), |
| 73 | } |
| 74 | if logConsole { |
| 75 | opts = append(opts, managedplugin.WithNoProgress()) |
| 76 | } |
| 77 | if cqDir != "" { |
| 78 | opts = append(opts, managedplugin.WithDirectory(cqDir)) |
| 79 | } |
| 80 | if disableSentry { |
| 81 | opts = append(opts, managedplugin.WithNoSentry()) |
| 82 | } |
| 83 | |
| 84 | sourcePluginConfigs := make([]managedplugin.Config, len(sources)) |
| 85 | sourceRegInferred := make([]bool, len(sources)) |
| 86 | for i, source := range sources { |
| 87 | sourcePluginConfigs[i] = managedplugin.Config{ |
| 88 | Name: source.Name, |
| 89 | Version: source.Version, |
| 90 | Path: source.Path, |
| 91 | Registry: SpecRegistryToPlugin(source.Registry), |
| 92 | DockerAuth: source.DockerRegistryAuthToken, |
| 93 | } |
| 94 | sourceRegInferred[i] = source.RegistryInferred() |
| 95 | } |
| 96 | destinationPluginConfigs := make([]managedplugin.Config, len(destinations)) |
nothing calls this directly
no test coverage detected