diff --git a/bolt/alerts.go b/bolt/alerts.go index d67264840a..d49f4d3a19 100644 --- a/bolt/alerts.go +++ b/bolt/alerts.go @@ -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 } diff --git a/bolt/client.go b/bolt/client.go index e34a378287..ae57cc558d 100644 --- a/bolt/client.go +++ b/bolt/client.go @@ -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} @@ -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() diff --git a/bolt/dashboards.go b/bolt/dashboards.go index 4df9ebf8ea..28cf83f413 100644 --- a/bolt/dashboards.go +++ b/bolt/dashboards.go @@ -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 @@ -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 @@ -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 diff --git a/bolt/layouts.go b/bolt/layouts.go index bd6ce4a8c6..e443f80b16 100644 --- a/bolt/layouts.go +++ b/bolt/layouts.go @@ -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 diff --git a/bolt/servers.go b/bolt/servers.go index d9a4ebccbf..63bd7c801f 100644 --- a/bolt/servers.go +++ b/bolt/servers.go @@ -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 } diff --git a/bolt/sources.go b/bolt/sources.go index 46ced92b85..a2809ff23d 100644 --- a/bolt/sources.go +++ b/bolt/sources.go @@ -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 } diff --git a/canned/apps.go b/canned/apps.go index 1fd8440d3f..8ad626e8dc 100644 --- a/canned/apps.go +++ b/canned/apps.go @@ -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. @@ -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, @@ -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 { @@ -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() @@ -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 { @@ -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 { @@ -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 { diff --git a/canned/bin.go b/canned/bin.go index 2c32e9e043..1b5fd4399f 100644 --- a/canned/bin.go +++ b/canned/bin.go @@ -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 } diff --git a/dist/dir.go b/dist/dir.go index 828ef231da..1f4ac90b93 100644 --- a/dist/dir.go +++ b/dist/dir.go @@ -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, diff --git a/enterprise/enterprise.go b/enterprise/enterprise.go index 3a39993492..bc7e3af731 100644 --- a/enterprise/enterprise.go +++ b/enterprise/enterprise.go @@ -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", diff --git a/enterprise/meta_test.go b/enterprise/meta_test.go index 2823c1256d..32d05bdeae 100644 --- a/enterprise/meta_test.go +++ b/enterprise/meta_test.go @@ -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, @@ -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{ diff --git a/kapacitor/http_out.go b/kapacitor/http_out.go index 848e44a970..45bb0b36e3 100644 --- a/kapacitor/http_out.go +++ b/kapacitor/http_out.go @@ -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 } diff --git a/kapacitor/operators.go b/kapacitor/operators.go index 745789fa6d..869c6ec232 100644 --- a/kapacitor/operators.go +++ b/kapacitor/operators.go @@ -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" @@ -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 diff --git a/kapacitor/validate.go b/kapacitor/validate.go index ed8dca32a7..4a81a9d0e5 100644 --- a/kapacitor/validate.go +++ b/kapacitor/validate.go @@ -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 diff --git a/kapacitor/vars.go b/kapacitor/vars.go index 081f349fb7..038834b463 100644 --- a/kapacitor/vars.go +++ b/kapacitor/vars.go @@ -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 diff --git a/log/log.go b/log/log.go index 2cfbb25133..2eb6b3ae99 100644 --- a/log/log.go +++ b/log/log.go @@ -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, diff --git a/oauth2/doc.go b/oauth2/doc.go index db132a6caa..7fed8f3b61 100644 --- a/oauth2/doc.go +++ b/oauth2/doc.go @@ -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: diff --git a/oauth2/google.go b/oauth2/google.go index fb082ace6c..ee5ff3bb13 100644 --- a/oauth2/google.go +++ b/oauth2/google.go @@ -10,7 +10,7 @@ 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", @@ -18,6 +18,7 @@ var GoogleEndpoint = oauth2.Endpoint{ } var _ Provider = &Google{} +// Google is an oauth2 provider supporting google. type Google struct { ClientID string ClientSecret string diff --git a/oauth2/heroku.go b/oauth2/heroku.go index 637c57adf1..831b095df1 100644 --- a/oauth2/heroku.go +++ b/oauth2/heroku.go @@ -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 @@ -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) @@ -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 diff --git a/oauth2/mux.go b/oauth2/mux.go index dc45a15256..9ecc11dba6 100644 --- a/oauth2/mux.go +++ b/oauth2/mux.go @@ -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, @@ -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 { diff --git a/oauth2/oauth2_test.go b/oauth2/oauth2_test.go index 60c34e1eb6..ed63794141 100644 --- a/oauth2/oauth2_test.go +++ b/oauth2/oauth2_test.go @@ -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", }, } } diff --git a/server/server.go b/server/server.go index f9a12cd971..738f0d9061 100644 --- a/server/server.go +++ b/server/server.go @@ -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 != "" } diff --git a/server/url_prefixer.go b/server/url_prefixer.go index d20563fc15..6cbed57cb2 100644 --- a/server/url_prefixer.go +++ b/server/url_prefixer.go @@ -62,7 +62,8 @@ func (wrw *wrapResponseWriter) Header() http.Header { return *wrw.dupHeader } -const CHUNK_SIZE int = 512 +// ChunkSize is the number of bytes per chunked transfer-encoding +const ChunkSize int = 512 // ServeHTTP implements an http.Handler that prefixes relative URLs from the // Next handler with the configured prefix. It does this by examining the @@ -109,7 +110,7 @@ func (up *URLPrefixer) ServeHTTP(rw http.ResponseWriter, r *http.Request) { writtenCount++ buf.Write(src.Bytes()) - if writtenCount >= CHUNK_SIZE { + if writtenCount >= ChunkSize { flusher.Flush() writtenCount = 0 } diff --git a/server/version.go b/server/version.go index 6bf7dbe9da..e7fc4c9013 100644 --- a/server/version.go +++ b/server/version.go @@ -4,6 +4,7 @@ import ( "net/http" ) +// Version handler adds X-Chronograf-Version header to responses func Version(version string, h http.Handler) http.Handler { fn := func(w http.ResponseWriter, r *http.Request) { w.Header().Add("X-Chronograf-Version", version)