Skip to content

Commit

Permalink
Merge pull request #73 from ba-st/42-Operational-Plugin-Configuration
Browse files Browse the repository at this point in the history
Add a new Operational Plugin: Application Configuration
  • Loading branch information
gcotelli authored Nov 27, 2019
2 parents 46d8235 + 5c6bd08 commit d5b8bfb
Show file tree
Hide file tree
Showing 12 changed files with 614 additions and 4 deletions.
66 changes: 66 additions & 0 deletions docs/ApplicationConfiguration.md
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
```
1 change: 1 addition & 0 deletions docs/Operations.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ An operational plugin has the following characteristics:
- Should be possible to enable/disable/configure it on the fly using an API endpoint (given the proper authorization credentials) using the media controls provided in the plugin representation

## Implemented Plugins
- [Application Configuration](ApplicationConfiguration.md)
- [Application Control](ApplicationControl.md)
- [Application Info](ApplicationInfo.md)
- [Healt Check](HealthCheck.md)
Expand Down
21 changes: 19 additions & 2 deletions source/BaselineOfStargate/BaselineOfStargate.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,14 @@ BaselineOfStargate >> setUpDependencies: spec [

spec
baseline: 'JRPC' with: [ spec repository: 'github://juliendelplanque/JRPC:v3.0.0/src' ];
project: 'JRPC-Deployment' copyFrom: 'JRPC' with: [ spec loads: 'Server-Deployment' ]
project: 'JRPC-Deployment' copyFrom: 'JRPC' with: [ spec loads: 'Server-Deployment' ].

spec
baseline: 'ApplicationStarter'
with: [ spec repository: 'github://ba-st/ApplicationStarter:v1/source' ];
project: 'ApplicationStarter-Deployment'
copyFrom: 'ApplicationStarter'
with: [ spec loads: 'Deployment' ]
]

{ #category : #baselines }
Expand Down Expand Up @@ -107,7 +114,13 @@ BaselineOfStargate >> setUpDeploymentPackages: spec [
spec
package: 'Stargate-Application-Info' with: [ spec requires: 'Stargate-Model' ];
group: 'Application-Info' with: 'Stargate-Application-Info';
group: 'Deployment' with: 'Application-Info'
group: 'Deployment' with: 'Application-Info'.

spec
package: 'Stargate-Application-Configuration'
with: [ spec requires: #('Stargate-Model' 'ApplicationStarter-Deployment') ];
group: 'Application-Configuration' with: 'Stargate-Application-Configuration';
group: 'Deployment' with: 'Application-Configuration'
]

{ #category : #baselines }
Expand Down Expand Up @@ -150,6 +163,10 @@ BaselineOfStargate >> setUpTestPackages: spec [
package: 'Stargate-Application-Info-Tests'
with: [ spec requires: #('Application-Info' 'Stargate-Model-Tests') ];
group: 'Tests' with: 'Stargate-Application-Info-Tests'.
spec
package: 'Stargate-Application-Configuration-Tests'
with: [ spec requires: #('Application-Configuration' 'Stargate-Model-Tests') ];
group: 'Tests' with: 'Stargate-Application-Configuration-Tests'.
spec
package: 'Stargate-Examples-Tests'
with: [ spec requires: #('Dependent-SUnit-Extensions' 'Stargate-Examples') ];
Expand Down
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' )
]
]
]
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 ]
]
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'
]
Loading

0 comments on commit d5b8bfb

Please sign in to comment.