text
stringlengths 0
828
|
---|
raise IndexError('Step is not allowed.')
|
indexes = (index.start, index.stop)
|
else:
|
indexes = (index,)
|
for index in indexes:
|
if index is not None and index < 0:
|
raise IndexError('Negative indexes are not allowed.')"
|
4650,"def _find_pivot_addr(self, index):
|
""""""Inserting by slicing can lead into situation where no addresses are
|
selected. In that case a pivot address has to be chosen so we know
|
where to add characters.
|
""""""
|
if not self.addresses or index.start == 0:
|
return CharAddress('', self.tree, 'text', -1) # string beginning
|
if index.start > len(self.addresses):
|
return self.addresses[-1]
|
return self.addresses[index.start]"
|
4651,"def apply_connectivity_changes(request, add_vlan_action, remove_vlan_action, logger=None):
|
""""""
|
Standard implementation for the apply_connectivity_changes operation
|
This function will accept as an input the actions to perform for add/remove vlan. It implements
|
the basic flow of decoding the JSON connectivity changes requests, and combining the results
|
of the add/remove vlan functions into a result object.
|
:param str request: json string sent from the CloudShell server describing the connectivity changes to perform
|
:param Function -> ConnectivityActionResult remove_vlan_action: This action will be called for VLAN remove operations
|
:param Function -> ConnectivityActionResult add_vlan_action: This action will be called for VLAN add operations
|
:param logger: logger to use for the operation, if you don't provide a logger, a default Python logger will be used
|
:return Returns a driver action result object, this can be returned to CloudShell server by the command result
|
:rtype: DriverResponseRoot
|
""""""
|
if not logger:
|
logger = logging.getLogger(""apply_connectivity_changes"")
|
if request is None or request == '':
|
raise Exception('ConnectivityOperations', 'request is None or empty')
|
holder = connectivity_request_from_json(request)
|
driver_response = DriverResponse()
|
results = []
|
driver_response_root = DriverResponseRoot()
|
for action in holder.actions:
|
logger.info('Action: ', action.__dict__)
|
if action.type == ConnectivityActionRequest.SET_VLAN:
|
action_result = add_vlan_action(action)
|
elif action.type == ConnectivityActionRequest.REMOVE_VLAN:
|
action_result = remove_vlan_action(action)
|
else:
|
continue
|
results.append(action_result)
|
driver_response.actionResults = results
|
driver_response_root.driverResponse = driver_response
|
return driver_response_root"
|
4652,"def check_api_key(email, api_key):
|
""""""Check the API key of the user.""""""
|
table = boto3.resource(""dynamodb"").Table(os.environ['people'])
|
user = table.get_item(Key={'email': email})
|
if not user:
|
return False
|
user = user.get(""Item"")
|
if api_key != user.get('api_key', None):
|
return False
|
return user"
|
4653,"def lambda_handler(event, context):
|
""""""Main handler.""""""
|
email = event.get('email', None)
|
api_key = event.get('api_key', None)
|
if not (api_key or email):
|
msg = ""Missing authentication parameters in your request""
|
return {'success': False, 'message': msg}
|
indicators = list(set(event.get('indicators', list())))
|
if len(indicators) == 0:
|
return {'success': False, 'message': ""No indicators sent in""}
|
user = check_api_key(email, api_key)
|
if not user:
|
return {'success': False, 'message': ""Email or API key was invalid.""}
|
role = check_role(user)
|
if not role:
|
return {'success': False, 'message': ""Account not approved to contribute.""}
|
current_time = datetime.datetime.now().strftime(""%Y-%m-%d %H:%M:%S"")
|
table = boto3.resource(""dynamodb"").Table(os.environ['database'])
|
with table.batch_writer(overwrite_by_pkeys=['indicator']) as batch:
|
for item in indicators:
|
if item == """":
|
continue
|
if len(item) != 32:
|
item = hashlib.md5(item).hexdigest()
|
try:
|
batch.put_item(Item={'indicator': item,
|
'creator': user.get('email'),
|
'datetime': current_time})
|
except Exception as e:
|
logger.error(str(e))
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.