Skip to content

Commit

Permalink
Update to fix go linter issues
Browse files Browse the repository at this point in the history
  • Loading branch information
goller committed Mar 6, 2017
1 parent 4abcb91 commit 8dc012a
Show file tree
Hide file tree
Showing 24 changed files with 70 additions and 37 deletions.
2 changes: 2 additions & 0 deletions bolt/alerts.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ import (
// Ensure AlertsStore implements chronograf.AlertsStore.
var _ chronograf.AlertRulesStore = &AlertsStore{}

// AlertsBucket is the name of the bucket alert configuration is stored in
var AlertsBucket = []byte("Alerts")

// AlertsStore represents the bolt implementation of a store for alerts
type AlertsStore struct {
client *Client
}
Expand Down
2 changes: 2 additions & 0 deletions bolt/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type Client struct {
DashboardsStore *DashboardsStore
}

// NewClient initializes all stores
func NewClient() *Client {
c := &Client{Now: time.Now}
c.SourcesStore = &SourcesStore{client: c}
Expand Down Expand Up @@ -79,6 +80,7 @@ func (c *Client) Open() error {
return nil
}

// Close the connection to the bolt database
func (c *Client) Close() error {
if c.db != nil {
return c.db.Close()
Expand Down
16 changes: 9 additions & 7 deletions bolt/dashboards.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ import (
// Ensure DashboardsStore implements chronograf.DashboardsStore.
var _ chronograf.DashboardsStore = &DashboardsStore{}

// DashboardBucket is the bolt bucket dashboards are stored in
var DashboardBucket = []byte("Dashoard")

// DashboardsStore is the bolt implementation of storing dashboards
type DashboardsStore struct {
client *Client
IDs chronograf.DashboardID
Expand Down Expand Up @@ -81,9 +83,9 @@ func (d *DashboardsStore) Get(ctx context.Context, id chronograf.DashboardID) (c
}

// Delete the dashboard from DashboardsStore
func (s *DashboardsStore) Delete(ctx context.Context, d chronograf.Dashboard) error {
if err := s.client.db.Update(func(tx *bolt.Tx) error {
if err := tx.Bucket(DashboardBucket).Delete(itob(int(d.ID))); err != nil {
func (d *DashboardsStore) Delete(ctx context.Context, dash chronograf.Dashboard) error {
if err := d.client.db.Update(func(tx *bolt.Tx) error {
if err := tx.Bucket(DashboardBucket).Delete(itob(int(dash.ID))); err != nil {
return err
}
return nil
Expand All @@ -95,16 +97,16 @@ func (s *DashboardsStore) Delete(ctx context.Context, d chronograf.Dashboard) er
}

// Update the dashboard in DashboardsStore
func (s *DashboardsStore) Update(ctx context.Context, d chronograf.Dashboard) error {
if err := s.client.db.Update(func(tx *bolt.Tx) error {
func (d *DashboardsStore) Update(ctx context.Context, dash chronograf.Dashboard) error {
if err := d.client.db.Update(func(tx *bolt.Tx) error {
// Get an existing dashboard with the same ID.
b := tx.Bucket(DashboardBucket)
strID := strconv.Itoa(int(d.ID))
strID := strconv.Itoa(int(dash.ID))
if v := b.Get([]byte(strID)); v == nil {
return chronograf.ErrDashboardNotFound
}

if v, err := internal.MarshalDashboard(d); err != nil {
if v, err := internal.MarshalDashboard(dash); err != nil {
return err
} else if err := b.Put([]byte(strID), v); err != nil {
return err
Expand Down
2 changes: 2 additions & 0 deletions bolt/layouts.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ import (
// Ensure LayoutStore implements chronograf.LayoutStore.
var _ chronograf.LayoutStore = &LayoutStore{}

// LayoutBucket is the bolt bucket layouts are stored in
var LayoutBucket = []byte("Layout")

// LayoutStore is the bolt implementation to store layouts
type LayoutStore struct {
client *Client
IDs chronograf.ID
Expand Down
3 changes: 3 additions & 0 deletions bolt/servers.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ import (
// Ensure ServersStore implements chronograf.ServersStore.
var _ chronograf.ServersStore = &ServersStore{}

// ServersBucket is the bolt bucket to store lists of servers
var ServersBucket = []byte("Servers")

// ServersStore is the bolt implementation to store servers in a store.
// Used store servers that are associated in some way with a source
type ServersStore struct {
client *Client
}
Expand Down
2 changes: 2 additions & 0 deletions bolt/sources.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ import (
// Ensure SourcesStore implements chronograf.SourcesStore.
var _ chronograf.SourcesStore = &SourcesStore{}

// SourcesBucket is the bolt bucket used to store source information
var SourcesBucket = []byte("Sources")

// SourcesStore is a bolt implementation to store time-series source information.
type SourcesStore struct {
client *Client
}
Expand Down
14 changes: 10 additions & 4 deletions canned/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/influxdata/chronograf"
)

// AppExt is the the file extension searched for in the directory for layout files
const AppExt = ".json"

// Apps are canned JSON layouts. Implements LayoutStore.
Expand All @@ -25,6 +26,7 @@ type Apps struct {
Logger chronograf.Logger
}

// NewApps constructs a layout store wrapping a file system directory
func NewApps(dir string, ids chronograf.ID, logger chronograf.Logger) chronograf.LayoutStore {
return &Apps{
Dir: dir,
Expand Down Expand Up @@ -63,14 +65,14 @@ func createLayout(file string, layout chronograf.Layout) error {
defer h.Close()
if octets, err := json.MarshalIndent(layout, " ", " "); err != nil {
return chronograf.ErrLayoutInvalid
} else {
if _, err := h.Write(octets); err != nil {
return err
}
} else if _, err := h.Write(octets); err != nil {
return err
}

return nil
}

// All returns all layouts from the directory
func (a *Apps) All(ctx context.Context) ([]chronograf.Layout, error) {
files, err := a.ReadDir(a.Dir)
if err != nil {
Expand All @@ -91,6 +93,7 @@ func (a *Apps) All(ctx context.Context) ([]chronograf.Layout, error) {
return layouts, nil
}

// Add creates a new layout within the directory
func (a *Apps) Add(ctx context.Context, layout chronograf.Layout) (chronograf.Layout, error) {
var err error
layout.ID, err = a.IDs.Generate()
Expand Down Expand Up @@ -118,6 +121,7 @@ func (a *Apps) Add(ctx context.Context, layout chronograf.Layout) (chronograf.La
return layout, nil
}

// Delete removes a layout file from the directory
func (a *Apps) Delete(ctx context.Context, layout chronograf.Layout) error {
_, file, err := a.idToFile(layout.ID)
if err != nil {
Expand All @@ -134,6 +138,7 @@ func (a *Apps) Delete(ctx context.Context, layout chronograf.Layout) error {
return nil
}

// Get returns an app file from the layout directory
func (a *Apps) Get(ctx context.Context, ID string) (chronograf.Layout, error) {
l, file, err := a.idToFile(ID)
if err != nil {
Expand All @@ -157,6 +162,7 @@ func (a *Apps) Get(ctx context.Context, ID string) (chronograf.Layout, error) {
return l, nil
}

// Update replaces a layout from the file system directory
func (a *Apps) Update(ctx context.Context, layout chronograf.Layout) error {
l, _, err := a.idToFile(layout.ID)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions canned/bin.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

//go:generate go-bindata -o bin_gen.go -ignore README|apps|.sh|go -pkg canned .

// BinLayoutStore represents a layout store using data generated by go-bindata
type BinLayoutStore struct {
Logger chronograf.Logger
}
Expand Down
1 change: 1 addition & 0 deletions dist/dir.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type Dir struct {
dir http.Dir
}

// NewDir constructs a Dir with a default file
func NewDir(dir, def string) Dir {
return Dir{
Default: def,
Expand Down
2 changes: 1 addition & 1 deletion enterprise/enterprise.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func (c *Client) Roles(ctx context.Context) (chronograf.RolesStore, error) {
return c.RolesStore, nil
}

// Allowances returns all Influx Enterprise permission strings
// Permissions returns all Influx Enterprise permission strings
func (c *Client) Permissions(context.Context) chronograf.Permissions {
all := chronograf.Allowances{
"NoPermissions",
Expand Down
4 changes: 2 additions & 2 deletions enterprise/meta_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func TestMetaClient_ShowCluster(t *testing.T) {
http.StatusBadGateway,
nil,
nil,
fmt.Errorf("Time circuits on. Flux Capacitor... fluxxing."),
fmt.Errorf("time circuits on. Flux Capacitor... fluxxing"),
),
},
wantErr: true,
Expand Down Expand Up @@ -214,7 +214,7 @@ func TestMetaClient_Users(t *testing.T) {
http.StatusOK,
[]byte(`{"users":[{"name":"admin","hash":"1234","permissions":{"":["ViewAdmin","ViewChronograf"]}}]}`),
nil,
fmt.Errorf("Time circuits on. Flux Capacitor... fluxxing."),
fmt.Errorf("time circuits on. Flux Capacitor... fluxxing"),
),
},
args: args{
Expand Down
2 changes: 2 additions & 0 deletions kapacitor/http_out.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import (
"github.com/influxdata/chronograf"
)

// HTTPEndpoint is the default location of the tickscript output
const HTTPEndpoint = "output"

// HTTPOut adds a kapacitor httpOutput to a tickscript
func HTTPOut(rule chronograf.AlertRule) (string, error) {
return fmt.Sprintf(`trigger|httpOut('%s')`, HTTPEndpoint), nil
}
8 changes: 4 additions & 4 deletions kapacitor/operators.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package kapacitor
import "fmt"

const (
GreaterThan = "greater than"
LessThan = "less than"
greaterThan = "greater than"
lessThan = "less than"
LessThanEqual = "equal to or less than"
GreaterThanEqual = "equal to or greater"
Equal = "equal to"
Expand All @@ -16,9 +16,9 @@ const (
// kapaOperator converts UI strings to kapacitor operators
func kapaOperator(operator string) (string, error) {
switch operator {
case GreaterThan:
case greaterThan:
return ">", nil
case LessThan:
case lessThan:
return "<", nil
case LessThanEqual:
return "<=", nil
Expand Down
3 changes: 3 additions & 0 deletions kapacitor/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ func validateTick(script chronograf.TICKScript) error {
return err
}

// deadman is an empty implementation of a kapacitor DeadmanService to allow CreatePipeline
var _ pipeline.DeadmanService = &deadman{}

type deadman struct {
interval time.Duration
threshold float64
Expand Down
13 changes: 6 additions & 7 deletions kapacitor/vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,16 @@ func Vars(rule chronograf.AlertRule) (string, error) {
var crit = %s
`
return fmt.Sprintf(vars, common, formatValue(rule.TriggerValues.Value)), nil
} else {
vars := `
}
vars := `
%s
var lower = %s
var upper = %s
`
return fmt.Sprintf(vars,
common,
rule.TriggerValues.Value,
rule.TriggerValues.RangeValue), nil
}
return fmt.Sprintf(vars,
common,
rule.TriggerValues.Value,
rule.TriggerValues.RangeValue), nil
case Relative:
vars := `
%s
Expand Down
1 change: 1 addition & 0 deletions log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ func (ll *logrusLogger) WithField(key string, value interface{}) chronograf.Logg
return &logrusLogger{ll.l.WithField(key, value)}
}

// New wraps a logrus Logger
func New(l Level) chronograf.Logger {
logger := &logrus.Logger{
Out: os.Stderr,
Expand Down
2 changes: 1 addition & 1 deletion oauth2/doc.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// The oauth2 package provides http.Handlers necessary for implementing Oauth2
// Package oauth2 provides http.Handlers necessary for implementing Oauth2
// authentication with multiple Providers.
//
// This is how the pieces of this package fit together:
Expand Down
3 changes: 2 additions & 1 deletion oauth2/google.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ import (
goauth2 "google.golang.org/api/oauth2/v2"
)

// Endpoint is Google's OAuth 2.0 endpoint.
// GoogleEndpoint is Google's OAuth 2.0 endpoint.
// Copied here to remove tons of package dependencies
var GoogleEndpoint = oauth2.Endpoint{
AuthURL: "https://accounts.google.com/o/oauth2/auth",
TokenURL: "https://accounts.google.com/o/oauth2/token",
}
var _ Provider = &Google{}

// Google is an oauth2 provider supporting google.
type Google struct {
ClientID string
ClientSecret string
Expand Down
10 changes: 5 additions & 5 deletions oauth2/heroku.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (
var _ Provider = &Heroku{}

const (
// Routes required for interacting with Heroku API
HEROKU_ACCOUNT_ROUTE string = "https://api.heroku.com/account"
// HerokuAccountRoute is required for interacting with Heroku API
HerokuAccountRoute string = "https://api.heroku.com/account"
)

// Heroku is an OAuth2 Provider allowing users to authenticate with Heroku to
Expand Down Expand Up @@ -61,13 +61,14 @@ func (h *Heroku) PrincipalID(provider *http.Client) (string, error) {
DefaultOrganization DefaultOrg `json:"default_organization"`
}

resp, err := provider.Get(HEROKU_ACCOUNT_ROUTE)
resp, err := provider.Get(HerokuAccountRoute)
if err != nil {
h.Logger.Error("Unable to communicate with Heroku. err:", err)
return "", err
}
defer resp.Body.Close()
d := json.NewDecoder(resp.Body)

var account Account
if err := d.Decode(&account); err != nil {
h.Logger.Error("Unable to decode response from Heroku. err:", err)
Expand All @@ -83,9 +84,8 @@ func (h *Heroku) PrincipalID(provider *http.Client) (string, error) {
}
h.Logger.Error(ErrOrgMembership)
return "", ErrOrgMembership
} else {
return account.Email, nil
}
return account.Email, nil
}

// Scopes for heroku is "identity" which grants access to user account
Expand Down
3 changes: 2 additions & 1 deletion oauth2/mux.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type cookie struct {
// Check to ensure CookieMux is an oauth2.Mux
var _ Mux = &CookieMux{}

// NewCookieMux constructs a Mux handler that checks a cookie against the authenticator
func NewCookieMux(p Provider, a Authenticator, l chronograf.Logger) *CookieMux {
return &CookieMux{
Provider: p,
Expand Down Expand Up @@ -55,7 +56,7 @@ type CookieMux struct {
Now func() time.Time // Now returns the current time
}

// Uses a Cookie with a random string as the state validation method. JWTs are
// Login uses a Cookie with a random string as the state validation method. JWTs are
// a good choice here for encoding because they can be validated without
// storing state.
func (j *CookieMux) Login() http.Handler {
Expand Down
4 changes: 2 additions & 2 deletions oauth2/oauth2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ func (mp *MockProvider) Config() *goauth.Config {
ClientID: "4815162342",
ClientSecret: "8675309",
Endpoint: goauth.Endpoint{
mp.ProviderURL + "/oauth/auth",
mp.ProviderURL + "/oauth/token",
AuthURL: mp.ProviderURL + "/oauth/auth",
TokenURL: mp.ProviderURL + "/oauth/token",
},
}
}
Expand Down
3 changes: 3 additions & 0 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,17 @@ func provide(p oauth2.Provider, m oauth2.Mux, ok func() bool) func(func(oauth2.P
}
}

// UseGithub validates the CLI parameters to enable github oauth support
func (s *Server) UseGithub() bool {
return s.TokenSecret != "" && s.GithubClientID != "" && s.GithubClientSecret != ""
}

// UseGoogle validates the CLI parameters to enable google oauth support
func (s *Server) UseGoogle() bool {
return s.TokenSecret != "" && s.GoogleClientID != "" && s.GoogleClientSecret != "" && s.PublicURL != ""
}

// UseHeroku validates the CLI parameters to enable heroku oauth support
func (s *Server) UseHeroku() bool {
return s.TokenSecret != "" && s.HerokuClientID != "" && s.HerokuSecret != ""
}
Expand Down
Loading

0 comments on commit 8dc012a

Please sign in to comment.