This is a common pattern that is replicated both in our code and in rpm-ostree a lot. Let's add a canonical API.