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 golangci-lint error and run it in GH actions. #122

Merged
merged 2 commits into from
Aug 21, 2021
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
19 changes: 19 additions & 0 deletions .github/workflows/golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Golangci-Lint

on: [pull_request]
jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2.3.4

- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: 1.16.x

- name: Run golangci-lint
uses: golangci/golangci-lint-action@v2.5.2
with:
version: v1.40
5 changes: 5 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
issues:
exclude-rules:
- linters:
- errcheck
text: "Error return value of `d.Set` is not checked"
2 changes: 1 addition & 1 deletion postgresql/resource_postgresql_default_privileges.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ func grantRoleDefaultPrivileges(txn *sql.Tx, d *schema.ResourceData) error {
pq.QuoteIdentifier(role),
)

if d.Get("with_grant_option").(bool) == true {
if d.Get("with_grant_option").(bool) {
query = query + " WITH GRANT OPTION"
}

Expand Down
4 changes: 2 additions & 2 deletions postgresql/resource_postgresql_grant.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ func createGrantQuery(d *schema.ResourceData, privileges []string) string {
}
}

if d.Get("with_grant_option").(bool) == true {
if d.Get("with_grant_option").(bool) {
query = query + " WITH GRANT OPTION"
}

Expand Down Expand Up @@ -493,7 +493,7 @@ func checkRoleDBSchemaExists(client *Client, d *schema.ResourceData) (bool, erro
if err != nil {
return false, err
}
defer dbTxn.Rollback()
defer deferredRollback(dbTxn)

// Check the schema exists (the SQL connection needs to be on the right database)
exists, err = schemaExists(dbTxn, pgSchema)
Expand Down
4 changes: 3 additions & 1 deletion postgresql/resource_postgresql_role.go
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,9 @@ func readRolePassword(db *DBConnection, d *schema.ResourceData, roleCanLogin boo
if statePassword != "" && !strings.HasPrefix(statePassword, "md5") && !strings.HasPrefix(statePassword, "SCRAM-SHA-256") {
if strings.HasPrefix(rolePassword, "md5") {
hasher := md5.New()
hasher.Write([]byte(statePassword + d.Id()))
if _, err := hasher.Write([]byte(statePassword + d.Id())); err != nil {
return "", err
}
hashedPassword := "md5" + hex.EncodeToString(hasher.Sum(nil))

if hashedPassword == rolePassword {
Expand Down
15 changes: 0 additions & 15 deletions postgresql/resource_postgresql_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -568,16 +568,6 @@ func schemaChangedPolicies(old, new []interface{}) (dropped, added, update, unch
return droppedRoles, addedRoles, updatedRoles, unchangedRoles
}

func schemaPolicyToHCL(s *acl.Schema) map[string]interface{} {
return map[string]interface{}{
schemaPolicyRoleAttr: s.Role,
schemaPolicyCreateAttr: s.GetPrivilege(acl.Create),
schemaPolicyCreateWithGrantAttr: s.GetGrantOption(acl.Create),
schemaPolicyUsageAttr: s.GetPrivilege(acl.Usage),
schemaPolicyUsageWithGrantAttr: s.GetGrantOption(acl.Usage),
}
}

func schemaPolicyToACL(policyMap map[string]interface{}) acl.Schema {
var rolePolicy acl.Schema

Expand Down Expand Up @@ -615,11 +605,6 @@ func generateSchemaID(d *schema.ResourceData, databaseName string) string {
return SchemaID
}

func getSchemaNameFromID(ID string) string {
splitted := strings.Split(ID, ".")
return splitted[0]
}

func getDBSchemaName(d *schema.ResourceData, databaseName string) (string, string, error) {
database := getDatabase(d, databaseName)
schemaName := d.Get(schemaNameAttr).(string)
Expand Down
3 changes: 1 addition & 2 deletions postgresql/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,10 @@ func createTestTables(t *testing.T, dbSuffix string, tables []string, owner stri
// In this case we need to drop table after each test.
return func() {
db, err := sql.Open("postgres", config.connStr(dbName))
defer db.Close()

if err != nil {
t.Fatalf("could not open connection pool for db %s: %v", dbName, err)
}
defer db.Close()

if owner != "" && !config.Superuser {
if _, err := db.Exec(fmt.Sprintf("GRANT %s TO CURRENT_USER", owner)); err != nil {
Expand Down