Package: check-ezproxy
##Check for EZProxy configurationsA simple command-line script to check that EZProxy configurations existfor library databases. Built for checking LibGuides A-Z databases andOCLC Knowledge Base, but can be easily extended. Built/Tested withPython 3.4, but should work back to at least 2.7.##InstallationEasiest way is:``pip install check_ezproxy``Or:1. Clone the repository.2. Optional: If you want to make the file exectuable, run ``chmod +x check_ezproxy_run.py`` (in a bash system; this makes it so you shouldn't have to prepend each call with python)3. From the main directory, run ``python check_ezproxy_run.py -args`` (or ``./check_ezproxy_run.py -args`` if you did step 2 above)4. Run ``python setup.py install`` to install (after this, you can just use the ``check_ezproxy``, setup makes it available everywhere)Or use Docker:1. Clone the repository2. Edit the Dockerfile to fill in your information for environment variables (takes the place of editing cfg or JSON config)3. With your Docker daimon running and from the project root, run ``docker build -t check_ezproxy .``4. Now you can run Docker run commands with flags for this tool at the end, i.e. ``docker run check_ezproxy --urlsource=libguides``Docker support is still fairly limited, and with the current Dockerfile you won't be able to check KBART files or use a JSON config.##UseInstalling via pip or setup.py will make the ``check_ezproxy`` commandavailable globally. It is suggested you install it into a virtualenvironment to:1. not permanently pollute the global namespace in your shell2. not pollute your base Python packages, as this utility uses somepopular libraries and even if this tool isn't necessarily reliant ona particular version, another tool might be. Best to keep emseparated.##ConfigurationSome minimal configuration is needed for the checks to be able to run,and there are a couple of ways to supply this.- Rename 'config\_template.py' to 'config.py' and supply the listed parameters. This is best for quick testing or if you want to extend the tool.- Make a .json file containing the necessary config, then point the tool to it with the -c argument. You can optionally use a -s flag to save these configs so you don't need to point toward them again, but note that these will override any other configs you may try to give. You will need to use ``--flush-config`` to use another configuration.- You can also use the package as a tool for making your own utility and provide config in your script. Details below.Configurations to set are:- **ezproxy_prefix**- the full prefix for your EZProxy server, protocol included- **libguides_api_url**- The full URL to LibGuides API for database assets including your site id, API key, and asset\_type=10 as query parameters (v. 1.1 only at this  time, v. 1.2 soon)- **ezproxy_error_text**- Some text on your page for proxied links with no stanzas set that you can be relatively sure is unique. The tool will match against this the page text to determine which links are not properly configured.- **kb_wskey**- If you want to check links directly from the OCLC knowledge base, you will need to apply for an API key. Only the WSKey is needed here, not the secret.- **kb_collections**- The name of the collections in the knowledge base to check. If using Python for config these can be in a tuple or list (or any iterable), if using JSON they go in an array. Even if you only have 1 to check, it needs to be in an iterable wrapper.##ArgumentsNote: none of these arguments are mandatory, though some rely on othersto be set as well.**-u, --urlsource**The location to get the urls to run the check on. Current possible options are 'libguides','oclc', and 'kbart' (will have to use -k to provide the path to theKBART file to check. -k can be used on its own as well).**-t, --type**The type of check to run. Current supported checks are 'text' and'link'.``-t text`` will make a call to retrieve the page through the proxyserver and compare the text returned to known error text (can't usestatus codes because those are 200 even for a wrongly configureddatabase). At Westfield this text is 'your EZproxy administrator mustfirst' but you will need to set comparison text for your institution asERROR\_TEXT in constants.py ``-t links`` will just make a head requestand check the status code.**-k, --kbart**The path to a kbart file to check. If using this, it is not necessary toset a --urlsource, though it is fine to do so. The path can be relative,absolute, or relative to your home directory (~)**-w, --write**Write the output to a file rather than printing to the standard output**-f, --output-file**The path and filename you wish to use in conjunction with the ``-w``. Itis necessary to also use ``-w``, but if you do not specify a file hereit will default to 'check\_proxy.txt' in your home directory.**-p, --proxy**Force the presence or absence of a proxy prefix. Acceptable values are:- ``force``- ``no_proxy````force`` will cause every link to have a proxy prefix regardless ofwhether it 'should' (i.e. whether the LibGuides Database A-Z list has itset to not be proxied)``no_proxy`` will do the opposite and force the link to have no proxyprefix, useful for checking for dead links which will still be dead whenproxied (and which might give false negatives if a link is dead andproxied)**-c, --config-file**Use a JSON config file rather than one of the Python options for configfiles. Arg just takes the path (relative, absolute, or relative to home)of the .json file you want to use.**-s, --save-config**To be used in conjunction with ``-c``, will save the config file youused so that you don't have to provide the path to it every time. Thissaved config will trump everything.**--flush-config**Flush any saved JSON configuration and use either a Python or new JSONconfiguration. Can be used on the same call as``-c new_json_config.json``.##Example CallsBasic call to check link status on the OCLC Knowledge Base collectiondefined in your configuration.``check_ezproxy -u oclc -t link``Call with a JSON config that we are saving.``check_ezproxy --config=./config.json -s``Check set OCLC knowledge base collection with an updated config.json (you can combine flags, but any flag that takes an argument must be the last one, and you can only have 1 of these when combining)``check_ezproxy --flush-config -sc ./config.json``##Add New Url Sources or types of checksimport the 'register' decorator from registration.py.###For a new Url sourceWrite a function that returns an iterable (i.e. list or tuple) ofclasses or named tuples with a url and name element. Named tuple can beused like so:```pythonfrom collections import namedtupleRecord = namedtuple('Record', 'name url')new_record = Record('this_name', 'http://www.example.com')print(new_record.name)  # will output 'this_name'```Decorate that function with the register decorator that takes what youwant the argument to be called in the command line script and 'places'```pythonfrom registration import register@register('get_links_here', 'places')def get_links_here():return [list_of_record_named_tuples]```Save that file to the same directory as the rest of the scripts, importit in check proxy, and it should automatically be available in thecommand line script.###For a new type of checkDo the same thing as for a url source above, except the second argumentto the decorator should be 'checks' and your function should take adatabase argument and a config argument, run some kind of check, andreturn that object if everything is fine and an object with name, url,and a new status attribute if something went wrong.```pythonfrom registration import register@register('check_em_good', 'checks')def check_em_good(db):check(db)return db```You can also just add the check to the checks.py or places.py files and(optionally) make a pull request to bring your checks into the mainrepository.