Skip to content

Commit

Permalink
Generate deterministic Goa sample data
Browse files Browse the repository at this point in the history
  • Loading branch information
sevein committed Jul 11, 2023
1 parent 20c03b3 commit 1edf603
Show file tree
Hide file tree
Showing 21 changed files with 4,382 additions and 835 deletions.
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ include hack/make/dep_gomajor.mk
include hack/make/dep_goreleaser.mk
include hack/make/dep_gotestsum.mk
include hack/make/dep_hugo.mk
include hack/make/dep_jq.mk
include hack/make/dep_mockgen.mk
include hack/make/dep_temporal_cli.mk

Expand Down Expand Up @@ -87,6 +88,15 @@ lint: $(GOLANGCI_LINT) # @HELP Lints the code using golangci-lint.

gen-goa: $(GOA) # @HELP Generates Goa assets.
goa gen github.com/artefactual-labs/enduro/internal/api/design -o internal/api
@$(MAKE) gen-goa-json-pretty

gen-goa-json-pretty: goa_http_dir = "internal/api/gen/http"
gen-goa-json-pretty: json_files = $(shell find $(goa_http_dir) -type f -name "*.json" | sort -u)
gen-goa-json-pretty: $(JQ)
@for f in $(json_files); \
do (cat "$$f" | jq -S '.' >> "$$f".sorted && mv "$$f".sorted "$$f") \
&& echo "Formatting $$f with jq" || exit 1; \
done

clean: # @HELP Cleans temporary files.
rm -rf ./build ./dist
Expand Down
32 changes: 32 additions & 0 deletions hack/make/dep_jq.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
$(call _assert_var,MAKEDIR)
$(call _conditional_include,$(MAKEDIR)/base.mk)
$(call _assert_var,UNAME_OS)
$(call _assert_var,UNAME_ARCH)
$(call _assert_var,CACHE_VERSIONS)
$(call _assert_var,CACHE_BIN)

JQ_VERSION ?= 1.6

ifeq ($(UNAME_OS),Darwin)
JQ_OS := osx
JQ_ARCH := -amd64
endif

ifeq ($(UNAME_ARCH),x86_64)
ifeq ($(UNAME_OS),Linux)
JQ_OS := linux
JQ_ARCH := 64
endif
endif

JQ := $(CACHE_VERSIONS)/jq/$(JQ_VERSION)
$(JQ):
@rm -f $(CACHE_BIN)/jq
@mkdir -p $(CACHE_BIN)
@curl -sSL \
https://github.com/stedolan/jq/releases/download/jq-$(JQ_VERSION)/jq-$(JQ_OS)$(JQ_ARCH) \
-o $(CACHE_BIN)/jq
@chmod +x $(CACHE_BIN)/jq
@rm -rf $(dir $(JQ))
@mkdir -p $(dir $(JQ))
@touch $(JQ)
34 changes: 10 additions & 24 deletions internal/api/design/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,16 @@ var _ = Service("collection", func() {
Payload(func() {
Attribute("name", String)
Attribute("original_id", String)
Attribute("transfer_id", String, func() {
Format(FormatUUID)
})
Attribute("aip_id", String, func() {
Format(FormatUUID)
})
Attribute("pipeline_id", String, func() {
Format(FormatUUID)
})
AttributeUUID("transfer_id", "Identifier of Archivematica tranfser")
AttributeUUID("aip_id", "Identifier of Archivematica AIP")
AttributeUUID("pipeline_id", "Identifier of Archivematica pipeline")
Attribute("earliest_created_time", String, func() {
Format(FormatDateTime)
Example("e1d563b0-1474-4155-beed-f2d3a12e1529")
})
Attribute("latest_created_time", String, func() {
Format(FormatDateTime)
Example("e1d563b0-1474-4155-beed-f2d3a12e1529")
})
Attribute("status", String, func() {
EnumCollectionStatus()
Expand Down Expand Up @@ -217,22 +213,12 @@ var Collection = Type("Collection", func() {
EnumCollectionStatus()
Default("new")
})
Attribute("workflow_id", String, "Identifier of processing workflow", func() {
Format(FormatUUID)
})
Attribute("run_id", String, "Identifier of latest processing workflow run", func() {
Format(FormatUUID)
})
Attribute("transfer_id", String, "Identifier of Archivematica transfer", func() {
Format(FormatUUID)
})
Attribute("aip_id", String, "Identifier of Archivematica AIP", func() {
Format(FormatUUID)
})
AttributeUUID("workflow_id", "Identifier of processing workflow")
AttributeUUID("run_id", "Identifier of latest processing workflow run")
AttributeUUID("transfer_id", "Identifier of Archivematica tranfser")
AttributeUUID("aip_id", "Identifier of Archivematica AIP")
Attribute("original_id", String, "Identifier provided by the client")
Attribute("pipeline_id", String, "Identifier of Archivematica pipeline", func() {
Format(FormatUUID)
})
AttributeUUID("pipeline_id", "Identifier of Archivematica pipeline")
Attribute("created_at", String, "Creation datetime", func() {
Format(FormatDateTime)
})
Expand Down
2 changes: 2 additions & 0 deletions internal/api/design/design.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ package design

import (
. "goa.design/goa/v3/dsl"
"goa.design/goa/v3/expr"
cors "goa.design/plugins/v3/cors/dsl"
)

var _ = API("enduro", func() {
Title("Enduro API")
Randomizer(expr.NewDeterministicRandomizer())
Server("enduro", func() {
Services("pipeline", "batch", "collection", "swagger")
Host("localhost", func() {
Expand Down
6 changes: 3 additions & 3 deletions internal/api/design/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var _ = Service("pipeline", func() {
Method("show", func() {
Description("Show pipeline by ID")
Payload(func() {
Attribute("id", String, "Identifier of pipeline to show", func() { Format(FormatUUID) })
AttributeUUID("id", "Identifier of pipeline to show")
Required("id")
})
Result(StoredPipeline)
Expand All @@ -42,7 +42,7 @@ var _ = Service("pipeline", func() {
Method("processing", func() {
Description("List all processing configurations of a pipeline given its ID")
Payload(func() {
Attribute("id", String, "Identifier of pipeline", func() { Format(FormatUUID) })
AttributeUUID("id", "Identifier of pipeline")
Required("id")
})
Result(ArrayOf(String))
Expand All @@ -57,7 +57,7 @@ var _ = Service("pipeline", func() {

var Pipeline = Type("Pipeline", func() {
Description("Pipeline describes an Archivematica pipeline.")
Attribute("id", String, "Identifier of the pipeline", func() { Format(FormatUUID) })
AttributeUUID("id", "Identifier of pipeline")
Attribute("name", String, "Name of the pipeline")
Attribute("capacity", Int64, "Maximum concurrent transfers")
Attribute("current", Int64, "Current transfers")
Expand Down
34 changes: 34 additions & 0 deletions internal/api/design/uuid.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// # UUID attributes
//
// Use [AttributeUUID] or [TypedAttributeUUID] to declare UUID attributes.
//
// These attributes produce consistent example UUIDs.
package design

import (
. "goa.design/goa/v3/dsl"
)

// AttributeUUID describes a string typed field that must be a valid UUID.
// The desc is a short description of the field's purpose.
//
// AttributeUUID's example value is a deterministic UUID.
func AttributeUUID(name, desc string) {
Attribute(name, String, desc, func() {
Format(FormatUUID)
Example("d1845cb6-a5ea-474a-9ab8-26f9bcd919f5")
})
}

// TypedAttributeUUID describes a [uuid.UUID] typed field. The desc is a short
// description of the field's purpose.
//
// TypedAttributeUUID's example value is a deterministic UUID.
//
// [uuid.UUID]: https://github.com/google/uuid
func TypedAttributeUUID(name, desc string) {
Attribute(name, String, desc, func() {
Meta("struct:field:type", "uuid.UUID", "github.com/google/uuid")
Example("d1845cb6-a5ea-474a-9ab8-26f9bcd919f5")
})
}
13 changes: 8 additions & 5 deletions internal/api/gen/collection/service.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/api/gen/collection/views/view.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/api/gen/http/batch/client/cli.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 26 additions & 26 deletions internal/api/gen/http/cli/enduro/cli.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 1edf603

Please sign in to comment.