[ckan-dev] I've a problem in uploading data to Datastore - command curl

Julio Zinga Suzuki Lopes juliozinga at gmail.com
Tue Jan 24 12:45:25 UTC 2017


Hi,

I'm installing CKAN in an Ubuntu 14.04 machine and I'm following the
official documentation
Ckan and all related software are installed in the same machine.

I've a problem in uploading  data to Datastore via curl.
I believe that the problem is somehow related with user and permissions in
the database.
Upload to Filestore was successful, whoever when I try to upload to
Datastore have the following problems:

Successful consultation as tutorial:
$ curl -X GET "
http://192.168.0.31/api/3/action/datastore_search?resource_id=_table_metadata
"
{"help": "http://192.168.0.31/api/3/action/help_show?name=datastore_search",
"success": true, "result": {"resource_id": "_table_metadata", "fields":
[{"type": "text", "id": "_id"}, {"type": "name", "id": "name"}, {"type":
"oid", "id": "oid"}, {"type": "name", "id": "alias_of"}], "records":
[{"_id": "1fab8662e5772995", "alias_of": "pg_views", "name":
"_table_metadata", "oid": 18109}, {"_id": "21b5fe766665b205", "alias_of":
"pg_tables", "name": "_table_metadata", "oid": 18109}], "_links": {"start":
"/api/3/action/datastore_search?resource_id=_table_metadata", "next":
"/api/3/action/datastore_search?offset=100&resource_id=_table_metadata"},
"total": 2}}

Attempt to create the dataset in the Datastore through the command curl
(tutorial):

curl -X POST http://192.168.0.31/api/3/action/datastore_create -H
"Authorization: {8195d98d-c892-428a-9d9a-ac7061f3a572}" -d '{"resource":
{"package_id": "{data1}"}, "fields": [ {"id": "a"}, {"id": "b"} ],
"records": [ { "a": 1, "b": "xyz"}, {"a": 2, "b": "zzz"} ]}'

{"help": "http://192.168.0.31/api/3/action/help_show?name=datastore_create",
"success": false, "error": {"message": "Access denied: <function
datastore_create at 0x7fa6a0072410> requires an authenticated user",
"__type": "Authorization Error"}}



Some commands previously assigned:

xx at server:~$ sudo ckan datastore set-permissions | sudo -u postgres psql
--set ON_ERROR_STOP=1
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
    LANGUAGE = (unset),
    LC_ALL = (unset),
    LC_CTYPE = "pt_BR.UTF-8",
    LANG = "en_US.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
You are now connected to database "datastore_default" as user "postgres".
REVOKE
REVOKE
GRANT
GRANT
GRANT
GRANT
REVOKE
GRANT
GRANT
GRANT
ALTER DEFAULT PRIVILEGES
xx at server:~$ sudo ckan datastore set-permissions
/*
This script configures the permissions for the datastore.

It ensures that the datastore read-only user will only be able to select
from
the datastore database but has no create/write/edit permission or any
permissions on other databases. You must execute this script as a database
superuser on the PostgreSQL server that hosts your datastore database.

For example, if PostgreSQL is running locally and the "postgres" user has
the
appropriate permissions (as in the default Ubuntu PostgreSQL install), you
can
run:

    paster datastore set-permissions | sudo -u postgres psql

Or, if your PostgreSQL server is remote, you can pipe the permissions script
over SSH:

    paster datastore set-permissions | ssh dbserver sudo -u postgres psql

*/

-- Most of the following commands apply to an explicit database or to the
whole
-- 'public' schema, and could be executed anywhere. But ALTER DEFAULT
-- PERMISSIONS applies to the current database, and so we must be connected
to
-- the datastore DB:
\connect datastore_default

-- revoke permissions for the read-only user
REVOKE CREATE ON SCHEMA public FROM PUBLIC;
REVOKE USAGE ON SCHEMA public FROM PUBLIC;

GRANT CREATE ON SCHEMA public TO "ckan_default";
GRANT USAGE ON SCHEMA public TO "ckan_default";

GRANT CREATE ON SCHEMA public TO "ckan_default";
GRANT USAGE ON SCHEMA public TO "ckan_default";

-- take connect permissions from main db
REVOKE CONNECT ON DATABASE "ckan_default" FROM "datastore_default";

-- grant select permissions for read-only user
GRANT CONNECT ON DATABASE "datastore_default" TO "datastore_default";
GRANT USAGE ON SCHEMA public TO "datastore_default";

-- grant access to current tables and views to read-only user
GRANT SELECT ON ALL TABLES IN SCHEMA public TO "datastore_default";

-- grant access to new tables and views by default
ALTER DEFAULT PRIVILEGES FOR USER "ckan_default" IN SCHEMA public
   GRANT SELECT ON TABLES TO "datastore_default";


xx at server:~$ sudo -u postgres psql -l
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
    LANGUAGE = (unset),
    LC_ALL = (unset),
    LC_CTYPE = "pt_BR.UTF-8",
    LANG = "en_US.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
                                             List of databases
       Name        |    Owner     | Encoding |   Collate   |    Ctype
|        Access privileges
-------------------+--------------+----------+-------------+-------------+----------------------------------
 ckan_default      | ckan_default | UTF8     | en_US.UTF-8 | en_US.UTF-8 |
=Tc/ckan_default                +
                   |              |          |             |             |
ckan_default=CTc/ckan_default
 datastore_default | ckan_default | UTF8     | en_US.UTF-8 | en_US.UTF-8 |
=Tc/ckan_default                +
                   |              |          |             |             |
ckan_default=CTc/ckan_default   +
                   |              |          |             |             |
datastore_default=c/ckan_default
 postgres          | postgres     | UTF8     | en_US.UTF-8 | en_US.UTF-8 |
 template0         | postgres     | UTF8     | en_US.UTF-8 | en_US.UTF-8 |
=c/postgres                     +
                   |              |          |             |             |
postgres=CTc/postgres
 template1         | postgres     | UTF8     | en_US.UTF-8 | en_US.UTF-8 |
=c/postgres                     +
                   |              |          |             |             |
postgres=CTc/postgres
(5 rows)

-- 
-- 
Júlio Zinga Suzuki Lopes
Analista de TI
Instituto Federal da Paraíba
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.okfn.org/pipermail/ckan-dev/attachments/20170124/93c9ccc4/attachment-0002.html>


More information about the ckan-dev mailing list