-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathModuleConfig.cfc
180 lines (154 loc) · 6.33 KB
/
ModuleConfig.cfc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/**
* Copyright Since 2005 ColdBox Framework by Luis Majano and Ortus Solutions, Corp
* www.ortussolutions.com
* ---
*/
component {
// Module Properties
this.title = "stachebox";
this.author = "Ortus Solutions";
this.webURL = "https://github.com/coldbox-modules/stachebox";
this.description = "A Logstash and Bug Management Platform for Coldbox";
// Model Namespace
this.modelNamespace = "stachebox";
this.entrypoint = "stachebox";
// CF Mapping
this.cfmapping = "stachebox";
// Dependencies
this.dependencies = [ "logstash", "BCrypt", "cbrestbasehandler", "cbsecurity", "cbvalidation", "mementifier", "cfmigrations", "cbmailservices" ];
// App Helpers
this.applicationHelper = [
"models/mixins/elixirPath.cfm"
];
/**
* Configure Module
*/
function configure(){
var applicationName = server.coldfusion.productname == "Lucee" ? getApplicationSettings().name : getApplicationMetadata().name;
settings = {
// The index to be used to store the module settings overrides
"settingsIndex" : getSystemSetting( "STACHEBOX_SETTINGS_INDEX", ".stachebox_settings" ),
// The index used to to manage user accounts ( if using the StacheBox users service for cbSecurity and cbAuth )
"usersIndex" : getSystemSetting( "STACHEBOX_USERS_INDEX", ".stachebox_users" ),
// A default index pattern for logstash logs ( e.g. application exceptions). May be overriden in the UI settings admin
"logIndexPattern" : "logs-coldbox-*",
// A default index pattern for filebeat logs ( e.g. server log files/entries ). May be overriden in the UI settings admin
"beatsIndexPattern" : "filebeat-*",
// An initial admin email address. When present, it will create the initial login.
"adminEmail" : getSystemSetting( "STACHEBOX_ADMIN_EMAIL", "" ),
// An initial admin password to login
"adminPassword" : getSystemSetting( "STACHEBOX_ADMIN_PASSWORD", "" ),
// A username/email to use for the default token reporter ( no login privileges )
"tokenReporter" : getSystemSetting( "STACHEBOX_TOKEN_REPORTER", "nologin@stachebox.io" ),
// Whether to promote the module UI to the root URLS of the application
"isStandalone" : getSystemSetting( "STACHEBOX_STANDALONE", false ),
// Notification Email "from"
"notificationsFrom" : getSystemSetting( "STACHEBOX_NOTIFICATIONS_FROM", "no-reply@stachebox.io" ),
// The cbSecurity configuration overrides for this module
"cbsecurity" : {
"authentication" : {
"userService" : "UserService@stachebox"
},
"firewall" : {
// Module Relocation when an invalid access is detected, instead of each rule declaring one.
"invalidAuthenticationEvent" : "stachebox:api.v1.BaseAPIHandler.onAuthenticationFailure",
// Default Auhtentication Action: override or redirect when a user has not logged in
"defaultAuthenticationAction" : "override",
// Module override event when an invalid access is detected, instead of each rule declaring one.
"invalidAuthorizationEvent" : "stachebox:api.v1.BaseAPIHandler.onAuthorizationFailure",
// Default Authorization Action: override or redirect when a user does not have enough permissions to access something
"defaultAuthorizationAction" : "override"
},
"jwt" : {
"validator" : "JWTService@cbsecurity",
"expiration" : 120,
"enableRefreshTokens" : true,
"enableAutoRefreshValidator" : true
}
},
// the cbauth overrides for this module
"cbauth" : {
"userServiceClass" : "UserService@stachebox"
}
};
cbi18n = {
"resourceBundles" : {
"stachebox" : "#moduleMapping#/includes/i18n/stachebox"
}
}
// Try to look up the release based on a box.json
if( !isNull( appmapping ) ) {
var boxJSONPath = expandPath( '/' & appmapping & '/box.json' );
if( fileExists( boxJSONPath ) ) {
var boxJSONRaw = fileRead( boxJSONPath );
if( isJSON( boxJSONRaw ) ) {
var boxJSON = deserializeJSON( boxJSONRaw );
if( boxJSON.keyExists( 'version' ) ) {
settings.release = boxJSON.version;
if( boxJSON.keyExists( 'slug' ) ) {
settings.release = boxJSON.slug & '@' & settings.release;
} else if( boxJSON.keyExists( 'name' ) ) {
settings.release = boxJSON.name & '@' & settings.release;
}
}
}
}
}
interceptors = [
{ class="stachebox.interceptors.BasicAuthentication" },
{ class="stachebox.interceptors.Stachebox" }
];
interceptorSettings = {
customInterceptionPoints = [
"onStacheboxSettingUpdate",
"ensureStacheboxMappings"
]
};
}
/**
* Fired when the module is registered and activated.
*/
function onLoad(){
if( settings.isStandalone ){
scopeRoutingToRoot();
}
if( url.keyExists( "seed" ) && url.seed ){
controller.getWirebox().getInstance( "migrationService:elasticsearch" ).seed( "Seed-Test-Data" );
}
}
/**
* Fired when the module is unregistered and unloaded
*/
function onUnload(){}
/**
* Sets the module as the main application
* Snipped and morphed from contentbox-ui:ModuleConfig.cfc:onLoad()
*/
private function scopeRoutingToRoot(){
var router = controller.getRoutingService().getRouter();
// get parent routes so we can re-mix them later
var parentRoutes = router.getRoutes();
var newRoutes = [];
// iterate and only keep module routing
for(var x=1; x lte arrayLen(parentRoutes); x++){
if( parentRoutes[ x ].pattern NEQ ":handler/" AND
parentRoutes[ x ].pattern NEQ ":handler/:action/" ){
arrayAppend(newRoutes, parentRoutes[ x ]);
}
}
// override new cleaned routes
router.setRoutes( newRoutes );
router.getModuleRoutingTable().stachebox.each( function( route ){
// append module location to it so the route is now system wide
var args = duplicate( route );
// Check if handler defined
if( structKeyExists( args, "handler" ) ){
args.handler = "stachebox:#args.handler#";
}
// add it as main application route.
router.addRoute( argumentCollection=args );
});
// change the default event of the entire app
controller.setSetting( "DefaultEvent","stachebox:index" );
}
}