Skip to content

Commit

Permalink
Merge branch 'feature/hyphen-fix' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
nsoblath committed Oct 15, 2024
2 parents 2921874 + a6451bd commit e24a927
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 25 deletions.
2 changes: 0 additions & 2 deletions examples/run_oscillator_service_endpoints.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ int main( int argc, char** argv )
add_dripline_options( the_main );
add_service_options( the_main );

add_dripline_auth_spec( the_main );

int the_return = -1;

auto t_service_callback = [&](){
Expand Down
2 changes: 0 additions & 2 deletions examples/run_oscillator_service_hub.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ int main( int argc, char** argv )
add_dripline_options( the_main );
add_service_options( the_main );

add_dripline_auth_spec( the_main );

int the_return = -1;

auto t_service_callback = [&](){
Expand Down
2 changes: 0 additions & 2 deletions examples/run_simple_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ int main( int argc, char** argv )
add_dripline_options( the_main );
add_service_options( the_main );

add_dripline_auth_spec( the_main );

int the_return = -1;

auto t_service_callback = [&](){
Expand Down
8 changes: 3 additions & 5 deletions executables/dl-agent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,12 @@ int main( int argc, char** argv )
[&]() { the_agent.execute< agent::sub_agent_alert>( the_main.primary_config(), the_main.nonoption_ord_args(), the_main.auth() ); }
);

// Default configuration
// Agent-specific default configuration
the_main.default_config() = agent_config();

// Dripline authentication specification
add_dripline_auth_spec( the_main );

// Command line options
// Dripline options and configuration conventions
add_dripline_options( the_main );

the_main.add_config_option< std::string >( "-s,--specifier", "specifier", "Set the specifier" );
the_main.add_config_multi_option< std::string >( "-P,--payload", "payload", "Add values to the payload" );
the_main.add_config_multi_option< std::string >( "--values", "option_values", "Add ordered values" ); // stored in the config as "option-values" so they can be merged in later in the proper order
Expand Down
3 changes: 0 additions & 3 deletions executables/dl-mon.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ int main( int argc, char** argv )
// Default configuration
the_main.default_config() = monitor_config();

// Dripline authentication specification
add_dripline_auth_spec( the_main );

try
{
// Command line options
Expand Down
4 changes: 2 additions & 2 deletions library/agent.hh
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ namespace dripline
"exchange" : "[exchange]",
"reply_timeout_ms": [ms] // optional; default is 10000
},
"auth-file" : "[filename]" // optional, if using an auth file
"auth-groups" : {
"auth_file" : "[filename]" // optional, if using an auth file
"auth_groups" : {
"dripline": {
"username": {[username specification]}
"password": {[password specification]}
Expand Down
15 changes: 11 additions & 4 deletions library/dripline_config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,18 @@ namespace dripline

void add_dripline_options( scarab::main_app& an_app )
{
// Fix two hyphen-->underscore issues
an_app.auth_file_key() = "auth_file";
an_app.auth_groups_key() = "auth_groups";

// Add auth spec (must be after fixing the keys above)
add_dripline_auth_spec( an_app );

// authentication for the broker
an_app.add_config_option< std::string >( "-u,--username", "auth-groups.dripline.username.value", "Specify the username for the rabbitmq broker" );
an_app.add_config_option< std::string >( "--password", "auth-groups.dripline.password.value", "Specify a password for the rabbitmq broker -- NOTE: this will be plain text on the command line and may end up in your command history!" );
an_app.add_config_option< std::string >( "--password-file", "auth-groups.dripline.password.file", "Specify a file (e.g. a secrets file) to be read in as the rabbitmq broker password" );
an_app.add_config_option< std::string >( "--auth-file", "auth-file", "Set the authentication file path" );
an_app.add_config_option< std::string >( "-u,--username", "auth_groups.dripline.username.value", "Specify the username for the rabbitmq broker" );
an_app.add_config_option< std::string >( "--password", "auth_groups.dripline.password.value", "Specify a password for the rabbitmq broker -- NOTE: this will be plain text on the command line and may end up in your command history!" );
an_app.add_config_option< std::string >( "--password-file", "auth_groups.dripline.password.file", "Specify a file (e.g. a secrets file) to be read in as the rabbitmq broker password" );
an_app.add_config_option< std::string >( "--auth-file", "auth_file", "Set the authentication file path" );

// other dripline things
an_app.add_config_option< std::string >( "-b,--broker", "dripline_mesh.broker", "Set the dripline broker address" );
Expand Down
2 changes: 1 addition & 1 deletion scarab
9 changes: 5 additions & 4 deletions testing/test_agent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ TEST_CASE( "agent_configuration", "[agent]" )
scarab::main_app the_main;
dripline::agent the_agent;

dripline::add_dripline_options( the_main );
the_main.default_config() = dripline::agent_config();
// Dripline authentication specification
dripline::add_dripline_auth_spec( the_main );
Expand All @@ -35,16 +36,16 @@ TEST_CASE( "agent_configuration", "[agent]" )
REQUIRE( the_main.default_config()["timeout"]().as_int() == 10 );
REQUIRE( the_main.default_config()["dripline_mesh"].is_node() );

REQUIRE( the_main.default_config().has("auth-groups") );
REQUIRE_THAT( the_main.default_config()["auth-groups"]["dripline"]["username"]["default"]().as_string(), Equals("guest") );
REQUIRE_THAT( the_main.default_config()["auth-groups"]["dripline"]["password"]["default"]().as_string(), Equals("guest") );
REQUIRE( the_main.default_config().has("auth_groups") );
REQUIRE_THAT( the_main.default_config()["auth_groups"]["dripline"]["username"]["default"]().as_string(), Equals("guest") );
REQUIRE_THAT( the_main.default_config()["auth_groups"]["dripline"]["password"]["default"]().as_string(), Equals("guest") );

// pre_callback() runs the configuration stages and authentication step
the_main.pre_callback();

REQUIRE( the_main.primary_config()["timeout"]().as_int() == 10 );
REQUIRE( the_main.primary_config()["dripline_mesh"].is_node() );
REQUIRE_FALSE( the_main.primary_config().has("auth-groups") ); // auth-groups should have been stripped out after authentication was handled by the_main
REQUIRE_FALSE( the_main.primary_config().has("auth_groups") ); // auth_groups should have been stripped out after authentication was handled by the_main
}

TEST_CASE( "sub_agent_get", "[agent]" )
Expand Down

0 comments on commit e24a927

Please sign in to comment.