示例#1
0
    def __init__(self, configuration, startimediatly=True, logger=logging.getLogger("Jeggings")):

        self.logger = logger

        self.logger.debug("Jeggings called")
        self.configuration = configuration

        if startimediatly:
            waitseconds = 30
            self.start_running(waitseconds=waitseconds)
            if not self.is_running():
                raise RuntimeError("Jeggings did not start in expected time of [{}] seconds".format(waitseconds))

        ctype = jeggings_utils.figure_out_google_auth_credentials_method_from_config(configuration)

        if ctype == "service_account_file":
            self.google_credentials = google_utils.google_get_credentials_from_serviceaccount_file(
                 serviceaccount_credentials_filepath=configuration["GOOGLE_SERVICES"]["CREDENTIALS"],
                 domain_account=configuration["GOOGLE_SERVICES"]["DOMAIN_ACCOUNT"],
                 apis=configuration["GOOGLE_SERVICES"]["APIS"])

        elif ctype == "service_account":
            self.google_credentials = google_utils.google_get_credentials_from_serviceaccount(
                 serviceaccount_credentials_json=configuration["GOOGLE_SERVICES"]["CREDENTIALS"],
                 domain_account=configuration["GOOGLE_SERVICES"]["DOMAIN_ACCOUNT"],

                 apis=configuration["GOOGLE_SERVICES"]["APIS"])

        elif ctype == "ouath_account":
            self.google_credentials = \
                google_utils.google_get_credentials_from_usercredentials(
                                        applicationname=self.configuration["APPLICATION_NAME"],
                                        credentialsfilepath=configuration["GOOGLE_SERVICES"]["CREDENTIALS_FILEPATH"],
                                        clientsecretsfilepath=configuration["GOOGLE_SERVICES"]["CLIENTSECRET_FILEPATH"],
                                        apis=configuration["GOOGLE_SERVICES"]["APIS"]
                                        )
        else:
            raise ValueError("Could not determin authentication type for Google services. Unsupported type [{}]".
                             format(ctype))

        self.googleservice_calendar = google_utils.google_get_calendar_service(self.google_credentials)
        self.googleservice_directory = google_utils.google_get_directory_service(self.google_credentials)

        self.google_domain = self.configuration["GOOGLE_SERVICES"]["DOMAIN_ACCOUNT"].split("@")[-1],\
示例#2
0
                        help="Verbose logging. Overrides configuration values and --q")
    parser.add_argument('--configurationschema', type=str, required=False,
                        default="schemas/jeggings.configschema.json",
                        help="Path to configuration file schema. Defaults to relative path "
                             "schemas/jeggings.configschema.json")

    args = parser.parse_args()

    if args.debug:
        mlogger.setLevel(logging.DEBUG)

    bootstrapconfig = jeggings_utils.load_configuration_from_json(args.configurationresource,
                                                                  args.configurationschema,
                                                                  withdefaults=True)

    ctype = jeggings_utils.figure_out_google_auth_credentials_method_from_config(bootstrapconfig)

    google_credentials = None
    if ctype == "service_account_file":
        google_credentials = google_get_credentials_from_serviceaccount_file(
            serviceaccount_credentials_filepath=bootstrapconfig["GOOGLE_SERVICES"]["CREDENTIALS"],
            domain_account=bootstrapconfig["GOOGLE_SERVICES"]["DOMAIN_ACCOUNT"],
            apis=bootstrapconfig["GOOGLE_SERVICES"]["APIS"])

    elif ctype == "service_account":
        google_credentials = google_get_credentials_from_serviceaccount(
            serviceaccount_credentials_json=bootstrapconfig["GOOGLE_SERVICES"]["CREDENTIALS"],
            domain_account=bootstrapconfig["GOOGLE_SERVICES"]["DOMAIN_ACCOUNT"],
            apis=bootstrapconfig["GOOGLE_SERVICES"]["APIS"])

    elif ctype == "ouath_account":