Skip to content

Can not POST updates to /config/application or other resoruces #306

Open
@jgruber

Description

@jgruber

Unit compiled from the master branch.

In the manual Configuration section it references:
POST Updates the array at the request URI, appending the JSON value from the HTTP request body.
I looked at the code and saw that the path length is checked in the controller, but just wanted to report that trying to use unit as described in the Configuration doc, is not obvious.

I have the following configuration applied successfully:

bash-5.0# curl -v --unix-socket /var/run/unit/control.sock http://localhost/config
*   Trying /var/run/unit/control.sock:0...
* Connected to localhost (/var/run/unit/control.sock) port 80 (#0)
> GET /config HTTP/1.1
> Host: localhost
> User-Agent: curl/7.65.1
> Accept: */*
> 
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Server: Unit/1.11.0
< Date: Wed, 04 Sep 2019 21:50:20 GMT
< Content-Type: application/json
< Content-Length: 707
< Connection: close
< 
{
	"listeners": {
		"127.0.0.1:8102": {
			"pass": "routes"
		}
	},

	"routes": [
		{
			"match": {
				"uri": "/TrustedDevicesUI*"
			},

			"action": {
				"pass": "applications/trusteddevices"
			}
		},
		{
			"match": {
				"uri": "/TrustedDevices*"
			},

			"action": {
				"pass": "applications/trusteddevices"
			}
		},
		{
			"match": {
				"uri": "/TrustedProxy*"
			},

			"action": {
				"pass": "applications/trusteddevices"
			}
		}
	],

	"applications": {
		"trusteddevices": {
			"type": "external",
			"working_directory": "/var/lib/f5-icontrol-trusted-devices",
			"executable": "unitapp.js",
			"user": "nginx",
			"group": "nginx"
		}
	}
}
* Closing connection 0

Then I try to add an additional application using POST.

bash-5.0# curl -X POST -d '{"testunitapp":{"type":"external","working_directory":"/var/lib/test-unit-app","executable":"bin/www","user":"nginx","group":"nginx"}}' -v --unix-socket /var/run/unit/control.sock http://localhost/config/applications
Note: Unnecessary use of -X or --request, POST is already inferred.
*   Trying /var/run/unit/control.sock:0...
* Connected to localhost (/var/run/unit/control.sock) port 80 (#0)
> POST /config/applications HTTP/1.1
> Host: localhost
> User-Agent: curl/7.65.1
> Accept: */*
> Content-Length: 134
> Content-Type: application/x-www-form-urlencoded
> 
* upload completely sent off: 134 out of 134 bytes
* Mark bundle as not supporting multiuse
< HTTP/1.1 405 Method Not Allowed
< Server: Unit/1.11.0
< Date: Wed, 04 Sep 2019 21:50:28 GMT
< Content-Type: application/json
< Content-Length: 41
< Connection: close
< 
{
	"error": "Method isn't allowed."
}
* Closing connection 0
`
and get a 405 Method not allowed response.

We need to either update the Configuration doc to show that POST is only for attributes or make it work. 

Naturally merging the JSON and issuing a PUT for the entire configuration works fine.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions