|
86 | 86 | "\n", |
87 | 87 | "import oracledb\n", |
88 | 88 | "\n", |
89 | | - "# please update with your username, password, hostname and service_name\n", |
90 | | - "# please make sure this user has sufficient privileges to perform all below\n", |
| 89 | + "# Update with your username, password, hostname, and service_name\n", |
91 | 90 | "username = \"\"\n", |
92 | 91 | "password = \"\"\n", |
93 | 92 | "dsn = \"\"\n", |
|
97 | 96 | " print(\"Connection successful!\")\n", |
98 | 97 | "\n", |
99 | 98 | " cursor = conn.cursor()\n", |
100 | | - " cursor.execute(\n", |
101 | | - " \"\"\"\n", |
102 | | - " begin\n", |
103 | | - " -- drop user\n", |
104 | | - " begin\n", |
105 | | - " execute immediate 'drop user testuser cascade';\n", |
106 | | - " exception\n", |
107 | | - " when others then\n", |
108 | | - " dbms_output.put_line('Error setting up user.');\n", |
109 | | - " end;\n", |
110 | | - " execute immediate 'create user testuser identified by testuser';\n", |
111 | | - " execute immediate 'grant connect, unlimited tablespace, create credential, create procedure, create any index to testuser';\n", |
112 | | - " execute immediate 'create or replace directory DEMO_PY_DIR as ''/scratch/hroy/view_storage/hroy_devstorage/demo/orachain''';\n", |
113 | | - " execute immediate 'grant read, write on directory DEMO_PY_DIR to public';\n", |
114 | | - " execute immediate 'grant create mining model to testuser';\n", |
115 | | - "\n", |
116 | | - " -- network access\n", |
117 | | - " begin\n", |
118 | | - " DBMS_NETWORK_ACL_ADMIN.APPEND_HOST_ACE(\n", |
119 | | - " host => '*',\n", |
120 | | - " ace => xs$ace_type(privilege_list => xs$name_list('connect'),\n", |
121 | | - " principal_name => 'testuser',\n", |
122 | | - " principal_type => xs_acl.ptype_db));\n", |
123 | | - " end;\n", |
124 | | - " end;\n", |
125 | | - " \"\"\"\n", |
126 | | - " )\n", |
127 | | - " print(\"User setup done!\")\n", |
128 | | - " cursor.close()\n", |
| 99 | + " try:\n", |
| 100 | + " cursor.execute(\n", |
| 101 | + " \"\"\"\n", |
| 102 | + " begin\n", |
| 103 | + " -- Drop user\n", |
| 104 | + " begin\n", |
| 105 | + " execute immediate 'drop user testuser cascade';\n", |
| 106 | + " exception\n", |
| 107 | + " when others then\n", |
| 108 | + " dbms_output.put_line('Error dropping user: ' || SQLERRM);\n", |
| 109 | + " end;\n", |
| 110 | + " \n", |
| 111 | + " -- Create user and grant privileges\n", |
| 112 | + " execute immediate 'create user testuser identified by testuser';\n", |
| 113 | + " execute immediate 'grant connect, unlimited tablespace, create credential, create procedure, create any index to testuser';\n", |
| 114 | + " execute immediate 'create or replace directory DEMO_PY_DIR as ''/scratch/hroy/view_storage/hroy_devstorage/demo/orachain''';\n", |
| 115 | + " execute immediate 'grant read, write on directory DEMO_PY_DIR to public';\n", |
| 116 | + " execute immediate 'grant create mining model to testuser';\n", |
| 117 | + " \n", |
| 118 | + " -- Network access\n", |
| 119 | + " begin\n", |
| 120 | + " DBMS_NETWORK_ACL_ADMIN.APPEND_HOST_ACE(\n", |
| 121 | + " host => '*',\n", |
| 122 | + " ace => xs$ace_type(privilege_list => xs$name_list('connect'),\n", |
| 123 | + " principal_name => 'testuser',\n", |
| 124 | + " principal_type => xs_acl.ptype_db)\n", |
| 125 | + " );\n", |
| 126 | + " end;\n", |
| 127 | + " end;\n", |
| 128 | + " \"\"\"\n", |
| 129 | + " )\n", |
| 130 | + " print(\"User setup done!\")\n", |
| 131 | + " except Exception as e:\n", |
| 132 | + " print(f\"User setup failed with error: {e}\")\n", |
| 133 | + " finally:\n", |
| 134 | + " cursor.close()\n", |
129 | 135 | " conn.close()\n", |
130 | 136 | "except Exception as e:\n", |
131 | | - " print(\"User setup failed!\")\n", |
132 | | - " cursor.close()\n", |
133 | | - " conn.close()\n", |
| 137 | + " print(f\"Connection failed with error: {e}\")\n", |
134 | 138 | " sys.exit(1)" |
135 | 139 | ] |
136 | 140 | }, |
|
0 commit comments