Skip to content
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
14 changes: 9 additions & 5 deletions .codeclimate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@ checks:
return-statements:
enabled: false
exclude_patterns:
- "docs/"
- "**/generated.go"
- "**/test/**/*.go"
- "**/test.go"
- "**/*_test.go"
- '**/test.go'
- "test/*"
- "**/mock/**/*.go"
- "**/mock.go"
- "**/generated.go"
- "**/mock/*"
- "docs/**/*.go"
- "**/*.pb.go"
# Until network protocol implementation has been spec and optionally replace, ignore those sources
- "network/p2p/**/*.go"
- "network/proto/**/*.go"

plugins:
gofmt:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,5 @@ data

# ignore generated pem files from running the nuts-node executable.
/*.pem

/nuts-node
71 changes: 62 additions & 9 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Distributed registry for storing and querying health care providers their vendor
Dependencies
************

This projects is using go modules, so version > 1.12 is recommended. 1.10 would be a minimum.
Go >= 1.15 is required.

Running tests
*************
Expand All @@ -38,20 +38,22 @@ Building

Just use ``go build``.

The server and client API is generated from the open-api spec:
Code Generation
***************

.. code-block:: shell
Code generation is used for generating mocks, OpenAPI client- and servers and gRPC services. To regenerate the code
run the `run-generators` target from the Makefile:

make gen-api
.. code-block:: shell

Generating Mocks
****************
make run-generators

These mocks are used by other modules
The peer-to-peer API uses gRPC. To generate Go code from the protobuf specs you need the `protoc-gen-go` package:

.. code-block:: shell

make gen-mocks
go get -u github.com/golang/protobuf/protoc-gen-go

README
******

Expand Down Expand Up @@ -122,5 +124,56 @@ The following options can be configured:

.. marker-for-config-options

.. include:: options.rst
======================================== =================================================================================== ================================================================================================================================================================================
Key Default Description
======================================== =================================================================================== ================================================================================================================================================================================
****
address localhost:1323 Address and port the server will be listening to
configfile nuts.yaml Nuts config file
identity Vendor identity for the node, mandatory when running in server mode. Must be in the format: urn:oid:1.3.6.1.4.1.54851.4:<number>
mode server Mode the application will run in. When 'cli' it can be used to administer a remote Nuts node. When 'server' it will start a Nuts node. Defaults to 'server'.
strictmode false When set, insecure settings are forbidden.
verbosity info Log level (trace, debug, info, warn, error)
**Auth**
auth.actingPartyCn The acting party Common name used in contracts
auth.address localhost:1323 Interface and port for http server to bind to
auth.enableCORS false Set if you want to allow CORS requests. This is useful when you want browsers to directly communicate with the nuts node.
auth.irmaConfigPath path to IRMA config folder. If not set, a tmp folder is created.
auth.irmaSchemeManager pbdf The IRMA schemeManager to use for attributes. Can be either 'pbdf' or 'irma-demo'
auth.mode server or client, when client it does not start any services so that CLI commands can be used.
auth.publicUrl Public URL which can be reached by a users IRMA client
auth.skipAutoUpdateIrmaSchemas false set if you want to skip the auto download of the irma schemas every 60 minutes.
**ConsentBridgeClient**
cbridge.address http://localhost:8080 API Address of the consent bridge
**ConsentStore**
cstore.address localhost:1323 Address of the server when in client mode
cstore.connectionstring \:memory: Db connectionString
cstore.mode server or client, when client it uses the HttpClient
**Crypto**
crypto.fspath ./ when file system is used as storage, this configures the path where keys are stored (default .)
crypto.keysize 2048 number of bits to use when creating new RSA keys
crypto.storage fs storage to use, 'fs' for file system (default)
**Events octopus**
events.autoRecover false Republish unfinished events at startup
events.connectionstring file::memory:?cache=shared db connection string for event store
events.incrementalBackoff 8 Incremental backoff per retry queue, queue 0 retries after 1 second, queue 1 after {incrementalBackoff} * {previousDelay}
events.maxRetryCount 5 Max number of retries for events before giving up (only for recoverable errors
events.natsPort 4222 Port for Nats to bind on
events.purgeCompleted false Purge completed events at startup
events.retryInterval 60 Retry delay in seconds for reconnecting
**Network**
network.bootstrapNodes Space-separated list of bootstrap nodes (`<host>:<port>`) which the node initially connect to.
network.certFile PEM file containing the certificate this node will identify itself with to other nodes. If not set, the Nuts node will attempt to load a TLS certificate from the crypto module.
network.certKeyFile PEM file containing the key belonging to this node's certificate. If not set, the Nuts node will attempt to load a TLS certificate from the crypto module.
network.grpcAddr \:5555 Local address for gRPC to listen on.
network.publicAddr Public address (of this node) other nodes can use to connect to it. If set, it is registered on the nodelist.
network.databaseFile network.db Path to BBolt database file for storage of the network.
network.trustStoreFile PEM file containing the trusted CA certificates for authenticating remote gRPC servers.
network.advertHashesInterval 2000 Interval (in milliseconds) that specifies how often the node should broadcast its last hashes to other nodes.
**VDR**
vdr.clientTimeout 10 Time-out for the client in seconds (e.g. when using the CLI), default: 10
vdr.datadir ./data Location of data files, default: ./data
**Validation**
fhir.schemapath location of json schema, default nested Asset
=========================================================================================================================== ================================================================================================================================================================================

26 changes: 18 additions & 8 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,20 @@ import (
"github.com/labstack/echo/v4/middleware"
"github.com/nuts-foundation/nuts-node/core"
crypto "github.com/nuts-foundation/nuts-node/crypto/engine"
"github.com/nuts-foundation/nuts-node/network/engine"
vdr "github.com/nuts-foundation/nuts-node/vdr/engine"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

// Allows overriding Echo server implementation to aid testing
var echoCreator = func() core.EchoServer {
echo := echo.New()
echo.HideBanner = true
echo.Use(middleware.Logger())
return echo
}

func createRootCommand() *cobra.Command {
return &cobra.Command{
Use: "nuts",
Expand All @@ -41,18 +50,17 @@ func createRootCommand() *cobra.Command {
return
}
// start interfaces
echo := echo.New()
echo.HideBanner = true
echo.Use(middleware.Logger())

echo := echoCreator()
for _, engine := range core.EngineCtl.Engines {
if engine.Routes != nil {
engine.Routes(echo)
}
}

defer shutdownEngines()
logrus.Fatal(echo.Start(cfg.ServerAddress()))
if err := echo.Start(cfg.ServerAddress()); err != nil {
logrus.Fatal(err)
}
},
}
}
Expand Down Expand Up @@ -104,9 +112,11 @@ func registerEngines() {
core.RegisterEngine(core.NewStatusEngine())
core.RegisterEngine(core.NewLoggerEngine())
core.RegisterEngine(core.NewMetricsEngine())
core.RegisterEngine(crypto.NewCryptoEngine())
core.RegisterEngine(vdr.NewVDREngine())

cryptoEngine, keyStore := crypto.NewCryptoEngine()
core.RegisterEngine(cryptoEngine)
networkEngine, networkInstance := engine.NewNetworkEngine(keyStore)
core.RegisterEngine(networkEngine)
core.RegisterEngine(vdr.NewVDREngine(keyStore, networkInstance))
}

func injectConfig(cfg *core.NutsGlobalConfig) {
Expand Down
21 changes: 21 additions & 0 deletions cmd/root_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,33 @@
package cmd

import (
"github.com/golang/mock/gomock"
"github.com/nuts-foundation/nuts-node/core"
"github.com/nuts-foundation/nuts-node/test/io"
"github.com/stretchr/testify/assert"
"os"
"path"
"testing"
)

func Test_rootCmd(t *testing.T) {
t.Run("start in server mode", func(t *testing.T) {
ctrl := gomock.NewController(t)
echoServer := core.NewMockEchoServer(ctrl)
echoServer.EXPECT().GET(gomock.Any(), gomock.Any()).AnyTimes()
echoServer.EXPECT().POST(gomock.Any(), gomock.Any()).AnyTimes()
echoServer.EXPECT().PUT(gomock.Any(), gomock.Any()).AnyTimes()
echoServer.EXPECT().Start(gomock.Any())
echoCreator = func() core.EchoServer {
return echoServer
}
testDirectory := io.TestDirectory(t)
os.Setenv("NUTS_NETWORK_DATABASEFILE", path.Join(testDirectory, "network.db"))
os.Setenv("NUTS_VDR_DATADIR", path.Join(testDirectory, "vdr"))
os.Setenv("NUTS_CRYPTO_FSPATH", path.Join(testDirectory, "crypto"))
os.Args = []string{"nuts"}
Execute()
})
t.Run("start in CLI mode", func(t *testing.T) {
var routesCalled = false
core.RegisterEngine(&core.Engine{
Expand All @@ -20,4 +40,5 @@ func Test_rootCmd(t *testing.T) {
assert.NoError(t, CreateCommand().Execute())
assert.False(t, routesCalled, "engine.Routes was called")
})

}
13 changes: 9 additions & 4 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
ignore:
- "**/generated.go"
- "test/*"
- '**/test.go'
- "mock/*"
- "**/test/"
- "**/test.go"
- "**/*_test.go"
- "mock/**/*.go"
- "**/mock.go"
- "docs/*"
- "docs/**/*.go"
- "**/*.pb.go"
# Until network protocol implementation has been spec and optionally replace, ignore those sources
- "network/p2p/"
- "network/proto/"
Comment thread
reinkrul marked this conversation as resolved.
github_checks:
annotations: false
2 changes: 0 additions & 2 deletions core/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,6 @@ func TestNutsGlobalConfig_LoadConfigFile(t *testing.T) {

func TestNutsGlobalConfig_LoadAndUnmarshal(t *testing.T) {
cfg := NewNutsGlobalConfig()
os.Setenv("NUTS_IDENTITY", "urn:oid:1.3.6.1.4.1.54851.4:4")
defer os.Unsetenv("NUTS_IDENTITY")
cfg.Load(&cobra.Command{})

type mandatory struct {
Expand Down
6 changes: 6 additions & 0 deletions core/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ type EngineControl struct {

var EngineCtl EngineControl

// EchoServer implements both the EchoRouter interface and Start function to aid testing.
type EchoServer interface {
EchoRouter
Start(address string) error
}

// EchoRouter is the interface the generated server API's will require as the Routes func argument
type EchoRouter interface {
CONNECT(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
Expand Down
Loading