Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.18
go-version: 1.21

- name: Install Staticcheck
run: go install honnef.co/go/tools/cmd/staticcheck@latest
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
module github.com/SUSE/container-suseconnect

go 1.18
go 1.21

require (
github.com/mssola/capture v1.0.0
github.com/urfave/cli/v2 v2.23.5
github.com/urfave/cli/v2 v2.25.7
)

require (
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ github.com/mssola/capture v1.0.0 h1:12SBWBSezcVmPSKgXsztvmQKEyV6KFdsJFywk4rad34=
github.com/mssola/capture v1.0.0/go.mod h1:DjttWXqt7luHAiBDANPVmgXuqulxud7NWB7jmuLezG4=
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/urfave/cli/v2 v2.23.5 h1:xbrU7tAYviSpqeR3X4nEFWUdB/uDZ6DE+HxmRU7Xtyw=
github.com/urfave/cli/v2 v2.23.5/go.mod h1:GHupkWPMM0M/sj1a2b4wUrWBPzazNrIjouW6fmdJLxc=
github.com/urfave/cli/v2 v2.25.7 h1:VAzn5oq403l5pHjc4OhD54+XGO9cdKVL/7lDjF+iKUs=
github.com/urfave/cli/v2 v2.25.7/go.mod h1:8qnjx1vcq5s2/wpsqoZFndg2CE5tNFyrTvS6SinrnYQ=
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU=
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8=
3 changes: 1 addition & 2 deletions internal/installed_product.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"encoding/xml"
"fmt"
"io"
"io/ioutil"
"os"
)

Expand Down Expand Up @@ -56,7 +55,7 @@ func (p InstalledProduct) String() string {
func parseInstalledProduct(reader io.Reader) (InstalledProduct, error) {
// We can ignore this error because of the pre-condition of the `reader`
// being actually readable.
xmlData, _ := ioutil.ReadAll(reader)
xmlData, _ := io.ReadAll(reader)

var p InstalledProduct
err := xml.Unmarshal(xmlData, &p)
Expand Down
3 changes: 1 addition & 2 deletions internal/products.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"crypto/tls"
"encoding/json"
"io"
"io/ioutil"
"log"
"net/http"
"net/url"
Expand Down Expand Up @@ -81,7 +80,7 @@ func fixRepoUrlsForRMT(p *Product) error {
func parseProducts(reader io.Reader) ([]Product, error) {
var products []Product

data, err := ioutil.ReadAll(reader)
data, err := io.ReadAll(reader)
if err != nil {
return products,
loggedError(RepositoryError, "Can't read product information: %v", err.Error())
Expand Down
7 changes: 3 additions & 4 deletions internal/regionsrv/ca.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package regionsrv
import (
"crypto/md5"
"io"
"io/ioutil"
"os"
"os/exec"
"strings"
Expand All @@ -41,7 +40,7 @@ func updateNeeded(contents string) bool {
return true
}

data, err := ioutil.ReadFile(hashFilePath)
data, err := os.ReadFile(hashFilePath)
if err != nil {
return true
}
Expand All @@ -66,7 +65,7 @@ func safeCAFile(cmd commander, contents string) error {
_ = os.Remove(caFilePath)

// Safe the file
err := ioutil.WriteFile(caFilePath, []byte(contents), 0644)
err := os.WriteFile(caFilePath, []byte(contents), 0644)
if err != nil {
return err
}
Expand All @@ -79,7 +78,7 @@ func safeCAFile(cmd commander, contents string) error {
// Safe the new checksum
hash := md5.New()
io.WriteString(hash, contents)
_ = ioutil.WriteFile(hashFilePath, hash.Sum(nil), 0644)
_ = os.WriteFile(hashFilePath, hash.Sum(nil), 0644)

return nil
}
Expand Down
5 changes: 2 additions & 3 deletions internal/regionsrv/ca_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"math/rand"
"os"
"path/filepath"
Expand Down Expand Up @@ -132,7 +131,7 @@ func TestSafeCAFileSuccess(t *testing.T) {
t.Fatalf("Expected error to be nil: %v\n", err)
}

b, _ := ioutil.ReadFile(hashFilePath)
b, _ := os.ReadFile(hashFilePath)
_ = os.Remove(hashFilePath)

hash := md5.New()
Expand All @@ -141,7 +140,7 @@ func TestSafeCAFileSuccess(t *testing.T) {
t.Fatal("Bad checksum")
}

b, _ = ioutil.ReadFile(caFilePath)
b, _ = os.ReadFile(caFilePath)
if string(b) != "valid" {
t.Fatalf("Wrong certificate. Expected 'valid', got '%v'\n", string(b))
}
Expand Down
6 changes: 3 additions & 3 deletions internal/regionsrv/hostsfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ package regionsrv

import (
"fmt"
"io/ioutil"
"log"
"os"
"strings"
)

var hostsFile = "/etc/hosts"

// UpdateHostsFile updates the hosts file with the given hostname and IP.
func UpdateHostsFile(hostname string, ip string) error {
content, err := ioutil.ReadFile(hostsFile)
content, err := os.ReadFile(hostsFile)
if err != nil {
return fmt.Errorf("can't read %s file: %v", hostsFile, err.Error())
}
Expand All @@ -50,7 +50,7 @@ func UpdateHostsFile(hostname string, ip string) error {
newcontent += fmt.Sprintf("%s %s %s\n", ip, hostname, shorthost)
}

err = ioutil.WriteFile(hostsFile, []byte(newcontent), 0644)
err = os.WriteFile(hostsFile, []byte(newcontent), 0644)
if err != nil {
return fmt.Errorf("can't write %s file: %v", hostsFile, err.Error())
}
Expand Down
11 changes: 5 additions & 6 deletions internal/regionsrv/hostsfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package regionsrv

import (
"fmt"
"io/ioutil"
"math/rand"
"os"
"strings"
Expand All @@ -28,14 +27,14 @@ import (
// temporary file instead of the original hosts file inside of the fixtures path
// on these tests.
func copyHostFileToTemp(mode os.FileMode) string {
data, err := ioutil.ReadFile(fixturesPath("hosts"))
data, err := os.ReadFile(fixturesPath("hosts"))
if err != nil {
fmt.Printf("Read file error: %v\n", err)
return ""
}

path := fixturesPath(fmt.Sprintf("testfile%v", rand.Int()))
err = ioutil.WriteFile(path, data, mode)
err = os.WriteFile(path, data, mode)
if err != nil {
fmt.Printf("Write file error: %v\n", err)
return ""
Expand Down Expand Up @@ -77,14 +76,14 @@ func TestUpdateHostsFileSuccessful(t *testing.T) {

defer os.Remove(hostsFile)

before, err := ioutil.ReadFile(hostsFile)
before, err := os.ReadFile(hostsFile)

err = UpdateHostsFile("test-hostname", "1.1.1.1")
if err != nil {
t.Fatalf("Expected a nil error, got: %v", err)
}

after, err := ioutil.ReadFile(hostsFile)
after, err := os.ReadFile(hostsFile)
if err != nil {
t.Fatalf("Expected a nil error, got: %v", err)
}
Expand All @@ -111,7 +110,7 @@ func TestUpdateHostsFileUpdateExistingEntry(t *testing.T) {
t.Fatalf("Expected a nil error, got: %v", err)
}

after, err := ioutil.ReadFile(hostsFile)
after, err := os.ReadFile(hostsFile)
if err != nil {
t.Fatalf("Expected a nil error, got: %v", err)
}
Expand Down
3 changes: 1 addition & 2 deletions internal/regionsrv/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"log"
"net"
"os"
Expand Down Expand Up @@ -81,7 +80,7 @@ func (ts *testServer) close() error {

// Execute fn by suppressing any logger output.
func withSuppressedLog(fn func()) {
log.SetOutput(ioutil.Discard)
log.SetOutput(io.Discard)
fn()
log.SetOutput(os.Stdout)
}
Expand Down
5 changes: 2 additions & 3 deletions internal/regionsrv/zypper_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2020 SUSE LLC. All rights reserved.
// Copyright (c) 2023 SUSE LLC. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -15,7 +15,6 @@
package regionsrv

import (
"io/ioutil"
"os"
"strings"
"testing"
Expand All @@ -25,7 +24,7 @@ import (

func TestParseStdinSuccessful(t *testing.T) {
content := []byte("RESOLVEURL\nkey:value1\nanother:value2")
tmp, err := ioutil.TempFile("", "file")
tmp, err := os.CreateTemp("", "file")
if err != nil {
t.Fatalf("Initialization error: %v", err)
}
Expand Down
11 changes: 7 additions & 4 deletions internal/service.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2015 SUSE LLC. All rights reserved.
// Copyright (c) 2023 SUSE LLC. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -17,7 +17,6 @@ package containersuseconnect
import (
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"regexp"
Expand Down Expand Up @@ -96,15 +95,19 @@ func moduleEnabledInEnv(identifier string) bool {
// moduleEnabledInProductFiles returns true if the provided `identifier` is
// a name of a file in the /etc/product.d/*.prod, otherwise false.
func moduleEnabledInProductFiles(identifier string) bool {
files, err := ioutil.ReadDir("/etc/products.d")
files, err := os.ReadDir("/etc/products.d")
if err != nil {
return false
}
for _, file := range files {
ext := filepath.Ext(file.Name())
info, err := file.Info()
if err != nil {
continue
}
if ext == ".prod" &&
identifier == strings.TrimSuffix(file.Name(), ext) &&
file.Mode()&os.ModeSymlink == 0 {
info.Mode()&os.ModeSymlink == 0 {
return true
}
}
Expand Down
3 changes: 1 addition & 2 deletions internal/subscriptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"crypto/tls"
"encoding/json"
"io"
"io/ioutil"
"log"
"net/http"
"net/url"
Expand Down Expand Up @@ -92,7 +91,7 @@ func requestRegcodes(data SUSEConnectData, credentials Credentials) ([]string, e
func parseSubscriptions(reader io.Reader) ([]Subscription, error) {
var subscriptions []Subscription

data, err := ioutil.ReadAll(reader)
data, err := io.ReadAll(reader)
if err != nil {
return subscriptions, loggedError(SubscriptionError, "Can't read subscriptions information: %v", err.Error())
}
Expand Down