Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix most of golint warnings #301

Merged
merged 1 commit into from
Jan 10, 2019
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 .circleci/check_golint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# golint print issues it found in source files
# count lines with wc and check that N lines was in output
result=$($GOPATH/bin/golint ./... | wc -l)
if [[ $result -gt 142 ]]; then
if [[ $result -gt 10 ]]; then
Lagovas marked this conversation as resolved.
Show resolved Hide resolved
# too many golint issues
echo "Too many golint issues: $result"
exit 1;
Expand Down
10 changes: 5 additions & 5 deletions acra-censor/acra-censor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func TestAllowTables(t *testing.T) {
// now we should allow query that access EMPLOYEE or Customers tables and deny all others
queryIndexesToPass := []int{1, 4, 5}
for _, i := range queryIndexesToPass {
err := censor.HandleQuery(testQueries[i])
err = censor.HandleQuery(testQueries[i])
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -857,15 +857,15 @@ func TestDenyTables(t *testing.T) {
//acracensor should block these queries
queryIndexesToBlock := []int{0, 2, 4, 5, 6}
for _, i := range queryIndexesToBlock {
err := censor.HandleQuery(testQueries[i])
err = censor.HandleQuery(testQueries[i])
if err != common.ErrDenyByTableError {
t.Fatal(err)
}
}
//acracensor should not block these queries
queryIndexesToPass := []int{1, 3}
for _, i := range queryIndexesToPass {
err := censor.HandleQuery(testQueries[i])
err = censor.HandleQuery(testQueries[i])
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -915,7 +915,7 @@ func TestDenySelectPattern(t *testing.T) {
}
//Queries that should be blocked by specified pattern have indexes: [0 .. 12] (all select queries)
for i, query := range testQueries {
err := censor.HandleQuery(query)
err = censor.HandleQuery(query)
if strings.HasPrefix(strings.ToLower(query), "select") {
if err != common.ErrDenyByPatternError {
t.Fatal(err, "Blacklist pattern passed query. \nPattern:", blacklistPattern+"\nQuery:", testQueries[i])
Expand Down Expand Up @@ -1464,7 +1464,7 @@ func TestQueryIgnoring(t *testing.T) {
acraCensor.AddHandler(blacklist)
//should not block
for _, query := range testQueries {
err := acraCensor.HandleQuery(query)
err = acraCensor.HandleQuery(query)
if err != nil {
t.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion acra-censor/common/logging_logic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func TestSerializationOnSameQueries(t *testing.T) {

defer func() {
writer.Free()
err = os.Remove(tmpFile.Name())
err := os.Remove(tmpFile.Name())
if err != nil {
t.Fatal(err)
}
Expand Down
4 changes: 2 additions & 2 deletions benchmarks/cmd/read/direct/direct.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ func main() {
}
fmt.Println("Start benchmark")
startTime := time.Now()
for i := 0; i < config.REQUEST_COUNT; i++ {
id := rand.Intn(config.ROW_COUNT)
for i := 0; i < config.RequestCount; i++ {
id := rand.Intn(config.RowCount)
rows, err := db.Query("SELECT id, data FROM test_raw WHERE id=$1;", &id)
if err != nil {
panic(err)
Expand Down
4 changes: 2 additions & 2 deletions benchmarks/cmd/read/onekey_acrastruct/onekey_acrastruct.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ func main() {
startTime := time.Now()
var rowID int
var data []byte
for i := 0; i < config.REQUEST_COUNT; i++ {
id := rand.Intn(config.ROW_COUNT)
for i := 0; i < config.RequestCount; i++ {
id := rand.Intn(config.RowCount)
err := db.QueryRow("SELECT id, data FROM test_without_zone WHERE id=$1+1;", &id).Scan(&rowID, &data)
if err != nil {
panic(err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ func main() {
startTime := time.Now()
var rowID int
var data []byte
for i := 0; i < config.REQUEST_COUNT; i++ {
id := rand.Intn(config.ROW_COUNT)
for i := 0; i < config.RequestCount; i++ {
id := rand.Intn(config.RowCount)
err := db.QueryRow("SELECT id, data FROM test_raw WHERE id=$1+1;", &id).Scan(&rowID, &data)
if err != nil {
panic(err)
Expand Down
4 changes: 2 additions & 2 deletions benchmarks/cmd/read/zone_acrastruct/zone_acrastruct.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ func main() {
startTime := time.Now()
var rowID int
var zone, data []byte
for i := 0; i < config.REQUEST_COUNT; i++ {
id := rand.Intn(config.ROW_COUNT)
for i := 0; i < config.RequestCount; i++ {
id := rand.Intn(config.RowCount)
err := db.QueryRow("SELECT id, zone, data FROM test_with_zone WHERE id=$1+1;", &id).Scan(&rowID, &zone, &data)
if err != nil {
panic(err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ func main() {
startTime := time.Now()
var rowID int
var zone, data []byte
for i := 0; i < config.REQUEST_COUNT; i++ {
id := rand.Intn(config.ROW_COUNT)
for i := 0; i < config.RequestCount; i++ {
id := rand.Intn(config.RowCount)
err := db.QueryRow("SELECT id, '1111111111111111111', data FROM test_raw WHERE id=$1+1;", &id).Scan(&rowID, &zone, &data)
if err != nil {
panic(err)
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/common/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func RunScripts(scripts []string, db *sql.DB) {
func IsExistsData(tablename string, db *sql.DB) bool {
var count int
db.QueryRow(fmt.Sprintf("SELECT count(*) FROM %s;", tablename)).Scan(&count)
if count == config.ROW_COUNT {
if count == config.RowCount {
fmt.Printf("Data in table '%s' already exists\n", tablename)
return true
}
Expand Down
12 changes: 6 additions & 6 deletions benchmarks/common/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ import (
"path/filepath"
)

// GenerateData generates random data with MAX_DATA_LENGTH
// GenerateData generates random data with MaxDataLength
func GenerateData() ([]byte, error) {
length := rand.Intn(config.MAX_DATA_LENGTH)
length := rand.Intn(config.MaxDataLength)
data := make([]byte, length)
_, err := data_rand.Read(data)
return data, err
Expand All @@ -45,13 +45,13 @@ func GetServerOneKeyPublic() *keys.PublicKey {

// ZoneData stores zone: zoneID and PublicKey
type ZoneData struct {
Id []byte
ID []byte
PublicKey []byte
}

// JSONData stores JSON zone: zoneID and PublicKey
type JSONData struct {
Id string
ID string
PublicKey []byte
}

Expand All @@ -61,7 +61,7 @@ func LoadZones() []*ZoneData {
if err != nil {
panic(err)
}
zones := make([]*ZoneData, config.ZONE_COUNT)
zones := make([]*ZoneData, config.ZoneCount)
dumpedZoneData, err := ioutil.ReadFile(fmt.Sprintf("%v/public_keys.txt", absDir))
if err != nil {
panic(err)
Expand All @@ -72,7 +72,7 @@ func LoadZones() []*ZoneData {
if err != nil {
panic(err)
}
zones[i] = &ZoneData{PublicKey: jsonData.PublicKey, Id: []byte(jsonData.Id)}
zones[i] = &ZoneData{PublicKey: jsonData.PublicKey, ID: []byte(jsonData.ID)}
}
return zones
}
16 changes: 8 additions & 8 deletions benchmarks/config/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
package config

const (
// ROW_COUNT num of rows that will be generated in each write benchmark
ROW_COUNT = 10000
// REQUEST_COUNT num of requests that will be done in each read benchmark
REQUEST_COUNT = 10000
// ZONE_COUNT num of zones which will be generated and used
ZONE_COUNT = 100
// MAX_DATA_LENGTH size of test random data that will be generated and inserted to db (before encrypting)
MAX_DATA_LENGTH = 100 * 1024 // 100 kb
// RowCount num of rows that will be generated in each write benchmark
RowCount = 10000
// RequestCount num of requests that will be done in each read benchmark
RequestCount = 10000
// ZoneCount num of zones which will be generated and used
ZoneCount = 100
// MaxDataLength size of test random data that will be generated and inserted to db (before encrypting)
MaxDataLength = 100 * 1024 // 100 kb
)
20 changes: 10 additions & 10 deletions benchmarks/write/write.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ func GetPublicOneKey() *keys.PublicKey {
return publicKey
}

// GenerateAcrastructRowsOneKey generate ROW_COUNT acrastructs with random data
// GenerateAcrastructRowsOneKey generate RowCount acrastructs with random data
// using <onekey_storage.pub> and insert to db
func GenerateAcrastructRowsOneKey(publicKey *keys.PublicKey, db *sql.DB) {
for count := 0; count < config.ROW_COUNT; count++ {
for count := 0; count < config.RowCount; count++ {
data, err := common.GenerateData()
if err != nil {
panic(err)
Expand All @@ -78,9 +78,9 @@ func GenerateAcrastructRowsOneKey(publicKey *keys.PublicKey, db *sql.DB) {
}
}

// GenerateDataRows generate ROW_COUNT raw random data and insert to db
// GenerateDataRows generate RowCount raw random data and insert to db
func GenerateDataRows(db *sql.DB) {
for count := 0; count < config.ROW_COUNT; count++ {
for count := 0; count < config.RowCount; count++ {
data, err := common.GenerateData()
if err != nil {
panic(err)
Expand All @@ -92,22 +92,22 @@ func GenerateDataRows(db *sql.DB) {
}
}

// GenerateAcrastructWithZone generate ROW_COUNT acrastructs using sequentially
// all ZONE_COUNT zones
// GenerateAcrastructWithZone generate RowCount acrastructs using sequentially
// all ZoneCount zones
func GenerateAcrastructWithZone(db *sql.DB) {
zones := common.LoadZones()
for count := 0; count < config.ROW_COUNT; count++ {
for count := 0; count < config.RowCount; count++ {
data, err := common.GenerateData()
if err != nil {
panic(err)
}

zoneData := zones[count%config.ZONE_COUNT]
acrastruct, err := acrawriter.CreateAcrastruct(data, &keys.PublicKey{Value: zoneData.PublicKey}, zoneData.Id)
zoneData := zones[count%config.ZoneCount]
acrastruct, err := acrawriter.CreateAcrastruct(data, &keys.PublicKey{Value: zoneData.PublicKey}, zoneData.ID)
if err != nil {
panic(err)
}
_, err = db.Exec("INSERT INTO test_with_zone(zone, data) VALUES ($1, $2);", &zoneData.Id, &acrastruct)
_, err = db.Exec("INSERT INTO test_with_zone(zone, data) VALUES ($1, $2);", &zoneData.ID, &acrastruct)
if err != nil {
panic(err)
}
Expand Down
10 changes: 5 additions & 5 deletions cmd/acra-addzone/acra-addzone.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ import (

// Constants used by AcraAddZone util.
var (
// DEFAULT_CONFIG_PATH relative path to config which will be parsed as default
DEFAULT_CONFIG_PATH = utils.GetConfigPathByName("acra-addzone")
SERVICE_NAME = "acra-addzone"
// defaultConfigPath relative path to config which will be parsed as default
defaultConfigPath = utils.GetConfigPathByName("acra-addzone")
serviceName = "acra-addzone"
)

func main() {
Expand All @@ -55,12 +55,12 @@ func main() {

logging.SetLogLevel(logging.LogVerbose)

err := cmd.Parse(DEFAULT_CONFIG_PATH, SERVICE_NAME)
err := cmd.Parse(defaultConfigPath, serviceName)
if err != nil {
log.WithError(err).Errorln("can't parse args")
os.Exit(1)
}
//LoadFromConfig(DEFAULT_CONFIG_PATH)
//LoadFromConfig(defaultConfigPath)
//iniflags.Parse()

output, err := filepath.Abs(*outputDir)
Expand Down
16 changes: 8 additions & 8 deletions cmd/acra-authmanager/acra_authmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ type HashedPasswords map[string]string

// Constants used by AcraAuthManager
var (
DEFAULT_CONFIG_PATH = utils.GetConfigPathByName("acra-authmanager")
SERVICE_NAME = "acra-authmanager"
defaultConfigPath = utils.GetConfigPathByName("acra-authmanager")
serviceName = "acra-authmanager"
)

// Constants used for Argon password manager
Expand All @@ -65,7 +65,7 @@ func (hp HashedPasswords) Bytes() (passwordBytes []byte) {
}

// WriteToFile writes encrypted names and password hashes to file
func (hp HashedPasswords) WriteToFile(file string, keystore *filesystem.FilesystemKeyStore) error {
func (hp HashedPasswords) WriteToFile(file string, keystore *filesystem.KeyStore) error {
key, err := keystore.GetAuthKey(false)
if err != nil {
return err
Expand Down Expand Up @@ -97,7 +97,7 @@ func (hp HashedPasswords) SetPassword(name, password string) (err error) {
return nil
}

func parseHtpasswdFile(file string, keystore *filesystem.FilesystemKeyStore) (passwords HashedPasswords, err error) {
func parseHtpasswdFile(file string, keystore *filesystem.KeyStore) (passwords HashedPasswords, err error) {
htpasswdBytes, err := ioutil.ReadFile(file)
if err != nil {
return
Expand Down Expand Up @@ -140,7 +140,7 @@ func parseHtpasswd(htpasswdBytes []byte) (passwords HashedPasswords, err error)
return
}

func removeUser(file, user string, keystore *filesystem.FilesystemKeyStore) error {
func removeUser(file, user string, keystore *filesystem.KeyStore) error {
passwords, err := parseHtpasswdFile(file, keystore)
if err != nil {
return err
Expand All @@ -153,7 +153,7 @@ func removeUser(file, user string, keystore *filesystem.FilesystemKeyStore) erro
return passwords.WriteToFile(file, keystore)
}

func setPassword(file, name, password string, keystore *filesystem.FilesystemKeyStore) error {
func setPassword(file, name, password string, keystore *filesystem.KeyStore) error {
_, err := os.Stat(file)
passwords := HashedPasswords(map[string]string{})
if err == nil {
Expand All @@ -174,11 +174,11 @@ func main() {
remove := flag.Bool("remove", false, "Remove user")
user := flag.String("user", "", "User")
password := flag.String("password", "", "Password")
filePath := flag.String("file", cmd.DEFAULT_ACRA_AUTH_PATH, "Auth file")
filePath := flag.String("file", cmd.DefaultAcraServerAuthPath, "Auth file")
keysDir := flag.String("keys_dir", keystore.DefaultKeyDirShort, "Folder from which will be loaded keys")
debug := flag.Bool("d", false, "Turn on debug logging")

if err := cmd.Parse(DEFAULT_CONFIG_PATH, SERVICE_NAME); err != nil {
if err := cmd.Parse(defaultConfigPath, serviceName); err != nil {
log.WithError(err).Errorln("can't parse cmd arguments")
os.Exit(1)
}
Expand Down
Loading