-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #73 from ba-st/42-Operational-Plugin-Configuration
Add a new Operational Plugin: Application Configuration
- Loading branch information
Showing
12 changed files
with
614 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# Application Configuration | ||
|
||
One of the operational plugins. It exposes information about the configuration of the running application. | ||
|
||
This plugin is disabled by default and allows configuring the available configuration providers. This configuration is made via the `#operations` config. | ||
|
||
For example: | ||
|
||
```smalltalk | ||
Dictionary new | ||
at: #operations put: ( | ||
Dictionary new | ||
at: 'application-configuration' | ||
put: {#enabled -> true. #'definitions' -> application definitions. #provider -> application configuration } asDictionary; | ||
yourself | ||
); | ||
yourself | ||
``` | ||
|
||
## API | ||
|
||
### Getting configuration information | ||
|
||
- Endpoint: `/application-configuration` | ||
- Allowed HTTP methods: `GET` | ||
- Supported media types: | ||
- `application/vnd.stargate.operational-application-configuration+json` | ||
- `text/plain` | ||
- Authentication: Required | ||
- Authorization: Requires `read:application-configuration` | ||
- Expected Responses: | ||
- `200 OK` | ||
|
||
Example response: | ||
|
||
```json | ||
HTTP/1.1 200 OK | ||
... | ||
[ | ||
{ | ||
"type": "optional", | ||
"name": "port", | ||
"current-value": 6000, | ||
"default": 4000 | ||
}, | ||
{ | ||
"type": "mandatory", | ||
"name": "base-url", | ||
"current-value": "https://api.example.com" | ||
}, | ||
{ | ||
"type": "flag", | ||
"name": "debug-mode", | ||
"current-value": true | ||
} | ||
] | ||
``` | ||
|
||
``` | ||
HTTP/1.1 200 OK | ||
... | ||
port = 6000 | ||
base-url = https://api.example.com | ||
debug-mode = true | ||
``` |
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
69 changes: 69 additions & 0 deletions
69
...e/Stargate-Application-Configuration-Tests/ApplicationConfigurationPluginAPITest.class.st
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,69 @@ | ||
" | ||
I'm the test case for the Application Configuration API | ||
" | ||
Class { | ||
#name : #ApplicationConfigurationPluginAPITest, | ||
#superclass : #OperationalPluginAPITest, | ||
#category : #'Stargate-Application-Configuration-Tests' | ||
} | ||
|
||
{ #category : #private } | ||
ApplicationConfigurationPluginAPITest >> configurationDefinitions [ | ||
|
||
^ Array with: ( FlagArgument named: 'debug-mode' ) | ||
] | ||
|
||
{ #category : #private } | ||
ApplicationConfigurationPluginAPITest >> configurationProvider [ | ||
|
||
^ [ Dictionary new | ||
at: 'debug-mode' put: true; | ||
yourself | ||
] | ||
] | ||
|
||
{ #category : #running } | ||
ApplicationConfigurationPluginAPITest >> operationsConfiguration [ | ||
|
||
^ super operationsConfiguration | ||
at: ApplicationConfigurationPlugin endpoint | ||
put: { | ||
#enabled -> true . | ||
#definitions -> self configurationDefinitions . | ||
#provider -> self configurationProvider | ||
} asDictionary; | ||
yourself | ||
] | ||
|
||
{ #category : #private } | ||
ApplicationConfigurationPluginAPITest >> requiredPermissions [ | ||
|
||
^ #('read:application-configuration') | ||
] | ||
|
||
{ #category : #tests } | ||
ApplicationConfigurationPluginAPITest >> testGetConfigurationWithPermissions [ | ||
|
||
| response | | ||
|
||
response := self newJWTAuthorizedClient | ||
url: self operationsUrl / ApplicationConfigurationPlugin endpoint asUrl; | ||
setAccept: ZnMimeType applicationJson; | ||
get; | ||
response. | ||
|
||
self | ||
assert: response isSuccess; | ||
assert: response contentType asMediaType | ||
equals: 'application/vnd.stargate.operational-application-configuration+json;version=1.0.0' asMediaType; | ||
withJsonFromContentsIn: response | ||
do: [ :configurations | | ||
self | ||
withTheOnlyOneIn: configurations | ||
do: [ :config | | ||
self | ||
assert: config name equals: 'debug-mode'; | ||
assert: ( config at: #'current-value' ) | ||
] | ||
] | ||
] |
36 changes: 36 additions & 0 deletions
36
...plication-Configuration-Tests/ApplicationConfigurationPluginConfigurationAPITest.class.st
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,36 @@ | ||
" | ||
I'm a test for API configuration options | ||
" | ||
Class { | ||
#name : #ApplicationConfigurationPluginConfigurationAPITest, | ||
#superclass : #OperationalPluginAPITest, | ||
#category : #'Stargate-Application-Configuration-Tests' | ||
} | ||
|
||
{ #category : #running } | ||
ApplicationConfigurationPluginConfigurationAPITest >> operationsConfiguration [ | ||
|
||
^ super operationsConfiguration | ||
at: ApplicationConfigurationPlugin endpoint put: { #enabled -> false } asDictionary; | ||
yourself | ||
] | ||
|
||
{ #category : #private } | ||
ApplicationConfigurationPluginConfigurationAPITest >> requiredPermissions [ | ||
|
||
^ #('read:application-configuration') | ||
] | ||
|
||
{ #category : #tests } | ||
ApplicationConfigurationPluginConfigurationAPITest >> testPluginIsDisabled [ | ||
|
||
self | ||
deny: ( api isEnabled: ApplicationConfigurationPlugin ); | ||
should: [ self newJWTAuthorizedClient | ||
url: self operationsUrl / ApplicationConfigurationPlugin endpoint asUrl; | ||
setAccept: ZnMimeType textPlain; | ||
get | ||
] | ||
raise: ZnHttpUnsuccessful | ||
withExceptionDo: [ :error | self assert: error response isNotFound ] | ||
] |
88 changes: 88 additions & 0 deletions
88
source/Stargate-Application-Configuration-Tests/ApplicationConfigurationPluginTest.class.st
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,88 @@ | ||
" | ||
An ApplicationConfigurationPluginTest is a test class for testing the behavior of ApplicationConfigurationPlugin | ||
" | ||
Class { | ||
#name : #ApplicationConfigurationPluginTest, | ||
#superclass : #TestCase, | ||
#category : #'Stargate-Application-Configuration-Tests' | ||
} | ||
|
||
{ #category : #accessing } | ||
ApplicationConfigurationPluginTest >> configuration [ | ||
|
||
^ Dictionary new | ||
at: ApplicationConfigurationPlugin endpoint | ||
put: { | ||
#enabled -> true . | ||
#definitions -> self configurationDefinitions . | ||
#provider -> self configurationProvider | ||
} asDictionary; | ||
yourself | ||
] | ||
|
||
{ #category : #accessing } | ||
ApplicationConfigurationPluginTest >> configurationDefinitions [ | ||
|
||
^ Array | ||
with: ( OptionalArgument named: 'port' defaultingTo: 4000 ) | ||
with: ( MandatoryArgument named: 'base-url' ) | ||
with: ( FlagArgument named: 'debug-mode' ) | ||
] | ||
|
||
{ #category : #accessing } | ||
ApplicationConfigurationPluginTest >> configurationProvider [ | ||
|
||
^ [ Dictionary new | ||
at: 'port' put: 6000; | ||
at: 'base-url' put: 'https://api.example.com'; | ||
at: 'debug-mode' put: true; | ||
yourself | ||
] | ||
] | ||
|
||
{ #category : #tests } | ||
ApplicationConfigurationPluginTest >> testConfigurationAccessing [ | ||
|
||
| plugin definition | | ||
|
||
plugin := ApplicationConfigurationPlugin configuredBy: self configuration. | ||
|
||
self assert: plugin configurationDefinitions size equals: 3. | ||
|
||
definition := plugin configurationDefinitions first. | ||
|
||
self | ||
assert: definition name equals: 'port'; | ||
assert: definition default equals: 4000; | ||
assert: ( plugin currentValueFor: definition ) equals: 6000. | ||
|
||
definition := plugin configurationDefinitions second. | ||
|
||
self | ||
assert: definition name equals: 'base-url'; | ||
assert: ( plugin currentValueFor: definition ) equals: 'https://api.example.com'. | ||
|
||
definition := plugin configurationDefinitions last. | ||
|
||
self | ||
assert: definition name equals: 'debug-mode'; | ||
assert: ( plugin currentValueFor: definition ) | ||
] | ||
|
||
{ #category : #tests } | ||
ApplicationConfigurationPluginTest >> testEnabledByDefault [ | ||
|
||
self deny: ApplicationConfigurationPlugin enabledByDefault | ||
] | ||
|
||
{ #category : #tests } | ||
ApplicationConfigurationPluginTest >> testEndpoint [ | ||
|
||
self assert: ApplicationConfigurationPlugin endpoint equals: 'application-configuration' | ||
] | ||
|
||
{ #category : #tests } | ||
ApplicationConfigurationPluginTest >> testPluginName [ | ||
|
||
self assert: ApplicationConfigurationPlugin pluginName equals: 'Application Configuration' | ||
] |
Oops, something went wrong.