{
"cells": [
{
"cell_type": "markdown",
"id": "4125b834",
"metadata": {},
"source": [
"### Reference Documents:\n",
"SparkMagic \n",
"Spark Doc"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "53d53650",
"metadata": {},
"outputs": [
{
"ename": "ImportError",
"evalue": "cannot import name 'synutils' from 'syn_utils' (/opt/conda/lib/python3.7/site-packages/syn_utils/__init__.py)",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mImportError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0;32mfrom\u001b[0m \u001b[0msyn_utils\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0msynutils\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[0;31mImportError\u001b[0m: cannot import name 'synutils' from 'syn_utils' (/opt/conda/lib/python3.7/site-packages/syn_utils/__init__.py)"
]
}
],
"source": [
"from syn_utils import synutils"
]
},
{
"cell_type": "markdown",
"id": "7c9c7115",
"metadata": {},
"source": [
"---"
]
},
{
"cell_type": "markdown",
"id": "85f1ad0c",
"metadata": {},
"source": [
"## Create Credential\n",
"\n",
"- ability to create credentials in vault for specific user\n",
"- By default login user has **create** permissions within his/her user space ."
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "52b65ffd",
"metadata": {
"scrolled": true
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"login using pchandrasekaran\n"
]
},
{
"ename": "Exception",
"evalue": "status code = [409] Reason = [[test_credentials] credential already exists]",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mException\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 1\u001b[0m synutils.credentials.create(\"test_credentials\", {\n\u001b[1;32m 2\u001b[0m \u001b[0;34m\"test-key\"\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;34m\"test-value\"\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 3\u001b[0;31m \u001b[0;34m\"test-key-1\"\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;34m\"test-value-1\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 4\u001b[0m })\n",
"\u001b[0;32m/opt/conda/lib/python3.7/site-packages/syn_utils/syn_notebook/credential_store/credential_store.py\u001b[0m in \u001b[0;36mcreate\u001b[0;34m(self, credential_store_name, data)\u001b[0m\n\u001b[1;32m 24\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 25\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mcreate\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcredential_store_name\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mstr\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdata\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mdict\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m->\u001b[0m \u001b[0mdict\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 26\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mkey_value_service\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcreate_credential\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0musername\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcredential_store_name\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdata\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 27\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 28\u001b[0m def update(self,\n",
"\u001b[0;32m/opt/conda/lib/python3.7/site-packages/syn_utils/syn_notebook/credential_store/service/key_value_service.py\u001b[0m in \u001b[0;36mcreate_credential\u001b[0;34m(self, username, credential_store_name, data)\u001b[0m\n\u001b[1;32m 21\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 22\u001b[0m \u001b[0mcredential_storage_path\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34mf\"{username}/{credential_store_name}\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 23\u001b[0;31m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmetadata\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcreate_credential_metadata\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mformatted_username\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcredential_store_name\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcredential_storage_path\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 24\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 25\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mkey_value_management\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcreate_credential\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtoken\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mformatted_username\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcredential_store_name\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdata\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;32m/opt/conda/lib/python3.7/site-packages/syn_utils/syn_notebook/credential_store/utils/metadata_utils.py\u001b[0m in \u001b[0;36mcreate_credential_metadata\u001b[0;34m(self, owner, credential_name, path)\u001b[0m\n\u001b[1;32m 21\u001b[0m }\n\u001b[1;32m 22\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 23\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcreate\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mbody\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mdata\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 24\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 25\u001b[0m def update_credential_metadata(self,\n",
"\u001b[0;32m/opt/conda/lib/python3.7/site-packages/syn_utils/syn_notebook/credential_store/utils/metadata_utils.py\u001b[0m in \u001b[0;36mcreate\u001b[0;34m(self, body)\u001b[0m\n\u001b[1;32m 41\u001b[0m def create(self,\n\u001b[1;32m 42\u001b[0m body: dict):\n\u001b[0;32m---> 43\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrest_client\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mexecute_post_request\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34mf\"{self.credential_url}/secrets/metadata\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mbody\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 44\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 45\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mupdate\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtoken\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mstr\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mbody\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mdict\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;32m/opt/conda/lib/python3.7/site-packages/syn_utils/syn_notebook/utils/rest_client.py\u001b[0m in \u001b[0;36mexecute_post_request\u001b[0;34m(self, url, data, **kwargs)\u001b[0m\n\u001b[1;32m 16\u001b[0m \u001b[0mlogging\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0minfo\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"Executing Post Request.. {} \\ndata = {}\"\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mformat\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0murl\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdata\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 17\u001b[0m \u001b[0mresponse\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mrequests\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpost\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0murl\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mjson\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mdata\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mheaders\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mheaders\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 18\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_to_json\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"POST\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mresponse\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0murl\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 19\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 20\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mexecute_get_request\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0murl\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mparams\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mNone\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;32m/opt/conda/lib/python3.7/site-packages/syn_utils/syn_notebook/utils/rest_client.py\u001b[0m in \u001b[0;36m_to_json\u001b[0;34m(self, method, response, url)\u001b[0m\n\u001b[1;32m 42\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mresponse\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mstatus_code\u001b[0m \u001b[0;34m!=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mHTTP_OK\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 43\u001b[0m \u001b[0mresponse_body\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mresponse\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mjson\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 44\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mException\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34mf\"status code = [{response.status_code}] Reason = [{response_body['message']}]\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 45\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mresponse\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mjson\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mException\u001b[0m: status code = [409] Reason = [[test_credentials] credential already exists]"
]
}
],
"source": [
"synutils.credentials.create(\"test_credentials\", {\n",
" \"test-key\": \"test-value\",\n",
" \"test-key-1\": \"test-value-1\"\n",
"})"
]
},
{
"cell_type": "markdown",
"id": "3a40b5a5",
"metadata": {},
"source": [
"---"
]
},
{
"cell_type": "markdown",
"id": "61e1d63e",
"metadata": {},
"source": [
"---"
]
},
{
"cell_type": "markdown",
"id": "5042453e",
"metadata": {},
"source": [
"## Update Multiple Key-Value in Credentials Object\n",
"\n",
"- Ability to update multiple key-value in a Credentials Object\n",
"- By default login user has **update** permissions for all credential objects created by him\n"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "dad7fece",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"login using pchandrasekaran\n",
"read key value store pchandrasekaran/test_credentials\n",
"update key value store {'name': 'test_credentials', 'subfolder': 'pchandrasekaran', 'data': {'test-key': 'test-value10001', 'test-key-1': 'test-value-1', 'test-key10000': 'test-value10002'}}\n"
]
}
],
"source": [
"response = synutils.credentials.update(\"test_credentials\", {\n",
" \"test-key\": \"test-value10001\"\n",
"})"
]
},
{
"cell_type": "markdown",
"id": "269192e8",
"metadata": {},
"source": [
"---"
]
},
{
"cell_type": "markdown",
"id": "3036f37a",
"metadata": {},
"source": [
"---"
]
},
{
"cell_type": "markdown",
"id": "31af3e4c",
"metadata": {},
"source": [
"---"
]
},
{
"cell_type": "markdown",
"id": "eb0b4deb",
"metadata": {},
"source": [
"## Update Single Key-Value in Credentials Object \n",
"\n",
"- Ability to update Single key-value in credentials object\n",
"- The credential object must belongs to the login user"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "e7857dd3",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"login using pchandrasekaran\n",
"read key value store pchandrasekaran/test_credentials\n",
"update key value store {'name': 'test_credentials', 'subfolder': 'pchandrasekaran', 'data': {'test-key': 'test-value10001', 'test-key-1': 'test-value-1', 'test-key10000': 'test-value10002'}}\n"
]
}
],
"source": [
"synutils.credentials.update(credential_store_name=\"test_credentials\", key=\"test-key10000\", value=\"test-value10002\")"
]
},
{
"cell_type": "markdown",
"id": "81aaecdf",
"metadata": {},
"source": [
"---"
]
},
{
"cell_type": "markdown",
"id": "c3b06b90",
"metadata": {},
"source": [
"---"
]
},
{
"cell_type": "markdown",
"id": "9b93098b",
"metadata": {},
"source": [
"## List Credentials\n",
"\n",
"- List credentials for the login user\n",
"- By default login user has **read** permissions on all credential object created by him."
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "93045718",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"+------------------+\n",
"| Credentials |\n",
"+------------------+\n",
"| test_credentials |\n",
"+------------------+\n"
]
}
],
"source": [
"synutils.credentials.list()"
]
},
{
"cell_type": "markdown",
"id": "b45954ef",
"metadata": {},
"source": [
"---"
]
},
{
"cell_type": "markdown",
"id": "5d87d2da",
"metadata": {},
"source": [
"---"
]
},
{
"cell_type": "markdown",
"id": "ba930fe3",
"metadata": {},
"source": [
"## Read Credentials \n",
"\n",
"- Ability to read key-value from credentials object"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "deeeba93",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"login using pchandrasekaran\n",
"read key value store pchandrasekaran/test_credentials\n"
]
},
{
"data": {
"text/plain": [
"{'test-key': 'test-value10001',\n",
" 'test-key-1': 'test-value-1',\n",
" 'test-key10000': 'test-value10002'}"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"synutils.credentials.read(\"test_credentials\")"
]
},
{
"cell_type": "markdown",
"id": "e932b21a",
"metadata": {},
"source": [
"---"
]
},
{
"cell_type": "markdown",
"id": "de147d35",
"metadata": {},
"source": [
"## Read Credentials \n",
"\n",
"- Ability to read value from given key from credentials object"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "5ca297ea",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"login using pchandrasekaran\n",
"read key value store pchandrasekaran/test_credentials\n",
"login using pchandrasekaran\n",
"read key value store pchandrasekaran/test_credentials\n"
]
},
{
"data": {
"text/plain": [
"'test-value-1'"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"synutils.credentials.read(\"test_credentials\", \"test-key-1\")"
]
},
{
"cell_type": "markdown",
"id": "43f1f091",
"metadata": {},
"source": [
"---"
]
},
{
"cell_type": "markdown",
"id": "9ad74521",
"metadata": {},
"source": [
"---"
]
},
{
"cell_type": "markdown",
"id": "7bb2bd0b",
"metadata": {},
"source": [
"## Share Credentials with other users\n",
"- Ability to share credentials with other users "
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "b964411d",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"creating user {'username': 'syntasaadmin'}\n",
"login using syn-credential-store-admin\n",
"fetching user syntasaadmin\n",
"fetching group syn-credential-store-owners from server\n",
"update group {'name': 'syn-credential-store-owners', 'id': '7da69e64-8d28-a186-f0f7-8631799fa112', 'type': 'internal', 'metadata': None, 'policies': ['syn-credential-store-data-policy', 'syn-credential-store-group-policy'], 'memberGroupIds': None, 'memberUserIds': ['b3513f93-38f3-f874-e59e-3a0be69db64f', 'd607cae6-92e1-328e-c680-8f83aed1276a', 'b3513f93-38f3-f874-e59e-3a0be69db64f']}\n",
"create folder access policies\n",
"{\n",
" \"name\": \"syntasaadmin-group-folder-read\",\n",
" \"type\": \"internal\",\n",
" \"memberUserIds\": null,\n",
" \"policies\": [\n",
" \"syntasaadmin-folder-read\"\n",
" ]\n",
"}\n",
"{\n",
" \"name\": \"syntasaadmin-group-folder-create\",\n",
" \"type\": \"internal\",\n",
" \"memberUserIds\": null,\n",
" \"policies\": [\n",
" \"syntasaadmin-folder-create\"\n",
" ]\n",
"}\n",
"{\n",
" \"name\": \"syntasaadmin-group-folder-update\",\n",
" \"type\": \"internal\",\n",
" \"memberUserIds\": null,\n",
" \"policies\": [\n",
" \"syntasaadmin-folder-update\"\n",
" ]\n",
"}\n",
"login using pchandrasekaran\n",
"fetching user syntasaadmin\n",
"fetching group pchandrasekaran-group-test_credentials-read from server\n"
]
},
{
"ename": "AttributeError",
"evalue": "'NoneType' object has no attribute 'append'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0msynutils\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcredentials\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mshare\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"syntasaadmin\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mpermissions\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'read'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcredential_name\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m\"test_credentials\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[0;32m/opt/conda/lib/python3.7/site-packages/syn_utils/syn_notebook/credential_store/credential_store.py\u001b[0m in \u001b[0;36mshare\u001b[0;34m(self, username, permissions, credential_name)\u001b[0m\n\u001b[1;32m 75\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mshare\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0musername\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mstr\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mpermissions\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mlist\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcredential_name\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mstr\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 76\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0muser_management\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcreate_user\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0musername\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 77\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgroup_service\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0madd_user_to_group\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0musername\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0musername\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mpermissions\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcredential_name\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 78\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 79\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mrevoke\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0musername\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mstr\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mpermissions\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mlist\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcredential_name\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mstr\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;32m/opt/conda/lib/python3.7/site-packages/syn_utils/syn_notebook/credential_store/service/groups_service.py\u001b[0m in \u001b[0;36madd_user_to_group\u001b[0;34m(self, owner_name, username, grants, credential_name)\u001b[0m\n\u001b[1;32m 40\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 41\u001b[0m \u001b[0mgroup_name\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgroup_management\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget_folder_group\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mformatted_owner_name\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mgrant\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 42\u001b[0;31m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgroup_management\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0madd_user_to_group\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtoken\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0muser_details\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mgroup_name\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 43\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 44\u001b[0m def remove_user_from_group(self,\n",
"\u001b[0;32m/opt/conda/lib/python3.7/site-packages/syn_utils/syn_notebook/credential_store/utils/groups_utils.py\u001b[0m in \u001b[0;36madd_user_to_group\u001b[0;34m(self, token, user_details, group_name)\u001b[0m\n\u001b[1;32m 63\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 64\u001b[0m \u001b[0mmembers_user_ids\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mlist\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mowners_group\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'memberUserIds'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mlist\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 65\u001b[0;31m \u001b[0mmembers_user_ids\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mappend\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0muser_details\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'entityId'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 66\u001b[0m \u001b[0mowners_group\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'memberUserIds'\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mmembers_user_ids\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 67\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mAttributeError\u001b[0m: 'NoneType' object has no attribute 'append'"
]
}
],
"source": [
"synutils.credentials.share(\"syntasaadmin\", permissions=['read'], credential_name=\"test_credentials\")"
]
},
{
"cell_type": "markdown",
"id": "b7561b65",
"metadata": {},
"source": [
"---"
]
},
{
"cell_type": "markdown",
"id": "0250e5d6",
"metadata": {},
"source": [
"---"
]
},
{
"cell_type": "markdown",
"id": "3755a688",
"metadata": {},
"source": [
"## Revoke permission for other users\n",
"- Ability to remove permission for other users"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "d6f7c2aa",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"creating user {'username': 'syntasaadmin'}\n",
"login using syn-credential-store-admin\n",
"fetching user syntasaadmin\n",
"fetching group syn-credential-store-owners from server\n",
"update group {'name': 'syn-credential-store-owners', 'id': '7da69e64-8d28-a186-f0f7-8631799fa112', 'type': 'internal', 'metadata': None, 'policies': ['syn-credential-store-data-policy', 'syn-credential-store-group-policy'], 'memberGroupIds': None, 'memberUserIds': ['6562d4c6-1fa2-0337-ed12-9b7740a7d2ef', 'b3513f93-38f3-f874-e59e-3a0be69db64f', 'd607cae6-92e1-328e-c680-8f83aed1276a', 'b3513f93-38f3-f874-e59e-3a0be69db64f']}\n",
"create folder access policies\n",
"{\n",
" \"name\": \"syntasaadmin-group-folder-read\",\n",
" \"type\": \"internal\",\n",
" \"memberUserIds\": null,\n",
" \"policies\": [\n",
" \"syntasaadmin-folder-read\"\n",
" ]\n",
"}\n",
"{\n",
" \"name\": \"syntasaadmin-group-folder-create\",\n",
" \"type\": \"internal\",\n",
" \"memberUserIds\": null,\n",
" \"policies\": [\n",
" \"syntasaadmin-folder-create\"\n",
" ]\n",
"}\n",
"{\n",
" \"name\": \"syntasaadmin-group-folder-update\",\n",
" \"type\": \"internal\",\n",
" \"memberUserIds\": null,\n",
" \"policies\": [\n",
" \"syntasaadmin-folder-update\"\n",
" ]\n",
"}\n",
"login using pchandrasekaran\n",
"fetching user syntasaadmin\n",
"fetching group pchandrasekaran-group-test_credentials-read from server\n",
"update group {'name': 'pchandrasekaran-group-test_credentials-read', 'id': '7b6b9c76-a509-3bf5-4fa8-0ca9337f1ef1', 'type': 'internal', 'metadata': None, 'policies': ['pchandrasekaran-test_credentials-read'], 'memberGroupIds': None, 'memberUserIds': []}\n"
]
}
],
"source": [
"synutils.credentials.revoke(\"syntasaadmin\", permissions=['read'], credential_name=\"test_credentials\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "bdce2f60",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Syntasa Kernel",
"language": "python",
"name": "syntasa_kernel"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.6"
},
"syn_metadata": {
"spark_lang_type": "python"
}
},
"nbformat": 4,
"nbformat_minor": 5
}