Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change Rosetta to hard coded default configuration #2484

Merged
merged 2 commits into from
Sep 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ The Rosetta API supports loading configuration from YAML. By default, it loads a
`application.yml` in each of the search paths (see below). The configuration is loaded in the following order with the
latter configuration overwriting (technically recursively merged into) the current configuration:

1. `./config/application.yml`
1. Hard coded configuration embedded in the code
2. `./application.yml`
3. `${HEDERA_MIRROR_ROSETTA_API_CONFIG}` environment variable to custom values file (
e.g. `HEDERA_MIRROR_ROSETTA_API_CONFIG=/Users/Downloads/hedera-mirror-rosetta/application.yml`)
Expand Down
1 change: 0 additions & 1 deletion hedera-mirror-rosetta/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@ RUN go build -o main ./cmd
FROM ubuntu:20.04
WORKDIR $GOPATH/src/hedera-mirror-rosetta
COPY --from=build /tmp/src/hedera-mirror-rosetta/main .
COPY ./config/application.yml ./config/application.yml
CMD ["./main"]
1 change: 0 additions & 1 deletion hedera-mirror-rosetta/build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ USER root
# Copy the Rosetta Executable from the Rosetta Builder stage
WORKDIR /var/rosetta
COPY --from=rosetta-builder /hedera-mirror-rosetta/rosetta-executable .
COPY --from=rosetta-builder /hedera-mirror-rosetta/config/application.yml ./config/application.yml

# Copy the Importer Jar and Config from the Java-Builder stage
WORKDIR /var/importer
Expand Down
43 changes: 37 additions & 6 deletions hedera-mirror-rosetta/cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,42 @@ import (
)

const (
defaultConfigFile = "config/application.yml"
mainConfigFile = "application.yml"
mainConfigFile = "application.yml"
)

// loadConfig loads configuration from yaml files and env variables
func loadConfig() (*types.Config, error) {
var config types.Config

if !getConfig(&config, defaultConfigFile) {
return nil, errors.New("failed to load the default config file: " + defaultConfigFile)
var config = types.Config{
Hedera: types.Hedera{
Mirror: types.Mirror{
Rosetta: types.Rosetta{
ApiVersion: "1.4.10",
Db: types.Db{
Host: "127.0.0.1",
Name: "mirror_node",
Password: "mirror_rosetta_pass",
Pool: types.Pool{
MaxIdleConnections: 20,
MaxLifetime: 30,
MaxOpenConnections: 100,
},
Port: 5432,
Username: "mirror_rosetta",
},
Log: types.Log{
Level: "info",
},
Network: "DEMO",
Nodes: types.NodeMap{},
NodeVersion: "0",
Online: true,
Port: 5700,
Realm: "0",
Shard: "0",
Version: "0.40.0-SNAPSHOT",
},
},
},
}

getConfig(&config, mainConfigFile)
Expand All @@ -60,6 +86,11 @@ func loadConfig() (*types.Config, error) {
return nil, err
}

var password = config.Hedera.Mirror.Rosetta.Db.Password
config.Hedera.Mirror.Rosetta.Db.Password = "<omitted>"
log.Infof("Using configuration: %+v", &config)
config.Hedera.Mirror.Rosetta.Db.Password = password

return &config, nil
}

Expand Down
42 changes: 37 additions & 5 deletions hedera-mirror-rosetta/cmd/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,56 @@
package main

import (
"io/ioutil"
"os"
"path/filepath"
"testing"

"github.com/hashgraph/hedera-mirror-node/hedera-mirror-rosetta/types"
"github.com/hashgraph/hedera-sdk-go/v2"
"github.com/stretchr/testify/assert"
)

func TestLoadDefaultConfig(t *testing.T) {
wd, _ := os.Getwd()
// change to project root so to load the default config
os.Chdir("../")
defer os.Chdir(wd)
const yml = `
hedera:
mirror:
rosetta:
db:
port: 5431
username: foobar`

func TestLoadDefaultConfig(t *testing.T) {
config, err := loadConfig()

assert.NoError(t, err)
assert.NotNil(t, config)
assert.Equal(t, uint16(5432), config.Hedera.Mirror.Rosetta.Db.Port)
assert.Equal(t, config.Hedera.Mirror.Rosetta.Db.Username, "mirror_rosetta")
}

func TestLoadCustomConfig(t *testing.T) {
tempDir, err := ioutil.TempDir("", "rosetta")
if err != nil {
assert.Fail(t, "Unable to create temp dir", err)
}
defer os.RemoveAll(tempDir)
err = os.Chdir(tempDir)
if err != nil {
assert.Fail(t, "Unable to change directory", err)
}
customConfig := filepath.Join(tempDir, "application.yml")

err = ioutil.WriteFile(customConfig, []byte(yml), 0644)
if err != nil {
assert.Fail(t, "Unable to create custom config", err)
}

config, err := loadConfig()
assert.NoError(t, err)
assert.NotNil(t, config)
assert.Equal(t, true, config.Hedera.Mirror.Rosetta.Online)
assert.Equal(t, uint16(5431), config.Hedera.Mirror.Rosetta.Db.Port)
assert.Equal(t, "foobar", config.Hedera.Mirror.Rosetta.Db.Username)
}

func TestParseNodesFromEnv(t *testing.T) {
Expand Down
25 changes: 0 additions & 25 deletions hedera-mirror-rosetta/config/application.yml

This file was deleted.

6 changes: 5 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@
<include>hedera-mirror-rest/**/openapi.yml</include>
<include>hedera-mirror-rest/package*.json</include>
<include>hedera-mirror-rest/monitoring/monitor_apis/package*.json</include>
<include>hedera-mirror-rosetta/config/application*.yml</include>
<include>hedera-mirror-rosetta/cmd/config.go</include>
</includes>
<replacements>
<replacement>
Expand All @@ -530,6 +530,10 @@
<token><![CDATA[(?<=(\s{3})version: )[0-9a-zA-Z.-]+]]></token>
<value>${release.version}</value>
</replacement>
<replacement>
<token><![CDATA[(?<= Version: ")[0-9a-zA-Z.-]+]]></token>
<value>${release.version}</value>
</replacement>
<replacement>
<token>
<![CDATA[(?<=gcr.io/mirrornode/hedera-mirror-(grpc|importer|monitor|rest|rosetta|test):)[0-9a-zA-Z.-]+]]></token>
Expand Down