[docs]classConnector(BaseConnector):NAME="workday_activity_logging"POINTER_PATH="requestTime"LOG_ORDER=CHRONOLOGICAL@propertydefbase_url(self):"""Fetches the Workday unique base url from the configuration. This is required as this is the url required by WD for authentication and API usage. :return: The "base_url" portion of the connector's configuration. """try:returnself.configuration.base_urlexceptAttributeError:returnNone@propertydefclient_id(self):"""Fetches the Workday Client ID from the configuration. This is required as this is an additional authentication element required by WD. :return: The "client_id" portion of the connector's configuration. """try:returnself.configuration.client_idexceptAttributeError:returnNone@propertydefclient_secret(self):"""Fetches the Workday Client Secret from the configuration. This is required as this is an additional authentication element required by WD. :return: The "client_secret" portion of the connector's configuration. """try:returnself.configuration.client_secretexceptAttributeError:returnNone
[docs]defcollect(self):"""Collects all logs from the Workday Audit API. This will first check whether there are any pointers cached to indicate previous collections. If not, the last week of data will be collected. """client=Client(base_url=self.base_url,identity=self.identity,client_id=self.client_id,client_secret=self.client_secret,refresh_token=self.key,)# Use the refresh token to generate a temporary access token.client.get_access_token()# Set cursorcursor=0# If no pointer is stored then a previous run hasn't been performed, so set the# pointer to a week ago.now=datetime.utcnow().strftime(DATESTAMP_FORMAT)try:_=self.pointerexceptNotFoundException:self.pointer=(datetime.utcnow()-timedelta(days=7)).strftime(DATESTAMP_FORMAT)# Get log data from the upstream API. A "from" and "to" datetime query# parameters are required.whileTrue:log=client.get_activity_logging(from_date=self.pointer,to_date=now,cursor=cursor,)# Save this batch of log entries.self.save(log.entries)# Check if we need to continue paging.cursor=log.cursor# type: ignoreifnotcursor:break