Skip to content

Commit

Permalink
Merge pull request #348 from fairDataSociety/staging
Browse files Browse the repository at this point in the history
Staging
  • Loading branch information
asabya authored Jan 9, 2023
2 parents afeffb7 + 051c7fa commit 0ff3da9
Show file tree
Hide file tree
Showing 107 changed files with 4,134 additions and 1,983 deletions.
1 change: 1 addition & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ updates:
schedule:
interval: weekly
day: sunday
target-branch: "staging"
34 changes: 33 additions & 1 deletion DISCLAIMER
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,40 @@ of liability, arising out of or in connection with the possession, use or
performance of this software.


# Disclaimer of Endorsement
Reference herein to any specific commercial product, process, or service by trade
name, trademark, manufacturer, or otherwise, in this Work does not constitute an
endorsement, recommendation, or favoring by the any Government and
shall not be used for advertising or product endorsement purposes.
=======
# DISCLAIMER
Account integrity persistence and security are not assured. Expect that funds
used for account might be lost, as well as any data the account uses.

Use of this service is limited only to **non-sensitive and publicly available
data**. Users must not use, share, or store any kind of sensitive data like
health status, provision or payment of healthcare, Personally Identifiable
Information (PII) and/or Protected Health Information (PHI), etc. under **ANY**
circumstance.

Administrators for this service can not moderate any information
used, shared, or stored with this service at any time. Any user that cannot
abide by this disclaimer and Code of Conduct must refrain from using this service.

The material embodied in this software is provided to you "as-is" and without
warranty of any kind, express, implied or otherwise, including without
limitation, any warranty of fitness for a particular purpose. In no event shall
the any government be liable to you or anyone else for any direct, special, incidental,
indirect or consequential damages of any kind, or any damages whatsoever,
including without limitation, loss of profit, loss of use, savings or revenue,
or the claims of third parties, whether or not any government has
been advised of the possibility of such loss, however caused and on any theory
of liability, arising out of or in connection with the possession, use or
performance of this software.


# Disclaimer of Endorsement
Reference herein to any specific commercial product, process, or service by trade
name, trademark, manufacturer, or otherwise, in this Work does not constitute an
endorsement, recommendation, or favoring by the any Government and
shall not be used for advertising or product endorsement purposes.
shall not be used for advertising or product endorsement purposes.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
GO ?= go
GOLANGCI_LINT ?= $$($(GO) env GOPATH)/bin/golangci-lint
GOLANGCI_LINT_VERSION ?= v1.47.2
GOLANGCI_LINT_VERSION ?= v1.50.0
GOGOPROTOBUF ?= protoc-gen-gogofaster
GOGOPROTOBUF_VERSION ?= v1.3.1

Expand Down Expand Up @@ -56,7 +56,7 @@ githooks:

.PHONY: protobuftools
protobuftools:
which protoac || ( echo "install protoc for your system from https://github.com/protocolbuffers/protobuf/releases" && exit 1)
which protoc || ( echo "install protoc for your system from https://github.com/protocolbuffers/protobuf/releases" && exit 1)
which $(GOGOPROTOBUF) || ( cd /tmp && GO111MODULE=on $(GO) get -u github.com/gogo/protobuf/$(GOGOPROTOBUF)@$(GOGOPROTOBUF_VERSION) )

.PHONY: protobuf
Expand Down
11 changes: 1 addition & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

Latest documentation is available at [https://docs.fairos.fairdatasociety.org/docs/](https://docs.fairos.fairdatasociety.org/docs/)

![FairOS-dfs](https://github.com/fairDataSociety/fairOS-dfs/blob/master/docs/images/FairOS-dfs.png)
![FairOS-dfs](./docs/images/FairOS-dfs.png)

The Decentralised File System (dfs) is a file system built for the [FairOS](https://github.com/fairDataSociety/fairOS/blob/master/README.md).
It is a stateless thin layer which uses the building blocks provided by Swarm to provide high level functionalities like
Expand Down Expand Up @@ -62,13 +62,11 @@ To get the most out of your FairOS-dfs it is important that you configure FairOS
bee:
bee-api-endpoint: http://localhost:1633
postage-batch-id: ""
is-gateway-proxy: false
```

##### Configuration for FairOS-dfs
```
dfs:
data-dir: /Users/fairos/.fairOS/dfs
ports:
http-port: :9090
pprof-port: :9091
Expand Down Expand Up @@ -110,11 +108,9 @@ This is how a config file should look like
bee:
bee-api-endpoint: http://localhost:1633
postage-batch-id: <BATCH>
is-gateway-proxy: false
cookie-domain: localhost
cors-allowed-origins: []
dfs:
data-dir: /Users/username/.fairOS/dfs
ports:
http-port: :9090
pprof-port: :9091
Expand Down Expand Up @@ -158,13 +154,9 @@ Flags:
Global Flags:
--beeApi string full bee api endpoint (default "localhost:1633")
--config string config file (default "/Users/sabyasachipatra/.dfs.yaml")
--dataDir string store data in this dir (default "dataDirPath")
--verbosity string verbosity level (default "trace")
```

### Introduction to Key Value Store over Swarm
[![](https://j.gifs.com/6XZwvl.gif)](https://gateway.ethswarm.org/access/130dcf7d01442836bc14c8c38db32ebfc4d5771c28677438b6a2a2a078bd1414)

### HTTP APIs

https://docs.fairos.fairdatasociety.org/docs/fairOS-dfs/api-reference
Expand Down Expand Up @@ -214,5 +206,4 @@ network: "testnet"
bee:
bee-api-endpoint: http://localhost:1633 # bee running on mainnet
postage-batch-id: <BATCH>
is-gateway-proxy: false
```
60 changes: 38 additions & 22 deletions cmd/dfs/cmd/commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,39 @@ import (
"io"
"os"
"path/filepath"
"strings"
"testing"

"github.com/stretchr/testify/assert"

"github.com/stretchr/testify/require"
)

func TestMain(m *testing.M) {
//goleak.VerifyTestMain(m)
}

func Test_ExecuteCommand(t *testing.T) {

t.Run("config-help", func(t *testing.T) {
configHelpPrefix := `Print default or provided configuration in yaml format`
b := bytes.NewBufferString("")
rootCmd.SetOut(b)
rootCmd.SetArgs([]string{"config", "extra"})
Execute()
dt, err := io.ReadAll(b)
require.NoError(t, err)

assert.Equal(t, strings.HasPrefix(string(dt), configHelpPrefix), true)
})

t.Run("config", func(t *testing.T) {
b := bytes.NewBufferString("")
rootCmd.SetOut(b)
rootCmd.SetArgs([]string{"config"})
Execute()
_, err := io.ReadAll(b)
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)
})

t.Run("version", func(t *testing.T) {
Expand All @@ -26,16 +46,14 @@ func Test_ExecuteCommand(t *testing.T) {
rootCmd.SetArgs([]string{"version"})
Execute()
_, err := io.ReadAll(b)
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)

})

t.Run("server-postageBlockId-required", func(t *testing.T) {
tempDir, err := os.MkdirTemp("", ".dfs")
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)

defer os.RemoveAll(tempDir)
b := bytes.NewBufferString("")
rootCmd.SetOut(b)
Expand All @@ -49,9 +67,8 @@ func Test_ExecuteCommand(t *testing.T) {

t.Run("server-postageBlockId-invalid", func(t *testing.T) {
tempDir, err := os.MkdirTemp("", ".dfs")
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)

defer os.RemoveAll(tempDir)
b := bytes.NewBufferString("")
rootCmd.SetOut(b)
Expand All @@ -69,9 +86,8 @@ func Test_ExecuteCommand(t *testing.T) {

t.Run("server-rpc-err", func(t *testing.T) {
tempDir, err := os.MkdirTemp("", ".dfs")
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)

defer os.RemoveAll(tempDir)
b := bytes.NewBufferString("")
rootCmd.SetOut(b)
Expand All @@ -89,9 +105,8 @@ func Test_ExecuteCommand(t *testing.T) {

t.Run("server-ens-err", func(t *testing.T) {
tempDir, err := os.MkdirTemp("", ".dfs")
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)

defer os.RemoveAll(tempDir)
b := bytes.NewBufferString("")
rootCmd.SetOut(b)
Expand All @@ -108,9 +123,8 @@ func Test_ExecuteCommand(t *testing.T) {

t.Run("server-network-err", func(t *testing.T) {
tempDir, err := os.MkdirTemp("", ".dfs")
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)

defer os.RemoveAll(tempDir)
b := bytes.NewBufferString("")
rootCmd.SetOut(b)
Expand All @@ -119,8 +133,10 @@ func Test_ExecuteCommand(t *testing.T) {
"server",
"--network",
"play",
"--rpc",
"--beeHost",
"http://localhost:1633",
"--rpc",
"http://localhost:9545",
"--postageBlockId",
"c108266827eb7ba357797de2707bea00446919346b51954f773560b79765d552",
"--config",
Expand Down
9 changes: 2 additions & 7 deletions cmd/dfs/cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,12 @@ import (
)

var (
optionCORSAllowedOrigins = "cors-allowed-origins"
// FOR MIGRATION PURPOSE ONLY
optionDFSDataDir = "dfs.data-dir"

optionCORSAllowedOrigins = "cors-allowed-origins"
optionDFSHttpPort = "dfs.ports.http-port"
optionDFSPprofPort = "dfs.ports.pprof-port"
optionVerbosity = "verbosity"
optionBeeApi = "bee.bee-api-endpoint"
optionBeePostageBatchId = "bee.postage-batch-id"
optionIsGatewayProxy = "bee.is-gateway-proxy"
optionCookieDomain = "cookie-domain"
optionNetwork = "network"
optionRPC = "rpc"
Expand All @@ -30,7 +26,6 @@ var (
defaultVerbosity = "trace"
defaultBeeApi = "http://localhost:1633"
defaultCookieDomain = "api.fairos.io"
defaultIsGatewayProxy = false
)

var configCmd = &cobra.Command{
Expand All @@ -44,7 +39,7 @@ var configCmd = &cobra.Command{

d := config.AllSettings()
ym, err := yaml.Marshal(d)
if err != nil {
if err != nil { // skipcq: TCV-001
return err
}
cmd.Println(string(ym))
Expand Down
29 changes: 6 additions & 23 deletions cmd/dfs/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,13 @@ import (
)

var (
// FOR MIGRATION PURPOSE ONLY
defaultDir = filepath.Join(".fairOS", "dfs")

defaultConfig = ".dfs.yaml"

cfgFile string
beeApi string
verbosity string

config = viper.New()

// FOR MIGRATION PURPOSE ONLY
dataDir string
dataDirPath string
)

// rootCmd represents the base command when called without any subcommands
Expand All @@ -61,12 +54,6 @@ It can also be used as a standalone personal, decentralised drive over the inter

beeApi = config.GetString(optionBeeApi)
verbosity = config.GetString(optionVerbosity)

// FOR MIGRATION PURPOSE ONLY
if err := config.BindPFlag(optionDFSDataDir, cmd.Flags().Lookup("dataDir")); err != nil {
return err
}
dataDir = config.GetString(optionDFSDataDir)
return nil
},
}
Expand Down Expand Up @@ -105,12 +92,13 @@ func init() {

rootCmd.PersistentFlags().StringVar(&cfgFile, "config", configPath, "config file")

rootCmd.PersistentFlags().String("beeApi", "localhost:1633", "full bee api endpoint")
rootCmd.PersistentFlags().String("beeApi", "http://localhost:1633", "full bee api endpoint")
rootCmd.PersistentFlags().String("verbosity", "trace", "verbosity level")

rootCmd.PersistentFlags().String("beeDebugApi", "localhost:1635", "full bee debug api endpoint")
rootCmd.PersistentFlags().String("beeHost", "127.0.0.1", "bee host")
rootCmd.PersistentFlags().String("beePort", "1633", "bee port")
rootCmd.PersistentFlags().String("dataDir", "dataDirPath", "store data in this dir")

if err := rootCmd.PersistentFlags().MarkDeprecated("beeDebugApi", "using debugAPI is not supported in fairOS-dfs server anymore"); err != nil {
fmt.Println(err)
Expand All @@ -124,11 +112,10 @@ func init() {
fmt.Println(err)
os.Exit(1)
}

// FOR MIGRATION PURPOSE ONLY
dataDirPath = filepath.Join(home, defaultDir)
rootCmd.PersistentFlags().String("dataDir", "dataDirPath", "store data in this dir")

if err := rootCmd.PersistentFlags().MarkDeprecated("dataDir", "dataDir is no longer required"); err != nil {
fmt.Println(err)
os.Exit(1)
}
}

// initConfig reads in config file and ENV variables if set.
Expand Down Expand Up @@ -176,10 +163,6 @@ func writeConfig() {
c.Set(optionBeeApi, defaultBeeApi)
c.Set(optionBeePostageBatchId, "")
c.Set(optionCookieDomain, defaultCookieDomain)
c.Set(optionIsGatewayProxy, defaultIsGatewayProxy)

// FOR MIGRATION PURPOSE ONLY
c.Set(optionDFSDataDir, dataDirPath)

if err := c.WriteConfigAs(cfgFile); err != nil {
fmt.Println("failed to write config file")
Expand Down
Loading

0 comments on commit 0ff3da9

Please sign in to comment.