-
Notifications
You must be signed in to change notification settings - Fork 6
[WIP] Enabling host certificate #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: integration
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| import types | ||
| import os | ||
| import shutil | ||
| import json | ||
| from tornado import web, gen | ||
| from RESTDIRAC.RESTSystem.Base.RESTHandler import WErr, WOK, TmpDir, RESTHandler | ||
|
||
| from RESTDIRAC.ConfigurationSystem.Client.Helpers import RESTConf | ||
|
|
||
| class CSHandler( RESTHandler ): | ||
|
|
||
| ROUTE = "/config/(Sections|Options|Value)" | ||
|
|
||
| @web.asynchronous | ||
| def get( self, reqType ): | ||
| if reqType == "Sections": | ||
| return self.SectionsAction() | ||
| elif reqType == "Options": | ||
| return self.OptionsAction() | ||
| elif reqType == "Value": | ||
| return self.ValueAction() | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't so much get the code, but IIUC, out of the above, only "ValueAction" is implemented.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I need to finish the implementation. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I marked this as a "WIP" (Work In progress) PR, when finished please remove the tag |
||
|
|
||
|
|
||
| @gen.engine | ||
| def ValueAction( self ): | ||
| args = self.request.arguments | ||
| try: | ||
| path = args[ 'ValuePath' ][0] | ||
| except KeyError: | ||
| self.send_error( 400 ) | ||
| return | ||
| condDict = {} | ||
| if 'allOwners' not in self.request.arguments: | ||
| condDict[ 'Owner' ] = self.getUserName() | ||
| result = RESTConf.getValue( path ) | ||
| self.finish( result ) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -75,12 +75,19 @@ def __getGroups( self, DN = False ): | |
| return WErr( 401, "No certificate received to issue a token" ) | ||
| DN = credDict[ 'subject' ] | ||
| if not credDict[ 'validDN' ]: | ||
| return WErr( 401, "Unknown DN %s" % DN ) | ||
| return WErr( 401, "Unknown DN %s" % DN ) | ||
| result = Registry.getGroupsForDN( DN ) | ||
| if not result[ 'OK' ]: | ||
| return WErr( 500, result[ 'Message' ] ) | ||
| return WOK( { 'groups' : result[ 'Value' ] } ) | ||
|
|
||
| def __getHostProperties ( self, group, DN ): | ||
| result = Registry.getPropertiesForEntity( group, dn = DN ) | ||
| if not result: | ||
| return WErr( 500, "Can't get the Property for the host" ) | ||
| return WOK( { 'groups' : result} ) | ||
|
|
||
|
|
||
| def groupsAction( self ): | ||
| result = self.__getGroups() | ||
| if not result.ok: | ||
|
|
@@ -140,7 +147,11 @@ def __clientCredentialsRequest( self ): | |
| if not credDict[ 'validDN' ]: | ||
| return WErr( 401, "Unknown DN %s" % DN ) | ||
| #Check group | ||
| result = self.__getGroups( DN ) | ||
| if credDict.has_key( 'group' ): | ||
|
||
| if credDict['group'] == 'hosts': | ||
| result = self.__getHostProperties( 'hosts', DN ) | ||
| else: | ||
| result = self.__getGroups( DN ) | ||
| if not result.ok: | ||
| return result | ||
| groups = result.data[ 'groups' ] | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| import requests | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The content of this file is a bit too "personal". Please add at least some explanations on what it's for.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll do it. |
||
| import json | ||
| import os | ||
|
|
||
| # The REST server url | ||
| REST_URL = 'https://0.0.0.0:9910' | ||
|
|
||
| ########################################### | ||
| # Get the access token first | ||
|
|
||
| # GET request parameters | ||
| params = {'grant_type':'client_credentials', | ||
| 'group':'TrustedHost', | ||
| 'setup':'LHCb-Certification'} | ||
|
|
||
| # The user certificate, password will be asked for to the user | ||
| # before request submission | ||
| #certificate = ('/home/cinzia/.globus/usercert.pem', | ||
| # '/home/cinzia/.globus/userkey.pem') | ||
|
|
||
|
|
||
| certificate = ('/home/cinzia/devRoot/etc/grid-security/hostcert.pem','/home/cinzia/devRoot/etc/grid-security/hostkey.pem') | ||
| proxies=('/tmp/x509up_u1000','/tmp/x509up_u1000') | ||
|
|
||
| #result = requests.get(REST_URL+"/oauth2/token",params=params,cert=proxies, verify=False) | ||
| result = requests.get(REST_URL+"/oauth2/token",params=params,cert=certificate,verify=False) | ||
|
|
||
|
|
||
| # the output is returned as a json encoded string, decode it here | ||
| resultDict = json.loads( result.text ) | ||
| access_token = resultDict['token'] | ||
|
|
||
| JobHistory = requests.get(REST_URL+'/jobs/history',params={'access_token':access_token}, | ||
| verify=False) | ||
|
|
||
| PilotCommands = requests.get(REST_URL+'/config/Value',params={'access_token':access_token,'ValuePath':'/Operations/LHCb-Certification/Pilot/Commands/BOINC'}, verify=False) | ||
|
|
||
| ######################################## | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
None of the above imports is needed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, right. I need to finish the implementation.
I should have write on the PR "only for discussion" since I did it only to get you know how I was proceeding.