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

Staging #588

Merged
merged 24 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
e50d7bd
feat: #580, change cli to use access_token for longer sessions
asabya Dec 27, 2023
0143450
minor lint fixes
asabya Jan 2, 2024
e2fb27b
Merge pull request #585 from fairDataSociety/issue580-access-token-cli
asabya Jan 2, 2024
73e9d37
create and open group
asabya Jan 9, 2024
3aab7b1
feat: member add, remove, file ops work, datahub contract update
asabya Jan 18, 2024
2c9c3b1
fix: lint
asabya Jan 18, 2024
b5cdeeb
feat: group rest apis working
asabya Feb 8, 2024
f41043c
fix: potential fix for #593
asabya Feb 9, 2024
8b3db51
Merge pull request #598 from fairDataSociety/cli-exit-593
asabya Feb 13, 2024
3f46c8a
feat: groups in wasm
asabya Feb 13, 2024
21bd5fb
chore: update readme for groups
asabya Feb 14, 2024
7a6c933
Merge pull request #592 from fairDataSociety/groups
asabya Feb 14, 2024
303bc55
chore(deps): bump github.com/ethereum/go-ethereum from 1.13.6 to 1.13.12
dependabot[bot] Feb 14, 2024
c4bdfe5
Merge pull request #601 from fairDataSociety/dependabot/go_modules/st…
asabya Feb 14, 2024
b9363b6
chore(deps): bump golang.org/x/term from 0.15.0 to 0.17.0
dependabot[bot] Feb 14, 2024
777f442
Merge pull request #600 from fairDataSociety/dependabot/go_modules/st…
asabya Feb 14, 2024
994e68b
chore(deps): bump golang.org/x/crypto from 0.17.0 to 0.19.0
dependabot[bot] Feb 14, 2024
9fa990b
Merge pull request #599 from fairDataSociety/dependabot/go_modules/st…
asabya Feb 14, 2024
9f9a82e
chore(deps): bump github.com/swaggo/swag from 1.16.2 to 1.16.3
dependabot[bot] Feb 14, 2024
5c1ca4b
Merge pull request #597 from fairDataSociety/dependabot/go_modules/st…
asabya Feb 14, 2024
5a231ab
feat: modify files/dir REST api with groupName
asabya Feb 19, 2024
a837537
feat: wasm group-files api
asabya Feb 19, 2024
0615bc1
fix test
asabya Feb 19, 2024
2dfa6b0
Merge pull request #602 from fairDataSociety/groups.1
asabya Feb 21, 2024
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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ The user can share files in his pod with any other user just like in other centr

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
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
12 changes: 12 additions & 0 deletions cmd/dfs-cli/cmd/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
15 changes: 15 additions & 0 deletions cmd/dfs/cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,21 @@ func startHttpService(logger logging.Logger) *http.Server {
podRouter.HandleFunc("/fork", handler.PodForkHandler).Methods("POST")
podRouter.HandleFunc("/fork-from-reference", handler.PodForkFromReferenceHandler).Methods("POST")

groupRouter := baseRouter.PathPrefix("/group/").Subrouter()
groupRouter.Use(handler.LoginMiddleware)
groupRouter.HandleFunc("/new", handler.GroupCreateHandler).Methods("POST")
groupRouter.HandleFunc("/ls", handler.GroupListHandler).Methods("GET")
groupRouter.HandleFunc("/delete", handler.GroupDeleteHandler).Methods("DELETE")
groupRouter.HandleFunc("/delete-shared", handler.GroupDeleteSharedHandler).Methods("DELETE")
groupRouter.HandleFunc("/accept", handler.GroupAcceptInviteHandler).Methods("POST")
groupRouter.HandleFunc("/invite", handler.GroupAddMemberHandler).Methods("POST")
groupRouter.HandleFunc("/remove", handler.GroupRemoveMemberHandler).Methods("POST")
groupRouter.HandleFunc("/update-permission", handler.GroupUpdatePermissionHandler).Methods("POST")
groupRouter.HandleFunc("/close", handler.GroupCloseHandler).Methods("POST")
groupRouter.HandleFunc("/members", handler.GroupGetMembers).Methods("GET")
groupRouter.HandleFunc("/permission", handler.GroupGetPermission).Methods("GET")
groupRouter.HandleFunc("/open", handler.GroupOpenHandler).Methods("POST")

// directory related handlers
dirRouter := baseRouter.PathPrefix("/dir/").Subrouter()
dirRouter.Use(handler.LoginMiddleware)
Expand Down
Loading
Loading