@@ -106,9 +106,7 @@ trait WhiskActionsApi extends WhiskCollectionAPI with PostActionActivation with
106106
107107 /** Config flag for Execute Only for Actions in Shared Packages */
108108 protected def executeOnly =
109- Try ({
110- loadConfigOrThrow[Boolean ](ConfigKeys .sharedPackageExecuteOnly)
111- }).getOrElse(false )
109+ loadConfigOrThrow[Boolean ](ConfigKeys .sharedPackageExecuteOnly)
112110
113111 /** Entity normalizer to JSON object. */
114112 import RestApiCommons .emptyEntityToJsObject
@@ -338,6 +336,56 @@ trait WhiskActionsApi extends WhiskCollectionAPI with PostActionActivation with
338336 deleteEntity(WhiskAction , entityStore, entityName.toDocId, (a : WhiskAction ) => Future .successful({}))
339337 }
340338
339+ /** GET --save which retrieves all source code for an entity **/
340+ private def getEntityWithSourceCode (entityName : FullyQualifiedEntityName , env : Option [Parameters ])(
341+ implicit transid : TransactionId ) = {
342+ getEntity(WhiskAction .resolveActionAndMergeParameters(entityStore, entityName), Some { action : WhiskAction =>
343+ val mergedAction = env map {
344+ action inherit _
345+ } getOrElse action
346+ complete(OK , mergedAction)
347+ })
348+ }
349+
350+ /** Standard GET which just retrieves metadata**/
351+ private def getEntityMetaData (entityName : FullyQualifiedEntityName , env : Option [Parameters ])(
352+ implicit transid : TransactionId ) = {
353+ getEntity(WhiskActionMetaData .resolveActionAndMergeParameters(entityStore, entityName), Some {
354+ action : WhiskActionMetaData =>
355+ val mergedAction = env map {
356+ action inherit _
357+ } getOrElse action
358+ complete(OK , mergedAction)
359+ })
360+ }
361+
362+ /** Checks for package binding case. we don't want to allow get for a package binding in shared package */
363+ private def fetchEntity (entityName : FullyQualifiedEntityName , env : Option [Parameters ], code : Boolean )(
364+ implicit transid : TransactionId ) = {
365+ if (entityName.path.defaultPackage) {
366+ if (code) {
367+ getEntityWithSourceCode(entityName, env)
368+ } else {
369+ getEntityMetaData(entityName, env)
370+ }
371+ } else {
372+ getEntity(
373+ WhiskPackage .resolveBinding(entityStore, entityName.path.toDocId, mergeParameters = true ),
374+ Some { pkg : WhiskPackage =>
375+ val originalPackageLocation = pkg.fullyQualifiedName(withVersion = false ).namespace
376+ if (executeOnly && originalPackageLocation != entityName.namespace) {
377+ terminate(Forbidden , forbiddenGetActionBinding(entityName.toDocId.asString))
378+ } else {
379+ if (code) {
380+ getEntityWithSourceCode(entityName, env)
381+ } else {
382+ getEntityMetaData(entityName, env)
383+ }
384+ }
385+ })
386+ }
387+ }
388+
341389 /**
342390 * Gets action. The action name is prefixed with the namespace to create the primary index key.
343391 *
@@ -351,67 +399,10 @@ trait WhiskActionsApi extends WhiskCollectionAPI with PostActionActivation with
351399 parameter(' code ? true ) { code =>
352400 // check if execute only is enabled, and if there is a discrepancy between the current user's namespace
353401 // and that of the entity we are trying to fetch
354-
355402 if (executeOnly && user.namespace.name != entityName.namespace) {
356403 terminate(Forbidden , forbiddenGetAction(entityName.path.asString))
357404 } else {
358- code match {
359- case true =>
360- // Resolve Binding(Package) of the action
361- if (entityName.path.defaultPackage) {
362- getEntity(WhiskAction .resolveActionAndMergeParameters(entityStore, entityName), Some {
363- action : WhiskAction =>
364- val mergedAction = env map {
365- action inherit _
366- } getOrElse action
367- complete(OK , mergedAction)
368- })
369- } else {
370- getEntity(
371- WhiskPackage .resolveBinding(entityStore, entityName.path.toDocId, mergeParameters = true ),
372- Some { pkg : WhiskPackage =>
373- val originalPackageLocation = pkg.fullyQualifiedName(withVersion = false ).namespace
374- if (executeOnly && originalPackageLocation != entityName.namespace) {
375- terminate(Forbidden , forbiddenGetActionBinding(entityName.toDocId.asString))
376- } else {
377- getEntity(WhiskAction .resolveActionAndMergeParameters(entityStore, entityName), Some {
378- action : WhiskAction =>
379- val mergedAction = env map {
380- action inherit _
381- } getOrElse action
382- complete(OK , mergedAction)
383- })
384- }
385- })
386- }
387- case false =>
388- if (entityName.path.defaultPackage) {
389- getEntity(WhiskActionMetaData .resolveActionAndMergeParameters(entityStore, entityName), Some {
390- action : WhiskActionMetaData =>
391- val mergedAction = env map {
392- action inherit _
393- } getOrElse action
394- complete(OK , mergedAction)
395- })
396- } else {
397- getEntity(
398- WhiskPackage .resolveBinding(entityStore, entityName.path.toDocId, mergeParameters = true ),
399- Some { pkg : WhiskPackage =>
400- val originalPackageLocation = pkg.fullyQualifiedName(withVersion = false ).namespace
401- if (executeOnly && originalPackageLocation != entityName.namespace) {
402- terminate(Forbidden , forbiddenGetActionBinding(entityName.toDocId.asString))
403- } else {
404- getEntity(WhiskActionMetaData .resolveActionAndMergeParameters(entityStore, entityName), Some {
405- action : WhiskActionMetaData =>
406- val mergedAction = env map {
407- action inherit _
408- } getOrElse action
409- complete(OK , mergedAction)
410- })
411- }
412- })
413- }
414- }
405+ fetchEntity(entityName, env, code)
415406 }
416407 }
417408 }
0 commit comments