Skip to content
This repository has been archived by the owner on Oct 2, 2022. It is now read-only.

Commit

Permalink
Message code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Janos Pasztor committed Mar 8, 2021
1 parent 7b2d246 commit a17f469
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 29 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 0.9.8: Message code cleanup

This release cleans up the message codes being emitted.

## 0.9.7: Bugfixing validation

This release fixes a validation bug introduced in the previous version where TLS parameters were validated even if the URL didn't point to a `https://` URL.
Expand Down
18 changes: 10 additions & 8 deletions CODES.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# Message/error codes
# Message / error codes

| Code | Explanation |
| `HTTP_CLIENT_CONNECTION_FAILED` | Sending a HTTP request failed for reasons outside of ContainerSSH |
| `HTTP_CLIENT_DECODE_FAILED` | ContainerSSH failed to decode the JSON response after sending a request. Check if the HTTP server is misbehaving. |
| `HTTP_CLIENT_ENCODE_FAILED` | ContainerSSH failed to encode the payload for sending a HTTP request. This is a bug, please file an issue. |
| `HTTP_CLIENT_REDIRECTS_DISABLED` | ContainerSSH is refusing to follow a HTTP redirect received because the `allowRedirects` option is disabled. |
| `HTTP_CLIENT_REDIRECT` | ContainerSSH has received a HTTP redirect from the server. |
| `HTTP_CLIENT_RESPONSE` | ContainerSSH has received a response to a HTTP request sent to a server. |
| `HTTP_CLIENT_REQUEST` | ContainerSSH is sending a HTTP request to a server. |
|------|-------------|
| `HTTP_CLIENT_CONNECTION_FAILED` | This message indicates a connection failure on the network level. |
| `HTTP_CLIENT_DECODE_FAILED` | This message indicates that decoding the JSON response has failed. The status code is set for this code. |
| `HTTP_CLIENT_ENCODE_FAILED` | This message indicates that JSON encoding the request failed. This is usually a bug. |
| `HTTP_CLIENT_REDIRECT` | This message indicates that the server responded with a HTTP redirect. |
| `HTTP_CLIENT_REDIRECTS_DISABLED` | This message indicates that ContainerSSH is not following a HTTP redirect sent by the server. Use the allowRedirects option to allow following HTTP redirects. |
| `HTTP_CLIENT_REQUEST` | This message indicates that a HTTP request is being sent from ContainerSSH |
| `HTTP_CLIENT_RESPONSE` | This message indicates that ContainerSSH received a HTTP response from a server. |

36 changes: 19 additions & 17 deletions codes.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
package http

const (
// EFailureEncodeFailed indicates that JSON encoding the request failed. This is usually a bug.
EFailureEncodeFailed = "HTTP_CLIENT_ENCODE_FAILED"
// EFailureConnectionFailed indicates a connection failure on the network level.
EFailureConnectionFailed = "HTTP_CLIENT_CONNECTION_FAILED"
// EFailureDecodeFailed indicates that decoding the JSON response has failed. The status code is set for this
// code.
EFailureDecodeFailed = "HTTP_CLIENT_DECODE_FAILED"
// EClientRedirectsDisabled indicates that ContainerSSH is not following a HTTP redirect sent by the server.
EClientRedirectsDisabled = "HTTP_CLIENT_REDIRECTS_DISABLED"
// This message indicates that JSON encoding the request failed. This is usually a bug.
const EFailureEncodeFailed = "HTTP_CLIENT_ENCODE_FAILED"

// MClientRequest is a message indicating a HTTP request sent from ContainerSSH
MClientRequest = "HTTP_CLIENT_REQUEST"
// This message indicates a connection failure on the network level.
const EFailureConnectionFailed = "HTTP_CLIENT_CONNECTION_FAILED"

// MClientRedirect indicates that the server has sent a HTTP redirect.
MClientRedirect = "HTTP_CLIENT_REDIRECT"
// This message indicates that decoding the JSON response has failed. The status code is set for this
// code.
const EFailureDecodeFailed = "HTTP_CLIENT_DECODE_FAILED"

// MClientResponse is a message indicating receiving a HTTP response to a client request
MClientResponse = "HTTP_CLIENT_RESPONSE"
)
// This message indicates that ContainerSSH is not following a HTTP redirect sent by the server. Use the allowRedirects
// option to allow following HTTP redirects.
const EClientRedirectsDisabled = "HTTP_CLIENT_REDIRECTS_DISABLED"

// This message indicates that a HTTP request is being sent from ContainerSSH
const MClientRequest = "HTTP_CLIENT_REQUEST"

// This message indicates that the server responded with a HTTP redirect.
const MClientRedirect = "HTTP_CLIENT_REDIRECT"

// This message indicates that ContainerSSH received a HTTP response from a server.
const MClientResponse = "HTTP_CLIENT_RESPONSE"
3 changes: 3 additions & 0 deletions codes_doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package http

//go:generate containerssh-generate-codes
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ module github.com/containerssh/http
go 1.14

require (
github.com/containerssh/log v0.9.11
github.com/containerssh/service v0.9.2
github.com/containerssh/log v0.9.13
github.com/containerssh/service v0.9.3
github.com/containerssh/structutils v0.9.0
github.com/stretchr/testify v1.7.0
)
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@ github.com/containerssh/log v0.9.10 h1:c5cYbopsWKX+f5AdDCeMHaRQmkFexpAEgY8MlpLMk
github.com/containerssh/log v0.9.10/go.mod h1:NBMzkhOLZ4z45ShSBKQ/Ij6Hqqg15DgOKy6HlSITx0s=
github.com/containerssh/log v0.9.11 h1:CLpl9mhxBg4giLZjcZB+FjddYypm2f2x1bCY3iissdA=
github.com/containerssh/log v0.9.11/go.mod h1:uVuUPoZsJYi2KoV9+lgPeB/gWuXeUTD3AoVxc4y+tKY=
github.com/containerssh/log v0.9.13 h1:jBSrFaxZNGwkjHU6y/efYI8lyG8KIFR5aOIeOnNzquE=
github.com/containerssh/log v0.9.13/go.mod h1:uVuUPoZsJYi2KoV9+lgPeB/gWuXeUTD3AoVxc4y+tKY=
github.com/containerssh/service v0.9.0 h1:JUHqiK12tclq7EWQYGRTfgKKw6fhHs0gxlKWTvVwFlQ=
github.com/containerssh/service v0.9.0/go.mod h1:otAKYF1MWy2eB0K7Sk7YQIECQMTHR3yikbyS1UstGpY=
github.com/containerssh/service v0.9.2 h1:+EZ7s7sxSme+IosYBR24oNhVlPTz3GJTXBZ0HaSD9rU=
github.com/containerssh/service v0.9.2/go.mod h1:nbA2I+GL0vU7ls0JEQKI+QOJfbUjlIDmmUSQqx/G7ro=
github.com/containerssh/service v0.9.3 h1:mYpvZ9zxUrKL8OpBen86heXfGtdUGdtfZ3Y7P605zvQ=
github.com/containerssh/service v0.9.3/go.mod h1:Yeq3hwfM6js9TfpkrQAQhv5IRfurrGEkM+AbFEC9KCE=
github.com/containerssh/structutils v0.9.0 h1:pz4xl5ZrPnpdSx7B/ru8Fj3oU3vOtx1jprIuSkm5s7o=
github.com/containerssh/structutils v0.9.0/go.mod h1:zirdwNXan3kuTpsJp9Gl3W6VQz0fexqMySqxmfviSjw=
github.com/creasty/defaults v1.5.1 h1:j8WexcS3d/t4ZmllX4GEkl4wIB/trOr035ajcLHCISM=
Expand Down
5 changes: 3 additions & 2 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
)

// ServerConfiguration is a structure to configure the simple HTTP server by.
//goland:noinspection GoVetStructTag
type ServerConfiguration struct {
// Listen contains the IP and port to listen on.
Listen string `json:"listen" yaml:"listen" default:"0.0.0.0:8080"`
Expand All @@ -22,9 +23,9 @@ type ServerConfiguration struct {
ClientCACert string `json:"clientcacert" yaml:"clientcacert"`

// cert is for internal use only. It contains the key and certificate after Validate.
cert *tls.Certificate
cert *tls.Certificate `json:"-" yaml:"-"`
// clientCAPool is for internal use only. It contains the client CA pool after Validate.
clientCAPool *x509.CertPool
clientCAPool *x509.CertPool `json:"-" yaml:"-"`
}

// Validate validates the server configuration.
Expand Down

0 comments on commit a17f469

Please sign in to comment.