Skip to content

Commit

Permalink
Streamline the SUBSTREAMS_DOWNLOAD_ENDPOINT and other such env vars.
Browse files Browse the repository at this point in the history
Removed the flags that used to do the same thing.

Use the the functions instead of duping the functionality.
  • Loading branch information
Alexandre Bourget committed Nov 11, 2024
1 parent 625acc5 commit f3e78d8
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 34 deletions.
3 changes: 1 addition & 2 deletions cmd/substreams/gui.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ func init() {
guiCmd.Flags().String("network", "", "Specify the network to use for params and initialBlocks, overriding the 'network' field in the substreams package")
guiCmd.Flags().Bool("insecure", false, "Skip certificate validation on GRPC connection")
guiCmd.Flags().Bool("plaintext", false, "Establish GRPC connection in plaintext")
guiCmd.Flags().String("spkg-registry", "https://spkg.io", "Substreams package registry")
guiCmd.Flags().StringSliceP("header", "H", nil, "Additional headers to be sent in the substreams request")
guiCmd.Flags().StringP("start-block", "s", "", "Start block to stream from. If empty, will be replaced by initialBlock of the first module you are streaming. If negative, will be resolved by the server relative to the chain head")
guiCmd.Flags().StringP("cursor", "c", "", "Cursor to stream from. Leave blank for no cursor")
Expand Down Expand Up @@ -93,7 +92,7 @@ func runGui(cmd *cobra.Command, args []string) (err error) {
}

readerOptions := []manifest.Option{
manifest.WithRegistryURL(sflags.MustGetString(cmd, "spkg-registry")),
manifest.WithRegistryURL(getSubstreamsRegistryEndpoint()),
}

if len(requestParams) != 0 {
Expand Down
5 changes: 1 addition & 4 deletions cmd/substreams/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,7 @@ func runSubstreamsInitE(cmd *cobra.Command, args []string) error {
connect.WithGRPC(),
}

codegenEndpoint := "https://codegen.substreams.dev"
if newValue := os.Getenv("SUBSTREAMS_CODEGEN_ENDPOINT"); newValue != "" {
codegenEndpoint = newValue
}
codegenEndpoint := getSubstreamsCodegenEndpoint()

initConvoURL := codegenEndpoint
stateFile, stateFileFlagProvided := sflags.MustGetStringProvided(cmd, "state-file")
Expand Down
12 changes: 5 additions & 7 deletions cmd/substreams/registry-login.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package main
import (
"errors"
"fmt"
"github.com/charmbracelet/huh"
"github.com/charmbracelet/lipgloss"
"os"
"path/filepath"

"github.com/charmbracelet/huh"
"github.com/charmbracelet/lipgloss"

"github.com/spf13/cobra"
)

Expand All @@ -25,10 +26,7 @@ func init() {
}

func runRegistryLoginE(cmd *cobra.Command, args []string) error {
registryURL := "https://substreams.dev"
if newValue := os.Getenv("SUBSTREAMS_REGISTRY_ENDPOINT"); newValue != "" {
registryURL = newValue
}
registryURL := getSubstreamsRegistryEndpoint()

linkStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("12"))
token, err := copyPasteTokenForm(registryURL, linkStyle)
Expand Down Expand Up @@ -92,4 +90,4 @@ func runConfirmForm(title string) (bool, error) {
}

return confirmOverwrite, nil
}
}
14 changes: 2 additions & 12 deletions cmd/substreams/registry-publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ import (
)

func init() {
registryPublish.PersistentFlags().String("spkg-registry", "https://spkg.io", "Substreams package registry")
registryPublish.PersistentFlags().String("setup-mode", "production", "Setup mode (production, staging, local-development). Default: production")

registryCmd.AddCommand(registryPublish)
}

Expand All @@ -33,10 +30,7 @@ var registryPublish = &cobra.Command{
}

func runRegistryPublish(cmd *cobra.Command, args []string) error {
apiEndpoint := "https://substreams.dev"
if newValue := os.Getenv("SUBSTREAMS_REGISTRY_ENDPOINT"); newValue != "" {
apiEndpoint = newValue
}
apiEndpoint := getSubstreamsRegistryEndpoint()

var apiKey string
registryTokenBytes, err := os.ReadFile(registryTokenFilename)
Expand Down Expand Up @@ -81,10 +75,7 @@ func runRegistryPublish(cmd *cobra.Command, args []string) error {
manifestPath = args[0]
}

spkgRegistry := "https://spkg.io"
if newValue := os.Getenv("SUBSTREAMS_DOWNLOAD_ENDPOINT"); newValue != "" {
apiEndpoint = newValue
}
spkgRegistry := getSubstreamsDownloadEndpoint()

readerOptions := []manifest.Option{
manifest.WithRegistryURL(spkgRegistry),
Expand All @@ -102,7 +93,6 @@ func runRegistryPublish(cmd *cobra.Command, args []string) error {

spkg := pkgBundle.Package


style := lipgloss.NewStyle().Foreground(lipgloss.Color("12"))
headerStyle := lipgloss.NewStyle().Bold(true)
fmt.Println()
Expand Down
30 changes: 30 additions & 0 deletions cmd/substreams/registry.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package main

import (
"fmt"
"os"

"github.com/spf13/cobra"
"github.com/streamingfast/cli"
)
Expand All @@ -17,3 +20,30 @@ var registryCmd = &cobra.Command{
func init() {
rootCmd.AddCommand(registryCmd)
}

func getSubstreamsRegistryEndpoint() string {
endpoint := "https://substreams.dev"
if newValue := os.Getenv("SUBSTREAMS_REGISTRY_ENDPOINT"); newValue != "" {
fmt.Println("Using registry endpoint: " + newValue)
endpoint = newValue
}
return endpoint
}

func getSubstreamsDownloadEndpoint() string {
endpoint := "https://spkg.io"
if newValue := os.Getenv("SUBSTREAMS_DOWNLOAD_ENDPOINT"); newValue != "" {
fmt.Println("Using download endpoint: " + newValue)
endpoint = newValue
}
return endpoint
}

func getSubstreamsCodegenEndpoint() string {
endpoint := "https://codegen.substreams.dev"
if newValue := os.Getenv("SUBSTREAMS_CODEGEN_ENDPOINT"); newValue != "" {
fmt.Println("Using codegen endpoint: " + newValue)
endpoint = newValue
}
return endpoint
}
3 changes: 1 addition & 2 deletions cmd/substreams/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ func init() {
runCmd.Flags().Bool("final-blocks-only", false, "Only process blocks that have pass finality, to prevent any reorg and undo signal by staying further away from the chain HEAD")
runCmd.Flags().Bool("insecure", false, "Skip certificate validation on GRPC connection")
runCmd.Flags().Bool("plaintext", false, "Establish GRPC connection in plaintext")
runCmd.Flags().String("spkg-registry", "https://spkg.io", "Substreams package registry")
runCmd.Flags().StringP("output", "o", "", "Output mode, one of: [ui, json, jsonl, clock] Defaults to 'ui' when in a TTY is present, and 'json' otherwise")
runCmd.Flags().StringSlice("debug-modules-initial-snapshot", nil, "List of 'store' modules from which to print the initial data snapshot (Unavailable in Production Mode)")
runCmd.Flags().StringSlice("debug-modules-output", nil, "List of modules from which to print outputs, deltas and logs (Unavailable in Production Mode)")
Expand Down Expand Up @@ -72,7 +71,7 @@ func runRun(cmd *cobra.Command, args []string) error {
manifest.WithOverrideOutputModule(outputModule),
manifest.WithOverrideNetwork(network),
manifest.WithParams(params),
manifest.WithRegistryURL(sflags.MustGetString(cmd, "spkg-registry")),
manifest.WithRegistryURL(getSubstreamsRegistryEndpoint()),
}
if sflags.MustGetBool(cmd, "skip-package-validation") {
readerOptions = append(readerOptions, manifest.SkipPackageValidationReader())
Expand Down
10 changes: 3 additions & 7 deletions docs/release-notes/change-log.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## Unreleased

* In `substreams run`, the two positional parameters now align with `gui`: `[package [module_name]]`. Before, it was using fuzzy heuristics to see if a single param was a module name or a package name. You need to be more explicit now, like `gui`.

## v1.10.12

* Add `substreams publish` to `publish` a package on the substreams registry (check on `https://substreams.dev`).
* Add `substreams registry` to `login` and `publish` on the substreams registry (check on `https://substreams.dev`).

* Changed `substreams run`: the two positional parameters now align with `gui`: `[package [module_name]]`. Before, it was using fuzzy heuristics to see if a single param was a module name or a package name. You need to be more explicit now, like `gui`.
* Added `substreams publish` to `publish` a package on the substreams registry (check on `https://substreams.dev`).
* Added `substreams registry` to `login` and `publish` on the substreams registry (check on `https://substreams.dev`).

## v1.10.11

Expand Down

0 comments on commit f3e78d8

Please sign in to comment.