This repository has been archived by the owner on Sep 24, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplify the provider interface by getting rid of suitable()
The responsibilities of suitable() and describe() were an awkward split and it was confusing to remember which one would be called first, and which one had to make sure the provider is set up and functional. We now only require a describe() method that does both: set up any internal state the provider needs before get() and set() can work, and reports whether the provider is suitable; suitability is now stored in the provider spec. To narrow down how describe() finds things on the system, we now have an environment class which provides convenience accessors to the things a provider needs to learn about. This also helps in focusing and clarifying what a provider writer needs to know about the libral API.
- Loading branch information
Showing
23 changed files
with
281 additions
and
168 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#pragma once | ||
|
||
#include <vector> | ||
|
||
#include <boost/optional.hpp> | ||
|
||
#include <libral/command.hpp> | ||
#include <libral/augeas.hpp> | ||
#include <libral/prov/spec.hpp> | ||
|
||
namespace libral { | ||
// Forward declaration to break an include loop | ||
class ral; | ||
|
||
/** | ||
* This class represents the environment in which providers operate and | ||
* contains convenience function for accessing various aspects of the | ||
* environment. An instance of this class is passed to the provider's | ||
* describe method. */ | ||
class environment { | ||
public: | ||
/** | ||
* Looks for a command called \p cmd and returns a command object that | ||
* can be used to run the command. | ||
* | ||
* @return \c boost::none if no command \p cmd can be found, or a | ||
* command object to run this command. | ||
*/ | ||
boost::optional<libral::command> command(const std::string& cmd); | ||
|
||
/** | ||
* Creates an augeas handle that has the files described by \p xfms | ||
* loaded. | ||
*/ | ||
result<std::shared_ptr<augeas::handle>> | ||
augeas(const std::vector<std::pair<std::string, std::string>>& xfms); | ||
|
||
const std::vector<std::string>& data_dirs() const; | ||
|
||
/** | ||
* Creates provider metadata from the description \p desc, which must | ||
* be valid YAML and comply with the provider metadata | ||
* specification. The \p name is used as the default name for the | ||
* provider, unless the metadata specifies a different name. | ||
* | ||
* If \p suitable is not \c boost::none, it takes precedence over a | ||
* suitable entry that might be in \p desc. If \p suitable is | ||
* boost::none, then \p desc must contain an entry that indicates | ||
* whether the provider is suitable or not. | ||
*/ | ||
result<prov::spec> parse_spec(const std::string& name, | ||
const std::string& desc, | ||
boost::optional<bool> suitable = boost::none); | ||
|
||
result<prov::spec> | ||
parse_spec(const std::string& name, const YAML::Node &node); | ||
|
||
protected: | ||
friend class ral; | ||
|
||
environment(std::shared_ptr<ral> ral) : _ral(ral) { } | ||
private: | ||
std::shared_ptr<ral> _ral; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.