14 |
15 |
16 |
--------------------------------------------------------------------------------
/glide.yaml:
--------------------------------------------------------------------------------
1 | package: github.com/appc/spec
2 | import:
3 | - package: github.com/coreos/go-semver
4 | version: ~0.1.0
5 | subpackages:
6 | - semver
7 | - package: github.com/gogo/protobuf
8 | version: ~0.2
9 | subpackages:
10 | - proto
11 | - package: github.com/spf13/pflag
12 | version: 94e98a55fb412fcbcfc302555cb990f5e1590627
13 | - package: go4.org
14 | version: 03efcb870d84809319ea509714dd6d19a1498483
15 | subpackages:
16 | - errorutil
17 | - package: golang.org/x/net
18 | version: ccfcd82c7124abd517842acbacc3b8c1e390c73d
19 | subpackages:
20 | - html
21 | - html/atom
22 | - package: gopkg.in/inf.v0
23 | version: 3887ee99ecf07df5b447e9b00d9c0b2adaa9f3e4
24 |
--------------------------------------------------------------------------------
/ace/image_manifest_sidekick.json.in:
--------------------------------------------------------------------------------
1 | {
2 | "acVersion": "0.8.11",
3 | "acKind": "ImageManifest",
4 | "name": "coreos.com/ace-validator-sidekick",
5 | "labels": [
6 | { "name": "version", "value": "0.8.11" },
7 | { "name": "os", "value": "@ACI_OS@" },
8 | { "name": "arch", "value": "@ACI_ARCH@" }
9 | ],
10 | "app": {
11 | "exec": [
12 | "/ace-validator", "sidekick"
13 | ],
14 | "user": "0",
15 | "group": "0",
16 | "mountPoints": [
17 | {
18 | "name": "database",
19 | "path": "/db",
20 | "readOnly": false
21 | }
22 | ]
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/aci/doc.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The appc Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | // Package aci contains various functions for working with App Container Images.
16 | package aci
17 |
--------------------------------------------------------------------------------
/actool/doc.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The appc Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | // Package main contains a tool for building and validating images and
16 | // manifests that meet the App Container specifications.
17 | package main
18 |
--------------------------------------------------------------------------------
/discovery/doc.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The appc Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | // Package discovery contains an experimental implementation of the Image
16 | // Discovery section of the appc specification.
17 | package discovery
18 |
--------------------------------------------------------------------------------
/pkg/tarheader/doc.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The appc Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | // Package tarheader contains a simple abstraction to accurately create
16 | // tar.Headers on different operating systems.
17 | package tarheader
18 |
--------------------------------------------------------------------------------
/schema/types/user_labels.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The appc Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package types
16 |
17 | // UserLabels are arbitrary key-value pairs, to be supplied and interpreted by the user
18 | type UserLabels map[string]string
19 |
--------------------------------------------------------------------------------
/schema/types/user_annotations.go:
--------------------------------------------------------------------------------
1 | // Copyright 2016 The appc Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package types
16 |
17 | // UserAnnotations are arbitrary key-value pairs, to be supplied and interpreted by the user
18 | type UserAnnotations map[string]string
19 |
--------------------------------------------------------------------------------
/glide.lock:
--------------------------------------------------------------------------------
1 | hash: 8b25ad4ed6df28ab1f97f21f0744ff4fd42cba97cecad3443b4f1d039ca4f6cf
2 | updated: 2017-01-25T15:30:44.303100067-08:00
3 | imports:
4 | - name: github.com/coreos/go-semver
5 | version: 294930c1e79c64e7dbe360054274fdad492c8cf5
6 | subpackages:
7 | - semver
8 | - name: github.com/gogo/protobuf
9 | version: 4168943e65a2802828518e95310aeeed6d84c4e5
10 | subpackages:
11 | - proto
12 | - name: github.com/spf13/pflag
13 | version: 94e98a55fb412fcbcfc302555cb990f5e1590627
14 | - name: go4.org
15 | version: 03efcb870d84809319ea509714dd6d19a1498483
16 | subpackages:
17 | - errorutil
18 | - name: golang.org/x/net
19 | version: ccfcd82c7124abd517842acbacc3b8c1e390c73d
20 | subpackages:
21 | - html
22 | - html/atom
23 | - name: gopkg.in/inf.v0
24 | version: 3887ee99ecf07df5b447e9b00d9c0b2adaa9f3e4
25 | testImports: []
26 |
--------------------------------------------------------------------------------
/ace/os_default.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The appc Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | // +build !linux
16 | // +build !freebsd
17 |
18 | package main
19 |
20 | import (
21 | "syscall"
22 | )
23 |
24 | func isSameFilesystem(a, b *syscall.Statfs_t) bool {
25 | return a.Fsid == b.Fsid
26 | }
27 |
--------------------------------------------------------------------------------
/schema/types/doc.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The appc Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | // Package types contains structs representing the various types in the app
16 | // container specification. It is used by the [schema manifest types](../)
17 | // to enforce validation.
18 | package types
19 |
--------------------------------------------------------------------------------
/ace/doc.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The appc Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | // Package ace contains a tool intended to be run within an _Application
16 | // Container Executor_ to validate that the ACE has set up the container
17 | // environment correctly. This tool can be built into an ACI image ready for
18 | // running on an executor by using the `build_aci` script.
19 | package main
20 |
--------------------------------------------------------------------------------
/ace/os_shared.go:
--------------------------------------------------------------------------------
1 | // +build !linux
2 |
3 | package main
4 |
5 | import (
6 | "fmt"
7 | "path/filepath"
8 | "syscall"
9 | )
10 |
11 | func checkMountStatfs(d string, readonly bool) error {
12 | // or....
13 | // os.Stat(path).Sys().(*syscall.Stat_t).Dev
14 | sfs1 := &syscall.Statfs_t{}
15 | if err := syscall.Statfs(d, sfs1); err != nil {
16 | return fmt.Errorf("error calling statfs on %q: %v", d, err)
17 | }
18 | sfs2 := &syscall.Statfs_t{}
19 | if err := syscall.Statfs(filepath.Dir(d), sfs2); err != nil {
20 | return fmt.Errorf("error calling statfs on %q: %v", d, err)
21 | }
22 | if isSameFilesystem(sfs1, sfs2) {
23 | return fmt.Errorf("%q is not a mount point", d)
24 | }
25 | ro := sfs1.Flags&syscall.O_RDONLY == 1
26 | if ro != readonly {
27 | return fmt.Errorf("%q mounted ro=%t, want %t", d, ro, readonly)
28 | }
29 |
30 | return nil
31 | }
32 |
33 | func checkMountImpl(d string, readonly bool) error {
34 | return checkMountStatfs(d, readonly)
35 | }
36 |
--------------------------------------------------------------------------------
/pkg/tarheader/tarheader.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The appc Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package tarheader
16 |
17 | import (
18 | "archive/tar"
19 | "os"
20 | )
21 |
22 | var populateHeaderStat []func(h *tar.Header, fi os.FileInfo, seen map[uint64]string)
23 |
24 | func Populate(h *tar.Header, fi os.FileInfo, seen map[uint64]string) {
25 | for _, pop := range populateHeaderStat {
26 | pop(h, fi, seen)
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/schema/types/exec_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The appc Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package types
16 |
17 | import "testing"
18 |
19 | func TestExecValid(t *testing.T) {
20 | tests := []Exec{
21 | Exec{"/bin/httpd"},
22 | Exec{"/app"},
23 | Exec{"/app", "arg1", "arg2"},
24 | Exec{"app"},
25 | }
26 | for i, tt := range tests {
27 | if err := tt.assertValid(); err != nil {
28 | t.Errorf("#%d: err == %v, want nil", i, err)
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/actool/version.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The appc Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package main
16 |
17 | import (
18 | "fmt"
19 |
20 | "github.com/appc/spec/schema"
21 | )
22 |
23 | var cmdVersion = &Command{
24 | Name: "version",
25 | Description: "Print the version and exit",
26 | Summary: "Print the version and exit",
27 | Run: runVersion,
28 | }
29 |
30 | func runVersion(args []string) (exit int) {
31 | fmt.Printf("actool version %s\n", schema.AppContainerVersion.String())
32 | return
33 | }
34 |
--------------------------------------------------------------------------------
/scripts/build-release:
--------------------------------------------------------------------------------
1 | #!/bin/bash -eu
2 | #
3 | # Build the appc release of the specified version.
4 | #
5 | # YMMV, no disclaimer or warranty, etc.
6 |
7 | if ! [[ "$1" =~ ^v[[:digit:]]+.[[:digit:]]+.[[:digit:]]$ ]]; then
8 | echo "Usage: scripts/build-release "
9 | echo " where VERSION must be vX.Y.Z"
10 | exit 255
11 | fi
12 |
13 | ver="appc-${1}"
14 | releasedir="release-${ver}"
15 | mkdir "${ver}"
16 | mkdir "release-${ver}"
17 |
18 | git checkout "${1}"
19 | ./build.sh
20 | cp -r bin/actool SPEC.md spec/ "${ver}/"
21 | tar czvf "${ver}.tar.gz" "${ver}"
22 | echo "Wrote release tarball ${ver}.tar.gz"
23 | rm -fr "${ver}"
24 | gpg --detach-sign "${ver}.tar.gz"
25 | mv "${ver}.tar.gz" "${ver}.tar.gz.sig" "${releasedir}/"
26 |
27 | echo "Building ACE validators"
28 | if [[ -f scripts/build-ace-validator-acis ]]; then
29 | scripts/build-ace-validator-acis
30 | else
31 | ace/build_aci # backwards-compatible fallback
32 | fi
33 | cp bin/ace-validator-{main,sidekick}.aci{,.asc} "${releasedir}/"
34 |
35 | git checkout -
36 |
37 | echo "Done. Release artifacts in ${releasedir}/"
38 |
--------------------------------------------------------------------------------
/vendor/github.com/coreos/go-semver/semver/sort.go:
--------------------------------------------------------------------------------
1 | // Copyright 2013-2015 CoreOS, Inc.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package semver
16 |
17 | import (
18 | "sort"
19 | )
20 |
21 | type Versions []*Version
22 |
23 | func (s Versions) Len() int {
24 | return len(s)
25 | }
26 |
27 | func (s Versions) Swap(i, j int) {
28 | s[i], s[j] = s[j], s[i]
29 | }
30 |
31 | func (s Versions) Less(i, j int) bool {
32 | return s[i].LessThan(*s[j])
33 | }
34 |
35 | // Sort sorts the given slice of Version
36 | func Sort(versions []*Version) {
37 | sort.Sort(Versions(versions))
38 | }
39 |
--------------------------------------------------------------------------------
/schema/lastditch/labels.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The appc Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package lastditch
16 |
17 | import (
18 | "encoding/json"
19 | )
20 |
21 | type Labels []Label
22 |
23 | // a type just to avoid a recursion during unmarshalling
24 | type labels Labels
25 |
26 | type Label struct {
27 | Name string `json:"name"`
28 | Value string `json:"value"`
29 | }
30 |
31 | func (l *Labels) UnmarshalJSON(data []byte) error {
32 | var jl labels
33 | if err := json.Unmarshal(data, &jl); err != nil {
34 | return err
35 | }
36 | *l = Labels(jl)
37 | return nil
38 | }
39 |
--------------------------------------------------------------------------------
/ace/os_freebsd.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The appc Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | // +build freebsd
16 |
17 | package main
18 |
19 | import (
20 | "syscall"
21 | )
22 |
23 | func isSameFilesystem(a, b *syscall.Statfs_t) bool {
24 | if a.Fsid != (syscall.Fsid{}) || b.Fsid != (syscall.Fsid{}) {
25 | // If Fsid is not empty, we can just compare the IDs
26 | return a.Fsid == b.Fsid
27 | }
28 | // Fsids are zero, this happens in jails, but we can compare the rest
29 | return a.Fstypename == b.Fstypename &&
30 | a.Mntfromname == b.Mntfromname &&
31 | a.Mntonname == b.Mntonname
32 | }
33 |
--------------------------------------------------------------------------------
/pkg/tarheader/pop_linux.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The appc Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | // +build linux
16 |
17 | package tarheader
18 |
19 | import (
20 | "archive/tar"
21 | "os"
22 | "syscall"
23 | "time"
24 | )
25 |
26 | func init() {
27 | populateHeaderStat = append(populateHeaderStat, populateHeaderCtime)
28 | }
29 |
30 | func populateHeaderCtime(h *tar.Header, fi os.FileInfo, _ map[uint64]string) {
31 | st, ok := fi.Sys().(*syscall.Stat_t)
32 | if !ok {
33 | return
34 | }
35 |
36 | sec, nsec := st.Ctim.Unix()
37 | ctime := time.Unix(sec, nsec)
38 | h.ChangeTime = ctime
39 | }
40 |
--------------------------------------------------------------------------------
/pkg/tarheader/pop_darwin.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The appc Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | //+build darwin
16 |
17 | package tarheader
18 |
19 | import (
20 | "archive/tar"
21 | "os"
22 | "syscall"
23 | "time"
24 | )
25 |
26 | func init() {
27 | populateHeaderStat = append(populateHeaderStat, populateHeaderCtime)
28 | }
29 |
30 | func populateHeaderCtime(h *tar.Header, fi os.FileInfo, _ map[uint64]string) {
31 | st, ok := fi.Sys().(*syscall.Stat_t)
32 | if !ok {
33 | return
34 | }
35 |
36 | sec, nsec := st.Ctimespec.Unix()
37 | ctime := time.Unix(sec, nsec)
38 | h.ChangeTime = ctime
39 | }
40 |
--------------------------------------------------------------------------------
/scripts/bump-release:
--------------------------------------------------------------------------------
1 | #!/bin/bash -e
2 | #
3 | # Attempt to bump the appc release to the specified version by replacing all
4 | # occurrences of the current/previous version.
5 | #
6 | # Generates two commits: the release itself and the bump to the next +git
7 | # version
8 | #
9 | # YMMV, no disclaimer or warranty, etc.
10 |
11 | if ! [[ "$1" =~ ^v[[:digit:]]+.[[:digit:]]+.[[:digit:]]+$ ]]; then
12 | echo "Usage: scripts/bump-release "
13 | echo " where VERSION must be vX.Y.Z"
14 | exit 255
15 | fi
16 |
17 | function replace_all() {
18 | REPLACE=$(sed -e 's/[]\/$*.^|[]/\\&/g'<<< $1)
19 | git ls-files | fgrep -v CHANGELOG.md | xargs sed -i -e "s/$REPLACE/$2/g"
20 | }
21 |
22 | function replace_version() {
23 | REPLACE=$(sed -e 's/[]\/$*.^|[]/\\&/g'<<< $1)
24 | sed -i -e "s/$REPLACE/$2/g" VERSION schema/version.go
25 | }
26 |
27 | NEXT=${1:1} # 0.2.3
28 | NEXTGIT="${NEXT}+git" # 0.2.3+git
29 |
30 | PREVGIT=$(cat VERSION) # 0.1.2+git
31 | PREV=${PREVGIT::-4} # 0.1.2
32 |
33 | replace_version $PREVGIT $NEXT
34 | replace_all $PREV $NEXT
35 | git commit -am "version: bump to v${NEXT}"
36 |
37 | replace_version $NEXT $NEXTGIT
38 | git commit -am "version: bump to v${NEXTGIT}"
39 |
--------------------------------------------------------------------------------
/schema/kind.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The appc Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package schema
16 |
17 | import (
18 | "encoding/json"
19 |
20 | "github.com/appc/spec/schema/types"
21 | )
22 |
23 | type Kind struct {
24 | ACVersion types.SemVer `json:"acVersion"`
25 | ACKind types.ACKind `json:"acKind"`
26 | }
27 |
28 | type kind Kind
29 |
30 | func (k *Kind) UnmarshalJSON(data []byte) error {
31 | nk := kind{}
32 | err := json.Unmarshal(data, &nk)
33 | if err != nil {
34 | return err
35 | }
36 | *k = Kind(nk)
37 | return nil
38 | }
39 |
40 | func (k Kind) MarshalJSON() ([]byte, error) {
41 | return json.Marshal(kind(k))
42 | }
43 |
--------------------------------------------------------------------------------
/pkg/device/device_linux.go:
--------------------------------------------------------------------------------
1 | // Copyright 2016 The appc Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | // +build linux
16 |
17 | package device
18 |
19 | // with glibc/sysdeps/unix/sysv/linux/sys/sysmacros.h as reference
20 |
21 | func Major(rdev uint64) uint {
22 | return uint((rdev>>8)&0xfff) | (uint(rdev>>32) & ^uint(0xfff))
23 | }
24 |
25 | func Minor(rdev uint64) uint {
26 | return uint(rdev&0xff) | uint(uint32(rdev>>12) & ^uint32(0xff))
27 | }
28 |
29 | func Makedev(maj uint, min uint) uint64 {
30 | return uint64(min&0xff) | (uint64(maj&0xfff) << 8) |
31 | ((uint64(min) & ^uint64(0xff)) << 12) |
32 | ((uint64(maj) & ^uint64(0xfff)) << 32)
33 | }
34 |
--------------------------------------------------------------------------------
/schema/doc.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The appc Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | // Package schema provides definitions for the JSON schema of the different
16 | // manifests in the App Container Specification. The manifests are canonically
17 | // represented in their respective structs:
18 | // - `ImageManifest`
19 | // - `PodManifest`
20 | //
21 | // Validation is performed through serialization: if a blob of JSON data will
22 | // unmarshal to one of the *Manifests, it is considered a valid implementation
23 | // of the standard. Similarly, if a constructed *Manifest struct marshals
24 | // successfully to JSON, it must be valid.
25 | package schema
26 |
--------------------------------------------------------------------------------
/schema/types/exec.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The appc Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package types
16 |
17 | import "encoding/json"
18 |
19 | type Exec []string
20 |
21 | type exec Exec
22 |
23 | func (e Exec) assertValid() error {
24 | return nil
25 | }
26 |
27 | func (e Exec) MarshalJSON() ([]byte, error) {
28 | if err := e.assertValid(); err != nil {
29 | return nil, err
30 | }
31 | return json.Marshal(exec(e))
32 | }
33 |
34 | func (e *Exec) UnmarshalJSON(data []byte) error {
35 | var je exec
36 | err := json.Unmarshal(data, &je)
37 | if err != nil {
38 | return err
39 | }
40 | ne := Exec(je)
41 | if err := ne.assertValid(); err != nil {
42 | return err
43 | }
44 | *e = ne
45 | return nil
46 | }
47 |
--------------------------------------------------------------------------------
/ace/os_linux.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The appc Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | // +build linux
16 |
17 | package main
18 |
19 | import (
20 | "fmt"
21 | "os"
22 | )
23 |
24 | func checkMountImpl(d string, readonly bool) error {
25 | mountinfoPath := fmt.Sprintf("/proc/self/mountinfo")
26 | mi, err := os.Open(mountinfoPath)
27 | if err != nil {
28 | return err
29 | }
30 | defer mi.Close()
31 |
32 | isMounted, ro, err := parseMountinfo(mi, d)
33 | if err != nil {
34 | return err
35 | }
36 | if !isMounted {
37 | return fmt.Errorf("%q is not a mount point", d)
38 | }
39 |
40 | if ro == readonly {
41 | return nil
42 | } else {
43 | return fmt.Errorf("%q mounted ro=%t, want %t", d, ro, readonly)
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/schema/version.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The appc Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package schema
16 |
17 | import (
18 | "github.com/appc/spec/schema/types"
19 | )
20 |
21 | const (
22 | // version represents the canonical version of the appc spec and tooling.
23 | // For now, the schema and tooling is coupled with the spec itself, so
24 | // this must be kept in sync with the VERSION file in the root of the repo.
25 | version string = "0.8.11+git"
26 | )
27 |
28 | var (
29 | // AppContainerVersion is the SemVer representation of version
30 | AppContainerVersion types.SemVer
31 | )
32 |
33 | func init() {
34 | v, err := types.NewSemVer(version)
35 | if err != nil {
36 | panic(err)
37 | }
38 | AppContainerVersion = *v
39 | }
40 |
--------------------------------------------------------------------------------
/schema/types/port_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The appc Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package types
16 |
17 | import (
18 | "testing"
19 | )
20 |
21 | func TestGoodPort(t *testing.T) {
22 | p := Port{
23 | Port: 32456,
24 | Count: 100,
25 | }
26 | if err := p.assertValid(); err != nil {
27 | t.Errorf("good port assertion failed: %v", err)
28 | }
29 | }
30 |
31 | func TestBadPort(t *testing.T) {
32 | p := Port{
33 | Port: 88888,
34 | }
35 | if p.assertValid() == nil {
36 | t.Errorf("bad port asserted valid")
37 | }
38 | }
39 |
40 | func TestBadRange(t *testing.T) {
41 | p := Port{
42 | Port: 32456,
43 | Count: 45678,
44 | }
45 | if p.assertValid() == nil {
46 | t.Errorf("bad port range asserted valid")
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/examples/pod_template.json:
--------------------------------------------------------------------------------
1 | {
2 | "acVersion": "0.3.0",
3 | "acKind": "PodManifest",
4 | "apps": [
5 | {
6 | "name": "reduce-worker",
7 | "image": {
8 | "name": "example.com/reduce-worker",
9 | "id": "sha512-8d3fffddf79e9a232ffd19f9ccaa4d6b37a6a243dbe0f23137b108a043d9da13121a9b505c804956b22e93c7f93969f4a7ba8ddea45bf4aab0bebc8f814e0990"
10 | }
11 | },
12 | {
13 | "name": "backup",
14 | "image": {
15 | "name": "example.com/worker-backup",
16 | "labels": [
17 | {
18 | "name": "version",
19 | "value": "latest"
20 | }
21 | ]
22 | }
23 | },
24 | {
25 | "name": "register",
26 | "image": {
27 | "name": "example.com/reduce-worker-register",
28 | "labels": [
29 | {
30 | "name": "version",
31 | "value": "3.0.0"
32 | }
33 | ]
34 | }
35 | }
36 | ],
37 | "isolators": [
38 | {
39 | "name": "resource/memory",
40 | "value": {"limit": "4G"}
41 | }
42 | ]
43 | }
44 |
--------------------------------------------------------------------------------
/schema/types/dependencies_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The appc Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package types
16 |
17 | import "testing"
18 |
19 | func TestEmptyHash(t *testing.T) {
20 | dj := `{"imageName": "example.com/reduce-worker-base"}`
21 |
22 | var d Dependency
23 |
24 | err := d.UnmarshalJSON([]byte(dj))
25 | if err != nil {
26 | t.Fatalf("unexpected error: %v", err)
27 | }
28 |
29 | // Marshal to verify that marshalling works without validation errors
30 | buf, err := d.MarshalJSON()
31 | if err != nil {
32 | t.Fatalf("unexpected error: %v", err)
33 | }
34 |
35 | // Unmarshal to verify that the generated json will not create wrong empty hash
36 | err = d.UnmarshalJSON(buf)
37 | if err != nil {
38 | t.Fatalf("unexpected error: %v", err)
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/schema/lastditch/doc.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The appc Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | // Package lastditch provides fallback redefinitions of parts of
16 | // schemas provided by schema package.
17 | //
18 | // Almost no validation of schemas is done (besides checking if data
19 | // really is `JSON`-encoded and kind is either `ImageManifest` or
20 | // `PodManifest`. This is to get as much data as possible from an
21 | // invalid manifest. The main aim of the package is to be used for the
22 | // better error reporting. The another aim might be to force some
23 | // operation (like removing a pod), which would otherwise fail because
24 | // of an invalid manifest.
25 | //
26 | // To avoid validation during deserialization, types provided by this
27 | // package use plain strings.
28 | package lastditch
29 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/net/PATENTS:
--------------------------------------------------------------------------------
1 | Additional IP Rights Grant (Patents)
2 |
3 | "This implementation" means the copyrightable works distributed by
4 | Google as part of the Go project.
5 |
6 | Google hereby grants to You a perpetual, worldwide, non-exclusive,
7 | no-charge, royalty-free, irrevocable (except as stated in this section)
8 | patent license to make, have made, use, offer to sell, sell, import,
9 | transfer and otherwise run, modify and propagate the contents of this
10 | implementation of Go, where such license applies only to those patent
11 | claims, both currently owned or controlled by Google and acquired in
12 | the future, licensable by Google that are necessarily infringed by this
13 | implementation of Go. This grant does not include claims that would be
14 | infringed only as a consequence of further modification of this
15 | implementation. If you or your agent or exclusive licensee institute or
16 | order or agree to the institution of patent litigation against any
17 | entity (including a cross-claim or counterclaim in a lawsuit) alleging
18 | that this implementation of Go or any code incorporated within this
19 | implementation of Go constitutes direct or contributory patent
20 | infringement, or inducement of patent infringement, then any patent
21 | rights granted to you under this License for this implementation of Go
22 | shall terminate as of the date such litigation is filed.
23 |
--------------------------------------------------------------------------------
/schema/lastditch/image.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The appc Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package lastditch
16 |
17 | import (
18 | "encoding/json"
19 |
20 | "github.com/appc/spec/schema"
21 | "github.com/appc/spec/schema/types"
22 | )
23 |
24 | type ImageManifest struct {
25 | ACVersion string `json:"acVersion"`
26 | ACKind string `json:"acKind"`
27 | Name string `json:"name"`
28 | Labels Labels `json:"labels,omitempty"`
29 | }
30 |
31 | // a type just to avoid a recursion during unmarshalling
32 | type imageManifest ImageManifest
33 |
34 | func (im *ImageManifest) UnmarshalJSON(data []byte) error {
35 | i := imageManifest(*im)
36 | err := json.Unmarshal(data, &i)
37 | if err != nil {
38 | return err
39 | }
40 | if i.ACKind != string(schema.ImageManifestKind) {
41 | return types.InvalidACKindError(schema.ImageManifestKind)
42 | }
43 | *im = ImageManifest(i)
44 | return nil
45 | }
46 |
--------------------------------------------------------------------------------
/pkg/device/device_posix.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The appc Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | // +build freebsd netbsd openbsd darwin
16 |
17 | package device
18 |
19 | /*
20 | #define _BSD_SOURCE
21 | #define _DEFAULT_SOURCE
22 | #include
23 |
24 | unsigned int
25 | my_major(dev_t dev)
26 | {
27 | return major(dev);
28 | }
29 |
30 | unsigned int
31 | my_minor(dev_t dev)
32 | {
33 | return minor(dev);
34 | }
35 |
36 | dev_t
37 | my_makedev(unsigned int maj, unsigned int min)
38 | {
39 | return makedev(maj, min);
40 | }
41 | */
42 | import "C"
43 |
44 | func Major(rdev uint64) uint {
45 | major := C.my_major(C.dev_t(rdev))
46 | return uint(major)
47 | }
48 |
49 | func Minor(rdev uint64) uint {
50 | minor := C.my_minor(C.dev_t(rdev))
51 | return uint(minor)
52 | }
53 |
54 | func Makedev(maj uint, min uint) uint64 {
55 | dev := C.my_makedev(C.uint(maj), C.uint(min))
56 | return uint64(dev)
57 | }
58 |
--------------------------------------------------------------------------------
/schema/common/common.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The appc Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package common
16 |
17 | import (
18 | "fmt"
19 | "net/url"
20 | "strings"
21 | )
22 |
23 | // MakeQueryString takes a comma-separated LABEL=VALUE string and returns an
24 | // "&"-separated string with URL escaped values.
25 | //
26 | // Examples:
27 | // version=1.0.0,label=v1+v2 -> version=1.0.0&label=v1%2Bv2
28 | // name=db,source=/tmp$1 -> name=db&source=%2Ftmp%241
29 | func MakeQueryString(app string) (string, error) {
30 | parts := strings.Split(app, ",")
31 | escapedParts := make([]string, len(parts))
32 | for i, s := range parts {
33 | p := strings.SplitN(s, "=", 2)
34 | if len(p) != 2 {
35 | return "", fmt.Errorf("malformed string %q - has a label without a value: %s", app, p[0])
36 | }
37 | escapedParts[i] = fmt.Sprintf("%s=%s", p[0], url.QueryEscape(p[1]))
38 | }
39 | return strings.Join(escapedParts, "&"), nil
40 | }
41 |
--------------------------------------------------------------------------------
/DCO:
--------------------------------------------------------------------------------
1 | Developer Certificate of Origin
2 | Version 1.1
3 |
4 | Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
5 | 660 York Street, Suite 102,
6 | San Francisco, CA 94110 USA
7 |
8 | Everyone is permitted to copy and distribute verbatim copies of this
9 | license document, but changing it is not allowed.
10 |
11 |
12 | Developer's Certificate of Origin 1.1
13 |
14 | By making a contribution to this project, I certify that:
15 |
16 | (a) The contribution was created in whole or in part by me and I
17 | have the right to submit it under the open source license
18 | indicated in the file; or
19 |
20 | (b) The contribution is based upon previous work that, to the best
21 | of my knowledge, is covered under an appropriate open source
22 | license and I have the right under that license to submit that
23 | work with modifications, whether created in whole or in part
24 | by me, under the same open source license (unless I am
25 | permitted to submit under a different license), as indicated
26 | in the file; or
27 |
28 | (c) The contribution was provided directly to me by some other
29 | person who certified (a), (b) or (c) and I have not modified
30 | it.
31 |
32 | (d) I understand and agree that this project and the contribution
33 | are public and that a record of the contribution (including all
34 | personal information I submit with it, including my sign-off) is
35 | maintained indefinitely and may be redistributed consistent with
36 | this project or the open source license(s) involved.
37 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/net/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2009 The Go Authors. All rights reserved.
2 |
3 | Redistribution and use in source and binary forms, with or without
4 | modification, are permitted provided that the following conditions are
5 | met:
6 |
7 | * Redistributions of source code must retain the above copyright
8 | notice, this list of conditions and the following disclaimer.
9 | * Redistributions in binary form must reproduce the above
10 | copyright notice, this list of conditions and the following disclaimer
11 | in the documentation and/or other materials provided with the
12 | distribution.
13 | * Neither the name of Google Inc. nor the names of its
14 | contributors may be used to endorse or promote products derived from
15 | this software without specific prior written permission.
16 |
17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 |
--------------------------------------------------------------------------------
/scripts/build-ace-validator-acis:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 | #
3 | set -eu
4 |
5 | PREFIX="ace"
6 | : ${NO_SIGNATURE=}
7 |
8 | ACI_OS="$(go env GOOS)"
9 | GOARCH="$(go env GOARCH)"
10 | case $GOARCH in
11 | arm64) ACI_ARCH="aarch64" ;;
12 | *) ACI_ARCH="$GOARCH" ;;
13 | esac
14 |
15 | if ! [[ $0 =~ "scripts/build-ace-validator-acis" ]]; then
16 | echo "invoke from repository root" 1>&2
17 | exit 255
18 | fi
19 |
20 | if ! [[ -f "bin/ace-validator" ]]; then
21 | ./build
22 | fi
23 |
24 | for typ in main sidekick; do
25 | layoutdir="bin/ace-validator-${typ}-layout"
26 | mkdir -p ${layoutdir}/rootfs/opt/acvalidator
27 | cp bin/ace-validator ${layoutdir}/rootfs/
28 | sed -e "s/@ACI_OS@/$ACI_OS/" -e "s/@ACI_ARCH@/$ACI_ARCH/" < ${PREFIX}/image_manifest_${typ}.json.in > ${layoutdir}/manifest
29 | # now build the tarball, and sign it
30 | pushd ${layoutdir} >/dev/null
31 | # Set a consistent timestamp so we get a consistent hash
32 | # TODO(jonboulle): make this cleaner..
33 | for path in rootfs rootfs/ace-validator; do
34 | touch -a -m -d 1970-01-01T00:00:00Z ${path}
35 | done
36 | ../actool build --overwrite ./ ../ace-validator-${typ}.aci
37 | if [ -z "$NO_SIGNATURE" ] ; then
38 | gpg --cipher-algo AES256 --armor --output ace-validator-${typ}.aci.asc --detach-sig ../ace-validator-${typ}.aci
39 | mv ace-validator-${typ}.aci.asc ../
40 | fi
41 | popd >/dev/null
42 | echo "Wrote unsigned ${typ} ACI bin/ace-validator-${typ}.aci"
43 | if [ -f "bin/ace-validator-${typ}.aci.asc" ]; then
44 | echo "Wrote ${typ} ACI signature bin/ace-validator-${typ}.aci.asc"
45 | fi
46 | done
47 |
--------------------------------------------------------------------------------
/pkg/tarheader/pop_posix.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The appc Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | // +build linux freebsd netbsd openbsd
16 |
17 | package tarheader
18 |
19 | import (
20 | "archive/tar"
21 | "os"
22 | "syscall"
23 |
24 | "github.com/appc/spec/pkg/device"
25 | )
26 |
27 | func init() {
28 | populateHeaderStat = append(populateHeaderStat, populateHeaderUnix)
29 | }
30 |
31 | func populateHeaderUnix(h *tar.Header, fi os.FileInfo, seen map[uint64]string) {
32 | st, ok := fi.Sys().(*syscall.Stat_t)
33 | if !ok {
34 | return
35 | }
36 | h.Uid = int(st.Uid)
37 | h.Gid = int(st.Gid)
38 | if st.Mode&syscall.S_IFMT == syscall.S_IFBLK || st.Mode&syscall.S_IFMT == syscall.S_IFCHR {
39 | h.Devminor = int64(device.Minor(uint64(st.Rdev)))
40 | h.Devmajor = int64(device.Major(uint64(st.Rdev)))
41 | }
42 | // If we have already seen this inode, generate a hardlink
43 | p, ok := seen[uint64(st.Ino)]
44 | if ok {
45 | h.Linkname = p
46 | h.Typeflag = tar.TypeLink
47 | } else {
48 | seen[uint64(st.Ino)] = h.Name
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/schema/types/isolator_unix_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2016 The appc Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package types
16 |
17 | import (
18 | "reflect"
19 | "testing"
20 | )
21 |
22 | func TestUnixSysctlIsolator(t *testing.T) {
23 | tests := []struct {
24 | inCfg map[string]string
25 |
26 | expectedErr bool
27 | expectedRes UnixSysctl
28 | }{
29 | // empty isolator - valid
30 | {
31 | make(map[string]string),
32 |
33 | false,
34 | UnixSysctl{},
35 | },
36 | // simple isolator - valid
37 | {
38 | map[string]string{
39 | "foo": "bar",
40 | },
41 |
42 | false,
43 | UnixSysctl{
44 | "foo": "bar",
45 | },
46 | },
47 | }
48 | for i, tt := range tests {
49 | gotRes, err := NewUnixSysctlIsolator(tt.inCfg)
50 | if gotErr := err != nil; gotErr != tt.expectedErr {
51 | t.Errorf("#%d: want err=%t, got %t (err=%v)", i, tt.expectedErr, gotErr, err)
52 | }
53 | if !reflect.DeepEqual(tt.expectedRes, *gotRes) {
54 | t.Errorf("#%d: want %s, got %s", i, tt.expectedRes, *gotRes)
55 | }
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/schema/types/errors.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The appc Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package types
16 |
17 | import "fmt"
18 |
19 | // An ACKindError is returned when the wrong ACKind is set in a manifest
20 | type ACKindError string
21 |
22 | func (e ACKindError) Error() string {
23 | return string(e)
24 | }
25 |
26 | func InvalidACKindError(kind ACKind) ACKindError {
27 | return ACKindError(fmt.Sprintf("missing or bad ACKind (must be %#v)", kind))
28 | }
29 |
30 | // An ACVersionError is returned when a bad ACVersion is set in a manifest
31 | type ACVersionError string
32 |
33 | func (e ACVersionError) Error() string {
34 | return string(e)
35 | }
36 |
37 | // An ACIdentifierError is returned when a bad value is used for an ACIdentifier
38 | type ACIdentifierError string
39 |
40 | func (e ACIdentifierError) Error() string {
41 | return string(e)
42 | }
43 |
44 | // An ACNameError is returned when a bad value is used for an ACName
45 | type ACNameError string
46 |
47 | func (e ACNameError) Error() string {
48 | return string(e)
49 | }
50 |
--------------------------------------------------------------------------------
/vendor/gopkg.in/inf.v0/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2012 Péter Surányi. Portions Copyright (c) 2009 The Go
2 | Authors. All rights reserved.
3 |
4 | Redistribution and use in source and binary forms, with or without
5 | modification, are permitted provided that the following conditions are
6 | met:
7 |
8 | * Redistributions of source code must retain the above copyright
9 | notice, this list of conditions and the following disclaimer.
10 | * Redistributions in binary form must reproduce the above
11 | copyright notice, this list of conditions and the following disclaimer
12 | in the documentation and/or other materials provided with the
13 | distribution.
14 | * Neither the name of Google Inc. nor the names of its
15 | contributors may be used to endorse or promote products derived from
16 | this software without specific prior written permission.
17 |
18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 |
--------------------------------------------------------------------------------
/vendor/github.com/spf13/pflag/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2012 Alex Ogier. All rights reserved.
2 | Copyright (c) 2012 The Go Authors. All rights reserved.
3 |
4 | Redistribution and use in source and binary forms, with or without
5 | modification, are permitted provided that the following conditions are
6 | met:
7 |
8 | * Redistributions of source code must retain the above copyright
9 | notice, this list of conditions and the following disclaimer.
10 | * Redistributions in binary form must reproduce the above
11 | copyright notice, this list of conditions and the following disclaimer
12 | in the documentation and/or other materials provided with the
13 | distribution.
14 | * Neither the name of Google Inc. nor the names of its
15 | contributors may be used to endorse or promote products derived from
16 | this software without specific prior written permission.
17 |
18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 |
--------------------------------------------------------------------------------
/schema/types/event_handler.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The appc Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package types
16 |
17 | import (
18 | "encoding/json"
19 | "errors"
20 | "fmt"
21 | )
22 |
23 | type EventHandler struct {
24 | Name string `json:"name"`
25 | Exec Exec `json:"exec"`
26 | }
27 |
28 | type eventHandler EventHandler
29 |
30 | func (e EventHandler) assertValid() error {
31 | s := e.Name
32 | switch s {
33 | case "pre-start", "post-stop":
34 | return nil
35 | case "":
36 | return errors.New(`eventHandler "name" cannot be empty`)
37 | default:
38 | return fmt.Errorf(`bad eventHandler "name": %q`, s)
39 | }
40 | }
41 |
42 | func (e EventHandler) MarshalJSON() ([]byte, error) {
43 | if err := e.assertValid(); err != nil {
44 | return nil, err
45 | }
46 | return json.Marshal(eventHandler(e))
47 | }
48 |
49 | func (e *EventHandler) UnmarshalJSON(data []byte) error {
50 | var je eventHandler
51 | err := json.Unmarshal(data, &je)
52 | if err != nil {
53 | return err
54 | }
55 | ne := EventHandler(je)
56 | if err := ne.assertValid(); err != nil {
57 | return err
58 | }
59 | *e = ne
60 | return nil
61 | }
62 |
--------------------------------------------------------------------------------
/schema/types/dependencies.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The appc Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package types
16 |
17 | import (
18 | "encoding/json"
19 | "errors"
20 | )
21 |
22 | type Dependencies []Dependency
23 |
24 | type Dependency struct {
25 | ImageName ACIdentifier `json:"imageName"`
26 | ImageID *Hash `json:"imageID,omitempty"`
27 | Labels Labels `json:"labels,omitempty"`
28 | Size uint `json:"size,omitempty"`
29 | }
30 |
31 | type dependency Dependency
32 |
33 | func (d Dependency) assertValid() error {
34 | if len(d.ImageName) < 1 {
35 | return errors.New(`imageName cannot be empty`)
36 | }
37 | return nil
38 | }
39 |
40 | func (d Dependency) MarshalJSON() ([]byte, error) {
41 | if err := d.assertValid(); err != nil {
42 | return nil, err
43 | }
44 | return json.Marshal(dependency(d))
45 | }
46 |
47 | func (d *Dependency) UnmarshalJSON(data []byte) error {
48 | var jd dependency
49 | if err := json.Unmarshal(data, &jd); err != nil {
50 | return err
51 | }
52 | nd := Dependency(jd)
53 | if err := nd.assertValid(); err != nil {
54 | return err
55 | }
56 | *d = nd
57 | return nil
58 | }
59 |
--------------------------------------------------------------------------------
/schema/lastditch/common_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The appc Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package lastditch
16 |
17 | import (
18 | "fmt"
19 | "strings"
20 | )
21 |
22 | // extJ returns a JSON snippet describing an extra field with a given
23 | // name
24 | func extJ(name string) string {
25 | return fmt.Sprintf(`"%s": [],`, name)
26 | }
27 |
28 | // labsJ returns a labels array JSON snippet with given labels
29 | func labsJ(labels ...string) string {
30 | return fmt.Sprintf("[%s]", strings.Join(labels, ","))
31 | }
32 |
33 | // labsI returns a labels array instance with given labels
34 | func labsI(labels ...Label) Labels {
35 | if labels == nil {
36 | return Labels{}
37 | }
38 | return labels
39 | }
40 |
41 | // labJ returns a label JSON snippet with given name and value
42 | func labJ(name, value, extra string) string {
43 | return fmt.Sprintf(`
44 | {
45 | %s
46 | "name": "%s",
47 | "value": "%s"
48 | }`, extra, name, value)
49 | }
50 |
51 | // labI returns a label instance with given name and value
52 | func labI(name, value string) Label {
53 | return Label{
54 | Name: name,
55 | Value: value,
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/schema/lastditch/pod.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The appc Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package lastditch
16 |
17 | import (
18 | "encoding/json"
19 |
20 | "github.com/appc/spec/schema"
21 | "github.com/appc/spec/schema/types"
22 | )
23 |
24 | type PodManifest struct {
25 | ACVersion string `json:"acVersion"`
26 | ACKind string `json:"acKind"`
27 | Apps AppList `json:"apps"`
28 | }
29 |
30 | type AppList []RuntimeApp
31 |
32 | type RuntimeApp struct {
33 | Name string `json:"name"`
34 | Image RuntimeImage `json:"image"`
35 | }
36 |
37 | type RuntimeImage struct {
38 | Name string `json:"name,omitempty"`
39 | ID string `json:"id"`
40 | Labels Labels `json:"labels,omitempty"`
41 | }
42 |
43 | // a type just to avoid a recursion during unmarshalling
44 | type podManifest PodManifest
45 |
46 | func (pm *PodManifest) UnmarshalJSON(data []byte) error {
47 | p := podManifest(*pm)
48 | err := json.Unmarshal(data, &p)
49 | if err != nil {
50 | return err
51 | }
52 | if p.ACKind != string(schema.PodManifestKind) {
53 | return types.InvalidACKindError(schema.PodManifestKind)
54 | }
55 | *pm = PodManifest(p)
56 | return nil
57 | }
58 |
--------------------------------------------------------------------------------
/vendor/github.com/gogo/protobuf/proto/lib_gogo.go:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved.
2 | // http://github.com/gogo/protobuf/gogoproto
3 | //
4 | // Redistribution and use in source and binary forms, with or without
5 | // modification, are permitted provided that the following conditions are
6 | // met:
7 | //
8 | // * Redistributions of source code must retain the above copyright
9 | // notice, this list of conditions and the following disclaimer.
10 | // * Redistributions in binary form must reproduce the above
11 | // copyright notice, this list of conditions and the following disclaimer
12 | // in the documentation and/or other materials provided with the
13 | // distribution.
14 | //
15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 |
27 | package proto
28 |
29 | import (
30 | "encoding/json"
31 | "strconv"
32 | )
33 |
34 | func MarshalJSONEnum(m map[int32]string, value int32) ([]byte, error) {
35 | s, ok := m[value]
36 | if !ok {
37 | s = strconv.Itoa(int(value))
38 | }
39 | return json.Marshal(s)
40 | }
41 |
--------------------------------------------------------------------------------
/schema/image_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The appc Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package schema
16 |
17 | import "testing"
18 |
19 | func TestEmptyApp(t *testing.T) {
20 | imj := `
21 | {
22 | "acKind": "ImageManifest",
23 | "acVersion": "0.8.11",
24 | "name": "example.com/test"
25 | }
26 | `
27 |
28 | var im ImageManifest
29 |
30 | err := im.UnmarshalJSON([]byte(imj))
31 | if err != nil {
32 | t.Errorf("unexpected error: %v", err)
33 | }
34 |
35 | // Marshal and Unmarshal to verify that no "app": {} is generated on
36 | // Marshal and converted to empty struct on Unmarshal
37 | buf, err := im.MarshalJSON()
38 | if err != nil {
39 | t.Errorf("unexpected error: %v", err)
40 | }
41 |
42 | err = im.UnmarshalJSON(buf)
43 | if err != nil {
44 | t.Errorf("unexpected error: %v", err)
45 | }
46 | }
47 |
48 | func TestImageManifestMerge(t *testing.T) {
49 | imj := `{"name": "example.com/test"}`
50 | im := &ImageManifest{}
51 |
52 | if im.UnmarshalJSON([]byte(imj)) == nil {
53 | t.Fatal("Manifest JSON without acKind and acVersion unmarshalled successfully")
54 | }
55 |
56 | im = BlankImageManifest()
57 |
58 | err := im.UnmarshalJSON([]byte(imj))
59 | if err != nil {
60 | t.Errorf("unexpected error: %v", err)
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/schema/types/ackind.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The appc Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package types
16 |
17 | import (
18 | "encoding/json"
19 | "fmt"
20 | )
21 |
22 | var (
23 | ErrNoACKind = ACKindError("ACKind must be set")
24 | )
25 |
26 | // ACKind wraps a string to define a field which must be set with one of
27 | // several ACKind values. If it is unset, or has an invalid value, the field
28 | // will refuse to marshal/unmarshal.
29 | type ACKind string
30 |
31 | func (a ACKind) String() string {
32 | return string(a)
33 | }
34 |
35 | func (a ACKind) assertValid() error {
36 | s := a.String()
37 | switch s {
38 | case "ImageManifest", "PodManifest":
39 | return nil
40 | case "":
41 | return ErrNoACKind
42 | default:
43 | msg := fmt.Sprintf("bad ACKind: %s", s)
44 | return ACKindError(msg)
45 | }
46 | }
47 |
48 | func (a ACKind) MarshalJSON() ([]byte, error) {
49 | if err := a.assertValid(); err != nil {
50 | return nil, err
51 | }
52 | return json.Marshal(a.String())
53 | }
54 |
55 | func (a *ACKind) UnmarshalJSON(data []byte) error {
56 | var s string
57 | err := json.Unmarshal(data, &s)
58 | if err != nil {
59 | return err
60 | }
61 | na := ACKind(s)
62 | if err := na.assertValid(); err != nil {
63 | return err
64 | }
65 | *a = na
66 | return nil
67 | }
68 |
--------------------------------------------------------------------------------
/vendor/go4.org/errorutil/highlight.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2011 Google Inc.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | */
16 |
17 | // Package errorutil helps make better error messages.
18 | package errorutil // import "go4.org/errorutil"
19 |
20 | import (
21 | "bufio"
22 | "bytes"
23 | "fmt"
24 | "io"
25 | "strings"
26 | )
27 |
28 | // HighlightBytePosition takes a reader and the location in bytes of a parse
29 | // error (for instance, from json.SyntaxError.Offset) and returns the line, column,
30 | // and pretty-printed context around the error with an arrow indicating the exact
31 | // position of the syntax error.
32 | func HighlightBytePosition(f io.Reader, pos int64) (line, col int, highlight string) {
33 | line = 1
34 | br := bufio.NewReader(f)
35 | lastLine := ""
36 | thisLine := new(bytes.Buffer)
37 | for n := int64(0); n < pos; n++ {
38 | b, err := br.ReadByte()
39 | if err != nil {
40 | break
41 | }
42 | if b == '\n' {
43 | lastLine = thisLine.String()
44 | thisLine.Reset()
45 | line++
46 | col = 1
47 | } else {
48 | col++
49 | thisLine.WriteByte(b)
50 | }
51 | }
52 | if line > 1 {
53 | highlight += fmt.Sprintf("%5d: %s\n", line-1, lastLine)
54 | }
55 | highlight += fmt.Sprintf("%5d: %s\n", line, thisLine.String())
56 | highlight += fmt.Sprintf("%s^\n", strings.Repeat(" ", col+5))
57 | return
58 | }
59 |
--------------------------------------------------------------------------------
/vendor/github.com/gogo/protobuf/LICENSE:
--------------------------------------------------------------------------------
1 | Extensions for Protocol Buffers to create more go like structures.
2 |
3 | Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved.
4 | http://github.com/gogo/protobuf/gogoproto
5 |
6 | Go support for Protocol Buffers - Google's data interchange format
7 |
8 | Copyright 2010 The Go Authors. All rights reserved.
9 | https://github.com/golang/protobuf
10 |
11 | Redistribution and use in source and binary forms, with or without
12 | modification, are permitted provided that the following conditions are
13 | met:
14 |
15 | * Redistributions of source code must retain the above copyright
16 | notice, this list of conditions and the following disclaimer.
17 | * Redistributions in binary form must reproduce the above
18 | copyright notice, this list of conditions and the following disclaimer
19 | in the documentation and/or other materials provided with the
20 | distribution.
21 | * Neither the name of Google Inc. nor the names of its
22 | contributors may be used to endorse or promote products derived from
23 | this software without specific prior written permission.
24 |
25 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 |
37 |
--------------------------------------------------------------------------------
/schema/types/date.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The appc Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package types
16 |
17 | import (
18 | "encoding/json"
19 | "fmt"
20 | "time"
21 | )
22 |
23 | // Date wraps time.Time to marshal/unmarshal to/from JSON strings in strict
24 | // accordance with RFC3339
25 | // TODO(jonboulle): golang's implementation seems slightly buggy here;
26 | // according to http://tools.ietf.org/html/rfc3339#section-5.6 , applications
27 | // may choose to separate the date and time with a space instead of a T
28 | // character (for example, `date --rfc-3339` on GNU coreutils) - but this is
29 | // considered an error by go's parser. File a bug?
30 | type Date time.Time
31 |
32 | func NewDate(s string) (*Date, error) {
33 | t, err := time.Parse(time.RFC3339, s)
34 | if err != nil {
35 | return nil, fmt.Errorf("bad Date: %v", err)
36 | }
37 | d := Date(t)
38 | return &d, nil
39 | }
40 |
41 | func (d Date) String() string {
42 | return time.Time(d).Format(time.RFC3339)
43 | }
44 |
45 | func (d *Date) UnmarshalJSON(data []byte) error {
46 | var s string
47 | if err := json.Unmarshal(data, &s); err != nil {
48 | return err
49 | }
50 | nd, err := NewDate(s)
51 | if err != nil {
52 | return err
53 | }
54 | *d = *nd
55 | return nil
56 | }
57 |
58 | func (d Date) MarshalJSON() ([]byte, error) {
59 | return json.Marshal(d.String())
60 | }
61 |
--------------------------------------------------------------------------------
/schema/types/url.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The appc Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package types
16 |
17 | import (
18 | "encoding/json"
19 | "fmt"
20 | "net/url"
21 | )
22 |
23 | // URL wraps url.URL to marshal/unmarshal to/from JSON strings and enforce
24 | // that the scheme is HTTP/HTTPS only
25 | type URL url.URL
26 |
27 | func NewURL(s string) (*URL, error) {
28 | uu, err := url.Parse(s)
29 | if err != nil {
30 | return nil, fmt.Errorf("bad URL: %v", err)
31 | }
32 | nu := URL(*uu)
33 | if err := nu.assertValidScheme(); err != nil {
34 | return nil, err
35 | }
36 | return &nu, nil
37 | }
38 |
39 | func (u URL) String() string {
40 | uu := url.URL(u)
41 | return uu.String()
42 | }
43 |
44 | func (u URL) assertValidScheme() error {
45 | switch u.Scheme {
46 | case "http", "https":
47 | return nil
48 | default:
49 | return fmt.Errorf("bad URL scheme, must be http/https")
50 | }
51 | }
52 |
53 | func (u *URL) UnmarshalJSON(data []byte) error {
54 | var s string
55 | if err := json.Unmarshal(data, &s); err != nil {
56 | return err
57 | }
58 | nu, err := NewURL(s)
59 | if err != nil {
60 | return err
61 | }
62 | *u = *nu
63 | return nil
64 | }
65 |
66 | func (u URL) MarshalJSON() ([]byte, error) {
67 | if err := u.assertValidScheme(); err != nil {
68 | return nil, err
69 | }
70 | return json.Marshal(u.String())
71 | }
72 |
--------------------------------------------------------------------------------
/schema/types/uuid_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The appc Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package types
16 |
17 | import "testing"
18 |
19 | func TestNewUUID(t *testing.T) {
20 | tests := []struct {
21 | in string
22 | ws string
23 | }{
24 | {
25 | "6733C088-A507-4694-AABF-EDBE4FC5266F",
26 |
27 | "6733c088-a507-4694-aabf-edbe4fc5266f",
28 | },
29 | {
30 | "6733C088A5074694AABFEDBE4FC5266F",
31 |
32 | "6733c088-a507-4694-aabf-edbe4fc5266f",
33 | },
34 | {
35 | "0aaf0a79-1a39-4d59-abbf-1bebca8209d2",
36 |
37 | "0aaf0a79-1a39-4d59-abbf-1bebca8209d2",
38 | },
39 | {
40 | "0aaf0a791a394d59abbf1bebca8209d2",
41 |
42 | "0aaf0a79-1a39-4d59-abbf-1bebca8209d2",
43 | },
44 | }
45 | for i, tt := range tests {
46 | gu, err := NewUUID(tt.in)
47 | if err != nil {
48 | t.Errorf("#%d: err=%v, want %v", i, err, nil)
49 | }
50 | if gs := gu.String(); gs != tt.ws {
51 | t.Errorf("#%d: String()=%v, want %v", i, gs, tt.ws)
52 | }
53 | }
54 | }
55 |
56 | func TestNewUUIDBad(t *testing.T) {
57 | tests := []string{
58 | "asdf",
59 | "0AAF0A79-1A39-4D59-ABBF-1BEBCA8209D2ABC",
60 | "",
61 | }
62 | for i, tt := range tests {
63 | g, err := NewUUID(tt)
64 | if err == nil {
65 | t.Errorf("#%d: err=nil, want non-nil", i)
66 | }
67 | if g != nil {
68 | t.Errorf("#%d: err=%v, want %v", i, g, nil)
69 |
70 | }
71 | }
72 |
73 | }
74 |
--------------------------------------------------------------------------------
/schema/types/resource/quantity_example_test.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2014 The Kubernetes Authors All rights reserved.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | */
16 |
17 | package resource_test
18 |
19 | import (
20 | "fmt"
21 |
22 | "github.com/appc/spec/schema/types/resource"
23 | )
24 |
25 | func ExampleFormat() {
26 | memorySize := resource.NewQuantity(5*1024*1024*1024, resource.BinarySI)
27 | fmt.Printf("memorySize = %v\n", memorySize)
28 |
29 | diskSize := resource.NewQuantity(5*1000*1000*1000, resource.DecimalSI)
30 | fmt.Printf("diskSize = %v\n", diskSize)
31 |
32 | cores := resource.NewMilliQuantity(5300, resource.DecimalSI)
33 | fmt.Printf("cores = %v\n", cores)
34 |
35 | // Output:
36 | // memorySize = 5Gi
37 | // diskSize = 5G
38 | // cores = 5300m
39 | }
40 |
41 | func ExampleMustParse() {
42 | memorySize := resource.MustParse("5Gi")
43 | fmt.Printf("memorySize = %v (%v)\n", memorySize.Value(), memorySize.Format)
44 |
45 | diskSize := resource.MustParse("5G")
46 | fmt.Printf("diskSize = %v (%v)\n", diskSize.Value(), diskSize.Format)
47 |
48 | cores := resource.MustParse("5300m")
49 | fmt.Printf("milliCores = %v (%v)\n", cores.MilliValue(), cores.Format)
50 |
51 | cores2 := resource.MustParse("5.4")
52 | fmt.Printf("milliCores = %v (%v)\n", cores2.MilliValue(), cores2.Format)
53 |
54 | // Output:
55 | // memorySize = 5368709120 (BinarySI)
56 | // diskSize = 5000000000 (DecimalSI)
57 | // milliCores = 5300 (DecimalSI)
58 | // milliCores = 5400 (DecimalSI)
59 | }
60 |
--------------------------------------------------------------------------------
/test.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 | #
3 | # Run all appc tests
4 | # ./test
5 | # ./test -v
6 | #
7 | # Run tests for one package
8 | #
9 | # PKG=./discovery ./test
10 | # PKG=schema/types ./test
11 |
12 | set -e
13 |
14 | # Invoke ./cover for HTML output
15 | COVER=${COVER:-"-cover"}
16 |
17 | source ./build.sh
18 |
19 | TESTABLE_AND_FORMATTABLE="aci discovery pkg/acirenderer pkg/tarheader schema schema/lastditch schema/types"
20 | FORMATTABLE="$TESTABLE_AND_FORMATTABLE ace actool"
21 |
22 | # user has not provided PKG override
23 | if [ -z "$PKG" ]; then
24 | TEST=$TESTABLE_AND_FORMATTABLE
25 | FMT=$FORMATTABLE
26 |
27 | # user has provided PKG override
28 | else
29 | # strip out leading dotslashes and trailing slashes from PKG=./foo/
30 | TEST=${PKG/#./}
31 | TEST=${TEST/#\//}
32 | TEST=${TEST/%\//}
33 |
34 | # only run gofmt on packages provided by user
35 | FMT="$TEST"
36 | fi
37 |
38 | # split TEST into an array and prepend REPO_PATH to each local package
39 | split=(${TEST// / })
40 | TEST=${split[@]/#/${REPO_PATH}/}
41 |
42 | echo "Checking version..."
43 | sver=$(bin/actool version|awk '{print $NF}')
44 | read rver < VERSION
45 | if [ "${sver}" != "${rver}" ]; then
46 | echo "schema/version.go and VERSION differ (${sver} != ${rver})"
47 | exit 255
48 | fi
49 |
50 | echo "Running tests..."
51 | go test -timeout 60s ${COVER} $@ ${TEST} --race
52 |
53 | echo "Validating image manifest..."
54 | bin/actool validate examples/image.json
55 |
56 | echo "Validating pod template manifest..."
57 | bin/actool validate examples/pod_template.json
58 |
59 | # TODO(jonboulle): add `actool validate --resolved-pod-manifest`
60 | echo "Validating pod runtime manifest..."
61 | bin/actool validate examples/pod_runtime.json
62 |
63 | echo "Checking gofmt..."
64 | fmtRes=$(gofmt -l $FMT)
65 | if [ -n "${fmtRes}" ]; then
66 | echo -e "gofmt checking failed:\n${fmtRes}"
67 | exit 255
68 | fi
69 |
70 | echo "Checking govet..."
71 | vetRes=$(go vet $TEST)
72 | if [ -n "${vetRes}" ]; then
73 | echo -e "govet checking failed:\n${vetRes}"
74 | exit 255
75 | fi
76 |
77 | echo "Success"
78 |
--------------------------------------------------------------------------------
/schema/common/common_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The appc Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package common
16 |
17 | import (
18 | "testing"
19 | )
20 |
21 | func TestMakeQueryString(t *testing.T) {
22 | tests := []struct {
23 | input string
24 | output string
25 | werr bool
26 | }{
27 | {
28 | input: "",
29 | output: "",
30 | werr: true,
31 | },
32 | {
33 | input: "version,label=v1+v2",
34 | output: "",
35 | werr: true,
36 | },
37 | {
38 | input: "foo=bar",
39 | output: "foo=bar",
40 | werr: false,
41 | },
42 | {
43 | input: "foo=bar,boo=baz",
44 | output: "foo=bar&boo=baz",
45 | werr: false,
46 | },
47 | {
48 | input: "foo=Ümlaut",
49 | output: "foo=%C3%9Cmlaut",
50 | werr: false,
51 | },
52 | {
53 | input: "version=1.0.0,label=v1+v2",
54 | output: "version=1.0.0&label=v1%2Bv2",
55 | werr: false,
56 | },
57 | {
58 | input: "name=db,source=/tmp$1",
59 | output: "name=db&source=%2Ftmp%241",
60 | werr: false,
61 | },
62 | {
63 | input: "greeting-fr=Ça va?,greeting-es=¿Cómo estás?",
64 | output: "greeting-fr=%C3%87a+va%3F&greeting-es=%C2%BFC%C3%B3mo+est%C3%A1s%3F",
65 | werr: false,
66 | },
67 | }
68 |
69 | for i, tt := range tests {
70 | o, err := MakeQueryString(tt.input)
71 | gerr := (err != nil)
72 | if o != tt.output {
73 | t.Errorf("#%d: expected `%v` got `%v`", i, tt.output, o)
74 | }
75 | if gerr != tt.werr {
76 | t.Errorf("#%d: gerr=%t, want %t (err=%v)", i, gerr, tt.werr, err)
77 | }
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/vendor/github.com/gogo/protobuf/proto/text_gogo.go:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved.
2 | // http://github.com/gogo/protobuf/gogoproto
3 | //
4 | // Redistribution and use in source and binary forms, with or without
5 | // modification, are permitted provided that the following conditions are
6 | // met:
7 | //
8 | // * Redistributions of source code must retain the above copyright
9 | // notice, this list of conditions and the following disclaimer.
10 | // * Redistributions in binary form must reproduce the above
11 | // copyright notice, this list of conditions and the following disclaimer
12 | // in the documentation and/or other materials provided with the
13 | // distribution.
14 | //
15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 |
27 | package proto
28 |
29 | import (
30 | "fmt"
31 | "reflect"
32 | )
33 |
34 | func writeEnum(w *textWriter, v reflect.Value, props *Properties) error {
35 | m, ok := enumStringMaps[props.Enum]
36 | if !ok {
37 | if err := writeAny(w, v, props); err != nil {
38 | return err
39 | }
40 | }
41 | key := int32(0)
42 | if v.Kind() == reflect.Ptr {
43 | key = int32(v.Elem().Int())
44 | } else {
45 | key = int32(v.Int())
46 | }
47 | s, ok := m[key]
48 | if !ok {
49 | if err := writeAny(w, v, props); err != nil {
50 | return err
51 | }
52 | }
53 | _, err := fmt.Fprint(w, s)
54 | return err
55 | }
56 |
--------------------------------------------------------------------------------
/schema/types/date_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The appc Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package types
16 |
17 | import (
18 | "encoding/json"
19 | "testing"
20 | "time"
21 | )
22 |
23 | var (
24 | pst = time.FixedZone("Pacific", -8*60*60)
25 | )
26 |
27 | func TestUnmarshalDate(t *testing.T) {
28 | tests := []struct {
29 | in string
30 |
31 | wt time.Time
32 | }{
33 | {
34 | `"2004-05-14T23:11:14+00:00"`,
35 |
36 | time.Date(2004, 05, 14, 23, 11, 14, 0, time.UTC),
37 | },
38 | {
39 | `"2001-02-03T04:05:06Z"`,
40 |
41 | time.Date(2001, 02, 03, 04, 05, 06, 0, time.UTC),
42 | },
43 | {
44 | `"2014-11-14T17:36:54-08:00"`,
45 |
46 | time.Date(2014, 11, 14, 17, 36, 54, 0, pst),
47 | },
48 | {
49 | `"2004-05-14T23:11:14+00:00"`,
50 |
51 | time.Date(2004, 05, 14, 23, 11, 14, 0, time.UTC),
52 | },
53 | }
54 | for i, tt := range tests {
55 | var d Date
56 | if err := json.Unmarshal([]byte(tt.in), &d); err != nil {
57 | t.Errorf("#%d: got err=%v, want nil", i, err)
58 | }
59 | if gt := time.Time(d); !gt.Equal(tt.wt) {
60 | t.Errorf("#%d: got time=%v, want %v", i, gt, tt.wt)
61 | }
62 | }
63 | }
64 |
65 | func TestUnmarshalDateBad(t *testing.T) {
66 | tests := []string{
67 | `not a json string`,
68 | `2014-11-14T17:36:54-08:00`,
69 | `"garbage"`,
70 | `"1416015188"`,
71 | `"Fri Nov 14 17:53:02 PST 2014"`,
72 | `"2014-11-1417:36:54"`,
73 | }
74 | for i, tt := range tests {
75 | var d Date
76 | if err := json.Unmarshal([]byte(tt), &d); err == nil {
77 | t.Errorf("#%d: unexpected nil err", i)
78 | }
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/schema/types/hash_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The appc Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package types
16 |
17 | import (
18 | "encoding/json"
19 | "testing"
20 | )
21 |
22 | func TestMarshalHash(t *testing.T) {
23 | tests := []struct {
24 | typ string
25 | val string
26 |
27 | wout string
28 | }{
29 | {
30 | "sha512",
31 | "abcdefghi",
32 |
33 | `"sha512-abcdefghi"`,
34 | },
35 | {
36 | "sha512",
37 | "06c733b1838136838e6d2d3e8fa5aea4c7905e92",
38 |
39 | `"sha512-06c733b1838136838e6d2d3e8fa5aea4c7905e92"`,
40 | },
41 | }
42 | for i, tt := range tests {
43 | h := Hash{
44 | typ: tt.typ,
45 | Val: tt.val,
46 | }
47 | b, err := json.Marshal(h)
48 | if err != nil {
49 | t.Errorf("#%d: unexpected err=%v", i, err)
50 | }
51 | if g := string(b); g != tt.wout {
52 | t.Errorf("#%d: got string=%v, want %v", i, g, tt.wout)
53 | }
54 | }
55 | }
56 |
57 | func TestMarshalHashBad(t *testing.T) {
58 | tests := []struct {
59 | typ string
60 | val string
61 | }{
62 | {
63 | // empty value
64 | "sha512",
65 | "",
66 | },
67 | {
68 | // bad type
69 | "sha1",
70 | "abcdef",
71 | },
72 | {
73 | // empty type
74 | "",
75 | "abcdef",
76 | },
77 | {
78 | // empty empty
79 | "",
80 | "",
81 | },
82 | }
83 | for i, tt := range tests {
84 | h := Hash{
85 | typ: tt.typ,
86 | Val: tt.val,
87 | }
88 | g, err := json.Marshal(h)
89 | if err == nil {
90 | t.Errorf("#%d: unexpected nil err", i)
91 | }
92 | if g != nil {
93 | t.Errorf("#%d: unexpected non-nil bytes: %v", i, g)
94 | }
95 | }
96 | }
97 |
--------------------------------------------------------------------------------
/aci/layout_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The appc Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package aci
16 |
17 | import (
18 | "fmt"
19 | "io/ioutil"
20 | "os"
21 | "path"
22 | "testing"
23 |
24 | "github.com/appc/spec/schema"
25 | )
26 |
27 | func newValidateLayoutTest() (string, error) {
28 | td, err := ioutil.TempDir("", "")
29 | if err != nil {
30 | return "", err
31 | }
32 |
33 | if err := os.MkdirAll(path.Join(td, "rootfs"), 0755); err != nil {
34 | return "", err
35 | }
36 |
37 | if err := os.MkdirAll(path.Join(td, "rootfs", "dir", "rootfs"), 0755); err != nil {
38 | return "", err
39 | }
40 |
41 | evilManifestBody := "malformedManifest"
42 | manifestBody := fmt.Sprintf(`{"acKind":"ImageManifest","acVersion":"%s","name":"example.com/app"}`, schema.AppContainerVersion)
43 |
44 | evilManifestPath := "rootfs/manifest"
45 | evilManifestPath = path.Join(td, evilManifestPath)
46 |
47 | em, err := os.Create(evilManifestPath)
48 | if err != nil {
49 | return "", err
50 | }
51 |
52 | em.WriteString(evilManifestBody)
53 | em.Close()
54 |
55 | manifestPath := path.Join(td, "manifest")
56 |
57 | m, err := os.Create(manifestPath)
58 | if err != nil {
59 | return "", err
60 | }
61 |
62 | m.WriteString(manifestBody)
63 | m.Close()
64 |
65 | return td, nil
66 | }
67 |
68 | func TestValidateLayout(t *testing.T) {
69 | layoutPath, err := newValidateLayoutTest()
70 | if err != nil {
71 | t.Fatalf("newValidateLayoutTest: unexpected error: %v", err)
72 | }
73 | defer os.RemoveAll(layoutPath)
74 |
75 | err = ValidateLayout(layoutPath)
76 | if err != nil {
77 | t.Fatalf("ValidateLayout: unexpected error: %v", err)
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/schema/types/isolator_unix.go:
--------------------------------------------------------------------------------
1 | // Copyright 2016 The appc Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package types
16 |
17 | import (
18 | "encoding/json"
19 | )
20 |
21 | var (
22 | UnixIsolatorNames = make(map[ACIdentifier]struct{})
23 | )
24 |
25 | const (
26 | //TODO(lucab): add "ulimit" isolators
27 | UnixSysctlName = "os/unix/sysctl"
28 | )
29 |
30 | func init() {
31 | for name, con := range map[ACIdentifier]IsolatorValueConstructor{
32 | UnixSysctlName: func() IsolatorValue { return &UnixSysctl{} },
33 | } {
34 | AddIsolatorName(name, UnixIsolatorNames)
35 | AddIsolatorValueConstructor(name, con)
36 | }
37 | }
38 |
39 | type UnixSysctl map[string]string
40 |
41 | func (s *UnixSysctl) UnmarshalJSON(b []byte) error {
42 | var v map[string]string
43 | err := json.Unmarshal(b, &v)
44 | if err != nil {
45 | return err
46 | }
47 | *s = UnixSysctl(v)
48 | return err
49 | }
50 |
51 | func (s UnixSysctl) AssertValid() error {
52 | return nil
53 | }
54 |
55 | func (s UnixSysctl) multipleAllowed() bool {
56 | return false
57 | }
58 | func (s UnixSysctl) Conflicts() []ACIdentifier {
59 | return nil
60 | }
61 |
62 | func (s UnixSysctl) AsIsolator() Isolator {
63 | isol := isolatorMap[UnixSysctlName]()
64 |
65 | b, err := json.Marshal(s)
66 | if err != nil {
67 | panic(err)
68 | }
69 | valRaw := json.RawMessage(b)
70 | return Isolator{
71 | Name: UnixSysctlName,
72 | ValueRaw: &valRaw,
73 | value: isol,
74 | }
75 | }
76 |
77 | func NewUnixSysctlIsolator(cfg map[string]string) (*UnixSysctl, error) {
78 | s := UnixSysctl(cfg)
79 | if err := s.AssertValid(); err != nil {
80 | return nil, err
81 | }
82 | return &s, nil
83 | }
84 |
--------------------------------------------------------------------------------
/schema/types/mountpoint_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The appc Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package types
16 |
17 | import (
18 | "reflect"
19 | "testing"
20 | )
21 |
22 | func TestMountPointFromString(t *testing.T) {
23 | tests := []struct {
24 | s string
25 | mount MountPoint
26 | }{
27 | {
28 | "foobar,path=/tmp",
29 | MountPoint{
30 | Name: "foobar",
31 | Path: "/tmp",
32 | ReadOnly: false,
33 | },
34 | },
35 | {
36 | "foobar,path=/tmp,readOnly=false",
37 | MountPoint{
38 | Name: "foobar",
39 | Path: "/tmp",
40 | ReadOnly: false,
41 | },
42 | },
43 | {
44 | "foobar,path=/tmp,readOnly=true",
45 | MountPoint{
46 | Name: "foobar",
47 | Path: "/tmp",
48 | ReadOnly: true,
49 | },
50 | },
51 | }
52 | for i, tt := range tests {
53 | mount, err := MountPointFromString(tt.s)
54 | if err != nil {
55 | t.Errorf("#%d: got err=%v, want nil", i, err)
56 | }
57 | if !reflect.DeepEqual(*mount, tt.mount) {
58 | t.Errorf("#%d: mount=%v, want %v", i, *mount, tt.mount)
59 | }
60 | }
61 | }
62 |
63 | func TestMountPointFromStringBad(t *testing.T) {
64 | tests := []string{
65 | "#foobar,path=/tmp",
66 | "foobar,path=/tmp,readOnly=true,asdf=asdf",
67 | "foobar,path=/tmp,readOnly=maybe",
68 | "foobar,path=/tmp,readOnly=",
69 | "foobar,path=",
70 | "foobar",
71 | "",
72 | ",path=/",
73 | }
74 | for i, in := range tests {
75 | l, err := MountPointFromString(in)
76 | if l != nil {
77 | t.Errorf("#%d: got l=%v, want nil", i, l)
78 | }
79 | if err == nil {
80 | t.Errorf("#%d: got err=nil, want non-nil", i)
81 | }
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/schema/types/environment_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The appc Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package types
16 |
17 | import (
18 | "testing"
19 | )
20 |
21 | func TestEnvironmentAssertValid(t *testing.T) {
22 | tests := []struct {
23 | env Environment
24 | werr bool
25 | }{
26 | // duplicate names should fail
27 | {
28 | Environment{
29 | EnvironmentVariable{"DEBUG", "true"},
30 | EnvironmentVariable{"DEBUG", "true"},
31 | },
32 | true,
33 | },
34 | // empty name should fail
35 | {
36 | Environment{
37 | EnvironmentVariable{"", "value"},
38 | },
39 | true,
40 | },
41 | // name beginning with digit should fail
42 | {
43 | Environment{
44 | EnvironmentVariable{"0DEBUG", "true"},
45 | },
46 | true,
47 | },
48 | // name with non [A-Za-z0-9_.-] should fail
49 | {
50 | Environment{
51 | EnvironmentVariable{"VERBOSE|DEBUG", "true"},
52 | },
53 | true,
54 | },
55 | // accepted environment variable forms
56 | {
57 | Environment{
58 | EnvironmentVariable{"DEBUG", "true"},
59 | },
60 | false,
61 | },
62 | {
63 | Environment{
64 | EnvironmentVariable{"_0_DEBUG_0_", "true"},
65 | },
66 | false,
67 | },
68 | {
69 | Environment{
70 | EnvironmentVariable{"DEBUG.0", "true"},
71 | },
72 | false,
73 | },
74 | {
75 | Environment{
76 | EnvironmentVariable{"DEBUG-0", "true"},
77 | },
78 | false,
79 | },
80 | }
81 | for i, test := range tests {
82 | env := Environment(test.env)
83 | err := env.assertValid()
84 | if gerr := (err != nil); gerr != test.werr {
85 | t.Errorf("#%d: gerr=%t, want %t (err=%v)", i, gerr, test.werr, err)
86 | }
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/spec/OS-SPEC.md:
--------------------------------------------------------------------------------
1 | # Linux
2 |
3 | The Linux ABI consists of several special file paths and syscalls.
4 | Most applications targeted at Linux will require additional parts of the environment to be set up to run correctly.
5 |
6 | This document attempts to define a minimal set of things that must exist for most applications.
7 |
8 | ACIs that define the label `os=linux` can expect this environment by default.
9 |
10 | ## Devices and File Systems
11 |
12 | The following devices and filesystems MUST be made available in each application's filesystem
13 |
14 | | Path | Type | Notes |
15 | | ------------ | ------ | ------- |
16 | | /proc | [procfs](https://www.kernel.org/doc/Documentation/filesystems/proc.txt) | |
17 | | /sys | [sysfs](https://www.kernel.org/doc/Documentation/filesystems/sysfs.txt) | |
18 | | /dev/null | [device](http://man7.org/linux/man-pages/man4/null.4.html) | |
19 | | /dev/zero | [device](http://man7.org/linux/man-pages/man4/zero.4.html) | |
20 | | /dev/full | [device](http://man7.org/linux/man-pages/man4/full.4.html) | |
21 | | /dev/random | [device](http://man7.org/linux/man-pages/man4/random.4.html) | |
22 | | /dev/urandom | [device](http://man7.org/linux/man-pages/man4/random.4.html) | |
23 | | /dev/tty | [device](http://man7.org/linux/man-pages/man4/tty.4.html) | |
24 | | /dev/console | [device](http://man7.org/linux/man-pages/man4/console.4.html) | |
25 | | /dev/pts | [devpts](https://www.kernel.org/doc/Documentation/filesystems/devpts.txt) | |
26 | | /dev/ptmx | [device](https://www.kernel.org/doc/Documentation/filesystems/devpts.txt) | Bind-mount or symlink of /dev/pts/ptmx |
27 | | /dev/shm | [tmpfs](https://www.kernel.org/doc/Documentation/filesystems/tmpfs.txt) | |
28 |
29 | ## Common Files
30 |
31 | An ACE MAY provide a default, functional `/etc/hosts` in each application's filesystem.
32 | If provided, this file SHOULD contain a localhost loopback entry.
33 | If an application's filesystem already contains `/etc/hosts` (whether because it is provided in the application's image, or mounted in using a volume) the ACE SHOULD NOT modify the file unless explicitly requested by the user.
34 |
--------------------------------------------------------------------------------
/ace/image_manifest_main.json.in:
--------------------------------------------------------------------------------
1 | {
2 | "acVersion": "0.8.11",
3 | "acKind": "ImageManifest",
4 | "name": "coreos.com/ace-validator-main",
5 | "labels": [
6 | { "name": "version", "value": "0.8.11" },
7 | { "name": "os", "value": "@ACI_OS@" },
8 | { "name": "arch", "value": "@ACI_ARCH@" }
9 | ],
10 | "app": {
11 | "exec": [
12 | "/ace-validator", "main"
13 | ],
14 | "eventHandlers": [
15 | {
16 | "name": "pre-start",
17 | "exec": [
18 | "/ace-validator", "prestart"
19 | ]
20 | },
21 | {
22 | "name": "post-stop",
23 | "exec": [
24 | "/ace-validator", "poststop"
25 | ]
26 | }
27 | ],
28 | "user": "0",
29 | "group": "0",
30 | "workingDirectory": "/opt/acvalidator",
31 | "environment": [
32 | {
33 | "name": "IN_ACE_VALIDATOR",
34 | "value": "correct"
35 | }
36 | ],
37 | "mountPoints": [
38 | {
39 | "name": "database",
40 | "path": "/db",
41 | "readOnly": false
42 | }
43 | ],
44 | "ports": [
45 | {
46 | "name": "www",
47 | "protocol": "tcp",
48 | "port": 80
49 | }
50 | ],
51 | "isolators": [
52 | {
53 | "name": "resource/memory",
54 | "value": {"limit": "1G"}
55 | }
56 | ]
57 | },
58 | "annotations": [
59 | {
60 | "name": "created",
61 | "value": "2014-10-27T19:32:27.67021798Z"
62 | },
63 | {
64 | "name": "authors",
65 | "value": "Carly Container , Nat Network "
66 | },
67 | {
68 | "name": "homepage",
69 | "value": "https://github.com/appc/spec"
70 | },
71 | {
72 | "name": "documentation",
73 | "value": "https://github.com/appc/spec/blob/master/README.md"
74 | },
75 | {
76 | "name": "lorem",
77 | "value": "ipsum"
78 | }
79 | ]
80 | }
81 |
--------------------------------------------------------------------------------
/pkg/tarheader/pop_posix_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The appc Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | // +build linux freebsd netbsd openbsd
16 |
17 | package tarheader
18 |
19 | import (
20 | "archive/tar"
21 | "io/ioutil"
22 | "os"
23 | "path/filepath"
24 | "syscall"
25 | "testing"
26 | )
27 |
28 | // mknod requires privilege ...
29 | func TestHeaderUnixDev(t *testing.T) {
30 | hExpect := tar.Header{
31 | Name: "./dev/test0",
32 | Size: 0,
33 | Typeflag: tar.TypeBlock,
34 | Devminor: 5,
35 | Devmajor: 233,
36 | }
37 | // make our test block device
38 | var path string
39 | {
40 | var err error
41 | path, err = ioutil.TempDir("", "tarheader-test-")
42 | if err != nil {
43 | t.Fatal(err)
44 | }
45 | defer os.RemoveAll(path)
46 | if err := os.Mkdir(filepath.Join(path, "dev"), os.FileMode(0755)); err != nil {
47 | t.Fatal(err)
48 | }
49 | mode := uint32(hExpect.Mode&07777) | syscall.S_IFBLK
50 | dev := uint32(((hExpect.Devminor & 0xfff00) << 12) | ((hExpect.Devmajor & 0xfff) << 8) | (hExpect.Devminor & 0xff))
51 | if err := syscall.Mknod(filepath.Join(path, hExpect.Name), mode, int(dev)); err != nil {
52 | if err == syscall.EPERM {
53 | t.Skip("no permission to CAP_MKNOD")
54 | }
55 | t.Fatal(err)
56 | }
57 | }
58 | fi, err := os.Stat(filepath.Join(path, hExpect.Name))
59 | if err != nil {
60 | t.Fatal(err)
61 | }
62 |
63 | hGot := tar.Header{
64 | Name: "./dev/test0",
65 | Size: 0,
66 | Typeflag: tar.TypeBlock,
67 | }
68 |
69 | seen := map[uint64]string{}
70 | populateHeaderUnix(&hGot, fi, seen)
71 | if hGot.Devminor != hExpect.Devminor {
72 | t.Errorf("dev minor: got %d, expected %d", hGot.Devminor, hExpect.Devminor)
73 | }
74 | if hGot.Devmajor != hExpect.Devmajor {
75 | t.Errorf("dev major: got %d, expected %d", hGot.Devmajor, hExpect.Devmajor)
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/schema/types/resource/scale_int_test.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2015 The Kubernetes Authors All rights reserved.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | */
16 |
17 | package resource
18 |
19 | import (
20 | "math"
21 | "math/big"
22 | "testing"
23 | )
24 |
25 | func TestScaledValueInternal(t *testing.T) {
26 | tests := []struct {
27 | unscaled *big.Int
28 | scale int
29 | newScale int
30 |
31 | want int64
32 | }{
33 | // remain scale
34 | {big.NewInt(1000), 0, 0, 1000},
35 |
36 | // scale down
37 | {big.NewInt(1000), 0, -3, 1},
38 | {big.NewInt(1000), 3, 0, 1},
39 | {big.NewInt(0), 3, 0, 0},
40 |
41 | // always round up
42 | {big.NewInt(999), 3, 0, 1},
43 | {big.NewInt(500), 3, 0, 1},
44 | {big.NewInt(499), 3, 0, 1},
45 | {big.NewInt(1), 3, 0, 1},
46 | // large scaled value does not lose precision
47 | {big.NewInt(0).Sub(maxInt64, bigOne), 1, 0, (math.MaxInt64-1)/10 + 1},
48 | // large intermidiate result.
49 | {big.NewInt(1).Exp(big.NewInt(10), big.NewInt(100), nil), 100, 0, 1},
50 |
51 | // scale up
52 | {big.NewInt(0), 0, 3, 0},
53 | {big.NewInt(1), 0, 3, 1000},
54 | {big.NewInt(1), -3, 0, 1000},
55 | {big.NewInt(1000), -3, 2, 100000000},
56 | {big.NewInt(0).Div(big.NewInt(math.MaxInt64), bigThousand), 0, 3,
57 | (math.MaxInt64 / 1000) * 1000},
58 | }
59 |
60 | for i, tt := range tests {
61 | old := (&big.Int{}).Set(tt.unscaled)
62 | got := scaledValue(tt.unscaled, tt.scale, tt.newScale)
63 | if got != tt.want {
64 | t.Errorf("#%d: got = %v, want %v", i, got, tt.want)
65 | }
66 | if tt.unscaled.Cmp(old) != 0 {
67 | t.Errorf("#%d: unscaled = %v, want %v", i, tt.unscaled, old)
68 | }
69 | }
70 | }
71 |
72 | func BenchmarkScaledValueSmall(b *testing.B) {
73 | s := big.NewInt(1000)
74 | for i := 0; i < b.N; i++ {
75 | scaledValue(s, 3, 0)
76 | }
77 | }
78 |
79 | func BenchmarkScaledValueLarge(b *testing.B) {
80 | s := big.NewInt(math.MaxInt64)
81 | s.Mul(s, big.NewInt(1000))
82 | for i := 0; i < b.N; i++ {
83 | scaledValue(s, 10, 0)
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/schema/types/uuid.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The appc Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package types
16 |
17 | import (
18 | "encoding/hex"
19 | "encoding/json"
20 | "errors"
21 | "fmt"
22 | "reflect"
23 | "strings"
24 | )
25 |
26 | var (
27 | ErrNoEmptyUUID = errors.New("UUID cannot be empty")
28 | )
29 |
30 | // UUID encodes an RFC4122-compliant UUID, marshaled to/from a string
31 | // TODO(jonboulle): vendor a package for this?
32 | // TODO(jonboulle): consider more flexibility in input string formats.
33 | // Right now, we only accept:
34 | // "6733C088-A507-4694-AABF-EDBE4FC5266F"
35 | // "6733C088A5074694AABFEDBE4FC5266F"
36 | type UUID [16]byte
37 |
38 | func (u UUID) String() string {
39 | return fmt.Sprintf("%x-%x-%x-%x-%x", u[0:4], u[4:6], u[6:8], u[8:10], u[10:16])
40 | }
41 |
42 | func (u *UUID) Set(s string) error {
43 | nu, err := NewUUID(s)
44 | if err == nil {
45 | *u = *nu
46 | }
47 | return err
48 | }
49 |
50 | // NewUUID generates a new UUID from the given string. If the string does not
51 | // represent a valid UUID, nil and an error are returned.
52 | func NewUUID(s string) (*UUID, error) {
53 | s = strings.Replace(s, "-", "", -1)
54 | if len(s) != 32 {
55 | return nil, errors.New("bad UUID length != 32")
56 | }
57 | dec, err := hex.DecodeString(s)
58 | if err != nil {
59 | return nil, err
60 | }
61 | var u UUID
62 | for i, b := range dec {
63 | u[i] = b
64 | }
65 | return &u, nil
66 | }
67 |
68 | func (u UUID) Empty() bool {
69 | return reflect.DeepEqual(u, UUID{})
70 | }
71 |
72 | func (u *UUID) UnmarshalJSON(data []byte) error {
73 | var s string
74 | if err := json.Unmarshal(data, &s); err != nil {
75 | return err
76 | }
77 | uu, err := NewUUID(s)
78 | if uu.Empty() {
79 | return ErrNoEmptyUUID
80 | }
81 | if err == nil {
82 | *u = *uu
83 | }
84 | return err
85 | }
86 |
87 | func (u UUID) MarshalJSON() ([]byte, error) {
88 | if u.Empty() {
89 | return nil, ErrNoEmptyUUID
90 | }
91 | return json.Marshal(u.String())
92 | }
93 |
--------------------------------------------------------------------------------
/schema/types/mountpoint.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The appc Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package types
16 |
17 | import (
18 | "errors"
19 | "fmt"
20 | "net/url"
21 | "strconv"
22 |
23 | "github.com/appc/spec/schema/common"
24 | )
25 |
26 | // MountPoint is the application-side manifestation of a Volume.
27 | type MountPoint struct {
28 | Name ACName `json:"name"`
29 | Path string `json:"path"`
30 | ReadOnly bool `json:"readOnly,omitempty"`
31 | }
32 |
33 | func (mount MountPoint) assertValid() error {
34 | if mount.Name.Empty() {
35 | return errors.New("name must be set")
36 | }
37 | if len(mount.Path) == 0 {
38 | return errors.New("path must be set")
39 | }
40 | return nil
41 | }
42 |
43 | // MountPointFromString takes a command line mountpoint parameter and returns a mountpoint
44 | //
45 | // It is useful for actool patch-manifest --mounts
46 | //
47 | // Example mountpoint parameters:
48 | // database,path=/tmp,readOnly=true
49 | func MountPointFromString(mp string) (*MountPoint, error) {
50 | var mount MountPoint
51 |
52 | mp = "name=" + mp
53 | mpQuery, err := common.MakeQueryString(mp)
54 | if err != nil {
55 | return nil, err
56 | }
57 |
58 | v, err := url.ParseQuery(mpQuery)
59 | if err != nil {
60 | return nil, err
61 | }
62 | for key, val := range v {
63 | if len(val) > 1 {
64 | return nil, fmt.Errorf("label %s with multiple values %q", key, val)
65 | }
66 |
67 | switch key {
68 | case "name":
69 | acn, err := NewACName(val[0])
70 | if err != nil {
71 | return nil, err
72 | }
73 | mount.Name = *acn
74 | case "path":
75 | mount.Path = val[0]
76 | case "readOnly":
77 | ro, err := strconv.ParseBool(val[0])
78 | if err != nil {
79 | return nil, err
80 | }
81 | mount.ReadOnly = ro
82 | default:
83 | return nil, fmt.Errorf("unknown mountpoint parameter %q", key)
84 | }
85 | }
86 | err = mount.assertValid()
87 | if err != nil {
88 | return nil, err
89 | }
90 |
91 | return &mount, nil
92 | }
93 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/net/html/atom/atom.go:
--------------------------------------------------------------------------------
1 | // Copyright 2012 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // Package atom provides integer codes (also known as atoms) for a fixed set of
6 | // frequently occurring HTML strings: tag names and attribute keys such as "p"
7 | // and "id".
8 | //
9 | // Sharing an atom's name between all elements with the same tag can result in
10 | // fewer string allocations when tokenizing and parsing HTML. Integer
11 | // comparisons are also generally faster than string comparisons.
12 | //
13 | // The value of an atom's particular code is not guaranteed to stay the same
14 | // between versions of this package. Neither is any ordering guaranteed:
15 | // whether atom.H1 < atom.H2 may also change. The codes are not guaranteed to
16 | // be dense. The only guarantees are that e.g. looking up "div" will yield
17 | // atom.Div, calling atom.Div.String will return "div", and atom.Div != 0.
18 | package atom
19 |
20 | // Atom is an integer code for a string. The zero value maps to "".
21 | type Atom uint32
22 |
23 | // String returns the atom's name.
24 | func (a Atom) String() string {
25 | start := uint32(a >> 8)
26 | n := uint32(a & 0xff)
27 | if start+n > uint32(len(atomText)) {
28 | return ""
29 | }
30 | return atomText[start : start+n]
31 | }
32 |
33 | func (a Atom) string() string {
34 | return atomText[a>>8 : a>>8+a&0xff]
35 | }
36 |
37 | // fnv computes the FNV hash with an arbitrary starting value h.
38 | func fnv(h uint32, s []byte) uint32 {
39 | for i := range s {
40 | h ^= uint32(s[i])
41 | h *= 16777619
42 | }
43 | return h
44 | }
45 |
46 | func match(s string, t []byte) bool {
47 | for i, c := range t {
48 | if s[i] != c {
49 | return false
50 | }
51 | }
52 | return true
53 | }
54 |
55 | // Lookup returns the atom whose name is s. It returns zero if there is no
56 | // such atom. The lookup is case sensitive.
57 | func Lookup(s []byte) Atom {
58 | if len(s) == 0 || len(s) > maxAtomLen {
59 | return 0
60 | }
61 | h := fnv(hash0, s)
62 | if a := table[h&uint32(len(table)-1)]; int(a&0xff) == len(s) && match(a.string(), s) {
63 | return a
64 | }
65 | if a := table[(h>>16)&uint32(len(table)-1)]; int(a&0xff) == len(s) && match(a.string(), s) {
66 | return a
67 | }
68 | return 0
69 | }
70 |
71 | // String returns a string whose contents are equal to s. In that sense, it is
72 | // equivalent to string(s) but may be more efficient.
73 | func String(s []byte) string {
74 | if a := Lookup(s); a != 0 {
75 | return a.String()
76 | }
77 | return string(s)
78 | }
79 |
--------------------------------------------------------------------------------
/vendor/github.com/gogo/protobuf/proto/properties_gogo.go:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved.
2 | // http://github.com/gogo/protobuf/gogoproto
3 | //
4 | // Redistribution and use in source and binary forms, with or without
5 | // modification, are permitted provided that the following conditions are
6 | // met:
7 | //
8 | // * Redistributions of source code must retain the above copyright
9 | // notice, this list of conditions and the following disclaimer.
10 | // * Redistributions in binary form must reproduce the above
11 | // copyright notice, this list of conditions and the following disclaimer
12 | // in the documentation and/or other materials provided with the
13 | // distribution.
14 | //
15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 |
27 | package proto
28 |
29 | import (
30 | "fmt"
31 | "os"
32 | "reflect"
33 | )
34 |
35 | func (p *Properties) setCustomEncAndDec(typ reflect.Type) {
36 | p.ctype = typ
37 | if p.Repeated {
38 | p.enc = (*Buffer).enc_custom_slice_bytes
39 | p.dec = (*Buffer).dec_custom_slice_bytes
40 | p.size = size_custom_slice_bytes
41 | } else if typ.Kind() == reflect.Ptr {
42 | p.enc = (*Buffer).enc_custom_bytes
43 | p.dec = (*Buffer).dec_custom_bytes
44 | p.size = size_custom_bytes
45 | } else {
46 | p.enc = (*Buffer).enc_custom_ref_bytes
47 | p.dec = (*Buffer).dec_custom_ref_bytes
48 | p.size = size_custom_ref_bytes
49 | }
50 | }
51 |
52 | func (p *Properties) setSliceOfNonPointerStructs(typ reflect.Type) {
53 | t2 := typ.Elem()
54 | p.sstype = typ
55 | p.stype = t2
56 | p.isMarshaler = isMarshaler(t2)
57 | p.isUnmarshaler = isUnmarshaler(t2)
58 | p.enc = (*Buffer).enc_slice_ref_struct_message
59 | p.dec = (*Buffer).dec_slice_ref_struct_message
60 | p.size = size_slice_ref_struct_message
61 | if p.Wire != "bytes" {
62 | fmt.Fprintf(os.Stderr, "proto: no ptr oenc for %T -> %T \n", typ, t2)
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/schema/types/semver.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The appc Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package types
16 |
17 | import (
18 | "encoding/json"
19 |
20 | "github.com/coreos/go-semver/semver"
21 | )
22 |
23 | var (
24 | ErrNoZeroSemVer = ACVersionError("SemVer cannot be zero")
25 | ErrBadSemVer = ACVersionError("SemVer is bad")
26 | )
27 |
28 | // SemVer implements the Unmarshaler interface to define a field that must be
29 | // a semantic version string
30 | // TODO(jonboulle): extend upstream instead of wrapping?
31 | type SemVer semver.Version
32 |
33 | // NewSemVer generates a new SemVer from a string. If the given string does
34 | // not represent a valid SemVer, nil and an error are returned.
35 | func NewSemVer(s string) (*SemVer, error) {
36 | nsv, err := semver.NewVersion(s)
37 | if err != nil {
38 | return nil, ErrBadSemVer
39 | }
40 | v := SemVer(*nsv)
41 | if v.Empty() {
42 | return nil, ErrNoZeroSemVer
43 | }
44 | return &v, nil
45 | }
46 |
47 | func (sv SemVer) LessThanMajor(versionB SemVer) bool {
48 | majorA := semver.Version(sv).Major
49 | majorB := semver.Version(versionB).Major
50 | if majorA < majorB {
51 | return true
52 | }
53 | return false
54 | }
55 |
56 | func (sv SemVer) LessThanExact(versionB SemVer) bool {
57 | vA := semver.Version(sv)
58 | vB := semver.Version(versionB)
59 | return vA.LessThan(vB)
60 | }
61 |
62 | func (sv SemVer) String() string {
63 | s := semver.Version(sv)
64 | return s.String()
65 | }
66 |
67 | func (sv SemVer) Empty() bool {
68 | return semver.Version(sv) == semver.Version{}
69 | }
70 |
71 | // UnmarshalJSON implements the json.Unmarshaler interface
72 | func (sv *SemVer) UnmarshalJSON(data []byte) error {
73 | var s string
74 | if err := json.Unmarshal(data, &s); err != nil {
75 | return err
76 | }
77 | v, err := NewSemVer(s)
78 | if err != nil {
79 | return err
80 | }
81 | *sv = *v
82 | return nil
83 | }
84 |
85 | // MarshalJSON implements the json.Marshaler interface
86 | func (sv SemVer) MarshalJSON() ([]byte, error) {
87 | if sv.Empty() {
88 | return nil, ErrNoZeroSemVer
89 | }
90 | return json.Marshal(sv.String())
91 | }
92 |
--------------------------------------------------------------------------------
/aci/writer.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The appc Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package aci
16 |
17 | import (
18 | "archive/tar"
19 | "bytes"
20 | "encoding/json"
21 | "io"
22 | "time"
23 |
24 | "github.com/appc/spec/schema"
25 | )
26 |
27 | // ArchiveWriter writes App Container Images. Users wanting to create an ACI or
28 | // should create an ArchiveWriter and add files to it; the ACI will be written
29 | // to the underlying tar.Writer
30 | type ArchiveWriter interface {
31 | AddFile(hdr *tar.Header, r io.Reader) error
32 | Close() error
33 | }
34 |
35 | type imageArchiveWriter struct {
36 | *tar.Writer
37 | am *schema.ImageManifest
38 | }
39 |
40 | // NewImageWriter creates a new ArchiveWriter which will generate an App
41 | // Container Image based on the given manifest and write it to the given
42 | // tar.Writer
43 | func NewImageWriter(am schema.ImageManifest, w *tar.Writer) ArchiveWriter {
44 | aw := &imageArchiveWriter{
45 | w,
46 | &am,
47 | }
48 | return aw
49 | }
50 |
51 | func (aw *imageArchiveWriter) AddFile(hdr *tar.Header, r io.Reader) error {
52 | err := aw.Writer.WriteHeader(hdr)
53 | if err != nil {
54 | return err
55 | }
56 |
57 | if r != nil {
58 | _, err := io.Copy(aw.Writer, r)
59 | if err != nil {
60 | return err
61 | }
62 | }
63 |
64 | return nil
65 | }
66 |
67 | func (aw *imageArchiveWriter) addFileNow(path string, contents []byte) error {
68 | buf := bytes.NewBuffer(contents)
69 | now := time.Now()
70 | hdr := tar.Header{
71 | Name: path,
72 | Mode: 0644,
73 | Uid: 0,
74 | Gid: 0,
75 | Size: int64(buf.Len()),
76 | ModTime: now,
77 | Typeflag: tar.TypeReg,
78 | Uname: "root",
79 | Gname: "root",
80 | ChangeTime: now,
81 | }
82 | return aw.AddFile(&hdr, buf)
83 | }
84 |
85 | func (aw *imageArchiveWriter) addManifest(name string, m json.Marshaler) error {
86 | out, err := m.MarshalJSON()
87 | if err != nil {
88 | return err
89 | }
90 | return aw.addFileNow(name, out)
91 | }
92 |
93 | func (aw *imageArchiveWriter) Close() error {
94 | if err := aw.addManifest(ManifestFile, aw.am); err != nil {
95 | return err
96 | }
97 | return aw.Writer.Close()
98 | }
99 |
--------------------------------------------------------------------------------
/schema/types/ackind_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The appc Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package types
16 |
17 | import (
18 | "encoding/json"
19 | "reflect"
20 | "testing"
21 | )
22 |
23 | func TestACKindMarshalBad(t *testing.T) {
24 | tests := map[string]error{
25 | "Foo": ACKindError("bad ACKind: Foo"),
26 | "ApplicationManifest": ACKindError("bad ACKind: ApplicationManifest"),
27 | "": ErrNoACKind,
28 | }
29 | for in, werr := range tests {
30 | a := ACKind(in)
31 | b, gerr := json.Marshal(a)
32 | if b != nil {
33 | t.Errorf("ACKind(%q): want b=nil, got %v", in, b)
34 | }
35 | if jerr, ok := gerr.(*json.MarshalerError); !ok {
36 | t.Errorf("expected JSONMarshalerError")
37 | } else {
38 | if e := jerr.Err; e != werr {
39 | t.Errorf("err=%#v, want %#v", e, werr)
40 | }
41 | }
42 | }
43 | }
44 |
45 | func TestACKindMarshalGood(t *testing.T) {
46 | for i, in := range []string{
47 | "ImageManifest",
48 | "PodManifest",
49 | } {
50 | a := ACKind(in)
51 | b, err := json.Marshal(a)
52 | if !reflect.DeepEqual(b, []byte(`"`+in+`"`)) {
53 | t.Errorf("#%d: marshalled=%v, want %v", i, b, []byte(in))
54 | }
55 | if err != nil {
56 | t.Errorf("#%d: err=%v, want nil", i, err)
57 | }
58 | }
59 | }
60 |
61 | func TestACKindUnmarshalBad(t *testing.T) {
62 | tests := []string{
63 | "ImageManifest", // Not a valid JSON-encoded string
64 | `"garbage"`,
65 | `"AppManifest"`,
66 | `""`,
67 | }
68 | for i, in := range tests {
69 | var a, b ACKind
70 | err := a.UnmarshalJSON([]byte(in))
71 | if err == nil {
72 | t.Errorf("#%d: err=nil, want non-nil", i)
73 | } else if !reflect.DeepEqual(a, b) {
74 | t.Errorf("#%d: a=%v, want empty", i, a)
75 | }
76 | }
77 | }
78 |
79 | func TestACKindUnmarshalGood(t *testing.T) {
80 | tests := map[string]ACKind{
81 | `"PodManifest"`: ACKind("PodManifest"),
82 | `"ImageManifest"`: ACKind("ImageManifest"),
83 | }
84 | for in, w := range tests {
85 | var a ACKind
86 | err := json.Unmarshal([]byte(in), &a)
87 | if err != nil {
88 | t.Errorf("%v: err=%v, want nil", in, err)
89 | } else if !reflect.DeepEqual(a, w) {
90 | t.Errorf("%v: a=%v, want %v", in, a, w)
91 | }
92 | }
93 | }
94 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # How to Contribute
2 |
3 | appc is [Apache 2.0 licensed](LICENSE) and accepts contributions via GitHub
4 | pull requests. This document outlines some of the conventions on development
5 | workflow, commit message formatting, contact points and other resources to make
6 | it easier to get your contribution accepted.
7 |
8 | For more information on the policy for accepting contributions, see [POLICY](POLICY.md)
9 |
10 | # Certificate of Origin
11 |
12 | By contributing to this project you agree to the Developer Certificate of
13 | Origin (DCO). This document was created by the Linux Kernel community and is a
14 | simple statement that you, as a contributor, have the legal right to make the
15 | contribution. See the [DCO](DCO) file for details.
16 |
17 | # Email and Chat
18 |
19 | The project uses the the appc-dev email list and #appc on Freenode for chat:
20 | - Email: [appc-dev](https://groups.google.com/forum/#!forum/appc-dev)
21 | - IRC: #[appc](irc://irc.freenode.org:6667/#appc) IRC channel on freenode.org
22 |
23 | Please avoid emailing maintainers found in the MAINTAINERS file directly. They
24 | are very busy and read the mailing lists.
25 |
26 | ## Getting Started
27 |
28 | - Fork the repository on GitHub
29 | - Read the [README](README.md) for build and test instructions
30 | - Play with the project, submit bugs, submit patches!
31 |
32 | ## Contribution Flow
33 |
34 | This is a rough outline of what a contributor's workflow looks like:
35 |
36 | - Create a topic branch from where you want to base your work (usually master).
37 | - Make commits of logical units.
38 | - Make sure your commit messages are in the proper format (see below).
39 | - Push your changes to a topic branch in your fork of the repository.
40 | - Make sure the tests pass, and add any new tests as appropriate.
41 | - Submit a pull request to the original repository.
42 |
43 | Thanks for your contributions!
44 |
45 | ### Format of the Commit Message
46 |
47 | We follow a rough convention for commit messages that is designed to answer two
48 | questions: what changed and why. The subject line should feature the what and
49 | the body of the commit should describe the why.
50 |
51 | ```
52 | scripts: add the test-cluster command
53 |
54 | this uses tmux to setup a test cluster that you can easily kill and
55 | start for debugging.
56 |
57 | Fixes #38
58 | ```
59 |
60 | The format can be described more formally as follows:
61 |
62 | ```
63 | :
64 |
65 |
66 |
67 |