MCPcopy Index your code
hub / github.com/cloudquery/cloudquery / testConnection

Function testConnection

cli/cmd/test_connection.go:42–197  ·  view source on GitHub ↗
(cmd *cobra.Command, args []string)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 11

SpecRegistryToPluginFunction · 0.85
filterPluginEnvFunction · 0.85
enrichClientErrorFunction · 0.85
testPluginConnectionFunction · 0.85
PrintfMethod · 0.80
ErrorfMethod · 0.80
AddSecretEnvMethod · 0.80
RegistryInferredMethod · 0.80
PrintlnMethod · 0.80
VersionStringMethod · 0.80
ContextMethod · 0.45

Tested by

no test coverage detected