Skip to content

Commit

Permalink
Merge pull request #2468 from htcondor/V23_8-HTCONDOR-2389-convert-mo…
Browse files Browse the repository at this point in the history
…re-lists

HTCONDOR-2389 convert-more-lists
  • Loading branch information
GregThain committed May 16, 2024
2 parents d17f779 + fab28e1 commit e65806d
Show file tree
Hide file tree
Showing 17 changed files with 172 additions and 214 deletions.
54 changes: 25 additions & 29 deletions src/annex/BulkRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,13 @@ BulkRequest::validateAndStore( ClassAd const * command, std::string & validation


std::string b;
StringList taglist;
std::string taglist;
formatstr( b, "%s=%s", "htcondor:AnnexName", annexID.c_str() );
taglist.append( b.c_str() );
taglist = b;

std::string buffer;
if( command->LookupString( ATTR_EC2_TAG_NAMES, buffer ) ) {
StringList tagNames(buffer);

char * tagName = NULL;
tagNames.rewind();
while( (tagName = tagNames.next()) ) {
for (const auto& tagName: StringTokenIterator(buffer)) {
std::string tagAttr(ATTR_EC2_TAG_PREFIX);
tagAttr.append(tagName);

Expand All @@ -117,16 +113,15 @@ BulkRequest::validateAndStore( ClassAd const * command, std::string & validation
return FALSE;
}

formatstr( b, "%s=%s", tagName, tagValue );
taglist.append( b.c_str() );
formatstr( b, "%s=%s", tagName.c_str(), tagValue );
if (!taglist.empty()) taglist += ',';
taglist += b;

free( tagValue );
}
}

char * s = taglist.print_to_string();
blob[ "Tags" ] = s;
free( s );
blob[ "Tags" ] = taglist;


ExprTree * iipTree = launchConfiguration.Lookup( "IamInstanceProfile" );
Expand All @@ -150,7 +145,7 @@ BulkRequest::validateAndStore( ClassAd const * command, std::string & validation
return false;
}

StringList sgIDList, sgNameList;
std::string sgIDList, sgNameList;
auto sgIterator = sgList->begin();
for( ; sgIterator != sgList->end(); ++sgIterator ) {
classad::ClassAd * ca = dynamic_cast<classad::ClassAd *>( * sgIterator );
Expand All @@ -163,20 +158,22 @@ BulkRequest::validateAndStore( ClassAd const * command, std::string & validation
std::string groupID, groupName;
securityGroup.LookupString( "GroupId", groupID );
securityGroup.LookupString( "GroupName", groupName );
if(! groupID.empty()) { sgIDList.append( groupID.c_str() ); }
if(! groupName.empty()){ sgNameList.append( groupName.c_str() ); }
if(! groupID.empty()) {
if (!sgIDList.empty()) sgIDList += ", ";
sgIDList += groupID;
}
if(! groupName.empty()){
if (!sgNameList.empty()) sgNameList += ", ";
sgNameList += groupName;
}
}

char * fail = sgIDList.print_to_delimed_string( ", " );
if( fail ) {
blob[ "SecurityGroupIDs" ] = fail;
free( fail );
if( !sgIDList.empty() ) {
blob[ "SecurityGroupIDs" ] = sgIDList;
}

char * suck = sgNameList.print_to_delimed_string( ", " );
if( suck ) {
blob[ "SecurityGroupNames" ] = suck;
free( suck );
if( !sgNameList.empty() ) {
blob[ "SecurityGroupNames" ] = sgNameList;
}
}

Expand All @@ -188,7 +185,7 @@ BulkRequest::validateAndStore( ClassAd const * command, std::string & validation
return false;
}

StringList bdmList;
std::string bdmList;
auto bdmIterator = blockDeviceMappings->begin();
for( ; bdmIterator != blockDeviceMappings->end(); ++bdmIterator ) {
classad::ClassAd * ca = dynamic_cast<classad::ClassAd *>( * bdmIterator );
Expand Down Expand Up @@ -243,13 +240,12 @@ BulkRequest::validateAndStore( ClassAd const * command, std::string & validation
std::string bdmString;
formatstr( bdmString, "%s=%s:%d:%s:%s",
dn.c_str(), si.c_str(), vs, dot ? "true" : "false", vt.c_str() );
bdmList.append( bdmString.c_str() );
if (!bdmList.empty()) bdmList += ", ";
bdmList += bdmString;
}

char * fail = bdmList.print_to_delimed_string( ", " );
if( fail != NULL ) {
blob[ "BlockDeviceMapping" ] = fail;
free( fail );
if( !bdmList.empty() ) {
blob[ "BlockDeviceMapping" ] = bdmList;
}
}

Expand Down
20 changes: 5 additions & 15 deletions src/annex/OnDemandRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,7 @@ OnDemandRequest::OnDemandRequest( ClassAd * r, EC2GahpClient * egc, ClassAd * s,

std::string iidString;
commandState->LookupString( "State_InstanceIDs", iidString );
if(! iidString.empty()) {
StringList sl( iidString.c_str(), "," );
sl.rewind(); char * current = sl.next();
for( ; current != NULL; current = sl.next() ) {
instanceIDs.emplace_back(current );
}
}
instanceIDs = split(iidString, ",");
}

// Generate a client token if we didn't get one from the log.
Expand Down Expand Up @@ -104,15 +98,11 @@ OnDemandRequest::log() {
}

if( instanceIDs.size() != 0 ) {
StringList sl;
for( size_t i = 0; i < instanceIDs.size(); ++i ) {
sl.append( instanceIDs[i].c_str() );
}
char * slString = sl.print_to_delimed_string( "," );
std::string quoted; formatstr( quoted, "\"%s\"", slString );
free( slString );
std::string sl = "\"";
sl += join(instanceIDs, ",");
sl += '"';
commandState->SetAttribute( commandID,
"State_InstanceIDs", quoted.c_str() );
"State_InstanceIDs", sl.c_str() );
} else {
commandState->DeleteAttribute( commandID,
"State_InstanceIDs" );
Expand Down
6 changes: 1 addition & 5 deletions src/annex/annex-create.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,7 @@ createOneAnnex( ClassAd * command, Stream * replyStream, ClassAd * reply ) {
std::string buffer;
std::vector< std::pair< std::string, std::string > > tags;
if( command->LookupString( ATTR_EC2_TAG_NAMES, buffer ) ) {
StringList tagNames( buffer );

char * tagName = NULL;
tagNames.rewind();
while( (tagName = tagNames.next()) ) {
for (const auto& tagName: StringTokenIterator(buffer)) {
std::string tagAttr(ATTR_EC2_TAG_PREFIX);
tagAttr.append(tagName);

Expand Down
11 changes: 5 additions & 6 deletions src/annex/annex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1292,17 +1292,16 @@ annex_main( int argc, char ** argv ) {
switch( theCommand ) {
case ct_create_annex:
case ct_update_annex: {
StringList tagNames;
std::string tagNames;
std::string attrName;
for( unsigned i = 0; i < tags.size(); ++i ) {
tagNames.append(tags[i].first.c_str());
if (!tagNames.empty()) tagNames += ',';
tagNames += tags[i].first;
formatstr( attrName, "%s%s", ATTR_EC2_TAG_PREFIX, tags[i].first.c_str() );
commandArguments.Assign( attrName, tags[i].second.c_str() );
commandArguments.Assign( attrName, tags[i].second );
}

char * sl = tagNames.print_to_string();
commandArguments.Assign( ATTR_EC2_TAG_NAMES, sl );
free( sl );
commandArguments.Assign( ATTR_EC2_TAG_NAMES, tagNames );
} break;

default:
Expand Down
4 changes: 2 additions & 2 deletions src/condor_daemon_core.V6/condor_daemon_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -2255,7 +2255,7 @@ class DaemonCore : public Service
*/
void InitSettableAttrsLists( void );
bool InitSettableAttrsList( const char* subsys, int i );
StringList* SettableAttrsLists[LAST_PERM];
std::vector<std::string>* SettableAttrsLists[LAST_PERM];

bool peaceful_shutdown;

Expand Down Expand Up @@ -2381,7 +2381,7 @@ bool InitCommandSockets(int tcp_port, int udp_port, DaemonCore::SockPairVec & so
// helper function to extract the parent address and inherited socket information from
// the inherit string that is normally passed via the CONDOR_INHERIT environment variable
// This function extracts parent & socket info then tokenizes the remaining items from
// the string into the supplied StringList.
// the string into the supplied vector.
//
// @return
// number of entries in the socks[] array that were populated.
Expand Down
36 changes: 15 additions & 21 deletions src/condor_daemon_core.V6/daemon_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ DaemonCore::DaemonCore(int ComSize,int SigSize,
inServiceCommandSocket_flag = FALSE;
m_need_reconfig = false;
m_delay_reconfig = false;
// Initialize our array of StringLists used to authorize
// Initialize our array of lists used to authorize
// condor_config_val -set and friends.
int i;
for( i=0; i<LAST_PERM; i++ ) {
Expand Down Expand Up @@ -2907,7 +2907,7 @@ DaemonCore::reconfig(void) {
// Initialize the collector list for ClassAd updates
initCollectorList();

// Initialize the StringLists that contain the attributes we
// Initialize the lists that contain the attributes we
// will allow people to set with condor_config_val from
// various kinds of hosts (ADMINISTRATOR, CONFIG, WRITE, etc).
InitSettableAttrsLists();
Expand Down Expand Up @@ -8684,7 +8684,7 @@ DaemonCore::Proc_Family_QuitProcd(void(*notify)(void*me, int pid, int status), v


// extracts the parent address and inherited socket information from the given inherit string
// then tokenizes the remaining items from the inherit string into the supplied StringList.
// then tokenizes the remaining items from the inherit string into the supplied vector.
// return value: number of entries in the socks[] array that were populated.
// note: the size of the socks array should be 1 more than the maximum
//
Expand Down Expand Up @@ -10374,23 +10374,19 @@ bool
DaemonCore::CheckConfigSecurity( const char* config, Sock* sock )
{
// we've got to check each textline of the string passed in by
// config. here we use the StringList class to split lines.

StringList all_attrs (config, "\n");
// config.

// start out by assuming everything is okay. we'll check all
// the attrs and set this flag if something is not authorized.
bool all_attrs_okay = true;

char *single_attr;
all_attrs.rewind();

// short-circuit out of the while once any attribute is not
// short-circuit out of the loop once any attribute is not
// okay. otherwise, get one value at a time
while (all_attrs_okay && (single_attr = all_attrs.next())) {
for (const auto& single_attr: StringTokenIterator(config, "\n")) {
// check this individual attr
if (!CheckConfigAttrSecurity(single_attr, sock)) {
if (!CheckConfigAttrSecurity(single_attr.c_str(), sock)) {
all_attrs_okay = false;
break;
}
}

Expand Down Expand Up @@ -10440,8 +10436,7 @@ DaemonCore::CheckConfigAttrSecurity( const char* name, Sock* sock )
if( sock->isAuthorizationInBoundingSet(perm_name) && Verify(command_desc.c_str(),(DCpermission)i, sock->peer_addr(), sock->getFullyQualifiedUser())) {
// now we can see if the specific attribute they're
// trying to set is in our list.
if( (SettableAttrsLists[i])->
contains_anycase_withwildcard(name) ) {
if( contains_anycase_withwildcard(*SettableAttrsLists[i], name) ) {
// everything's cool. allow this.

#if (DEBUG_SETTABLE_ATTR_LISTS)
Expand Down Expand Up @@ -10502,19 +10497,18 @@ DaemonCore::InitSettableAttrsLists( void )
}
// there's no subsystem-specific one, just try the generic
// version. if this doesn't work either, we just leave
// this StringList NULL and will ignore cmds from it.
// this list NULL and will ignore cmds from it.
InitSettableAttrsList( NULL, i );
}

#if (DEBUG_SETTABLE_ATTR_LISTS)
// Just for debugging, print out everything
char* tmp;
std::string tmp;
for( i=0; i<LAST_PERM; i++ ) {
if( SettableAttrsLists[i] ) {
tmp = (SettableAttrsLists[i])->print_to_string();
tmp = join(*SettableAttrsLists[i], ",");
dprintf( D_ALWAYS, "SettableAttrList[%s]: %s\n",
PermString((DCpermission)i), tmp?tmp:"" );
free( tmp );
PermString((DCpermission)i), tmp.c_str() );
}
}
#endif
Expand All @@ -10537,8 +10531,8 @@ DaemonCore::InitSettableAttrsList( const char* /* subsys */, int i )
param_name += PermString((DCpermission)i);
tmp = param( param_name.c_str() );
if( tmp ) {
SettableAttrsLists[i] = new StringList;
(SettableAttrsLists[i])->initializeFromString( tmp );
SettableAttrsLists[i] = new std::vector<std::string>;
*SettableAttrsLists[i] = split(tmp);
free( tmp );
return true;
}
Expand Down
21 changes: 5 additions & 16 deletions src/condor_daemon_core.V6/daemon_core_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1949,21 +1949,15 @@ handle_dc_start_token_request(int, Stream* stream)
std::set<std::string> config_bounding_set;
std::string config_bounding_set_str;
if (param(config_bounding_set_str, "SEC_TOKEN_REQUEST_LIMITS")) {
StringList config_bounding_set_list(config_bounding_set_str.c_str());
config_bounding_set_list.rewind();
const char *authz;
while ( (authz = config_bounding_set_list.next()) ) {
for (const auto& authz: StringTokenIterator(config_bounding_set_str)) {
config_bounding_set.insert(authz);
}
}

std::vector<std::string> authz_list;
std::string authz_list_str;
if (ad.EvaluateAttrString(ATTR_SEC_LIMIT_AUTHORIZATION, authz_list_str)) {
StringList authz_str_list(authz_list_str.c_str());
authz_str_list.rewind();
const char *authz;
while ( (authz = authz_str_list.next()) ) {
for (const auto& authz: StringTokenIterator(authz_list_str)) {
if (config_bounding_set.empty() || (config_bounding_set.find(authz) != config_bounding_set.end())) {
authz_list.emplace_back(authz);
}
Expand Down Expand Up @@ -2621,12 +2615,7 @@ handle_dc_session_token(int, Stream* stream)
std::vector<std::string> authz_list;
std::string authz_list_str;
if (ad.EvaluateAttrString(ATTR_SEC_LIMIT_AUTHORIZATION, authz_list_str)) {
StringList authz_str_list(authz_list_str.c_str());
authz_str_list.rewind();
const char *authz;
while ( (authz = authz_str_list.next()) ) {
authz_list.emplace_back(authz);
}
authz_list = split(authz_list_str);
}
int requested_lifetime;
if (ad.EvaluateAttrInt(ATTR_SEC_TOKEN_LIFETIME, requested_lifetime)) {
Expand All @@ -2645,8 +2634,8 @@ handle_dc_session_token(int, Stream* stream)
if (ad.EvaluateAttrString(ATTR_SEC_REQUESTED_KEY, requested_key_name)) {
std::string allowed_key_names_list;
param( allowed_key_names_list, "SEC_TOKEN_FETCH_ALLOWED_SIGNING_KEYS", "POOL" );
StringList sl(allowed_key_names_list);
if( sl.contains_withwildcard(requested_key_name.c_str()) ) {
std::vector<std::string> sl = split(allowed_key_names_list);
if( contains_withwildcard(sl, requested_key_name) ) {
final_key_name = requested_key_name;
} else {
result_ad.InsertAttr(ATTR_ERROR_STRING, "Server will not sign with requested key.");
Expand Down
2 changes: 1 addition & 1 deletion src/condor_includes/condor_cron_job_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class CondorCronJobList
int NumJobs( void ) const { return (int)m_job_list.size(); };
int NumAliveJobs(std::string * names = nullptr) const;
int NumActiveJobs() const;
bool GetStringList( StringList &sl ) const;
bool GetStringList( std::vector<std::string> &sl ) const;
double RunningJobLoad( void ) const;
bool AddJob(
const char *jobName,
Expand Down
12 changes: 5 additions & 7 deletions src/condor_startd.V6/startd_bench_job_mgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,25 +98,23 @@ StartdBenchJobMgr::StartBenchmarks( Resource *rip, int &count )
int
StartdBenchJobMgr::Reconfig( void )
{
StringList before, after;
std::vector<std::string> before, after;

m_job_list.GetStringList( before );
int status = CronJobMgr::HandleReconfig();
m_job_list.GetStringList( after );
if ( status ) {
return status;
}
if ( ! before.identical(after) ) {
char *before_str = before.print_to_string();
char *after_str = after.print_to_string();
if ( before != after ) {
std::string before_str = join(before, ",");
std::string after_str = join(after, ",");
dprintf( D_ALWAYS,
"WARNING: benchmark job list changed from '%s' to '%s'"
" -- If there are additions to the benchmark list, these"
" new benchmarks won't be run until the 'RunBenchmarks'"
" expresion becomes true and all benchmarks are run.\n",
before_str?before_str:"", after_str?after_str:"" );
free( before_str );
free( after_str );
before_str.c_str(), after_str.c_str() );
}
return 1;
}
Expand Down

0 comments on commit e65806d

Please sign in to comment.