Update deps without licenses

The following packes did not have discernible LICENSE files at the hash we have
vendored:
  github.com/beorn7/perks
  github.com/daviddengcn/go-colortext
  github.com/garyburd/redigo
  github.com/prometheus/common
  github.com/shurcooL/sanitized_anchor_name
  github.com/stretchr/objx

This commit updates all of them and updates the central LICENSE file.
This commit is contained in:
Tim Hockin
2016-05-27 14:35:17 -07:00
parent aae0c90d64
commit 372e904e51
41 changed files with 2801 additions and 296 deletions

View File

@@ -37,12 +37,13 @@ type DecodeOptions struct {
}
// ResponseFormat extracts the correct format from a HTTP response header.
func ResponseFormat(h http.Header) (Format, error) {
// If no matching format can be found FormatUnknown is returned.
func ResponseFormat(h http.Header) Format {
ct := h.Get(hdrContentType)
mediatype, params, err := mime.ParseMediaType(ct)
if err != nil {
return "", fmt.Errorf("invalid Content-Type header %q: %s", ct, err)
return FmtUnknown
}
const (
@@ -52,19 +53,19 @@ func ResponseFormat(h http.Header) (Format, error) {
switch mediatype {
case ProtoType:
if p := params["proto"]; p != ProtoProtocol {
return "", fmt.Errorf("unrecognized protocol message %s", p)
if p, ok := params["proto"]; ok && p != ProtoProtocol {
return FmtUnknown
}
if e := params["encoding"]; e != "delimited" {
return "", fmt.Errorf("unsupported encoding %s", e)
if e, ok := params["encoding"]; ok && e != "delimited" {
return FmtUnknown
}
return FmtProtoDelim, nil
return FmtProtoDelim
case textType:
if v, ok := params["version"]; ok && v != TextVersion {
return "", fmt.Errorf("unrecognized protocol version %s", v)
return FmtUnknown
}
return FmtText, nil
return FmtText
case jsonType:
var prometheusAPIVersion string
@@ -76,27 +77,26 @@ func ResponseFormat(h http.Header) (Format, error) {
}
switch prometheusAPIVersion {
case "0.0.2":
return FmtJSON2, nil
case "0.0.2", "":
return fmtJSON2
default:
return "", fmt.Errorf("unrecognized API version %s", prometheusAPIVersion)
return FmtUnknown
}
}
return "", fmt.Errorf("unsupported media type %q, expected %q or %q", mediatype, ProtoType, textType)
return FmtUnknown
}
// NewDecoder returns a new decoder based on the HTTP header.
func NewDecoder(r io.Reader, format Format) (Decoder, error) {
// NewDecoder returns a new decoder based on the given input format.
// If the input format does not imply otherwise, a text format decoder is returned.
func NewDecoder(r io.Reader, format Format) Decoder {
switch format {
case FmtProtoDelim:
return &protoDecoder{r: r}, nil
case FmtText:
return &textDecoder{r: r}, nil
case FmtJSON2:
return newJSON2Decoder(r), nil
return &protoDecoder{r: r}
case fmtJSON2:
return newJSON2Decoder(r)
}
return nil, fmt.Errorf("unsupported decoding format %q", format)
return &textDecoder{r: r}
}
// protoDecoder implements the Decoder interface for protocol buffers.
@@ -107,7 +107,29 @@ type protoDecoder struct {
// Decode implements the Decoder interface.
func (d *protoDecoder) Decode(v *dto.MetricFamily) error {
_, err := pbutil.ReadDelimited(d.r, v)
return err
if err != nil {
return err
}
if !model.IsValidMetricName(model.LabelValue(v.GetName())) {
return fmt.Errorf("invalid metric name %q", v.GetName())
}
for _, m := range v.GetMetric() {
if m == nil {
continue
}
for _, l := range m.GetLabel() {
if l == nil {
continue
}
if !model.LabelValue(l.GetValue()).IsValid() {
return fmt.Errorf("invalid label value %q", l.GetValue())
}
if !model.LabelName(l.GetName()).IsValid() {
return fmt.Errorf("invalid label name %q", l.GetName())
}
}
}
return nil
}
// textDecoder implements the Decoder interface for the text protcol.
@@ -129,13 +151,14 @@ func (d *textDecoder) Decode(v *dto.MetricFamily) error {
if len(fams) == 0 {
return io.EOF
}
d.fams = make([]*dto.MetricFamily, 0, len(fams))
for _, f := range fams {
d.fams = append(d.fams, f)
}
}
*v = *d.fams[len(d.fams)-1]
d.fams = d.fams[:len(d.fams)-1]
*v = *d.fams[0]
d.fams = d.fams[1:]
return nil
}