grpcschema

package
v1.6.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 8, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Command = &cobra.Command{
	Use:   "grpc",
	Short: "Inspect gRPC services and protobuf schemas",
	Run: func(cmd *cobra.Command, args []string) {
		err := cmd.Help()
		if err != nil {
			timber.Fatal(err, "output help")
		}
	},
}
View Source
var SchemaCommand = &cobra.Command{
	Use:     "schema [symbol...]",
	Aliases: []string{"proto", "protobuf", "protoset"},
	Short:   "Output protobuf descriptors using gRPC reflection",
	Args:    cobra.ArbitraryArgs,
	Run: func(cmd *cobra.Command, args []string) {
		if !slices.Contains(formats, flags.format) {
			timber.FatalMsg("invalid output format", timber.A("value", flags.format), timber.A("valid", strings.Join(formats, "|")))
		}

		config, err := conf.Read()
		if err != nil {
			app.Fatal(err, "failed to read configuration file")
		}

		client, err := auth.SynthientClient(config)
		if err != nil {
			app.Fatal(err, "failed to create synthient client")
		}
		config.ApplyToClient(&client)

		endpoint := strings.TrimSpace(flags.endpoint)
		if endpoint == "" {
			endpoint = config.GRPCEndpoint(synthient.DefaultGRPCEndpoint)
		}

		ctx, cancel := context.WithTimeout(context.Background(), flags.timeout)
		defer cancel()

		result, err := client.GRPCSchema(ctx, &synthient.GRPCSchemaOptions{
			Endpoint:          endpoint,
			Plaintext:         flags.plaintext,
			IncludeReflection: flags.includeReflection,
			Symbols:           args,
		})
		if err != nil {
			if msg := synthient.ExplainGRPCError(err); msg != "" {
				timber.FatalMsg(msg)
			}
			app.Fatal(err, "failed to fetch protobuf schemas")
		}

		out, closeOut := output.Open(flags.output)
		defer closeOut()

		switch flags.format {
		case "text":
			writeText(out, output.NewStyles(out), result)
		case "json":
			data, err := protojson.MarshalOptions{Multiline: true, Indent: "  "}.Marshal(result.DescriptorSet)
			if err != nil {
				app.Fatal(err, "failed to marshal descriptor set")
			}
			writeBytes(out, append(data, '\n'))
		case "binpb":
			data, err := proto.Marshal(result.DescriptorSet)
			if err != nil {
				app.Fatal(err, "failed to marshal descriptor set")
			}
			writeBytes(out, data)
		}
	},
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL