Skip to content

Commit

Permalink
oracle updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashish S. Maharjan committed Jan 11, 2024
1 parent 1d4ebe9 commit 2c44e79
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 6 deletions.
84 changes: 84 additions & 0 deletions django_project/rdbms/templates/oracle/dba-users.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
{% extends 'base.html' %}

{% load static %}

{% block title %}
DBA Users
{% endblock %}


{% block content %}
<div class="row mt-4 sm-mt-3">
<div class="col-lg-12">
{% if dba_users.result %}
<div class="card">
<div class="card-header">
</div>
<div class="card-body table-responsive">
<table class="table">
<thead>
<tr>
<th></th>
<th>USERNAME</th>
<th>USER_ID</th>
<th>PASSWORD</th>
<th>ACCOUNT_STATUS</th>
<th>LOCK_DATE</th>
<th>EXPIRY_DATE</th>
<th>DEFAULT_TABLESPACE</th>
<th>TEMPORARY_TABLESPACE</th>
<th>LOCAL_TEMP_TABLESPACE</th>
<th>CREATED</th>
<th>PROFILE</th>
<th>INITIAL_RSRC_CONSUMER_GROUP</th>
<th>EXTERNAL_NAME</th>
<th>PASSWORD_VERSIONS</th>
<th>EDITIONS_ENABLED</th>
<th>AUTHENTICATION_TYPE</th>
<th>COMMON</th>
<th>LAST_LOGIN</th>
<th>ORACLE_MAINTAINED</th>
<th>INHERITED</th>
<th>DEFAULT_COLLATION</th>
<th>IMPLICIT</th>
<th>ALL_SHARD</th>
</tr>
{% for i in dba_users.result %}
<tr>
<td></td>
<td>{{ i.USERNAME }}</td>
<td>{{ i.USER_ID }}</td>
<td>{{ i.PASSWORD }}</td>
<td>{{ i.ACCOUNT_STATUS }}</td>
<td>{{ i.LOCK_DATE }}</td>
<td>{{ i.EXPIRY_DATE }}</td>
<td>{{ i.DEFAULT_TABLESPACE }}</td>
<td>{{ i.TEMPORARY_TABLESPACE }}</td>
<td>{{ i.LOCAL_TEMP_TABLESPACE }}</td>
<td>{{ i.CREATED }}</td>
<td>{{ i.PROFILE }}</td>
<td>{{ i.INITIAL_RSRC_CONSUMER_GROUP }}</td>
<td>{{ i.EXTERNAL_NAME }}</td>
<td>{{ i.PASSWORD_VERSIONS }}</td>
<td>{{ i.EDITIONS_ENABLED }}</td>
<td>{{ i.AUTHENTICATION_TYPE }}</td>
<td>{{ i.PROXY_ONLY_CONNECT }}</td>
<td>{{ i.COMMON }}</td>
<td>{{ i.LAST_LOGIN }}</td>
<td>{{ i.ORACLE_MAINTAINED }}</td>
<td>{{ i.INHERITED }}</td>
<td>{{ i.DEFAULT_COLLATION }}</td>
<td>{{ i.IMPLICIT }}</td>
<td>{{ i.ALL_SHARD }}</td>
</tr>
{% endfor %}
</thead>
</table>
</div>
</div>
{% else %}
<div class="alert alert-warning">Not found!</div>
{% endif %}
</div>
</div>
{% endblock content %}
4 changes: 2 additions & 2 deletions django_project/rdbms/templates/rdbms/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ <h6>{{ user }}'s Primary Vault</h6>
</td>
<td class="d-flex justify-content-end">
{% if post.type == 'MySQL' %}
<a href="{% url 'rdbms-manager-detail' post.pk %}" class="btn btn-info btn-sm me-2">
<a href="{% url 'rdbms-mysql-manager-detail' post.pk %}" class="btn btn-info btn-sm me-2">
<i class="bi bi-box-arrow-in-right me-1"></i>Show MySQL
</a>
{% elif post.type == 'Oracle' %}
<a href="{% url 'rdbms-manager-detail' post.pk %}" class="btn btn-info btn-sm me-2">
<a href="{% url 'rdbms-oracle-manager-detail' post.pk %}" class="btn btn-info btn-sm me-2">
<i class="bi bi-box-arrow-in-right me-1"></i>Show Oracle
</a>
{% endif %}
Expand Down
6 changes: 4 additions & 2 deletions django_project/rdbms/urls.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.urls import path
from .views import (
RdbmsManagerDetailView,
RdbmsMySQLManagerDetailView,
RdbmsOracleManagerDetailView,
RdbmsManagerUpdateView,
RdbmsManagerDeleteView,
RdbmsManagerCreateView,
Expand All @@ -11,7 +12,8 @@
)

urlpatterns = [
path('<int:pk>/', RdbmsManagerDetailView.as_view(), name='rdbms-manager-detail'),
path('<int:pk>/', RdbmsMySQLManagerDetailView.as_view(), name='rdbms-mysql-manager-detail'),
path('oracle/<int:pk>/', RdbmsOracleManagerDetailView.as_view(), name='rdbms-oracle-manager-detail'),
path('<int:pk>/edit/', RdbmsManagerUpdateView.as_view(), name='rdbms-manager-update'),
path('<int:pk>/delete/', RdbmsManagerDeleteView.as_view(), name='rdbms-manager-delete'),
path('create', RdbmsManagerCreateView.as_view(), name='rdbms-manager-add'),
Expand Down
27 changes: 26 additions & 1 deletion django_project/rdbms/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from utils.rdbms.tknight_mysql.schema import get_schemas
from utils.rdbms.tknight_mysql.database import get_database
from utils.rdbms.tknight_mysql.table import get_describe_table
from utils.rdbms.tknight_oracle.dba_users import get_dba_users


class RdbmsManagerCreateView(CreateView):
Expand Down Expand Up @@ -40,7 +41,8 @@ class RdbmsManagerListView(ListView):
template_name = 'rdbms/index.html'


class RdbmsManagerDetailView(DetailView):
#Only for MySQL
class RdbmsMySQLManagerDetailView(DetailView):
model = RdbmsManager
extra_context = {'page_title': 'All schemas'}
template_name = 'mysql/detail.html'
Expand All @@ -59,6 +61,29 @@ def get_context_data(self, **kwargs):
#run utils
context['schemas'] = get_schemas(host, username, secret)
return context


#Only for Oracle
class RdbmsOracleManagerDetailView(DetailView):
model = RdbmsManager
extra_context = {'page_title': 'DBA Users'}
template_name = 'oracle/dba-users.html'
context_object_name = 'object'

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
#
pk = self.kwargs['pk']
obj_instance = RdbmsManager.objects.get(pk=pk)

host = obj_instance.host
username = obj_instance.username
secret = obj_instance.password

#run utils
result = get_dba_users(USERNAME=username, SECRET=secret, DSN=host)
context['dba_users'] = result
return context


@csrf_exempt
Expand Down
5 changes: 4 additions & 1 deletion utils/rdbms/tknight_oracle/dba_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@ def get_dba_users(USERNAME, SECRET, DSN):
rows = cursor.fetchall()
columns = [col[0] for col in cursor.description]
result = [dict(zip(columns, row)) for row in rows]
return result
return {
'result': result
}


0 comments on commit 2c44e79

Please sign in to comment.