diff --git a/.gitignore b/.gitignore index 678f804aca..2db59dfa98 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/Makefile b/Makefile index 427a137c3b..4d5d0f0486 100644 --- a/Makefile +++ b/Makefile @@ -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) @@ -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 @@ -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) \ @@ -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 diff --git a/cmd/aries-agentd/go.mod b/cmd/aries-agent-rest/go.mod similarity index 98% rename from cmd/aries-agentd/go.mod rename to cmd/aries-agent-rest/go.mod index d0f52e25a7..6b77acd28e 100644 --- a/cmd/aries-agentd/go.mod +++ b/cmd/aries-agent-rest/go.mod @@ -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 => ../.. diff --git a/cmd/aries-agentd/go.sum b/cmd/aries-agent-rest/go.sum similarity index 100% rename from cmd/aries-agentd/go.sum rename to cmd/aries-agent-rest/go.sum diff --git a/cmd/aries-agentd/main.go b/cmd/aries-agent-rest/main.go similarity index 74% rename from cmd/aries-agentd/main.go rename to cmd/aries-agent-rest/main.go index b7b04e7f80..ac0275ef2b 100644 --- a/cmd/aries-agentd/main.go +++ b/cmd/aries-agent-rest/main.go @@ -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: @@ -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 { @@ -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) } } diff --git a/cmd/aries-agentd/main_test.go b/cmd/aries-agent-rest/main_test.go similarity index 100% rename from cmd/aries-agentd/main_test.go rename to cmd/aries-agent-rest/main_test.go diff --git a/cmd/aries-agentd/startcmd/start.go b/cmd/aries-agent-rest/startcmd/start.go similarity index 94% rename from cmd/aries-agentd/startcmd/start.go rename to cmd/aries-agent-rest/startcmd/start.go index 292f86d47f..4f7f820803 100644 --- a/cmd/aries-agentd/startcmd/start.go +++ b/cmd/aries-agent-rest/startcmd/start.go @@ -102,7 +102,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 @@ -303,7 +303,7 @@ func startAgent(parameters *agentParameters) error { resolverOpts, err := getResolverOpts(parameters.defaultLabel, parameters.dbPath, 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) } @@ -311,13 +311,13 @@ func startAgent(parameters *agentParameters) error { 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) } @@ -325,7 +325,7 @@ func startAgent(parameters *agentParameters) error { 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) } @@ -336,13 +336,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 diff --git a/cmd/aries-agentd/startcmd/start_test.go b/cmd/aries-agent-rest/startcmd/start_test.go similarity index 99% rename from cmd/aries-agentd/startcmd/start_test.go rename to cmd/aries-agent-rest/startcmd/start_test.go index 0e4f716167..ed75c0bcbb 100644 --- a/cmd/aries-agentd/startcmd/start_test.go +++ b/cmd/aries-agent-rest/startcmd/start_test.go @@ -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) diff --git a/docs/rest/agent_cli.md b/docs/rest/agent_cli.md index 6138f8a029..ea008821fd 100644 --- a/docs/rest/agent_cli.md +++ b/docs/rest/agent_cli.md @@ -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 @@ -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 ``` diff --git a/docs/rest/agent_docker.md b/docs/rest/agent_docker.md index f2f22136c4..c3c0dc7503 100644 --- a/docs/rest/agent_docker.md +++ b/docs/rest/agent_docker.md @@ -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) diff --git a/docs/rest/agent_webhook.md b/docs/rest/agent_webhook.md index b022f72f9f..d2de0f6e37 100644 --- a/docs/rest/agent_webhook.md +++ b/docs/rest/agent_webhook.md @@ -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` diff --git a/images/agent/Dockerfile b/images/agent-rest/Dockerfile similarity index 79% rename from images/agent/Dockerfile rename to images/agent-rest/Dockerfile index faaab2b052..98447c8fcf 100644 --- a/images/agent/Dockerfile +++ b/images/agent-rest/Dockerfile @@ -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"] diff --git a/pkg/restapi/webhook/webhook.go b/pkg/restapi/webhook/webhook.go index 240a23c04f..b4adad58af 100644 --- a/pkg/restapi/webhook/webhook.go +++ b/pkg/restapi/webhook/webhook.go @@ -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 { diff --git a/scripts/check_lint.sh b/scripts/check_lint.sh index d3af2c8e52..5d14f32f81 100755 --- a/scripts/check_lint.sh +++ b/scripts/check_lint.sh @@ -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 diff --git a/scripts/check_unit.sh b/scripts/check_unit.sh index 46905eb8ad..ab796101d7 100755 --- a/scripts/check_unit.sh +++ b/scripts/check_unit.sh @@ -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 diff --git a/scripts/generate-openapi-spec.sh b/scripts/generate-openapi-spec.sh index 66651359d2..cf066ebbb6 100755 --- a/scripts/generate-openapi-spec.sh +++ b/scripts/generate-openapi-spec.sh @@ -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}" diff --git a/scripts/run-openapi-demo.sh b/scripts/run-openapi-demo.sh index 7205db3fc5..2b17a66f48 100755 --- a/scripts/run-openapi-demo.sh +++ b/scripts/run-openapi-demo.sh @@ -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" diff --git a/test/bdd/bddtests_test.go b/test/bdd/bddtests_test.go index c5f5dc56df..de978d9482 100644 --- a/test/bdd/bddtests_test.go +++ b/test/bdd/bddtests_test.go @@ -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 diff --git a/test/bdd/fixtures/agent/.env b/test/bdd/fixtures/agent-rest/.env similarity index 93% rename from test/bdd/fixtures/agent/.env rename to test/bdd/fixtures/agent-rest/.env index 89ff7a25a5..b78ff9d495 100644 --- a/test/bdd/fixtures/agent/.env +++ b/test/bdd/fixtures/agent-rest/.env @@ -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 diff --git a/test/bdd/fixtures/agent/docker-compose.yml b/test/bdd/fixtures/agent-rest/docker-compose.yml similarity index 94% rename from test/bdd/fixtures/agent/docker-compose.yml rename to test/bdd/fixtures/agent-rest/docker-compose.yml index 841d8d64c9..9029abfa6b 100644 --- a/test/bdd/fixtures/agent/docker-compose.yml +++ b/test/bdd/fixtures/agent-rest/docker-compose.yml @@ -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} @@ -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}