Skip to content

Commit

Permalink
Various idiomatic fixes throughout the repo
Browse files Browse the repository at this point in the history
Contains:
    * Comment fixes
    * Variable renaming
    * Grouping of imports into logical groups (stdlib, 3rd party, openshift)
    * makes golint a bit happier overall
  • Loading branch information
0xmichalis committed Feb 9, 2015
1 parent 7d5852a commit 357dc2e
Show file tree
Hide file tree
Showing 56 changed files with 105 additions and 108 deletions.
2 changes: 1 addition & 1 deletion pkg/assets/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (w *gzipResponseWriter) Write(b []byte) (int, error) {
return w.Writer.Write(b)
}

// Wrap a http.Handler to support transparent gzip encoding.
// GzipHandler wraps a http.Handler to support transparent gzip encoding.
func GzipHandler(h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Add("Vary", "Accept-Encoding")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ type basicPasswordAuthHandler struct {
realm string
}

// NewBasicPasswordAuthHandler returns a ChallengeAuthHandler that responds with a basic auth challenge for the supplied realm
// NewBasicAuthChallenger returns a AuthenticationChallenger that responds with a basic auth challenge for the supplied realm
func NewBasicAuthChallenger(realm string) oauthhandlers.AuthenticationChallenger {
return &basicPasswordAuthHandler{realm}
}

// AuthenticationChallengeNeeded returns a header that indicates a basic auth challenge for the supplied realm
// AuthenticationChallenge returns a header that indicates a basic auth challenge for the supplied realm
func (h *basicPasswordAuthHandler) AuthenticationChallenge(req *http.Request) (http.Header, error) {
headers := http.Header{}
headers.Add("WWW-Authenticate", "Basic realm=\""+h.realm+"\"")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func New(identityMapper authapi.UserIdentityMapper) authenticator.Password {
return &alwaysAcceptPasswordAuthenticator{identityMapper}
}

// alwaysAcceptPasswordAuthenticator.AuthenticatePassword approves any login attempt with non-blank username and password
// AuthenticatePassword approves any login attempt with non-blank username and password
func (a alwaysAcceptPasswordAuthenticator) AuthenticatePassword(username, password string) (authapi.UserInfo, bool, error) {
if username == "" || password == "" {
return nil, false, nil
Expand Down
9 changes: 6 additions & 3 deletions pkg/auth/oauth/external/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func NewExternalOAuthRedirector(provider Provider, state State, redirectURL stri
}, nil
}

// Implements oauth.handlers.RedirectAuthHandler
// AuthenticationRedirect implements oauth.handlers.RedirectAuthHandler
func (h *Handler) AuthenticationRedirect(w http.ResponseWriter, req *http.Request) error {
glog.V(4).Infof("Authentication needed for %v", h)

Expand All @@ -70,7 +70,7 @@ func (h *Handler) AuthenticationRedirect(w http.ResponseWriter, req *http.Reques
return nil
}

// Handles the callback request in response to an external oauth flow
// ServeHTTP handles the callback request in response to an external oauth flow
func (h *Handler) ServeHTTP(w http.ResponseWriter, req *http.Request) {

// Extract auth code
Expand Down Expand Up @@ -135,19 +135,21 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
}
}

// Provides default state-building, validation, and parsing to contain CSRF and "then" redirection
// defaultState provides default state-building, validation, and parsing to contain CSRF and "then" redirection
type defaultState struct{}

func DefaultState() State {
return defaultState{}
}

func (defaultState) Generate(w http.ResponseWriter, req *http.Request) (string, error) {
state := url.Values{
"csrf": {"..."}, // TODO: get csrf
"then": {req.URL.String()},
}
return state.Encode(), nil
}

func (defaultState) Check(state string, w http.ResponseWriter, req *http.Request) (bool, error) {
values, err := url.ParseQuery(state)
if err != nil {
Expand All @@ -165,6 +167,7 @@ func (defaultState) Check(state string, w http.ResponseWriter, req *http.Request

return true, nil
}

func (defaultState) AuthenticationSucceeded(user api.UserInfo, state string, w http.ResponseWriter, req *http.Request) (bool, error) {
values, err := url.ParseQuery(state)
if err != nil {
Expand Down
5 changes: 1 addition & 4 deletions pkg/auth/oauth/external/interfaces.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
/*
Package external implements an OAuth flow with an external identity provider
*/

// Package external implements an OAuth flow with an external identity provider
package external

import (
Expand Down
2 changes: 1 addition & 1 deletion pkg/auth/oauth/handlers/authenticator.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func (h *AccessAuthenticator) HandleAccess(ar *osin.AccessRequest, w http.Respon
return nil
}

// NewDenyAuthenticator returns an Authenticator which rejects all non-token access requests
// NewDenyAccessAuthenticator returns an AccessAuthenticator which rejects all non-token access requests
func NewDenyAccessAuthenticator() *AccessAuthenticator {
return &AccessAuthenticator{Deny, Deny, Deny}
}
Expand Down
6 changes: 6 additions & 0 deletions pkg/auth/oauth/handlers/default_auth_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,18 @@ type testClient struct {
func (w *testClient) GetId() string {
return w.client.Name
}

func (w *testClient) GetSecret() string {
return w.client.Secret
}

func (w *testClient) GetRedirectUri() string {
if len(w.client.RedirectURIs) == 0 {
return ""
}
return strings.Join(w.client.RedirectURIs, ",")
}

func (w *testClient) GetUserData() interface{} {
return w.client
}
Expand Down Expand Up @@ -167,15 +170,18 @@ type badTestClient struct {
func (w *badTestClient) GetId() string {
return w.client.Name
}

func (w *badTestClient) GetSecret() string {
return w.client.Secret
}

func (w *badTestClient) GetRedirectUri() string {
if len(w.client.RedirectURIs) == 0 {
return ""
}
return strings.Join(w.client.RedirectURIs, ",")
}

func (w *badTestClient) GetUserData() interface{} {
return "w.client"
}
2 changes: 1 addition & 1 deletion pkg/auth/server/login/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package login

import "net/http"

// mux is an object that can register http handlers.
// Mux is an object that can register http handlers.
type Mux interface {
Handle(pattern string, handler http.Handler)
HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request))
Expand Down
2 changes: 1 addition & 1 deletion pkg/auth/server/tokenrequest/endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (endpoints *endpointDetails) Install(mux login.Mux, paths ...string) {
}
}

// this works for getting a token in your browser and seeing what your token is
// requestToken works for getting a token in your browser and seeing what your token is
func (endpoints *endpointDetails) requestToken(w http.ResponseWriter, req *http.Request) {
authReq := endpoints.originOAuthClient.NewAuthorizeRequest(osincli.CODE)
oauthURL := authReq.GetAuthorizeUrlWithParams("")
Expand Down
15 changes: 7 additions & 8 deletions pkg/auth/userregistry/identitymapper/identitymapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@ package identitymapper
import (
authapi "github.com/openshift/origin/pkg/auth/api"
userapi "github.com/openshift/origin/pkg/user/api"
"github.com/openshift/origin/pkg/user/registry/useridentitymapping"
uimap "github.com/openshift/origin/pkg/user/registry/useridentitymapping"
)

type alwaysCreateUserIdentityToUserMapper struct {
providerID string
userIdentityRegistry useridentitymapping.Registry
userIdentityRegistry uimap.Registry
}

// NewAlwaysCreateProvisioner always does a createOrUpdate for the passed identity while forcing the identity.Provider to the providerID supplied here
func NewAlwaysCreateUserIdentityToUserMapper(providerID string, userIdentityRegistry useridentitymapping.Registry) authapi.UserIdentityMapper {
// NewAlwaysCreateUserIdentityToUserMapper always does a createOrUpdate for the passed identity
func NewAlwaysCreateUserIdentityToUserMapper(providerID string, userIdentityRegistry uimap.Registry) authapi.UserIdentityMapper {
return &alwaysCreateUserIdentityToUserMapper{providerID, userIdentityRegistry}
}

// ProvisionUser implements UserIdentityMapper.UserFor
// UserFor returns info about the user for whom identity info have been provided
func (p *alwaysCreateUserIdentityToUserMapper) UserFor(identityInfo authapi.UserIdentityInfo) (authapi.UserInfo, error) {
userIdentityMapping := &userapi.UserIdentityMapping{
Identity: userapi.Identity{
Expand All @@ -30,10 +30,9 @@ func (p *alwaysCreateUserIdentityToUserMapper) UserFor(identityInfo authapi.User
return nil, err
}

ret := &authapi.DefaultUserInfo{
return &authapi.DefaultUserInfo{
Name: authoritativeMapping.User.Name,
UID: string(authoritativeMapping.User.UID),
Extra: authoritativeMapping.Identity.Extra,
}
return ret, err
}, nil
}
3 changes: 1 addition & 2 deletions pkg/authorization/authorizer/authorizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (a *openshiftAuthorizer) getPolicy(namespace string) (*authorizationapi.Pol
return policy, nil
}

// getPolicy provides a point for easy caching
// getPolicyBindings provides a point for easy caching
func (a *openshiftAuthorizer) getPolicyBindings(namespace string) ([]authorizationapi.PolicyBinding, error) {
ctx := kapi.WithNamespace(kapi.NewContext(), namespace)
policyBindingList, err := a.policyBindingRegistry.ListPolicyBindings(ctx, klabels.Everything(), klabels.Everything())
Expand Down Expand Up @@ -120,7 +120,6 @@ func (a *openshiftAuthorizer) getRoleBindings(namespace string) ([]authorization
return ret, nil
}

// getRole
func (a *openshiftAuthorizer) getRole(roleBinding authorizationapi.RoleBinding) (*authorizationapi.Role, error) {
roleNamespace := roleBinding.RoleRef.Namespace
roleName := roleBinding.RoleRef.Name
Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/cli/cmd/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package cmd
import (
"fmt"

"github.com/spf13/cobra"

"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/meta"
kclient "github.com/GoogleCloudPlatform/kubernetes/pkg/client"
Expand All @@ -13,6 +11,8 @@ import (
kubecmd "github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl/cmd"
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl/resource"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/spf13/cobra"

"github.com/openshift/origin/pkg/api/latest"
"github.com/openshift/origin/pkg/client"
"github.com/openshift/origin/pkg/cmd/cli/describe"
Expand Down
3 changes: 2 additions & 1 deletion pkg/cmd/cli/cmd/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package cmd
import (
"io"

"github.com/openshift/origin/pkg/cmd/templates"
"github.com/spf13/cobra"

"github.com/openshift/origin/pkg/cmd/templates"
)

func NewCmdOptions(f *Factory, out io.Writer) *cobra.Command {
Expand Down
3 changes: 2 additions & 1 deletion pkg/cmd/cli/cmd/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import (
kubecmd "github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl/cmd"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/golang/glog"
"github.com/spf13/cobra"

"github.com/openshift/origin/pkg/template"
"github.com/openshift/origin/pkg/template/api"
"github.com/spf13/cobra"
)

// injectUserVars injects user specified variables into the Template
Expand Down
3 changes: 1 addition & 2 deletions pkg/cmd/cli/cmd/rollback.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ import (
"fmt"
"io"

"github.com/spf13/cobra"

kubectl "github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl"
kcmd "github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl/cmd"
"github.com/spf13/cobra"

describe "github.com/openshift/origin/pkg/cmd/cli/describe"
deployapi "github.com/openshift/origin/pkg/deploy/api"
Expand Down
3 changes: 1 addition & 2 deletions pkg/cmd/cli/cmd/startbuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ import (
"fmt"
"io"

"github.com/spf13/cobra"

kubecmd "github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl/cmd"
"github.com/spf13/cobra"

build "github.com/openshift/origin/pkg/build/api"
"github.com/openshift/origin/pkg/build/util"
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/cli/describe/describer.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ func (d *PolicyDescriber) Describe(namespace, name string) (string, error) {
})
}

// PolicyDescriber generates information about a Project
// PolicyBindingDescriber generates information about a Project
type PolicyBindingDescriber struct {
client.Interface
}
Expand Down
1 change: 1 addition & 0 deletions pkg/cmd/cli/describe/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"

"github.com/openshift/origin/pkg/api/latest"
buildapi "github.com/openshift/origin/pkg/build/api"
)
Expand Down
1 change: 1 addition & 0 deletions pkg/cmd/cli/describe/printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
kctl "github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"

authorizationapi "github.com/openshift/origin/pkg/authorization/api"
buildapi "github.com/openshift/origin/pkg/build/api"
deployapi "github.com/openshift/origin/pkg/deploy/api"
Expand Down
3 changes: 1 addition & 2 deletions pkg/cmd/experimental/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ import (
"fmt"
"os"

"github.com/spf13/cobra"

"github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl/cmd/config"
"github.com/spf13/cobra"
)

func NewCmdConfig(parentName, name string) *cobra.Command {
Expand Down
6 changes: 3 additions & 3 deletions pkg/cmd/experimental/login/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import (
clientcmdapi "github.com/GoogleCloudPlatform/kubernetes/pkg/client/clientcmd/api"
kubecmd "github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl/cmd"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"

"github.com/golang/glog"
"github.com/openshift/origin/pkg/cmd/cli/cmd"
"github.com/openshift/origin/pkg/cmd/util/tokencmd"
"github.com/spf13/cobra"
"github.com/spf13/pflag"

"github.com/openshift/origin/pkg/cmd/cli/cmd"
"github.com/openshift/origin/pkg/cmd/util/tokencmd"
)

func NewCmdLogin(name string, parent *cobra.Command) *cobra.Command {
Expand Down
3 changes: 1 addition & 2 deletions pkg/cmd/experimental/policy/add_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ package policy
import (
"fmt"

"github.com/spf13/cobra"

"github.com/GoogleCloudPlatform/kubernetes/pkg/client/clientcmd"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/spf13/cobra"

authorizationapi "github.com/openshift/origin/pkg/authorization/api"
"github.com/openshift/origin/pkg/client"
Expand Down
3 changes: 1 addition & 2 deletions pkg/cmd/experimental/policy/add_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ package policy
import (
"fmt"

"github.com/spf13/cobra"

"github.com/GoogleCloudPlatform/kubernetes/pkg/client/clientcmd"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/spf13/cobra"

authorizationapi "github.com/openshift/origin/pkg/authorization/api"
"github.com/openshift/origin/pkg/client"
Expand Down
5 changes: 2 additions & 3 deletions pkg/cmd/experimental/policy/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ import (
"os"
"strings"

"github.com/GoogleCloudPlatform/kubernetes/pkg/client/clientcmd"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/golang/glog"
"github.com/spf13/cobra"
"github.com/spf13/pflag"

"github.com/GoogleCloudPlatform/kubernetes/pkg/client/clientcmd"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"

authorizationapi "github.com/openshift/origin/pkg/authorization/api"
"github.com/openshift/origin/pkg/client"
)
Expand Down
3 changes: 1 addition & 2 deletions pkg/cmd/experimental/policy/remove_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ package policy
import (
"fmt"

"github.com/spf13/cobra"

"github.com/GoogleCloudPlatform/kubernetes/pkg/client/clientcmd"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/spf13/cobra"

"github.com/openshift/origin/pkg/client"
)
Expand Down
3 changes: 1 addition & 2 deletions pkg/cmd/experimental/policy/remove_group_from_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ package policy
import (
"fmt"

"github.com/spf13/cobra"

"github.com/GoogleCloudPlatform/kubernetes/pkg/client/clientcmd"
klabels "github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/spf13/cobra"

"github.com/openshift/origin/pkg/client"
)
Expand Down
Loading

0 comments on commit 357dc2e

Please sign in to comment.