@@ -48,7 +48,6 @@ use jwt::SignWithKey;
4848use oauth2:: {
4949 basic:: BasicTokenType , AccessToken , EmptyExtraTokenFields , Scope , StandardTokenResponse ,
5050} ;
51- use serde_json:: Value as JsonValue ;
5251use std:: {
5352 collections:: BTreeMap ,
5453 convert:: TryFrom ,
@@ -60,7 +59,7 @@ use std::{collections::HashMap, ffi::OsStr};
6059use tmc_langs_framework:: { TmcError , TmcProjectYml } ;
6160use tmc_langs_plugins:: { get_language_plugin, tmc_zip, AntPlugin , PluginType } ;
6261use tmc_langs_util:: progress_reporter;
63- use toml:: { map :: Map as TomlMap , Value as TomlValue } ;
62+ use toml:: Value as TomlValue ;
6463use url:: Url ;
6564use walkdir:: WalkDir ;
6665
@@ -208,6 +207,7 @@ pub fn paste_exercise(
208207}
209208
210209/// Downloads the given exercises, by either downloading the exercise template, updating the exercise or downloading an old submission.
210+ /// Requires authentication.
211211/// If the exercise doesn't exist on disk yet...
212212/// if there are previous submissions and download_template is not set, the latest submission is downloaded.
213213/// otherwise, the exercise template is downloaded.
@@ -223,6 +223,8 @@ pub fn download_or_update_course_exercises(
223223 projects_dir. display( )
224224 ) ;
225225
226+ client. require_authentication ( ) ?;
227+
226228 let exercises_details = client. get_exercises_details ( exercises) ?;
227229 let projects_config = ProjectsConfig :: load ( projects_dir) ?;
228230
@@ -672,19 +674,12 @@ pub fn get_settings(client_name: &str) -> Result<TmcConfig, LangsError> {
672674}
673675
674676/// Saves a setting in the config.
675- pub fn set_setting ( client_name : & str , key : & str , value : & str ) -> Result < ( ) , LangsError > {
676- log:: debug!( "setting {}={} in {}" , key, value , client_name) ;
677+ pub fn set_setting < T : Serialize > ( client_name : & str , key : & str , value : T ) -> Result < ( ) , LangsError > {
678+ log:: debug!( "setting {} in {}" , key, client_name) ;
677679
678680 let config_path = TmcConfig :: get_location ( client_name) ?;
679681 let mut tmc_config = TmcConfig :: load ( client_name, & config_path) ?;
680- let value = match serde_json:: from_str ( value) {
681- Ok ( json) => json,
682- Err ( _) => {
683- // interpret as string
684- JsonValue :: String ( value. to_string ( ) )
685- }
686- } ;
687- let value = setting_json_to_toml ( value) ?;
682+ let value = TomlValue :: try_from ( value) ?;
688683
689684 tmc_config. insert ( key. to_string ( ) , value) ?;
690685 tmc_config. save ( & config_path) ?;
@@ -711,38 +706,6 @@ pub fn unset_setting(client_name: &str, key: &str) -> Result<(), LangsError> {
711706 Ok ( ( ) )
712707}
713708
714- fn setting_json_to_toml ( json : JsonValue ) -> Result < TomlValue , LangsError > {
715- match json {
716- JsonValue :: Array ( arr) => {
717- let mut v = vec ! [ ] ;
718- for value in arr {
719- v. push ( setting_json_to_toml ( value) ?) ;
720- }
721- Ok ( TomlValue :: Array ( v) )
722- }
723- JsonValue :: Bool ( b) => Ok ( TomlValue :: Boolean ( b) ) ,
724- JsonValue :: Null => Err ( LangsError :: SettingsCannotContainNull ) ,
725- JsonValue :: Number ( num) => {
726- if let Some ( int) = num. as_i64 ( ) {
727- Ok ( TomlValue :: Integer ( int) )
728- } else if let Some ( float) = num. as_f64 ( ) {
729- Ok ( TomlValue :: Float ( float) )
730- } else {
731- // this error can occur because serde_json supports u64 ints but toml doesn't
732- Err ( LangsError :: SettingNumberTooHigh ( num) )
733- }
734- }
735- JsonValue :: Object ( obj) => {
736- let mut map = TomlMap :: new ( ) ;
737- for ( key, value) in obj {
738- map. insert ( key, setting_json_to_toml ( value) ?) ;
739- }
740- Ok ( TomlValue :: Table ( map) )
741- }
742- JsonValue :: String ( s) => Ok ( TomlValue :: String ( s) ) ,
743- }
744- }
745-
746709/// Checks the exercise's code quality.
747710pub fn checkstyle (
748711 exercise_path : & Path ,
0 commit comments