Git Product home page Git Product logo

py-postgrest's Introduction

py-postgrest's People

Contributors

james-callahan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

py-postgrest's Issues

Enquiry about Status of Library

Hey!

We are the maintainers of supabase-py which is the python client library for Supabase which is an open source Firebase. Supabase also uses Kong under the hood!

We'd just like to check if this library is actively being used/maintained and we would like to request for the postgrest namespace on PyPI. We are maintaining another postgrest client library and we were are currently using the PyPI namespace postgrest_py . We were hoping to use the postgrest namespace(if not actively used) to complement the convention other libraries realtime , supabase , and gotrue.

Totally understand if you'd prefer to keep the namespace though.

Let us know!

Joel

IP address support

Objects from the python ipaddress module should map to Postgres inet types.

Note that the python shared ipaddress._Base_Address class is private/undocumented

Cannot switch into role before POST requests

So I have a role called web_anon for anonymous requests
and a role called todo_user which basically has insert/delete/update access to the database

This is how I designed my schema

CREATE SCHEMA api;

CREATE TABLE api.users(
    last_name TEXT,
    first_name TEXT,
    user_name TEXT UNIQUE,
    email TEXT UNIQUE,
    has_premium BOOLEAN DEFAULT FALSE,
    date_created TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP,
    user_id BIGINT GENERATED ALWAYS AS IDENTITY 
    (START WITH 10000000 INCREMENT BY 1) PRIMARY KEY
    );

CREATE TABLE api.passwords(
    encrypted_password TEXT,
    ref_user_id BIGINT,
    FOREIGN KEY(ref_user_id) REFERENCES api.users(user_id) ON DELETE CASCADE ON UPDATE CASCADE
    );

CREATE INDEX idx_user_id ON api.users(user_id);
CREATE INDEX idx_user_name ON api.users(user_name);

CREATE ROLE web_anon NOLOGIN;
GRANT web_anon TO postgres;

GRANT USAGE ON schema api TO web_anon;
GRANT SELECT ON api.users TO web_anon;

CREATE ROLE todo_user NOLOGIN;
GRANT todo_user TO postgres;
GRANT USAGE ON schema api To todo_user;
GRANT ALL ON api.users TO todo_user;
GRANT ALL ON api.passwords TO todo_user;

I even checked in the psql the role todo_user has the permissions as expected
So now, I want to make an insert with the python client like

sync def create_user(self, first_name, last_name, username, email, password):
        """Adds a user to the StockTools database"""
        print('receiver end')
        async with postgrest.Client(self.host, default_headers={"role": "todo_user"}) as client:
            try:
                user_insert = await client.insert("users", {'last_name': last_name, 'first_name': first_name,
                                                            'user_name': username, 'email': email},
                                                  returning='representation')
                print('user insert complete')
                print(user_insert)
                await client.insert('passwords', {'encrypted_password': hashlib.sha3_512(password).hexdigest(),
                                                  'ref_user_id': user_insert})
                print('inserted passwords')
            except Exception as err:
                print(err)
                raise CannotManageUserData(err)
        print('user created')

I cannot do this as I get the following error:

401, message='permission denied for table users', url=URL('http://localhost:3000/users')

As far as I can tell I think that the role isnt being switched into todo_user before the post request. Why?
Am I doing anything wrong? pls help me

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.