def sendUpdate(self, infodict=None, time=None): # make json if not self.update_uri: return token = nicoskeystore.getCredential(self.tokenid) if not token: return if infodict is None: infodict = self.getDaemonInfo() paramdict = {self.infokey: json.dumps(infodict), 'token': token} append = '' if '?' not in self.update_uri: append = '?' elif not self.update_uri[-1] == '&': append = '&' update_string = self.update_uri + append update_string += urllib.parse.urlencode(paramdict) try: urllib.request.urlopen(update_string) self.log.debug('update sent successfully for %s', infodict.get('service', 'base')) except Exception: self.log.debug('cannot send version information! (tried:\n%r\n)', update_string, exc=True)
def doWriteSampleid(self, value): new_id = DUMMY_SAMPLE_ID # check whether given ID belongs to a sample by trying to add a # measurement entry to the sample database if value is not None: bot = session.experiment.sampledb_botname r = post( session.experiment.sampledb_url + 'objects/', auth=(bot, nicoskeystore.getCredential(bot, 'iffsampledb')), json={ 'action_id': MEASUREMENT_ACTION_ID[session.instrument.name.lower()], 'data': { 'sample': { '_type': 'sample', 'object_id': value } } }) if r.status_code != POST_REQUEST_OK: session.log.error( 'validating sample ID failed (invalid credentials for bot ' 'user %r specified in the NICOS keystore?): %s', bot, r.text, ) elif '(at sample)' in r.json()['message']: session.log.warning( 'given ID (%d) does not represent a ' 'sample', value) else: new_id = value return new_id
def doInit(self, mode): if self.update_uri is None: self.log.warning('No update URI configured, updates will not be ' 'sent') if not nicoskeystore.getCredential(self.tokenid): self.log.warning('No token %s found in keystore, updates will not ' 'be sent' % self.tokenid) BaseCacheClient.doInit(self, mode)
def authenticate(self, username, password): username = username.strip() if not username: raise AuthenticationError('No username, please identify yourself!') # check for exact match (also matches empty password if username # matches) pw = nicoskeystore.getCredential(username, domain=self.userdomain) if pw is None: raise AuthenticationError('Invalid username or password!') for (user, level) in self.access: if user == username: if pw == password: if password == '' and level > USER: # pylint: disable=compare-to-empty-string level = USER # limit passwordless entries to USER return User(username, level) else: raise AuthenticationError('Invalid username or password!') # do not give a hint whether username or password is wrong... raise AuthenticationError('Invalid username or password!')
def authenticate(self, username, password): secret = nicoskeystore.getCredential(self.keystoretoken) error = None try: oauth = OAuth2Session(client=LegacyApplicationClient( client_id=self.clientid)) token = oauth.fetch_token(token_url=self.tokenurl, username=username, password=password, client_id=self.clientid, client_secret=secret) except Exception as err: # this avoids leaking credential details via tracebacks error = str(err) if error: raise AuthenticationError('exception during authenticate(): %s' % error) if not oauth.authorized: raise AuthenticationError('wrong password') return User(username, USER, { 'token': token, 'clientid': self.clientid })
def doInit(self, mode): token = nicoskeystore.getCredential(self.keystoretoken) if not token: raise ConfigurationError('Slack API token missing in keyring') self._slack = slackwebclient(token)
def __init__(self, sink, dataset, detector): BaseDataSinkHandler.__init__(self, sink, dataset, detector) bot = session.experiment.sampledb_botname self._bot_auth = (bot, nicoskeystore.getCredential(bot, 'iffsampledb')) self._measurement_id = None self._user_id = NICOS_USER_ID