-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PRESIDECMS-2709 preside utils rest api feature endpoint
- Loading branch information
1 parent
34d98d5
commit abd2815
Showing
5 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/** | ||
* @restUri /features/{feature}/ | ||
*/ | ||
component { | ||
property name="features" inject="coldbox:setting:features"; | ||
|
||
private void function get( required string feature ) { | ||
if ( StructKeyExists( features, arguments.feature ) ) { | ||
restResponse.setData( features[ arguments.feature ] ); | ||
} else { | ||
restResponse.setData( { enabled=false } ); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/** | ||
* @restUri /features/ | ||
*/ | ||
component { | ||
property name="featureService" inject="featureService"; | ||
|
||
private void function get() { | ||
var allFeatures = {}; | ||
|
||
for ( var feature in featureService.getAllEnabledFeatures() ) { | ||
allFeatures[ feature ] = true; | ||
} | ||
|
||
restResponse.setData( allFeatures ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
component { | ||
property name="configuredToken" inject="coldbox:setting:preside.restauthtoken"; | ||
|
||
private string function authenticate() { | ||
var headers = getHTTPRequestData( false ).headers; | ||
var authHeader = headers.Authorization ?: ""; | ||
var token = ""; | ||
|
||
try { | ||
authHeader = toString( toBinary( listRest( authHeader, ' ' ) ) ); | ||
token = ListFirst( authHeader, ":" ); | ||
|
||
if ( !token.trim().len() ) { | ||
throw( type="missing.token" ); | ||
} | ||
} catch( any e ) { | ||
return ""; | ||
} | ||
|
||
if ( token == configuredToken ) { | ||
return token; | ||
} | ||
|
||
return ""; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters