summaryrefslogtreecommitdiff
path: root/hscript/script.cc
diff options
context:
space:
mode:
authorA. Wilcox <AWilcox@Wilcox-Tech.com>2019-10-24 02:20:33 -0500
committerA. Wilcox <AWilcox@Wilcox-Tech.com>2019-10-24 02:20:33 -0500
commit4755175ad26eaff1765407bb01f8820f394f847b (patch)
tree9951bb91734a04e71f82d44284c74e56e8711f09 /hscript/script.cc
parent30b63f19fedde7b60bf99f3a68c0437a0c93b64e (diff)
downloadhorizon-4755175ad26eaff1765407bb01f8820f394f847b.tar.gz
horizon-4755175ad26eaff1765407bb01f8820f394f847b.tar.bz2
horizon-4755175ad26eaff1765407bb01f8820f394f847b.tar.xz
horizon-4755175ad26eaff1765407bb01f8820f394f847b.zip
hscript: Fully implement Timezone, add tests
Diffstat (limited to 'hscript/script.cc')
-rw-r--r--hscript/script.cc42
1 files changed, 41 insertions, 1 deletions
diff --git a/hscript/script.cc b/hscript/script.cc
index 0e99059..63ea3de 100644
--- a/hscript/script.cc
+++ b/hscript/script.cc
@@ -90,6 +90,9 @@ struct Script::ScriptPrivate {
std::unique_ptr<RootPassphrase> rootpw;
/*! The system language. */
std::unique_ptr<Language> lang;
+ /* keymap */
+ /*! The system timezone. */
+ std::unique_ptr<Timezone> tzone;
/*! Network addressing configuration */
std::vector< std::unique_ptr<NetAddress> > addresses;
@@ -141,6 +144,8 @@ struct Script::ScriptPrivate {
return store_lang(obj, lineno, errors, warnings, opts);
} else if(key_name == "firmware") {
return store_firmware(obj, lineno, errors, warnings, opts);
+ } else if(key_name == "timezone") {
+ return store_timezone(obj, lineno, errors, warnings, opts);
} else if(key_name == "repository") {
std::unique_ptr<Repository> repo(dynamic_cast<Repository *>(obj));
this->repos.push_back(std::move(repo));
@@ -263,6 +268,18 @@ struct Script::ScriptPrivate {
return true;
}
+ bool store_timezone(Keys::Key *obj, int lineno, int *errors, int *,
+ ScriptOptions) {
+ if(this->tzone) {
+ DUPLICATE_ERROR(this->tzone, std::string("timezone"),
+ this->tzone->value())
+ return false;
+ }
+ std::unique_ptr<Timezone> t(dynamic_cast<Timezone *>(obj));
+ this->tzone = std::move(t);
+ return true;
+ }
+
bool store_username(Keys::Key *obj, int lineno, int *errors, int *,
ScriptOptions) {
if(accounts.size() >= 255) {
@@ -560,7 +577,22 @@ bool Script::validate() const {
if(!this->internal->firmware->validate(this->opts)) failures++;
#endif
- /* timezone */
+ /* REQ: Runner.Execute.timezone */
+ if(!internal->tzone) {
+ Keys::Timezone *utc = dynamic_cast<Keys::Timezone *>(
+ Horizon::Keys::Timezone::parseFromData("UTC", 0,
+ &failures, nullptr)
+ );
+ if(!utc) {
+ output_error("internal", "failed to create default timezone");
+ return false;
+ }
+ std::unique_ptr<Keys::Timezone> zone(utc);
+ this->internal->tzone = std::move(zone);
+ }
+
+ /* REQ: Runner.Validate.timezone */
+ if(!this->internal->tzone->validate(this->opts)) failures++;
/* REQ: Script.repository */
if(this->internal->repos.size() == 0) {
@@ -900,6 +932,14 @@ bool Script::execute() const {
return false;
}
+ /* keymap */
+ /* UserAccounts */
+
+ if(!this->internal->tzone->execute(opts)) {
+ EXECUTE_FAILURE("post-metadata");
+ return false;
+ }
+
output_step_end("post-metadata");
return true;
}