From 70c0a20c16f5cd65139d6ca11a66acc7cd1dbac7 Mon Sep 17 00:00:00 2001 From: Luke van der Hoeven Date: Tue, 23 Aug 2016 16:54:05 -0400 Subject: [PATCH 01/10] use epoch timestamps prod is stupid --- src/biplane/mixins/timestamps.cr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/biplane/mixins/timestamps.cr b/src/biplane/mixins/timestamps.cr index 9bfa857..45ac1d0 100644 --- a/src/biplane/mixins/timestamps.cr +++ b/src/biplane/mixins/timestamps.cr @@ -1,7 +1,7 @@ module Biplane::Mixins module Timestamps def pg_now - "now" + "'#{Time.now.epoch}'" end end end From 90c44b9b58dd591576bc79a759f4a31103f962ae Mon Sep 17 00:00:00 2001 From: Luke van der Hoeven Date: Tue, 23 Aug 2016 17:27:59 -0400 Subject: [PATCH 02/10] helpers for prod images build --- Makefile | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Makefile b/Makefile index 009ce1c..7e6c0e3 100644 --- a/Makefile +++ b/Makefile @@ -11,6 +11,11 @@ build: build-container: docker build -t articulate/biplane:local . +build-for-prod: + docker build --no-cache -t articulate/biplane:prod . + docker tag articulate/biplane:prod articulate/biplane:prod + docker push articulate/biplane:prod + build-release: crystal build --release src/cli.cr -o biplane From 51b9930816effaf507c34c1ad874bc73d38f2d59 Mon Sep 17 00:00:00 2001 From: Luke van der Hoeven Date: Tue, 23 Aug 2016 17:28:09 -0400 Subject: [PATCH 03/10] special version tag for prod --- src/biplane/version.cr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/biplane/version.cr b/src/biplane/version.cr index e63a767..ec33c30 100644 --- a/src/biplane/version.cr +++ b/src/biplane/version.cr @@ -1,3 +1,3 @@ module Biplane - VERSION = "1.3.11" + VERSION = "1.3.11-prod" end From 2584e93af549b90cd09c756a7a07543fb5d2afe1 Mon Sep 17 00:00:00 2001 From: Luke van der Hoeven Date: Tue, 23 Aug 2016 17:31:06 -0400 Subject: [PATCH 04/10] no quotes, we do it raw --- src/biplane/mixins/timestamps.cr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/biplane/mixins/timestamps.cr b/src/biplane/mixins/timestamps.cr index 45ac1d0..9cc62c6 100644 --- a/src/biplane/mixins/timestamps.cr +++ b/src/biplane/mixins/timestamps.cr @@ -1,7 +1,7 @@ module Biplane::Mixins module Timestamps def pg_now - "'#{Time.now.epoch}'" + Time.now.epoch end end end From 2a041350288faf40348c08c6ce65b86ec3c6c8e5 Mon Sep 17 00:00:00 2001 From: Luke van der Hoeven Date: Tue, 23 Aug 2016 17:39:46 -0400 Subject: [PATCH 05/10] try splitting up time formats --- src/biplane/configs/api_config.cr | 2 +- src/biplane/mixins/timestamps.cr | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/biplane/configs/api_config.cr b/src/biplane/configs/api_config.cr index 6d4548f..2e7cc6a 100644 --- a/src/biplane/configs/api_config.cr +++ b/src/biplane/configs/api_config.cr @@ -37,7 +37,7 @@ module Biplane "request_path": request_path, "strip_request_path": strip_request_path, "upstream_url": upstream_url, - "created_at": pg_now, + "created_at": epoch_int, } end diff --git a/src/biplane/mixins/timestamps.cr b/src/biplane/mixins/timestamps.cr index 9cc62c6..7b55ecf 100644 --- a/src/biplane/mixins/timestamps.cr +++ b/src/biplane/mixins/timestamps.cr @@ -1,6 +1,10 @@ module Biplane::Mixins module Timestamps def pg_now + "now" + end + + def epoch_int Time.now.epoch end end From 33786d51acf031e9e0df00186c7d385a4605e881 Mon Sep 17 00:00:00 2001 From: Luke van der Hoeven Date: Wed, 24 Aug 2016 14:24:13 -0400 Subject: [PATCH 06/10] add failing specs for demo case --- spec/configs/acl_config_spec.cr | 14 ++++++++++++++ spec/configs/api_config_spec.cr | 20 ++++++++++++++++++++ spec/configs/consumer_config_spec.cr | 14 ++++++++++++++ spec/configs/credential_config_spec.cr | 10 +++++++++- spec/configs/plugin_config_spec.cr | 14 ++++++++++++-- 5 files changed, 69 insertions(+), 3 deletions(-) diff --git a/spec/configs/acl_config_spec.cr b/spec/configs/acl_config_spec.cr index 56f374c..135f59e 100644 --- a/spec/configs/acl_config_spec.cr +++ b/spec/configs/acl_config_spec.cr @@ -15,5 +15,19 @@ module Biplane acl.member_route.should be_a(Route) acl.member_route.to_s.should eq "/consumers/#{parent.lookup_key}/acls/:id" end + + it "outputs attrs for create" do + acl.for_create.should eq({ + "group": acl.group, + "created_at": "now", + }) + end + + it "uses epoch time for update" do + acl.for_update.should eq({ + "group": acl.group, + "created_at": Time.now.epoch, + }) + end end end diff --git a/spec/configs/api_config_spec.cr b/spec/configs/api_config_spec.cr index 5b73eb7..aa029bf 100644 --- a/spec/configs/api_config_spec.cr +++ b/spec/configs/api_config_spec.cr @@ -20,5 +20,25 @@ module Biplane plugins.should be_a(Array(PluginConfig)) plugins.map { |p| p.name }.should eq ["acl", "jwt"] end + + it "outputs attrs for create" do + api.for_create.should eq({ + "name": api.name, + "request_path": api.request_path, + "strip_request_path": api.strip_request_path, + "upstream_url": api.upstream_url, + "created_at": "now", + }) + end + + it "uses epoch time for update" do + api.for_update.should eq({ + "name": api.name, + "request_path": api.request_path, + "strip_request_path": api.strip_request_path, + "upstream_url": api.upstream_url, + "created_at": Time.now.epoch, + }) + end end end diff --git a/spec/configs/consumer_config_spec.cr b/spec/configs/consumer_config_spec.cr index 1212ed0..40eb923 100644 --- a/spec/configs/consumer_config_spec.cr +++ b/spec/configs/consumer_config_spec.cr @@ -20,5 +20,19 @@ module Biplane items.should be_a(Array(AclConfig | CredentialConfig)) items.size.should eq 2 end + + it "outputs attrs for create" do + consumer.for_create.should eq({ + "username": consumer.username, + "created_at": "now", + }) + end + + it "uses epoch time for update" do + consumer.for_update.should eq({ + "username": consumer.username, + "created_at": Time.now.epoch, + }) + end end end diff --git a/spec/configs/credential_config_spec.cr b/spec/configs/credential_config_spec.cr index ca4fb10..802f94b 100644 --- a/spec/configs/credential_config_spec.cr +++ b/spec/configs/credential_config_spec.cr @@ -6,13 +6,21 @@ module Biplane credential.parent = parent = yaml_fixture(ConsumerConfig) it "can flatten for params" do - credential.as_params.should eq({ + credential.for_create.should eq({ "key": "xxx", "secret": "yyy", "created_at": "now", }) end + it "outputs epoch time for update" do + credential.for_update.should eq({ + "key": "xxx", + "secret": "yyy", + "created_at": Time.now.epoch, + }) + end + it "knows collection path" do credential.collection_route.should be_a(Route) credential.collection_route.to_s.should eq "/consumers/#{parent.lookup_key}/#{credential.name}" diff --git a/spec/configs/plugin_config_spec.cr b/spec/configs/plugin_config_spec.cr index 219650d..ca21575 100644 --- a/spec/configs/plugin_config_spec.cr +++ b/spec/configs/plugin_config_spec.cr @@ -23,7 +23,7 @@ module Biplane end it "can present config as params" do - plugin.as_params.should eq({ + plugin.for_create.should eq({ "name": "acl", "config": { "whitelist": ["docs-auth", "google-auth"], @@ -40,7 +40,7 @@ module Biplane }, })) - odd.as_params.should eq({ + odd.for_create.should eq({ "name": "what", "config": { "whitelist": ["name", "only"], @@ -48,5 +48,15 @@ module Biplane "created_at": "now", }) end + + it "outputs epoch time for update" do + plugin.for_update.should eq({ + "name": "acl", + "config": { + "whitelist": ["docs-auth", "google-auth"], + }, + "created_at": Time.now.epoch, + }) + end end end From d67aa7b5baeb8555ab4355ba659b790244b04f62 Mon Sep 17 00:00:00 2001 From: Luke van der Hoeven Date: Wed, 24 Aug 2016 14:24:54 -0400 Subject: [PATCH 07/10] split as_params to create/update specific methods --- src/biplane/configs/acl_config.cr | 10 ++++++---- src/biplane/configs/api_config.cr | 8 ++++++-- src/biplane/configs/consumer_config.cr | 6 +++++- src/biplane/configs/credential_config.cr | 10 ++++++---- src/biplane/configs/plugin_config.cr | 6 +++++- 5 files changed, 28 insertions(+), 12 deletions(-) diff --git a/src/biplane/configs/acl_config.cr b/src/biplane/configs/acl_config.cr index b072381..3705233 100644 --- a/src/biplane/configs/acl_config.cr +++ b/src/biplane/configs/acl_config.cr @@ -11,10 +11,12 @@ module Biplane group: String, }) - def as_params - normalize(serialize, { - created_at: pg_now, - }) + def for_create + normalize(serialize, {created_at: pg_now}) + end + + def for_update + normalize(for_create, {created_at: epoch_int}) end def serialize diff --git a/src/biplane/configs/api_config.cr b/src/biplane/configs/api_config.cr index 2e7cc6a..b6f9186 100644 --- a/src/biplane/configs/api_config.cr +++ b/src/biplane/configs/api_config.cr @@ -31,16 +31,20 @@ module Biplane ChildCollection.new(@plugins, self) end - def as_params + def for_create { "name": name, "request_path": request_path, "strip_request_path": strip_request_path, "upstream_url": upstream_url, - "created_at": epoch_int, + "created_at": pg_now, } end + def for_update + for_create.merge({"created_at": epoch_int}) + end + def serialize { "name": name, diff --git a/src/biplane/configs/consumer_config.cr b/src/biplane/configs/consumer_config.cr index 1a408ea..70fdfd5 100644 --- a/src/biplane/configs/consumer_config.cr +++ b/src/biplane/configs/consumer_config.cr @@ -14,13 +14,17 @@ module Biplane credentials: {type: Array(CredentialConfig), default: Array(CredentialConfig).new}, }) - def as_params + def for_create { "username": username, "created_at": pg_now, } end + def for_update + for_create.merge({"created_at": epoch_int}) + end + def acls ChildCollection.new(@acls, self) end diff --git a/src/biplane/configs/credential_config.cr b/src/biplane/configs/credential_config.cr index 1e200a5..a6ec02f 100644 --- a/src/biplane/configs/credential_config.cr +++ b/src/biplane/configs/credential_config.cr @@ -18,10 +18,12 @@ module Biplane route(collection_key, {name: name}) end - def as_params - normalize(attributes, { - created_at: pg_now, - }) + def for_create + normalize(attributes, {created_at: pg_now}) + end + + def for_update + normalize(for_create, {created_at: epoch_int}) end def serialize diff --git a/src/biplane/configs/plugin_config.cr b/src/biplane/configs/plugin_config.cr index 117e51f..ad7e803 100644 --- a/src/biplane/configs/plugin_config.cr +++ b/src/biplane/configs/plugin_config.cr @@ -18,13 +18,17 @@ module Biplane @parsed_attrs ||= @attributes.nil? ? Hash(String, Type).new : normalize(to_hash(@attributes) as Hash) end - def as_params + def for_create normalize(attributes, { name: name, created_at: pg_now, }) end + def for_update + normalize(for_create, {created_at: epoch_int}) + end + def serialize serial = Hash(String, Type).new serial["name"] = name From b2c638b6be756b2b1165df63c9c5e7294f3e0328 Mon Sep 17 00:00:00 2001 From: Luke van der Hoeven Date: Wed, 24 Aug 2016 14:25:12 -0400 Subject: [PATCH 08/10] use new update/create methods in api client --- src/biplane/kong_client.cr | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/biplane/kong_client.cr b/src/biplane/kong_client.cr index 08128ed..03b656f 100644 --- a/src/biplane/kong_client.cr +++ b/src/biplane/kong_client.cr @@ -101,7 +101,7 @@ module Biplane headers = HTTP::Headers.new headers.add("Content-Type", "application/json") - params = config.as_params + params = config.for_create response = @client.post(config.collection_route.to_s, headers, params.to_json) as HTTP::Client::Response @client.close # close immediately since we might make nested requests @@ -139,7 +139,7 @@ module Biplane headers = HTTP::Headers.new headers.add("Content-Type", "application/json") - params = normalize(config.as_params, {"id": object.id}) + params = normalize(config.for_update, {"id": object.id}) response = @client.put(config.collection_route.to_s, headers, params.to_json) as HTTP::Client::Response case response.status_code From a84c5d137118cbf5ab7b824aba64a5bbecf2777e Mon Sep 17 00:00:00 2001 From: Luke van der Hoeven Date: Wed, 24 Aug 2016 14:25:59 -0400 Subject: [PATCH 09/10] prepare updated release --- src/biplane/version.cr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/biplane/version.cr b/src/biplane/version.cr index ec33c30..391d091 100644 --- a/src/biplane/version.cr +++ b/src/biplane/version.cr @@ -1,3 +1,3 @@ module Biplane - VERSION = "1.3.11-prod" + VERSION = "1.3.12" end From 84ab5c9702bd3090c65519205e0b909fb1e13491 Mon Sep 17 00:00:00 2001 From: Luke van der Hoeven Date: Wed, 24 Aug 2016 14:26:26 -0400 Subject: [PATCH 10/10] drop prod-specific build --- Makefile | 5 ----- 1 file changed, 5 deletions(-) diff --git a/Makefile b/Makefile index 7e6c0e3..009ce1c 100644 --- a/Makefile +++ b/Makefile @@ -11,11 +11,6 @@ build: build-container: docker build -t articulate/biplane:local . -build-for-prod: - docker build --no-cache -t articulate/biplane:prod . - docker tag articulate/biplane:prod articulate/biplane:prod - docker push articulate/biplane:prod - build-release: crystal build --release src/cli.cr -o biplane