Skip to content

Commit

Permalink
Merge branch 'master' of github.com:snapcore/snapd into tweak/opensus…
Browse files Browse the repository at this point in the history
…e-snapd-mk
  • Loading branch information
zyga committed Feb 11, 2019
2 parents 288e7ec + 09ec71c commit bc5f521
Show file tree
Hide file tree
Showing 470 changed files with 19,725 additions and 3,237 deletions.
9 changes: 5 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ git:
jobs:
include:
- stage: quick
name: go 1.6/xenial static and unit test suites
name: go 1.9/xenial static and unit test suites
dist: xenial
go: 1.6
go: "1.9"
before_install:
- sudo apt --quiet -o Dpkg::Progress-Fancy=false update
install:
Expand All @@ -17,7 +17,7 @@ jobs:
- ./run-checks --static
- ./run-checks --short-unit
- stage: quick
go: 1.10
go: "1.10"
name: OSX build and minimal runtime sanity check
os: osx
addons:
Expand All @@ -36,6 +36,7 @@ jobs:
- /tmp/snp pack tests/lib/snaps/test-snapd-tools/ /tmp
- stage: quick
name: CLA check
dist: xenial
if: type = pull_request
language: bash
addons:
Expand All @@ -46,7 +47,7 @@ jobs:
- ./tests/lib/cla_check.py
- stage: integration
name: spread
os: linux
dist: xenial
addons:
apt:
packages:
Expand Down
19 changes: 2 additions & 17 deletions asserts/device_asserts.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"strings"
"time"

"github.com/snapcore/snapd/snap/naming"
"github.com/snapcore/snapd/strutil"
)

Expand Down Expand Up @@ -222,24 +223,8 @@ var (
classicModelOptional = []string{"architecture", "gadget"}
)

var almostValidName = regexp.MustCompile("^[a-z0-9-]*[a-z][a-z0-9-]*$")

// validateSnapName checks whether the name can be used as a snap name
//
// This function should be synchronized with the reference implementation
// snap.ValidateName() in snap/validate.go
func validateSnapName(name string, headerName string) error {
isValidName := func() bool {
if !almostValidName.MatchString(name) {
return false
}
if name[0] == '-' || name[len(name)-1] == '-' || strings.Contains(name, "--") {
return false
}
return true
}

if len(name) > 40 || !isValidName() {
if err := naming.ValidateSnap(name); err != nil {
return fmt.Errorf("invalid snap name in %q header: %s", headerName, name)
}
return nil
Expand Down
4 changes: 3 additions & 1 deletion asserts/device_asserts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ func (mods modelSuite) TestDecodeValidSnapNames(c *C) {
withTimestamp := strings.Replace(modelExample, "TSLINE", mods.tsLine, 1)

validNames := []string{
"a", "aa", "aaa", "aaaa",
"aa", "aaa", "aaaa",
"a-a", "aa-a", "a-aa", "a-b-c",
"a0", "a-0", "a-0a",
"01game", "1-or-2",
Expand All @@ -218,6 +218,8 @@ func (mods modelSuite) TestDecodeValidSnapNames(c *C) {
invalidNames := []string{
// name cannot be empty, never reaches snap name validation
"",
// too short (min 2 chars)
"a",
// names cannot be too long
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"xxxxxxxxxxxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxx",
Expand Down
13 changes: 4 additions & 9 deletions asserts/snap_asserts.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ import (
"bytes"
"crypto"
"fmt"
"regexp"
"time"

_ "golang.org/x/crypto/sha3" // expected for digests

"github.com/snapcore/snapd/osutil"
"github.com/snapcore/snapd/release"
"github.com/snapcore/snapd/snap/naming"
)

// SnapDeclaration holds a snap-declaration assertion, declaring a
Expand Down Expand Up @@ -195,11 +195,6 @@ func snapDeclarationFormatAnalyze(headers map[string]interface{}, body []byte) (
return formatnum, nil
}

var (
validAlias = regexp.MustCompile("^[a-zA-Z0-9][-_.a-zA-Z0-9]*$")
validAppName = regexp.MustCompile("^[a-zA-Z0-9](?:-?[a-zA-Z0-9])*$")
)

func checkAliases(headers map[string]interface{}) (map[string]string, error) {
value, ok := headers["aliases"]
if !ok {
Expand All @@ -221,13 +216,13 @@ func checkAliases(headers map[string]interface{}) (map[string]string, error) {
}

what := fmt.Sprintf(`in "aliases" item %d`, i+1)
name, err := checkStringMatchesWhat(aliasItem, "name", what, validAlias)
name, err := checkStringMatchesWhat(aliasItem, "name", what, naming.ValidAlias)
if err != nil {
return nil, err
}

what = fmt.Sprintf(`for alias %q`, name)
target, err := checkStringMatchesWhat(aliasItem, "target", what, validAppName)
target, err := checkStringMatchesWhat(aliasItem, "target", what, naming.ValidApp)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -296,7 +291,7 @@ func assembleSnapDeclaration(assert assertionBase) (Assertion, error) {
}

// XXX: depracated, will go away later
autoAliases, err := checkStringListMatches(assert.headers, "auto-aliases", validAlias)
autoAliases, err := checkStringListMatches(assert.headers, "auto-aliases", naming.ValidAlias)
if err != nil {
return nil, err
}
Expand Down
77 changes: 77 additions & 0 deletions client/connections.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// -*- Mode: Go; indent-tabs-mode: t -*-

/*
* Copyright (C) 2019 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

package client

import (
"net/url"
)

// Connection describes a connection between a plug and a slot.
type Connection struct {
Slot SlotRef `json:"slot"`
Plug PlugRef `json:"plug"`
Interface string `json:"interface"`
// Manual is set for connections that were established manually.
Manual bool `json:"manual"`
// Gadget is set for connections that were enabled by the gadget snap.
Gadget bool `json:"gadget"`
}

// Connections contains information about connections, as well as related plugs
// and slots.
type Connections struct {
// Established is the list of connections that are currently present.
Established []Connection `json:"established"`
// Undersired is a list of connections that are manually denied.
Undesired []Connection `json:"undesired"`
Plugs []Plug `json:"plugs"`
Slots []Slot `json:"slots"`
}

// ConnectionOptions contains criteria for selecting matching connections, plugs
// and slots.
type ConnectionOptions struct {
// Snap selects connections with the snap on one of the sides, as well
// as plugs and slots of a given snap.
Snap string
// Interface selects connections, plugs or slots using given interface.
Interface string
// All when true, selects established and undesired connections as well
// as all disconnected plugs and slots.
All bool
}

// Connections returns matching plugs, slots and their connections. Unless
// specified by matching options, returns established connections.
func (client *Client) Connections(opts *ConnectionOptions) (Connections, error) {
var conns Connections
query := url.Values{}
if opts != nil && opts.Snap != "" {
query.Set("snap", opts.Snap)
}
if opts != nil && opts.Interface != "" {
query.Set("interface", opts.Interface)
}
if opts != nil && opts.All {
query.Set("select", "all")
}
_, err := client.doSync("GET", "/v2/connections", query, nil, nil, &conns)
return conns, err
}
Loading

0 comments on commit bc5f521

Please sign in to comment.