Skip to content

Commit

Permalink
Docs (#46)
Browse files Browse the repository at this point in the history
* added openapi docs

* fix bugs during testing
  • Loading branch information
jmozah authored Feb 8, 2021
1 parent 6050537 commit 9a3419d
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 43 deletions.
28 changes: 7 additions & 21 deletions cmd/dfs-cli/cmd/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ import (
"encoding/json"
"errors"
"fmt"

"github.com/fairdatasociety/fairOS-dfs/pkg/collection"
"github.com/fairdatasociety/fairOS-dfs/pkg/pod"

"io/ioutil"
"log"
"net/http"
Expand All @@ -36,8 +32,10 @@ import (

"github.com/c-bata/go-prompt"
"github.com/fairdatasociety/fairOS-dfs/pkg/api"
"github.com/fairdatasociety/fairOS-dfs/pkg/collection"
"github.com/fairdatasociety/fairOS-dfs/pkg/dir"
"github.com/fairdatasociety/fairOS-dfs/pkg/file"
"github.com/fairdatasociety/fairOS-dfs/pkg/pod"
"github.com/fairdatasociety/fairOS-dfs/pkg/user"
"github.com/fairdatasociety/fairOS-dfs/pkg/utils"
"github.com/tinygrasshopper/bettercsv"
Expand Down Expand Up @@ -161,7 +159,6 @@ var suggestions = []prompt.Suggest{
{Text: "user login", Description: "login to a existing user"},
{Text: "user logout", Description: "logout from a logged in user"},
{Text: "user present", Description: "is user present"},
{Text: "user ls", Description: "list all users"},
{Text: "user name", Description: "sets and gets the user name information"},
{Text: "user contact", Description: "sets and gets the user contact information"},
{Text: "user share inbox", Description: "gets the information about the files received by the user"},
Expand Down Expand Up @@ -368,16 +365,6 @@ func executor(in string) {
fmt.Println("User is not present")
}
currentPrompt = getCurrentPrompt()
case "ls":
//users, err := dfsAPI.ListAllUsers()
//if err != nil {
// fmt.Println("user ls: ", err)
// return
//}
//for _, usr := range users {
// fmt.Println(usr)
//}
currentPrompt = getCurrentPrompt()
case "del":
if currentUser == "" {
fmt.Println("please login as user to do the operation")
Expand Down Expand Up @@ -474,7 +461,7 @@ func executor(in string) {
fmt.Println("please login as user to do the operation")
return
}
if len(blocks) == 8 {
if len(blocks) > 2 {
phone := blocks[2]
mobile := blocks[3]
addressLine1 := blocks[4]
Expand Down Expand Up @@ -863,7 +850,7 @@ func executor(in string) {
podSharingReference := blocks[2]
args := make(map[string]string)
args["ref"] = podSharingReference
data, err := fdfsAPI.callFdfsApi(http.MethodPost, apiPodReceive, args)
data, err := fdfsAPI.callFdfsApi(http.MethodGet, apiPodReceive, args)
if err != nil {
fmt.Println("pod receive failed: ", err)
return
Expand All @@ -879,7 +866,7 @@ func executor(in string) {
podSharingReference := blocks[2]
args := make(map[string]string)
args["ref"] = podSharingReference
data, err := fdfsAPI.callFdfsApi(http.MethodPost, apiPodReceiveInfo, args)
data, err := fdfsAPI.callFdfsApi(http.MethodGet, apiPodReceiveInfo, args)
if err != nil {
fmt.Println("pod receive info failed: ", err)
return
Expand Down Expand Up @@ -1915,7 +1902,7 @@ func executor(in string) {
args := make(map[string]string)
args["ref"] = sharingRefString
args["dir"] = podDir
data, err := fdfsAPI.callFdfsApi(http.MethodPost, apiFileReceive, args)
data, err := fdfsAPI.callFdfsApi(http.MethodGet, apiFileReceive, args)
if err != nil {
fmt.Println("receive: ", err)
return
Expand All @@ -1937,7 +1924,7 @@ func executor(in string) {
sharingRefString := blocks[1]
args := make(map[string]string)
args["ref"] = sharingRefString
data, err := fdfsAPI.callFdfsApi(http.MethodPost, apiFileReceiveInfo, args)
data, err := fdfsAPI.callFdfsApi(http.MethodGet, apiFileReceiveInfo, args)
if err != nil {
fmt.Println("receive info: ", err)
return
Expand Down Expand Up @@ -1982,7 +1969,6 @@ func help() {
fmt.Println(" - user <login> (user-name) - login as a given user")
fmt.Println(" - user <logout> - logout a logged in user")
fmt.Println(" - user <present> (user-name) - returns true if the user is present, false otherwise")
fmt.Println(" - user <ls> - lists all the user present in this instance")
fmt.Println(" - user <name> (first_name) (middle_name) (last_name) (surname) - sets the user name information")
fmt.Println(" - user <name> - gets the user name information")
fmt.Println(" - user <contact> (phone) (mobile) (address_line1) (address_line2) (state) (zipcode) - sets the user contact information")
Expand Down
16 changes: 8 additions & 8 deletions cmd/dfs-cli/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ var rootCmd = &cobra.Command{
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
fdfsCli := `
/$$$$$$ /$$ /$$$$$$ /$$ /$$
/$$__ $$ | $$ /$$__ $$ | $$|__/
| $$ \__//$$$$$$$| $$ \__//$$$$$$$ /$$$$$$$| $$ /$$
| $$$$ /$$__ $$| $$$$ /$$_____//$$$$$$ /$$_____/| $$| $$
| $$_/ | $$ | $$| $$_/ | $$$$$$|______/| $$ | $$| $$
| $$ | $$ | $$| $$ \____ $$ | $$ | $$| $$
| $$ | $$$$$$$| $$ /$$$$$$$/ | $$$$$$$| $$| $$
|__/ \_______/|__/ |_______/ \_______/|__/|__/
/$$ /$$$$$$ /$$ /$$
| $$ /$$__ $$ | $$|__/
/$$$$$$$| $$ \__//$$$$$$$ /$$$$$$$| $$ /$$
/$$__ $$| $$$$ /$$_____//$$$$$$ /$$_____/| $$| $$
| $$ | $$| $$_/ | $$$$$$|______/| $$ | $$| $$
| $$ | $$| $$ \____ $$ | $$ | $$| $$
| $$$$$$$| $$ /$$$$$$$/ | $$$$$$$| $$| $$
\_______/|__/ |_______/ \_______/|__/|__/
`
fmt.Println(fdfsCli)
if err := rootCmd.Execute(); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions cmd/dfs/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ func init() {

defaultDataDir := filepath.Join(home, ".fairOS/dfs")
rootCmd.PersistentFlags().StringVar(&dataDir, "dataDir", defaultDataDir, "store data in this dir")
rootCmd.PersistentFlags().StringVar(&beeHost, "beeHost", "127.0.0.1", "bee host (default 127.0.0.1)")
rootCmd.PersistentFlags().StringVar(&beePort, "beePort", "8080", "bee port")
rootCmd.PersistentFlags().StringVar(&beeHost, "beeHost", "127.0.0.1", "bee host")
rootCmd.PersistentFlags().StringVar(&beePort, "beePort", "1633", "bee port")
rootCmd.PersistentFlags().StringVar(&verbosity, "verbosity", "5", "verbosity level")
}

Expand Down
23 changes: 18 additions & 5 deletions cmd/dfs/cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (

var (
httpPort string
pprofPort string
cookieDomain string
corsOrigins []string
handler *api.Handler
Expand Down Expand Up @@ -72,6 +73,7 @@ can consume it.`,
logger.Info("beePort : ", beePort)
logger.Info("verbosity : ", verbosity)
logger.Info("httpPort : ", httpPort)
logger.Info("pprofPort : ", pprofPort)
logger.Info("cookieDomain : ", cookieDomain)
logger.Info("corsOrigins : ", corsOrigins)
hdlr, err := api.NewHandler(dataDir, beeHost, beePort, cookieDomain, logger)
Expand All @@ -86,6 +88,7 @@ can consume it.`,

func init() {
serverCmd.Flags().StringVar(&httpPort, "httpPort", "9090", "http port")
serverCmd.Flags().StringVar(&pprofPort, "pprofPort", "9091", "pprof port")
serverCmd.Flags().StringVar(&cookieDomain, "cookieDomain", "api.fairos.io", "the domain to use in the cookie")
serverCmd.Flags().StringSliceVar(&corsOrigins, "cors-origins", []string{}, "allow CORS headers for the given origins")
rootCmd.AddCommand(serverCmd)
Expand Down Expand Up @@ -147,8 +150,8 @@ func startHttpService(logger logging.Logger) {
userRouter.HandleFunc("/share/outbox", handler.GetUserSharingOutboxHandler).Methods("GET")

// pod related handlers
baseRouter.HandleFunc("/pod/receive", handler.PodReceiveHandler).Methods("POST")
baseRouter.HandleFunc("/pod/receiveinfo", handler.PodReceiveInfoHandler).Methods("POST")
baseRouter.HandleFunc("/pod/receive", handler.PodReceiveHandler).Methods("GET")
baseRouter.HandleFunc("/pod/receiveinfo", handler.PodReceiveInfoHandler).Methods("GET")
podRouter := baseRouter.PathPrefix("/pod/").Subrouter()
podRouter.Use(handler.LoginMiddleware)
podRouter.Use(handler.LogMiddleware)
Expand Down Expand Up @@ -178,8 +181,8 @@ func startHttpService(logger logging.Logger) {
fileRouter.HandleFunc("/download", handler.FileDownloadHandler).Methods("POST")
fileRouter.HandleFunc("/upload", handler.FileUploadHandler).Methods("POST")
fileRouter.HandleFunc("/share", handler.FileShareHandler).Methods("POST")
fileRouter.HandleFunc("/receive", handler.FileReceiveHandler).Methods("POST")
fileRouter.HandleFunc("/receiveinfo", handler.FileReceiveInfoHandler).Methods("POST")
fileRouter.HandleFunc("/receive", handler.FileReceiveHandler).Methods("GET")
fileRouter.HandleFunc("/receiveinfo", handler.FileReceiveInfoHandler).Methods("GET")
fileRouter.HandleFunc("/delete", handler.FileDeleteHandler).Methods("DELETE")
fileRouter.HandleFunc("/stat", handler.FileStatHandler).Methods("GET")

Expand Down Expand Up @@ -230,10 +233,20 @@ func startHttpService(logger logging.Logger) {
// Insert the middleware
handler := c.Handler(router)

// starting the pprof server
go func() {
logger.Infof("fairOS-dfs pprof listening on port: %v", pprofPort)
err := http.ListenAndServe("localhost:" + pprofPort, nil)
if err != nil {
logger.Errorf("pprof listenAndServe: %v ", err.Error())
return
}
}()

logger.Infof("fairOS-dfs API server listening on port: %v", httpPort)
err := http.ListenAndServe(":"+httpPort, handler)
if err != nil {
logger.Errorf("listenAndServe: %v ", err.Error())
logger.Errorf("http listenAndServe: %v ", err.Error())
return
}
}
5 changes: 0 additions & 5 deletions cmd/dfs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,9 @@ package main

import (
cmd2 "github.com/fairdatasociety/fairOS-dfs/cmd/dfs/cmd"
"log"
"net/http"
_ "net/http/pprof"
)

func main() {
go func() {
log.Println(http.ListenAndServe("localhost:9091", nil))
}()
cmd2.Execute()
}
3 changes: 3 additions & 0 deletions pkg/api/pod_open.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,11 @@ func (h *Handler) PodOpenHandler(w http.ResponseWriter, r *http.Request) {
return
}

// password will be empty in case of opening a shared pod
// so allow even if it is not set
password := r.FormValue("password")


// get values from cookie
sessionId, err := cookie.GetSessionIdFromCookie(r)
if err != nil {
Expand Down
5 changes: 4 additions & 1 deletion pkg/collection/document.go
Original file line number Diff line number Diff line change
Expand Up @@ -1188,7 +1188,10 @@ func (d *Document) DocBatchPut(docBatch *DocBatch, doc []byte, index int64) erro
switch v := v.(type) {
case float64:
if field == DefaultIndexFieldName {
valStr1 = fmt.Sprintf("%g", v)
if v == 2093751843 {
fmt.Println("debug")
}
valStr1 = fmt.Sprintf("%d", int64(v))
} else {
valStr1 = fmt.Sprintf("%020.20g", v)
}
Expand Down
8 changes: 8 additions & 0 deletions pkg/file/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,16 @@ func (r *Reader) ReadLine() ([]byte, error) {
buf := make([]byte, r.blockSize)
n, err := r.Read(buf)
if err != nil {
if errors.Is(err, io.EOF){
if buf[n-1] != '\n' {
return nil, err
} else {
goto SUCC
}
}
return nil, err
}
SUCC:
r.rlBuffer = buf[:n]
r.rlOffset = 0
}
Expand Down
2 changes: 1 addition & 1 deletion version.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
package dfs

var (
version = "0.3.0" // manually set semantic version number
version = "0.2.1" // manually set semantic version number
commit string // automatically set git commit hash

Version = func() string {
Expand Down

0 comments on commit 9a3419d

Please sign in to comment.