changes to retrieve quota information and send it as part of VerifyAPIKey response
diff --git a/api.go b/api.go index 1020414..b234e04 100644 --- a/api.go +++ b/api.go
@@ -9,6 +9,7 @@ ) type sucResponseDetail struct { + Org string `json:"org"` Key string `json:"key"` ExpiresAt int64 `json:"expiresAt"` IssuedAt int64 `json:"issuedAt"` @@ -17,6 +18,9 @@ RedirectionURIs string `json:"redirectionURIs"` AppId string `json:"appId"` AppName string `json:"appName"` + Quota string `json:quota` + QuotaTimeUnit string `json:quotaTimeUnit` + QuotaInterval int `json:quotaInterval` } type errResultDetail struct { @@ -92,8 +96,8 @@ db := getDB() // DANGER: This relies on an external TABLE - DATA_SCOPE is maintained by apidApigeeSync - var env, tenantId string - error := db.QueryRow("SELECT env, scope FROM DATA_SCOPE WHERE id = ?;", scopeuuid).Scan(&env, &tenantId) + var org, env, tenantId string + error := db.QueryRow("SELECT org, env, scope FROM DATA_SCOPE WHERE id = ?;", scopeuuid).Scan(&org, &env, &tenantId) switch { case error == sql.ErrNoRows: @@ -110,29 +114,32 @@ sSql := ` SELECT - ap.api_resources, - ap.environments, + ap.api_resources, + ap.environments, c.issued_at, c.status, a.callback_url, ad.email, ad.id, - "developer" as ctype + "developer" as ctype, + COALESCE(ap.quota, '') as quota, + COALESCE(ap.quota_time_unit, '') as quotatimeunit, + COALESCE(ap.quota_interval, 0) as quotainterval FROM - APP_CREDENTIAL AS c + APP_CREDENTIAL AS c INNER JOIN APP AS a ON c.app_id = a.id - INNER JOIN DEVELOPER AS ad + INNER JOIN DEVELOPER AS ad ON ad.id = a.developer_id - INNER JOIN APP_CREDENTIAL_APIPRODUCT_MAPPER as mp - ON mp.appcred_id = c.id + INNER JOIN APP_CREDENTIAL_APIPRODUCT_MAPPER as mp + ON mp.appcred_id = c.id INNER JOIN API_PRODUCT as ap ON ap.id = mp.apiprdt_id - WHERE (UPPER(ad.status) = 'ACTIVE' - AND mp.apiprdt_id = ap.id + WHERE (UPPER(ad.status) = 'ACTIVE' + AND mp.apiprdt_id = ap.id AND mp.app_id = a.id - AND mp.appcred_id = c.id - AND UPPER(mp.status) = 'APPROVED' + AND mp.appcred_id = c.id + AND UPPER(mp.status) = 'APPROVED' AND UPPER(a.status) = 'APPROVED' - AND c.id = $1 + AND c.id = $1 AND c.tenant_id = $2) UNION ALL SELECT @@ -143,7 +150,10 @@ a.callback_url, ad.name, ad.id, - "company" as ctype + "company" as ctype, + COALESCE(ap.quota, '') as quota, + COALESCE(ap.quota_time_unit, '') as quotatimeunit, + COALESCE(ap.quota_interval, 0) as quotainterval FROM APP_CREDENTIAL AS c INNER JOIN APP AS a ON c.app_id = a.id @@ -162,10 +172,12 @@ AND c.tenant_id = $2) ;` - var status, redirectionURIs, appName, appId, resName, resEnv, cType string + var status, redirectionURIs, appName, appId, resName, resEnv, cType, quota, quotaTimeUnit string var issuedAt int64 + var quotaInterval int + err := db.QueryRow(sSql, key, tenantId).Scan(&resName, &resEnv, &issuedAt, &status, - &redirectionURIs, &appName, &appId, &cType) + &redirectionURIs, &appName, &appId, &cType, "a, "aTimeUnit, "aInterval) switch { case err == sql.ErrNoRows: reason := "API Key verify failed for (" + key + ", " + scopeuuid + ", " + path + ")" @@ -202,6 +214,7 @@ resp := kmsResponseSuccess{ Type: "APIKeyContext", RspInfo: sucResponseDetail{ + Org: org, Key: key, ExpiresAt: expiresAt, IssuedAt: issuedAt, @@ -209,7 +222,10 @@ RedirectionURIs: redirectionURIs, Type: cType, AppId: appId, - AppName: appName}, + AppName: appName, + Quota: quota, + QuotaTimeUnit: quotaTimeUnit, + QuotaInterval: quotaInterval}, } return json.Marshal(resp) }
diff --git a/apidVerifyAPIKey-api.yaml b/apidVerifyAPIKey-api.yaml index b351771..7e635dd 100644 --- a/apidVerifyAPIKey-api.yaml +++ b/apidVerifyAPIKey-api.yaml
@@ -57,6 +57,7 @@ responseType: APIKeyContext resultCode: "SUCCESS" result: + org: "abc123" key: abc123 expiresAt: 1234567890 issuedAt: 1234567890 @@ -65,6 +66,9 @@ appName: abc123 appId: abc123 cType: "developer" + quota: abc123 + quotaTimeUnit: "minute" + quotaInterval: 1 default: description: 4xx or 5xx errors schema: @@ -123,6 +127,8 @@ result: type: object properties: + org: + type: string key: type: string expiresAt: @@ -139,9 +145,16 @@ type: string cType: type: string + quota: + type: string + quotaTimeUnit: + type: string + quotaInterval: + type: int example: type: "APIKeyContext" result: + org: "abc123" key: "abc123" expiresAt: 1234567890 issuedAt: 1234567890 @@ -150,6 +163,9 @@ appName: "abc123" appId: "abc123" cType: "company OR developer" + quota: "quotaName" + quotaTimeUnit: "timeUnit" + quotaInterval: 1 VerifyAPIKeyResponseFailed: allOf:
diff --git a/listener.go b/listener.go index 3fae5c0..bac48b5 100644 --- a/listener.go +++ b/listener.go
@@ -363,9 +363,9 @@ */ func insertAPIproducts(rows []common.Row, txn *sql.Tx) bool { - var scope, apiProduct, res, env, tenantId string - - prep, err := txn.Prepare("INSERT INTO API_PRODUCT (id, api_resources, environments, tenant_id,_change_selector) VALUES($1,$2,$3,$4,$5)") + var scope, apiProduct, res, env, tenantId, quota, quotaTimeUnit string + var quotaInterval int + prep, err := txn.Prepare("INSERT INTO API_PRODUCT (id, api_resources, environments, tenant_id,_change_selector, quota, quota_time_unit, quota_interval) VALUES($1,$2,$3,$4,$5,$6,$7,$8)") if err != nil { log.Error("INSERT API_PRODUCT Failed: ", err) return false @@ -379,6 +379,9 @@ ele.Get("api_resources", &res) ele.Get("environments", &env) ele.Get("tenant_id", &tenantId) + ele.Get("quota", "a) + ele.Get("quota_time_unit", "aTimeUnit) + ele.Get("quota_interval", "aInterval) /* Mandatory params check */ if apiProduct == "" || scope == "" || tenantId == "" { @@ -390,7 +393,10 @@ res, env, tenantId, - scope) + scope, + quota, + quotaTimeUnit, + quotaInterval) if err != nil { log.Error("INSERT API_PRODUCT Failed: (", apiProduct, ", ", tenantId, ")", err)