Last active
March 26, 2018 07:02
-
-
Save bdpiprava/db455c9b9c12c93a596bf85519a01c6d to your computer and use it in GitHub Desktop.
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
## Get plugin settings | |
- Plugin is not loaded | |
- Should return error response with failed dependecy status code(424) | |
- If the plugin is loaded then following checks we have to perform before returning response - | |
* If the plugin does not support plugin-settings then return an error message (have to decide what it will be :) ) | |
* When plugin supports plugin setting check if plugin-setting exist for the plugin | |
a. If plugin setting does not exist then return 404. | |
b. When plugin settings exist in DB then | |
- Check if user is a admin | |
- encrypt the secure variables in plugin-settings using plugin info and return the response | |
## Create a plugin settings | |
- If Plugin is not loaded then return an error - failed dependency | |
- If Plugin is loaded then following checks we have to perform before returning response - | |
* If the plugin does not support plugin-settings then return an error message (have to decide what it will be :) ) | |
* When plugin supports plugin setting check | |
a. If plugin settings already exists then return the error response | |
b. Validate with the plugin using extension | |
c. On successful validation store it in DB and return response else return 422 on validation failure | |
## Update a plugin settings | |
- If Plugin is not loaded then return an error | |
- If Plugin is loaded then following checks we have to perform before returning response - | |
* When plugin supports plugin setting check - | |
a. If plugin settings do not exist then return the error 404 response. | |
b. When plugin-settings exists to check if it is a stale request. | |
- Stale request, | |
* Return error response | |
- Not a stale request | |
* Validate with the plugin using extension | |
* On successful validation store it in DB and return response else return 422 | |
In pluginDao saveOrUpdate should remove cache entry after the transaction is commited |
Get Plugin settings
When it does not exist.
Request
curl --request GET \
--url 'http://{{GO_SERVER_URL}}/api/admin/plugin_settings/cd.go.contrib.elastic-agent.docker-swarm' \
--header 'Accept: application/vnd.go.cd.v1+json'
Response status code: NOT_FOUND(404)
{
"message": "Either the resource you requested was not found, or you are not authorized to perform this action."
}
When Plugin settings exist
Request
curl --request GET \
--url 'http://{{GO_SERVER_URL}}/api/admin/plugin_settings/cd.go.contrib.elastic-agent.docker-swarm' \
--header 'Accept: application/vnd.go.cd.v1+json'
Response status code: 200
{
"_links": {
"self": {
"href": "http://localhost:8153/go/api/admin/plugin_settings/cd.go.contrib.elastic-agent.docker-swarm"
},
"doc": {
"href": "https://api.gocd.org/#plugin-settings"
},
"find": {
"href": "http://localhost:8153/go/api/admin/plugin_settings/:plugin_id"
}
},
"plugin_id": "cd.go.contrib.elastic-agent.docker-swarm",
"configuration": [
{
"key": "environment_variables"
},
{
"key": "docker_ca_cert"
},
{
"key": "private_registry_username",
"value": "docker-user"
},
{
"key": "docker_uri",
"value": "https://fmtgocddockermanager01.gocd.org:2376/"
},
{
"key": "private_registry_server",
"value": "https://docker.gocd.org"
},
{
"key": "go_server_url",
"value": "https://build.gocd.org:8154/go"
},
{
"key": "docker_client_key"
},
{
"key": "max_docker_containers",
"value": "60"
},
{
"key": "docker_client_cert"
},
{
"key": "private_registry_password",
"encrypted_value": "8xok/YGUAoU="
},
{
"key": "enable_private_registry_authentication",
"value": "true"
},
{
"key": "auto_register_timeout",
"value": "5"
}
]
}
Create plugin settings when it is alreadu exist in DB
curl --request POST \
--url 'http://{{GO_SERVER_URL}}/api/admin/plugin_settings' \
--header 'Accept: application/vnd.go.cd.v1+json' \
--header 'Content-Type: application/json' \
--data '{
"plugin_id": "cd.go.contrib.elastic-agent.docker-swarm",
"configuration": [
{
"key": "environment_variables"
},
{
"key": "docker_ca_cert",
"encrypted_value": ""
},
{
"key": "private_registry_username",
"value": "docker-user"
},
{
"key": "docker_uri",
"value": "https://fmtgocddockermanager01.gocd.org:2376/"
},
{
"key": "private_registry_server",
"value": "https://docker.gocd.org"
},
{
"key": "go_server_url",
"value": "https://build.gocd.org:8154/go"
},
{
"key": "docker_client_key",
"encrypted_value": ""
},
{
"key": "max_docker_containers",
"value": "60"
},
{
"key": "docker_client_cert",
"encrypted_value": ""
},
{
"key": "private_registry_password",
"value": ""
},
{
"key": "enable_private_registry_authentication",
"value": "true"
},
{
"key": "auto_register_timeout",
"value": "5"
}
]
}
'
Response UNPROCESSABLE_ENTITY(422)
{
"message": "Save failed. The plugin settings for plugin[cd.go.contrib.elastic-agent.docker-swarm] is already exist. In order to update the plugin settings refer the https://api.gocd.org/18.3.0/#update-plugin-settings.",
"data": {
"_links": {
"self": {
"href": "http://localhost:8153/go/api/admin/plugin_settings/cd.go.contrib.elastic-agent.docker-swarm"
},
"doc": {
"href": "https://api.gocd.org/#plugin-settings"
},
"find": {
"href": "http://localhost:8153/go/api/admin/plugin_settings/:plugin_id"
}
},
"plugin_id": "cd.go.contrib.elastic-agent.docker-swarm",
"configuration": [
{
"key": "environment_variables"
},
{
"key": "docker_ca_cert"
},
{
"key": "private_registry_username",
"value": "docker-user"
},
{
"key": "docker_uri",
"value": "https://fmtgocddockermanager01.gocd.org:2376/"
},
{
"key": "private_registry_server",
"value": "https://docker.gocd.org"
},
{
"key": "go_server_url",
"value": "https://build.gocd.org:8154/go"
},
{
"key": "docker_client_key"
},
{
"key": "max_docker_containers",
"value": "60"
},
{
"key": "docker_client_cert"
},
{
"key": "private_registry_password"
},
{
"key": "enable_private_registry_authentication",
"value": "true"
},
{
"key": "auto_register_timeout",
"value": "5"
}
]
}
}
Update plugin settings -> 200
Request
curl --request PUT \
--url 'http://{{GO_SERVER_URL}}/api/admin/plugin_settings/cd.go.contrib.elastic-agent.docker-swarm' \
--header 'Accept: application/vnd.go.cd.v1+json' \
--header 'Content-Type: application/json' \
--header 'If-Match: "aa20416daae4f26191a211e2fda63d6d"' \
--data '{
"plugin_id": "cd.go.contrib.elastic-agent.docker-swarm",
"configuration": [
{
"key": "environment_variables"
},
{
"key": "docker_ca_cert",
"encrypted_value": ""
},
{
"key": "private_registry_username",
"value": "docker-user"
},
{
"key": "docker_uri",
"value": "https://fmtgocddockermanager01.gocd.org:2376/"
},
{
"key": "private_registry_server",
"value": "https://docker.gocd.org"
},
{
"key": "go_server_url",
"value": "https://build.gocd.org:8154/go"
},
{
"key": "docker_client_key",
"encrypted_value": ""
},
{
"key": "max_docker_containers",
"value": "60"
},
{
"key": "docker_client_cert",
"encrypted_value": ""
},
{
"key": "private_registry_password",
"value": "bar"
},
{
"key": "enable_private_registry_authentication",
"value": "true"
},
{
"key": "auto_register_timeout",
"value": "5"
}
]
}
'
Response
{ "_links": { "self": { "href": "http://localhost:8153/go/api/admin/plugin_settings/cd.go.contrib.elastic-agent.docker-swarm" }, "doc": { "href": "https://api.gocd.org/#plugin-settings" }, "find": { "href": "http://localhost:8153/go/api/admin/plugin_settings/:plugin_id" } }, "plugin_id": "cd.go.contrib.elastic-agent.docker-swarm", "configuration": [ { "key": "environment_variables" }, { "key": "docker_ca_cert" }, { "key": "private_registry_username", "value": "docker-user" }, { "key": "docker_uri", "value": "https://fmtgocddockermanager01.gocd.org:2376/" }, { "key": "private_registry_server", "value": "https://docker.gocd.org" }, { "key": "go_server_url", "value": "https://build.gocd.org:8154/go" }, { "key": "docker_client_key" }, { "key": "max_docker_containers", "value": "60" }, { "key": "docker_client_cert" }, { "key": "private_registry_password", "encrypted_value": "rw8RZMOKOqI=" }, { "key": "enable_private_registry_authentication", "value": "true" }, { "key": "auto_register_timeout", "value": "5" } ] }Update plugin settings -> 422
Error on secure and plain text plugin settings porperties
Request
curl --request PUT \
--url 'http://{{GO_SERVER_URL}}/api/admin/plugin_settings/cd.go.contrib.elastic-agent.docker-swarm' \
--header 'Accept: application/vnd.go.cd.v1+json' \
--header 'Content-Type: application/json' \
--header 'If-Match: "aa20416daae4f26191a211e2fda63d6d"' \
--data '{
"plugin_id": "cd.go.contrib.elastic-agent.docker-swarm",
"configuration": [
{
"key": "environment_variables"
},
{
"key": "docker_ca_cert",
"encrypted_value": ""
},
{
"key": "private_registry_username",
"value": "docker-user"
},
{
"key": "docker_uri",
"value": ""
},
{
"key": "private_registry_server",
"value": "https://docker.gocd.org"
},
{
"key": "go_server_url",
"value": "https://build.gocd.org:8154/go"
},
{
"key": "docker_client_key",
"encrypted_value": ""
},
{
"key": "max_docker_containers",
"value": "60"
},
{
"key": "docker_client_cert",
"encrypted_value": ""
},
{
"key": "private_registry_password",
"value": ""
},
{
"key": "enable_private_registry_authentication",
"value": "true"
},
{
"key": "auto_register_timeout",
"value": "5"
}
]
}
'
Response
{ "message": "Save failed. There are errors in the plugin settings. Please fix them and resubmit.", "data": { "_links": { "self": { "href": "http://localhost:8153/go/api/admin/plugin_settings/cd.go.contrib.elastic-agent.docker-swarm" }, "doc": { "href": "https://api.gocd.org/#plugin-settings" }, "find": { "href": "http://localhost:8153/go/api/admin/plugin_settings/:plugin_id" } }, "plugin_id": "cd.go.contrib.elastic-agent.docker-swarm", "configuration": [ { "key": "environment_variables" }, { "key": "docker_ca_cert" }, { "key": "private_registry_username", "value": "docker-user" }, { "errors": { "docker_uri": [ "Docker URI must not be blank." ] }, "key": "docker_uri", "value": "" }, { "key": "private_registry_server", "value": "https://docker.gocd.org" }, { "key": "go_server_url", "value": "https://build.gocd.org:8154/go" }, { "key": "docker_client_key" }, { "key": "max_docker_containers", "value": "60" }, { "key": "docker_client_cert" }, { "errors": { "private_registry_password": [ "Private Registry Password must not be blank." ] }, "key": "private_registry_password" }, { "key": "enable_private_registry_authentication", "value": "true" }, { "key": "auto_register_timeout", "value": "5" } ] } }
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Create plugin settings
Plugin is not loaded
FAILED_DEPENDENCY(424)
status code.Plugin is loaded
Before storing plugin settings in DB it should perform following checks.
UNAUTHORIZED(401)
status code.UNPROCESSABLE_ENTITY(422)
status code when plugin id is not specified or it is empty.UNPROCESSABLE_ENTITY(422)
status code.PluginInfo
does not have any metadata about plugin-settings then it is not supported.Take a lock on using
keyToLockOn(pluginId)
to block other create plugin settings requests. After taking lock run following validationsUNPROCESSABLE_ENTITY(422)
status code when plugin setting already created for the plugin.UNPROCESSABLE_ENTITY(422)
on validation error.Update plugin settings
Plugin is not loaded
FAILED_DEPENDENCY(424)
status code.Plugin is loaded
Before updating plugin settings in DB it should perform following checks.
UNAUTHORIZED(401)
status code.UNPROCESSABLE_ENTITY(422)
status code when plugin id is not specified or it is empty.UNPROCESSABLE_ENTITY(422)
status code.Take a lock on using
keyToLockOn(pluginId)
to block other create/update plugin settings requests. After taking lock run following validationsNOT_FOUND(404)
status code.UNPROCESSABLE_ENTITY(422)
on validation error.EntityHashingService
UNPROCESSABLE_ENTITY(422)
Get plugin settings
Plugin is not loaded
FAILED_DEPENDENCY(424)
status code.Plugin is loaded
UNPROCESSABLE_ENTITY(422)
status code.UNAUTHORIZED(401)
status code.NOT_FOUND(404)
status code.