Refactor loading of opensearch template file resource to constructor, so we only do it once

Also ensure we always close the stream.

Thanks to Matt Ramey (mrmateo) for the suggestions