Skip to content

Commit

Permalink
Add support for swarm API endpoints (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
hannseman authored and Liron Levin committed Jul 1, 2019
1 parent 5faaee1 commit f807dc9
Show file tree
Hide file tree
Showing 3 changed files with 144 additions and 0 deletions.
58 changes: 58 additions & 0 deletions core/route_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,64 @@ var routes = []route{
{pattern: "/networks/.+/disconnect", method: "POST", action: ActionNetworkDisconnect},
// https://docs.docker.com/engine/reference/api/docker_remote_api_v1.21/#remove-a-network
{pattern: "/networks/.+", method: "DELETE", action: ActionNetworkRemove},
// https://docs.docker.com/engine/api/v1.37/#operation/SwarmInit
{pattern: "/swarm/init", method: "POST", action: ActionSwarmInit},
// https://docs.docker.com/engine/api/v1.37/#operation/SwarmJoin
{pattern: "/swarm/join", method: "POST", action: ActionSwarmJoin},
// https://docs.docker.com/engine/api/v1.37/#operation/SwarmLeave
{pattern: "/swarm/leave", method: "POST", action: ActionSwarmLeave},
// https://docs.docker.com/engine/api/v1.37/#operation/SwarmUpdate
{pattern: "/swarm/update", method: "POST", action: ActionSwarmUpdate},
// https://docs.docker.com/engine/api/v1.37/#operation/SwarmUnlockkey
{pattern: "/swarm/unlockkey", method: "GET", action: ActionSwarmUnlockKey},
// https://docs.docker.com/engine/api/v1.37/#operation/SwarmUnlock
{pattern: "/swarm/unlock", method: "POST", action: ActionSwarmUnlock},
// https://docs.docker.com/engine/api/v1.37/#operation/SwarmInspect
{pattern: "/swarm", method: "GET", action: ActionSwarmInspect},
// https://docs.docker.com/engine/api/v1.39/#operation/NodeUpdate
{pattern: "/nodes/.+/update", method: "POST", action: ActionNodeUpdate},
// https://docs.docker.com/engine/api/v1.39/#operation/NodeInspect
{pattern: "/nodes/.+", method: "GET", action: ActionNodeInspect},
// https://docs.docker.com/engine/api/v1.39/#operation/NodeDelete
{pattern: "/nodes/.+", method: "DELETE", action: ActionNodeDelete},
// https://docs.docker.com/engine/api/v1.39/#operation/NodeList
{pattern: "/nodes", method: "GET", action: ActionNodeList},
// https://docs.docker.com/engine/api/v1.39/#operation/ServiceCreate
{pattern: "/services/create", method: "POST", action: ActionServiceCreate},
// https://docs.docker.com/engine/api/v1.39/#operation/ServiceUpdate
{pattern: "/services/.+/update", method: "POST", action: ActionServiceUpdate},
// https://docs.docker.com/engine/api/v1.39/#operation/ServiceLogs
{pattern: "/services/.+/logs", method: "GET", action: ActionServiceLogs},
// https://docs.docker.com/engine/api/v1.39/#operation/ServiceInspect
{pattern: "/services/.+", method: "GET", action: ActionServiceInspect},
// https://docs.docker.com/engine/api/v1.39/#operation/ServiceDelete
{pattern: "/services/.+", method: "DELETE", action: ActionServiceDelete},
// https://docs.docker.com/engine/api/v1.39/#operation/ServiceList
{pattern: "/services", method: "GET", action: ActionServiceList},
// https://docs.docker.com/engine/api/v1.39/#operation/TaskInspect
{pattern: "/tasks/.+", method: "GET", action: ActionTaskInspect},
// https://docs.docker.com/engine/api/v1.39/#operation/TaskList
{pattern: "/tasks", method: "GET", action: ActionTaskList},
// https://docs.docker.com/engine/api/v1.39/#operation/SecretCreate
{pattern: "/secrets/create", method: "POST", action: ActionSecretCreate},
// https://docs.docker.com/engine/api/v1.39/#operation/SecretUpdate
{pattern: "/secrets/.+/update", method: "POST", action: ActionSecretUpdate},
// https://docs.docker.com/engine/api/v1.39/#operation/SecretInspect
{pattern: "/secrets/.+", method: "GET", action: ActionSecretInspect},
// https://docs.docker.com/engine/api/v1.39/#operation/SecretDelete
{pattern: "/secrets/.+", method: "DELETE", action: ActionSecretDelete},
// https://docs.docker.com/engine/api/v1.39/#operation/SecretList
{pattern: "/secrets", method: "GET", action: ActionSecretList},
// https://docs.docker.com/engine/api/v1.39/#operation/ConfigCreate
{pattern: "/configs/create", method: "POST", action: ActionConfigCreate},
// https://docs.docker.com/engine/api/v1.39/#operation/ConfigUpdate
{pattern: "/configs/.+/update", method: "POST", action: ActionConfigUpdate},
// https://docs.docker.com/engine/api/v1.39/#operation/ConfigInspect
{pattern: "/configs/.+", method: "GET", action: ActionConfigInspect},
// https://docs.docker.com/engine/api/v1.39/#operation/ConfigDelete
{pattern: "/configs/.+", method: "DELETE", action: ActionConfigDelete},
// https://docs.docker.com/engine/api/v1.39/#operation/ConfigList
{pattern: "/configs", method: "GET", action: ActionConfigList},
}

// ParseRoute convert a method/url pattern to corresponding docker action
Expand Down
28 changes: 28 additions & 0 deletions core/route_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,34 @@ func TestRouteParser(t *testing.T) {
{"GET", "/v1.21/volumes/id", ActionVolumeInspect},
{"GET", "/v1.21/volumes", ActionVolumeList},
{"GET", "/v1.21/images/non_existing", ActionNone},
{"GET", "/v1.39/swarm", ActionSwarmInspect},
{"POST", "/v1.39/swarm/init", ActionSwarmInit},
{"POST", "/v1.39/swarm/join", ActionSwarmJoin},
{"POST", "/v1.39/swarm/leave", ActionSwarmLeave},
{"POST", "/v1.39/swarm/update", ActionSwarmUpdate},
{"GET", "/v1.39/swarm/unlockkey", ActionSwarmUnlockKey},
{"POST", "/v1.39/swarm/unlock", ActionSwarmUnlock},
{"GET", "/v1.39/nodes", ActionNodeList},
{"GET", "/v1.39/nodes/id", ActionNodeInspect},
{"DELETE", "/v1.39/nodes/id", ActionNodeDelete},
{"POST", "/v1.39/nodes/id/update", ActionNodeUpdate},
{"GET", "/v1.39/services", ActionServiceList},
{"POST", "/v1.39/services/create", ActionServiceCreate},
{"GET", "/v1.39/services/id", ActionServiceInspect},
{"DELETE", "/v1.39/services/id", ActionServiceDelete},
{"POST", "/v1.39/services/id/update", ActionServiceUpdate},
{"GET", "/v1.39/services/id/logs", ActionServiceLogs},
{"GET", "/v1.39/tasks", ActionTaskList},
{"GET", "/v1.39/tasks/id", ActionTaskInspect},
{"GET", "/v1.39/secrets", ActionSecretList},
{"POST", "/v1.39/secrets/create", ActionSecretCreate},
{"GET", "/v1.39/secrets/id", ActionSecretInspect},
{"DELETE", "/v1.39/secrets/id", ActionSecretDelete},
{"POST", "/v1.39/secrets/id/update", ActionSecretUpdate},
{"POST", "/v1.39/configs/create", ActionConfigCreate},
{"GET", "/v1.39/configs/id", ActionConfigInspect},
{"DELETE", "/v1.39/configs/id", ActionConfigDelete},
{"POST", "/v1.39/configs/id/update", ActionConfigUpdate},
}

for _, test := range tests {
Expand Down
58 changes: 58 additions & 0 deletions core/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,64 @@ var (
ActionNetworkDisconnect = "network_disconnect"
// ActionNetworkRemove describes https://docs.docker.com/engine/reference/api/docker_remote_api_v1.21/#remove-a-network
ActionNetworkRemove = "network_remove"
// ActionSwarmInspect describes https://docs.docker.com/engine/api/v1.37/#operation/SwarmInspect
ActionSwarmInspect = "swarm_inspect"
// ActionSwarmInit describes https://docs.docker.com/engine/api/v1.37/#operation/SwarmInit
ActionSwarmInit = "swarm_init"
// ActionSwarmJoin describes https://docs.docker.com/engine/api/v1.37/#operation/SwarmJoin
ActionSwarmJoin = "swarm_join"
// ActionSwarmLeave describes https://docs.docker.com/engine/api/v1.37/#operation/SwarmLeave
ActionSwarmLeave = "swarm_leave"
// ActionSwarmUpdate describes https://docs.docker.com/engine/api/v1.37/#operation/SwarmUpdate
ActionSwarmUpdate = "swarm_update"
// ActionSwarmUnlockKey describes https://docs.docker.com/engine/api/v1.37/#operation/SwarmUnlockkey
ActionSwarmUnlockKey = "swarm_unlock_key"
// ActionSwarmUnlock describes https://docs.docker.com/engine/api/v1.37/#operation/SwarmUnlock
ActionSwarmUnlock = "swarm_unlock"
// ActionNodeList describes https://docs.docker.com/engine/api/v1.39/#operation/NodeList
ActionNodeList = "node_list"
// ActionNodeInspect describes https://docs.docker.com/engine/api/v1.39/#operation/NodeInspect
ActionNodeInspect = "node_inspect"
// ActionNodeDelete describes https://docs.docker.com/engine/api/v1.39/#operation/NodeDelete
ActionNodeDelete = "node_delete"
// ActionNodeUpdate describes https://docs.docker.com/engine/api/v1.39/#operation/NodeUpdate
ActionNodeUpdate = "node_update"
// ActionServiceList describes https://docs.docker.com/engine/api/v1.39/#operation/ServiceList
ActionServiceList = "service_list"
// ActionServiceCreate describes https://docs.docker.com/engine/api/v1.39/#operation/ServiceCreate
ActionServiceCreate = "service_create"
// ActionServiceInspect describes https://docs.docker.com/engine/api/v1.39/#operation/ServiceInspect
ActionServiceInspect = "service_inspect"
// ActionServiceDelete describes https://docs.docker.com/engine/api/v1.39/#operation/ServiceDelete
ActionServiceDelete = "service_delete"
// ActionServiceUpdate describes https://docs.docker.com/engine/api/v1.39/#operation/ServiceUpdate
ActionServiceUpdate = "service_update"
// ActionServiceLogs describes https://docs.docker.com/engine/api/v1.39/#operation/ServiceLogs
ActionServiceLogs = "service_logs"
// ActionTaskList describes https://docs.docker.com/engine/api/v1.39/#operation/TaskList
ActionTaskList = "task_list"
// ActionTaskInspect describes https://docs.docker.com/engine/api/v1.39/#operation/TaskInspect
ActionTaskInspect = "task_inspect"
// ActionSecretList describes https://docs.docker.com/engine/api/v1.39/#operation/SecretList
ActionSecretList = "secret_list"
// ActionSecretCreate describes https://docs.docker.com/engine/api/v1.39/#operation/SecretCreate
ActionSecretCreate = "secret_create"
// ActionSecretInspect describes https://docs.docker.com/engine/api/v1.39/#operation/SecretInspect
ActionSecretInspect = "secret_inspect"
// ActionSecretDelete describes https://docs.docker.com/engine/api/v1.39/#operation/SecretDelete
ActionSecretDelete = "secret_delete"
// ActionSecretUpdate describes https://docs.docker.com/engine/api/v1.39/#operation/SecretUpdate
ActionSecretUpdate = "secret_update"
// ActionConfigList describes https://docs.docker.com/engine/api/v1.39/#operation/ConfigList
ActionConfigList = "config_list"
// ActionConfigCreate describes https://docs.docker.com/engine/api/v1.39/#operation/ConfigCreate
ActionConfigCreate = "config_create"
// ActionConfigInspect describes https://docs.docker.com/engine/api/v1.39/#operation/ConfigInspect
ActionConfigInspect = "config_inspect"
// ActionConfigDelete describes https://docs.docker.com/engine/api/v1.39/#operation/ConfigDelete
ActionConfigDelete = "config_delete"
// ActionConfigUpdate describes https://docs.docker.com/engine/api/v1.39/#operation/ConfigUpdate
ActionConfigUpdate = "config_update"
// ActionNone indicates no action matched the given method URL combination
ActionNone = ""
)

0 comments on commit f807dc9

Please sign in to comment.