I’m trying to create many data sources. (and user groups, and users) to properly separate data visibility.
I’d like to do this programmatically .
(so that each user, has their own data_source that logs into the db with a different user.)

i see there is some CLI in the repo, but can’t find documentation for it,
also i am fine with doing this with queries directly,
but so far i’m stuck on encrypted options.
what is it expecting?
(from the code it looks like a jsonified dictionary, but that doesn’t work. )

here’s what i tried – the long line is the problematic one.

 insert into data_sources (
 encrypted_options,
queue_name,
created_at,
id,
name,
scheduled_queue_name,
org_id,
type) VALUES(
'{"dbname": "dbname__", "host": "xyz__", "password": "ppp", "port": 5432, "user": "userAA___"}',
'queries',
current_timestamp,
6,
'test1',
'scheduled_queries',1, 'pg' )

all the other “encrypted options” start with the same prefix eg (modified:) "34767676767… ‘’
but whatever i try to insert any jsonifies dict, it has a different prefix in the data_sources table eg. “42342…”,
and the GUI doesn’t render the data_sources until i delete the latest attempt.

Has anyone ever inserted data sources programatically?

I think it would be easier to use the API. Just POST the data source details.

For example:

curl --request POST \
  --url baseurl/api/data_sources \
  --header 'authorization: Key {admin api key}' \
  --header 'content-type: application/json' \
   --data '{
	"type": "pg",
	"name": "My Postgres Database",
	"options": {
        "host": "127.0.0.1",
	    "database": "mydatabase",
   	    "user": "someuser",
	    "password": "somepassword"     
    }
}'
1 Like

This is AWESOME.
thanks

BTW that should be “dbname” above and not “database

is there more documentation?
i can’t figure out the API for adding a data source to a group, or adding users to a group

ok, so grabbing the traffic on the gui is helpful.
adding a data source to a group is just
/api/groups/11/data_sources with the json being e.g.
{id: 11, data_source_id: 33}