Commit Graph

34 Commits

Author SHA1 Message Date
9632b0f1e8 use t.Fatal() to output the err message where the values used for formatting
text does not appear to contain a placeholder

Signed-off-by: Helen Xie <chenjg@harmonycloud.cn>
Upstream-commit: 2a8d6368d4a930203b93f75914173ab65bf3b0bc
Component: engine
2017-02-23 10:16:22 +08:00
999e2c3104 fix status-code for "locked" swarm and "certificate expired"
These errors were producing the wrong status code,
changing to 503.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Upstream-commit: 7e44fffe40f39ef4cc0b3bee810f7d0a26136376
Component: engine
2017-02-17 16:51:50 -08:00
a02b030327 Fix #303111: dockerd leaks ExecIds on failed exec -i
Signed-off-by: Dmitry Shyshkin <dmitry@shyshkin.org.ua>
Upstream-commit: 3cc0d6bb0475551687d89e7925b09f864c866a71
Component: engine
2017-02-10 21:13:00 +02:00
5a2fed241e fix some types on errors and form
Signed-off-by: kaiwentan <kaiwentan@harmonycloud.cn>
Upstream-commit: ac9c47e26f57a0fa2fed95a1fb1bf6c9410a3b60
Component: engine
2017-02-07 20:29:32 +08:00
6b3d2b6135 Merge pull request #28631 from likel/master
Don't do format if it's unnecessary
Upstream-commit: d6be0e98027611cfb14a3246ca797bee0936e649
Component: engine
2016-12-30 01:13:12 +01:00
7c2700ecf9 Remove redundant format
Signed-off-by: Ke Li <kel@splunk.com>

Add missing changes

Signed-off-by: Ke Li <kel@splunk.com>

User errors.New to create error

Signed-off-by: Ke Li <kel@splunk.com>
Upstream-commit: 514adcf4580effa4820be8d5e6d2c0ea9825ceb2
Component: engine
2016-12-27 21:46:52 +08:00
98d422fce0 Move UAStringKey to dockerversion pkg
Removes grpc dependency from client

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
Upstream-commit: 64981b9f095459ae65954ca80a86c8f4a735ef24
Component: engine
2016-12-26 18:53:22 -08:00
d363742779 return directly without ifs in remaining packages
Signed-off-by: Cristian Staretu <cristian.staretu@gmail.com>
Upstream-commit: 2c187a24e0003f2f0ab90b85876e668f2b6210d4
Component: engine
2016-12-14 23:28:27 +02:00
5d1129c013 fix typo
Signed-off-by: allencloud <allen.sun@daocloud.io>
Upstream-commit: 1f039a66ac55c937f5dfa281a04009626d191f83
Component: engine
2016-11-18 15:51:36 +08:00
ba96408498 Merge pull request #28532 from stevvooe/disabled-swarm-service-unavailable
api/server/httputils: service unavailable for disable swarm
Upstream-commit: bbac9eeae68a2d1084961dc3b0adc4e9e729647c
Component: engine
2016-11-17 15:16:23 -08:00
e3739bc965 Merge pull request #28383 from zteBill/fix-useless-var
Remove needless var
Upstream-commit: 6969c98a3c9ca90616d88c6a57543ccd5724e6fb
Component: engine
2016-11-17 16:18:07 -05:00
781fc7e6b4 api/server/httputils: service unavailable for disable swarm
When swarm-mode is disabled, we need to return an error indicating this.
406 was chosen for the "Not Acceptable" verbiage, but this code has
specific semantics in relation to the `Accept` header, which aren't
applicable here.

We now use a 503 for this case. While it is not a perfect match, it does
make it clear that the particular "service" (read: API endpoint) is not
available. The body of the message provides the user with enough
information to take action on it by enabling swarm-mode and ensuring the
service is available.

Signed-off-by: Stephen J Day <stephen.day@docker.com>
Upstream-commit: 1d90d7604881e29b71819af9c092d565513aeeec
Component: engine
2016-11-17 11:43:45 -08:00
2b31c00bf1 make each return explicitly
Signed-off-by: zteBill <bi.zhenkun@zte.com.cn>
Upstream-commit: 4b3a1bbda5613ee12d4e94f7797fca51139109a6
Component: engine
2016-11-17 17:13:25 +08:00
3c5187452a api/server/httputils: ensure consistent status code
Error code resolution is powered by string matching. Not the greatest
thing in the world and I hope no one is proud of this code, but it
works. However, because a map is used, the iteration order of the map is
random, such that if an error matches two of the snippets, it may return
a different error code depending on the seed of the hashmap. This change
converts it to use a slice instead.

Signed-off-by: Stephen J Day <stephen.day@docker.com>
Upstream-commit: 3484e02590117d175d9c1ab24c583390b4e94a55
Component: engine
2016-11-16 18:58:55 -08:00
aaee5183a9 api/server/httputils: compile with go < 1.7
Signed-off-by: Antonio Murdaca <runcom@redhat.com>
Upstream-commit: d1d505fa701bfe28a59afee8158994cf33ef043c
Component: engine
2016-10-04 12:01:49 +02:00
e6c766802a Disable HTML escaping for JSON strings in docker inspect
This fix tries to address the issue raised in 27021 where
HTML strings like (`&, >, <, etc`) in environmental variables
are escaped for JSON output for `docker inspect`. For example,
`TEST_ENV="soanni&rtr"` has been escaped to `TEST_ENV="soanni\u0026rtr"`

This fix disabled HTML escaping with `SetEscapeHTML`, which is available
since golang 1.7.0. This changes will be applied to all JSON output
that utilize `httputils.WriteJSON`.

An integration test has been added to cover the changes.

This fix fixes 27021.

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
Upstream-commit: 0fa20ad13b0b5c6d1bf8a8285717c07697d079ba
Component: engine
2016-09-29 18:16:36 -07:00
e90292dd20 Use apiError in server version middleware.
Signed-off-by: Daniel Nephin <dnephin@docker.com>
Upstream-commit: bcb0405239e0c820516b05ccc2bb7e8d4a1599f9
Component: engine
2016-09-16 12:27:14 -04:00
45ddc4bfcb Add engine-api types to docker
This moves the types for the `engine-api` repo to the existing types
package.

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
Upstream-commit: 91e197d614547f0202e6ae9b8a24d88ee131d950
Component: engine
2016-09-07 11:05:58 -07:00
d354343b40 delete a function which isn't used in the project
Signed-off-by: Yanqiang Miao <miao.yanqiang@zte.com.cn>
Upstream-commit: 81849600fc1d7335f1ddc3ca5aa1cb5625bd2d30
Component: engine
2016-09-02 22:54:19 +08:00
be63983b3a Add Swarm management backend
As described in our ROADMAP.md, introduce new Swarm management API
endpoints relying on swarmkit to deploy services. It currently vendors
docker/engine-api changes.

This PR is fully backward compatible (joining a Swarm is an optional
feature of the Engine, and existing commands are not impacted).

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
Signed-off-by: Victor Vieux <vieux@docker.com>
Signed-off-by: Daniel Nephin <dnephin@docker.com>
Signed-off-by: Jana Radhakrishnan <mrjana@docker.com>
Signed-off-by: Madhu Venugopal <madhu@docker.com>
Upstream-commit: 534a90a99367af6f6bba1ddcc7eb07506e41f774
Component: engine
2016-06-13 22:16:18 -07:00
ecda48bde7 Return remote API errors as JSON
Signed-off-by: Ben Firshman <ben@firshman.co.uk>
Upstream-commit: 322e2a7d059a81617b593cf6ece2cfd9f6d4ea03
Component: engine
2016-06-07 18:45:27 -07:00
35c5774373 fix typos
Signed-off-by: allencloud <allen.sun@daocloud.io>
Upstream-commit: c1be45fa38e82054dcad606d71446a662524f2d5
Component: engine
2016-06-02 17:17:22 +08:00
b96d544c7a Fix bug which mistakes 400 error for 500
Signed-off-by: Wang Xing <hzwangxing@corp.netease.com>
Upstream-commit: beca2615782e24fa28803ada067129fdfa88c77d
Component: engine
2016-05-19 20:01:55 +08:00
b1397d2034 api: server: check for unauthorized error
This functionality has been fixed by
7bca93218291767c5dd8782de0ad630dbcda9995 but then it has been broken
again by a793564b2591035aec5412fbcbcccf220c773a4c and finally refixed
here.

Basically the functionality was to prompt for login when trying to pull
from the official docker hub.

Signed-off-by: Antonio Murdaca <runcom@redhat.com>
Upstream-commit: 4316ae2ed33d158e1d8d994646a75e25a70d9320
Component: engine
2016-04-22 17:14:02 +02:00
03d17b8c5f Update code for latest engine-api
- Update CopyToContainer uses
- Use engine-api/types/versions instead of pkg/version

Signed-off-by: Vincent Demeester <vincent@sbr.pm>
Upstream-commit: 7534f17261d0bb74557ca2f7cd893d5b7b531d49
Component: engine
2016-04-19 16:56:54 +02:00
97016757fb Let client print error when speicify wrong detach keys
Fix #21064

Let client print error message explicitly when user specifies wrong
detach keys.

Signed-off-by: Zhang Wei <zhangwei555@huawei.com>
Upstream-commit: 91e5bb954131904af150b06bd22b007559a8ce27
Component: engine
2016-04-04 15:35:55 +08:00
56103ffaad Remove runconfig package dependency from image and container routers.
Use an interface to specify the behavior of a configuration decoder.

Signed-off-by: David Calavera <david.calavera@gmail.com>
Upstream-commit: f0d26e1665f7552972db5b041554cc7b45bc3060
Component: engine
2016-03-28 16:23:51 -04:00
6143e6c8cf Pass upstream client's user agent through to registry on image pulls
Changes how the Engine interacts with Registry servers on image pull.
Previously, Engine sent a User-Agent string to the Registry server
that included only the Engine's version information.  This commit
appends to that string the fields from the User-Agent sent by the
client (e.g., Compose) of the Engine.  This allows Registry server
operators to understand what tools are actually generating pulls on
their registries.

Signed-off-by: Mike Goelzer <mgoelzer@docker.com>
Upstream-commit: d1502afb63a10df0bfce20ae2957774cfb3e58d8
Component: engine
2016-03-20 04:30:09 -07:00
b8f6e912b7 fix typos
Signed-off-by: allencloud <allen.sun@daocloud.io>
Upstream-commit: 2736f77a94f57ddde5de1e5dc66c168290b91da2
Component: engine
2016-03-06 00:59:11 +08:00
b2ac99b3fa Remove static errors from errors package.
Moving all strings to the errors package wasn't a good idea after all.

Our custom implementation of Go errors predates everything that's nice
and good about working with errors in Go. Take as an example what we
have to do to get an error message:

```go
func GetErrorMessage(err error) string {
	switch err.(type) {
	case errcode.Error:
		e, _ := err.(errcode.Error)
		return e.Message

	case errcode.ErrorCode:
		ec, _ := err.(errcode.ErrorCode)
		return ec.Message()

	default:
		return err.Error()
	}
}
```

This goes against every good practice for Go development. The language already provides a simple, intuitive and standard way to get error messages, that is calling the `Error()` method from an error. Reinventing the error interface is a mistake.

Our custom implementation also makes very hard to reason about errors, another nice thing about Go. I found several (>10) error declarations that we don't use anywhere. This is a clear sign about how little we know about the errors we return. I also found several error usages where the number of arguments was different than the parameters declared in the error, another clear example of how difficult is to reason about errors.

Moreover, our custom implementation didn't really make easier for people to return custom HTTP status code depending on the errors. Again, it's hard to reason about when to set custom codes and how. Take an example what we have to do to extract the message and status code from an error before returning a response from the API:

```go
	switch err.(type) {
	case errcode.ErrorCode:
		daError, _ := err.(errcode.ErrorCode)
		statusCode = daError.Descriptor().HTTPStatusCode
		errMsg = daError.Message()

	case errcode.Error:
		// For reference, if you're looking for a particular error
		// then you can do something like :
		//   import ( derr "github.com/docker/docker/errors" )
		//   if daError.ErrorCode() == derr.ErrorCodeNoSuchContainer { ... }

		daError, _ := err.(errcode.Error)
		statusCode = daError.ErrorCode().Descriptor().HTTPStatusCode
		errMsg = daError.Message

	default:
		// This part of will be removed once we've
		// converted everything over to use the errcode package

		// FIXME: this is brittle and should not be necessary.
		// If we need to differentiate between different possible error types,
		// we should create appropriate error types with clearly defined meaning
		errStr := strings.ToLower(err.Error())
		for keyword, status := range map[string]int{
			"not found":             http.StatusNotFound,
			"no such":               http.StatusNotFound,
			"bad parameter":         http.StatusBadRequest,
			"conflict":              http.StatusConflict,
			"impossible":            http.StatusNotAcceptable,
			"wrong login/password":  http.StatusUnauthorized,
			"hasn't been activated": http.StatusForbidden,
		} {
			if strings.Contains(errStr, keyword) {
				statusCode = status
				break
			}
		}
	}
```

You can notice two things in that code:

1. We have to explain how errors work, because our implementation goes against how easy to use Go errors are.
2. At no moment we arrived to remove that `switch` statement that was the original reason to use our custom implementation.

This change removes all our status errors from the errors package and puts them back in their specific contexts.
IT puts the messages back with their contexts. That way, we know right away when errors used and how to generate their messages.
It uses custom interfaces to reason about errors. Errors that need to response with a custom status code MUST implementent this simple interface:

```go
type errorWithStatus interface {
	HTTPErrorStatusCode() int
}
```

This interface is very straightforward to implement. It also preserves Go errors real behavior, getting the message is as simple as using the `Error()` method.

I included helper functions to generate errors that use custom status code in `errors/errors.go`.

By doing this, we remove the hard dependency we have eeverywhere to our custom errors package. Yes, you can use it as a helper to generate error, but it's still very easy to generate errors without it.

Please, read this fantastic blog post about errors in Go: http://dave.cheney.net/2014/12/24/inspecting-errors

Signed-off-by: David Calavera <david.calavera@gmail.com>
Upstream-commit: a793564b2591035aec5412fbcbcccf220c773a4c
Component: engine
2016-02-26 15:49:09 -05:00
3ddd694ddd remove unnecessary logs from daemon
if daemon encounters removing-file error. It will record two
similar logs as following . The later is meaningful for client, But not for
daemon. So remove it.

Signed-off-by: Liu Hua <sdu.liu@huawei.com>
Upstream-commit: 343e15fa3f3e6838a6cf6ebd2dd02e4e627fffcc
Component: engine
2015-11-10 17:44:38 +08:00
f38f3109c2 Remove defensive check of mux vars handling.
We should not check if the mux framework internals work as expected in every handler.
The missing parameter error doesn't make sense from the user point of view.

This change initializes a proper vars context if the mux fails to do so and delegates
specific parameter error checks to the handlers.

Signed-off-by: David Calavera <david.calavera@gmail.com>
Upstream-commit: 389ce0aae6a303660e591ef80272322ac82854e2
Component: engine
2015-10-14 10:31:09 -07:00
1dfde818a2 Resolves #16458 - filter events by labels.
Signed-off-by: Daniel Nephin <dnephin@docker.com>
Upstream-commit: 08b117517d6d6b5daebe4c056c135e1598f44385
Component: engine
2015-10-02 16:33:20 -04:00
1fb74bb17c Separate API router from server.
Implement basic interfaces to write custom routers that can be plugged
to the server. Remove server coupling with the daemon.

Signed-off-by: David Calavera <david.calavera@gmail.com>
Upstream-commit: da982cf5511814b6897244ecaa9c016f8800340a
Component: engine
2015-09-29 19:43:03 -04:00