Categorygithub.com/sean-/postgresql-acl
modulepackage
0.0.0-20161225120419-d10489e5d217
Repository: https://github.com/sean-/postgresql-acl.git
Documentation: pkg.go.dev

# README

postgresql-acl

acl Library

acl parses PostgreSQL's ACL syntax and returns a usable structure. Library documentation is available at https://godoc.org/github.com/sean-/postgresql-acl.

package main

import (
	"fmt"

	"github.com/sean-/postgresql-acl"
)

func structToString() acl.ACL {
	return acl.ACL{
		Role:         "foo",
		GrantedBy:    "bar",
		Privileges:   acl.Usage | acl.Create,
		GrantOptions: acl.Create,
	}
}

func stringToStruct() acl.Schema {
	// Parse an aclitem string
	aclitem, err := acl.Parse("foo=C*U/bar")
	if err != nil {
		panic(fmt.Sprintf("bad: %v", err))
	}

	// Verify that ACL permissions are appropriate for a schema type
	schema, err := acl.NewSchema(aclitem)
	if err != nil {
		panic(fmt.Sprintf("bad: %v", err))
	}

	return schema
}

func main() {
	fmt.Printf("ACL Struct to String: %+q\n", structToString().String())
	fmt.Printf("ACL String to Struct: %#v\n", stringToStruct().String())
}
ACL Struct to String: "foo=UC*/bar"
ACL String to Struct: "foo=UC*/bar"

Supported PostgreSQL aclitem Types

  • column permissions
  • database
  • domain
  • foreign data wrappers
  • foreign server
  • function
  • language
  • large object
  • schema
  • sequences
  • table
  • table space
  • type

Notes

The output from String() should match the ordering of characters in aclitem.

The target of each of these ACLs (e.g. schema name, table name, etc) is not contained within PostgreSQLs aclitem and it is expected this value is managed elsewhere in your object model.

Arrays of aclitem are supposed to be iterated over by the caller. For example:

const schema = "public"
var name, owner string
var acls []string
err := conn.QueryRow("SELECT n.nspname, pg_catalog.pg_get_userbyid(n.nspowner), COALESCE(n.nspacl, '{}'::aclitem[])::TEXT[] FROM pg_catalog.pg_namespace n WHERE n.nspname = $1", schema).Scan(&name, &owner, pq.Array(&acls))
if err == nil {
    for _, acl := range acls {
        acl, err = pgacl.NewSchema(acl)
        if err != nil {
            return err
        }
        // ...
    }
}

# Functions

NewColumn parses an ACL object and returns a Column object.
NewDatabase parses an ACL object and returns a Database object.
NewDomain parses an ACL object and returns a Domain object.
NewForeignDataWrapper parses an ACL object and returns a ForeignDataWrapper object.
NewForeignServer parses an ACL object and returns a ForeignServer object.
NewFunction parses an ACL object and returns a Function object.
NewLanguage parses an ACL object and returns a Language object.
NewLargeObject parses an ACL object and returns a LargeObject object.
NewSchema parses an ACL object and returns a Schema object.
NewSequence parses a PostgreSQL ACL string for a sequence and returns a Sequence object.
NewTable parses a PostgreSQL ACL string for a table and returns a Table object.
NewTablespace parses an ACL object and returns a Tablespace object.
NewType parses an ACL object and returns a Type object.
Parse parses a PostgreSQL aclitem string and returns an ACL.

# Constants

See postgresql/src/include/utils/acl.h for inspiration.
See postgresql/src/include/utils/acl.h for inspiration.
See postgresql/src/include/utils/acl.h for inspiration.
See postgresql/src/include/utils/acl.h for inspiration.
Ordering taken from postgresql/src/include/nodes/parsenodes.h.
See postgresql/src/include/utils/acl.h for inspiration.
See postgresql/src/include/utils/acl.h for inspiration.
See postgresql/src/include/utils/acl.h for inspiration.
See postgresql/src/include/utils/acl.h for inspiration.
See postgresql/src/include/utils/acl.h for inspiration.
See postgresql/src/include/utils/acl.h for inspiration.
See postgresql/src/include/utils/acl.h for inspiration.
See postgresql/src/include/utils/acl.h for inspiration.

# Structs

ACL represents a single PostgreSQL `aclitem` entry.
Column models the privileges of a column aclitem.
Database models the privileges of a database aclitem.
Domain models the privileges of a domain aclitem.
ForeignDataWrapper models the privileges of a domain aclitem.
ForeignServer models the privileges of a foreign server aclitem.
Function models the privileges of a function aclitem.
Language models the privileges of a language aclitem.
LargeObject models the privileges of a large object aclitem.
Schema models the privileges of a schema aclitem.
Sequence models the privileges of a sequence aclitem.
Table models the privileges of a table aclitem.
Tablespace models the privileges of a tablespace aclitem.
Type models the privileges of a type aclitem.

# Type aliases

Privileges represents a PostgreSQL ACL bitmask.