-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbatch.py
More file actions
196 lines (127 loc) · 5.05 KB
/
Copy pathbatch.py
File metadata and controls
196 lines (127 loc) · 5.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
###########################################################
#
# Copyright (c) 2005, Southpaw Technology
# All Rights Reserved
#
# PROPRIETARY INFORMATION. This software is proprietary to
# Southpaw Technology, and is not to be reproduced, transmitted,
# or disclosed in any way without written permission.
#
#
#
__all__ = ['Batch', 'XmlRpcInit', 'XmlRpcLogin', 'TacticInit']
import os, sys
from pyasm.common import Environment, Container, Config, Common, SecurityException
from pyasm.search import DbContainer
from security import Security
class Batch(Environment):
'''Environment object that is used for batch operations'''
def __init__(my, project_code=None, login_code=None):
my.set_app_server("batch")
super(Batch,my).__init__()
my.login_code = login_code
# clear the main container
Container.create()
# set this as the environment
if not project_code:
my.context = my.get_default_context()
else:
my.context = project_code
Environment.set_env_object( my )
# set up the security object
security = Security()
Environment.set_security(security)
my._do_login()
site_dir = Environment.get_site_dir()
if site_dir not in sys.path:
sys.path.insert(0, site_dir)
# set the project
from pyasm.biz import Project
if my.context == "batch":
Project.set_project("admin")
else:
Project.set_project(my.context)
DbContainer.commit_thread_sql()
def _do_login(my):
security = Environment.get_security()
security.login_as_batch(my.login_code)
def __del__(my):
# ensure that database connections are always closed
if DbContainer:
DbContainer.close_all()
def get_default_context(my):
return "batch"
# context methods
def set_context(my, context):
my.context = context
def get_context_name(my):
return my.context
def get_command_key(my):
return Common.generate_random_key()
class XmlRpcInit(Environment):
'''Used to authenticate using a ticket from an xmlrpc client'''
def __init__(my, ticket):
super(XmlRpcInit,my).__init__()
my.set_app_server("xmlrpc")
my.ticket = ticket
# clear the main container
#Container.clear()
Environment.set_env_object( my )
# set up the security object
security = Security()
Environment.set_security(security)
my._do_login()
def _do_login(my):
security = Environment.get_security()
ticket = security.login_with_ticket(my.ticket)
if not ticket:
raise SecurityException("Cannot login with key: %s. Session may have expired." % my.ticket)
class XmlRpcLogin(Environment):
'''Used to login in a user from an xmlrpc client'''
def __init__(my, login_name, password=None):
super(XmlRpcLogin,my).__init__()
my.set_app_server("xmlrpc")
# If the tag <force_lowercase_login> is set to "true"
# in the TACTIC config file,
# then force the login string argument to be lowercase.
# This tag is false by default.
my.login_name = login_name
if Config.get_value("security","force_lowercase_login") == "true":
my.login_name = my.login_name.lower()
my.password = password
# clear the main container
#Container.clear()
Environment.set_env_object( my )
# set up the security object
security = Security()
Environment.set_security(security)
my._do_login()
def _do_login(my):
security = Environment.get_security()
require_password = Config.get_value("security", "api_require_password")
api_password = Config.get_value("security", "api_password")
# the xmlrpc login can be overridden to not require a password
if require_password == "false":
security.login_user_without_password(my.login_name, expiry="NULL")
elif api_password:
if api_password == my.password:
security.login_user_without_password(my.login_name, expiry="NULL")
else:
# if api password is incorrect, still try and authenticate with
# user's password
security.login_user(my.login_name, my.password, expiry="NULL")
else:
security.login_user(my.login_name, my.password, expiry="NULL")
if not security.is_logged_in():
raise SecurityException("Cannot login as user: %s." % my.login_name)
class TacticInit(Environment):
'''Environment object that is used for Tactic Initiation'''
def __init__(my, ticket=None):
super(TacticInit,my).__init__()
my.ticket = ticket
# create the main container
Container.create()
Environment.set_env_object( my )
# set up the security object
security = Security()
Environment.set_security(security)