Skip to content

Commit

Permalink
Merge pull request #28 from domapic/release-1.0.0-beta.2
Browse files Browse the repository at this point in the history
Release 1.0.0 beta.2
  • Loading branch information
javierbrea authored May 2, 2019
2 parents 9613801 + f37392b commit 1b0b88d
Show file tree
Hide file tree
Showing 13 changed files with 786 additions and 359 deletions.
14 changes: 0 additions & 14 deletions .npmignore

This file was deleted.

2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ addons:
script:
- npm test
- npm run coveralls
- sonar-scanner
- 'if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then sonar-scanner; fi'
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Fixed
### Removed

## [1.0.0-beta.2] - 2019-05-02
### BREAKING CHANGES
- Ability data types "integer" and "float" are deprecated in favour of using only "number".
- getUsers method in controller api client now request all users by default. This will result in a forbidden response if plugin has not admin permissions granted. For requesting only operator users, which is allowed to all plugins, a role filter has to be provided.

### Added
- Add config and apiKeys methods to Controller api Client.

## [1.0.0-beta.1] - 2019-01-06
### BREAKING CHANGES
- From now, connection process not compatible with Domapic Controller versions lower than 1.0.0-alpha.14.
Expand Down
26 changes: 18 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ Each ability must be an object, which key will be the name of the ability (will

* `description` `<string>` Description of the ability.
* `data` `<object>` Defines the type of data that the ability will handle, and will be used to execute data validation for the action, state and event related api resources. If the ability don't needs any type of data, this property should be omitted (in that case, the ability can't have an state, because it has no sense).
* `type` `<string>` Type of data. Can be one of `string`, `boolean`, `number`, `integer` or `float`
* `type` `<string>` Type of data. Can be one of `string`, `boolean`, `number`
* `enum` `<array>` Used to restrict data to a fixed set of values. It must be an array with at least one element, where each element is unique.
* `minLength` `<number>` Minimum length of the data string.
* `maxLength` `<number>` Maximum length of the data string.
Expand Down Expand Up @@ -327,29 +327,39 @@ Wildcards are available for subscribing to all events of an specific `entity`, o
* `service:*` - All events of "service" entity.
* `*:created` - All operations "created" of any entity.

### Controller interface
### Controller api client

A Domapic Plugin provides an interface that allows to perform operations into the Controller. All methods returns a Promise, and are available under the `plugin.controller` object, which contains:
A Domapic Plugin provides an api client that allows to perform operations into the Controller. All methods returns a Promise, and are available under the `plugin.controller` object, which contains:

* `users` - Interface for Controller's "user" entities:
* `me()` - Returns data about plugin user
* `get([id][,filter])` - Returns users data. Because of security reasons, only "operator" users will be returned. Request can be filtered providing an specific user id as \<String\>, or an \<Object\> containing any other api supported filter (such as `{name:'foo-name'}`).
* `get([id][,filter])` - Returns users data. Because of security reasons, only "operator" users are allowed to be returned until plugin has "adminPermissions". For plugins without admin permissions granted, request must be filtered providing a role filter as `{role:'operator'}`. Extra filters can be provided too, id as \<String\>, or an \<Object\> containing any other api supported filter (such as `{name:'foo-name'}`).
* `create(userData)` - Creates an user, and returns the new `id`. Only creating users with "operator" role is supported.
* `services`- Interface for Controller's "service" entities:
* `get([id][,filter])` - Returns services data. Request can be filtered providing an specific service id as \<String\>, or an \<Object\> containing any other api supported filter (such as `{type:'module'}`).
* `servicePluginConfigs`- Interface for Controller's "servicePluginConfigs" entities:
* `get([id][,filter])` - Returns servicePluginConfigs data. Request can be filtered providing an specific servicePluginConfig id as \<String\>, or an \<Object\> containing any other api supported filter (such as `{service:'service-id', 'plugin-package-name': 'foo-plugin-package-name'}`).
* `create(configData)` - Creates a service plugin configuratin, and returns the new `id`.
* `update(id, configData)` - Updates an specific service plugin configuration.
* `get([id][,filter])` - Returns servicePluginConfigs data. Request can be filtered providing an specific servicePluginConfig id as \<String\>, or an \<Object\> containing any other api supported filter (such as `{service:'service-id', 'plugin-package-name': 'foo-plugin-package-name'}`).
* `create(configData)` - Creates a service plugin configuratin, and returns the new `id`.
* `update(id, configData)` - Updates an specific service plugin configuration.
* `abilities`- Interface for Controller's "ability" entities:
* `get([id][,filter])` - Returns abilities data. Request can be filtered providing an specific ability id as \<String\>, or an \<Object\> containing any other api supported filter (such as `{service:'foo-module-id'}`).
* `state(id)` - Returns state of provided ability.
* `action(id, data)` - Dispatches ability action with provided data.
* `logs` - Interface for Controller's "log" entity:
* `get()` - Returns Controller logs with all modules' actions and events.
* `get([filter])` - Returns Controller logs with all modules' actions and events. A query filter can be provided.
* `config` - Interface for Controller's configuration.
* `get()` - Returns Controller configuration.
* `apiKeys` - Interface for Controller's "securityTokens" entity, filtered by "apiKey" type. For security reasons, only plugins with admin permissions granted can access to this resource, otherwise requests will return a forbidden error.
* `get()` - Returns Controller user's api keys.
* `create(userData)` - Creates an api key for the given user, and returns it.

Consult the Controller Swagger interface to get more info about supported filters (queries) and requested data for each api interface.

### Security in plugins

Plugins are registered into the Controller with a "plugin" role, that, for security reasons, can't perform certain types of operations and have limited access to some resources, such as security tokens, etc.
Depending of the plugin behavior, it may need accessing to this resources to can work. If a plugin need special permissions to work, you can use the Controller web interface to modify it, and check the "grant admin permissions" option.

## Start the server

First of all, remember to start the server programatically after adding the abilities in your code:
Expand Down
38 changes: 30 additions & 8 deletions lib/ApiClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,29 @@ const ApiClient = function (service, url, apiKey) {
// auth tokens
const getAuthTokens = filter => client.get(uris.query(uris.authTokens(), filter))

const getApiKeys = filter => {
const query = {
...filter,
type: 'apiKey'
}
return client.get(uris.query(uris.authTokens(), query))
}

const createApiKey = data => client.post(uris.authApiKey(), data)

const getUser = id => client.get(uris.user(id))

// users
const getUsers = filter => {
if (_.isString(filter)) {
return getUser(filter)
}
if (filter) {
return client.get(uris.query(uris.users(), filter))
}
return client.get(uris.query(uris.users()))
return client.get(uris.users())
}

const getUser = id => client.get(uris.user(id))

const getOperatorUsers = filter => {
if (_.isString(filter)) {
return getUser(filter)
Expand All @@ -36,8 +47,10 @@ const ApiClient = function (service, url, apiKey) {
return client.get(uris.query(uris.users(), query))
}

const createUser = data => client.post(uris.users(), data)
.then(getCreatedId)
const createUser = data => {
return client.post(uris.users(), data)
.then(getCreatedId)
}

const createOperatorUser = data => client.post(uris.users(), { ...data, role: 'operator' })
.then(getCreatedId)
Expand Down Expand Up @@ -106,12 +119,19 @@ const ApiClient = function (service, url, apiKey) {

const sendAbilityAction = (id, data) => client.post(uris.abilityAction(id), data)

// logs
const getLogs = () => client.get(uris.logs())
const getLogs = filter => {
if (filter) {
return client.get(uris.query(uris.logs(), filter))
}
return client.get(uris.logs())
}

const getConfig = () => client.get(uris.config())

return {
getAuthTokens,
createApiKey,
getApiKeys,

getUsers,
getOperatorUsers,
Expand All @@ -135,7 +155,9 @@ const ApiClient = function (service, url, apiKey) {
sendAbilityEvent,
sendAbilityAction,

getLogs
getLogs,

getConfig
}
}

Expand Down
11 changes: 9 additions & 2 deletions lib/Connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,8 @@ const Connection = function (service, security) {
const controllerClient = {
users: {
me: new ControllerClient('getUserMe'),
get: new ControllerClient('getOperatorUsers'),
create: new ControllerClient('createOperatorUser')
get: new ControllerClient('getUsers'),
create: new ControllerClient('createUser')
},
services: {
get: new ControllerClient('getServices')
Expand All @@ -238,6 +238,13 @@ const Connection = function (service, security) {
},
logs: {
get: new ControllerClient('getLogs')
},
config: {
get: new ControllerClient('getConfig')
},
apiKeys: {
get: new ControllerClient('getApiKeys'),
create: new ControllerClient('createApiKey')
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/abilitySchema.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"properties": {
"type": {
"type": "string",
"enum": ["number", "integer", "float"]
"enum": ["number"]
},
"enum": {
"type": "array"
Expand Down
4 changes: 4 additions & 0 deletions lib/uris.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const SERVICES = 'services'
const SERVICE_PLUGIN_CONFIGS = 'service-plugin-configs'
const USERS = 'users'
const LOGS = 'logs'
const CONFIG = 'config'

const normalizeName = name => kebabCase(name)

Expand Down Expand Up @@ -49,6 +50,8 @@ const user = id => resolveUri(USERS, id)

const logs = () => LOGS

const config = () => CONFIG

// Helpers
const query = (baseUri, queryParams) => `${baseUri}?${querystring.stringify(omitBy(queryParams, isUndefined))}`

Expand All @@ -72,6 +75,7 @@ module.exports = {
user,
usersMe,
logs,
config,
// Helpers
query
}
Loading

0 comments on commit 1b0b88d

Please sign in to comment.