@@ -184,7 +184,7 @@ trait WhiskActionsApi extends WhiskCollectionAPI with PostActionActivation with
184
184
* - 500 Internal Server Error
185
185
*/
186
186
override def create (user : Identity , entityName : FullyQualifiedEntityName )(implicit transid : TransactionId ) = {
187
- parameter(' overwrite ? false ) { overwrite =>
187
+ parameter(' overwrite ? false , ' protection ? false ) { ( overwrite, protection) =>
188
188
entity(as[WhiskActionPut ]) { content =>
189
189
val request = content.resolve(user.namespace)
190
190
val checkAdditionalPrivileges = entitleReferencedEntities(user, Privilege .READ , request.exec).flatMap {
@@ -193,9 +193,15 @@ trait WhiskActionsApi extends WhiskCollectionAPI with PostActionActivation with
193
193
194
194
onComplete(checkAdditionalPrivileges) {
195
195
case Success (_) =>
196
- putEntity(WhiskAction , entityStore, entityName.toDocId, overwrite, update(user, request) _, () => {
197
- make(user, entityName, request)
198
- })
196
+ putEntity(
197
+ WhiskAction ,
198
+ entityStore,
199
+ entityName.toDocId,
200
+ overwrite,
201
+ update(user, request, protection) _,
202
+ () => {
203
+ make(user, entityName, request, protection)
204
+ })
199
205
case Failure (f) =>
200
206
super .handleEntitlementFailure(f)
201
207
}
@@ -307,7 +313,21 @@ trait WhiskActionsApi extends WhiskCollectionAPI with PostActionActivation with
307
313
* - 500 Internal Server Error
308
314
*/
309
315
override def remove (user : Identity , entityName : FullyQualifiedEntityName )(implicit transid : TransactionId ) = {
310
- deleteEntity(WhiskAction , entityStore, entityName.toDocId, (a : WhiskAction ) => Future .successful({}))
316
+ getEntity(WhiskAction .get(entityStore, entityName.toDocId), Some {
317
+ action : WhiskAction =>
318
+ action.annotations.get(" protection" ) match {
319
+ case Some (value) => {
320
+ if (value.convertTo[String ] == " false" ) {
321
+ deleteEntity(WhiskAction , entityStore, entityName.toDocId, (a : WhiskAction ) => Future .successful({}))
322
+ } else {
323
+ complete(MethodNotAllowed , " this action can't be deleted until protection annotation is updated to false" )
324
+ }
325
+ }
326
+ case None => {
327
+ deleteEntity(WhiskAction , entityStore, entityName.toDocId, (a : WhiskAction ) => Future .successful({}))
328
+ }
329
+ }
330
+ })
311
331
}
312
332
313
333
/**
@@ -387,7 +407,7 @@ trait WhiskActionsApi extends WhiskCollectionAPI with PostActionActivation with
387
407
/**
388
408
* Creates a WhiskAction instance from the PUT request.
389
409
*/
390
- private def makeWhiskAction (content : WhiskActionPut , entityName : FullyQualifiedEntityName )(
410
+ private def makeWhiskAction (content : WhiskActionPut , entityName : FullyQualifiedEntityName , protection : Boolean )(
391
411
implicit transid : TransactionId ) = {
392
412
val exec = content.exec.get
393
413
val limits = content.limits map { l =>
@@ -412,7 +432,9 @@ trait WhiskActionsApi extends WhiskCollectionAPI with PostActionActivation with
412
432
limits,
413
433
content.version getOrElse SemVer (),
414
434
content.publish getOrElse false ,
415
- (content.annotations getOrElse Parameters ()) ++ execAnnotation(exec))
435
+ (content.annotations getOrElse Parameters ()) ++ execAnnotation(exec) ++ Parameters (
436
+ " protection" ,
437
+ if (protection) " true" else " false" ))
416
438
}
417
439
418
440
/** For a sequence action, gather referenced entities and authorize access. */
@@ -437,37 +459,38 @@ trait WhiskActionsApi extends WhiskCollectionAPI with PostActionActivation with
437
459
}
438
460
439
461
/** Creates a WhiskAction from PUT content, generating default values where necessary. */
440
- private def make (user : Identity , entityName : FullyQualifiedEntityName , content : WhiskActionPut )(
462
+ private def make (user : Identity , entityName : FullyQualifiedEntityName , content : WhiskActionPut , protection : Boolean )(
441
463
implicit transid : TransactionId ) = {
442
464
content.exec map {
443
465
case seq : SequenceExec =>
444
466
// check that the sequence conforms to max length and no recursion rules
445
467
checkSequenceActionLimits(entityName, seq.components) map { _ =>
446
- makeWhiskAction(content.replace(seq), entityName)
468
+ makeWhiskAction(content.replace(seq), entityName, protection )
447
469
}
448
470
case supportedExec if ! supportedExec.deprecated =>
449
- Future successful makeWhiskAction(content, entityName)
471
+ Future successful makeWhiskAction(content, entityName, protection )
450
472
case deprecatedExec =>
451
473
Future failed RejectRequest (BadRequest , runtimeDeprecated(deprecatedExec))
452
474
453
475
} getOrElse Future .failed(RejectRequest (BadRequest , " exec undefined" ))
454
476
}
455
477
456
478
/** Updates a WhiskAction from PUT content, merging old action where necessary. */
457
- private def update (user : Identity , content : WhiskActionPut )(action : WhiskAction )(implicit transid : TransactionId ) = {
479
+ private def update (user : Identity , content : WhiskActionPut , protection : Boolean )(action : WhiskAction )(
480
+ implicit transid : TransactionId ) = {
458
481
content.exec map {
459
482
case seq : SequenceExec =>
460
483
// check that the sequence conforms to max length and no recursion rules
461
484
checkSequenceActionLimits(FullyQualifiedEntityName (action.namespace, action.name), seq.components) map { _ =>
462
- updateWhiskAction(content.replace(seq), action)
485
+ updateWhiskAction(content.replace(seq), action, protection )
463
486
}
464
487
case supportedExec if ! supportedExec.deprecated =>
465
- Future successful updateWhiskAction(content, action)
488
+ Future successful updateWhiskAction(content, action, protection )
466
489
case deprecatedExec =>
467
490
Future failed RejectRequest (BadRequest , runtimeDeprecated(deprecatedExec))
468
491
} getOrElse {
469
492
if (! action.exec.deprecated) {
470
- Future successful updateWhiskAction(content, action)
493
+ Future successful updateWhiskAction(content, action, protection )
471
494
} else {
472
495
Future failed RejectRequest (BadRequest , runtimeDeprecated(action.exec))
473
496
}
@@ -477,7 +500,8 @@ trait WhiskActionsApi extends WhiskCollectionAPI with PostActionActivation with
477
500
/**
478
501
* Updates a WhiskAction instance from the PUT request.
479
502
*/
480
- private def updateWhiskAction (content : WhiskActionPut , action : WhiskAction )(implicit transid : TransactionId ) = {
503
+ private def updateWhiskAction (content : WhiskActionPut , action : WhiskAction , protection : Boolean )(
504
+ implicit transid : TransactionId ) = {
481
505
val limits = content.limits map { l =>
482
506
ActionLimits (
483
507
l.timeout getOrElse action.limits.timeout,
@@ -526,7 +550,9 @@ trait WhiskActionsApi extends WhiskCollectionAPI with PostActionActivation with
526
550
limits,
527
551
content.version getOrElse action.version.upPatch,
528
552
content.publish getOrElse action.publish,
529
- (content.annotations getOrElse action.annotations) ++ execAnnotation(exec))
553
+ (content.annotations getOrElse action.annotations) ++ execAnnotation(exec) ++ Parameters (
554
+ " protection" ,
555
+ if (protection) " true" else " false" ))
530
556
.revision[WhiskAction ](action.docinfo.rev)
531
557
}
532
558
0 commit comments