Skip to content

Commit

Permalink
add support for AWS::Neptune:* resources (brabster#171)
Browse files Browse the repository at this point in the history
* add support for AWS::Neptune:* resources
  • Loading branch information
shooit authored and keerts committed Mar 14, 2019
1 parent 304257c commit 22f2cd7
Show file tree
Hide file tree
Showing 10 changed files with 255 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/crucible/aws/neptune.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
(ns crucible.aws.neptune
"Resources in AWS::Neptune::*"
(:require [clojure.spec.alpha :as s]
[crucible.encoding.keys :refer [->key]]
[crucible.resources :refer [spec-or-ref defresource]]))

;;; property specs shared among AWS::Neptune::* resources

(def db-cluster-identifier-regex #"^[a-zA-Z][a-zA-Z0-9_\-]*[a-zA-Z0-9_]")
(s/def ::db-cluster-identifier
(spec-or-ref (s/and string? #(re-matches db-cluster-identifier-regex %))))
(defmethod ->key :db-cluster-identifier [_] "DBClusterIdentifier")

(s/def ::db-subnet-group-name (spec-or-ref string?))
(defmethod ->key :db-subnet-group-name [_] "DBSubnetGroupName")

(s/def ::description (spec-or-ref string?))

(s/def ::family (spec-or-ref #{"neptune1"}))

(s/def ::name (spec-or-ref string?))

(s/def ::parameters (spec-or-ref (s/map-of string? string?)))
51 changes: 51 additions & 0 deletions src/crucible/aws/neptune/db_cluster.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
(ns crucible.aws.neptune.db-cluster
"AWS::Neptune::DBCluster"
(:require [clojure.spec.alpha :as s]
[crucible.aws.neptune :as neptune]
[crucible.encoding.keys :refer [->key]]
[crucible.resources :refer [spec-or-ref defresource]]))

(s/def ::availability-zones (spec-or-ref (s/* string?)))

(s/def ::backup-retention-period (spec-or-ref pos-int?))

(s/def ::db-cluster-identifier ::neptune/db-cluster-identifier)

(s/def ::db-cluster-parameter-group-name (spec-or-ref string?))
(defmethod ->key :db-cluster-parameter-group-name [_] "DBClusterParameterGroupName")

(s/def ::db-subnet-group-name ::neptune/db-subnet-group-name)

(s/def ::iam-auth-enabled (spec-or-ref boolean?))

(s/def ::kms-key-id (spec-or-ref string?))

(s/def ::port (spec-or-ref pos-int?))

(s/def ::preferred-backup-window (spec-or-ref string?))

(s/def ::preferred-maintenance-window (spec-or-ref string?))

(s/def ::snapshot-identifier (spec-or-ref string?))

(s/def ::storage-encrypted (spec-or-ref boolean?))

(s/def ::vpc-security-group-ids (spec-or-ref (s/* string?)))

(s/def ::db-cluster
(s/keys :opt [::availability-zones
::backup-retention-period
::db-cluster-identifier
::db-cluster-parameter-group-name
::db-subnet-group-name
::iam-auth-enabled
::kms-key-id
::port
::preferred-backup-window
::preferred-maintenance-window
::snapshot-identifier
::storage-encrypted
:crucible.resources/tags
::vpc-security-group-ids]))

(defresource db-cluster "AWS::Neptune::DBCluster" ::db-cluster)
23 changes: 23 additions & 0 deletions src/crucible/aws/neptune/db_cluster_parameter_group.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
(ns crucible.aws.neptune.db-cluster-parameter-group
(:require [clojure.spec.alpha :as s]
[crucible.aws.neptune :as neptune]
[crucible.resources :refer [spec-or-ref defresource]]))

(s/def ::description ::neptune/description)

(s/def ::family ::neptune/family)

(s/def ::parameters ::neptune/parameters)

(s/def ::name ::neptune/name)

(s/def ::db-cluster-parameter-group
(s/keys :req [::description
::parameters
::family]
:opt [:crucible.resources/tags
::name]))

(defresource db-cluster-parameter-group
"AWS::Neptune::DBClusterParameterGroup"
::db-cluster-parameter-group)
41 changes: 41 additions & 0 deletions src/crucible/aws/neptune/db_instance.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
(ns crucible.aws.neptune.db-instance
"Specs for AWS::Neptune::DBInstance"
(:require [clojure.spec.alpha :as s]
[crucible.aws.neptune :as neptune]
[crucible.encoding.keys :refer [->key]]
[crucible.resources :refer [spec-or-ref defresource]]))

(s/def ::allow-major-version-upgrade (spec-or-ref boolean?))

(s/def ::auto-minor-version-upgrade (spec-or-ref boolean?))

(s/def ::availability-zone (spec-or-ref string?))

(s/def ::db-cluster-identifier ::neptune/db-cluster-identifier)

(s/def ::db-instance-class (spec-or-ref string?))
(defmethod ->key :db-instance-class [_] "DBInstanceClass")

(s/def ::db-instance-identifier (spec-or-ref string?))
(defmethod ->key :db-instance-identifier [_] "DBInstanceIdentifier")

(s/def ::db-parameter-group-name (spec-or-ref string?))
(defmethod ->key :db-parameter-group-name [_] "DBParameterGroupName")

(s/def ::db-subnet-group-name ::neptune/db-subnet-group-name)

(s/def ::preferred-maintenance-window (spec-or-ref string?))

(s/def ::db-instance
(s/keys :req [::db-instance-class]
:opt [::allow-major-version-upgrade
::auto-minor-version-upgrade
::availability-zone
::db-cluster-identifier
::db-instance-identifier
::db-parameter-group-name
::db-subnet-group-name
::preferred-maintenance-window
:crucible.resources/tags]))

(defresource db-instance "AWS::Neptune::DBInstance" ::db-instance)
21 changes: 21 additions & 0 deletions src/crucible/aws/neptune/db_parameter_group.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
(ns crucible.aws.neptune.db-parameter-group
(:require [clojure.spec.alpha :as s]
[crucible.aws.neptune :as neptune]
[crucible.resources :refer [spec-or-ref defresource]]))

(s/def ::description ::neptune/description)

(s/def ::family ::neptune/family)

(s/def ::parameters ::neptune/parameters)

(s/def ::name ::neptune/name)

(s/def ::db-parameter-group
(s/keys :req [::description
::family]
:opt [::parameters
:crucible.resources/tags
::name]))

(defresource db-parameter-group "AWS::Neptune::DBParameterGroup" ::db-parameter-group)
21 changes: 21 additions & 0 deletions src/crucible/aws/neptune/db_subnet_group.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
(ns crucible.aws.neptune.db-subnet-group
"Specs for AWS::Neptune::DBSubnetGroup"
(:require [clojure.spec.alpha :as s]
[crucible.aws.neptune :as neptune]
[crucible.encoding.keys :refer [->key]]
[crucible.resources :refer [spec-or-ref defresource]]))

(s/def ::db-subnet-group-description (spec-or-ref string?))
(defmethod ->key :db-subnet-group-description [_] "DBSubnetGroupDescription")

(s/def ::db-subnet-group-name ::neptune/db-subnet-group-name)

(s/def ::subnet-ids (spec-or-ref (s/* string?)))

(s/def ::db-subnet-group
(s/keys :req [::db-subnet-group-description
::subnet-ids]
:opt [::db-subnet-group-name
:crucible.resources/tags]))

(defresource db-subnet-group "AWS::Neptune::SubnetGroup" ::db-subnet-group)
21 changes: 21 additions & 0 deletions test/crucible/aws/neptune/db_cluster_parameter_group_test.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
(ns crucible.aws.neptune.db-cluster-parameter-group-test
(:require [crucible.aws.neptune.db-cluster-parameter-group :as dbcpg]
[crucible.resources :as r]
[clojure.test :refer :all]))

(deftest neptune-db-cluster-parameter-group-test
(testing "encode"
(is (= {"Type" "AWS::Neptune::DBClusterParameterGroup",
"Properties"
{"Description" "description",
"Parameters" {"param1" "value1", "param2" "value2"},
"Family" "neptune1",
"Tags" [{"Key" "key", "Value" "value"}]}}
(crucible.encoding/rewrite-element-data
(dbcpg/db-cluster-parameter-group
{::dbcpg/description "description"
::dbcpg/parameters {"param1" "value1"
"param2" "value2"}
::dbcpg/family "neptune1"
::r/tags [{::r/key "key"
::r/value "value"}]}))))))
17 changes: 17 additions & 0 deletions test/crucible/aws/neptune/db_cluster_test.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
(ns crucible.aws.neptune.db-cluster-test
(:require [crucible.aws.neptune.db-cluster :as dbc]
[crucible.resources :as r]
[clojure.test :refer :all]))

(deftest neptune-db-cluster-test
(testing "encode"
(is (= {"Type" "AWS::Neptune::DBCluster",
"Properties"
{"DBClusterIdentifier" "abc-def-123",
"IamAuthEnabled" true,
"Tags" [{"Key" "key", "Value" "value"}]}}
(crucible.encoding/rewrite-element-data
(dbc/db-cluster {::dbc/db-cluster-identifier "abc-def-123"
::dbc/iam-auth-enabled true
::r/tags [{::r/key "key"
::r/value "value"}]}))))))
19 changes: 19 additions & 0 deletions test/crucible/aws/neptune/db_instance_test.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
(ns crucible.aws.neptune.db-instance-test
(:require [crucible.aws.neptune.db-instance :as dbi]
[crucible.resources :as r]
[clojure.test :refer :all]))

(deftest neptune-instance-test
(testing "encode"
(is (= {"Type" "AWS::Neptune::DBInstance",
"Properties"
{"AllowMajorVersionUpgrade" false,
"AutoMinorVersionUpgrade" true,
"DBInstanceClass" "db.r4.large",
"Tags" [{"Key" "key", "Value" "value"}]}}
(crucible.encoding/rewrite-element-data
(dbi/db-instance {::dbi/allow-major-version-upgrade false
::dbi/auto-minor-version-upgrade true
::dbi/db-instance-class "db.r4.large"
::r/tags [{::r/key "key"
::r/value "value"}]}))))))
18 changes: 18 additions & 0 deletions test/crucible/aws/neptune/db_parameter_group_test.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
(ns crucible.aws.neptune.db-parameter-group-test
(:require [crucible.aws.neptune.db-parameter-group :as dbpg]
[crucible.resources :as r]
[clojure.test :refer :all]))

(deftest neptune-db-parameter-group-test
(testing "encode"
(is (= {"Type" "AWS::Neptune::DBParameterGroup",
"Properties"
{"Description" "description",
"Family" "neptune1",
"Tags" [{"Key" "key", "Value" "value"}]}}
(crucible.encoding/rewrite-element-data
(dbpg/db-parameter-group
{::dbpg/description "description"
::dbpg/family "neptune1"
::r/tags [{::r/key "key"
::r/value "value"}]}))))))

0 comments on commit 22f2cd7

Please sign in to comment.