Skip to content

Commit

Permalink
Fixed error when importing http/https .spkg files in imports se…
Browse files Browse the repository at this point in the history
…ction.
  • Loading branch information
maoueh committed Aug 23, 2022
1 parent f432bb9 commit 775c6c7
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/release-notes/change-log.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## Unreleased

* Fixed error when importing `http/https` `.spkg` files in `imports` section.

## [0.0.19](https://github.com/streamingfast/substreams/releases/tag/v0.0.19)

Expand Down
4 changes: 3 additions & 1 deletion manifest/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ type Manifest struct {
Workdir string `yaml:"-"`
}

var httpSchemePrefixRegex = regexp.MustCompile("^https?://")

func (m *Manifest) resolvePath(path string) string {
if m.Workdir == "" || filepath.IsAbs(path) {
if m.Workdir == "" || filepath.IsAbs(path) || httpSchemePrefixRegex.MatchString(path) {
return path
}

Expand Down
35 changes: 35 additions & 0 deletions manifest/reader_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package manifest

import (
"net/http"
"net/http/httptest"
"os"
"path/filepath"
"strings"
"testing"
Expand All @@ -12,13 +15,23 @@ import (
)

func TestReader_Read(t *testing.T) {

systemProtoDefs := readSystemProtoDescriptors(t)
absolutePathToDep2, err := filepath.Abs("testdata/dep2.yaml")
require.NoError(t, err)

absolutePathToProto2, err := filepath.Abs("testdata/proto2")
require.NoError(t, err)

spkg1Content, err := os.ReadFile("testdata/spkg1/spkg1-v0.0.0.spkg")
require.NoError(t, err)

remoteServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
// FIXME: Handle more "spkgX" path if required
w.Write(spkg1Content)
}))
defer remoteServer.Close()

tests := []struct {
name string
env map[string]string
Expand Down Expand Up @@ -61,6 +74,28 @@ func TestReader_Read(t *testing.T) {
},
require.NoError,
},
{
"testdata/imports_http_url.yaml",
map[string]string{
"SERVER_HOST": strings.Replace(remoteServer.URL, "http://", "", 1),
},
&pbsubstreams.Package{
Version: 1,
ProtoFiles: append(systemProtoDefs),
Modules: &pbsubstreams.Modules{},
PackageMeta: []*pbsubstreams.PackageMetadata{
{
Name: "test",
Version: "v0.0.0",
},
{
Name: "spkg1",
Version: "v0.0.0",
},
},
},
require.NoError,
},
{
"testdata/imports_expand_env_variables.yaml",
map[string]string{
Expand Down
7 changes: 7 additions & 0 deletions manifest/testdata/imports_http_url.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
specVersion: v0.1.0
package:
name: test
version: v0.0.0

imports:
bare: "http://${SERVER_HOST}/spkg1-v0.0.0.spkg"
44 changes: 44 additions & 0 deletions manifest/testdata/spkg1/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env bash

ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd ../../.. && pwd )"

option=""

main() {
pushd "$ROOT" &> /dev/null

while getopts "ho:" opt; do
case $opt in
h) usage && exit 0;;
o) option="$OPTARG";;
\?) usage_error "Invalid option: -$OPTARG";;
esac
done
shift $((OPTIND-1))

set -e

substreams pack manifest/testdata/spkg1/spkg1.yaml
mv spkg1-v0.0.0.spkg manifest/testdata/spkg1/
}

usage_error() {
message="$1"
exit_code="$2"

echo "ERROR: $message"
echo ""
usage
exit ${exit_code:-1}
}

usage() {
echo "usage: build.sh <all>"
echo ""
echo "Generates the .spkg files from their manifest."
echo ""
echo "Options"
echo " -h Display help about this script"
}

main "$@"
Binary file added manifest/testdata/spkg1/spkg1-v0.0.0.spkg
Binary file not shown.
4 changes: 4 additions & 0 deletions manifest/testdata/spkg1/spkg1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
specVersion: v0.1.0
package:
name: spkg1
version: v0.0.0

0 comments on commit 775c6c7

Please sign in to comment.