Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
aa.gusti
/
opensipkd-tools
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Settings
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 4a8316ba
authored
Aug 10, 2022
by
aagusti
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
perbaikan rpc error
1 parent
36805cfc
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
71 additions
and
35 deletions
opensipkd/tools/api.py
opensipkd/tools/form_api.py
opensipkd/tools/api.py
View file @
4a8316b
...
...
@@ -6,6 +6,7 @@ import sys
from
datetime
import
datetime
,
date
import
requests
from
pyramid.i18n
import
TranslationStringFactory
from
pyramid_rpc.jsonrpc
import
JsonRpcError
from
opensipkd.tools
import
get_settings
,
get_random_number
...
...
@@ -17,75 +18,87 @@ MSG_OK = 'Data Submitted'
import
logging
log
=
logging
.
getLogger
(
__name__
)
_
=
TranslationStringFactory
(
'json_error'
)
class
JsonRpcOtherError
(
JsonRpcError
):
code
=
-
32604
message
=
'Other Error'
message
=
_
(
'Other Error'
)
# error terkait database
class
JsonRpcNotImplementedError
(
JsonRpcError
):
code
=
-
40000
message
=
"Method Not Implemented"
message
=
_
(
"Method Not Implemented"
)
class
JsonRpcDbUrlNotFoundError
(
JsonRpcError
):
code
=
-
40001
message
=
"DB URL Connection Not Found"
message
=
_
(
"DB URL Connection Not Found"
)
class
JsonRpcDbConnectionError
(
JsonRpcError
):
code
=
-
40002
message
=
"DB Connection Not Found"
message
=
_
(
"DB Connection Not Found"
)
class
JsonRpcDataNotFoundError
(
JsonRpcError
):
code
=
-
40003
message
=
"Error Data Not Found"
message
=
_
(
"Error Data Not Found"
)
class
JsonRpcDataFoundError
(
JsonRpcError
):
code
=
-
40004
message
=
"Error Data Found"
message
=
_
(
"Error Data Already Found"
)
class
JsonRpcInvalidLoginError
(
JsonRpcError
):
code
=
-
41001
message
=
"Invalid RPC User/Password"
message
=
_
(
"Invalid RPC User/Password"
)
class
JsonRpcInvalidNikError
(
JsonRpcError
):
code
=
-
41002
message
=
'NIK Tidak Valid'
message
=
_
(
'Invalid NIK'
)
class
JsonRpcNikFoundError
(
JsonRpcError
):
code
=
-
41003
message
=
'NIK Sudah Ada'
message
=
_
(
'NIK already found'
)
class
JsonRpcMobileFoundError
(
JsonRpcError
):
code
=
-
41004
message
=
'No HP Sudah Digunakan'
message
=
_
(
'Mobile number already found'
)
class
JsonRpcInvalidMobileError
(
JsonRpcError
):
code
=
-
41004
message
=
'No HP Tidak Valid'
message
=
_
(
'Invalid Mobile Number'
)
class
JsonRpcInvalidDataError
(
JsonRpcError
):
code
=
-
41005
message
=
'Data Tidak Valid'
message
=
_
(
'Data Invalid'
)
class
JsonRpcInvalidData
(
JsonRpcError
):
code
=
-
41005
message
=
_
(
'Invalid Data'
)
class
JsonRpcEmailFound
Error
(
JsonRpcError
):
class
JsonRpcEmailFound
(
JsonRpcError
):
code
=
-
41006
message
=
'e-mail Sudah Digunakan'
message
=
_
(
'e-mail already found'
)
class
JsonRpcEmailFoundError
(
JsonRpcEmailFound
):
"""Compatibilty"""
class
JsonRpcInvalidEmailError
(
JsonRpcError
):
code
=
-
41007
message
=
'e-mail Tidak Valid'
message
=
_
(
'Invalid e-mail'
)
class
JsonRpcMailError
(
JsonRpcError
):
...
...
@@ -93,19 +106,27 @@ class JsonRpcMailError(JsonRpcError):
message
=
'Gagal autentikasi mail server'
class
JsonRpcUserFound
Error
(
JsonRpcError
):
class
JsonRpcUserFound
(
JsonRpcError
):
code
=
-
41009
message
=
'User sudah digunakan'
message
=
_
(
'User already found'
)
class
JsonRpcUserFoundError
(
JsonRpcUserFound
):
"""Compatibity """
class
JsonRpcRegisterFailError
(
JsonRpcError
):
code
=
-
41010
message
=
'Gagal Registrasi User'
message
=
_
(
'User Registration Failed '
)
class
JsonRpcProfileFail
Error
(
JsonRpcError
):
class
JsonRpcProfileFail
(
JsonRpcError
):
code
=
-
41011
message
=
'Gagal Update Profile'
message
=
_
(
'Update Profile Failed'
)
class
JsonRpcProfileFailError
(
JsonRpcError
):
"""Portabitas"""
class
JsonRpcGetPasswordError
(
JsonRpcError
):
...
...
@@ -218,7 +239,7 @@ class JsonRpcBillerError(JsonRpcError):
class
JsonRpcProdukNotFoundError
(
JsonRpcError
):
code
=
-
56001
message
=
'Produk Not Found'
message
=
_
(
'Items Not Found'
)
# Biller Status
...
...
@@ -277,15 +298,16 @@ def json_rpc_header(userid, password, key=None):
if
sys
.
version
<
'3'
:
encoded_signature
=
base64
.
encodestring
(
signature
)
.
replace
(
'
\n
'
,
''
)
else
:
encoded_signature
=
base64
.
encodebytes
(
signature
)
.
decode
()
.
replace
(
'
\n
'
,
''
)
encoded_signature
=
base64
.
encodebytes
(
signature
)
.
decode
()
.
replace
(
'
\n
'
,
''
)
return
dict
(
userid
=
userid
,
signature
=
encoded_signature
,
key
=
key
)
def
get_mandatory
(
data
,
values
):
for
value
in
values
:
if
value
not
in
data
or
not
data
[
value
]:
raise
JsonRpcInvalidDataError
(
message
=
"{} Not Found"
.
format
(
value
))
raise
JsonRpcDataInvalid
(
message
=
"{} Not Found"
.
format
(
value
))
def
validate_time
(
request
):
global
lima_menit
...
...
@@ -302,11 +324,13 @@ def validate_time(request):
return
time_stamp
def
get_jsonrpc
(
method
,
params
,
**
kwargs
):
rid
=
kwargs
.
get
(
"id"
)
or
int
(
get_random_number
(
6
))
rid
=
kwargs
.
get
(
"id"
)
or
int
(
get_random_number
(
6
))
return
dict
(
jsonrpc
=
'2.0'
,
method
=
method
,
params
=
params
,
id
=
rid
)
def
send_rpc
(
auth
,
message
):
"""
Digunakan untuk mengirim data dengan methode JSONRPC 2.0 with os-auth
...
...
@@ -330,7 +354,8 @@ def send_rpc(auth, message):
log
.
info
(
"URL:{} timeout:{} detik"
.
format
(
url
,
timeout
))
log
.
warning
(
"REQUEST {}"
.
format
(
data
))
try
:
results
=
requests
.
post
(
url
,
json
=
data
,
headers
=
headers
,
timeout
=
timeout
)
# data=jsondata,
results
=
requests
.
post
(
url
,
json
=
data
,
headers
=
headers
,
timeout
=
timeout
)
# data=jsondata,
except
Exception
as
e
:
log
.
warning
(
str
(
e
))
return
...
...
@@ -342,14 +367,16 @@ def send_rpc(auth, message):
log
.
info
(
"RESPONSE {}"
.
format
(
rows
))
return
rows
##############################
# Web Service Authentication #
##############################
lima_menit
=
300
def
json_serial
(
obj
):
"""JSON serializer for objects not serializable by default json code"""
if
isinstance
(
obj
,
(
datetime
,
date
)):
return
obj
.
isoformat
()
raise
TypeError
(
"Type
%
s not serializable"
%
type
(
obj
))
\ No newline at end of file
raise
TypeError
(
"Type
%
s not serializable"
%
type
(
obj
))
opensipkd/tools/form_api.py
View file @
4a8316b
import
logging
import
traceback
import
colander
import
deform.widget
import
logging
from
icecream
import
ic
log
=
logging
.
getLogger
(
__name__
)
...
...
@@ -38,19 +39,22 @@ field2remove = (
def
form2dict
(
obj
):
d
=
{}
if
getattr
(
obj
,
"__dict__"
,
str
(
obj
)
):
if
hasattr
(
obj
,
"__dict__"
):
for
k
,
v
in
obj
.
__dict__
.
items
():
d
[
k
]
=
v
else
:
d
=
obj
ic
(
d
)
for
k
,
v
in
d
.
items
():
ic
(
k
,
v
,
type
(
v
))
try
:
if
k
in
field2remove
:
d
[
k
]
=
""
elif
type
(
v
)
==
colander
.
Invalid
:
d
[
k
]
=
v
.
asdict
()
elif
v
and
hasattr
(
v
,
"__dict__"
)
and
\
getattr
(
v
,
"__dict__"
,
str
(
v
)):
log
.
debug
(
v
)
elif
type
(
v
)
==
type
(
colander
.
null
):
d
[
k
]
=
None
elif
isinstance
(
v
,
dict
):
d
[
k
]
=
form2dict
(
v
)
elif
isinstance
(
v
,
list
):
lv
=
[]
...
...
@@ -59,6 +63,12 @@ def form2dict(obj):
getattr
(
l
,
"__dict__"
,
str
(
l
)):
lv
.
append
(
form2dict
(
l
))
d
[
k
]
=
lv
elif
v
and
hasattr
(
v
,
"__dict__"
)
and
\
getattr
(
v
,
"__dict__"
,
str
(
v
)):
log
.
debug
(
v
)
d
[
k
]
=
form2dict
(
v
)
elif
getattr
(
v
,
"__dict__"
,
str
(
v
))
==
{}:
d
[
k
]
=
{}
...
...
@@ -71,11 +81,10 @@ def form2dict(obj):
if
k
==
"missing"
and
v
==
colander
.
drop
:
d
[
k
]
=
True
except
Exception
as
e
:
log
.
error
(
e
)
traceback
.
print_exc
()
ic
(
d
)
return
d
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment