Skip to content

Commit

Permalink
Add SCC to the initialisms to check
Browse files Browse the repository at this point in the history
SCC should always be uppercased, check it with golangci-lint.
  • Loading branch information
cbosdo committed Nov 13, 2024
1 parent 5583d8e commit a6c3cb9
Show file tree
Hide file tree
Showing 24 changed files with 77 additions and 40 deletions.
37 changes: 37 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,43 @@ linters-settings:
stylecheck:
dot-import-whitelist:
- github.com/uyuni-project/uyuni-tools/shared/l10n
initialisms:
# Default
- ACL
- API
- ASCII
- CPU
- DNS
- EOF
- GUID
- HTML
- HTTP
- HTTPS
- ID
- IP
- JSON
- RPC
- SLA
- SMTP
- SQL
- SSH
- TCP
- TLS
- TTL
- UDP
- UI
- GID
- UID
- UUID
- URI
- URL
- UTF8
- VM
- XML
- RTP
- DB
# Added
- SCC
gofmt:
simplify: true
gocyclo:
Expand Down
4 changes: 2 additions & 2 deletions mgradm/cmd/inspect/inspect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ func TestParamsParsing(t *testing.T) {
}

args = append(args, flagstests.ImageFlagsTestArgs...)
args = append(args, flagstests.SccFlagTestArgs...)
args = append(args, flagstests.SCCFlagTestArgs...)

// Test function asserting that the args are properly parsed
tester := func(globalFlags *types.GlobalFlags, flags *inspectFlags,
cmd *cobra.Command, args []string,
) error {
flagstests.AssertImageFlag(t, cmd, &flags.Image)
flagstests.AssertSccFlag(t, cmd, &flags.SCC)
flagstests.AssertSCCFlag(t, cmd, &flags.SCC)
if utils.KubernetesBuilt {
testutils.AssertEquals(t, "Error parsing --backend", "kubectl", flags.Backend)
}
Expand Down
2 changes: 1 addition & 1 deletion mgradm/cmd/install/kubernetes/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func installForKubernetes(globalFlags *types.GlobalFlags,
helmArgs = append(helmArgs, sslArgs...)

// Create a secret using SCC credentials if any are provided
helmArgs, err = shared_kubernetes.AddSccSecret(helmArgs, flags.Helm.Uyuni.Namespace, &flags.Scc)
helmArgs, err = shared_kubernetes.AddSCCSecret(helmArgs, flags.Helm.Uyuni.Namespace, &flags.SCC)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion mgradm/cmd/install/podman/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func installForPodman(
return err
}

authFile, cleaner, err := shared_podman.PodmanLogin(hostData, flags.Scc)
authFile, cleaner, err := shared_podman.PodmanLogin(hostData, flags.SCC)
if err != nil {
return utils.Errorf(err, L("failed to login to registry.suse.com"))
}
Expand Down
2 changes: 1 addition & 1 deletion mgradm/cmd/install/shared/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ type InstallFlags struct {
DB DBFlags
ReportDB DBFlags
Ssl cmd_utils.InstallSSLFlags
Scc types.SCCCredentials
SCC types.SCCCredentials
Debug DebugFlags
Image types.ImageFlags `mapstructure:",squash"`
Coco cmd_utils.CocoFlags
Expand Down
4 changes: 2 additions & 2 deletions mgradm/cmd/install/shared/shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ func generateSetupScript(flags *InstallFlags, fqdn string, extraEnv map[string]s
"EXTERNALDB_PROVIDER": flags.DB.Provider,
"ISS_PARENT": flags.IssParent,
"ACTIVATE_SLP": "N", // Deprecated, will be removed soon
"SCC_USER": flags.Scc.User,
"SCC_PASS": flags.Scc.Password,
"SCC_USER": flags.SCC.User,
"SCC_PASS": flags.SCC.Password,
}
if flags.Mirror != "" {
env["MIRROR_PATH"] = "/mirror"
Expand Down
4 changes: 2 additions & 2 deletions mgradm/cmd/migrate/kubernetes/kubernetes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestParamsParsing(t *testing.T) {
}

args = append(args, flagstests.MirrorFlagTestArgs...)
args = append(args, flagstests.SccFlagTestArgs...)
args = append(args, flagstests.SCCFlagTestArgs...)
args = append(args, flagstests.ImageFlagsTestArgs...)
args = append(args, flagstests.DBUpdateImageFlagTestArgs...)
args = append(args, flagstests.CocoFlagsTestArgs...)
Expand All @@ -37,7 +37,7 @@ func TestParamsParsing(t *testing.T) {
) error {
testutils.AssertTrue(t, "Prepare not set", flags.Prepare)
flagstests.AssertMirrorFlag(t, cmd, flags.Mirror)
flagstests.AssertSccFlag(t, cmd, &flags.SCC)
flagstests.AssertSCCFlag(t, cmd, &flags.SCC)
flagstests.AssertImageFlag(t, cmd, &flags.Image)
flagstests.AssertDBUpgradeImageFlag(t, cmd, &flags.DBUpgradeImage)
flagstests.AssertCocoFlag(t, cmd, &flags.Coco)
Expand Down
2 changes: 1 addition & 1 deletion mgradm/cmd/migrate/kubernetes/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func migrateToKubernetes(
helmArgs := []string{}

// Create a secret using SCC credentials if any are provided
helmArgs, err = shared_kubernetes.AddSccSecret(helmArgs, flags.Helm.Uyuni.Namespace, &flags.Scc)
helmArgs, err = shared_kubernetes.AddSCCSecret(helmArgs, flags.Helm.Uyuni.Namespace, &flags.SCC)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions mgradm/cmd/migrate/podman/podman_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestParamsParsing(t *testing.T) {
}

args = append(args, flagstests.MirrorFlagTestArgs...)
args = append(args, flagstests.SccFlagTestArgs...)
args = append(args, flagstests.SCCFlagTestArgs...)
args = append(args, flagstests.ImageFlagsTestArgs...)
args = append(args, flagstests.DBUpdateImageFlagTestArgs...)
args = append(args, flagstests.CocoFlagsTestArgs...)
Expand All @@ -34,7 +34,7 @@ func TestParamsParsing(t *testing.T) {
) error {
testutils.AssertTrue(t, "Prepare not set", flags.Prepare)
flagstests.AssertMirrorFlag(t, cmd, flags.Mirror)
flagstests.AssertSccFlag(t, cmd, &flags.SCC)
flagstests.AssertSCCFlag(t, cmd, &flags.SCC)
flagstests.AssertImageFlag(t, cmd, &flags.Image)
flagstests.AssertDBUpgradeImageFlag(t, cmd, &flags.DBUpgradeImage)
flagstests.AssertCocoFlag(t, cmd, &flags.Coco)
Expand Down
2 changes: 1 addition & 1 deletion mgradm/cmd/migrate/shared/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type MigrateFlags struct {
User string
Mirror string
HubXmlrpc utils.HubXmlrpcFlags
Scc types.SCCCredentials
SCC types.SCCCredentials
}

// AddMigrateFlags add migration flags to a command.
Expand Down
2 changes: 1 addition & 1 deletion mgradm/cmd/upgrade/kubernetes/kubernetes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func TestParamsParsing(t *testing.T) {
args = append(args, flagstests.DBUpdateImageFlagTestArgs...)
args = append(args, flagstests.CocoFlagsTestArgs...)
args = append(args, flagstests.HubXmlrpcFlagsTestArgs...)
args = append(args, flagstests.SccFlagTestArgs...)
args = append(args, flagstests.SCCFlagTestArgs...)
args = append(args, flagstests.ServerHelmFlagsTestArgs...)

// Test function asserting that the args are properly parsed
Expand Down
4 changes: 2 additions & 2 deletions mgradm/cmd/upgrade/podman/podman_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestParamsParsing(t *testing.T) {
args = append(args, flagstests.DBUpdateImageFlagTestArgs...)
args = append(args, flagstests.CocoFlagsTestArgs...)
args = append(args, flagstests.HubXmlrpcFlagsTestArgs...)
args = append(args, flagstests.SccFlagTestArgs...)
args = append(args, flagstests.SCCFlagTestArgs...)
args = append(args, flagstests.PodmanFlagsTestArgs...)

// Test function asserting that the args are properly parsed
Expand All @@ -31,7 +31,7 @@ func TestParamsParsing(t *testing.T) {
flagstests.AssertDBUpgradeImageFlag(t, cmd, &flags.DBUpgradeImage)
flagstests.AssertCocoFlag(t, cmd, &flags.Coco)
flagstests.AssertHubXmlrpcFlag(t, cmd, &flags.HubXmlrpc)
flagstests.AssertSccFlag(t, cmd, &flags.SCC)
flagstests.AssertSCCFlag(t, cmd, &flags.SCC)
flagstests.AssertPodmanInstallFlags(t, cmd, &flags.Podman)
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion mgrpxy/cmd/install/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
type kubernetesProxyInstallFlags struct {
pxy_utils.ProxyImageFlags `mapstructure:",squash"`
Helm kubernetes.HelmFlags
Scc types.SCCCredentials
SCC types.SCCCredentials
}

func newCmd(globalFlags *types.GlobalFlags, run utils.CommandFunc[kubernetesProxyInstallFlags]) *cobra.Command {
Expand Down
4 changes: 2 additions & 2 deletions mgrpxy/cmd/install/kubernetes/kubernetes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ func TestParamsParsing(t *testing.T) {

args = append(args, flagstests.ImageProxyFlagsTestArgs...)
args = append(args, flagstests.ProxyHelmFlagsTestArgs...)
args = append(args, flagstests.SccFlagTestArgs...)
args = append(args, flagstests.SCCFlagTestArgs...)

// Test function asserting that the args are properly parsed
tester := func(globalFlags *types.GlobalFlags, flags *kubernetesProxyInstallFlags,
cmd *cobra.Command, args []string,
) error {
flagstests.AssertProxyImageFlags(t, cmd, &flags.ProxyImageFlags)
flagstests.AssertProxyHelmFlags(t, cmd, &flags.Helm)
flagstests.AssertSccFlag(t, cmd, &flags.Scc)
flagstests.AssertSCCFlag(t, cmd, &flags.SCC)
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion mgrpxy/cmd/install/kubernetes/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func installForKubernetes(globalFlags *types.GlobalFlags,
}

helmArgs := []string{"--set", "ingress=" + clusterInfos.Ingress}
helmArgs, err = shared_kubernetes.AddSccSecret(helmArgs, flags.Helm.Proxy.Namespace, &flags.Scc)
helmArgs, err = shared_kubernetes.AddSCCSecret(helmArgs, flags.Helm.Proxy.Namespace, &flags.SCC)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions mgrpxy/cmd/install/podman/podman_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ func TestParamsParsing(t *testing.T) {
}
args = append(args, flagstests.ImageProxyFlagsTestArgs...)
args = append(args, flagstests.PodmanFlagsTestArgs...)
args = append(args, flagstests.SccFlagTestArgs...)
args = append(args, flagstests.SCCFlagTestArgs...)

// Test function asserting that the args are properly parsed
tester := func(globalFlags *types.GlobalFlags, flags *podman.PodmanProxyFlags,
cmd *cobra.Command, args []string,
) error {
flagstests.AssertProxyImageFlags(t, cmd, &flags.ProxyImageFlags)
flagstests.AssertPodmanInstallFlags(t, cmd, &flags.Podman)
flagstests.AssertSccFlag(t, cmd, &flags.SCC)
flagstests.AssertSCCFlag(t, cmd, &flags.SCC)
return nil
}

Expand Down
4 changes: 2 additions & 2 deletions mgrpxy/cmd/support/ptf/podman/podman_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ func TestParamsParsing(t *testing.T) {
"--user", "sccuser",
}

args = append(args, flagstests.SccFlagTestArgs...)
args = append(args, flagstests.SCCFlagTestArgs...)
args = append(args, flagstests.ImageProxyFlagsTestArgs...)

// Test function asserting that the args are properly parsed
tester := func(globalFlags *types.GlobalFlags, flags *podmanPTFFlags,
cmd *cobra.Command, args []string,
) error {
flagstests.AssertSccFlag(t, cmd, &flags.UpgradeFlags.SCC)
flagstests.AssertSCCFlag(t, cmd, &flags.UpgradeFlags.SCC)
flagstests.AssertProxyImageFlags(t, cmd, &flags.UpgradeFlags.ProxyImageFlags)
testutils.AssertEquals(t, "Error parsing --ptf", "ptf123", flags.PTFId)
testutils.AssertEquals(t, "Error parsing --test", "test123", flags.TestID)
Expand Down
4 changes: 2 additions & 2 deletions mgrpxy/cmd/upgrade/podman/podman_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ import (
func TestParamsParsing(t *testing.T) {
args := []string{}

args = append(args, flagstests.SccFlagTestArgs...)
args = append(args, flagstests.SCCFlagTestArgs...)
args = append(args, flagstests.ImageProxyFlagsTestArgs...)
args = append(args, flagstests.PodmanFlagsTestArgs...)

// Test function asserting that the args are properly parsed
tester := func(globalFlags *types.GlobalFlags, flags *podman.PodmanProxyFlags,
cmd *cobra.Command, args []string,
) error {
flagstests.AssertSccFlag(t, cmd, &flags.SCC)
flagstests.AssertSCCFlag(t, cmd, &flags.SCC)
flagstests.AssertPodmanInstallFlags(t, cmd, &flags.Podman)
flagstests.AssertProxyImageFlags(t, cmd, &flags.ProxyImageFlags)
return nil
Expand Down
4 changes: 2 additions & 2 deletions shared/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ data:
return nil
}

// AddSccSecret creates a secret holding the SCC credentials and adds it to the helm args.
func AddSccSecret(helmArgs []string, namespace string, scc *types.SCCCredentials) ([]string, error) {
// AddSCCSecret creates a secret holding the SCC credentials and adds it to the helm args.
func AddSCCSecret(helmArgs []string, namespace string, scc *types.SCCCredentials) ([]string, error) {
if scc.User != "" && scc.Password != "" {
secretName := "scc-credentials"
if err := createDockerSecret(
Expand Down
4 changes: 2 additions & 2 deletions shared/podman/hostinspector.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ func NewHostInspector(scriptDir string) HostInspector {

// HostInspectData are the data returned by the host inspector.
type HostInspectData struct {
SccUsername string `mapstructure:"scc_username"`
SccPassword string `mapstructure:"scc_password"`
SCCUsername string `mapstructure:"scc_username"`
SCCPassword string `mapstructure:"scc_password"`
HasUyuniServer bool `mapstructure:"has_uyuni_server"`
}

Expand Down
4 changes: 2 additions & 2 deletions shared/podman/hostinspector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ has_uyuni_server=true
t.Fatalf("Unexpected error: %s", err)
}

testutils.AssertEquals(t, "Invalid SCC username", "myuser", actual.SccUsername)
testutils.AssertEquals(t, "Invalid SCC password", "mysecret", actual.SccPassword)
testutils.AssertEquals(t, "Invalid SCC username", "myuser", actual.SCCUsername)
testutils.AssertEquals(t, "Invalid SCC password", "mysecret", actual.SCCPassword)
testutils.AssertTrue(t, "HasUyuniServer should be true", actual.HasUyuniServer)
}
4 changes: 2 additions & 2 deletions shared/podman/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import (
//
// It returns an authentication file, a cleanup function and an error.
func PodmanLogin(hostData *HostInspectData, scc types.SCCCredentials) (string, func(), error) {
sccUser := hostData.SccUsername
sccPassword := hostData.SccPassword
sccUser := hostData.SCCUsername
sccPassword := hostData.SCCPassword
if scc.User != "" && scc.Password != "" {
log.Info().Msg(L("SCC credentials parameters will be used. SCC credentials from host will be ignored."))
sccUser = scc.User
Expand Down
4 changes: 2 additions & 2 deletions shared/testutils/flagstests/mgradm_install.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ var InstallFlagsTestArgs = func() []string {
}

args = append(args, MirrorFlagTestArgs...)
args = append(args, SccFlagTestArgs...)
args = append(args, SCCFlagTestArgs...)
args = append(args, ImageFlagsTestArgs...)
args = append(args, CocoFlagsTestArgs...)
args = append(args, HubXmlrpcFlagsTestArgs...)
Expand Down Expand Up @@ -94,7 +94,7 @@ func AssertInstallFlags(t *testing.T, cmd *cobra.Command, flags *shared.InstallF
testutils.AssertEquals(t, "Error parsing --admin-lastName", "adminlast", flags.Admin.LastName)
testutils.AssertEquals(t, "Error parsing --organization", "someorg", flags.Organization)
AssertMirrorFlag(t, cmd, flags.Mirror)
AssertSccFlag(t, cmd, &flags.Scc)
AssertSCCFlag(t, cmd, &flags.SCC)
AssertImageFlag(t, cmd, &flags.Image)
AssertCocoFlag(t, cmd, &flags.Coco)
AssertHubXmlrpcFlag(t, cmd, &flags.HubXmlrpc)
Expand Down
8 changes: 4 additions & 4 deletions shared/testutils/flagstests/scc.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ import (
"github.com/uyuni-project/uyuni-tools/shared/types"
)

// SccFlagTestArgs is the expected values for AssertSccFlag.
var SccFlagTestArgs = []string{
// SCCFlagTestArgs is the expected values for AssertSccFlag.
var SCCFlagTestArgs = []string{
"--scc-user", "mysccuser",
"--scc-password", "mysccpass",
}

// AssertSccFlag checks that all SCC flags are parsed correctly.
func AssertSccFlag(t *testing.T, cmd *cobra.Command, flags *types.SCCCredentials) {
// AssertSCCFlag checks that all SCC flags are parsed correctly.
func AssertSCCFlag(t *testing.T, cmd *cobra.Command, flags *types.SCCCredentials) {
testutils.AssertEquals(t, "Error parsing --scc-user", "mysccuser", flags.User)
testutils.AssertEquals(t, "Error parsing --scc-password", "mysccpass", flags.Password)
}

0 comments on commit a6c3cb9

Please sign in to comment.