Skip to content

Instantly share code, notes, and snippets.

@bdpiprava
Last active March 26, 2018 07:02
Show Gist options
  • Save bdpiprava/db455c9b9c12c93a596bf85519a01c6d to your computer and use it in GitHub Desktop.
Save bdpiprava/db455c9b9c12c93a596bf85519a01c6d to your computer and use it in GitHub Desktop.
## 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
@bdpiprava
Copy link
Author

bdpiprava commented Mar 26, 2018

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"
            }
        ]
    }
}

@bdpiprava
Copy link
Author

bdpiprava commented Mar 26, 2018

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" } ] }

@bdpiprava
Copy link
Author

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