Skip to content

Commit

Permalink
Add deleteOld parameter for action#create
Browse files Browse the repository at this point in the history
  • Loading branch information
jiangpengcheng committed Oct 29, 2020
1 parent 0bb1650 commit f284a6c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ trait WhiskActionsApi extends WhiskCollectionAPI with PostActionActivation with
* - 500 Internal Server Error
*/
override def create(user: Identity, entityName: FullyQualifiedEntityName)(implicit transid: TransactionId) = {
parameter('overwrite ? false) { overwrite =>
parameter('overwrite ? false, 'deleteOld ? false) { (overwrite, deleteOld) =>
entity(as[WhiskActionPut]) { content =>
val request = content.resolve(user.namespace)
val checkAdditionalPrivileges = entitleReferencedEntities(user, Privilege.READ, request.exec).flatMap {
Expand All @@ -230,6 +230,10 @@ trait WhiskActionsApi extends WhiskCollectionAPI with PostActionActivation with
onComplete(checkAdditionalPrivileges) {
case Success(_) =>
onComplete(WhiskActionVersionList.get(entityName, entityStore)) {
case Success(result) if (result.versions.size >= actionMaxVersionLimit && !deleteOld) =>
terminate(
Forbidden,
s"[PUT] entity has ${result.versions.size} versions exist which exceed $actionMaxVersionLimit, delete one of them before create new one or pass deleteOld=true to delete oldest version automatically")
case Success(result) =>
val id = result.matchedDocId(content.version).getOrElse(entityName.toDocId)
putEntity(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1627,6 +1627,10 @@ class ActionsApiTests extends ControllerTestCommon with WhiskActionsApi {

val content = WhiskActionPut(parameters = Some(Parameters("x", "X")))
Put(s"$collectionPath/${action.name}", content) ~> Route.seal(routes(creds)) ~> check {
status should be(Forbidden)
}

Put(s"$collectionPath/${action.name}?deleteOld=true", content) ~> Route.seal(routes(creds)) ~> check {
status should be(OK)
}
// the first version should be deleted automatically
Expand Down

0 comments on commit f284a6c

Please sign in to comment.