Refactor environment functions in preparation for get_file

These functions have been reorganised to break out functions that
deal with only file or URL handling to allow for better unit testing
and to prepare for get_file which will also use some of these functions.

Change-Id: I8576d09c556fc0835004da6b78070686482361e0
Merge "Refactor environment functions in preparation for get_file"