Skip to content

Commit

Permalink
Update PR
Browse files Browse the repository at this point in the history
* Validate and document --auth-files operation
  • Loading branch information
abraunegg committed Oct 10, 2023
1 parent c551203 commit 82bd593
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 18 deletions.
24 changes: 22 additions & 2 deletions docs/application-config-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -816,9 +816,29 @@ _**Config Example:**_
## Command Line Interface (CLI) Only Options

### CLI Option: --auth-files
_**Description:**_
_**Description:**_ This CLI option allows the user to perform application authentication not via an interactive dialog but via specific files that the application uses to read the authentication data from.

_**Usage Example:**_
_**Usage Example:**_ `onedrive --auth-files authUrl:responseUrl`

_**Additional Usage Notes:**_ The authorisation URL is written to the specified 'authUrl' file, then onedrive waits for the file 'responseUrl' to be present, and reads the authentication response from that file. Example:

```text
onedrive --auth-files '~/onedrive-auth-url:~/onedrive-response-url'
Reading configuration file: /home/alex/.config/onedrive/config
Configuration file successfully loaded
Configuring Global Azure AD Endpoints
Client requires authentication before proceeding. Waiting for --auth-files elements to be available.
```
At this point, the client has written the file `~/onedrive-auth-url` which contains the authentication URL that needs to be visited to perform the authentication process. The client will now wait and watch for the presence of the file `~/onedrive-response-url`.

Visit the authentication URL, and then create a new file called `~/onedrive-response-url` with the response URI. Once this has been done, the application will acknowledge the presence of this file, read the contents, and authenticate the application.
```text
Sync Engine Initialised with new Onedrive API instance
--sync or --monitor switches missing from your command line input. Please add one (not both) of these switches to your command line or use 'onedrive --help' for further assistance.
No OneDrive sync will be performed without one of these two arguments being present.
```

### CLI Option: --auth-response
_**Description:**_
Expand Down
64 changes: 60 additions & 4 deletions src/config.d
Original file line number Diff line number Diff line change
Expand Up @@ -909,16 +909,25 @@ class ApplicationConfig {

bool ignore_depreciation = false;

// min_notify_changes as been depreciated
// min_notify_changes has been depreciated
if (key == "min_notify_changes") {
log.log("\nThis option 'min_notify_changes' has been depreciated and will be ignored. Please read the updated documentation and update your client configuration.");
log.log("\nThe option 'min_notify_changes' has been depreciated and will be ignored. Please read the updated documentation and update your client configuration.");
writeln();
ignore_depreciation = true;
}

// force_http_2 has been depreciated
if (key == "force_http_2") {
log.log("\nThe option 'force_http_2' has been depreciated and will be ignored. Please read the updated documentation and update your client configuration.");
writeln();
ignore_depreciation = true;
}

// Application configuration update required for Business Shared Folders
if (key == "sync_business_shared_folders") {
log.log("\nThe method to sync Business Shared Folders has changed. Please read the updated documentation and update your client configuration.");
log.log("\nThe process for synchronising Microsoft OneDrive Business Shared Folders has changed.");
log.log("Please review the revised documentation on how to configure this application feature. You must update your client configuration and make any necessary online adjustments accordingly.");
writeln();
}
// Return false
return ignore_depreciation;
Expand Down Expand Up @@ -1151,6 +1160,54 @@ class ApplicationConfig {
"Create a read-write shareable link for an existing file on OneDrive when used with --create-share-link <file>",
&boolValues["with_editing_perms"]
);

// Was --auth-files used?
if (!getValueString("auth_files").empty) {
// --auth-files used, need to validate that '~' was not used as a path identifier, and if yes, perform the correct expansion
string[] tempAuthFiles = getValueString("auth_files").split(":");
string tempAuthUrl = tempAuthFiles[0];
string tempResponseUrl = tempAuthFiles[1];
string newAuthFilesString;

// shell expansion if required
if (!shellEnvironmentSet){
// No shell environment is set, no automatic expansion of '~' if present is possible
// Does the 'currently configured' tempAuthUrl include a ~
if (canFind(tempAuthUrl, "~")) {
// A ~ was found in auth_files(authURL)
log.vdebug("auth_files: A '~' was found in 'auth_files(authURL)', using the calculated 'homePath' to replace '~' as no SHELL or USER environment variable set");
tempAuthUrl = buildNormalizedPath(buildPath(defaultHomePath, strip(tempAuthUrl, "~")));
}

// Does the 'currently configured' tempAuthUrl include a ~
if (canFind(tempResponseUrl, "~")) {
// A ~ was found in auth_files(authURL)
log.vdebug("auth_files: A '~' was found in 'auth_files(tempResponseUrl)', using the calculated 'homePath' to replace '~' as no SHELL or USER environment variable set");
tempResponseUrl = buildNormalizedPath(buildPath(defaultHomePath, strip(tempResponseUrl, "~")));
}
} else {
// Shell environment is set, automatic expansion of '~' if present is possible
// Does the 'currently configured' tempAuthUrl include a ~
if (canFind(tempAuthUrl, "~")) {
// A ~ was found in auth_files(authURL)
log.vdebug("auth_files: A '~' was found in the configured 'auth_files(authURL)', automatically expanding as SHELL and USER environment variable is set");
tempAuthUrl = expandTilde(tempAuthUrl);
}

// Does the 'currently configured' tempAuthUrl include a ~
if (canFind(tempResponseUrl, "~")) {
// A ~ was found in auth_files(authURL)
log.vdebug("auth_files: A '~' was found in the configured 'auth_files(tempResponseUrl)', automatically expanding as SHELL and USER environment variable is set");
tempResponseUrl = expandTilde(tempResponseUrl);
}
}

// Build new string
newAuthFilesString = tempAuthUrl ~ ":" ~ tempResponseUrl;
log.vdebug("auth_files - updated value: ", newAuthFilesString);
setValueString("auth_files", newAuthFilesString);
}

if (opt.helpWanted) {
outputLongHelp(opt.options);
exit(EXIT_SUCCESS);
Expand Down Expand Up @@ -1188,7 +1245,6 @@ class ApplicationConfig {
log.error("DEPRECIATION WARNING: --get-O365-drive-id has been depreciated in favour of --get-sharepoint-drive-id");
depreciatedCommandsFound = true;
}

}

if (depreciatedCommandsFound) {
Expand Down
8 changes: 0 additions & 8 deletions src/main.d
Original file line number Diff line number Diff line change
Expand Up @@ -839,14 +839,6 @@ int main(string[] cliArgs) {
return EXIT_FAILURE;
}

/**
// Before we exit, if we are using --dry-run, clean up the local syste,
if (appConfig.getValueBool("dry_run")) {
// Cleanup any existing dry-run elements ... these should never be left hanging around
cleanupDryRunDatabaseFiles(appConfig.databaseFilePathDryRun);
}
**/

// Exit application using exit scope
if (!syncEngineInstance.syncFailures) {
return EXIT_SUCCESS;
Expand Down
4 changes: 0 additions & 4 deletions src/sync.d
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,6 @@ class SyncEngine {
// - Process any items to add (download data to local)
// - Detail any files that we failed to download
// - Process any deletes (remove local data)
// - Walk local file system for any differences (new files / data to upload to OneDrive)
void syncOneDriveAccountToLocalDisk() {

// performFullScanTrueUp value
Expand Down Expand Up @@ -6787,7 +6786,4 @@ class SyncEngine {
log.error("Selected path not found on local system: ", inputFilePath);
}
}



}

0 comments on commit 82bd593

Please sign in to comment.