Skip to content

Commit

Permalink
Support for GROUP command
Browse files Browse the repository at this point in the history
  • Loading branch information
aborroy committed May 12, 2023
1 parent c249e3f commit 8f4aae9
Show file tree
Hide file tree
Showing 29 changed files with 986 additions and 34 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ $(DARWIN):
env GOOS=darwin GOARCH=arm64 go build -v -o $(DARWIN) -ldflags="-s -w -X main.version=$(VERSION)" ./alfresco.go

test:
cd test && ./test_node.sh && ./test_people.sh
cd test && ./test_node.sh && ./test_people.sh && ./test_group.sh

docs:
cd docs/generate && go build generate.go && ./generate
Expand Down
38 changes: 7 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,19 @@ Using `-h` flag provides detail on the use of the different commands available:

```
$ ./alfresco -h
A Command Line Interface for Alfresco Content Services.
Alfresco CLI provides access to Alfresco REST API services via command line.
A running ACS server is required to use this program (commonly available in http://localhost:8080/alfresco).
Usage:
alfresco [command]
Available Commands:
completion Generate the autocompletion script for the specified shell
config Connection details
config Manage ACS connection details
group Manage groups in ACS Repository
help Help about any command
node Manage nodes
node Manage nodes in ACS Repository
people Manage people in ACS Repository
Flags:
-h, --help help for alfresco
Expand Down Expand Up @@ -79,32 +82,6 @@ $ tail -f alfresco.log
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
```

## Commands

**Node**

The `node` command provides access to Node handling in Alfresco Repository.

```
./alfresco node -h
Manage nodes
Usage:
alfresco node [command]
Available Commands:
create Create new Node
delete Delete Node
download-folder Download Alfresco Repository folder to local folder
get Get Node information (properties and content)
list Get children nodes
update Update Node information
upload-folder Upload local folder to Alfresco Repository
Flags:
-i, --nodeId string Node Id in Alfresco Repository
```

## Generic flags

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

## Documentation

Detailed documentation is available in [docs/alfresco.md](docs/alfresco.md)
Detailed documentation for available commands in [docs/alfresco.md](docs/alfresco.md)

## TODO

* Site commands
* Group commands
* Search commands
* Provide pre-built programs for Windows, Linux, Mac AMD64 & Mac ARM64
* Control concurrency rate
1 change: 1 addition & 0 deletions alfresco.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/aborroy/alfresco-cli/cmd"
_ "github.com/aborroy/alfresco-cli/cmd/config"
_ "github.com/aborroy/alfresco-cli/cmd/group"
_ "github.com/aborroy/alfresco-cli/cmd/node"
_ "github.com/aborroy/alfresco-cli/cmd/people"
)
Expand Down
55 changes: 55 additions & 0 deletions cmd/group/add.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package group

import (
"encoding/json"
"log"
"net/http"

"github.com/aborroy/alfresco-cli/cmd"
"github.com/aborroy/alfresco-cli/httpclient"
"github.com/spf13/cobra"
)

const AddGroupCmdId string = "[GROUP ADD]"

var authorityId string
var authorityType string
var groupAddCmd = &cobra.Command{
Use: "add",
Short: "Add an authority (person or group) to a Group in repository",
Long: `The authority is added as children of the Group.`,
Run: func(command *cobra.Command, args []string) {

var groupAdd GroupAdd
groupAdd.ID = authorityId
groupAdd.MemberType = authorityType
jsonGroupAdd, _ := json.Marshal(groupAdd)

execution := &httpclient.HttpExecution{
Method: http.MethodPost,
Data: string(jsonGroupAdd),
Format: httpclient.Json,
Url: groupsUrlPath + groupId + "/members",
ResponseBodyOutput: &responseBody,
}

_error := httpclient.Execute(execution)
if _error != nil {
cmd.ExitWithError(AddGroupCmdId, _error)
}
},
PostRun: func(command *cobra.Command, args []string) {
log.Println(AddGroupCmdId, "Authority "+authorityId+" ("+authorityType+") has been added to group "+groupId)
},
}

func init() {
groupCmd.AddCommand(groupAddCmd)
groupAddCmd.Flags().StringVarP(&groupId, "groupId", "i", "", "ID of the group in Alfresco Repository.")
groupAddCmd.Flags().StringVarP(&authorityId, "authorityId", "a", "", "ID of the authority (group or person) in Alfresco Repository to be added.")
groupAddCmd.Flags().StringVarP(&authorityType, "authorityType", "t", "", "Type of the authority: GROUP or PERSON.")
groupAddCmd.Flags().SortFlags = false
groupAddCmd.MarkFlagRequired("groupId")
groupAddCmd.MarkFlagRequired("authorityId")
groupAddCmd.MarkFlagRequired("authorityType")
}
60 changes: 60 additions & 0 deletions cmd/group/create.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package group

import (
"encoding/json"
"log"
"net/http"
"strings"

"github.com/aborroy/alfresco-cli/cmd"
"github.com/aborroy/alfresco-cli/httpclient"
"github.com/spf13/cobra"
)

const CreateGroupCmdId string = "[GROUP CREATE]"

var displayName string
var parentIds []string
var groupCreateCmd = &cobra.Command{
Use: "create",
Short: "Create new Group in ACS Repository",
Long: `Creates a new group in the repository.
The group can be created setting only required properties.
When specifying parentIds, the group is created associated to those parentIds, not as a children of them.`,
Run: func(command *cobra.Command, args []string) {

var groupCreate GroupUpdate
groupCreate.ID = groupId
groupCreate.DisplayName = displayName
if parentIds != nil {
groupCreate.ParentIds = parentIds
}
jsonGroupCreate, _ := json.Marshal(groupCreate)

execution := &httpclient.HttpExecution{
Method: http.MethodPost,
Data: string(jsonGroupCreate),
Format: httpclient.Json,
Url: strings.TrimSuffix(groupsUrlPath, "/"),
ResponseBodyOutput: &responseBody,
}

_error := httpclient.Execute(execution)
if _error != nil {
cmd.ExitWithError(CreateGroupCmdId, _error)
}
},
PostRun: func(command *cobra.Command, args []string) {
log.Println(CreateGroupCmdId, "Group "+groupId+" has been created")
},
}

func init() {
groupCmd.AddCommand(groupCreateCmd)
groupCreateCmd.Flags().StringVarP(&groupId, "groupId", "i", "", "ID of the group in Alfresco Repository.")
groupCreateCmd.Flags().StringVarP(&displayName, "displayName", "d", "", "Display name of the group in Alfresco Repository.")
groupCreateCmd.Flags().StringArrayVarP(&parentIds, "parentIds", "p", nil, "List containing the IDs of parent groups.")
groupCreateCmd.Flags().SortFlags = false
groupCreateCmd.MarkFlagRequired("groupId")

}
39 changes: 39 additions & 0 deletions cmd/group/delete.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package group

import (
"log"
"net/http"

"github.com/aborroy/alfresco-cli/cmd"
"github.com/aborroy/alfresco-cli/httpclient"
"github.com/spf13/cobra"
)

const DeleteGroupCmdId string = "[GROUP DELETE]"

var groupDeleteCmd = &cobra.Command{
Use: "delete",
Short: "Delete a Group existing in the repository",
Long: `Removes an existing group from the repository.`,
Run: func(command *cobra.Command, args []string) {
execution := &httpclient.HttpExecution{
Method: http.MethodDelete,
Format: httpclient.None,
Url: groupsUrlPath + groupId,
ResponseBodyOutput: &responseBody,
}
_error := httpclient.Execute(execution)
if _error != nil {
cmd.ExitWithError(DeleteGroupCmdId, _error)
}
},
PostRun: func(command *cobra.Command, args []string) {
log.Println(DeleteGroupCmdId, "Group "+groupId+" has been deleted")
},
}

func init() {
groupCmd.AddCommand(groupDeleteCmd)
groupDeleteCmd.Flags().StringVarP(&groupId, "groupId", "i", "", "ID of the group in Alfresco Repository.")
groupDeleteCmd.MarkFlagRequired("groupId")
}
40 changes: 40 additions & 0 deletions cmd/group/get.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package group

import (
"log"
"net/http"

"github.com/aborroy/alfresco-cli/cmd"
"github.com/aborroy/alfresco-cli/httpclient"
"github.com/spf13/cobra"
)

const GetGroupCmdId string = "[GROUP GET]"

var groupGetCmd = &cobra.Command{
Use: "get",
Short: "Get Group information from repository",
Long: `Properties of the Group are retrieved.
Properties are provided as output of the command.`,
Run: func(command *cobra.Command, args []string) {
execution := &httpclient.HttpExecution{
Method: http.MethodGet,
Format: httpclient.None,
Url: groupsUrlPath + groupId,
ResponseBodyOutput: &responseBody,
}
_error := httpclient.Execute(execution)
if _error != nil {
cmd.ExitWithError(GetGroupCmdId, _error)
}
},
PostRun: func(command *cobra.Command, args []string) {
log.Println(GetGroupCmdId, "Details for group "+groupId+" have been retrieved")
},
}

func init() {
groupCmd.AddCommand(groupGetCmd)
groupGetCmd.Flags().StringVarP(&groupId, "groupId", "i", "", "ID of the group in Alfresco Repository.")
groupGetCmd.MarkFlagRequired("groupId")
}
Loading

0 comments on commit 8f4aae9

Please sign in to comment.