Пример #1
0
    def setUpClass(cls):
        """Executed when module is loaded before any test."""
        # checks
        if not environ.get("ISOGEO_API_USER_LEGACY_CLIENT_ID") or not environ.get(
            "ISOGEO_API_USER_LEGACY_CLIENT_SECRET"
        ):
            logging.critical("No API credentials set as env variables.")
            exit()
        else:
            pass

        # ignore warnings related to the QA self-signed cert
        if environ.get("ISOGEO_PLATFORM").lower() == "qa":
            urllib3.disable_warnings()

        # API connection
        cls.isogeo = Isogeo(
            auth_mode="user_legacy",
            client_id=environ.get("ISOGEO_API_USER_LEGACY_CLIENT_ID"),
            client_secret=environ.get("ISOGEO_API_USER_LEGACY_CLIENT_SECRET"),
            auto_refresh_url="{}/oauth/token".format(environ.get("ISOGEO_ID_URL")),
            platform=environ.get("ISOGEO_PLATFORM", "qa"),
        )
        # getting a token
        cls.isogeo.connect(
            username=environ.get("ISOGEO_USER_NAME"),
            password=environ.get("ISOGEO_USER_PASSWORD"),
        )

        # fixture metadata - source
        cls.fixture_metadata = cls.isogeo.metadata.get(
            metadata_id=environ.get("ISOGEO_METADATA_FIXTURE_UUID"), include="all"
        )
Пример #2
0
    def setUpClass(cls):
        """Executed when module is loaded before any test."""
        # checks
        if not environ.get("ISOGEO_API_GROUP_CLIENT_ID") or not environ.get(
                "ISOGEO_API_GROUP_CLIENT_SECRET"):
            logging.critical("No API credentials set as env variables.")
            exit()
        else:
            pass

        # ignore warnings related to the QA self-signed cert
        if environ.get("ISOGEO_PLATFORM").lower() == "qa":
            urllib3.disable_warnings()

        # API connection
        cls.isogeo = Isogeo(
            auth_mode="group",
            client_id=environ.get("ISOGEO_API_GROUP_CLIENT_ID"),
            client_secret=environ.get("ISOGEO_API_GROUP_CLIENT_SECRET"),
            auto_refresh_url="{}/oauth/token".format(
                environ.get("ISOGEO_ID_URL")),
            platform=environ.get("ISOGEO_PLATFORM", "qa"),
        )
        # getting a token
        cls.isogeo.connect()

        # load fixture search
        search_all_includes = Path("tests/fixtures/api_search_complete.json")
        with search_all_includes.open("r") as f:
            search = json.loads(f.read())
        cls.search = MetadataSearch(**search)

        # module to test
        cls.fmt = Formatter()
    def pysdk_checking(self):
        logger.debug("\n--------------- isogeo-pysdk ---------------")
        logger.debug("Checking credentials")
        try:
            isogeo = Isogeo(self.app_id, self.app_secrets)
            isogeo.connect()
        except OSError as e:
            logger.debug("Credentials issue : {}".format(e))
            return
        except ValueError as e:
            logger.debug("Credentials issue : {}".format(e))
            return

        if self.search_type == "init":
            result = isogeo.search(
                whole_share=0, page_size=0, augment=0, tags_as_dicts=1
            )
        else:
            query = " ".join(list(self.checked_kw.keys()))
            result = isogeo.search(
                whole_share=0, page_size=0, augment=0, tags_as_dicts=1, query=query
            )

        self.tags_expected = result.get("tags")
        self.kw_expected_nb = len(self.tags_expected.get("keywords"))
        self.ui.lbl_expected.setText(
            "Expected : {} resources and {} keywords".format(
                result.get("total"), self.kw_expected_nb
            )
        )
        logger.debug(
            "isogeo-pysdk validates the authentication file, {} accessible resources".format(
                result.get("total")
            )
        )
Пример #4
0
    def manage_api_initialization(self):
        """Perform several operations to use Isogeo API:

        1. check if existing credentials are stored somewhere
        2. check if credentials are valid requesting Isogeo API ID
        """
        # try to retrieve existing credentials from potential sources
        self.credentials_storage["QSettings"] = self.credentials_check_qsettings()
        self.credentials_storage["oAuth2_file"] = self.credentials_check_file()

        # update class attributes from credentials found
        if self.credentials_storage.get("QSettings"):
            self.credentials_update("QSettings")
            logger.debug("Credentials used: QSettings")
        elif self.credentials_storage.get("oAuth2_file"):
            self.credentials_update("oAuth2_file")
            logger.debug("Credentials used: client_secrets file")
        else:
            logger.info("No credentials found. Opening the authentication form...")
            self.display_auth_form()
            return False

        # start api wrapper
        try:
            logger.debug("Start connection attempts")
            # client connexion
            self.isogeo = Isogeo(
                auth_mode="group",
                client_id=self.api_app_id,
                client_secret=self.api_app_secret,
                auto_refresh_url=self.api_url_token,
                lang=current_locale.name()[:2],
                platform=self.api_platform,
                proxy=app_utils.proxy_settings(),
                timeout=(30, 200),
            )
            # handle forced SSL verification
            if int(getenv("OAUTHLIB_INSECURE_TRANSPORT", 0)) == 1:
                logger.info("Forced disabled SSL verification")
                self.ssl = False
                self.isogeo.ssl = False
                app_utils.ssl = False

            # start connection
            self.isogeo.connect()
            logger.debug("Authentication succeeded")
            return True
        except ValueError as e:
            logger.error(e)
            self.display_auth_form()
        except EnvironmentError as e:
            logger.error(e)
        except Exception as e:
            logger.error(e)
            self.display_auth_form()
Пример #5
0
 def _init_isogeo(self):
     api_credentials = utils.credentials_loader("client_secrets.json")
     self.isogeo = Isogeo(
         client_id=api_credentials.get("client_id"),
         client_secret=api_credentials.get("client_secret"),
     )
     self.token = self.isogeo.connect()
     # app properties
     self.isogeo.get_app_properties(self.token)
     self.app_props = self.isogeo.app_properties
     self.app_name.set(
         "Authenticated application: {}".format(self.app_props.get("name"))
     )
     self.app_url.set(self.app_props.get("url", "https://www.isogeo.com"))
Пример #6
0
    def setUpClass(cls):
        """Executed when module is loaded before any test."""
        # checks
        if not environ.get(
                "ISOGEO_API_USER_LEGACY_CLIENT_ID") or not environ.get(
                    "ISOGEO_API_USER_LEGACY_CLIENT_SECRET"):
            logging.critical("No API credentials set as env variables.")
            exit()
        else:
            pass

        # ignore warnings related to the QA self-signed cert
        if environ.get("ISOGEO_PLATFORM").lower() == "qa":
            urllib3.disable_warnings()

        # API connection
        cls.isogeo = Isogeo(
            auth_mode="user_legacy",
            client_id=environ.get("ISOGEO_API_USER_LEGACY_CLIENT_ID"),
            client_secret=environ.get("ISOGEO_API_USER_LEGACY_CLIENT_SECRET"),
            auto_refresh_url="{}/oauth/token".format(
                environ.get("ISOGEO_ID_URL")),
            platform=environ.get("ISOGEO_PLATFORM", "qa"),
        )
        # getting a token
        cls.isogeo.connect(
            username=environ.get("ISOGEO_USER_NAME"),
            password=environ.get("ISOGEO_USER_PASSWORD"),
        )

        # fixture metadata
        cls.fixture_metadata = cls.isogeo.metadata.get(
            metadata_id=environ.get("ISOGEO_METADATA_FIXTURE_UUID"),
            include="all")

        # fixture workgroup
        # to create a workgroup, a contact is required
        contact_owner = Contact(
            name="{} - {}".format(
                get_test_marker(),
                "{}_{}".format(hostname, strftime("%Y-%m-%d_%H%M%S",
                                                  gmtime())),
            ),
            email="*****@*****.**",
        )
        workgroup = Workgroup(contact=contact_owner, canCreateMetadata=True)
        # create it online
        cls.fixture_workgroup = cls.isogeo.workgroup.create(
            workgroup=workgroup)
Пример #7
0
 def __init__(self, file_name: str = "client_secrets.json") -> object:
     # création du chemin vers le fichier d'authentification
     self.json_file = "{}/{}".format("/".join(__file__.split("\\")[:-1]),
                                     file_name)
     # récupérétion des informations d'authentification contenues dans le fichier
     self.client_id = utils.credentials_loader(
         self.json_file).get("client_id")
     self.client_secret = utils.credentials_loader(
         self.json_file).get("client_secret")
     # connexion à l'API et récupération du token
     self.isogeo = Isogeo(
         client_id=self.client_id,
         client_secret=self.client_secret,
         auth_mode="group",
         auto_refresh_url="https://id.api.isogeo.com/oauth/token",
         platform="prod")
     self.isogeo.connect()
Пример #8
0
    def pysdk_checking(self):
        logger.debug("\n------------------ isogeo-pysdk ------------------")
        logger.debug("Checking credentials")
        try:
            isogeo = Isogeo(self.app_id, self.app_secrets)
            isogeo.connect()
        except OSError as e:
            logger.debug("Credentials issue : {}".format(e))
            return
        except ValueError as e:
            logger.debug("Credentials issue : {}".format(e))
            return

        self.md_expected = isogeo.search(whole_share=0, page_size=0,
                                         augment=0).get("total")
        self.ui.lbl_expected.setText("{} expected resources".format(
            self.md_expected))
        logger.debug(
            "isogeo-pysdk validates the authentication file, {} accessible resources"
            .format(self.md_expected))
Пример #9
0
    Isogeo,
    IsogeoChecker,
)

checker = IsogeoChecker()
# load .env file
load_dotenv("./env/lille.env", override=True)

if __name__ == "__main__":

    # ############################### MIGRATING & SAVING ###############################
    # API client instanciation
    isogeo = Isogeo(
        client_id=environ.get("ISOGEO_API_USER_LEGACY_CLIENT_ID"),
        client_secret=environ.get("ISOGEO_API_USER_LEGACY_CLIENT_SECRET"),
        auth_mode="user_legacy",
        auto_refresh_url="{}/oauth/token".format(environ.get("ISOGEO_ID_URL")),
        platform=environ.get("ISOGEO_PLATFORM", "qa"),
    )
    isogeo.connect(
        username=environ.get("ISOGEO_USER_NAME"),
        password=environ.get("ISOGEO_USER_PASSWORD"),
    )

    workgroup_uuid = environ.get("ISOGEO_ORIGIN_WORKGROUP")

    # Search about all workgroup metadatas because there are less than 800
    whole_md_search = isogeo.search(group=workgroup_uuid,
                                    whole_results=True,
                                    include="all")
    isogeo.close()
Пример #10
0
        dico_gs.clear()
        logging.info("\n{0}: ".format(gs))
        ReadGeoServer(gs, dico_gs, 'GeoServer')

        # print(dico_gs)
        # print(dico_gs.keys())
        # print(dico_gs.get('ayants-droits')[1].get("BD_TOPO_2015_VOIES_FERREES_ET_AUTRES"))
        # print(dico_gs.get('ayants-droits')[1].get("bd_topo_reseau_routier_route_primaire"))
        # print(dico_gs.get('ayants-droits')[1].keys())
        # print(dico_gs.get('layers'))

    # ------------------------------------------------------------------------

    # ------------ ISOGEO ----------------------------------------------------
    # instanciating the class
    isogeo = Isogeo(client_id=app_id, client_secret=app_secret, lang=app_lang)
    token = isogeo.connect()

    search_results = isogeo.search(token)
    search_results = search_results.get('results')

    # ------------------------------------------------------------------------

    # ## EXCELs ############
    # -- WMS -------------------------------------------------------
    wb_gs_full = Workbook()
    dest_gs_full = '{}_gs_full.xlsx'.format(out_prefix)

    ws_gs_full = wb_gs_full.active
    ws_gs_full.title = "GEOSERVER - FULL"
Пример #11
0
    load_dotenv("dev.env")

    # misc
    METADATA_TEST_FIXTURE_UUID = environ.get(
        "ISOGEO_FIXTURES_METADATA_COMPLETE")
    WORKGROUP_TEST_FIXTURE_UUID = environ.get("ISOGEO_WORKGROUP_TEST_UUID")

    # ignore warnings related to the QA self-signed cert
    if environ.get("ISOGEO_PLATFORM").lower() == "qa":
        urllib3.disable_warnings()

    # for oAuth2 Backend (Client Credentials Grant) Flow
    isogeo = Isogeo(
        auth_mode="group",
        client_id=environ.get("ISOGEO_API_GROUP_CLIENT_ID"),
        client_secret=environ.get("ISOGEO_API_GROUP_CLIENT_SECRET"),
        auto_refresh_url="{}/oauth/token".format(environ.get("ISOGEO_ID_URL")),
        platform=environ.get("ISOGEO_PLATFORM", "qa"),
    )

    # getting a token
    isogeo.connect()

    # ------------ Isogeo search --------------------------
    search_results = isogeo.search(
        include="all",
        specific_md=(
            "70f1192f67ac43e5987800ead18effb2",
            "b140d9a92c20416d97c3cdc12dc12607",
        ),
    )
Пример #12
0
from isogeo_pysdk import Isogeo, IsogeoUtils, __version__

#########

print("Working with package version: {}".format(__version__))
utils = IsogeoUtils()

#print(dir(utils))
#print(help(utils))

#######

api_auth = utils.credentials_loader(r"./client_secrets.json")

# authenticate your client application
isogeo = Isogeo(client_id=api_auth.get("client_id"),
                client_secret=api_auth.get("client_secret"))

# get the token
token = isogeo.connect()

# add properties as attribute
isogeo.get_app_properties(token)

# set augment option on True
search = isogeo.search(token,
                       query="bar",
                       page_size=0,
                       whole_share=0,
                       augment=1)

print(search.get("total"))
Пример #13
0
F1s4cscTmCDjDTjdSPOHBQggUAEQDAgggTWDPoYMJkFoUdRmddyyjWLeULMMMcAsIw0x4wkM
IME1g25zyxpHxFYUHmyIggw4H4ojITnfiLMNMAkcAAub4BQjihRdDGTJHmvc4Qo1wD6Imje6
eILbj+BQ4wqu5Q3ECSJ0FOKKMtv4mBg33Pw4zjbKuBIIE1xYpIkhdQQiyi7OtAucj6dt48wu
otQhBRa6VvSJIRwhIkotvgRTzMUYZ6xxMcj4QkspeKDxxRhEmUfIHWjAgQcijEDissuXvCyz
zH7Q8YQURxDhUsn/bCInR3AELfTQZBRt9BBJkCGFFVhMwTNBlnBCSCGEIJQQIAklZMXWRBAR
RRRWENHwRQEBADs="""

# ############################################################################
# ############ Main ################
# ##################################

# Load Isogeo credentials
api_credentials = utils.credentials_loader("client_secrets.json")
isogeo = Isogeo(
    client_id=api_credentials.get("client_id"),
    client_secret=api_credentials.get("client_secret"),
    lang=language,
)
token = isogeo.connect()

# Get basic information
isogeo.get_app_properties(token)
app_props = isogeo.app_properties

print(app_props)

# Get tags to populate filters
search = isogeo.search(token, page_size=0, whole_share=0, augment=1, tags_as_dicts=1)
tags = search.get("tags")

# In case of a need of translation
Пример #14
0
    "ISOGEO_FIXTURES_METADATA_COMPLETE")
ISOGEO_WORKGROUP_TEST_UUID = environ.get("ISOGEO_WORKGROUP_TEST_UUID")

# ignore warnings related to the QA self-signed cert
if API_PLATFORM.lower() == "qa":
    urllib3.disable_warnings()

# #############################################################################
# ########## Fixturing ###############
# ####################################

# instanciating the class
isogeo = Isogeo(
    auth_mode="group",
    client_id=API_OAUTH_ID,
    client_secret=API_OAUTH_SECRET,
    auto_refresh_url="{}/oauth/token".format(environ.get("ISOGEO_ID_URL")),
    platform=API_PLATFORM,
)
isogeo.connect()

# Downloading directly from Isogeo API
BASE_DIR = path.dirname(path.abspath(__file__))

# complete search - only Isogeo Tests
out_search_complete_tests = path.join(BASE_DIR, "fixtures",
                                      "api_search_complete_tests.json")
if not path.isfile(out_search_complete_tests):
    request = isogeo.search(
        query="owner:{}".format(ISOGEO_WORKGROUP_TEST_UUID),
        whole_results=1,
Пример #15
0
    else:
        pass

    # reading ini file
    config = ConfigParser.SafeConfigParser()
    config.read(settings_file)

    share_id = config.get('auth', 'app_id')
    share_token = config.get('auth', 'app_secret')

    # ------------ Real start ----------------
    proxies = {'http': 'http://s-olfeo1.cab.local:3129',
               'https': 'https://s-olfeo1.cab.local:3129'}
    # instanciating the class
    isogeo = Isogeo(client_id=share_id,
                    client_secret=share_token,
                    proxy=proxies
                    )

    # getting a token
    jeton = isogeo.connect()

    # let's search for metadatas!
    search = isogeo.search(jeton)
    print("Total count of metadatas shared: ", search.get("total"))
    print("Count of resources got by request: {}\n".format(len(search.get("results"))))

    # make a list of path
    # settings_dict = {s: dict(config.items(s)) for s in config.sections()}
##    path_dict = {md.get("name"): dict(config.items(md)) for md in search.get("results")}
    names_dict = {}
    for md_isogeo in search.get("results"):
Пример #16
0
    def credentials_uploader(self):
        """Get file selected by the user and loads API credentials into plugin.
        If the selected is compliant, credentials are loaded from then it's
        moved inside ./_auth subfolder.
        """
        selected_file = app_utils.open_FileNameDialog(self.ui_auth_form)
        logger.debug(
            "Credentials file picker (QFileDialog) returned: {}".format(selected_file)
        )
        # test file path
        try:
            in_creds_path = Path(selected_file[0])
            assert in_creds_path.exists()
        except FileExistsError:
            logger.error(
                FileExistsError(
                    "No auth file selected or path is incorrect: {}".format(
                        selected_file[0]
                    )
                )
            )
            return False
        except Exception as e:
            logger.error(e)
            return False

        # test file structure
        try:
            api_credentials = app_utils.credentials_loader(in_creds_path.resolve())
        except Exception as e:
            logger.error("Selected file is bad formatted: {}".format(e))
            return False

        # rename previous credentials file
        creds_dest_path = Path(self.auth_folder) / "client_secrets.json"
        if creds_dest_path.is_file():
            creds_dest_path_renamed = Path(
                self.auth_folder
            ) / "old_client_secrets_{}.json".format(int(time.time()))
            rename(creds_dest_path.resolve(), creds_dest_path_renamed.resolve())
            logger.debug(
                "`./_auth/client_secrets.json already existed`. Previous file has been renamed."
            )
        else:
            pass
        # move new credentials file into ./_auth dir
        rename(in_creds_path.resolve(), creds_dest_path.resolve())
        logger.debug(
            "Selected credentials file has been moved into plugin './_auth' subfolder"
        )

        # check validity
        try:
            self.isogeo = Isogeo(
                auth_mode="group",
                client_id=api_credentials.get("client_id"),
                client_secret=api_credentials.get("client_secret"),
                auto_refresh_url=api_credentials.get("uri_token"),
                platform=api_credentials.get("platform"),
                proxy=app_utils.proxy_settings(),
            )
        except Exception as e:
            logger.debug(e)
            return False

        # set form
        self.ui_auth_form.ent_app_id.setText(api_credentials.get("client_id"))
        self.ui_auth_form.ent_app_secret.setText(api_credentials.get("client_secret"))
        self.ui_auth_form.lbl_api_url_value.setText(api_credentials.get("uri_auth"))
        self.ui_auth_form.btn_ok_cancel.setEnabled(1)

        # update class attributes from file
        self.credentials_update(credentials_source="oAuth2_file")

        # store into QSettings if existing
        self.credentials_storer(store_location="QSettings")