Skip to content

Commit

Permalink
Merge pull request #278 from slr71/multiyear-subscriptions
Browse files Browse the repository at this point in the history
CORE-1983: add support for multiyear subscriptions
  • Loading branch information
slr71 authored Mar 1, 2024
2 parents 708f03a + b5b118e commit 2f6781a
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 30 deletions.
9 changes: 6 additions & 3 deletions project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
(string/trim (:out (sh "git" "rev-parse" "HEAD")))
""))

(defproject org.cyverse/terrain "2.12.0-SNAPSHOT"
(defproject org.cyverse/terrain "3.0.0-SNAPSHOT"
:description "Discovery Environment API gateway/API services catch-all project"
:url "https://github.com/cyverse-de/terrain"
:license {:name "BSD Standard License"
Expand Down Expand Up @@ -66,7 +66,8 @@
[jonase/eastwood "0.3.10"]
[reifyhealth/lein-git-down "0.4.1"]]
:profiles {:dev {:dependencies [[clj-http-fake "1.0.3"]]
:resource-paths ["conf/test" "test-resources"]}
:resource-paths ["conf/test" "test-resources"]
:jvm-opts ["-Dotel.javaagent.enabled=false"]}
:uberjar {:aot :all}}
:main ^:skip-aot terrain.core
:ring {:handler terrain.core/dev-handler
Expand All @@ -79,4 +80,6 @@
["sonatype-releases"
{:url "https://oss.sonatype.org/content/repositories/releases/"}]
["public-github" {:url "git://github.com" :protocol :https}]]
:jvm-opts ["-Dlogback.configurationFile=/etc/iplant/de/logging/terrain-logging.xml" "-javaagent:./opentelemetry-javaagent.jar" "-Dotel.resource.attributes=service.name=terrain"])
:jvm-opts ["-Dlogback.configurationFile=/etc/iplant/de/logging/terrain-logging.xml"
"-javaagent:./opentelemetry-javaagent.jar"
"-Dotel.resource.attributes=service.name=terrain"])
40 changes: 20 additions & 20 deletions src/terrain/routes/qms.clj
Original file line number Diff line number Diff line change
Expand Up @@ -92,43 +92,43 @@
:body [body schema/SubscriptionRequests]
:return schema/BulkSubscriptionResponse
(ok (handlers/add-subscriptions params body)))

(context "/:subscription-uuid" []
:path-params [subscription-uuid :- schema/SubscriptionID]

(context "/addons" []
(GET "/" []
:middleware [require-authentication]
:summary schema/ListSubscriptionAddonsSummary
:description schema/ListSubscriptionAddonsDescription
:return schema/SubscriptionAddonListResponse
(ok (n/list-subscription-addons subscription-uuid)))

(POST "/" []
:middleware [require-authentication]
:summary schema/AddSubscriptionAddonSummary
:description schema/AddSubscriptionAddonDescription
:body [body schema/AddonIDBody]
:return schema/SubscriptionAddonResponse
(ok (n/add-subscription-addon subscription-uuid (:uuid body))))

(context "/:uuid" []
:path-params [uuid :- schema/SubscriptionAddonID]

(GET "/" []
:middleware [require-authentication]
:summary schema/GetSubscriptionAddonSummary
:description schema/GetSubscriptionAddonDescription
:return schema/SubscriptionAddonResponse
(ok (n/get-subscription-addon uuid)))

(PUT "/" []
:middleware [require-authentication]
:summary schema/UpdateSubscriptionAddonSummary
:description schema/UpdateSubscriptionAddonDescription
:body [body schema/UpdateSubscriptionAddon]
(ok (n/update-subscription-addon (assoc body :uuid uuid))))

(DELETE "/" []
:middleware [require-authentication]
:summary schema/DeleteSubscriptionAddonSummary
Expand All @@ -151,15 +151,15 @@
:description schema/ListAddonsDescription
:return schema/AddonListResponse
(ok (n/list-addons)))

(PUT "/" []
:middleware [require-authentication]
:summary schema/UpdateAddonSummary
:description schema/UpdateAddonDescription
:body [body schema/UpdateAddon]
:return schema/AddonResponse
(ok (n/update-addon body)))

(DELETE "/:uuid" []
:middleware [require-authentication]
:summary schema/DeleteAddonSummary
Expand Down Expand Up @@ -216,71 +216,71 @@
(context "/users" []
(context "/:username" []
:path-params [username :- schema/Username]

(context "/plan" []
(GET "/" []
:middleware [[require-service-account ["cyverse-subscription-updater"]]]
:summary schema/GetSubscriptionSummary
:description schema/GetSubscriptionDescription
:return schema/SubscriptionPlanResponse
(ok (qms/subscription username)))

(PUT "/:plan-name" []
:middleware [[require-service-account ["cyverse-subscription-updater"]]]
:summary schema/UpdateSubscriptionSummary
:description schema/UpdateSubscriptionDescription
:path-params [plan-name :- schema/PlanName]
:return schema/SuccessResponse
(ok (qms/update-subscription username plan-name {:paid true}))))))

(context "/addons" []
(GET "/" []
:middleware [[require-service-account ["cyverse-subscription-updater"]]]
:summary schema/ListAddonsSummary
:description schema/ListAddonsDescription
:return schema/AddonListResponse
(ok (n/list-addons))))

(context "/subscriptions" []
(context "/:subscription-uuid" []
:path-params [subscription-uuid :- schema/SubscriptionID]

(context "/addons" []
(GET "/" []
:middleware [[require-service-account ["cyverse-subscription-updater"]]]
:summary schema/ListSubscriptionAddonsSummary
:description schema/ListSubscriptionAddonsDescription
:return schema/SubscriptionAddonListResponse
(ok (n/list-subscription-addons subscription-uuid)))

(POST "/" []
:middleware [[require-service-account ["cyverse-subscription-updater"]]]
:summary schema/AddSubscriptionAddonSummary
:description schema/AddSubscriptionAddonDescription
:body [body schema/AddonIDBody]
:return schema/SubscriptionAddonResponse
(ok (n/add-subscription-addon subscription-uuid (:uuid body))))

(context "/:uuid" []
:path-params [uuid :- schema/SubscriptionAddonID]

(GET "/" []
:middleware [[require-service-account ["cyverse-subscription-updater"]]]
:summary schema/GetSubscriptionAddonSummary
:description schema/GetSubscriptionAddonDescription
:return schema/SubscriptionAddonResponse
(ok (n/get-subscription-addon uuid)))

(PUT "/" []
:middleware [[require-service-account ["cyverse-subscription-updater"]]]
:summary schema/UpdateSubscriptionAddonSummary
:description schema/UpdateSubscriptionAddonDescription
:body [body schema/UpdateSubscriptionAddon]
(ok (n/update-subscription-addon (assoc body :uuid uuid))))

(DELETE "/" []
:middleware [[require-service-account ["cyverse-subscription-updater"]]]
:summary schema/DeleteSubscriptionAddonSummary
:description schema/DeleteSubscriptionAddonDescription
:return schema/SubscriptionAddonResponse
(ok (n/delete-subscription-addon uuid))))))))))
(ok (n/delete-subscription-addon uuid))))))))))
20 changes: 13 additions & 7 deletions src/terrain/routes/schemas/qms.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(ns terrain.routes.schemas.qms
(:require [common-swagger-api.schema :refer [PagingParams describe]]
[schema.core :refer [defschema Any optional-key maybe enum]])
[schema.core :as s :refer [defschema Any optional-key maybe enum]])
(:import [java.util UUID]))

(def GetAllPlansSummary "Returns a list of all plans registered in QMS")
Expand Down Expand Up @@ -61,9 +61,10 @@
:status (describe String "The status of the response")})

(defschema ResourceType
{:id ResourceID
:name ResourceTypeName
:unit (describe String "The unit of the resource type")})
{:id ResourceID
:name ResourceTypeName
:unit (describe String "The unit of the resource type")
:consumable (describe Boolean "True if using the resource consumes it permanently")})

(defschema ResourceTypesResponse
{:result (describe [ResourceType] "The list of resource types")
Expand Down Expand Up @@ -160,7 +161,9 @@
(defschema SubscriptionRequest
{(optional-key :username) (describe String "The username to associate with the subscription")
(optional-key :plan_name) (describe String "The name of the plan to associate with the subscription")
:paid (describe Boolean "True if the user paid for the subscription")})
:paid (describe Boolean "True if the user paid for the subscription")
(optional-key :periods) (describe Integer "The number of subscription periods")
(optional-key :end_date) (describe String "The end date of the subscription.")})

(defschema SubscriptionRequests
{(optional-key :subscriptions) (describe (maybe [SubscriptionRequest]) "The list of subscription requests")})
Expand All @@ -169,8 +172,11 @@
{(optional-key :force)
(describe String "True if the subscription should be created even if the user already has a higher level plan")})

;; The :periods parameter uses s/Int so that we can get automatic coercion.
(defschema AddSubscriptionParams
{:paid (describe Boolean "True if the user paid for the subscription")})
{:paid (describe Boolean "True if the user paid for the subscription")
(optional-key :periods) (describe s/Int "The number of subscription periods")
(optional-key :end_date) (describe String "The end date of the subscription")})

(defschema ListSubscriptionsParams
(merge PagingParams
Expand Down Expand Up @@ -250,4 +256,4 @@
(optional-key :paid) (describe Boolean "Sets whether the subscription add-on needs to be charged for")})

(defschema SubscriptionAddonListResponse
{:subscription_addons (describe [SubscriptionAddon] "The returned list of subscription add-ons")})
{:subscription_addons (describe [SubscriptionAddon] "The returned list of subscription add-ons")})

0 comments on commit 2f6781a

Please sign in to comment.