postgresql-privileges-granted

Description

Grant a privilege on a Postgresql database.

Variables

Name Type Default Description

db_name

string --

The name of the database to connect to and add the schema. Required

objects

list --

A list of objects to grant permissions to. Required

roles

list --

A list of roles that will be granted permissions. Required

object_type

string table

The type of the object to grant permissions to.

privileges

list ['ALL']

The list of permissions to grant (default: ['ALL']).

schema

string --

Schema that contains the database objects specified via objs. May only be provided if type is table, sequence, function or default_privs. Defaults to public in these cases.

session_role

string --

Switch to session_role after connecting.

Code

doc:
  short_help: Grant a privilege on a Postgresql database.

args:
  db_name:
    doc:
      short_help: The name of the database to connect to and add the schema.
    type: string
    required: true
  db_user:
    doc:
      short_help: The name of the role to set as owner of the schema.
    type: string
    required: true
  object_type:
    doc:
      short_help: The type of the object to grant permissions to.
    type: string
    allowed:
    - database
    - default_privs
    - foreign_data_wrapper
    - foreign_server
    - function
    - group
    - language
    - table
    - tablespace
    - schema
    - sequence
    default: table
    required: true
  objects:
    doc:
      short_help: A list of objects to grant permissions to.
    type: list
    schema:
      type: string
    required: true
    empty: false
    cli:
      param_decls:
      - --object
      - -o
  roles:
    doc:
      short_help: A list of roles that will be granted permissions.
    type: list
    schema:
      type: string
    empty: false
    required: true
    cli:
      param_decls:
      - --role
      - -r
  privileges:
    doc:
      short_help: "The list of permissions to grant (default: ['ALL'])."
    type: list
    schema:
      type: string
    required: true
    empty: false
    default:
    - ALL
    cli:
      param_decls:
      - --privilege
      - -p
  schema:
    doc:
      short_help: Schema that contains the database objects specified via objects.
      help: |
        Schema that contains the database objects specified via objs.
        May only be provided if type is table, sequence, function or default_privs. Defaults to public in these cases.
    type: string
    required: false
  session_role:
    doc:
      short_help: Switch to session_role after connecting.
    type: string
    required: false

frecklets:
- frecklet:
    name: postgresql_privs
    type: ansible-module
    properties:
      idempotent: true
      elevated: true
      internet: false
    desc:
      short: "granting privilege(s) '{{:: privileges | join(',') ::}}' for {{:: object_type\
        \ ::}} {{:: objects | join(',') ::}} on db {{:: db_name ::}}"
  task:
    become: true
    become_user: postgres
  vars:
    db: '{{:: db_name ::}}'
    privs: "{{:: privileges | join(',') ::}}"
    type: '{{:: object_type ::}}'
    objs: "{{:: objects | join(',') ::}}"
    roles: "{{:: roles | join(',') ::}}"
    schema: '{{:: schema ::}}'
    session_role: '{{:: session_role ::}}'
frecklecute postgresql-privileges-granted --help

Usage: frecklecute postgresql-privileges-granted [OPTIONS]

  Grant a privilege on a Postgresql database.

Options:
  --db-name DB_NAME            The name of the database to connect to and add
                               the schema.  [required]
  -o, --object OBJECTS         A list of objects to grant permissions to.
                               [required]
  -r, --role ROLES             A list of roles that will be granted
                               permissions.  [required]
  --object-type OBJECT_TYPE    The type of the object to grant permissions to.
  -p, --privilege PRIVILEGES   The list of permissions to grant (default:
                               ['ALL']).
  --schema SCHEMA              Schema that contains the database objects
                               specified via objects.
  --session-role SESSION_ROLE  Switch to session_role after connecting.
  --help                       Show this message and exit.
# -*- coding: utf-8 -*-


#
# module path: pycklets.postgresql_privileges_granted.PostgresqlPrivilegesGranted
#


from dataclasses import dataclass
from pyckles import AutoPycklet
from typing import *    # noqa

@dataclass
class PostgresqlPrivilegesGranted(AutoPycklet):
    """Grant a privilege on a Postgresql database.

       Args:
         db_name: The name of the database to connect to and add the schema.
         object_type: The type of the object to grant permissions to.
         objects: A list of objects to grant permissions to.
         privileges: The list of permissions to grant (default: ['ALL']).
         roles: A list of roles that will be granted permissions.
         schema: Schema that contains the database objects specified via objects.
         session_role: Switch to session_role after connecting.

    """

    FRECKLET_ID = "postgresql-privileges-granted"

    db_name: str = None
    object_type: str = None
    objects: List = None
    privileges: List = None
    roles: List = None
    schema: str = None
    session_role: str = None


    def __post_init__(self):
        super(PostgresqlPrivilegesGranted, self).__init__(var_names=["db_name", "object_type", "objects", "privileges", "roles", "schema", "session_role"])


frecklet_class = PostgresqlPrivilegesGranted
# -*- coding: utf-8 -*-


#
# module path: pycklets.postgresql_privileges_granted.PostgresqlPrivilegesGranted
#


from pyckles import AutoPycklet

class PostgresqlPrivilegesGranted(AutoPycklet):
    """Grant a privilege on a Postgresql database.

       Args:
         db_name: The name of the database to connect to and add the schema.
         object_type: The type of the object to grant permissions to.
         objects: A list of objects to grant permissions to.
         privileges: The list of permissions to grant (default: ['ALL']).
         roles: A list of roles that will be granted permissions.
         schema: Schema that contains the database objects specified via objects.
         session_role: Switch to session_role after connecting.

    """

    FRECKLET_ID = "postgresql-privileges-granted"

    def __init__(self, db_name=None, object_type="table", objects=None, privileges=['ALL'], roles=None, schema=None, session_role=None):

        super(PostgresqlPrivilegesGranted, self).__init__(var_names=["db_name", "object_type", "objects", "privileges", "roles", "schema", "session_role"])
        self._db_name = db_name
        self._object_type = object_type
        self._objects = objects
        self._privileges = privileges
        self._roles = roles
        self._schema = schema
        self._session_role = session_role

    @property
    def db_name(self):
        return self._db_name

    @db_name.setter
    def db_name(self, db_name):
        self._db_name = db_name

    @property
    def object_type(self):
        return self._object_type

    @object_type.setter
    def object_type(self, object_type):
        self._object_type = object_type

    @property
    def objects(self):
        return self._objects

    @objects.setter
    def objects(self, objects):
        self._objects = objects

    @property
    def privileges(self):
        return self._privileges

    @privileges.setter
    def privileges(self, privileges):
        self._privileges = privileges

    @property
    def roles(self):
        return self._roles

    @roles.setter
    def roles(self, roles):
        self._roles = roles

    @property
    def schema(self):
        return self._schema

    @schema.setter
    def schema(self, schema):
        self._schema = schema

    @property
    def session_role(self):
        return self._session_role

    @session_role.setter
    def session_role(self, session_role):
        self._session_role = session_role



frecklet_class = PostgresqlPrivilegesGranted