2023-09-07 - Account Limits Docs
Jump to navigation
Jump to search
Service - Account Limits
Account Limits are used for services that need to limit some action that users perform.
Example Work Flow
Work Flow Description
- When need to perform an action that has limit. User need to check limit with account limits service before performing an action.
- If that limitTag needs to check for limitType static. Send a request to StaticLimitProcess and wait for static limit status return. No need to confirm or cancel after getting static limit status.
- If that limitTag needs to check for limitType timeBasedDynamic or runningTotal. Send a request to ReservedDynamicUsage and wait for dynamic limit status. Need to confirm or cancel after getting dynamic limit status.
Note!!!: limitTag can check with multiple limitType.
Account Limits Function
StaticLimitProcess
Use to check with static limitType.
Request Parameters
- userId
- Type: string
- Required: Yes
- limitTag
- Type: string
- Required: Yes
- value
- Type: number
- Required: Yes
- rbacType
- Type: string
- Required: Yes
- targetId
- Type: string
- Required: No
- callingFlow
- Type: string
- Required: Yes
- callingFlowProperties
- Type: object
- Required: Yes
Request Example
{
userId: "string",
limitTag: "string",
value: number,
rbacType: "string",
targetId: "string",
callingFlow:"string",
callingFlowProperties: {
prop1:"string",
prop2: number
}
}
Response Elements
- returnMessage
- Type: object
- returnMessage.limitTag
- Type: string
- returnMessage.limitValue
- Type: number
- errorsFound
- Type: array
- passStatus
- Type: boolean
- passBackProperties
- Type: object
Response Example
{
returnMessage: {
limitTag:"string",
limitValue: number
},
errorsFound: [],
passStatus: boolean,
passBackProperties: {
prop1:"string",
prop2: number
}
}
ReservedDynamicUsage
Use to check with runningTotal and timeBasedDynamic limitType.
Request Parameters
- userId
- Type: string
- Required: Yes
- limitTag
- Type: string
- Required: Yes
- value
- Type: number
- Required: Yes
- usedTimestamp
- Type: number
- Required: Yes
- decreaseUsage
- Type: boolean
- Required: false
- overDecreaseError
- Type: boolean
- Required: false
- rbacType
- Type: string
- Required: Yes
- targetId
- Type: string
- Required: No
- callingFlow
- Type: string
- Required: Yes
- callingFlowProperties
- Type: object
- Required: Yes
Request Example
{
userId: "string",
limitTag: "string",
value: number,
usedTimestamp: number,
decreaseUsage: boolean,
overDecreaseError: boolean,
rbacType: "string",
targetId: "string",
callingFlow:"string",
callingFlowProperties: {
prop1:"string",
prop2: number
}
}
Response Elements
- returnMessage
- Type: object
- returnMessage.limitFound
- Type: object
- returnMessage.limitFound.runningTotal
- Type: object
- returnMessage.limitFound.runningTotal.uniqueIdentify.usedTimestampId
- Type: string
- returnMessage.limitFound.timeBasedDynamic
- Type: object
- returnMessage.limitFound.timeBasedDynamic.uniqueIdentify.usedTimestampId
- Type: string
- returnMessage.limitTag
- Type: string
- errorsFound
- Type: array
- passStatus
- Type: boolean
- passBackProperties
- Type: object
Response Example
{
returnMessage: {
limitFound:{
runningTotal: {
passStatus: boolean,
maxLimit: number,
currentUsage: number,
uniqueIdentify:{
usedTimestampId: "string"
},
},
timeBasedDynamic:{
<period in milliseconds>: {
passStatus: boolean,
maxLimit: number,
currentUsage: number
},
...
uniqueIdentify:{
usedTimestampId: "string"
},
}
}
limitTag: "string",
},
errorsFound: [],
passStatus: boolean,
passBackProperties: {
prop1:"string",
prop2: number
}
}
ConfirmUsage
CancelUsage
Using Account Limits
When need limit user when uploading an image. Limit by size per image, number of uploads per day, and total images that can be uploaded.
For example, limit size per image is 5 MB. Can upload 50 images per day.And total of 1000 images can be uploaded.
limitTag: uploadImage
- Client needs to create a record in UserRoles table in service Rbac before using service Account Limits.
- ref. for create user and role API Gateway Authorizers, Deploy service stack - User Authentication
- Use roleId to create roleLimit in RoleLimit table at service AccountLimits.
record 1 : { roleLimitId:"this-is-uuid-for-role-basicUserA_uploadImage", limitType: "static", limitValue: 5 }
Upload limit size per image
record 2 : { roleLimitId:"this-is-uuid-for-role-basicUserA_uploadImage", limitType: "timeBasedDynamic_86400000", limitValue: 100 }
Can upload 50 images per day.
record 3 : { roleLimitId:"this-is-uuid-for-role-basicUserA_uploadImage", limitType: "runningTotal", limitValue: 1000 }
Total of 1000 images can be uploaded