Added networking support for SL1 Digest authorization.

Renamed login/password/authorization_type to printhost_user/printhost_password/printhost_authorization_type.
Added initialization of physical printer preset with default values.
This commit is contained in:
Vojtech Bubnik 2020-09-08 15:30:59 +02:00
parent 0a4debc98c
commit ce06fc6cb7
11 changed files with 98 additions and 41 deletions

View file

@ -170,6 +170,13 @@ std::string OctoPrint::make_url(const std::string &path) const
}
}
SL1Host::SL1Host(DynamicPrintConfig *config) :
OctoPrint(config),
authorization_type(dynamic_cast<const ConfigOptionEnum<AuthorizationType>*>(config->option("printhost_authorization_type"))->value),
username(config->opt_string("printhost_user")),
password(config->opt_string("printhost_password"))
{
}
// SL1Host
const char* SL1Host::get_name() const { return "SL1Host"; }
@ -191,4 +198,20 @@ bool SL1Host::validate_version_text(const boost::optional<std::string> &version_
return version_text ? boost::starts_with(*version_text, "Prusa SLA") : false;
}
void SL1Host::set_auth(Http &http) const
{
switch (authorization_type) {
case atKeyPassword:
http.header("X-Api-Key", get_apikey());
break;
case atUserPassword:
http.auth_digest(username, password);
break;
}
if (! get_cafile().empty()) {
http.ca_file(get_cafile());
}
}
}