Move deps from _workspace/ to vendor/

godep restore
pushd $GOPATH/src/github.com/appc/spec
git co master
popd
go get go4.org/errorutil
rm -rf Godeps
godep save ./...
git add vendor
git add -f $(git ls-files --other vendor/)
git co -- Godeps/LICENSES Godeps/.license_file_state Godeps/OWNERS
This commit is contained in:
Tim Hockin
2016-05-08 20:30:21 -07:00
parent 899f9b4e31
commit 3c0c5ed4e0
4400 changed files with 16739 additions and 376 deletions

40
vendor/github.com/appc/spec/schema/common/common.go generated vendored Normal file
View File

@@ -0,0 +1,40 @@
// Copyright 2015 The appc Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package common
import (
"fmt"
"net/url"
"strings"
)
// MakeQueryString takes a comma-separated LABEL=VALUE string and returns an
// "&"-separated string with URL escaped values.
//
// Examples:
// version=1.0.0,label=v1+v2 -> version=1.0.0&label=v1%2Bv2
// name=db,source=/tmp$1 -> name=db&source=%2Ftmp%241
func MakeQueryString(app string) (string, error) {
parts := strings.Split(app, ",")
escapedParts := make([]string, len(parts))
for i, s := range parts {
p := strings.SplitN(s, "=", 2)
if len(p) != 2 {
return "", fmt.Errorf("malformed string %q - has a label without a value: %s", app, p[0])
}
escapedParts[i] = fmt.Sprintf("%s=%s", p[0], url.QueryEscape(p[1]))
}
return strings.Join(escapedParts, "&"), nil
}

25
vendor/github.com/appc/spec/schema/doc.go generated vendored Normal file
View File

@@ -0,0 +1,25 @@
// Copyright 2015 The appc Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Package schema provides definitions for the JSON schema of the different
// manifests in the App Container Specification. The manifests are canonically
// represented in their respective structs:
// - `ImageManifest`
// - `PodManifest`
//
// Validation is performed through serialization: if a blob of JSON data will
// unmarshal to one of the *Manifests, it is considered a valid implementation
// of the standard. Similarly, if a constructed *Manifest struct marshals
// successfully to JSON, it must be valid.
package schema

103
vendor/github.com/appc/spec/schema/image.go generated vendored Normal file
View File

@@ -0,0 +1,103 @@
// Copyright 2015 The appc Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package schema
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"github.com/appc/spec/schema/types"
"go4.org/errorutil"
)
const (
ACIExtension = ".aci"
ImageManifestKind = types.ACKind("ImageManifest")
)
type ImageManifest struct {
ACKind types.ACKind `json:"acKind"`
ACVersion types.SemVer `json:"acVersion"`
Name types.ACIdentifier `json:"name"`
Labels types.Labels `json:"labels,omitempty"`
App *types.App `json:"app,omitempty"`
Annotations types.Annotations `json:"annotations,omitempty"`
Dependencies types.Dependencies `json:"dependencies,omitempty"`
PathWhitelist []string `json:"pathWhitelist,omitempty"`
}
// imageManifest is a model to facilitate extra validation during the
// unmarshalling of the ImageManifest
type imageManifest ImageManifest
func BlankImageManifest() *ImageManifest {
return &ImageManifest{ACKind: ImageManifestKind, ACVersion: AppContainerVersion}
}
func (im *ImageManifest) UnmarshalJSON(data []byte) error {
a := imageManifest(*im)
err := json.Unmarshal(data, &a)
if err != nil {
if serr, ok := err.(*json.SyntaxError); ok {
line, col, highlight := errorutil.HighlightBytePosition(bytes.NewReader(data), serr.Offset)
return fmt.Errorf("\nError at line %d, column %d\n%s%v", line, col, highlight, err)
}
return err
}
nim := ImageManifest(a)
if err := nim.assertValid(); err != nil {
return err
}
*im = nim
return nil
}
func (im ImageManifest) MarshalJSON() ([]byte, error) {
if err := im.assertValid(); err != nil {
return nil, err
}
return json.Marshal(imageManifest(im))
}
var imKindError = types.InvalidACKindError(ImageManifestKind)
// assertValid performs extra assertions on an ImageManifest to ensure that
// fields are set appropriately, etc. It is used exclusively when marshalling
// and unmarshalling an ImageManifest. Most field-specific validation is
// performed through the individual types being marshalled; assertValid()
// should only deal with higher-level validation.
func (im *ImageManifest) assertValid() error {
if im.ACKind != ImageManifestKind {
return imKindError
}
if im.ACVersion.Empty() {
return errors.New(`acVersion must be set`)
}
if im.Name.Empty() {
return errors.New(`name must be set`)
}
return nil
}
func (im *ImageManifest) GetLabel(name string) (val string, ok bool) {
return im.Labels.Get(name)
}
func (im *ImageManifest) GetAnnotation(name string) (val string, ok bool) {
return im.Annotations.Get(name)
}

42
vendor/github.com/appc/spec/schema/kind.go generated vendored Normal file
View File

@@ -0,0 +1,42 @@
// Copyright 2015 The appc Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package schema
import (
"encoding/json"
"github.com/appc/spec/schema/types"
)
type Kind struct {
ACVersion types.SemVer `json:"acVersion"`
ACKind types.ACKind `json:"acKind"`
}
type kind Kind
func (k *Kind) UnmarshalJSON(data []byte) error {
nk := kind{}
err := json.Unmarshal(data, &nk)
if err != nil {
return err
}
*k = Kind(nk)
return nil
}
func (k Kind) MarshalJSON() ([]byte, error) {
return json.Marshal(kind(k))
}

28
vendor/github.com/appc/spec/schema/lastditch/doc.go generated vendored Normal file
View File

@@ -0,0 +1,28 @@
// Copyright 2015 The appc Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Package lastditch provides fallback redefinitions of parts of
// schemas provided by schema package.
//
// Almost no validation of schemas is done (besides checking if data
// really is `JSON`-encoded and kind is either `ImageManifest` or
// `PodManifest`. This is to get as much data as possible from an
// invalid manifest. The main aim of the package is to be used for the
// better error reporting. The another aim might be to force some
// operation (like removing a pod), which would otherwise fail because
// of an invalid manifest.
//
// To avoid validation during deserialization, types provided by this
// package use plain strings.
package lastditch

45
vendor/github.com/appc/spec/schema/lastditch/image.go generated vendored Normal file
View File

@@ -0,0 +1,45 @@
// Copyright 2015 The appc Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package lastditch
import (
"encoding/json"
"github.com/appc/spec/schema"
"github.com/appc/spec/schema/types"
)
type ImageManifest struct {
ACVersion string `json:"acVersion"`
ACKind string `json:"acKind"`
Name string `json:"name"`
Labels Labels `json:"labels,omitempty"`
}
// a type just to avoid a recursion during unmarshalling
type imageManifest ImageManifest
func (im *ImageManifest) UnmarshalJSON(data []byte) error {
i := imageManifest(*im)
err := json.Unmarshal(data, &i)
if err != nil {
return err
}
if i.ACKind != string(schema.ImageManifestKind) {
return types.InvalidACKindError(schema.ImageManifestKind)
}
*im = ImageManifest(i)
return nil
}

38
vendor/github.com/appc/spec/schema/lastditch/labels.go generated vendored Normal file
View File

@@ -0,0 +1,38 @@
// Copyright 2015 The appc Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package lastditch
import (
"encoding/json"
)
type Labels []Label
// a type just to avoid a recursion during unmarshalling
type labels Labels
type Label struct {
Name string `json:"name"`
Value string `json:"value"`
}
func (l *Labels) UnmarshalJSON(data []byte) error {
var jl labels
if err := json.Unmarshal(data, &jl); err != nil {
return err
}
*l = Labels(jl)
return nil
}

57
vendor/github.com/appc/spec/schema/lastditch/pod.go generated vendored Normal file
View File

@@ -0,0 +1,57 @@
// Copyright 2015 The appc Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package lastditch
import (
"encoding/json"
"github.com/appc/spec/schema"
"github.com/appc/spec/schema/types"
)
type PodManifest struct {
ACVersion string `json:"acVersion"`
ACKind string `json:"acKind"`
Apps AppList `json:"apps"`
}
type AppList []RuntimeApp
type RuntimeApp struct {
Name string `json:"name"`
Image RuntimeImage `json:"image"`
}
type RuntimeImage struct {
Name string `json:"name"`
ID string `json:"id"`
Labels Labels `json:"labels,omitempty"`
}
// a type just to avoid a recursion during unmarshalling
type podManifest PodManifest
func (pm *PodManifest) UnmarshalJSON(data []byte) error {
p := podManifest(*pm)
err := json.Unmarshal(data, &p)
if err != nil {
return err
}
if p.ACKind != string(schema.PodManifestKind) {
return types.InvalidACKindError(schema.PodManifestKind)
}
*pm = PodManifest(p)
return nil
}

167
vendor/github.com/appc/spec/schema/pod.go generated vendored Normal file
View File

@@ -0,0 +1,167 @@
// Copyright 2015 The appc Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package schema
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"github.com/appc/spec/schema/types"
"go4.org/errorutil"
)
const PodManifestKind = types.ACKind("PodManifest")
type PodManifest struct {
ACVersion types.SemVer `json:"acVersion"`
ACKind types.ACKind `json:"acKind"`
Apps AppList `json:"apps"`
Volumes []types.Volume `json:"volumes"`
Isolators []types.Isolator `json:"isolators"`
Annotations types.Annotations `json:"annotations"`
Ports []types.ExposedPort `json:"ports"`
}
// podManifest is a model to facilitate extra validation during the
// unmarshalling of the PodManifest
type podManifest PodManifest
func BlankPodManifest() *PodManifest {
return &PodManifest{ACKind: PodManifestKind, ACVersion: AppContainerVersion}
}
func (pm *PodManifest) UnmarshalJSON(data []byte) error {
p := podManifest(*pm)
err := json.Unmarshal(data, &p)
if err != nil {
if serr, ok := err.(*json.SyntaxError); ok {
line, col, highlight := errorutil.HighlightBytePosition(bytes.NewReader(data), serr.Offset)
return fmt.Errorf("\nError at line %d, column %d\n%s%v", line, col, highlight, err)
}
return err
}
npm := PodManifest(p)
if err := npm.assertValid(); err != nil {
return err
}
*pm = npm
return nil
}
func (pm PodManifest) MarshalJSON() ([]byte, error) {
if err := pm.assertValid(); err != nil {
return nil, err
}
return json.Marshal(podManifest(pm))
}
var pmKindError = types.InvalidACKindError(PodManifestKind)
// assertValid performs extra assertions on an PodManifest to
// ensure that fields are set appropriately, etc. It is used exclusively when
// marshalling and unmarshalling an PodManifest. Most
// field-specific validation is performed through the individual types being
// marshalled; assertValid() should only deal with higher-level validation.
func (pm *PodManifest) assertValid() error {
if pm.ACKind != PodManifestKind {
return pmKindError
}
return nil
}
type AppList []RuntimeApp
type appList AppList
func (al *AppList) UnmarshalJSON(data []byte) error {
a := appList{}
err := json.Unmarshal(data, &a)
if err != nil {
return err
}
nal := AppList(a)
if err := nal.assertValid(); err != nil {
return err
}
*al = nal
return nil
}
func (al AppList) MarshalJSON() ([]byte, error) {
if err := al.assertValid(); err != nil {
return nil, err
}
return json.Marshal(appList(al))
}
func (al AppList) assertValid() error {
seen := map[types.ACName]bool{}
for _, a := range al {
if _, ok := seen[a.Name]; ok {
return fmt.Errorf(`duplicate apps of name %q`, a.Name)
}
seen[a.Name] = true
}
return nil
}
// Get retrieves an app by the specified name from the AppList; if there is
// no such app, nil is returned. The returned *RuntimeApp MUST be considered
// read-only.
func (al AppList) Get(name types.ACName) *RuntimeApp {
for _, a := range al {
if name.Equals(a.Name) {
aa := a
return &aa
}
}
return nil
}
// Mount describes the mapping between a volume and the path it is mounted
// inside of an app's filesystem.
type Mount struct {
Volume types.ACName `json:"volume"`
Path string `json:"path"`
}
func (r Mount) assertValid() error {
if r.Volume.Empty() {
return errors.New("volume must be set")
}
if r.Path == "" {
return errors.New("path must be set")
}
return nil
}
// RuntimeApp describes an application referenced in a PodManifest
type RuntimeApp struct {
Name types.ACName `json:"name"`
Image RuntimeImage `json:"image"`
App *types.App `json:"app,omitempty"`
Mounts []Mount `json:"mounts,omitempty"`
Annotations types.Annotations `json:"annotations,omitempty"`
}
// RuntimeImage describes an image referenced in a RuntimeApp
type RuntimeImage struct {
Name *types.ACIdentifier `json:"name,omitempty"`
ID types.Hash `json:"id"`
Labels types.Labels `json:"labels,omitempty"`
}

View File

@@ -0,0 +1,145 @@
// Copyright 2015 The appc Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package types
import (
"encoding/json"
"errors"
"regexp"
"strings"
)
var (
// ValidACIdentifier is a regular expression that defines a valid ACIdentifier
ValidACIdentifier = regexp.MustCompile("^[a-z0-9]+([-._~/][a-z0-9]+)*$")
invalidACIdentifierChars = regexp.MustCompile("[^a-z0-9-._~/]")
invalidACIdentifierEdges = regexp.MustCompile("(^[-._~/]+)|([-._~/]+$)")
ErrEmptyACIdentifier = ACIdentifierError("ACIdentifier cannot be empty")
ErrInvalidEdgeInACIdentifier = ACIdentifierError("ACIdentifier must start and end with only lower case " +
"alphanumeric characters")
ErrInvalidCharInACIdentifier = ACIdentifierError("ACIdentifier must contain only lower case " +
`alphanumeric characters plus "-._~/"`)
)
// ACIdentifier (an App-Container Identifier) is a format used by keys in image names
// and image labels of the App Container Standard. An ACIdentifier is restricted to numeric
// and lowercase URI unreserved characters defined in URI RFC[1]; all alphabetical characters
// must be lowercase only. Furthermore, the first and last character ("edges") must be
// alphanumeric, and an ACIdentifier cannot be empty. Programmatically, an ACIdentifier must
// conform to the regular expression ValidACIdentifier.
//
// [1] http://tools.ietf.org/html/rfc3986#section-2.3
type ACIdentifier string
func (n ACIdentifier) String() string {
return string(n)
}
// Set sets the ACIdentifier to the given value, if it is valid; if not,
// an error is returned.
func (n *ACIdentifier) Set(s string) error {
nn, err := NewACIdentifier(s)
if err == nil {
*n = *nn
}
return err
}
// Equals checks whether a given ACIdentifier is equal to this one.
func (n ACIdentifier) Equals(o ACIdentifier) bool {
return strings.ToLower(string(n)) == strings.ToLower(string(o))
}
// Empty returns a boolean indicating whether this ACIdentifier is empty.
func (n ACIdentifier) Empty() bool {
return n.String() == ""
}
// NewACIdentifier generates a new ACIdentifier from a string. If the given string is
// not a valid ACIdentifier, nil and an error are returned.
func NewACIdentifier(s string) (*ACIdentifier, error) {
n := ACIdentifier(s)
if err := n.assertValid(); err != nil {
return nil, err
}
return &n, nil
}
// MustACIdentifier generates a new ACIdentifier from a string, If the given string is
// not a valid ACIdentifier, it panics.
func MustACIdentifier(s string) *ACIdentifier {
n, err := NewACIdentifier(s)
if err != nil {
panic(err)
}
return n
}
func (n ACIdentifier) assertValid() error {
s := string(n)
if len(s) == 0 {
return ErrEmptyACIdentifier
}
if invalidACIdentifierChars.MatchString(s) {
return ErrInvalidCharInACIdentifier
}
if invalidACIdentifierEdges.MatchString(s) {
return ErrInvalidEdgeInACIdentifier
}
return nil
}
// UnmarshalJSON implements the json.Unmarshaler interface
func (n *ACIdentifier) UnmarshalJSON(data []byte) error {
var s string
if err := json.Unmarshal(data, &s); err != nil {
return err
}
nn, err := NewACIdentifier(s)
if err != nil {
return err
}
*n = *nn
return nil
}
// MarshalJSON implements the json.Marshaler interface
func (n ACIdentifier) MarshalJSON() ([]byte, error) {
if err := n.assertValid(); err != nil {
return nil, err
}
return json.Marshal(n.String())
}
// SanitizeACIdentifier replaces every invalid ACIdentifier character in s with an underscore
// making it a legal ACIdentifier string. If the character is an upper case letter it
// replaces it with its lower case. It also removes illegal edge characters
// (hyphens, period, underscore, tilde and slash).
//
// This is a helper function and its algorithm is not part of the spec. It
// should not be called without the user explicitly asking for a suggestion.
func SanitizeACIdentifier(s string) (string, error) {
s = strings.ToLower(s)
s = invalidACIdentifierChars.ReplaceAllString(s, "_")
s = invalidACIdentifierEdges.ReplaceAllString(s, "")
if s == "" {
return "", errors.New("must contain at least one valid character")
}
return s, nil
}

67
vendor/github.com/appc/spec/schema/types/ackind.go generated vendored Normal file
View File

@@ -0,0 +1,67 @@
// Copyright 2015 The appc Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package types
import (
"encoding/json"
"fmt"
)
var (
ErrNoACKind = ACKindError("ACKind must be set")
)
// ACKind wraps a string to define a field which must be set with one of
// several ACKind values. If it is unset, or has an invalid value, the field
// will refuse to marshal/unmarshal.
type ACKind string
func (a ACKind) String() string {
return string(a)
}
func (a ACKind) assertValid() error {
s := a.String()
switch s {
case "ImageManifest", "PodManifest":
return nil
case "":
return ErrNoACKind
default:
msg := fmt.Sprintf("bad ACKind: %s", s)
return ACKindError(msg)
}
}
func (a ACKind) MarshalJSON() ([]byte, error) {
if err := a.assertValid(); err != nil {
return nil, err
}
return json.Marshal(a.String())
}
func (a *ACKind) UnmarshalJSON(data []byte) error {
var s string
err := json.Unmarshal(data, &s)
if err != nil {
return err
}
na := ACKind(s)
if err := na.assertValid(); err != nil {
return err
}
*a = na
return nil
}

145
vendor/github.com/appc/spec/schema/types/acname.go generated vendored Normal file
View File

@@ -0,0 +1,145 @@
// Copyright 2015 The appc Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package types
import (
"encoding/json"
"errors"
"regexp"
"strings"
)
var (
// ValidACName is a regular expression that defines a valid ACName
ValidACName = regexp.MustCompile("^[a-z0-9]+([-][a-z0-9]+)*$")
invalidACNameChars = regexp.MustCompile("[^a-z0-9-]")
invalidACNameEdges = regexp.MustCompile("(^[-]+)|([-]+$)")
ErrEmptyACName = ACNameError("ACName cannot be empty")
ErrInvalidEdgeInACName = ACNameError("ACName must start and end with only lower case " +
"alphanumeric characters")
ErrInvalidCharInACName = ACNameError("ACName must contain only lower case " +
`alphanumeric characters plus "-"`)
)
// ACName (an App-Container Name) is a format used by keys in different formats
// of the App Container Standard. An ACName is restricted to numeric and lowercase
// characters accepted by the DNS RFC[1] plus "-"; all alphabetical characters must
// be lowercase only. Furthermore, the first and last character ("edges") must be
// alphanumeric, and an ACName cannot be empty. Programmatically, an ACName must
// conform to the regular expression ValidACName.
//
// [1] http://tools.ietf.org/html/rfc1123#page-13
type ACName string
func (n ACName) String() string {
return string(n)
}
// Set sets the ACName to the given value, if it is valid; if not,
// an error is returned.
func (n *ACName) Set(s string) error {
nn, err := NewACName(s)
if err == nil {
*n = *nn
}
return err
}
// Equals checks whether a given ACName is equal to this one.
func (n ACName) Equals(o ACName) bool {
return strings.ToLower(string(n)) == strings.ToLower(string(o))
}
// Empty returns a boolean indicating whether this ACName is empty.
func (n ACName) Empty() bool {
return n.String() == ""
}
// NewACName generates a new ACName from a string. If the given string is
// not a valid ACName, nil and an error are returned.
func NewACName(s string) (*ACName, error) {
n := ACName(s)
if err := n.assertValid(); err != nil {
return nil, err
}
return &n, nil
}
// MustACName generates a new ACName from a string, If the given string is
// not a valid ACName, it panics.
func MustACName(s string) *ACName {
n, err := NewACName(s)
if err != nil {
panic(err)
}
return n
}
func (n ACName) assertValid() error {
s := string(n)
if len(s) == 0 {
return ErrEmptyACName
}
if invalidACNameChars.MatchString(s) {
return ErrInvalidCharInACName
}
if invalidACNameEdges.MatchString(s) {
return ErrInvalidEdgeInACName
}
return nil
}
// UnmarshalJSON implements the json.Unmarshaler interface
func (n *ACName) UnmarshalJSON(data []byte) error {
var s string
if err := json.Unmarshal(data, &s); err != nil {
return err
}
nn, err := NewACName(s)
if err != nil {
return err
}
*n = *nn
return nil
}
// MarshalJSON implements the json.Marshaler interface
func (n ACName) MarshalJSON() ([]byte, error) {
if err := n.assertValid(); err != nil {
return nil, err
}
return json.Marshal(n.String())
}
// SanitizeACName replaces every invalid ACName character in s with a dash
// making it a legal ACName string. If the character is an upper case letter it
// replaces it with its lower case. It also removes illegal edge characters
// (hyphens).
//
// This is a helper function and its algorithm is not part of the spec. It
// should not be called without the user explicitly asking for a suggestion.
func SanitizeACName(s string) (string, error) {
s = strings.ToLower(s)
s = invalidACNameChars.ReplaceAllString(s, "-")
s = invalidACNameEdges.ReplaceAllString(s, "")
if s == "" {
return "", errors.New("must contain at least one valid character")
}
return s, nil
}

106
vendor/github.com/appc/spec/schema/types/annotations.go generated vendored Normal file
View File

@@ -0,0 +1,106 @@
// Copyright 2015 The appc Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package types
import (
"encoding/json"
"fmt"
)
type Annotations []Annotation
type annotations Annotations
type Annotation struct {
Name ACIdentifier `json:"name"`
Value string `json:"value"`
}
func (a Annotations) assertValid() error {
seen := map[ACIdentifier]string{}
for _, anno := range a {
_, ok := seen[anno.Name]
if ok {
return fmt.Errorf(`duplicate annotations of name %q`, anno.Name)
}
seen[anno.Name] = anno.Value
}
if c, ok := seen["created"]; ok {
if _, err := NewDate(c); err != nil {
return err
}
}
if h, ok := seen["homepage"]; ok {
if _, err := NewURL(h); err != nil {
return err
}
}
if d, ok := seen["documentation"]; ok {
if _, err := NewURL(d); err != nil {
return err
}
}
return nil
}
func (a Annotations) MarshalJSON() ([]byte, error) {
if err := a.assertValid(); err != nil {
return nil, err
}
return json.Marshal(annotations(a))
}
func (a *Annotations) UnmarshalJSON(data []byte) error {
var ja annotations
if err := json.Unmarshal(data, &ja); err != nil {
return err
}
na := Annotations(ja)
if err := na.assertValid(); err != nil {
return err
}
*a = na
return nil
}
// Retrieve the value of an annotation by the given name from Annotations, if
// it exists.
func (a Annotations) Get(name string) (val string, ok bool) {
for _, anno := range a {
if anno.Name.String() == name {
return anno.Value, true
}
}
return "", false
}
// Set sets the value of an annotation by the given name, overwriting if one already exists.
func (a *Annotations) Set(name ACIdentifier, value string) {
for i, anno := range *a {
if anno.Name.Equals(name) {
(*a)[i] = Annotation{
Name: name,
Value: value,
}
return
}
}
anno := Annotation{
Name: name,
Value: value,
}
*a = append(*a, anno)
}

90
vendor/github.com/appc/spec/schema/types/app.go generated vendored Normal file
View File

@@ -0,0 +1,90 @@
// Copyright 2015 The appc Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package types
import (
"encoding/json"
"errors"
"fmt"
"path"
)
type App struct {
Exec Exec `json:"exec"`
EventHandlers []EventHandler `json:"eventHandlers,omitempty"`
User string `json:"user"`
Group string `json:"group"`
SupplementaryGIDs []int `json:"supplementaryGIDs,omitempty"`
WorkingDirectory string `json:"workingDirectory,omitempty"`
Environment Environment `json:"environment,omitempty"`
MountPoints []MountPoint `json:"mountPoints,omitempty"`
Ports []Port `json:"ports,omitempty"`
Isolators Isolators `json:"isolators,omitempty"`
}
// app is a model to facilitate extra validation during the
// unmarshalling of the App
type app App
func (a *App) UnmarshalJSON(data []byte) error {
ja := app(*a)
err := json.Unmarshal(data, &ja)
if err != nil {
return err
}
na := App(ja)
if err := na.assertValid(); err != nil {
return err
}
if na.Environment == nil {
na.Environment = make(Environment, 0)
}
*a = na
return nil
}
func (a App) MarshalJSON() ([]byte, error) {
if err := a.assertValid(); err != nil {
return nil, err
}
return json.Marshal(app(a))
}
func (a *App) assertValid() error {
if err := a.Exec.assertValid(); err != nil {
return err
}
if a.User == "" {
return errors.New(`user is required`)
}
if a.Group == "" {
return errors.New(`group is required`)
}
if !path.IsAbs(a.WorkingDirectory) && a.WorkingDirectory != "" {
return errors.New("workingDirectory must be an absolute path")
}
eh := make(map[string]bool)
for _, e := range a.EventHandlers {
name := e.Name
if eh[name] {
return fmt.Errorf("Only one eventHandler of name %q allowed", name)
}
eh[name] = true
}
if err := a.Environment.assertValid(); err != nil {
return err
}
return nil
}

60
vendor/github.com/appc/spec/schema/types/date.go generated vendored Normal file
View File

@@ -0,0 +1,60 @@
// Copyright 2015 The appc Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package types
import (
"encoding/json"
"fmt"
"time"
)
// Date wraps time.Time to marshal/unmarshal to/from JSON strings in strict
// accordance with RFC3339
// TODO(jonboulle): golang's implementation seems slightly buggy here;
// according to http://tools.ietf.org/html/rfc3339#section-5.6 , applications
// may choose to separate the date and time with a space instead of a T
// character (for example, `date --rfc-3339` on GNU coreutils) - but this is
// considered an error by go's parser. File a bug?
type Date time.Time
func NewDate(s string) (*Date, error) {
t, err := time.Parse(time.RFC3339, s)
if err != nil {
return nil, fmt.Errorf("bad Date: %v", err)
}
d := Date(t)
return &d, nil
}
func (d Date) String() string {
return time.Time(d).Format(time.RFC3339)
}
func (d *Date) UnmarshalJSON(data []byte) error {
var s string
if err := json.Unmarshal(data, &s); err != nil {
return err
}
nd, err := NewDate(s)
if err != nil {
return err
}
*d = *nd
return nil
}
func (d Date) MarshalJSON() ([]byte, error) {
return json.Marshal(d.String())
}

View File

@@ -0,0 +1,58 @@
// Copyright 2015 The appc Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package types
import (
"encoding/json"
"errors"
)
type Dependencies []Dependency
type Dependency struct {
ImageName ACIdentifier `json:"imageName"`
ImageID *Hash `json:"imageID,omitempty"`
Labels Labels `json:"labels,omitempty"`
Size uint `json:"size,omitempty"`
}
type dependency Dependency
func (d Dependency) assertValid() error {
if len(d.ImageName) < 1 {
return errors.New(`imageName cannot be empty`)
}
return nil
}
func (d Dependency) MarshalJSON() ([]byte, error) {
if err := d.assertValid(); err != nil {
return nil, err
}
return json.Marshal(dependency(d))
}
func (d *Dependency) UnmarshalJSON(data []byte) error {
var jd dependency
if err := json.Unmarshal(data, &jd); err != nil {
return err
}
nd := Dependency(jd)
if err := nd.assertValid(); err != nil {
return err
}
*d = nd
return nil
}

18
vendor/github.com/appc/spec/schema/types/doc.go generated vendored Normal file
View File

@@ -0,0 +1,18 @@
// Copyright 2015 The appc Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Package types contains structs representing the various types in the app
// container specification. It is used by the [schema manifest types](../)
// to enforce validation.
package types

110
vendor/github.com/appc/spec/schema/types/environment.go generated vendored Normal file
View File

@@ -0,0 +1,110 @@
// Copyright 2015 The appc Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package types
import (
"encoding/json"
"fmt"
"regexp"
)
var (
envPattern = regexp.MustCompile("^[A-Za-z_][A-Za-z_0-9]*$")
)
type Environment []EnvironmentVariable
type environment Environment
type EnvironmentVariable struct {
Name string `json:"name"`
Value string `json:"value"`
}
func (ev EnvironmentVariable) assertValid() error {
if len(ev.Name) == 0 {
return fmt.Errorf(`environment variable name must not be empty`)
}
if !envPattern.MatchString(ev.Name) {
return fmt.Errorf(`environment variable does not have valid identifier %q`, ev.Name)
}
return nil
}
func (e Environment) assertValid() error {
seen := map[string]bool{}
for _, env := range e {
if err := env.assertValid(); err != nil {
return err
}
_, ok := seen[env.Name]
if ok {
return fmt.Errorf(`duplicate environment variable of name %q`, env.Name)
}
seen[env.Name] = true
}
return nil
}
func (e Environment) MarshalJSON() ([]byte, error) {
if err := e.assertValid(); err != nil {
return nil, err
}
return json.Marshal(environment(e))
}
func (e *Environment) UnmarshalJSON(data []byte) error {
var je environment
if err := json.Unmarshal(data, &je); err != nil {
return err
}
ne := Environment(je)
if err := ne.assertValid(); err != nil {
return err
}
*e = ne
return nil
}
// Retrieve the value of an environment variable by the given name from
// Environment, if it exists.
func (e Environment) Get(name string) (value string, ok bool) {
for _, env := range e {
if env.Name == name {
return env.Value, true
}
}
return "", false
}
// Set sets the value of an environment variable by the given name,
// overwriting if one already exists.
func (e *Environment) Set(name string, value string) {
for i, env := range *e {
if env.Name == name {
(*e)[i] = EnvironmentVariable{
Name: name,
Value: value,
}
return
}
}
env := EnvironmentVariable{
Name: name,
Value: value,
}
*e = append(*e, env)
}

49
vendor/github.com/appc/spec/schema/types/errors.go generated vendored Normal file
View File

@@ -0,0 +1,49 @@
// Copyright 2015 The appc Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package types
import "fmt"
// An ACKindError is returned when the wrong ACKind is set in a manifest
type ACKindError string
func (e ACKindError) Error() string {
return string(e)
}
func InvalidACKindError(kind ACKind) ACKindError {
return ACKindError(fmt.Sprintf("missing or bad ACKind (must be %#v)", kind))
}
// An ACVersionError is returned when a bad ACVersion is set in a manifest
type ACVersionError string
func (e ACVersionError) Error() string {
return string(e)
}
// An ACIdentifierError is returned when a bad value is used for an ACIdentifier
type ACIdentifierError string
func (e ACIdentifierError) Error() string {
return string(e)
}
// An ACNameError is returned when a bad value is used for an ACName
type ACNameError string
func (e ACNameError) Error() string {
return string(e)
}

View File

@@ -0,0 +1,61 @@
// Copyright 2015 The appc Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package types
import (
"encoding/json"
"errors"
"fmt"
)
type EventHandler struct {
Name string `json:"name"`
Exec Exec `json:"exec"`
}
type eventHandler EventHandler
func (e EventHandler) assertValid() error {
s := e.Name
switch s {
case "pre-start", "post-stop":
return nil
case "":
return errors.New(`eventHandler "name" cannot be empty`)
default:
return fmt.Errorf(`bad eventHandler "name": %q`, s)
}
}
func (e EventHandler) MarshalJSON() ([]byte, error) {
if err := e.assertValid(); err != nil {
return nil, err
}
return json.Marshal(eventHandler(e))
}
func (e *EventHandler) UnmarshalJSON(data []byte) error {
var je eventHandler
err := json.Unmarshal(data, &je)
if err != nil {
return err
}
ne := EventHandler(je)
if err := ne.assertValid(); err != nil {
return err
}
*e = ne
return nil
}

46
vendor/github.com/appc/spec/schema/types/exec.go generated vendored Normal file
View File

@@ -0,0 +1,46 @@
// Copyright 2015 The appc Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package types
import "encoding/json"
type Exec []string
type exec Exec
func (e Exec) assertValid() error {
return nil
}
func (e Exec) MarshalJSON() ([]byte, error) {
if err := e.assertValid(); err != nil {
return nil, err
}
return json.Marshal(exec(e))
}
func (e *Exec) UnmarshalJSON(data []byte) error {
var je exec
err := json.Unmarshal(data, &je)
if err != nil {
return err
}
ne := Exec(je)
if err := ne.assertValid(); err != nil {
return err
}
*e = ne
return nil
}

118
vendor/github.com/appc/spec/schema/types/hash.go generated vendored Normal file
View File

@@ -0,0 +1,118 @@
// Copyright 2015 The appc Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package types
import (
"crypto/sha512"
"encoding/json"
"errors"
"fmt"
"reflect"
"strings"
)
const (
maxHashSize = (sha512.Size / 2) + len("sha512-")
)
// Hash encodes a hash specified in a string of the form:
// "<type>-<value>"
// for example
// "sha512-06c733b1838136838e6d2d3e8fa5aea4c7905e92[...]"
// Valid types are currently:
// * sha512
type Hash struct {
typ string
Val string
}
func NewHash(s string) (*Hash, error) {
elems := strings.Split(s, "-")
if len(elems) != 2 {
return nil, errors.New("badly formatted hash string")
}
nh := Hash{
typ: elems[0],
Val: elems[1],
}
if err := nh.assertValid(); err != nil {
return nil, err
}
return &nh, nil
}
func (h Hash) String() string {
return fmt.Sprintf("%s-%s", h.typ, h.Val)
}
func (h *Hash) Set(s string) error {
nh, err := NewHash(s)
if err == nil {
*h = *nh
}
return err
}
func (h Hash) Empty() bool {
return reflect.DeepEqual(h, Hash{})
}
func (h Hash) assertValid() error {
switch h.typ {
case "sha512":
case "":
return fmt.Errorf("unexpected empty hash type")
default:
return fmt.Errorf("unrecognized hash type: %v", h.typ)
}
if h.Val == "" {
return fmt.Errorf("unexpected empty hash value")
}
return nil
}
func (h *Hash) UnmarshalJSON(data []byte) error {
var s string
if err := json.Unmarshal(data, &s); err != nil {
return err
}
nh, err := NewHash(s)
if err != nil {
return err
}
*h = *nh
return nil
}
func (h Hash) MarshalJSON() ([]byte, error) {
if err := h.assertValid(); err != nil {
return nil, err
}
return json.Marshal(h.String())
}
func NewHashSHA512(b []byte) *Hash {
h := sha512.New()
h.Write(b)
nh, _ := NewHash(fmt.Sprintf("sha512-%x", h.Sum(nil)))
return nh
}
func ShortHash(hash string) string {
if len(hash) > maxHashSize {
return hash[:maxHashSize]
}
return hash
}

129
vendor/github.com/appc/spec/schema/types/isolator.go generated vendored Normal file
View File

@@ -0,0 +1,129 @@
// Copyright 2015 The appc Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package types
import (
"encoding/json"
)
var (
isolatorMap map[ACIdentifier]IsolatorValueConstructor
)
func init() {
isolatorMap = make(map[ACIdentifier]IsolatorValueConstructor)
}
type IsolatorValueConstructor func() IsolatorValue
func AddIsolatorValueConstructor(n ACIdentifier, i IsolatorValueConstructor) {
isolatorMap[n] = i
}
func AddIsolatorName(n ACIdentifier, ns map[ACIdentifier]struct{}) {
ns[n] = struct{}{}
}
// Isolators encapsulates a list of individual Isolators for the ImageManifest
// and PodManifest schemas.
type Isolators []Isolator
// GetByName returns the last isolator in the list by the given name.
func (is *Isolators) GetByName(name ACIdentifier) *Isolator {
var i Isolator
for j := len(*is) - 1; j >= 0; j-- {
i = []Isolator(*is)[j]
if i.Name == name {
return &i
}
}
return nil
}
// Unrecognized returns a set of isolators that are not recognized.
// An isolator is not recognized if it has not had an associated
// constructor registered with AddIsolatorValueConstructor.
func (is *Isolators) Unrecognized() Isolators {
u := Isolators{}
for _, i := range *is {
if i.value == nil {
u = append(u, i)
}
}
return u
}
// IsolatorValue encapsulates the actual value of an Isolator which may be
// serialized as any arbitrary JSON blob. Specific Isolator types should
// implement this interface to facilitate unmarshalling and validation.
type IsolatorValue interface {
UnmarshalJSON(b []byte) error
AssertValid() error
}
// Isolator is a model for unmarshalling isolator types from their JSON-encoded
// representation.
type Isolator struct {
// Name is the name of the Isolator type as defined in the specification.
Name ACIdentifier `json:"name"`
// ValueRaw captures the raw JSON value of an Isolator that was
// unmarshalled. This field is used for unmarshalling only. It MUST NOT
// be referenced by external users of the Isolator struct. It is
// exported only to satisfy Go's unfortunate requirement that fields
// must be capitalized to be unmarshalled successfully.
ValueRaw *json.RawMessage `json:"value"`
// value captures the "true" value of the isolator.
value IsolatorValue
}
// isolator is a shadow type used for unmarshalling.
type isolator Isolator
// Value returns the raw Value of this Isolator. Users should perform a type
// switch/assertion on this value to extract the underlying isolator type.
func (i *Isolator) Value() IsolatorValue {
return i.value
}
// UnmarshalJSON populates this Isolator from a JSON-encoded representation. To
// unmarshal the Value of the Isolator, it will use the appropriate constructor
// as registered by AddIsolatorValueConstructor.
func (i *Isolator) UnmarshalJSON(b []byte) error {
var ii isolator
err := json.Unmarshal(b, &ii)
if err != nil {
return err
}
var dst IsolatorValue
con, ok := isolatorMap[ii.Name]
if ok {
dst = con()
err = dst.UnmarshalJSON(*ii.ValueRaw)
if err != nil {
return err
}
err = dst.AssertValid()
if err != nil {
return err
}
}
i.value = dst
i.ValueRaw = ii.ValueRaw
i.Name = ii.Name
return nil
}

View File

@@ -0,0 +1,143 @@
// Copyright 2015 The appc Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package types
import (
"encoding/json"
"errors"
)
const (
LinuxCapabilitiesRetainSetName = "os/linux/capabilities-retain-set"
LinuxCapabilitiesRevokeSetName = "os/linux/capabilities-remove-set"
)
var LinuxIsolatorNames = make(map[ACIdentifier]struct{})
func init() {
for name, con := range map[ACIdentifier]IsolatorValueConstructor{
LinuxCapabilitiesRevokeSetName: func() IsolatorValue { return &LinuxCapabilitiesRevokeSet{} },
LinuxCapabilitiesRetainSetName: func() IsolatorValue { return &LinuxCapabilitiesRetainSet{} },
} {
AddIsolatorName(name, LinuxIsolatorNames)
AddIsolatorValueConstructor(name, con)
}
}
type LinuxCapabilitiesSet interface {
Set() []LinuxCapability
AssertValid() error
}
type LinuxCapability string
type linuxCapabilitiesSetValue struct {
Set []LinuxCapability `json:"set"`
}
type linuxCapabilitiesSetBase struct {
val linuxCapabilitiesSetValue
}
func (l linuxCapabilitiesSetBase) AssertValid() error {
if len(l.val.Set) == 0 {
return errors.New("set must be non-empty")
}
return nil
}
func (l *linuxCapabilitiesSetBase) UnmarshalJSON(b []byte) error {
var v linuxCapabilitiesSetValue
err := json.Unmarshal(b, &v)
if err != nil {
return err
}
l.val = v
return err
}
func (l linuxCapabilitiesSetBase) Set() []LinuxCapability {
return l.val.Set
}
type LinuxCapabilitiesRetainSet struct {
linuxCapabilitiesSetBase
}
func NewLinuxCapabilitiesRetainSet(caps ...string) (*LinuxCapabilitiesRetainSet, error) {
l := LinuxCapabilitiesRetainSet{
linuxCapabilitiesSetBase{
linuxCapabilitiesSetValue{
make([]LinuxCapability, len(caps)),
},
},
}
for i, c := range caps {
l.linuxCapabilitiesSetBase.val.Set[i] = LinuxCapability(c)
}
if err := l.AssertValid(); err != nil {
return nil, err
}
return &l, nil
}
func (l LinuxCapabilitiesRetainSet) AsIsolator() Isolator {
b, err := json.Marshal(l.linuxCapabilitiesSetBase.val)
if err != nil {
panic(err)
}
rm := json.RawMessage(b)
return Isolator{
Name: LinuxCapabilitiesRetainSetName,
ValueRaw: &rm,
value: &l,
}
}
type LinuxCapabilitiesRevokeSet struct {
linuxCapabilitiesSetBase
}
func NewLinuxCapabilitiesRevokeSet(caps ...string) (*LinuxCapabilitiesRevokeSet, error) {
l := LinuxCapabilitiesRevokeSet{
linuxCapabilitiesSetBase{
linuxCapabilitiesSetValue{
make([]LinuxCapability, len(caps)),
},
},
}
for i, c := range caps {
l.linuxCapabilitiesSetBase.val.Set[i] = LinuxCapability(c)
}
if err := l.AssertValid(); err != nil {
return nil, err
}
return &l, nil
}
func (l LinuxCapabilitiesRevokeSet) AsIsolator() Isolator {
b, err := json.Marshal(l.linuxCapabilitiesSetBase.val)
if err != nil {
panic(err)
}
rm := json.RawMessage(b)
return Isolator{
Name: LinuxCapabilitiesRevokeSetName,
ValueRaw: &rm,
value: &l,
}
}

View File

@@ -0,0 +1,236 @@
// Copyright 2015 The appc Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package types
import (
"encoding/json"
"errors"
"fmt"
"k8s.io/kubernetes/pkg/api/resource"
)
var (
ErrDefaultTrue = errors.New("default must be false")
ErrDefaultRequired = errors.New("default must be true")
ErrRequestNonEmpty = errors.New("request not supported by this resource, must be empty")
ResourceIsolatorNames = make(map[ACIdentifier]struct{})
)
const (
ResourceBlockBandwidthName = "resource/block-bandwidth"
ResourceBlockIOPSName = "resource/block-iops"
ResourceCPUName = "resource/cpu"
ResourceMemoryName = "resource/memory"
ResourceNetworkBandwidthName = "resource/network-bandwidth"
)
func init() {
for name, con := range map[ACIdentifier]IsolatorValueConstructor{
ResourceBlockBandwidthName: func() IsolatorValue { return &ResourceBlockBandwidth{} },
ResourceBlockIOPSName: func() IsolatorValue { return &ResourceBlockIOPS{} },
ResourceCPUName: func() IsolatorValue { return &ResourceCPU{} },
ResourceMemoryName: func() IsolatorValue { return &ResourceMemory{} },
ResourceNetworkBandwidthName: func() IsolatorValue { return &ResourceNetworkBandwidth{} },
} {
AddIsolatorName(name, ResourceIsolatorNames)
AddIsolatorValueConstructor(name, con)
}
}
type Resource interface {
Limit() *resource.Quantity
Request() *resource.Quantity
Default() bool
}
type ResourceBase struct {
val resourceValue
}
type resourceValue struct {
Default bool `json:"default"`
Request *resource.Quantity `json:"request"`
Limit *resource.Quantity `json:"limit"`
}
func (r ResourceBase) Limit() *resource.Quantity {
return r.val.Limit
}
func (r ResourceBase) Request() *resource.Quantity {
return r.val.Request
}
func (r ResourceBase) Default() bool {
return r.val.Default
}
func (r *ResourceBase) UnmarshalJSON(b []byte) error {
return json.Unmarshal(b, &r.val)
}
func (r ResourceBase) AssertValid() error {
return nil
}
type ResourceBlockBandwidth struct {
ResourceBase
}
func (r ResourceBlockBandwidth) AssertValid() error {
if r.Default() != true {
return ErrDefaultRequired
}
if r.Request() != nil {
return ErrRequestNonEmpty
}
return nil
}
type ResourceBlockIOPS struct {
ResourceBase
}
func (r ResourceBlockIOPS) AssertValid() error {
if r.Default() != true {
return ErrDefaultRequired
}
if r.Request() != nil {
return ErrRequestNonEmpty
}
return nil
}
type ResourceCPU struct {
ResourceBase
}
func (r ResourceCPU) String() string {
return fmt.Sprintf("ResourceCPU(request=%s, limit=%s)", r.Request(), r.Limit())
}
func (r ResourceCPU) AssertValid() error {
if r.Default() != false {
return ErrDefaultTrue
}
return nil
}
func (r ResourceCPU) AsIsolator() Isolator {
isol := isolatorMap[ResourceCPUName]()
b, err := json.Marshal(r.val)
if err != nil {
panic(err)
}
valRaw := json.RawMessage(b)
return Isolator{
Name: ResourceCPUName,
ValueRaw: &valRaw,
value: isol,
}
}
func NewResourceCPUIsolator(request, limit string) (*ResourceCPU, error) {
req, err := resource.ParseQuantity(request)
if err != nil {
return nil, fmt.Errorf("error parsing request: %v", err)
}
lim, err := resource.ParseQuantity(limit)
if err != nil {
return nil, fmt.Errorf("error parsing limit: %v", err)
}
res := &ResourceCPU{
ResourceBase{
resourceValue{
Request: req,
Limit: lim,
},
},
}
if err := res.AssertValid(); err != nil {
// should never happen
return nil, err
}
return res, nil
}
type ResourceMemory struct {
ResourceBase
}
func (r ResourceMemory) String() string {
return fmt.Sprintf("ResourceMemory(request=%s, limit=%s)", r.Request(), r.Limit())
}
func (r ResourceMemory) AssertValid() error {
if r.Default() != false {
return ErrDefaultTrue
}
return nil
}
func (r ResourceMemory) AsIsolator() Isolator {
isol := isolatorMap[ResourceMemoryName]()
b, err := json.Marshal(r.val)
if err != nil {
panic(err)
}
valRaw := json.RawMessage(b)
return Isolator{
Name: ResourceMemoryName,
ValueRaw: &valRaw,
value: isol,
}
}
func NewResourceMemoryIsolator(request, limit string) (*ResourceMemory, error) {
req, err := resource.ParseQuantity(request)
if err != nil {
return nil, fmt.Errorf("error parsing request: %v", err)
}
lim, err := resource.ParseQuantity(limit)
if err != nil {
return nil, fmt.Errorf("error parsing limit: %v", err)
}
res := &ResourceMemory{
ResourceBase{
resourceValue{
Request: req,
Limit: lim,
},
},
}
if err := res.AssertValid(); err != nil {
// should never happen
return nil, err
}
return res, nil
}
type ResourceNetworkBandwidth struct {
ResourceBase
}
func (r ResourceNetworkBandwidth) AssertValid() error {
if r.Default() != true {
return ErrDefaultRequired
}
if r.Request() != nil {
return ErrRequestNonEmpty
}
return nil
}

134
vendor/github.com/appc/spec/schema/types/labels.go generated vendored Normal file
View File

@@ -0,0 +1,134 @@
// Copyright 2015 The appc Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package types
import (
"encoding/json"
"fmt"
"sort"
)
var ValidOSArch = map[string][]string{
"linux": {"amd64", "i386", "aarch64", "aarch64_be", "armv6l", "armv7l", "armv7b"},
"freebsd": {"amd64", "i386", "arm"},
"darwin": {"x86_64", "i386"},
}
type Labels []Label
type labels Labels
type Label struct {
Name ACIdentifier `json:"name"`
Value string `json:"value"`
}
// IsValidOsArch checks if a OS-architecture combination is valid given a map
// of valid OS-architectures
func IsValidOSArch(labels map[ACIdentifier]string, validOSArch map[string][]string) error {
if os, ok := labels["os"]; ok {
if validArchs, ok := validOSArch[os]; !ok {
// Not a whitelisted OS. TODO: how to warn rather than fail?
validOses := make([]string, 0, len(validOSArch))
for validOs := range validOSArch {
validOses = append(validOses, validOs)
}
sort.Strings(validOses)
return fmt.Errorf(`bad os %#v (must be one of: %v)`, os, validOses)
} else {
// Whitelisted OS. We check arch here, as arch makes sense only
// when os is defined.
if arch, ok := labels["arch"]; ok {
found := false
for _, validArch := range validArchs {
if arch == validArch {
found = true
break
}
}
if !found {
return fmt.Errorf(`bad arch %#v for %v (must be one of: %v)`, arch, os, validArchs)
}
}
}
}
return nil
}
func (l Labels) assertValid() error {
seen := map[ACIdentifier]string{}
for _, lbl := range l {
if lbl.Name == "name" {
return fmt.Errorf(`invalid label name: "name"`)
}
_, ok := seen[lbl.Name]
if ok {
return fmt.Errorf(`duplicate labels of name %q`, lbl.Name)
}
seen[lbl.Name] = lbl.Value
}
return IsValidOSArch(seen, ValidOSArch)
}
func (l Labels) MarshalJSON() ([]byte, error) {
if err := l.assertValid(); err != nil {
return nil, err
}
return json.Marshal(labels(l))
}
func (l *Labels) UnmarshalJSON(data []byte) error {
var jl labels
if err := json.Unmarshal(data, &jl); err != nil {
return err
}
nl := Labels(jl)
if err := nl.assertValid(); err != nil {
return err
}
*l = nl
return nil
}
// Get retrieves the value of the label by the given name from Labels, if it exists
func (l Labels) Get(name string) (val string, ok bool) {
for _, lbl := range l {
if lbl.Name.String() == name {
return lbl.Value, true
}
}
return "", false
}
// ToMap creates a map[ACIdentifier]string.
func (l Labels) ToMap() map[ACIdentifier]string {
labelsMap := make(map[ACIdentifier]string)
for _, lbl := range l {
labelsMap[lbl.Name] = lbl.Value
}
return labelsMap
}
// LabelsFromMap creates Labels from a map[ACIdentifier]string
func LabelsFromMap(labelsMap map[ACIdentifier]string) (Labels, error) {
labels := Labels{}
for n, v := range labelsMap {
labels = append(labels, Label{Name: n, Value: v})
}
if err := labels.assertValid(); err != nil {
return nil, err
}
return labels, nil
}

91
vendor/github.com/appc/spec/schema/types/mountpoint.go generated vendored Normal file
View File

@@ -0,0 +1,91 @@
// Copyright 2015 The appc Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package types
import (
"errors"
"fmt"
"net/url"
"strconv"
"github.com/appc/spec/schema/common"
)
type MountPoint struct {
Name ACName `json:"name"`
Path string `json:"path"`
ReadOnly bool `json:"readOnly,omitempty"`
}
func (mount MountPoint) assertValid() error {
if mount.Name.Empty() {
return errors.New("name must be set")
}
if len(mount.Path) == 0 {
return errors.New("path must be set")
}
return nil
}
// MountPointFromString takes a command line mountpoint parameter and returns a mountpoint
//
// It is useful for actool patch-manifest --mounts
//
// Example mountpoint parameters:
// database,path=/tmp,readOnly=true
func MountPointFromString(mp string) (*MountPoint, error) {
var mount MountPoint
mp = "name=" + mp
mpQuery, err := common.MakeQueryString(mp)
if err != nil {
return nil, err
}
v, err := url.ParseQuery(mpQuery)
if err != nil {
return nil, err
}
for key, val := range v {
if len(val) > 1 {
return nil, fmt.Errorf("label %s with multiple values %q", key, val)
}
switch key {
case "name":
acn, err := NewACName(val[0])
if err != nil {
return nil, err
}
mount.Name = *acn
case "path":
mount.Path = val[0]
case "readOnly":
ro, err := strconv.ParseBool(val[0])
if err != nil {
return nil, err
}
mount.ReadOnly = ro
default:
return nil, fmt.Errorf("unknown mountpoint parameter %q", key)
}
}
err = mount.assertValid()
if err != nil {
return nil, err
}
return &mount, nil
}

139
vendor/github.com/appc/spec/schema/types/port.go generated vendored Normal file
View File

@@ -0,0 +1,139 @@
// Copyright 2015 The appc Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package types
import (
"encoding/json"
"errors"
"fmt"
"net/url"
"strconv"
"github.com/appc/spec/schema/common"
)
type Port struct {
Name ACName `json:"name"`
Protocol string `json:"protocol"`
Port uint `json:"port"`
Count uint `json:"count"`
SocketActivated bool `json:"socketActivated"`
}
type ExposedPort struct {
Name ACName `json:"name"`
HostPort uint `json:"hostPort"`
}
type port Port
func (p *Port) UnmarshalJSON(data []byte) error {
var pp port
if err := json.Unmarshal(data, &pp); err != nil {
return err
}
np := Port(pp)
if err := np.assertValid(); err != nil {
return err
}
if np.Count == 0 {
np.Count = 1
}
*p = np
return nil
}
func (p Port) MarshalJSON() ([]byte, error) {
if err := p.assertValid(); err != nil {
return nil, err
}
return json.Marshal(port(p))
}
func (p Port) assertValid() error {
// Although there are no guarantees, most (if not all)
// transport protocols use 16 bit ports
if p.Port > 65535 || p.Port < 1 {
return errors.New("port must be in 1-65535 range")
}
if p.Port+p.Count > 65536 {
return errors.New("end of port range must be in 1-65535 range")
}
return nil
}
// PortFromString takes a command line port parameter and returns a port
//
// It is useful for actool patch-manifest --ports
//
// Example port parameters:
// health-check,protocol=udp,port=8000
// query,protocol=tcp,port=8080,count=1,socketActivated=true
func PortFromString(pt string) (*Port, error) {
var port Port
pt = "name=" + pt
ptQuery, err := common.MakeQueryString(pt)
if err != nil {
return nil, err
}
v, err := url.ParseQuery(ptQuery)
if err != nil {
return nil, err
}
for key, val := range v {
if len(val) > 1 {
return nil, fmt.Errorf("label %s with multiple values %q", key, val)
}
switch key {
case "name":
acn, err := NewACName(val[0])
if err != nil {
return nil, err
}
port.Name = *acn
case "protocol":
port.Protocol = val[0]
case "port":
p, err := strconv.ParseUint(val[0], 10, 16)
if err != nil {
return nil, err
}
port.Port = uint(p)
case "count":
cnt, err := strconv.ParseUint(val[0], 10, 16)
if err != nil {
return nil, err
}
port.Count = uint(cnt)
case "socketActivated":
sa, err := strconv.ParseBool(val[0])
if err != nil {
return nil, err
}
port.SocketActivated = sa
default:
return nil, fmt.Errorf("unknown port parameter %q", key)
}
}
err = port.assertValid()
if err != nil {
return nil, err
}
return &port, nil
}

91
vendor/github.com/appc/spec/schema/types/semver.go generated vendored Normal file
View File

@@ -0,0 +1,91 @@
// Copyright 2015 The appc Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package types
import (
"encoding/json"
"github.com/coreos/go-semver/semver"
)
var (
ErrNoZeroSemVer = ACVersionError("SemVer cannot be zero")
ErrBadSemVer = ACVersionError("SemVer is bad")
)
// SemVer implements the Unmarshaler interface to define a field that must be
// a semantic version string
// TODO(jonboulle): extend upstream instead of wrapping?
type SemVer semver.Version
// NewSemVer generates a new SemVer from a string. If the given string does
// not represent a valid SemVer, nil and an error are returned.
func NewSemVer(s string) (*SemVer, error) {
nsv, err := semver.NewVersion(s)
if err != nil {
return nil, ErrBadSemVer
}
v := SemVer(*nsv)
if v.Empty() {
return nil, ErrNoZeroSemVer
}
return &v, nil
}
func (sv SemVer) LessThanMajor(versionB SemVer) bool {
majorA := semver.Version(sv).Major
majorB := semver.Version(versionB).Major
if majorA < majorB {
return true
}
return false
}
func (sv SemVer) LessThanExact(versionB SemVer) bool {
vA := semver.Version(sv)
vB := semver.Version(versionB)
return vA.LessThan(vB)
}
func (sv SemVer) String() string {
s := semver.Version(sv)
return s.String()
}
func (sv SemVer) Empty() bool {
return semver.Version(sv) == semver.Version{}
}
// UnmarshalJSON implements the json.Unmarshaler interface
func (sv *SemVer) UnmarshalJSON(data []byte) error {
var s string
if err := json.Unmarshal(data, &s); err != nil {
return err
}
v, err := NewSemVer(s)
if err != nil {
return err
}
*sv = *v
return nil
}
// MarshalJSON implements the json.Marshaler interface
func (sv SemVer) MarshalJSON() ([]byte, error) {
if sv.Empty() {
return nil, ErrNoZeroSemVer
}
return json.Marshal(sv.String())
}

71
vendor/github.com/appc/spec/schema/types/url.go generated vendored Normal file
View File

@@ -0,0 +1,71 @@
// Copyright 2015 The appc Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package types
import (
"encoding/json"
"fmt"
"net/url"
)
// URL wraps url.URL to marshal/unmarshal to/from JSON strings and enforce
// that the scheme is HTTP/HTTPS only
type URL url.URL
func NewURL(s string) (*URL, error) {
uu, err := url.Parse(s)
if err != nil {
return nil, fmt.Errorf("bad URL: %v", err)
}
nu := URL(*uu)
if err := nu.assertValidScheme(); err != nil {
return nil, err
}
return &nu, nil
}
func (u URL) String() string {
uu := url.URL(u)
return uu.String()
}
func (u URL) assertValidScheme() error {
switch u.Scheme {
case "http", "https":
return nil
default:
return fmt.Errorf("bad URL scheme, must be http/https")
}
}
func (u *URL) UnmarshalJSON(data []byte) error {
var s string
if err := json.Unmarshal(data, &s); err != nil {
return err
}
nu, err := NewURL(s)
if err != nil {
return err
}
*u = *nu
return nil
}
func (u URL) MarshalJSON() ([]byte, error) {
if err := u.assertValidScheme(); err != nil {
return nil, err
}
return json.Marshal(u.String())
}

92
vendor/github.com/appc/spec/schema/types/uuid.go generated vendored Normal file
View File

@@ -0,0 +1,92 @@
// Copyright 2015 The appc Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package types
import (
"encoding/hex"
"encoding/json"
"errors"
"fmt"
"reflect"
"strings"
)
var (
ErrNoEmptyUUID = errors.New("UUID cannot be empty")
)
// UUID encodes an RFC4122-compliant UUID, marshaled to/from a string
// TODO(jonboulle): vendor a package for this?
// TODO(jonboulle): consider more flexibility in input string formats.
// Right now, we only accept:
// "6733C088-A507-4694-AABF-EDBE4FC5266F"
// "6733C088A5074694AABFEDBE4FC5266F"
type UUID [16]byte
func (u UUID) String() string {
return fmt.Sprintf("%x-%x-%x-%x-%x", u[0:4], u[4:6], u[6:8], u[8:10], u[10:16])
}
func (u *UUID) Set(s string) error {
nu, err := NewUUID(s)
if err == nil {
*u = *nu
}
return err
}
// NewUUID generates a new UUID from the given string. If the string does not
// represent a valid UUID, nil and an error are returned.
func NewUUID(s string) (*UUID, error) {
s = strings.Replace(s, "-", "", -1)
if len(s) != 32 {
return nil, errors.New("bad UUID length != 32")
}
dec, err := hex.DecodeString(s)
if err != nil {
return nil, err
}
var u UUID
for i, b := range dec {
u[i] = b
}
return &u, nil
}
func (u UUID) Empty() bool {
return reflect.DeepEqual(u, UUID{})
}
func (u *UUID) UnmarshalJSON(data []byte) error {
var s string
if err := json.Unmarshal(data, &s); err != nil {
return err
}
uu, err := NewUUID(s)
if uu.Empty() {
return ErrNoEmptyUUID
}
if err == nil {
*u = *uu
}
return err
}
func (u UUID) MarshalJSON() ([]byte, error) {
if u.Empty() {
return nil, ErrNoEmptyUUID
}
return json.Marshal(u.String())
}

236
vendor/github.com/appc/spec/schema/types/volume.go generated vendored Normal file
View File

@@ -0,0 +1,236 @@
// Copyright 2015 The appc Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package types
import (
"encoding/json"
"errors"
"fmt"
"net/url"
"path/filepath"
"strconv"
"strings"
"github.com/appc/spec/schema/common"
)
const (
emptyVolumeDefaultMode = "0755"
emptyVolumeDefaultUID = 0
emptyVolumeDefaultGID = 0
)
// Volume encapsulates a volume which should be mounted into the filesystem
// of all apps in a PodManifest
type Volume struct {
Name ACName `json:"name"`
Kind string `json:"kind"`
// currently used only by "host"
// TODO(jonboulle): factor out?
Source string `json:"source,omitempty"`
ReadOnly *bool `json:"readOnly,omitempty"`
// currently used only by "empty"
Mode *string `json:"mode,omitempty"`
UID *int `json:"uid,omitempty"`
GID *int `json:"gid,omitempty"`
}
type volume Volume
func (v Volume) assertValid() error {
if v.Name.Empty() {
return errors.New("name must be set")
}
switch v.Kind {
case "empty":
if v.Source != "" {
return errors.New("source for empty volume must be empty")
}
if v.Mode == nil {
return errors.New("mode for empty volume must be set")
}
if v.UID == nil {
return errors.New("uid for empty volume must be set")
}
if v.GID == nil {
return errors.New("gid for empty volume must be set")
}
return nil
case "host":
if v.Source == "" {
return errors.New("source for host volume cannot be empty")
}
if v.Mode != nil {
return errors.New("mode for host volume cannot be set")
}
if v.UID != nil {
return errors.New("uid for host volume cannot be set")
}
if v.GID != nil {
return errors.New("gid for host volume cannot be set")
}
if !filepath.IsAbs(v.Source) {
return errors.New("source for host volume must be absolute path")
}
return nil
default:
return errors.New(`unrecognized volume kind: should be one of "empty", "host"`)
}
}
func (v *Volume) UnmarshalJSON(data []byte) error {
var vv volume
if err := json.Unmarshal(data, &vv); err != nil {
return err
}
nv := Volume(vv)
maybeSetDefaults(&nv)
if err := nv.assertValid(); err != nil {
return err
}
*v = nv
return nil
}
func (v Volume) MarshalJSON() ([]byte, error) {
if err := v.assertValid(); err != nil {
return nil, err
}
return json.Marshal(volume(v))
}
func (v Volume) String() string {
s := []string{
v.Name.String(),
",kind=",
v.Kind,
}
if v.Source != "" {
s = append(s, ",source=")
s = append(s, v.Source)
}
if v.ReadOnly != nil {
s = append(s, ",readOnly=")
s = append(s, strconv.FormatBool(*v.ReadOnly))
}
switch v.Kind {
case "empty":
if *v.Mode != emptyVolumeDefaultMode {
s = append(s, ",mode=")
s = append(s, *v.Mode)
}
if *v.UID != emptyVolumeDefaultUID {
s = append(s, ",uid=")
s = append(s, strconv.Itoa(*v.UID))
}
if *v.GID != emptyVolumeDefaultGID {
s = append(s, ",gid=")
s = append(s, strconv.Itoa(*v.GID))
}
}
return strings.Join(s, "")
}
// VolumeFromString takes a command line volume parameter and returns a volume
//
// Example volume parameters:
// database,kind=host,source=/tmp,readOnly=true
func VolumeFromString(vp string) (*Volume, error) {
var vol Volume
vp = "name=" + vp
vpQuery, err := common.MakeQueryString(vp)
if err != nil {
return nil, err
}
v, err := url.ParseQuery(vpQuery)
if err != nil {
return nil, err
}
for key, val := range v {
val := val
if len(val) > 1 {
return nil, fmt.Errorf("label %s with multiple values %q", key, val)
}
switch key {
case "name":
acn, err := NewACName(val[0])
if err != nil {
return nil, err
}
vol.Name = *acn
case "kind":
vol.Kind = val[0]
case "source":
vol.Source = val[0]
case "readOnly":
ro, err := strconv.ParseBool(val[0])
if err != nil {
return nil, err
}
vol.ReadOnly = &ro
case "mode":
vol.Mode = &val[0]
case "uid":
u, err := strconv.Atoi(val[0])
if err != nil {
return nil, err
}
vol.UID = &u
case "gid":
g, err := strconv.Atoi(val[0])
if err != nil {
return nil, err
}
vol.GID = &g
default:
return nil, fmt.Errorf("unknown volume parameter %q", key)
}
}
maybeSetDefaults(&vol)
err = vol.assertValid()
if err != nil {
return nil, err
}
return &vol, nil
}
// maybeSetDefaults sets the correct default values for certain fields on a
// Volume if they are not already been set. These fields are not
// pre-populated on all Volumes as the Volume type is polymorphic.
func maybeSetDefaults(vol *Volume) {
if vol.Kind == "empty" {
if vol.Mode == nil {
m := emptyVolumeDefaultMode
vol.Mode = &m
}
if vol.UID == nil {
u := emptyVolumeDefaultUID
vol.UID = &u
}
if vol.GID == nil {
g := emptyVolumeDefaultGID
vol.GID = &g
}
}
}

39
vendor/github.com/appc/spec/schema/version.go generated vendored Normal file
View File

@@ -0,0 +1,39 @@
// Copyright 2015 The appc Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package schema
import (
"github.com/appc/spec/schema/types"
)
const (
// version represents the canonical version of the appc spec and tooling.
// For now, the schema and tooling is coupled with the spec itself, so
// this must be kept in sync with the VERSION file in the root of the repo.
version string = "0.7.4+git"
)
var (
// AppContainerVersion is the SemVer representation of version
AppContainerVersion types.SemVer
)
func init() {
v, err := types.NewSemVer(version)
if err != nil {
panic(err)
}
AppContainerVersion = *v
}