コード例 #1
0
 def init(self, env, serverStartTime, testingMode=False):
     self.curDateTimeOverrideForTesting = None
     self.serverStartTime = serverStartTime
     self.version = readFromEnviroment(env, 'APIAPP_VERSION', None, None)
     apikey = readFromEnviroment(env, 'APIAPP_FIXERIO_APIKEY', None, None)
     self.currencyConverter = CurrencyConverter(self, apikey)
     super(appObjClass, self).init(env)
コード例 #2
0
ファイル: appObj.py プロジェクト: rmetcalf9/dockJob
  def init(self, env, serverStartTime, testingMode = False, objectStoreTestingPopulationHookFn = None):
    try:
      self.minutesBeforeMostRecentCompletionStatusBecomesUnknown = 49 * 60
      self.curDateTimeOverrideForTesting = None
      self.serverStartTime = serverStartTime
      if self.jobExecutor is not None:
        #for testing we init multiple times. We need to stop the thread running in this case
        self.jobExecutor.stopThreadRunning()
        if self.jobExecutor.isAlive():
          self.jobExecutor.join()
        self.jobExecutor = None
      super(appObjClass, self).init(env, serverStartTime, testingMode, serverinfoapiprefix='')
      resetJobsData(self)

      self.userforjobs = readFromEnviroment(env, 'APIAPP_USERFORJOBS', None, None)
      self.groupforjobs = readFromEnviroment(env, 'APIAPP_GROUPFORJOBS', None, None)
      skipUserCheck = readFromEnviroment(env, 'APIAPP_SKIPUSERCHECK', False, [False, True])
      self.jobExecutor = JobExecutorClass(self, skipUserCheck)

      #When we are testing we will launch the loop iterations manually
      if not testingMode:
        self.jobExecutor.start()

      objectStoreConfigJSON = readFromEnviroment(env, 'APIAPP_OBJECTSTORECONFIG', '{}', None)
      objectStoreConfigDict = None
      try:
        if objectStoreConfigJSON != '{}':
          objectStoreConfigDict = json.loads(objectStoreConfigJSON)
      except Exception as err:
        print(err) # for the repr
        print(str(err)) # for just the message
        print(err.args) # the arguments that the exception has been called with.
        raise(InvalidObjectStoreConfigInvalidJSONException)

      fns = {
        'getCurDateTime': self.getCurDateTime
      }
      self.objectStore = createObjectStoreInstance(objectStoreConfigDict, fns)

      if testingMode:
        if objectStoreTestingPopulationHookFn is not None:
          # Give our tests the chance to inject some base data
          objectStoreTestingPopulationHookFn(objectStore = self.objectStore)

      appObj.appData['jobsData'].loadFromObjectStore()
    except Exception as a:
      self.stopThread()
      raise a
コード例 #3
0
def getGatewayInterface(env, appObj):
    APIAPP_GATEWAYINTERFACETYPE = readFromEnviroment(
        env, 'APIAPP_GATEWAYINTERFACECONFIG', '{"Type": "none"}', None)

    gatewayInterfaceTypeConfigDict = None
    try:
        gatewayInterfaceTypeConfigDict = json.loads(
            APIAPP_GATEWAYINTERFACETYPE)
    except Exception as err:
        print("APIAPP_GATEWAYINTERFACECONFIG has invalid JSON")
        print(err)  # for the repr
        print(str(err))  # for just the message
        print(
            err.args)  # the arguments that the exception has been called with.
        raise InvalidGatewayInterfaceConfigException

    if "Type" not in gatewayInterfaceTypeConfigDict:
        print("Type element missing")
        raise InvalidGatewayInterfaceConfigException

    if gatewayInterfaceTypeConfigDict["Type"] == 'none':
        return gi_none(gatewayInterfaceTypeConfigDict, appObj)
    if gatewayInterfaceTypeConfigDict["Type"] == 'kong':
        return gi_kong(gatewayInterfaceTypeConfigDict, appObj)

    print("Gatewat interface type " + gatewayInterfaceTypeConfigDict["Type"] +
          " not found")
    raise InvalidGatewayInterfaceTypeSpecifiedException
コード例 #4
0
ファイル: appObj.py プロジェクト: rmetcalf9/saasTemplate
  def init(self, env, serverStartTime, testingMode = False):
    ##self.setupLogging() Comment in when debugging

    super(appObjClass, self).init(env, serverStartTime, testingMode, serverinfoapiprefix='public/info')

    #This app always needs a JWT key
    if self.APIAPP_JWTSECRET is None:
      print("ERROR - APIAPP_JWTSECRET should always be set")
      raise invalidConfigurationException

    objectStoreConfigJSON = readFromEnviroment(env, 'APIAPP_OBJECTSTORECONFIG', '{}', None)
    objectStoreConfigDict = None
    try:
      if objectStoreConfigJSON != '{}':
        objectStoreConfigDict = json.loads(objectStoreConfigJSON)
    except Exception as err:
      print(err) # for the repr
      print(str(err)) # for just the message
      print(err.args) # the arguments that the exception has been called with.
      raise(InvalidObjectStoreConfigInvalidJSONException)

    self.APIAPP_OBJECTSTOREDETAILLOGGING = readFromEnviroment(
      env=env,
      envVarName='APIAPP_OBJECTSTOREDETAILLOGGING',
      defaultValue='N',
      acceptableValues=['Y', 'N'],
      nullValueAllowed=True
    ).strip()
    if (self.APIAPP_OBJECTSTOREDETAILLOGGING=='Y'):
      print("APIAPP_OBJECTSTOREDETAILLOGGING set to Y - statement logging enabled")

    fns = {
      'getCurDateTime': self.getCurDateTime
    }
    self.objectStore = createObjectStoreInstance(
      objectStoreConfigDict,
      fns,
      detailLogging=(self.APIAPP_OBJECTSTOREDETAILLOGGING=='Y')
    )
コード例 #5
0
    def init(self, env, serverStartTime, testingMode=False):
        self.minutesBeforeMostRecentCompletionStatusBecomesUnknown = 49 * 60
        self.curDateTimeOverrideForTesting = None
        self.serverStartTime = serverStartTime
        if self.jobExecutor is not None:
            #for testing we init multiple times. We need to stop the thread running in this case
            self.jobExecutor.stopThreadRunning()
            if self.jobExecutor.isAlive():
                self.jobExecutor.join()
            self.jobExecutor = None
        super(appObjClass, self).init(env)
        resetJobsData(self)

        self.userforjobs = readFromEnviroment(env, 'APIAPP_USERFORJOBS', None,
                                              None)
        self.groupforjobs = readFromEnviroment(env, 'APIAPP_GROUPFORJOBS',
                                               None, None)
        skipUserCheck = readFromEnviroment(env, 'APIAPP_SKIPUSERCHECK', False,
                                           [False, True])
        self.jobExecutor = JobExecutorClass(self, skipUserCheck)

        #When we are testing we will launch the loop iterations manually
        if not testingMode:
            self.jobExecutor.start()
コード例 #6
0
def readDictFromEnviroment(
  env,
  envVarName,
  defaultValue,
  safeToOutput=False
):
  valueJSON = readFromEnviroment(
    env=env,
    envVarName=envVarName,
    defaultValue=defaultValue,
    acceptableValues=None
  )
  valueDict = None
  try:
    if valueJSON != '{}':
      valueDict = json.loads(valueJSON)
  except Exception as err:
    print("Error parsing JSON for " + envVarName)
    if safeToOutput:
      print("Value:" + valueJSON + ":")
    print(err)  # for the repr
    print(str(err))  # for just the message
    print(err.args)  # the arguments that the exception has been called with.
    raise getInvalidEnvVarParamaterException(envVarName=envVarName, actualValue=None, messageOverride=None)

  if isinstance(valueDict, str):
    # Codfresh container test has problems passing json this deals with it's input
    print(envVarName + " parsing First JSON pass gave string")
    #####print("XXX", valueDict) (This debug comment may display a password)
    valueDict = json.loads(valueDict)

    if not valueDict is None:
      if not isinstance(valueDict, dict):
        print(envVarName + " did not evaluate to a dictionary")
        raise getInvalidEnvVarParamaterException(envVarName=envVarName, actualValue=None, messageOverride=None)

  return valueDict
コード例 #7
0
import logging


print("---------------------------------------")
print("---------------------------------------")
print("---------------------------------------")
print("---------------------------------------")
print("---------------------------------------")
print("Start of main.py\n")

#Configure SQLAlchemy to log all statements
logging.basicConfig()
logging.getLogger('sqlalchemy.engine').setLevel(logging.INFO)

objectStoreConfigJSON = readFromEnviroment(os.environ, 'APIAPP_OBJECTSTORECONFIG', '{}', None)
objectStoreConfigDict = None
try:
  if objectStoreConfigJSON != '{}':
    objectStoreConfigDict = json.loads(objectStoreConfigJSON)
except Exception as err:
  raise err

def getCurDateTime():
  return datetime.datetime.now(pytz.timezone("UTC"))

fns = {
  'getCurDateTime': getCurDateTime
}
objectStoreInstance = createObjectStoreInstance(objectStoreConfigDict, fns)
コード例 #8
0
  def init(self, env, serverStartTime, testingMode = False):
    ##self.setupLogging() Comment in when debugging

    super(appObjClass, self).init(env, serverStartTime, testingMode, serverinfoapiprefix='public/info')
    ##print("appOBj init")

    self.APIAPP_REDIRECTPREFIX = readFromEnviroment(
      env=env,
      envVarName='APIAPP_REDIRECTPREFIX',
      defaultValue=None,
      acceptableValues=None,
      nullValueAllowed=False
    )
    print("APIAPP_REDIRECTPREFIX:", self.APIAPP_REDIRECTPREFIX)
    if self.APIAPP_REDIRECTPREFIX.endswith("/"):
      raise InvalidRedirectPrefixException
    if not self.APIAPP_REDIRECTPREFIX.startswith("http://"):
      if not self.APIAPP_REDIRECTPREFIX.startswith("https://"):
        raise InvalidRedirectPrefixException

    self.APIAPP_URLEXPIREDAYS = readFromEnviroment(
      env=env,
      envVarName='APIAPP_URLEXPIREDAYS',
      defaultValue=None,
      acceptableValues=None,
      nullValueAllowed=False
    )
    print("APIAPP_URLEXPIREDAYS:", self.APIAPP_URLEXPIREDAYS)
    self.APIAPP_URLEXPIREDAYS = int(self.APIAPP_URLEXPIREDAYS)
    if (self.APIAPP_URLEXPIREDAYS < 0):
      print("ERROR - Expire days less than 0")
      raise invalidConfigurationException

    objectStoreConfigDict = readDictFromEnviroment(
      env=env,
      envVarName='APIAPP_OBJECTSTORECONFIG',
      defaultValue='{}'
    )

    self.APIAPP_OBJECTSTOREDETAILLOGGING = readFromEnviroment(
      env=env,
      envVarName='APIAPP_OBJECTSTOREDETAILLOGGING',
      defaultValue='N',
      acceptableValues=['Y', 'N'],
      nullValueAllowed=True
    ).strip()
    if (self.APIAPP_OBJECTSTOREDETAILLOGGING=='Y'):
      print("APIAPP_OBJECTSTOREDETAILLOGGING set to Y - statement logging enabled")

    fns = {
      'getCurDateTime': self.getCurDateTime
    }
    self.objectStore = createObjectStoreInstance(
      objectStoreConfigDict,
      fns,
      detailLogging=(self.APIAPP_OBJECTSTOREDETAILLOGGING == 'Y')
    )

    self.shortUrlFunctions = Logic.ShortUrlFunctionClass(appObj=self)

    self.APIAPP_DESTWHITELIST = readDictFromEnviroment(
      env=env,
      envVarName='APIAPP_DESTWHITELIST',
      defaultValue='{}',
      safeToOutput=True
    )
    if self.APIAPP_DESTWHITELIST is None:
      self.APIAPP_DESTWHITELIST = {}
    print("APIAPP_DESTWHITELIST:", self.APIAPP_DESTWHITELIST)
    for curTenant in self.APIAPP_DESTWHITELIST:
      if not isinstance(self.APIAPP_DESTWHITELIST[curTenant], list):
        print("ERROR - APIAPP_DESTWHITELIST tenant values must be lists of string")
        raise invalidConfigurationException
      for ite in self.APIAPP_DESTWHITELIST[curTenant]:
        if not isinstance(ite, str):
          print("ERROR - APIAPP_DESTWHITELIST tenant value lists can only contain strings")
          raise invalidConfigurationException
コード例 #9
0
    def init(self, env, serverStartTime, testingMode=False):
        ##self.setupLogging() Comment in when debugging

        self.TicketManager = ticketManager.ticketManagerClass(appObj=self)
        self.ApiKeyManager = apiKeyManager.apiKeyManagerClass(appObj=self)

        authProviders_resetStaticData()
        self.scheduler = BackgroundScheduler(timezone="UTC")
        self.defaultUserGUID = str(uuid.uuid4())
        if testingMode:
            self.defaultUserGUID = conDefaultUserGUID
            self.testingDefaultPersonGUID = conTestingDefaultPersonGUID

        super(appObjClass, self).init(env,
                                      serverStartTime,
                                      testingMode,
                                      serverinfoapiprefix='public/info')

        #This app always needs a JWT key
        if self.APIAPP_JWTSECRET is None:
            print("ERROR - APIAPP_JWTSECRET should always be set")
            raise invalidConfigurationException

        self.APIAPP_MASTERPASSWORDFORPASSHASH = readFromEnviroment(
            env, 'APIAPP_MASTERPASSWORDFORPASSHASH', None, None).strip()
        self.APIAPP_DEFAULTHOMEADMINUSERNAME = readFromEnviroment(
            env, 'APIAPP_DEFAULTHOMEADMINUSERNAME', 'Admin', None).strip()
        self.APIAPP_DEFAULTHOMEADMINPASSWORD = readFromEnviroment(
            env, 'APIAPP_DEFAULTHOMEADMINPASSWORD', None,
            None).strip()  #no default must be read in
        self.APIAPP_JWT_TOKEN_TIMEOUT = int(
            readFromEnviroment(env, 'APIAPP_JWT_TOKEN_TIMEOUT', 60 * 10,
                               None))  #default to 10 minutes
        self.APIAPP_REFRESH_TOKEN_TIMEOUT = int(
            readFromEnviroment(env, 'APIAPP_REFRESH_TOKEN_TIMEOUT',
                               60 * 60 * 2, None))  #default to 2 hours
        self.APIAPP_REFRESH_SESSION_TIMEOUT = int(
            readFromEnviroment(env, 'APIAPP_REFRESH_SESSION_TIMEOUT',
                               60 * 60 * 12, None))  #default to 12 hours

        autoconfigraw = readFromEnviroment(env=env,
                                           envVarName='APIAPP_AUTOCONFIG',
                                           defaultValue='',
                                           acceptableValues=None,
                                           nullValueAllowed=False).strip()
        if autoconfigraw == '':
            self.APIAPP_AUTOCONFIG = None
        else:
            try:
                self.APIAPP_AUTOCONFIG = json.loads(autoconfigraw)
            except:
                print("ERROR - APIAPP_AUTOCONFIG is not valid json")
                raise invalidConfigurationException

        if self.APIAPP_REFRESH_TOKEN_TIMEOUT < self.APIAPP_JWT_TOKEN_TIMEOUT:
            print(
                "ERROR - APIAPP_REFRESH_TOKEN_TIMEOUT should never be less than APIAPP_JWT_TOKEN_TIMEOUT"
            )
            raise invalidConfigurationException
        if self.APIAPP_REFRESH_SESSION_TIMEOUT < self.APIAPP_REFRESH_TOKEN_TIMEOUT:
            print(
                "ERROR - APIAPP_REFRESH_SESSION_TIMEOUT should never be less than APIAPP_REFRESH_SESSION_TIMEOUT"
            )
            raise invalidConfigurationException

        self.APIAPP_DEFAULTMASTERTENANTJWTCOLLECTIONALLOWEDORIGINFIELD = readFromEnviroment(
            env, 'APIAPP_DEFAULTMASTERTENANTJWTCOLLECTIONALLOWEDORIGINFIELD',
            'http://localhost', None)

        # add to the baseapp default so allowed origns are in this list and extra vals
        self.accessControlAllowOriginObj = uniqueCommaSeperatedListClass(
            self.APIAPP_DEFAULTMASTERTENANTJWTCOLLECTIONALLOWEDORIGINFIELD +
            ", " + self.accessControlAllowOriginObj.toString())

        # print('uniqueCommaSeperatedListClass:', self.accessControlAllowOriginObj.toString())

        print('APIAPP_JWT_TOKEN_TIMEOUT:' +
              str(self.APIAPP_JWT_TOKEN_TIMEOUT) + ' seconds')
        print('APIAPP_REFRESH_TOKEN_TIMEOUT:' +
              str(self.APIAPP_REFRESH_TOKEN_TIMEOUT) + ' seconds')
        print('APIAPP_REFRESH_SESSION_TIMEOUT:' +
              str(self.APIAPP_REFRESH_SESSION_TIMEOUT) + ' seconds')

        objectStoreConfigJSON = readFromEnviroment(env,
                                                   'APIAPP_OBJECTSTORECONFIG',
                                                   '{}', None)
        objectStoreConfigDict = None
        try:
            if objectStoreConfigJSON != '{}':
                objectStoreConfigDict = json.loads(objectStoreConfigJSON)
        except Exception as err:
            print(err)  # for the repr
            print(str(err))  # for just the message
            print(err.args
                  )  # the arguments that the exception has been called with.
            raise (InvalidObjectStoreConfigInvalidJSONException)

        self.APIAPP_OBJECTSTOREDETAILLOGGING = readFromEnviroment(
            env=env,
            envVarName='APIAPP_OBJECTSTOREDETAILLOGGING',
            defaultValue='N',
            acceptableValues=['Y', 'N'],
            nullValueAllowed=True).strip()
        if (self.APIAPP_OBJECTSTOREDETAILLOGGING == 'Y'):
            print(
                "APIAPP_OBJECTSTOREDETAILLOGGING set to Y - statement logging enabled"
            )

        fns = {'getCurDateTime': self.getCurDateTime}
        self.objectStore = createObjectStoreInstance(
            objectStoreConfigDict,
            fns,
            detailLogging=(self.APIAPP_OBJECTSTOREDETAILLOGGING == 'Y'))

        def dbChangingFn(storeConnection):
            if GetTenant(masterTenantName, storeConnection,
                         appObj=self) is None:
                print("********No master tenant found - creating********")

                def someFn(connectionContext):
                    CreateMasterTenant(self, testingMode, storeConnection)

                storeConnection.executeInsideTransaction(someFn)

        self.objectStore.executeInsideConnectionContext(dbChangingFn)

        self.gateway = getGatewayInterface(env, self)
        self.refreshTokenManager = RefreshTokenManager(self)

        self.scheduler.start()

        # Load origins from tenants
        def dbfn(storeConnection):
            for curTenant in storeConnection.getAllRowsForObjectType(
                    "tenants", None, None, ""):
                print("Loading allowed origins for " + curTenant[0]["Name"] +
                      ":" +
                      str(curTenant[0]["JWTCollectionAllowedOriginList"]))
                appObj.accessControlAllowOriginObj.addList(
                    curTenant[0]["JWTCollectionAllowedOriginList"])

            ##return storeConnection.getPaginatedResult("tenants", paginatedParamValues, outputFN)

        self.objectStore.executeInsideConnectionContext(dbfn)

        if self.APIAPP_AUTOCONFIG != None:
            autoConfigRunner = autoConfig.AutoConfigRunner(
                self.APIAPP_AUTOCONFIG)

            def configRunnerFn(storeConnection):
                autoConfigRunner.run(self, storeConnection)

            self.objectStore.executeInsideTransaction(configRunnerFn)

        tenantOnAppInit(self)
コード例 #10
0
 def init(self, env, serverStartTime, testingMode=False):
     self.curDateTimeOverrideForTesting = None
     self.serverStartTime = serverStartTime
     self.version = readFromEnviroment(env, 'APIAPP_VERSION', None, None)
     super(appObjClass, self).init(env)