Skip to content

Commit 8f4aae9

Browse files
committed
Support for GROUP command
1 parent c249e3f commit 8f4aae9

29 files changed

+986
-34
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ $(DARWIN):
2727
env GOOS=darwin GOARCH=arm64 go build -v -o $(DARWIN) -ldflags="-s -w -X main.version=$(VERSION)" ./alfresco.go
2828

2929
test:
30-
cd test && ./test_node.sh && ./test_people.sh
30+
cd test && ./test_node.sh && ./test_people.sh && ./test_group.sh
3131

3232
docs:
3333
cd docs/generate && go build generate.go && ./generate

README.md

+7-31
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,19 @@ Using `-h` flag provides detail on the use of the different commands available:
1111

1212
```
1313
$ ./alfresco -h
14-
A Command Line Interface for Alfresco Content Services.
14+
Alfresco CLI provides access to Alfresco REST API services via command line.
15+
A running ACS server is required to use this program (commonly available in http://localhost:8080/alfresco).
1516
1617
Usage:
1718
alfresco [command]
1819
1920
Available Commands:
2021
completion Generate the autocompletion script for the specified shell
21-
config Connection details
22+
config Manage ACS connection details
23+
group Manage groups in ACS Repository
2224
help Help about any command
23-
node Manage nodes
25+
node Manage nodes in ACS Repository
26+
people Manage people in ACS Repository
2427
2528
Flags:
2629
-h, --help help for alfresco
@@ -79,32 +82,6 @@ $ tail -f alfresco.log
7982
2023/04/28 10:12:56 ERROR [NODE CREATE] Post "http://localhost:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/4960a8a5-a258-4fed-84b4-73ae8cf9b2de/children": EOF
8083
```
8184

82-
## Commands
83-
84-
**Node**
85-
86-
The `node` command provides access to Node handling in Alfresco Repository.
87-
88-
```
89-
./alfresco node -h
90-
Manage nodes
91-
92-
Usage:
93-
alfresco node [command]
94-
95-
Available Commands:
96-
create Create new Node
97-
delete Delete Node
98-
download-folder Download Alfresco Repository folder to local folder
99-
get Get Node information (properties and content)
100-
list Get children nodes
101-
update Update Node information
102-
upload-folder Upload local folder to Alfresco Repository
103-
104-
Flags:
105-
-i, --nodeId string Node Id in Alfresco Repository
106-
```
107-
10885
## Generic flags
10986

11087
```
@@ -173,12 +150,11 @@ Sample bash scripts for testing purposes are provided in [test](test) folder.
173150

174151
## Documentation
175152

176-
Detailed documentation is available in [docs/alfresco.md](docs/alfresco.md)
153+
Detailed documentation for available commands in [docs/alfresco.md](docs/alfresco.md)
177154

178155
## TODO
179156

180157
* Site commands
181-
* Group commands
182158
* Search commands
183159
* Provide pre-built programs for Windows, Linux, Mac AMD64 & Mac ARM64
184160
* Control concurrency rate

alfresco.go

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

77
"github.com/aborroy/alfresco-cli/cmd"
88
_ "github.com/aborroy/alfresco-cli/cmd/config"
9+
_ "github.com/aborroy/alfresco-cli/cmd/group"
910
_ "github.com/aborroy/alfresco-cli/cmd/node"
1011
_ "github.com/aborroy/alfresco-cli/cmd/people"
1112
)

cmd/group/add.go

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package group
2+
3+
import (
4+
"encoding/json"
5+
"log"
6+
"net/http"
7+
8+
"github.com/aborroy/alfresco-cli/cmd"
9+
"github.com/aborroy/alfresco-cli/httpclient"
10+
"github.com/spf13/cobra"
11+
)
12+
13+
const AddGroupCmdId string = "[GROUP ADD]"
14+
15+
var authorityId string
16+
var authorityType string
17+
var groupAddCmd = &cobra.Command{
18+
Use: "add",
19+
Short: "Add an authority (person or group) to a Group in repository",
20+
Long: `The authority is added as children of the Group.`,
21+
Run: func(command *cobra.Command, args []string) {
22+
23+
var groupAdd GroupAdd
24+
groupAdd.ID = authorityId
25+
groupAdd.MemberType = authorityType
26+
jsonGroupAdd, _ := json.Marshal(groupAdd)
27+
28+
execution := &httpclient.HttpExecution{
29+
Method: http.MethodPost,
30+
Data: string(jsonGroupAdd),
31+
Format: httpclient.Json,
32+
Url: groupsUrlPath + groupId + "/members",
33+
ResponseBodyOutput: &responseBody,
34+
}
35+
36+
_error := httpclient.Execute(execution)
37+
if _error != nil {
38+
cmd.ExitWithError(AddGroupCmdId, _error)
39+
}
40+
},
41+
PostRun: func(command *cobra.Command, args []string) {
42+
log.Println(AddGroupCmdId, "Authority "+authorityId+" ("+authorityType+") has been added to group "+groupId)
43+
},
44+
}
45+
46+
func init() {
47+
groupCmd.AddCommand(groupAddCmd)
48+
groupAddCmd.Flags().StringVarP(&groupId, "groupId", "i", "", "ID of the group in Alfresco Repository.")
49+
groupAddCmd.Flags().StringVarP(&authorityId, "authorityId", "a", "", "ID of the authority (group or person) in Alfresco Repository to be added.")
50+
groupAddCmd.Flags().StringVarP(&authorityType, "authorityType", "t", "", "Type of the authority: GROUP or PERSON.")
51+
groupAddCmd.Flags().SortFlags = false
52+
groupAddCmd.MarkFlagRequired("groupId")
53+
groupAddCmd.MarkFlagRequired("authorityId")
54+
groupAddCmd.MarkFlagRequired("authorityType")
55+
}

cmd/group/create.go

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package group
2+
3+
import (
4+
"encoding/json"
5+
"log"
6+
"net/http"
7+
"strings"
8+
9+
"github.com/aborroy/alfresco-cli/cmd"
10+
"github.com/aborroy/alfresco-cli/httpclient"
11+
"github.com/spf13/cobra"
12+
)
13+
14+
const CreateGroupCmdId string = "[GROUP CREATE]"
15+
16+
var displayName string
17+
var parentIds []string
18+
var groupCreateCmd = &cobra.Command{
19+
Use: "create",
20+
Short: "Create new Group in ACS Repository",
21+
Long: `Creates a new group in the repository.
22+
The group can be created setting only required properties.
23+
When specifying parentIds, the group is created associated to those parentIds, not as a children of them.`,
24+
Run: func(command *cobra.Command, args []string) {
25+
26+
var groupCreate GroupUpdate
27+
groupCreate.ID = groupId
28+
groupCreate.DisplayName = displayName
29+
if parentIds != nil {
30+
groupCreate.ParentIds = parentIds
31+
}
32+
jsonGroupCreate, _ := json.Marshal(groupCreate)
33+
34+
execution := &httpclient.HttpExecution{
35+
Method: http.MethodPost,
36+
Data: string(jsonGroupCreate),
37+
Format: httpclient.Json,
38+
Url: strings.TrimSuffix(groupsUrlPath, "/"),
39+
ResponseBodyOutput: &responseBody,
40+
}
41+
42+
_error := httpclient.Execute(execution)
43+
if _error != nil {
44+
cmd.ExitWithError(CreateGroupCmdId, _error)
45+
}
46+
},
47+
PostRun: func(command *cobra.Command, args []string) {
48+
log.Println(CreateGroupCmdId, "Group "+groupId+" has been created")
49+
},
50+
}
51+
52+
func init() {
53+
groupCmd.AddCommand(groupCreateCmd)
54+
groupCreateCmd.Flags().StringVarP(&groupId, "groupId", "i", "", "ID of the group in Alfresco Repository.")
55+
groupCreateCmd.Flags().StringVarP(&displayName, "displayName", "d", "", "Display name of the group in Alfresco Repository.")
56+
groupCreateCmd.Flags().StringArrayVarP(&parentIds, "parentIds", "p", nil, "List containing the IDs of parent groups.")
57+
groupCreateCmd.Flags().SortFlags = false
58+
groupCreateCmd.MarkFlagRequired("groupId")
59+
60+
}

cmd/group/delete.go

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package group
2+
3+
import (
4+
"log"
5+
"net/http"
6+
7+
"github.com/aborroy/alfresco-cli/cmd"
8+
"github.com/aborroy/alfresco-cli/httpclient"
9+
"github.com/spf13/cobra"
10+
)
11+
12+
const DeleteGroupCmdId string = "[GROUP DELETE]"
13+
14+
var groupDeleteCmd = &cobra.Command{
15+
Use: "delete",
16+
Short: "Delete a Group existing in the repository",
17+
Long: `Removes an existing group from the repository.`,
18+
Run: func(command *cobra.Command, args []string) {
19+
execution := &httpclient.HttpExecution{
20+
Method: http.MethodDelete,
21+
Format: httpclient.None,
22+
Url: groupsUrlPath + groupId,
23+
ResponseBodyOutput: &responseBody,
24+
}
25+
_error := httpclient.Execute(execution)
26+
if _error != nil {
27+
cmd.ExitWithError(DeleteGroupCmdId, _error)
28+
}
29+
},
30+
PostRun: func(command *cobra.Command, args []string) {
31+
log.Println(DeleteGroupCmdId, "Group "+groupId+" has been deleted")
32+
},
33+
}
34+
35+
func init() {
36+
groupCmd.AddCommand(groupDeleteCmd)
37+
groupDeleteCmd.Flags().StringVarP(&groupId, "groupId", "i", "", "ID of the group in Alfresco Repository.")
38+
groupDeleteCmd.MarkFlagRequired("groupId")
39+
}

cmd/group/get.go

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package group
2+
3+
import (
4+
"log"
5+
"net/http"
6+
7+
"github.com/aborroy/alfresco-cli/cmd"
8+
"github.com/aborroy/alfresco-cli/httpclient"
9+
"github.com/spf13/cobra"
10+
)
11+
12+
const GetGroupCmdId string = "[GROUP GET]"
13+
14+
var groupGetCmd = &cobra.Command{
15+
Use: "get",
16+
Short: "Get Group information from repository",
17+
Long: `Properties of the Group are retrieved.
18+
Properties are provided as output of the command.`,
19+
Run: func(command *cobra.Command, args []string) {
20+
execution := &httpclient.HttpExecution{
21+
Method: http.MethodGet,
22+
Format: httpclient.None,
23+
Url: groupsUrlPath + groupId,
24+
ResponseBodyOutput: &responseBody,
25+
}
26+
_error := httpclient.Execute(execution)
27+
if _error != nil {
28+
cmd.ExitWithError(GetGroupCmdId, _error)
29+
}
30+
},
31+
PostRun: func(command *cobra.Command, args []string) {
32+
log.Println(GetGroupCmdId, "Details for group "+groupId+" have been retrieved")
33+
},
34+
}
35+
36+
func init() {
37+
groupCmd.AddCommand(groupGetCmd)
38+
groupGetCmd.Flags().StringVarP(&groupId, "groupId", "i", "", "ID of the group in Alfresco Repository.")
39+
groupGetCmd.MarkFlagRequired("groupId")
40+
}

0 commit comments

Comments
 (0)