Commit a2caef0b authored by Sebastiaan van Steenis's avatar Sebastiaan van Steenis
Browse files

Update golangci-lint

parent be03c8bd
Showing with 72 additions and 66 deletions
+72 -66
......@@ -2,9 +2,12 @@
"linters": {
"disable-all": true,
"enable": [
"govet",
"golint",
"goimports"
"govet",
"revive",
"goimports",
"misspell",
"ineffassign",
"gofmt"
]
},
"linters-settings": {
......@@ -42,6 +45,18 @@
{
"path":"pkg/apis/management.cattle.io/v3/zz_generated_list_types.go",
"text":".*lobalDns.*"
},
{
"linters": "revive",
"text": "should have comment"
},
{
"linters": "revive",
"text": "should be of the form"
},
{
"linters": "typecheck",
"text": "imported but not used as apierrors"
}
]
}
......
......@@ -28,7 +28,7 @@ ENV GOLANG_ARCH_amd64=amd64 GOLANG_ARCH_arm=armv6l GOLANG_ARCH_arm64=arm64 GOLAN
RUN wget -O - https://storage.googleapis.com/golang/go1.16.4.linux-${!GOLANG_ARCH}.tar.gz | tar -xzf - -C /usr/local
RUN if [ "${ARCH}" == "amd64" ]; then \
curl -sL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s v1.27.0; \
curl -sL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s v1.40.1; \
fi
ENV DOCKER_URL_amd64=https://get.docker.com/builds/Linux/x86_64/docker-1.10.3 \
......
......@@ -289,7 +289,7 @@ func (bc *bindingsCleanup) dedupeRB(roleBindings []k8srbacv1.RoleBinding) (int,
}
func (bc *bindingsCleanup) checkIfDeterministicCRBExists(sampleBinding k8srbacv1.ClusterRoleBinding) (bool, string, error) {
var deterministicFound bool = false
var deterministicFound bool
crbName, err := getDeterministicBindingName(sampleBinding)
if err != nil {
return deterministicFound, "", err
......@@ -302,7 +302,7 @@ func (bc *bindingsCleanup) checkIfDeterministicCRBExists(sampleBinding k8srbacv1
}
func (bc *bindingsCleanup) checkIfDeterministicRBExists(sampleBinding k8srbacv1.RoleBinding) (bool, string, error) {
var deterministicFound bool = false
var deterministicFound bool
rbName, err := getDeterministicBindingName(sampleBinding)
if err != nil {
return deterministicFound, "", err
......
......@@ -80,11 +80,7 @@ func (v *Validator) Validator(request *types.APIContext, schema *types.Schema, d
return err
}
if err := v.validateGKEConfig(request, data, &clusterSpec); err != nil {
return err
}
return nil
return v.validateGKEConfig(request, data, &clusterSpec)
}
func (v *Validator) validateScheduledClusterScan(spec *mgmtclient.Cluster) error {
......@@ -315,11 +311,7 @@ func (v *Validator) accessTemplate(request *types.APIContext, spec *mgmtclient.C
}
var ctMap map[string]interface{}
if err := access.ByID(request, &mgmtSchema.Version, mgmtclient.ClusterTemplateType, clusterTempRev.Spec.ClusterTemplateName, &ctMap); err != nil {
return err
}
return nil
return access.ByID(request, &mgmtSchema.Version, mgmtclient.ClusterTemplateType, clusterTempRev.Spec.ClusterTemplateName, &ctMap)
}
// validateGenericEngineConfig allows for additional validation of clusters that depend on Kontainer Engine or Rancher Machine driver
......
......@@ -90,6 +90,9 @@ func (a ActionHandler) refresh(apiContext *types.APIContext) error {
setting.Annotations[forceRefreshAnnotation] = strconv.FormatInt(time.Now().Unix(), 10)
_, err = a.MetadataHandler.Settings.Update(setting)
if err != nil {
return err
}
apiContext.WriteResponse(http.StatusOK, response)
return nil
}
......
......@@ -138,10 +138,7 @@ func (p *PasswordStore) replacePasswords(sepData, data, existing map[string]inte
*/
if len(data) == 0 {
// nothing to put in data, delete existing secret for this path
if err := p.deleteExistingSecrets(sepData, existing); err != nil {
return err
}
return nil
return p.deleteExistingSecrets(sepData, existing)
}
for sepKey, sepVal := range sepData {
if convert.ToString(sepVal) == separator {
......
......@@ -199,7 +199,7 @@ func (r *refresher) refreshAttributes(attribs *v3.UserAttribute) (*v3.UserAttrib
break
}
}
newGroupPrincipals := []v3.Principal{}
var newGroupPrincipals []v3.Principal
// If there is no principalID for the provider, there is no reason to go through the refetch process
if principalID != "" {
......
......@@ -32,23 +32,23 @@ type Group struct {
Subgroups []Group `json:"subGroups,omitempty"`
}
//KClient implements a httpclient for keycloak
type KClient struct {
//KeyCloakClient implements a httpclient for keycloak
type KeyCloakClient struct {
httpClient *http.Client
}
func (k *KClient) newClient(config *v32.OIDCConfig) (KClient, error) {
kClient := KClient{}
func (k *KeyCloakClient) newClient(config *v32.OIDCConfig) (KeyCloakClient, error) {
keyCloakClient := KeyCloakClient{}
if config.Certificate != "" && config.PrivateKey != "" {
err := oidc.GetClientWithCertKey(kClient.httpClient, config.Certificate, config.PrivateKey)
err := oidc.GetClientWithCertKey(keyCloakClient.httpClient, config.Certificate, config.PrivateKey)
if err != nil {
return KClient{}, err
return KeyCloakClient{}, err
}
}
return kClient, nil
return keyCloakClient, nil
}
func (k *KClient) searchPrincipals(searchTerm, principalType string, accessToken string, config *v32.OIDCConfig) ([]account, error) {
func (k *KeyCloakClient) searchPrincipals(searchTerm, principalType string, accessToken string, config *v32.OIDCConfig) ([]account, error) {
var accounts []account
sURL, err := getSearchURL(config.Issuer)
if err != nil {
......@@ -119,7 +119,7 @@ func getSubGroups(group Group) []Group {
return groups
}
func (k *KClient) getFromKeyCloakByID(principalID, accessToken, searchType string, config *v32.OIDCConfig) (account, error) {
func (k *KeyCloakClient) getFromKeyCloakByID(principalID, accessToken, searchType string, config *v32.OIDCConfig) (account, error) {
sURL, err := getSearchURL(config.Issuer)
if err != nil {
return account{}, nil
......@@ -158,8 +158,8 @@ func URLEncoded(str string) string {
return u.String()
}
func (k *KClient) getFromKeyCloak(accessToken, url string, config *v32.OIDCConfig) ([]byte, int, error) {
kHTTPClient, err := k.newClient(config)
func (k *KeyCloakClient) getFromKeyCloak(accessToken, url string, config *v32.OIDCConfig) ([]byte, int, error) {
keyCloakHTTPClient, err := k.newClient(config)
if err != nil {
logrus.Errorf("[keycloak oidc]: error creating new http client: %v", err)
return nil, 500, err
......@@ -170,7 +170,7 @@ func (k *KClient) getFromKeyCloak(accessToken, url string, config *v32.OIDCConfi
}
req.Header.Add("Authorization", "token "+accessToken)
req.Header.Add("Accept", "application/json")
resp, err := kHTTPClient.httpClient.Do(req)
resp, err := keyCloakHTTPClient.httpClient.Do(req)
if err != nil {
logrus.Errorf("[keycloak oidc]: received error from keycloak: %v", err)
return nil, resp.StatusCode, err
......
......@@ -26,13 +26,13 @@ const (
)
type keyCloakOIDCProvider struct {
kClient *KClient
keyCloakClient *KeyCloakClient
oidc.OpenIDCProvider
}
func Configure(ctx context.Context, mgmtCtx *config.ScaledContext, userMGR user.Manager, tokenMGR *tokens.Manager) common.AuthProvider {
return &keyCloakOIDCProvider{
&KClient{
&KeyCloakClient{
httpClient: &http.Client{},
},
oidc.OpenIDCProvider{
......@@ -67,8 +67,8 @@ func (k *keyCloakOIDCProvider) SearchPrincipals(searchValue, principalType strin
}
accessToken = token.ProviderInfo["access_token"]
}
oidc.GetClientWithCertKey(k.kClient.httpClient, config.Certificate, config.PrivateKey)
accts, err := k.kClient.searchPrincipals(searchValue, principalType, accessToken, config)
oidc.GetClientWithCertKey(k.keyCloakClient.httpClient, config.Certificate, config.PrivateKey)
accts, err := k.keyCloakClient.searchPrincipals(searchValue, principalType, accessToken, config)
if err != nil {
logrus.Errorf("[keycloak oidc] problem searching keycloak: %v", err)
}
......@@ -133,8 +133,8 @@ func (k *keyCloakOIDCProvider) GetPrincipal(principalID string, token v3.Token)
if principalType == GroupType {
searchType = "groups"
}
oidc.GetClientWithCertKey(k.kClient.httpClient, config.Certificate, config.PrivateKey)
acct, err := k.kClient.getFromKeyCloakByID(externalID, searchType, accessToken, config)
oidc.GetClientWithCertKey(k.keyCloakClient.httpClient, config.Certificate, config.PrivateKey)
acct, err := k.keyCloakClient.getFromKeyCloakByID(externalID, searchType, accessToken, config)
if err != nil {
return v3.Principal{}, err
}
......
......@@ -28,12 +28,10 @@ func GetClientWithCertKey(httpClient *http.Client, certificate, key string) erro
}
caCertPool := x509.NewCertPool()
caCertPool.AppendCertsFromPEM([]byte(certificate))
httpClient = &http.Client{
Transport: &http.Transport{
TLSClientConfig: &tls.Config{
RootCAs: caCertPool,
Certificates: []tls.Certificate{keyPair},
},
httpClient.Transport = &http.Transport{
TLSClientConfig: &tls.Config{
RootCAs: caCertPool,
Certificates: []tls.Certificate{keyPair},
},
}
return nil
......
......@@ -405,6 +405,11 @@ func (s *Provider) HandleSamlAssertion(w http.ResponseWriter, r *http.Request, a
}
keyBytes, err := base64.StdEncoding.DecodeString(publicKey)
if err != nil {
log.Errorf("SAML: base64 DecodeString error %v", err)
http.Redirect(w, r, redirectURL+"errorCode=500", http.StatusFound)
return
}
pubKey := &rsa.PublicKey{}
err = json.Unmarshal(keyBytes, pubKey)
if err != nil {
......
......@@ -190,7 +190,7 @@ func (a *tokenAuthenticator) TokenFromRequest(req *http.Request) (*v3.Token, err
lookupUsingClient = true
}
storedToken := &v3.Token{}
var storedToken *v3.Token
if lookupUsingClient {
storedToken, err = a.tokenClient.Get(tokenName, metav1.GetOptions{})
if err != nil {
......
......@@ -49,11 +49,7 @@ var (
func RegisterIndexer(ctx context.Context, apiContext *config.ScaledContext) error {
informer := apiContext.Management.Users("").Controller().Informer()
if err := informer.AddIndexers(map[string]cache.IndexFunc{userPrincipalIndex: userPrincipalIndexer}); err != nil {
return err
}
return nil
return informer.AddIndexers(map[string]cache.IndexFunc{userPrincipalIndex: userPrincipalIndexer})
}
func NewManager(ctx context.Context, apiContext *config.ScaledContext) *Manager {
......@@ -174,7 +170,7 @@ func (m *Manager) getToken(tokenAuthValue string) (*v3.Token, int, error) {
lookupUsingClient = true
}
storedToken := &v3.Token{}
var storedToken *v3.Token
if lookupUsingClient {
storedToken, err = m.tokensClient.Get(tokenName, metav1.GetOptions{})
if err != nil {
......
......@@ -205,10 +205,7 @@ func (m *Manager) ValidateChartCompatibility(template *v3.CatalogTemplateVersion
if err := m.ValidateRancherVersion(template); err != nil {
return err
}
if err := m.ValidateKubeVersion(template, clusterName); err != nil {
return err
}
return nil
return m.ValidateKubeVersion(template, clusterName)
}
func (m *Manager) ValidateKubeVersion(template *v3.CatalogTemplateVersion, clusterName string) error {
......
......@@ -282,7 +282,7 @@ func (m *Manager) traverseAndUpdate(helm *helmlib.Helm, commit string, cmt *Cata
if _, err := m.updateCatalogInfo(cmt, catalogType, "", false, true); err != nil {
return err
}
logrus.Error(fmt.Sprintf("failed to sync templates. Multiple error(s) occured: %v", invalidChartErrors))
logrus.Error(fmt.Sprintf("failed to sync templates. Multiple error(s) occurred: %v", invalidChartErrors))
return &controller.ForgetError{Err: errors.Errorf("failed to sync templates. Multiple error(s) occurred: %v", invalidChartErrors)}
}
if len(errstrings) > 0 {
......
......@@ -59,6 +59,9 @@ func Icon(secret *corev1.Secret, repoURL string, caBundle []byte, insecureSkipTL
}
data, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, "", err
}
return ioutil.NopCloser(bytes.NewBuffer(data)), path.Ext(u.String()), nil
}
......
......@@ -17,11 +17,7 @@ func Register(settingController managementcontrollers.SettingController) error {
settingCache: settingController.Cache(),
}
if err := settings.SetProvider(sp); err != nil {
return err
}
return nil
return settings.SetProvider(sp)
}
type settingsProvider struct {
......
......@@ -855,7 +855,7 @@ func (p *Provisioner) getSpec(cluster *v3.Cluster) (*apimgmtv3.ClusterSpec, erro
return nil, err
}
newSpec, newConfig, err := p.getConfig(true, censoredSpec, driverName, cluster.Name)
_, newConfig, err := p.getConfig(true, censoredSpec, driverName, cluster.Name)
if err != nil {
return nil, err
}
......@@ -864,7 +864,7 @@ func (p *Provisioner) getSpec(cluster *v3.Cluster) (*apimgmtv3.ClusterSpec, erro
return nil, nil
}
newSpec, _, err = p.getConfig(true, cluster.Spec, driverName, cluster.Name)
newSpec, _, err := p.getConfig(true, cluster.Spec, driverName, cluster.Name)
return newSpec, err
}
......
......@@ -44,6 +44,9 @@ func BuildEKSUpstreamSpec(secretsCache wranglerv1.SecretCache, cluster *mgmtv3.C
&eks.ListNodegroupsInput{
ClusterName: aws.String(cluster.Spec.EKSConfig.DisplayName),
})
if err != nil {
return nil, err
}
// gather upstream node groups states
var nodeGroupStates []*eks.DescribeNodegroupOutput
......
......@@ -228,7 +228,9 @@ func (c *Controller) etcdSaveWithBackoff(b *v3.EtcdBackup) (runtime.Object, erro
}
return true, nil
})
if err != nil {
return b, err
}
return b, inErr
})
if err != nil {
......@@ -395,7 +397,6 @@ func GetS3Client(sbc *rketypes.S3BackupConfig, timeout int, dialer dialer.Dialer
if sbc == nil {
return nil, fmt.Errorf("Can't find S3 backup target configuration")
}
var s3Client = &minio.Client{}
var creds *credentials.Credentials
var tr http.RoundTripper = &http.Transport{
Proxy: http.ProxyFromEnvironment,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment