Skip to content

Commit

Permalink
fix license lint.
Browse files Browse the repository at this point in the history
  • Loading branch information
lingdie committed Oct 20, 2023
1 parent 7a1d1e1 commit 70ef9b3
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 32 deletions.
4 changes: 2 additions & 2 deletions controllers/license/cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ package main
import (
"context"
"flag"
accountv1 "github.com/labring/sealos/controllers/account/api/v1"
"github.com/labring/sealos/controllers/license/internal/util/database"
"os"

// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
Expand All @@ -34,8 +32,10 @@ import (
"sigs.k8s.io/controller-runtime/pkg/healthz"
"sigs.k8s.io/controller-runtime/pkg/log/zap"

accountv1 "github.com/labring/sealos/controllers/account/api/v1"
licensev1 "github.com/labring/sealos/controllers/license/api/v1"
"github.com/labring/sealos/controllers/license/internal/controller"
"github.com/labring/sealos/controllers/license/internal/util/database"
//+kubebuilder:scaffold:imports
)

Expand Down
10 changes: 6 additions & 4 deletions controllers/license/internal/controller/license_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@ package controller

import (
"context"
accountutil "github.com/labring/sealos/controllers/license/internal/util/account"
"github.com/labring/sealos/controllers/license/internal/util/database"
"github.com/labring/sealos/controllers/license/internal/util/key"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"time"

"github.com/go-logr/logr"

licensev1 "github.com/labring/sealos/controllers/license/api/v1"
accountutil "github.com/labring/sealos/controllers/license/internal/util/account"
"github.com/labring/sealos/controllers/license/internal/util/database"
"github.com/labring/sealos/controllers/license/internal/util/key"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/builder"
Expand Down
12 changes: 6 additions & 6 deletions controllers/license/internal/controller/license_recorder.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ package controller
import (
"context"
"errors"

v1 "github.com/labring/sealos/controllers/license/api/v1"
"github.com/labring/sealos/controllers/license/internal/util/database"
"github.com/labring/sealos/controllers/license/internal/util/meta"

"go.mongodb.org/mongo-driver/mongo"
"sigs.k8s.io/controller-runtime/pkg/client"
)
Expand All @@ -26,12 +28,10 @@ func (r *LicenseRecorder) Get(ctx context.Context, license *v1.License) (*meta.M

func (r *LicenseRecorder) Find(ctx context.Context, license *v1.License) (bool, error) {
_, err := r.Get(ctx, license)
if err != nil {
if errors.Is(err, mongo.ErrNoDocuments) {
return false, nil
} else {
return false, err
}
if err != nil && errors.Is(err, mongo.ErrNoDocuments) {
return false, nil
} else if err != nil {
return false, err
}
return true, nil
}
Expand Down
5 changes: 1 addition & 4 deletions controllers/license/internal/util/account/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,7 @@ func Recharge(ctx context.Context, client client.Client, license *licensev1.Lice
if err := crypto.RechargeBalance(account.Status.EncryptBalance, data.Amount*count.CurrencyUnit); err != nil {
return err
}
if err := client.Status().Update(ctx, account); err != nil {
return err
}
return nil
return client.Status().Update(ctx, account)
}

func GetNameByNameSpace(ns string) string {
Expand Down
3 changes: 2 additions & 1 deletion controllers/license/internal/util/claims/claims.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package claims

import (
"github.com/golang-jwt/jwt/v4"
"github.com/labring/sealos/controllers/license/api/v1"
"github.com/mitchellh/mapstructure"

v1 "github.com/labring/sealos/controllers/license/api/v1"
)

type Claims struct {
Expand Down
1 change: 0 additions & 1 deletion controllers/license/internal/util/database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,4 @@ func (db *DataBase) Disconnect(ctx context.Context) {
logger.Error(err, "disconnect from database failed")
return
}
return
}
10 changes: 1 addition & 9 deletions controllers/license/internal/util/database/database_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
package database

import "testing"

func TestDataBase_GetLicenseMeta(t *testing.T) {

}

func TestDataBase_StoreLicenseMeta(t *testing.T) {

}
// TODO Add tests
4 changes: 2 additions & 2 deletions controllers/license/internal/util/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ import (
"fmt"
)

var LicenseInvalidError = fmt.Errorf("the license provided appears to be invalid")
var ClaimsConventError = fmt.Errorf("the claims data provided appears to be invalid")
var ErrLicenseInvalid = fmt.Errorf("the license provided appears to be invalid")
var ErrClaimsConvent = fmt.Errorf("the claims data provided appears to be invalid")
3 changes: 2 additions & 1 deletion controllers/license/internal/util/license/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package license

import (
"encoding/base64"

"github.com/golang-jwt/jwt/v4"

licensev1 "github.com/labring/sealos/controllers/license/api/v1"
Expand Down Expand Up @@ -37,7 +38,7 @@ func GetClaims(license *licensev1.License) (*utilclaims.Claims, error) {
}
claims, ok := token.Claims.(*utilclaims.Claims)
if !ok {
return nil, errors.ClaimsConventError
return nil, errors.ErrClaimsConvent
}
return claims, nil
}
Expand Down
4 changes: 3 additions & 1 deletion controllers/license/internal/util/license/validate_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package license

import (
"testing"

"github.com/golang-jwt/jwt/v4"

licensev1 "github.com/labring/sealos/controllers/license/api/v1"
utilclaims "github.com/labring/sealos/controllers/license/internal/util/claims"
"testing"
)

func TestIsLicenseValid(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion deploy/cloud/manifests/free-license.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ metadata:
namespace: ns-admin
spec:
type: Account
token: "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJTZWFsb3MiLCJpYXQiOjE2OTA0NDU5NjIsImFtdCI6MjAwMH0.ZzZfPRbNiNvRBLMn5FGJeKitRPHmUHZ1qvnGdJUIbIH1L5mQ4yECzvvsa5S8-OTqF6HXmrw9QmFcQOjoz5GpqjqrqXdH2H-JDXFGNNAib2J9UmLFmtV1BVm3zReucfK-bOY5NiWOr5wplEVwkoUKNPHLY5Mw142y9J62vELE-XW-hb3xcmWjLTPVRYgMqk0KEi7Z7cQ_rS0QgJh1Rqb2WS6AKz2ILE5J8XUhhhUva0nCEyLzE-I8oZtV6kugQy8YjWI-SjfneFOLI8-Pg40vry6DZZ-_J_9QmjkUlZx0YNMRiRA5yg2yWeMEzVnam9L310TJgu6Od-bEUijsfOcZyw"
# nosemgrep: generic.secrets.security.detected-jwt-token.detected-jwt-token
token: ""

0 comments on commit 70ef9b3

Please sign in to comment.