Skip to content
Snippets Groups Projects
Commit f65139ba authored by Jono's avatar Jono
Browse files

Migrate to new file utility functions

parent e9c6920e
No related branches found
No related tags found
No related merge requests found
......@@ -7,8 +7,8 @@
package conf
import (
"gitlab.com/elixxir/primitives/utils"
"gopkg.in/yaml.v2"
"io/ioutil"
"reflect"
"testing"
)
......@@ -28,7 +28,7 @@ var ExpectedDatabase = Database{
// has the expected Database object.
func TestDB_UnmarshallingFileEqualsExpected(t *testing.T) {
buf, _ := ioutil.ReadFile("./params.yaml")
buf, _ := utils.ReadFile("./params.yaml")
actual := Params{}
......
......@@ -7,8 +7,8 @@
package conf
import (
"gitlab.com/elixxir/primitives/utils"
"gopkg.in/yaml.v2"
"io/ioutil"
"reflect"
"testing"
)
......@@ -30,7 +30,7 @@ var ExpectedGateways = Gateways{
// has the expected Gateways object.
func TestGateways_UnmarshallingFileEqualsExpected(t *testing.T) {
buf, _ := ioutil.ReadFile("./params.yaml")
buf, _ := utils.ReadFile("./params.yaml")
actual := Params{}
......
......@@ -9,8 +9,8 @@ package conf
import (
"gitlab.com/elixxir/crypto/cyclic"
"gitlab.com/elixxir/crypto/large"
"gitlab.com/elixxir/primitives/utils"
"gopkg.in/yaml.v2"
"io/ioutil"
"reflect"
"testing"
)
......@@ -39,7 +39,7 @@ var ExpectedGroups = Groups{
func TestGroups_UnmarshallingFileEqualsExpected(t *testing.T) {
actual := Params{}
buf, _ := ioutil.ReadFile("./params.yaml")
buf, _ := utils.ReadFile("./params.yaml")
err := yaml.Unmarshal(buf, &actual)
if err != nil {
......@@ -56,7 +56,7 @@ func TestGroups_UnmarshallingFileEqualsExpected(t *testing.T) {
// matches the actualy cyclic group object
func TestGroup_GetCMixValidFingerprint(t *testing.T) {
actual := Params{}
buf, _ := ioutil.ReadFile("./params.yaml")
buf, _ := utils.ReadFile("./params.yaml")
err := yaml.Unmarshal(buf, &actual)
if err != nil {
......@@ -73,7 +73,7 @@ func TestGroup_GetCMixValidFingerprint(t *testing.T) {
// matches the actualy cyclic group object
func TestGroup_GetE2EValidFingerprint(t *testing.T) {
actual := Params{}
buf, _ := ioutil.ReadFile("./params.yaml")
buf, _ := utils.ReadFile("./params.yaml")
err := yaml.Unmarshal(buf, &actual)
if err != nil {
......
......@@ -7,8 +7,8 @@
package conf
import (
"gitlab.com/elixxir/primitives/utils"
"gopkg.in/yaml.v2"
"io/ioutil"
"reflect"
"testing"
)
......@@ -21,7 +21,7 @@ var ExpectedMetrics = Metrics{
// has the expected Database object.
func TestMetrics_UnmarshallingFileEqualsExpected(t *testing.T) {
buf, _ := ioutil.ReadFile("./params.yaml")
buf, _ := utils.ReadFile("./params.yaml")
actual := Params{}
......
......@@ -7,8 +7,8 @@
package conf
import (
"gitlab.com/elixxir/primitives/utils"
"gopkg.in/yaml.v2"
"io/ioutil"
"reflect"
"testing"
)
......@@ -30,7 +30,7 @@ var ExpectedNode = Node{
// has the expected Node object.
func TestNode_UnmarshallingFileEqualsExpected(t *testing.T) {
buf, _ := ioutil.ReadFile("./params.yaml")
buf, _ := utils.ReadFile("./params.yaml")
actual := Params{}
......
......@@ -13,14 +13,13 @@ import (
"github.com/pkg/errors"
jww "github.com/spf13/jwalterweatherman"
"github.com/spf13/viper"
"gitlab.com/elixxir/comms/utils"
"gitlab.com/elixxir/crypto/signature/rsa"
"gitlab.com/elixxir/crypto/tls"
"gitlab.com/elixxir/primitives/circuit"
"gitlab.com/elixxir/primitives/id"
"gitlab.com/elixxir/primitives/utils"
"gitlab.com/elixxir/server/server"
"golang.org/x/crypto/blake2b"
"io/ioutil"
"net"
)
......@@ -124,7 +123,7 @@ func (p *Params) ConvertToDefinition() *server.Definition {
var err error
if p.Node.Paths.Cert != "" {
tlsCert, err = ioutil.ReadFile(utils.GetFullPath(p.Node.Paths.Cert))
tlsCert, err = utils.ReadFile(p.Node.Paths.Cert)
if err != nil {
jww.FATAL.Panicf("Could not load TLS Cert: %+v", err)
......@@ -132,7 +131,7 @@ func (p *Params) ConvertToDefinition() *server.Definition {
}
if p.Node.Paths.Key != "" {
tlsKey, err = ioutil.ReadFile(utils.GetFullPath(p.Node.Paths.Key))
tlsKey, err = utils.ReadFile(p.Node.Paths.Key)
if err != nil {
jww.FATAL.Panicf("Could not load TLS Key: %+v", err)
......@@ -191,7 +190,7 @@ func (p *Params) ConvertToDefinition() *server.Definition {
var GwTlsCerts []byte
if p.Gateways.Paths.Cert != "" {
GwTlsCerts, err = ioutil.ReadFile(utils.GetFullPath(p.Gateways.Paths.Cert))
GwTlsCerts, err = utils.ReadFile(p.Gateways.Paths.Cert)
if err != nil {
jww.FATAL.Panicf("Could not load gateway TLS Cert: %+v", err)
}
......@@ -209,7 +208,7 @@ func (p *Params) ConvertToDefinition() *server.Definition {
var PermTlsCert []byte
if p.Permissioning.Paths.Cert != "" {
PermTlsCert, err = ioutil.ReadFile(utils.GetFullPath(p.Permissioning.Paths.Cert))
PermTlsCert, err = utils.ReadFile(p.Permissioning.Paths.Cert)
if err != nil {
jww.FATAL.Panicf("Could not load permissioning TLS Cert: %+v", err)
......@@ -224,7 +223,7 @@ func (p *Params) ConvertToDefinition() *server.Definition {
jww.FATAL.Panicf("Could not generate RSA key: %+v", err)
} else {
// Get the node's TLS cert
tlsCertPEM, err := ioutil.ReadFile(utils.GetFullPath(p.Node.Paths.Cert))
tlsCertPEM, err := utils.ReadFile(p.Node.Paths.Cert)
if err != nil {
jww.FATAL.Panicf("Could not read tls cert file: %v", err)
}
......@@ -239,7 +238,7 @@ func (p *Params) ConvertToDefinition() *server.Definition {
publicKey = &rsa.PublicKey{PublicKey: *tlsCert.PublicKey.(*gorsa.PublicKey)}
// Get the node's TLS Key
tlsKeyPEM, err := ioutil.ReadFile(utils.GetFullPath(p.Node.Paths.Key))
tlsKeyPEM, err := utils.ReadFile(p.Node.Paths.Key)
if err != nil {
jww.FATAL.Panicf("Could not read tls key file: %v", err)
}
......
......@@ -7,8 +7,8 @@
package conf
import (
"gitlab.com/elixxir/primitives/utils"
"gopkg.in/yaml.v2"
"io/ioutil"
"reflect"
"testing"
)
......@@ -27,7 +27,7 @@ var ExpectedPermissioning = Permissioning{
// has the expected Permissioning object.
func TestPermissioning_UnmarshallingFileEqualsExpected(t *testing.T) {
buf, _ := ioutil.ReadFile("./params.yaml")
buf, _ := utils.ReadFile("./params.yaml")
actual := Params{}
......
......@@ -4,12 +4,11 @@ import (
"encoding/json"
"fmt"
jww "github.com/spf13/jwalterweatherman"
"gitlab.com/elixxir/comms/utils"
"gitlab.com/elixxir/primitives/id"
"gitlab.com/elixxir/primitives/utils"
"gitlab.com/elixxir/server/io"
"gitlab.com/elixxir/server/server"
"gitlab.com/elixxir/server/server/measure"
"io/ioutil"
"strconv"
"strings"
)
......@@ -18,9 +17,6 @@ const (
// Symbol placeholder that specifies where to put a unique identifier in the
// log file name
logFilePlaceholder = "*"
// Log file permissions in octal; user: read/write, group: read, other: read
logFilePermissions = 0644
)
// GatherMetrics retrieves the roundMetrics for each node, converts it to JSON,
......@@ -62,11 +58,8 @@ func saveMetricJSON(jsonData []byte, logFileName string, roundID id.Round) error
path := strings.ReplaceAll(logFileName, logFilePlaceholder,
strconv.FormatUint(uint64(roundID), 10))
// Get the full file path by resolving the "~" character
path = utils.GetFullPath(path)
// Write the JSON data to the specified file
err := ioutil.WriteFile(path, jsonData, logFilePermissions)
err := utils.WriteFile(path, jsonData, utils.FilePerms, utils.DirPerms)
if err != nil {
return fmt.Errorf("failed to write metrics log file %s: %v", path, err)
......
......@@ -4,9 +4,9 @@ import (
"bytes"
"encoding/json"
"gitlab.com/elixxir/primitives/id"
"gitlab.com/elixxir/primitives/utils"
"gitlab.com/elixxir/server/server"
"gitlab.com/elixxir/server/server/measure"
"io/ioutil"
"os"
"reflect"
"strconv"
......@@ -85,7 +85,7 @@ func Test_saveMetricJSON(t *testing.T) {
}
// Check if the data written to the file is correct
if fileData, _ := ioutil.ReadFile(filePath2); !bytes.Equal(fileData, data) {
if fileData, _ := utils.ReadFile(filePath2); !bytes.Equal(fileData, data) {
t.Errorf("Data written by saveMetricJSON() incorrect"+
"\n\texpected: %s\n\treceived: %s", string(data), string(fileData))
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment