Enable unparam, prealloc, sqlclosecheck linters
Signed-off-by: m.nabokikh <maksim.nabokikh@flant.com>
This commit is contained in:
@@ -285,7 +285,7 @@ func testClientCRUD(t *testing.T, s storage.Storage) {
|
||||
t.Fatalf("create client: %v", err)
|
||||
}
|
||||
|
||||
getAndCompare := func(id string, want storage.Client) {
|
||||
getAndCompare := func(_ string, want storage.Client) {
|
||||
gc, err := s.GetClient(id1)
|
||||
if err != nil {
|
||||
t.Errorf("get client: %v", err)
|
||||
@@ -845,13 +845,8 @@ func testGC(t *testing.T, s storage.Storage) {
|
||||
t.Errorf("expected storage.ErrNotFound, got %v", err)
|
||||
}
|
||||
|
||||
userCode, err := storage.NewUserCode()
|
||||
if err != nil {
|
||||
t.Errorf("Unexpected Error: %v", err)
|
||||
}
|
||||
|
||||
d := storage.DeviceRequest{
|
||||
UserCode: userCode,
|
||||
UserCode: storage.NewUserCode(),
|
||||
DeviceCode: storage.NewID(),
|
||||
ClientID: "client1",
|
||||
ClientSecret: "secret1",
|
||||
@@ -970,12 +965,8 @@ func testTimezones(t *testing.T, s storage.Storage) {
|
||||
}
|
||||
|
||||
func testDeviceRequestCRUD(t *testing.T, s storage.Storage) {
|
||||
userCode, err := storage.NewUserCode()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
d1 := storage.DeviceRequest{
|
||||
UserCode: userCode,
|
||||
UserCode: storage.NewUserCode(),
|
||||
DeviceCode: storage.NewID(),
|
||||
ClientID: "client1",
|
||||
ClientSecret: "secret1",
|
||||
@@ -988,7 +979,7 @@ func testDeviceRequestCRUD(t *testing.T, s storage.Storage) {
|
||||
}
|
||||
|
||||
// Attempt to create same DeviceRequest twice.
|
||||
err = s.CreateDeviceRequest(d1)
|
||||
err := s.CreateDeviceRequest(d1)
|
||||
mustBeErrAlreadyExists(t, "device request", err)
|
||||
|
||||
// No manual deletes for device requests, will be handled by garbage collection routines
|
||||
|
@@ -338,13 +338,13 @@ func (c *conn) ListPasswords() (passwords []storage.Password, err error) {
|
||||
func (c *conn) CreateOfflineSessions(s storage.OfflineSessions) error {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), defaultStorageTimeout)
|
||||
defer cancel()
|
||||
return c.txnCreate(ctx, keySession(offlineSessionPrefix, s.UserID, s.ConnID), fromStorageOfflineSessions(s))
|
||||
return c.txnCreate(ctx, keySession(s.UserID, s.ConnID), fromStorageOfflineSessions(s))
|
||||
}
|
||||
|
||||
func (c *conn) UpdateOfflineSessions(userID string, connID string, updater func(s storage.OfflineSessions) (storage.OfflineSessions, error)) error {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), defaultStorageTimeout)
|
||||
defer cancel()
|
||||
return c.txnUpdate(ctx, keySession(offlineSessionPrefix, userID, connID), func(currentValue []byte) ([]byte, error) {
|
||||
return c.txnUpdate(ctx, keySession(userID, connID), func(currentValue []byte) ([]byte, error) {
|
||||
var current OfflineSessions
|
||||
if len(currentValue) > 0 {
|
||||
if err := json.Unmarshal(currentValue, ¤t); err != nil {
|
||||
@@ -363,7 +363,7 @@ func (c *conn) GetOfflineSessions(userID string, connID string) (s storage.Offli
|
||||
ctx, cancel := context.WithTimeout(context.Background(), defaultStorageTimeout)
|
||||
defer cancel()
|
||||
var os OfflineSessions
|
||||
if err = c.getKey(ctx, keySession(offlineSessionPrefix, userID, connID), &os); err != nil {
|
||||
if err = c.getKey(ctx, keySession(userID, connID), &os); err != nil {
|
||||
return
|
||||
}
|
||||
return toStorageOfflineSessions(os), nil
|
||||
@@ -372,7 +372,7 @@ func (c *conn) GetOfflineSessions(userID string, connID string) (s storage.Offli
|
||||
func (c *conn) DeleteOfflineSessions(userID string, connID string) error {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), defaultStorageTimeout)
|
||||
defer cancel()
|
||||
return c.deleteKey(ctx, keySession(offlineSessionPrefix, userID, connID))
|
||||
return c.deleteKey(ctx, keySession(userID, connID))
|
||||
}
|
||||
|
||||
func (c *conn) CreateConnector(connector storage.Connector) error {
|
||||
@@ -564,8 +564,8 @@ func (c *conn) txnUpdate(ctx context.Context, key string, update func(current []
|
||||
|
||||
func keyID(prefix, id string) string { return prefix + id }
|
||||
func keyEmail(prefix, email string) string { return prefix + strings.ToLower(email) }
|
||||
func keySession(prefix, userID, connID string) string {
|
||||
return prefix + strings.ToLower(userID+"|"+connID)
|
||||
func keySession(userID, connID string) string {
|
||||
return offlineSessionPrefix + strings.ToLower(userID+"|"+connID)
|
||||
}
|
||||
|
||||
func (c *conn) CreateDeviceRequest(d storage.DeviceRequest) error {
|
||||
|
@@ -19,7 +19,7 @@ package k8sapi
|
||||
// Where possible, json tags match the cli argument names.
|
||||
// Top level config objects and all values required for proper functioning are not "omitempty". Any truly optional piece of config is allowed to be omitted.
|
||||
|
||||
// Config holds the information needed to build connect to remote kubernetes clusters as a given user
|
||||
// Config holds the information needed to build connect to remote kubernetes clusters as a given user.
|
||||
type Config struct {
|
||||
// Legacy field from pkg/api/types.go TypeMeta.
|
||||
// TODO(jlowdermilk): remove this after eliminating downstream dependencies.
|
||||
@@ -51,7 +51,7 @@ type Preferences struct {
|
||||
Extensions []NamedExtension `json:"extensions,omitempty"`
|
||||
}
|
||||
|
||||
// Cluster contains information about how to communicate with a kubernetes cluster
|
||||
// Cluster contains information about how to communicate with a kubernetes cluster.
|
||||
type Cluster struct {
|
||||
// Server is the address of the kubernetes cluster (https://hostname:port).
|
||||
Server string `json:"server"`
|
||||
@@ -97,7 +97,8 @@ type AuthInfo struct {
|
||||
Extensions []NamedExtension `json:"extensions,omitempty"`
|
||||
}
|
||||
|
||||
// Context is a tuple of references to a cluster (how do I communicate with a kubernetes cluster), a user (how do I identify myself), and a namespace (what subset of resources do I want to work with)
|
||||
// Context is a tuple of references to a cluster (how do I communicate with a kubernetes cluster),
|
||||
// a user (how do I identify myself), and a namespace (what subset of resources do I want to work with).
|
||||
type Context struct {
|
||||
// Cluster is the name of the cluster for this context
|
||||
Cluster string `json:"cluster"`
|
||||
|
@@ -378,6 +378,8 @@ func (c *conn) ListRefreshTokens() ([]storage.RefreshToken, error) {
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("query: %v", err)
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
var tokens []storage.RefreshToken
|
||||
for rows.Next() {
|
||||
r, err := scanRefresh(rows)
|
||||
@@ -556,6 +558,8 @@ func (c *conn) ListClients() ([]storage.Client, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
var clients []storage.Client
|
||||
for rows.Next() {
|
||||
cli, err := scanClient(rows)
|
||||
@@ -652,6 +656,7 @@ func (c *conn) ListPasswords() ([]storage.Password, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
var passwords []storage.Password
|
||||
for rows.Next() {
|
||||
@@ -837,6 +842,8 @@ func (c *conn) ListConnectors() ([]storage.Connector, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
var connectors []storage.Connector
|
||||
for rows.Next() {
|
||||
conn, err := scanConnector(rows)
|
||||
|
@@ -386,22 +386,19 @@ type Keys struct {
|
||||
|
||||
// NewUserCode returns a randomized 8 character user code for the device flow.
|
||||
// No vowels are included to prevent accidental generation of words
|
||||
func NewUserCode() (string, error) {
|
||||
code, err := randomString(8)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return code[:4] + "-" + code[4:], nil
|
||||
func NewUserCode() string {
|
||||
code := randomString(8)
|
||||
return code[:4] + "-" + code[4:]
|
||||
}
|
||||
|
||||
func randomString(n int) (string, error) {
|
||||
func randomString(n int) string {
|
||||
v := big.NewInt(int64(len(validUserCharacters)))
|
||||
bytes := make([]byte, n)
|
||||
for i := 0; i < n; i++ {
|
||||
c, _ := rand.Int(rand.Reader, v)
|
||||
bytes[i] = validUserCharacters[c.Int64()]
|
||||
}
|
||||
return string(bytes), nil
|
||||
return string(bytes)
|
||||
}
|
||||
|
||||
// DeviceRequest represents an OIDC device authorization request. It holds the state of a device request until the user
|
||||
|
Reference in New Issue
Block a user