postgres

package module
v0.12.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 16, 2022 License: Apache-2.0 Imports: 8 Imported by: 0

README

Permissions Postgres Store

Usage

Make sure that sql service has been deployed.

import (
_ "github.com/aacfactory/fns-contrib/permissions/store/postgres"
)

Config setting

permissions:
  store:
    model: 
      schema: "schema"
      table: "table name"
    policy:
      schema: "schema"
      table: "table name"

DML

Model table

CREATE TABLE "{YOUR SCHEMA}"."{YOUR TABLE}"
(
    "NAME"          character varying(255) NOT NULL PRIMARY KEY,
    "PARENT"        character varying(255) NOT NULL,
    "RESOURCES"     jsonb                 NOT NULL DEFAULT '{}'::jsonb,
    "VERSION"       bigint                NOT NULL DEFAULT 0
) TABLESPACE pg_default;

ALTER TABLE IF EXISTS "YOUR SCHEMA"."YOUR TABLE" OWNER to someone;

Policy table

CREATE TABLE "{YOUR SCHEMA}"."{YOUR TABLE}"
(
    "USER_ID"       character varying(63) NOT NULL PRIMARY KEY,
    "ROLES"         jsonb                 NOT NULL DEFAULT '[]'::jsonb,
    "VERSION"       bigint                NOT NULL DEFAULT 0
) TABLESPACE pg_default;

ALTER TABLE IF EXISTS "YOUR SCHEMA"."YOUR TABLE" OWNER to someone;

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Model  TableName
	Policy TableName
}

type ModelRow

type ModelRow struct {
	Name      string         `col:"NAME,pk" json:"NAME"`
	Parent    string         `col:"PARENT" json:"PARENT"`
	Resources map[string]int `col:"RESOURCES,json" json:"RESOURCES"`
	Version   int64          `col:"VERSION,aol"`
	// contains filtered or unexported fields
}

func (ModelRow) TableName

func (row ModelRow) TableName() (schema string, table string)

type PolicyRow

type PolicyRow struct {
	UserId  string   `col:"USER_ID,pk" json:"USER_ID"`
	Roles   []string `col:"ROLES,json" json:"ROLES"`
	Version int64    `col:"VERSION,aol"`
	// contains filtered or unexported fields
}

func (PolicyRow) TableName

func (row PolicyRow) TableName() (schema string, table string)

type Store

type Store struct {
	Model  TableName
	Policy TableName
	// contains filtered or unexported fields
}

func (*Store) Build

func (store *Store) Build(options permissions.StoreOptions) (err error)

func (*Store) Close

func (store *Store) Close() (err error)

func (*Store) RemoveRole

func (store *Store) RemoveRole(ctx context.Context, name string) (err error)

func (*Store) Role

func (store *Store) Role(ctx context.Context, name string) (role *permissions.Role, err error)

func (*Store) Roles

func (store *Store) Roles(ctx context.Context) (roles []*permissions.Role, err error)

func (*Store) SaveRole

func (store *Store) SaveRole(ctx context.Context, role *permissions.Role) (err error)

func (*Store) UserBindRoles

func (store *Store) UserBindRoles(ctx context.Context, userId string, roleNames ...string) (err error)

func (*Store) UserRoles

func (store *Store) UserRoles(ctx context.Context, userId string) (roles []*permissions.Role, err error)

func (*Store) UserUnbindRoles

func (store *Store) UserUnbindRoles(ctx context.Context, userId string, roleNames ...string) (err error)

type TableName

type TableName struct {
	Schema string
	Table  string
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL