-
Notifications
You must be signed in to change notification settings - Fork 19
/
collaborators.go
107 lines (93 loc) · 2.99 KB
/
collaborators.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package cmd
import (
"fmt"
"os"
"github.com/0chain/gosdk/zboxcore/sdk"
"github.com/spf13/cobra"
)
var addCollabCmd = &cobra.Command{
Use: "add-collab",
Short: "add collaborator for a file",
Long: `add collaborator for a file`,
Args: cobra.MinimumNArgs(0),
Run: func(cmd *cobra.Command, args []string) {
allocationID := cmd.Flag("allocation").Value.String()
if len(allocationID) == 0 {
PrintError("Error: allocation flag is missing")
os.Exit(1)
}
remotepath := cmd.Flag("remotepath").Value.String()
if len(remotepath) == 0 {
PrintError("Error: remotepath flag is missing")
os.Exit(1)
}
collabID := cmd.Flag("collabid").Value.String()
if len(collabID) == 0 {
PrintError("Error: collabid flag is missing")
os.Exit(1)
}
allocationObj, err := sdk.GetAllocation(allocationID)
if err != nil {
PrintError("Error fetching the allocation", err)
os.Exit(1)
}
err = allocationObj.AddCollaborator(remotepath, collabID)
if err != nil {
PrintError(err.Error())
os.Exit(1)
}
fmt.Printf("Collaborator %s added successfully for the file %s \n", collabID, remotepath)
return
},
}
var deleteCollabCmd = &cobra.Command{
Use: "delete-collab",
Short: "delete collaborator for a file",
Long: `delete collaborator for a file`,
Args: cobra.MinimumNArgs(0),
Run: func(cmd *cobra.Command, args []string) {
allocationID := cmd.Flag("allocation").Value.String()
if len(allocationID) == 0 {
PrintError("Error: allocation flag is missing")
os.Exit(1)
}
remotepath := cmd.Flag("remotepath").Value.String()
if len(remotepath) == 0 {
PrintError("Error: remotepath flag is missing")
os.Exit(1)
}
collabID := cmd.Flag("collabid").Value.String()
if len(collabID) == 0 {
PrintError("Error: collabid flag is missing")
os.Exit(1)
}
allocationObj, err := sdk.GetAllocation(allocationID)
if err != nil {
PrintError("Error fetching the allocation", err)
os.Exit(1)
}
err = allocationObj.RemoveCollaborator(remotepath, collabID)
if err != nil {
PrintError(err.Error())
os.Exit(1)
}
fmt.Printf("Collaborator %s removed successfully for the file %s \n", collabID, remotepath)
return
},
}
func init() {
rootCmd.AddCommand(addCollabCmd)
addCollabCmd.PersistentFlags().String("allocation", "", "Allocation ID")
addCollabCmd.PersistentFlags().String("remotepath", "", "Remote path to list from")
addCollabCmd.PersistentFlags().String("collabid", "", "Collaborator's clientID")
addCollabCmd.MarkFlagRequired("allocation")
addCollabCmd.MarkFlagRequired("remotepath")
addCollabCmd.MarkFlagRequired("collabid")
rootCmd.AddCommand(deleteCollabCmd)
deleteCollabCmd.PersistentFlags().String("allocation", "", "Allocation ID")
deleteCollabCmd.PersistentFlags().String("remotepath", "", "Remote path to list from")
deleteCollabCmd.PersistentFlags().String("collabid", "", "Collaborator's clientID")
deleteCollabCmd.MarkFlagRequired("allocation")
deleteCollabCmd.MarkFlagRequired("remotepath")
deleteCollabCmd.MarkFlagRequired("collabid")
}