Skip to content

Commit

Permalink
Merge pull request #603 from fairDataSociety/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
asabya authored Feb 26, 2024
2 parents 2c33051 + 656a7ab commit 8a4b433
Show file tree
Hide file tree
Showing 168 changed files with 11,584 additions and 3,366 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/coverge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: '1.20.1'
go-version: '1.21.4'
- name: Checkout
uses: actions/checkout@v3
with:
Expand All @@ -24,6 +24,6 @@ jobs:
env:
DEEPSOURCE_DSN: ${{ secrets.DEEPSOURCE_DSN }}
run: |
go test -coverprofile=cover.out $(go list ./... | grep -v wasm)
go test -coverprofile=cover.out $(go list ./... | grep -v wasm) -timeout=30m
curl https://deepsource.io/cli | sh
./bin/deepsource report --analyzer test-coverage --key go --value-file ./cover.out
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
go: ['1.20.1']
go: ['1.21.4']
os: [ubuntu-latest, macos-latest, windows-latest]
steps:
- name: Setup Go
Expand Down
9 changes: 6 additions & 3 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: '1.20.1'
go-version: '1.21.4'
- name: Checkout
uses: actions/checkout@v3
with:
Expand All @@ -45,7 +45,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: '1.20.1'
go-version: '1.21.4'
- name: Checkout
uses: actions/checkout@v3
with:
Expand All @@ -70,6 +70,9 @@ jobs:
- name: Build android aar
run: |
make android
- name: Git checkout
run: |
git checkout .
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
Expand All @@ -85,7 +88,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: '1.20.1'
go-version: '1.21.4'
- name: Checkout
uses: actions/checkout@v3
with:
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.19-alpine AS build
FROM golang:1.21.4-alpine AS build

WORKDIR /usr/fairos
COPY go.mod go.sum /usr/fairos/
Expand All @@ -9,7 +9,7 @@ COPY . /usr/fairos/
RUN apk add --update --no-cache make gcc git musl-dev libc-dev linux-headers bash \
&& make binary

FROM alpine:3.15
FROM alpine:3.18

ARG CONFIG
ENV CONFIG=$CONFIG
Expand Down
10 changes: 5 additions & 5 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.52.2
GOLANGCI_LINT_VERSION ?= v1.55.2
GOGOPROTOBUF ?= protoc-gen-gogofaster
GOGOPROTOBUF_VERSION ?= v1.3.1

Expand Down Expand Up @@ -41,11 +41,11 @@ vet:

.PHONY: test-race
test-race:
$(GO) test -race -timeout 300000ms -v "$(DEST)"
$(GO) test -race -timeout 30m -v "$(DEST)"

.PHONY: test
test:
$(GO) test -v "$(DEST)"
$(GO) test -v "$(DEST)" -timeout=30m

.PHONY: githooks
githooks:
Expand Down Expand Up @@ -74,7 +74,7 @@ release:
-v `pwd`:/go/src/github.com/fairDataSociety/fairOS-dfs \
-v /var/run/docker.sock:/var/run/docker.sock \
-w /go/src/github.com/fairDataSociety/fairOS-dfs \
ghcr.io/goreleaser/goreleaser-cross:v1.20.2 release --rm-dist
ghcr.io/goreleaser/goreleaser-cross:v1.21.0 release --rm-dist

.PHONY: release-dry-run
release-dry-run:
Expand All @@ -84,7 +84,7 @@ release-dry-run:
-v `pwd`:/go/src/github.com/fairDataSociety/fairOS-dfs \
-v /var/run/docker.sock:/var/run/docker.sock \
-w /go/src/github.com/fairDataSociety/fairOS-dfs \
ghcr.io/goreleaser/goreleaser-cross:v1.20.2 release --rm-dist \
ghcr.io/goreleaser/goreleaser-cross:v1.21.0 release --rm-dist \
--skip-validate=true \
--skip-publish

Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,14 @@ the blockchain as ens record. whenever a user created a pod for himself, a new k
is created using this mnemonic.

## What is a pod?
A pod is a personal drive created by a user in fairOS-dfs. It is used to store files and related metadata in a decentralised fashion. A pod is always under the control of the user who created it. A user can create and store any number of files or directories in a pod.
A pod is a personal drive created by a user. It is used to store files and related metadata in a decentralised fashion. A pod is always under the control of the user who created it. A user can create and store any number of files or directories in a pod.
The user can share files in his pod with any other user just like in other centralised drives like dropbox. Not only users, a pod can be used by decentralised applications (DApp's) to store data related to that user.

Pod creation is cheap. A user can create multiple pods and use it to organise his data. for ex: Personal-Pod, Applications-Pod etc.

## (NEW) What is a group?
A group is a shared drive created by a user. It is basically a pod, but on steroids. Group Owner can add members and update permissions. Members with "write" permission can create and store any number of files or directories in a group.

## How to run FairOS-dfs?
Run the following command to download the latest release

Expand Down Expand Up @@ -197,4 +200,4 @@ network: "testnet"
bee:
bee-api-endpoint: http://localhost:1633 # bee running on mainnet
postage-batch-id: <BATCH>
```
```
8 changes: 5 additions & 3 deletions cmd/common/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ type PodReceiveRequest struct {
// FileSystemRequest is the request body for file system operations
type FileSystemRequest struct {
PodName string `json:"podName,omitempty"`
GroupName string `json:"groupName,omitempty"`
DirectoryPath string `json:"dirPath,omitempty"`
DirectoryName string `json:"dirName,omitempty"`
FilePath string `json:"filePath,omitempty"`
Expand All @@ -62,9 +63,10 @@ type FileSystemRequest struct {

// RenameRequest is the request body for file rename
type RenameRequest struct {
PodName string `json:"podName,omitempty"`
OldPath string `json:"oldPath,omitempty"`
NewPath string `json:"newPath,omitempty"`
PodName string `json:"podName,omitempty"`
GroupName string `json:"groupName,omitempty"`
OldPath string `json:"oldPath,omitempty"`
NewPath string `json:"newPath,omitempty"`
}

// FileReceiveRequest is the request body for file receiving
Expand Down
38 changes: 19 additions & 19 deletions cmd/dfs-cli/cmd/fdfs-api.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ const (

// fdfsClient is the http client for dfs
type fdfsClient struct {
url string
client *http.Client
cookie *http.Cookie
url string
client *http.Client
accessToken string
}

func newFdfsClient(fdfsServer string) (*fdfsClient, error) {
Expand Down Expand Up @@ -97,6 +97,14 @@ func (s *fdfsClient) CheckConnection() bool {
return err == nil
}

func (s *fdfsClient) setAccessToken(token string) {
s.accessToken = token
}

func (s *fdfsClient) getAccessToken() string {
return s.accessToken
}

func (s *fdfsClient) postReq(method, urlPath string, jsonBytes []byte) ([]byte, error) {
// prepare the request
fullUrl := fmt.Sprintf(s.url + urlPath)
Expand All @@ -118,8 +126,8 @@ func (s *fdfsClient) postReq(method, urlPath string, jsonBytes []byte) ([]byte,
}
}

if s.cookie != nil {
req.AddCookie(s.cookie)
if s.getAccessToken() != "" {
req.Header.Add("Authorization", "Bearer "+s.getAccessToken())
}
// execute the request
response, err := s.client.Do(req)
Expand Down Expand Up @@ -150,10 +158,6 @@ func (s *fdfsClient) postReq(method, urlPath string, jsonBytes []byte) ([]byte,
return nil, errors.New(resp.Message)
}

if len(response.Cookies()) > 0 {
s.cookie = response.Cookies()[0]
}

data, err := io.ReadAll(response.Body)
if err != nil {
return nil, errors.New("error downloading data")
Expand Down Expand Up @@ -190,8 +194,8 @@ func (s *fdfsClient) getReq(urlPath, argsString string) ([]byte, error) {
}
}

if s.cookie != nil {
req.AddCookie(s.cookie)
if s.getAccessToken() != "" {
req.Header.Add("Authorization", "Bearer "+s.getAccessToken())
}

// execute the request
Expand Down Expand Up @@ -219,10 +223,6 @@ func (s *fdfsClient) getReq(urlPath, argsString string) ([]byte, error) {
return nil, errors.New(resp.Message)
}

if len(response.Cookies()) > 0 {
s.cookie = response.Cookies()[0]
}

data, err := io.ReadAll(response.Body)
if err != nil {
return nil, errors.New("error downloading data")
Expand Down Expand Up @@ -283,8 +283,8 @@ func (s *fdfsClient) uploadMultipartFile(urlPath, fileName string, fileSize int6
req.Header.Set(api.CompressionHeader, compValue)
}

if s.cookie != nil {
req.AddCookie(s.cookie)
if s.getAccessToken() != "" {
req.Header.Add("Authorization", "Bearer "+s.getAccessToken())
}

// execute the request
Expand Down Expand Up @@ -338,8 +338,8 @@ func (s *fdfsClient) downloadMultipartFile(method, urlPath string, arguments map
req.Header.Add("Content-Type", contentType)
req.Header.Add("Content-Length", strconv.Itoa(len(body.Bytes())))

if s.cookie != nil {
req.AddCookie(s.cookie)
if s.getAccessToken() != "" {
req.Header.Add("Authorization", "Bearer "+s.getAccessToken())
}

// execute the request
Expand Down
10 changes: 9 additions & 1 deletion cmd/dfs-cli/cmd/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,19 @@ func initPrompt() {
prompt.OptionPrefix(currentPrompt),
prompt.OptionLivePrefix(changeLivePrefix),
prompt.OptionTitle("dfs"),
prompt.OptionSetExitCheckerOnInput(exitChecker),
)
p.Run()
}

func exitChecker(in string, breakline bool) bool {
if breakline && strings.TrimSpace(in) == "exit" {
fmt.Println("exiting dfs-cli")
return true
}
return false
}

func changeLivePrefix() (string, bool) {
return currentPrompt, true
}
Expand Down Expand Up @@ -261,7 +270,6 @@ func executor(in string) {
case "help":
help()
case "exit":
os.Exit(0)
case "user":
if len(blocks) < 2 {
log.Println("invalid command.")
Expand Down
14 changes: 13 additions & 1 deletion cmd/dfs-cli/cmd/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func userNew(userName, mnemonic string) {
}
if resp.Message == eth.ErrInsufficientBalance.Error() {
fmt.Println("Failed to create new user")
fmt.Println("Please fund your account with some eth and try again with the following command")
fmt.Println("Please fund your account with some eth and try again with the following command. This is not related with bee wallet")
fmt.Printf(">>> user new %s %s\n", userName, resp.Mnemonic)
fmt.Println("address :", resp.Address)
fmt.Println("=============== Mnemonic ==========================")
Expand All @@ -66,6 +66,9 @@ func userNew(userName, mnemonic string) {
fmt.Println("Please store the 12 words mnemonic safely")
fmt.Println("if you loose that, you cannot recover the data in-case of an emergency.")
fmt.Println("you can also use that mnemonic to access the data in-case this device is lost")

fdfsAPI.setAccessToken(resp.AccessToken)

currentUser = userName
}

Expand All @@ -85,8 +88,17 @@ func userLogin(userName, apiEndpoint string) {
fmt.Println("login user: ", err)
return
}
var resp api.UserSignupResponse
err = json.Unmarshal(data, &resp)
if err != nil {
fmt.Println("create user: ", err)
return
}

currentUser = userName
message := strings.ReplaceAll(string(data), "\n", "")
fdfsAPI.setAccessToken(resp.AccessToken)

fmt.Println(message)
}

Expand Down
2 changes: 0 additions & 2 deletions cmd/dfs/cmd/commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,6 @@ func Test_ExecuteCommand(t *testing.T) {

rootCmd.SetArgs([]string{
"server",
"--ens-network",
"play",
"--beeHost",
"http://localhost:1633",
"--rpc",
Expand Down
2 changes: 2 additions & 0 deletions cmd/dfs/cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ var (
optionVerbosity = "verbosity"
optionBeeApi = "bee.bee-api-endpoint"
optionBeePostageBatchId = "bee.postage-batch-id"
optionFeedCacheSize = "feed.cache-size"
optionFeedCacheTTL = "feed.cache-ttl"
optionCookieDomain = "cookie-domain"
optionNetwork = "ens-network"
optionRPC = "rpc"
Expand Down
Loading

0 comments on commit 8a4b433

Please sign in to comment.