Skip to content

Commit

Permalink
Refactor BackupStoreAccountControl to be for a specific account ID
Browse files Browse the repository at this point in the history
This allows other BackupAccountControl implementations to implement the same
interface without needing to support account IDs, which are very
store-specific.
  • Loading branch information
qris committed Jul 8, 2017
1 parent 6d3fde6 commit 45e6f1f
Show file tree
Hide file tree
Showing 4 changed files with 236 additions and 254 deletions.
206 changes: 106 additions & 100 deletions bin/bbstoreaccounts/bbstoreaccounts.cpp
Expand Up @@ -175,128 +175,134 @@ int main(int argc, const char *argv[])
argv++;
argc--;


BackupStoreAccountControl control(*config, machineReadableOutput);
BackupStoreAccountControl control(*config, id, machineReadableOutput);

// Now do the command.
if(command == "create")
{
// which disc?
int32_t discnum;
int32_t softlimit;
int32_t hardlimit;
if(argc < 3
|| ::sscanf(argv[0], "%d", &discnum) != 1)
{
BOX_ERROR("create requires raid file disc number, "
"soft and hard limits.");
return 1;
}

// Decode limits
int blocksize = control.BlockSizeOfDiscSet(discnum);
softlimit = control.SizeStringToBlocks(argv[1], blocksize);
hardlimit = control.SizeStringToBlocks(argv[2], blocksize);
control.CheckSoftHardLimits(softlimit, hardlimit);

// Create the account...
return control.CreateAccount(id, discnum, softlimit, hardlimit);
}
else if(command == "info")
try
{
// Print information on this account
return control.PrintAccountInfo(id);
}
else if(command == "enabled")
{
// Change the AccountEnabled flag on this account
if(argc != 1)
if(command == "create")
{
return PrintUsage();
}
// which disc?
int32_t discnum;
int32_t softlimit;
int32_t hardlimit;
if(argc < 3
|| ::sscanf(argv[0], "%d", &discnum) != 1)
{
BOX_ERROR("create requires raid file disc number, "
"soft and hard limits.");
return 1;
}

// Decode limits
int blocksize = control.BlockSizeOfDiscSet(discnum);
softlimit = control.SizeStringToBlocks(argv[1], blocksize);
hardlimit = control.SizeStringToBlocks(argv[2], blocksize);
control.CheckSoftHardLimits(softlimit, hardlimit);

bool enabled = true;
std::string enabled_string = argv[0];
if(enabled_string == "yes")
{
enabled = true;
// Create the account...
return control.CreateAccount(discnum, softlimit, hardlimit);
}
else if(enabled_string == "no")
else if(command == "info")
{
enabled = false;
// Print information on this account
return control.PrintAccountInfo();
}
else
else if(command == "enabled")
{
return PrintUsage();
}

return control.SetAccountEnabled(id, enabled);
}
else if(command == "setlimit")
{
// Change the limits on this account
if(argc < 2)
{
BOX_ERROR("setlimit requires soft and hard limits.");
return 1;
}

return control.SetLimit(id, argv[0], argv[1]);
}
else if(command == "name")
{
// Change the limits on this account
if(argc != 1)
{
BOX_ERROR("name command requires a new name.");
return 1;
// Change the AccountEnabled flag on this account
if(argc != 1)
{
return PrintUsage();
}

bool enabled = true;
std::string enabled_string = argv[0];
if(enabled_string == "yes")
{
enabled = true;
}
else if(enabled_string == "no")
{
enabled = false;
}
else
{
return PrintUsage();
}

return control.SetAccountEnabled(enabled);
}

return control.SetAccountName(id, argv[0]);
}
else if(command == "delete")
{
// Delete an account
bool askForConfirmation = true;
if(argc >= 1 && (::strcmp(argv[0], "yes") == 0))
else if(command == "setlimit")
{
askForConfirmation = false;
// Change the limits on this account
if(argc < 2)
{
BOX_ERROR("setlimit requires soft and hard limits.");
return 1;
}

return control.SetLimit(argv[0], argv[1]);
}
return control.DeleteAccount(id, askForConfirmation);
}
else if(command == "check")
{
bool fixErrors = false;
bool quiet = false;

// Look at other options
for(int o = 0; o < argc; ++o)
else if(command == "name")
{
if(::strcmp(argv[o], "fix") == 0)
// Change the limits on this account
if(argc != 1)
{
fixErrors = true;
BOX_ERROR("name command requires a new name.");
return 1;
}
else if(::strcmp(argv[o], "quiet") == 0)
return control.SetAccountName(argv[0]);
}
else if(command == "delete")
{
// Delete an account
bool askForConfirmation = true;
if(argc >= 1 && (::strcmp(argv[0], "yes") == 0))
{
quiet = true;
askForConfirmation = false;
}
else
return control.DeleteAccount(askForConfirmation);
}
else if(command == "check")
{
bool fixErrors = false;
bool quiet = false;

// Look at other options
for(int o = 0; o < argc; ++o)
{
BOX_ERROR("Unknown option " << argv[o] << ".");
return 2;
if(::strcmp(argv[o], "fix") == 0)
{
fixErrors = true;
}
else if(::strcmp(argv[o], "quiet") == 0)
{
quiet = true;
}
else
{
BOX_ERROR("Unknown option " << argv[o] << ".");
return 2;
}
}

// Check the account
return control.CheckAccount(fixErrors, quiet);
}
else if(command == "housekeep")
{
return control.HousekeepAccountNow();
}
else
{
BOX_ERROR("Unknown command '" << command << "'.");
return 1;
}

// Check the account
return control.CheckAccount(id, fixErrors, quiet);
}
else if(command == "housekeep")
{
return control.HousekeepAccountNow(id);
}
else
catch(BoxException &e)
{
BOX_ERROR("Unknown command '" << command << "'.");
BOX_ERROR("Failed command: " << command << ": " << e.what());
return 1;
}

Expand Down

0 comments on commit 45e6f1f

Please sign in to comment.