Skip to content
This repository has been archived by the owner on Mar 27, 2024. It is now read-only.

refactor: Rename agentd to agent-rest as to support multiple bindings #812

Merged
merged 1 commit into from
Nov 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ mocks/
*.dll
*.so
*.dylib
cmd/aries-agentd/aries-agentd
cmd/aries-agent-rest/aries-agent-rest

# Editor and go temporary files & folders
.swp
Expand Down
36 changes: 18 additions & 18 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
# SPDX-License-Identifier: Apache-2.0

GO_CMD ?= go
ARIES_AGENTD_PATH=cmd/aries-agentd
ARIES_AGENT_REST_PATH=cmd/aries-agent-rest
OPENAPI_DOCKER_IMG=quay.io/goswagger/swagger
OPENAPI_SPEC_PATH=build/rest/openapi/spec
OPENAPI_DOCKER_IMG_VERSION=v0.21.0

# Namespace for the agent images
DOCKER_OUTPUT_NS ?= aries-framework-go
AGENT_IMAGE_NAME ?= agent
AGENT_REST_IMAGE_NAME ?= agent-rest
WEBHOOK_IMAGE_NAME ?= sample-webhook

# Tool commands (overridable)
Expand Down Expand Up @@ -41,7 +41,7 @@ unit-test: mocks
@scripts/check_unit.sh

.PHONY: bdd-test
bdd-test: clean generate-test-keys agent-docker sample-webhook-docker
bdd-test: clean generate-test-keys agent-rest-docker sample-webhook-docker
@scripts/check_integration.sh

.PHONY: vc-test-suite
Expand All @@ -59,33 +59,33 @@ generate-test-keys: clean
generate-openapi-spec: clean
@echo "Generating and validating controller API specifications using Open API"
@mkdir -p build/rest/openapi/spec
@SPEC_META=$(ARIES_AGENTD_PATH) SPEC_LOC=${OPENAPI_SPEC_PATH} \
@SPEC_META=$(ARIES_AGENT_REST_PATH) SPEC_LOC=${OPENAPI_SPEC_PATH} \
DOCKER_IMAGE=$(OPENAPI_DOCKER_IMG) DOCKER_IMAGE_VERSION=$(OPENAPI_DOCKER_IMG_VERSION) \
scripts/generate-openapi-spec.sh

.PHONY: generate-openapi-demo-specs
generate-openapi-demo-specs: clean generate-openapi-spec agent-docker sample-webhook-docker
@echo "Generate demo agent controller API specifications using Open API"
generate-openapi-demo-specs: clean generate-openapi-spec agent-rest-docker sample-webhook-docker
@echo "Generate demo agent rest controller API specifications using Open API"
@SPEC_PATH=${OPENAPI_SPEC_PATH} OPENAPI_DEMO_PATH=test/bdd/fixtures/demo/openapi \
DOCKER_IMAGE=$(OPENAPI_DOCKER_IMG) DOCKER_IMAGE_VERSION=$(OPENAPI_DOCKER_IMG_VERSION) \
scripts/generate-openapi-demo-specs.sh

.PHONY: run-openapi-demo
run-openapi-demo: generate-openapi-demo-specs
@echo "Starting demo agent containers ..."
@DEMO_COMPOSE_PATH=test/bdd/fixtures/demo/openapi SIDETREE_COMPOSE_PATH=test/bdd/fixtures/sidetree-mock AGENT_COMPOSE_PATH=test/bdd/fixtures/agent \
@echo "Starting demo agent rest containers ..."
@DEMO_COMPOSE_PATH=test/bdd/fixtures/demo/openapi SIDETREE_COMPOSE_PATH=test/bdd/fixtures/sidetree-mock AGENT_REST_COMPOSE_PATH=test/bdd/fixtures/agent-rest \
scripts/run-openapi-demo.sh

.PHONY: agent
agent:
@echo "Building aries-agentd"
.PHONY: agent-rest
agent-rest:
@echo "Building aries-agent-rest"
@mkdir -p ./build/bin
@cd ${ARIES_AGENTD_PATH} && go build -o ../../build/bin/aries-agentd main.go
@cd ${ARIES_AGENT_REST_PATH} && go build -o ../../build/bin/aries-agent-rest main.go

.PHONY: agent-docker
agent-docker:
@echo "Building aries agent docker image"
@docker build -f ./images/agent/Dockerfile --no-cache -t $(DOCKER_OUTPUT_NS)/$(AGENT_IMAGE_NAME):latest \
.PHONY: agent-rest-docker
agent-rest-docker:
@echo "Building aries agent rest docker image"
@docker build -f ./images/agent-rest/Dockerfile --no-cache -t $(DOCKER_OUTPUT_NS)/$(AGENT_REST_IMAGE_NAME):latest \
--build-arg GO_VER=$(GO_VER) \
--build-arg ALPINE_VER=$(ALPINE_VER) \
--build-arg GO_TAGS=$(GO_TAGS) \
Expand Down Expand Up @@ -146,7 +146,7 @@ clean-build:
clean-fixtures:
@rm -Rf ./test/bdd/fixtures/keys/tls
@rm -Rf ./test/bdd/fixtures/demo/openapi/specs
@cd test/bdd/fixtures/agent && docker-compose down 2> /dev/null
@DEMO_COMPOSE_PATH=test/bdd/fixtures/demo/openapi AGENT_COMPOSE_PATH=test/bdd/fixtures/agent \
@cd test/bdd/fixtures/agent-rest && docker-compose down 2> /dev/null
@DEMO_COMPOSE_PATH=test/bdd/fixtures/demo/openapi AGENT_REST_COMPOSE_PATH=test/bdd/fixtures/agent-rest \
SIDETREE_COMPOSE_PATH=test/bdd/fixtures/sidetree-mock DEMO_COMPOSE_OP=down scripts/run-openapi-demo.sh 2> /dev/null
@cd test/bdd/fixtures/sidetree-mock && docker-compose down 2> /dev/null
2 changes: 1 addition & 1 deletion cmd/aries-agentd/go.mod → cmd/aries-agent-rest/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// SPDX-License-Identifier: Apache-2.0

module github.com/hyperledger/aries-framework-go/cmd/aries-agentd
module github.com/hyperledger/aries-framework-go/cmd/aries-agent-rest

replace github.com/hyperledger/aries-framework-go => ../..

Expand Down
File renamed without changes.
10 changes: 5 additions & 5 deletions cmd/aries-agentd/main.go → cmd/aries-agent-rest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Copyright SecureKey Technologies Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/

// Package aries-agentd (Aries Agent Server) of aries-framework-go.
// Package aries-agent-rest (Aries Agent REST Server) of aries-framework-go.
//
//
// Terms Of Service:
Expand All @@ -26,20 +26,20 @@ package main
import (
"github.com/spf13/cobra"

"github.com/hyperledger/aries-framework-go/cmd/aries-agentd/startcmd"
"github.com/hyperledger/aries-framework-go/cmd/aries-agent-rest/startcmd"
"github.com/hyperledger/aries-framework-go/pkg/common/log"
)

// This is an application which starts Aries agent controller API on given port
func main() {
rootCmd := &cobra.Command{
Use: "aries-agentd",
Use: "aries-agent-rest",
Run: func(cmd *cobra.Command, args []string) {
cmd.HelpFunc()(cmd, args)
},
}

logger := log.New("aries-framework/agentd")
logger := log.New("aries-framework/agent-rest")

startCmd, err := startcmd.Cmd(&startcmd.HTTPServer{})
if err != nil {
Expand All @@ -49,6 +49,6 @@ func main() {
rootCmd.AddCommand(startCmd)

if err := rootCmd.Execute(); err != nil {
logger.Fatalf("Failed to run aries-agentd: %s", err)
logger.Fatalf("Failed to run aries-agent-rest: %s", err)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ var errMissingHost = errors.New("host not provided")

var errMissingInboundHost = errors.New("HTTP Inbound transport host not provided")

var logger = log.New("aries-framework/agentd")
var logger = log.New("aries-framework/agent-rest")

type agentParameters struct {
server server
Expand Down Expand Up @@ -284,29 +284,29 @@ func startAgent(parameters *agentParameters) error {

resolverOpts, err := getResolverOpts(parameters.httpResolvers)
if err != nil {
return fmt.Errorf("failed to start aries agentd on port [%s], failed to resolver opts : %w",
return fmt.Errorf("failed to start aries agent rest on port [%s], failed to resolver opts : %w",
parameters.host, err)
}

opts = append(opts, resolverOpts...)

framework, err := aries.New(opts...)
if err != nil {
return fmt.Errorf("failed to start aries agentd on port [%s], failed to initialize framework : %w",
return fmt.Errorf("failed to start aries agent rest on port [%s], failed to initialize framework : %w",
parameters.host, err)
}

ctx, err := framework.Context()
if err != nil {
return fmt.Errorf("failed to start aries agentd on port [%s], failed to get aries context : %w",
return fmt.Errorf("failed to start aries agent rest on port [%s], failed to get aries context : %w",
parameters.host, err)
}

// get all HTTP REST API handlers available for controller API
restService, err := restapi.New(ctx, restapi.WithWebhookURLs(parameters.webhookURLs...),
restapi.WithDefaultLabel(parameters.defaultLabel))
if err != nil {
return fmt.Errorf("failed to start aries agentd on port [%s], failed to get rest service api : %w",
return fmt.Errorf("failed to start aries agent rest on port [%s], failed to get rest service api : %w",
parameters.host, err)
}

Expand All @@ -317,13 +317,13 @@ func startAgent(parameters *agentParameters) error {
router.HandleFunc(handler.Path(), handler.Handle()).Methods(handler.Method())
}

logger.Infof("Starting aries agentd on host [%s]", parameters.host)
logger.Infof("Starting aries agent rest on host [%s]", parameters.host)
// start server on given port and serve using given handlers
handler := cors.Default().Handler(router)

err = parameters.server.ListenAndServe(parameters.host, handler)
if err != nil {
return fmt.Errorf("failed to start aries agentd on port [%s], cause: %w", parameters.host, err)
return fmt.Errorf("failed to start aries agent rest on port [%s], cause: %w", parameters.host, err)
}

return nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ func TestStartMultipleAgentsWithSameHost(t *testing.T) {
defer cleanup2()

parameters := &agentParameters{&HTTPServer{}, host, inboundHost2, "", path2, "", []string{}, []string{}}
addressAlreadyInUseErrorMessage := "failed to start aries agentd on port [" + host +
addressAlreadyInUseErrorMessage := "failed to start aries agent rest on port [" + host +
"], cause: listen tcp 127.0.0.1:8095: bind: address already in use"

err := startAgent(parameters)
Expand Down
8 changes: 4 additions & 4 deletions docs/rest/agent_cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

## Build the Agent

The agent can be built from within the `cmd/aries-agentd` directory with `go build`.
The agent can be built from within the `cmd/aries-agent-rest` directory with `go build`.

## Run the Agent

Start the agent with `./aries-agentd start [flags]`.
Start the agent with `./aries-agent-rest start [flags]`.

## Agent Parameters

Expand All @@ -30,7 +30,7 @@ Flags:
## Example

```shell
$ cd cmd/aries-agentd
$ cd cmd/aries-agent-rest
$ go build
$ ./aries-agentd start --api-host localhost:8080 --db-path "" --inbound-host localhost:8081 --inbound-host-external example.com:8081 --webhook-url localhost:8082 --agent-default-label MyAgent
$ ./aries-agent-rest start --api-host localhost:8080 --db-path "" --inbound-host localhost:8081 --inbound-host-external example.com:8081 --webhook-url localhost:8082 --agent-default-label MyAgent
```
6 changes: 3 additions & 3 deletions docs/rest/agent_docker.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# Run the agent as docker container

## Build the Agent
Build the docker image for `aries-agentd` by running following make target from project root directory.
Build the docker image for `aries-agent-rest` by running following make target from project root directory.

`make agent-docker`

## Run the Agent
Above target will build docker image `aries-framework-go/agent` which can be used to start agent by running command as simple as
Above target will build docker image `aries-framework-go/agent-rest` which can be used to start agent by running command as simple as

```
docker run aries-framework-go/agent start [flags]
docker run aries-framework-go/agent-rest start [flags]
```

Details about flags can be found [here](agent_cli.md#Agent-Parameters)
12 changes: 6 additions & 6 deletions docs/rest/agent_webhook.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# Webhook Usage in Aries-agentd
# Webhook Usage in Aries-agent-rest

Aries-agentd uses a webhook mechanism to communicate events back to the controller.
Aries-agent-rest uses a webhook mechanism to communicate events back to the controller.

The URL that aries-agentd should send events to can be set with the `--webhook-url` command line argument or with the `ARIESD_WEBHOOK_URL` environment variable.
The URL that aries-agent-rest should send events to can be set with the `--webhook-url` command line argument or with the `ARIESD_WEBHOOK_URL` environment variable.

## Multiple Webhook Support

Aries-agentd supports multiple webhooks.
Aries-agent-rest supports multiple webhooks.
To pass in multiple webhooks, simplify repeat the `--webhook-url` argument for each url. Alternatively, a CSV list of webhook URLS can be set to the environment variable `ARIESD_WEBHOOK_URL`.

### Example

This command registers both localhost:8082 and localhost:8083 as endpoints for aries-agentd to send notifications to:
This command registers both localhost:8082 and localhost:8083 as endpoints for aries-agent-rest to send notifications to:

`./aries-agentd start --api-host localhost:8080 --db-path "" --inbound-host localhost:8081 --inbound-host-external example.com:8081 --webhook-url localhost:8082 --webhook-url localhost:8083 --agent-default-label MyAgent`
`./aries-agent-rest start --api-host localhost:8080 --db-path "" --inbound-host localhost:8081 --inbound-host-external example.com:8081 --webhook-url localhost:8082 --webhook-url localhost:8083 --agent-default-label MyAgent`
6 changes: 3 additions & 3 deletions images/agent/Dockerfile → images/agent-rest/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ ENV EXECUTABLES go git
FROM golang as aries-framework
ARG GO_TAGS
ARG GOPROXY
RUN GO_TAGS=${GO_TAGS} GOPROXY=${GOPROXY} make agent
RUN GO_TAGS=${GO_TAGS} GOPROXY=${GOPROXY} make agent-rest


FROM alpine:${ALPINE_VER} as base
COPY --from=aries-framework /go/src/github.com/hyperledger/aries-framework-go/build/bin/aries-agentd /usr/local/bin
ENTRYPOINT ["aries-agentd"]
COPY --from=aries-framework /go/src/github.com/hyperledger/aries-framework-go/build/bin/aries-agent-rest /usr/local/bin
ENTRYPOINT ["aries-agent-rest"]
2 changes: 1 addition & 1 deletion pkg/restapi/webhook/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const (
emptyMessageErrMsg = "cannot notify with an empty message"
)

var logger = log.New("aries-framework/agentd")
var logger = log.New("aries-framework/webhook")

// Notifier represents a webhook dispatcher.
type Notifier interface {
Expand Down
2 changes: 1 addition & 1 deletion scripts/check_lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ if [ ! $(command -v ${DOCKER_CMD}) ]; then
fi

${DOCKER_CMD} run --rm -e GOPROXY=${GOPROXY} -v $(pwd):/opt/workspace -w /opt/workspace golangci/golangci-lint:v1.21 golangci-lint run
${DOCKER_CMD} run --rm -e GOPROXY=${GOPROXY} -v $(pwd):/opt/workspace -w /opt/workspace/cmd/aries-agentd golangci/golangci-lint:v1.21 golangci-lint run -c ../../.golangci.yml
${DOCKER_CMD} run --rm -e GOPROXY=${GOPROXY} -v $(pwd):/opt/workspace -w /opt/workspace/cmd/aries-agent-rest golangci/golangci-lint:v1.21 golangci-lint run -c ../../.golangci.yml
${DOCKER_CMD} run --rm -e GOPROXY=${GOPROXY} -v $(pwd):/opt/workspace -w /opt/workspace/test/bdd golangci/golangci-lint:v1.21 golangci-lint run -c ../../.golangci.yml
6 changes: 3 additions & 3 deletions scripts/check_unit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ PKGS=`go list github.com/hyperledger/aries-framework-go/... 2> /dev/null | \
go test $PKGS -count=1 -race -coverprofile=profile.out -covermode=atomic -timeout=10m
amend_coverage_file

# Running aries-agentd unit test
cd cmd/aries-agentd
PKGS=`go list github.com/hyperledger/aries-framework-go/cmd/aries-agentd/... 2> /dev/null | \
# Running aries-agent-rest unit test
cd cmd/aries-agent-rest
PKGS=`go list github.com/hyperledger/aries-framework-go/cmd/aries-agent-rest/... 2> /dev/null | \
grep -v /mocks`
go test $PKGS -count=1 -race -coverprofile=profile.out -covermode=atomic -timeout=10m
amend_coverage_file
Expand Down
2 changes: 1 addition & 1 deletion scripts/generate-openapi-spec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
set -e

SPEC_LOC="${SPEC_LOC}"
SPEC_META="${SPEC_META:-cmd/aries-agentd}"
SPEC_META="${SPEC_META:-cmd/aries-agent-rest}"
OUTPUT="$PWD/$SPEC_LOC/openAPI.yml"
IMAGE="${DOCKER_IMAGE:-quay.io/goswagger/swagger}"
IMAGE_VERSION="${DOCKER_IMAGE_VERSION:-latest}"
Expand Down
2 changes: 1 addition & 1 deletion scripts/run-openapi-demo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ set -e
DEMO_COMPOSE_OP="${DEMO_COMPOSE_OP:-up --force-recreate}"
COMPOSE_FILES="${DEMO_COMPOSE_FILES}"
DEMO_PATH="${DEMO_COMPOSE_PATH}"
AGENT_PATH="${AGENT_COMPOSE_PATH}"
AGENT_PATH="${AGENT_REST_COMPOSE_PATH}"
AGENT_COMPOSE_FILE="$PWD/$AGENT_PATH/docker-compose.yml"
SIDETREE_PATH="${SIDETREE_COMPOSE_PATH}"
SIDETREE_COMPOSE_FILE="$PWD/$SIDETREE_PATH/docker-compose.yml"
Expand Down
2 changes: 1 addition & 1 deletion test/bdd/bddtests_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const (
)

var composition []*dockerutil.Composition
var composeFiles = []string{"./fixtures/sidetree-mock", "./fixtures/agent"}
var composeFiles = []string{"./fixtures/sidetree-mock", "./fixtures/agent-rest"}

func TestMain(m *testing.M) {
// default is to run all tests with tag @all
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@


# Agent configurations
AGENTD_IMAGE=aries-framework-go/agent
AGENTD_IMAGE_TAG=latest
AGENT_REST_IMAGE=aries-framework-go/agent-rest
AGENT_REST_IMAGE_TAG=latest

# Alice agent configurations
ALICE_HOST=0.0.0.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ services:

alice.agent.example.com:
container_name: alice.aries.example.com
image: ${AGENTD_IMAGE}:${AGENTD_IMAGE_TAG}
image: ${AGENT_REST_IMAGE}:${AGENT_REST_IMAGE_TAG}
environment:
- ARIESD_API_HOST=${ALICE_HOST}:${ALICE_API_PORT}
- ARIESD_INBOUND_HOST=${ALICE_HOST}:${ALICE_INBOUND_PORT}
Expand All @@ -25,7 +25,7 @@ services:

bob.agent.example.com:
container_name: bob.aries.example.com
image: ${AGENTD_IMAGE}:${AGENTD_IMAGE_TAG}
image: ${AGENT_REST_IMAGE}:${AGENT_REST_IMAGE_TAG}
environment:
- ARIESD_API_HOST=${BOB_HOST}:${BOB_API_PORT}
- ARIESD_INBOUND_HOST=${BOB_HOST}:${BOB_INBOUND_PORT}
Expand Down