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

Commit

Permalink
Fixes #900: Removes '0' from the list of valid ports the REST API can…
Browse files Browse the repository at this point in the history
… be started on; also refactors how command-line flags are set and prints valid defaults where applicable
  • Loading branch information
Tom McSweeney committed Jun 7, 2016
1 parent 4b8ee45 commit 4f7afa7
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 72 deletions.
56 changes: 56 additions & 0 deletions control/flags.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
http://www.apache.org/licenses/LICENSE-2.0.txt
Copyright 2015 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package control

import "github.com/codegangsta/cli"

var (
flNumberOfPLs = cli.IntFlag{
Name: "max-running-plugins, m",
Value: defaultMaxRunningPlugins,
Usage: "The maximum number of instances of a loaded plugin to run",
EnvVar: "SNAP_MAX_PLUGINS",
}
flPluginTrust = cli.IntFlag{
Name: "plugin-trust, t",
Usage: "0-2 (Disabled, Enabled, Warning)",
Value: defaultPluginTrust,
EnvVar: "SNAP_TRUST_LEVEL",
}
flAutoDiscover = cli.StringFlag{
Name: "auto-discover, a",
Usage: "Auto discover paths separated by colons.",
EnvVar: "SNAP_AUTODISCOVER_PATH",
}
flKeyringPaths = cli.StringFlag{
Name: "keyring-paths, k",
Usage: "Keyring paths for signing verification separated by colons",
EnvVar: "SNAP_KEYRING_PATHS",
}
flCache = cli.DurationFlag{
Name: "cache-expiration",
Usage: "The time limit for which a metric cache entry is valid",
Value: defaultCacheExpiration,
EnvVar: "SNAP_CACHE_EXPIRATION",
}

// Flags consumed by snapd
Flags = []cli.Flag{flNumberOfPLs, flPluginTrust, flAutoDiscover, flKeyringPaths, flCache}
)
63 changes: 63 additions & 0 deletions mgmt/rest/flags.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
http://www.apache.org/licenses/LICENSE-2.0.txt
Copyright 2015 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package rest

import (
"fmt"

"github.com/codegangsta/cli"
)

var (
flAPIDisabled = cli.BoolFlag{
Name: "disable-api, d",
Usage: "Disable the agent REST API",
}
flAPIAddr = cli.StringFlag{
Name: "api-addr, b",
Usage: "API Address[:port] to bind to/listen on. Default: empty string => listen on all interfaces",
EnvVar: "SNAP_ADDR",
}
flAPIPort = cli.IntFlag{
Name: "api-port, p",
Usage: fmt.Sprintf("API port (Default: %d)", defaultPort),
Value: defaultPort,
EnvVar: "SNAP_PORT",
}
flRestHTTPS = cli.BoolFlag{
Name: "rest-https",
Usage: "start snap's API as https",
}
flRestCert = cli.StringFlag{
Name: "rest-cert",
Usage: "A path to a certificate to use for HTTPS deployment of snap's REST API",
}
flRestKey = cli.StringFlag{
Name: "rest-key",
Usage: "A path to a key file to use for HTTPS deployment of snap's REST API",
}
flRestAuth = cli.BoolFlag{
Name: "rest-auth",
Usage: "Enables snap's REST API authentication",
}

// Flags consumed by snapd
Flags = []cli.Flag{flAPIDisabled, flAPIAddr, flAPIPort, flRestHTTPS, flRestCert, flRestKey, flRestAuth}
)
2 changes: 1 addition & 1 deletion mgmt/rest/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ const (
},
"port" : {
"type": "integer",
"minimum": 0,
"minimum": 1,
"maximum": 65535
},
"addr" : {
Expand Down
1 change: 1 addition & 0 deletions mgmt/tribe/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ var (
flTribeAdvertisePort = cli.IntFlag{
Name: "tribe-port",
Usage: "Port tribe gossips over to maintain membership",
Value: defaultBindPort,
EnvVar: "SNAP_TRIBE_PORT",
}

Expand Down
12 changes: 9 additions & 3 deletions scheduler/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,24 @@ limitations under the License.

package scheduler

import "github.com/codegangsta/cli"
import (
"fmt"

"github.com/codegangsta/cli"
)

var (
flSchedulerQueueSize = cli.IntFlag{
Name: "work-manager-queue-size",
Usage: "Size of the work manager queue (default: 25)",
Usage: fmt.Sprintf("Size of the work manager queue (default: %d)", defaultWorkManagerQueueSize),
Value: int(defaultWorkManagerQueueSize),
EnvVar: "WORK_MANAGER_QUEUE_SIZE",
}

flSchedulerPoolSize = cli.IntFlag{
Name: "work-manager-pool-size",
Usage: "Size of the work manager pool (default 4)",
Usage: fmt.Sprintf("Size of the work manager pool (default %d)", defaultWorkManagerPoolSize),
Value: int(defaultWorkManagerPoolSize),
EnvVar: "WORK_MANAGER_POOL_SIZE",
}

Expand Down
73 changes: 5 additions & 68 deletions snapd.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,30 +48,12 @@ import (
)

var (
flAPIDisabled = cli.BoolFlag{
Name: "disable-api, d",
Usage: "Disable the agent REST API",
}
flAPIPort = cli.IntFlag{
Name: "api-port, p",
Usage: "API port (Default: 8181)",
EnvVar: "SNAP_PORT",
}
flAPIAddr = cli.StringFlag{
Name: "api-addr, b",
Usage: "API Address[:port] to bind to/listen on. Default: empty string => listen on all interfaces",
EnvVar: "SNAP_ADDR",
}
flMaxProcs = cli.IntFlag{
Name: "max-procs, c",
Usage: "Set max cores to use for snap Agent. Default is 1 core.",
Usage: fmt.Sprintf("Set max cores to use for snap Agent. Default is %d core.", defaultGoMaxProcs),
Value: defaultGoMaxProcs,
EnvVar: "GOMAXPROCS",
}
flNumberOfPLs = cli.IntFlag{
Name: "max-running-plugins, m",
Usage: "The maximum number of instances of a loaded plugin to run",
EnvVar: "SNAP_MAX_PLUGINS",
}
// plugin
flLogPath = cli.StringFlag{
Name: "log-path, o",
Expand All @@ -81,49 +63,14 @@ var (
flLogLevel = cli.IntFlag{
Name: "log-level, l",
Usage: "1-5 (Debug, Info, Warning, Error, Fatal)",
Value: defaultLogLevel,
EnvVar: "SNAP_LOG_LEVEL",
}
flAutoDiscover = cli.StringFlag{
Name: "auto-discover, a",
Usage: "Auto discover paths separated by colons.",
EnvVar: "SNAP_AUTODISCOVER_PATH",
}
flPluginTrust = cli.IntFlag{
Name: "plugin-trust, t",
Usage: "0-2 (Disabled, Enabled, Warning)",
EnvVar: "SNAP_TRUST_LEVEL",
}
flKeyringPaths = cli.StringFlag{
Name: "keyring-paths, k",
Usage: "Keyring paths for signing verification separated by colons",
EnvVar: "SNAP_KEYRING_PATHS",
}
flCache = cli.DurationFlag{
Name: "cache-expiration",
Usage: "The time limit for which a metric cache entry is valid",
EnvVar: "SNAP_CACHE_EXPIRATION",
}
flConfig = cli.StringFlag{
Name: "config",
Usage: "A path to a config file",
EnvVar: "SNAP_CONFIG_PATH",
}
flRestHTTPS = cli.BoolFlag{
Name: "rest-https",
Usage: "start snap's API as https",
}
flRestCert = cli.StringFlag{
Name: "rest-cert",
Usage: "A path to a certificate to use for HTTPS deployment of snap's REST API",
}
flRestKey = cli.StringFlag{
Name: "rest-key",
Usage: "A path to a key file to use for HTTPS deployment of snap's REST API",
}
flRestAuth = cli.BoolFlag{
Name: "rest-auth",
Usage: "Enables snap's REST API authentication",
}

gitversion string
coreModules []coreModule
Expand Down Expand Up @@ -230,24 +177,14 @@ func main() {
app.Version = gitversion
app.Usage = "A powerful telemetry framework"
app.Flags = []cli.Flag{
flAPIDisabled,
flAPIPort,
flAPIAddr,
flLogLevel,
flLogPath,
flMaxProcs,
flAutoDiscover,
flNumberOfPLs,
flCache,
flPluginTrust,
flKeyringPaths,
flRestCert,
flConfig,
flRestHTTPS,
flRestKey,
flRestAuth,
}
app.Flags = append(app.Flags, scheduler.Flags...)
app.Flags = append(app.Flags, control.Flags...)
app.Flags = append(app.Flags, rest.Flags...)
app.Flags = append(app.Flags, tribe.Flags...)

app.Action = action
Expand Down

0 comments on commit 4f7afa7

Please sign in to comment.