Skip to content

Commit

Permalink
adapter, cert succ, application, organization have bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
xiao-kong-long committed Nov 27, 2023
1 parent 0a1939a commit 657978a
Show file tree
Hide file tree
Showing 12 changed files with 591 additions and 110 deletions.
65 changes: 49 additions & 16 deletions src/casdoor/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,40 @@


class Adapter:
def __init__(self):
self.owner = ""
self.name = ""
self.createdTime = ""
self.type = ""
self.databaseType = ""
self.host = ""
self.port = 0
self.user = ""
self.password = ""
self.database = ""
self.table = ""
self.tableNamePrefix = ""
self.isEnabled = False
def __init__(self, owner:str='', name:str='',createdTime:str='',table:str='',useSameDb:bool=False,type:str='',databaseType:str='',host:str='',\
port:int=0,user:str='',password:str='',database:str='', tableNamePrefix:str='', isEnabled:bool=False):

self.owner = owner
self.name = name
self.createdTime = createdTime
self.table = table
self.useSameDb = useSameDb
self.type = type
self.databaseType = databaseType
self.host = host
self.port = port
self.user = user
self.password = password
self.database = database
self.tableNamePrefix = tableNamePrefix
self.isEnabled = isEnabled


# previous version

# self.owner = owner
# self.name = name
# self.created_time = created_time
# self.type = type
# self.database_type = database_type
# self.host = host
# self.port = port
# self.user = user
# self.password = password
# self.database = database
# self.table = table
# self.table_name_prefix = table_name_prefix
# self.is_enabled = is_enabled

def __str__(self):
return str(self.__dict__)
Expand All @@ -55,7 +75,13 @@ def get_adapters(self) -> List[Dict]:
"clientSecret": self.client_secret,
}
r = requests.get(url, params)
adapters = r.json()
adapters_json = r.json()['data']
adapters = []

# dict to object
for item in adapters_json:
adapter = Adapter(**item)
adapters.append(adapter)
return adapters

def get_adapter(self, adapter_id: str) -> Dict:
Expand All @@ -72,7 +98,14 @@ def get_adapter(self, adapter_id: str) -> Dict:
"clientSecret": self.client_secret,
}
r = requests.get(url, params)
adapter = r.json()
adapter_json = r.json()['data']

# dict to object
if adapter_json is not None:
adapter = Adapter(**adapter_json)
else:
adapter = None

return adapter

def modify_adapter(self, method: str, adapter: Adapter) -> Dict:
Expand Down
127 changes: 83 additions & 44 deletions src/casdoor/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

from .organization import Organization, ThemeData
from .provider import Provider
from utils.json_utils import CustomEncoder


class ProviderItem:
Expand All @@ -29,9 +30,9 @@ def __init__(self):
self.canSignIn = False
self.canUnlink = False
self.prompted = False
self.alertType = ""
self.signupGroup = ""
self.rule = ""
self.provider = Provider
self.provider = Provider()

def __str__(self):
return str(self.__dict__)
Expand All @@ -47,6 +48,8 @@ def __init__(self):
self.required = False
self.prompted = False
self.rule = ""
self.label = ""
self.placeholder = ""

def __str__(self):
return str(self.__dict__)
Expand All @@ -56,45 +59,62 @@ def to_dict(self) -> dict:


class Application:
def __init__(self):
self.owner = ""
self.name = ""
self.createdTime = ""
self.displayName = ""
self.logo = ""
self.homepageUrl = ""
self.description = ""
self.organization = ""
self.cert = ""
self.enablePassword = False
self.enableSignUp = False
self.enableSigninSession = False
self.enableAutoSignin = False
self.enableCodeSignin = False
self.enableSamlCompress = False
self.enableWebAuthn = False
self.enableLinkWithEmail = False
self.orgChoiceMode = ""
self.samlReplyUrl = ""
self.providers = [ProviderItem]
self.signupItems = [SignupItem]
self.grantTypes = [""]
self.organizationObj = Organization
self.tags = [""]
self.clientId = ""
self.clientSecret = ""
self.redirectUris = [""]
self.tokenFormat = ""
self.expireInHours = 0
self.refreshExpireInHours = 0
self.signupUrl = ""
self.signinUrl = ""
self.forgetUrl = ""
self.affiliationUrl = ""
self.termsOfUse = ""
self.signupHtml = ""
self.signinHtml = ""
self.themeData = ThemeData
def __init__(self, owner:str='', name:str='',createdTime:str='',displayName:str='',logo:str='',homepageUrl:str='',description:str='',organization:str='',\
cert:str='',enablePassword:bool=False,enableSignUp:bool=False,enableSigninSession:bool=False,enableAutoSignin:bool=False,enableCodeSignin:bool=False,\
enableSamlCompress:bool=False,enableSamlC14n10:bool=False,enableWebAuthn:bool=False,enableLinkWithEmail:bool=False,orgChoiceMode:str='',samlReplyUrl:str='',\
providers:List[ProviderItem]=[ProviderItem()],signupItems:List[SignupItem]=[SignupItem()],grantTypes:List[str]=None,organizationObj:Organization=Organization(),\
tags:List[str]=None,clientId:str='',clientSecret:str='',redirectUris:List[str]=None,tokenFormat:str='',expireInHours:int=0,refreshExpireInHours:int=0,\
signupUrl:str='',signinUrl:str='',forgetUrl:str='',affiliationUrl:str='',termsOfUse:str='',signupHtml:str='',signinHtml:str='',themeData:ThemeData=ThemeData(),\
certPublicKey:str='',invitationCodes:List[str]=None, samlAttributes:List[str]=None, formCss:str='', formCssMobile:str='', formOffset:int=0, formSideHtml:str='',\
formBackgroundUrl:str=''):

self.owner = owner
self.name = name
self.createdTime = createdTime
self.displayName = displayName
self.logo = logo
self.homepageUrl = homepageUrl
self.description = description
self.organization = organization
self.cert = cert
self.enablePassword = enablePassword
self.enableSignUp = enableSignUp
self.enableSigninSession = enableSigninSession
self.enableAutoSignin = enableAutoSignin
self.enableCodeSignin = enableCodeSignin
self.enableSamlCompress = enableSamlCompress
self.enableSamlC14n10 = enableSamlC14n10
self.enableWebAuthn = enableWebAuthn
self.enableLinkWithEmail = enableLinkWithEmail
self.orgChoiceMode = orgChoiceMode
self.samlReplyUrl = samlReplyUrl
self.providers = providers
self.signupItems = signupItems
self.grantTypes = grantTypes
self.organizationObj = organizationObj
self.tags = tags
self.clientId = clientId
self.clientSecret = clientSecret
self.redirectUris = redirectUris
self.tokenFormat = tokenFormat
self.expireInHours = expireInHours
self.refreshExpireInHours = refreshExpireInHours
self.signupUrl = signupUrl
self.signinUrl = signinUrl
self.forgetUrl = forgetUrl
self.affiliationUrl = affiliationUrl
self.termsOfUse = termsOfUse
self.signupHtml = signupHtml
self.signinHtml = signinHtml
self.themeData = themeData
self.certPublicKey = certPublicKey
self.invitationCodes = invitationCodes
self.samlAttributes = samlAttributes
self.formCss = formCss
self.formCssMobile = formCssMobile
self.formOffset = formOffset
self.formSideHtml = formSideHtml
self.formBackgroundUrl = formBackgroundUrl

def __str__(self):
return str(self.__dict__)
Expand All @@ -117,7 +137,19 @@ def get_applications(self) -> List[Dict]:
"clientSecret": self.client_secret,
}
r = requests.get(url, params)
applications = r.json()
applications_json = r.json()['data']

json_str = json.dumps(applications_json[0], indent=4,sort_keys=True)
print('json_str')
print(json_str)

applications = []

# dict to object
for item in applications_json:
application = Application(**item)
applications.append(application)

return applications

def get_application(self, application_id: str) -> Dict:
Expand All @@ -134,7 +166,11 @@ def get_application(self, application_id: str) -> Dict:
"clientSecret": self.client_secret,
}
r = requests.get(url, params)
application = r.json()
application_dict = r.json()['data']
if application_dict is not None:
application = Application(**application_dict)
else:
application = None
return application

def modify_application(self, method: str, application: Application) -> Dict:
Expand All @@ -145,9 +181,12 @@ def modify_application(self, method: str, application: Application) -> Dict:
"clientId": self.client_id,
"clientSecret": self.client_secret,
}
application_info = json.dumps(application.to_dict())

application_info = json.dumps(application.to_dict(), indent=4, default=lambda x : x.__dict__, sort_keys=True)
print(application_info)
r = requests.post(url, params=params, data=application_info)
response = r.json()

return response

def add_application(self, application: Application) -> Dict:
Expand Down
41 changes: 25 additions & 16 deletions src/casdoor/cert.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,21 @@


class Cert:
def __init__(self):
self.name = ""
self.owner = ""
self.createdTime = ""
self.displayName = ""
self.type = ""
self.scope = ""
self.cryptoAlgorithm = ""
self.bitSize = 0
self.expireInYears = 0
self.certificate = ""
self.privateKey = ""
self.authorityPublicKey = ""
self.authorityRootPublicKey = ""
def __init__(self, owner: str = "", name: str = "", createdTime: str = "", displayName: str = "", type: str = "", scope: str = "", cryptoAlgorithm: str = "", bitSize: int = 0, expireInYears: int = 0, certificate: str = "", privateKey: str = "", authorityPublicKey: str = "", authorityRootPublicKey: str = ""):

self.owner = owner
self.name = name
self.createdTime = createdTime
self.displayName = displayName
self.type = type
self.scope = scope
self.cryptoAlgorithm = cryptoAlgorithm
self.bitSize = bitSize
self.expireInYears = expireInYears
self.certificate = certificate
self.privateKey = privateKey
self.authorityPublicKey = authorityPublicKey
self.authorityRootPublicKey = authorityRootPublicKey

def __str__(self):
return str(self.__dict__)
Expand All @@ -55,7 +56,11 @@ def get_certs(self) -> List[Dict]:
"clientSecret": self.client_secret,
}
r = requests.get(url, params)
certs = r.json()
certs_json = r.json()['data']
certs = []
for item in certs_json:
cert = Cert(**item)
certs.append(cert)
return certs

def get_cert(self, cert_id: str) -> Dict:
Expand All @@ -72,7 +77,11 @@ def get_cert(self, cert_id: str) -> Dict:
"clientSecret": self.client_secret,
}
r = requests.get(url, params)
cert = r.json()
cert_json = r.json()['data']
if cert_json is not None:
cert = Cert(**cert_json)
else:
cert = None
return cert

def modify_cert(self, method: str, cert: Cert) -> Dict:
Expand Down
Loading

0 comments on commit 657978a

Please sign in to comment.