Skip to content

Commit

Permalink
Update PR
Browse files Browse the repository at this point in the history
* Update PR
  • Loading branch information
abraunegg committed Oct 16, 2023
1 parent d893ea5 commit 6db484c
Show file tree
Hide file tree
Showing 5 changed files with 218 additions and 84 deletions.
12 changes: 9 additions & 3 deletions docs/application-config-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ _**Config Example:**_ `monitor_fullscan_frequency = "24"`

_**CLI Option Use:**_ `--monitor-fullscan-frequency '24'`

_**Additional Usage Notes:**_ By default without configuration, 'monitor_fullscan_frequency' is set to 12. In this default state, this means that a full scan is performed every 'monitor_interval' x 'monitor_fullscan_frequency' = 3600 seconds. This setting is only applicable when running in `--monitor` mode.
_**Additional Usage Notes:**_ By default without configuration, 'monitor_fullscan_frequency' is set to 12. In this default state, this means that a full scan is performed every 'monitor_interval' x 'monitor_fullscan_frequency' = 3600 seconds. This setting is only applicable when running in `--monitor` mode. Setting this configuration option to '0' will *disable* the full scan of your data online.

### monitor_interval
_**Description:**_ This configuration setting determines how often the synchronisation loops run in --monitor mode, measured in seconds. When this time period elapses, the client will check for online changes in Microsoft OneDrive, conduct integrity checks on local data and scan the local 'sync_dir' to identify any new content that hasn't been uploaded yet.
Expand Down Expand Up @@ -841,9 +841,15 @@ No OneDrive sync will be performed without one of these two arguments being pres
```

### CLI Option: --auth-response
_**Description:**_
_**Description:**_ This CLI option allows the user to perform application authentication not via an interactive dialog but via providing the authentication response URI directly.

_**Usage Example:**_
_**Usage Example:**_ `onedrive --auth-response https://login.microsoftonline.com/common/oauth2/nativeclient?code=<redacted>`

_**Additional Usage Notes:**_ Typically, unless the application client identifier, authentication scopes are being modified or a specific Azure Tenant is being specified, the authentication URL will mostlikely be as follows:
```text
https://login.microsoftonline.com/common/oauth2/v2.0/authorise?client_id=22c49a0d-d21c-4792-aed1-8f163c982546&scope=Files.ReadWrite%20Files.ReadWrite.all%20Sites.ReadWrite.All%20offline_access&response_type=code&redirect_uri=https://login.microsoftonline.com/common/oauth2/nativeclient
```
With this URL being known, it is possible ahead of time to request an authentication token by visiting this URL, and performing the authenticaton access request.

### CLI Option: --confdir
_**Description:**_ This CLI option allows the user to specify where all the application configuration and relevant components are stored.
Expand Down
14 changes: 12 additions & 2 deletions src/config.d
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import std.path;
import std.getopt;
import std.format;
import std.ascii;
import std.datetime;

// What other modules that we have created do we need to import?
import log;
Expand Down Expand Up @@ -99,6 +100,11 @@ class ApplicationConfig {
string refreshTokenFilePath = "";
// Store the refreshToken for use within the application
string refreshToken;
// Store the accessTokenExpiration for use within the application
SysTime accessTokenExpiration;
// Store the current accessToken for use within the application
string accessToken;

// Store the 'session_upload.CRC32-HASH' file path
string uploadSessionFilePath = "";

Expand Down Expand Up @@ -873,8 +879,12 @@ class ApplicationConfig {
ulong tempValue = thisConfigValue;
// the temp value needs to be greater than 12
if (tempValue < 12) {
log.log("Invalid value for key in config file - using default value: ", key);
tempValue = 12;
// If this is not set to zero (0) then we are not disabling 'monitor_fullscan_frequency'
if (tempValue != 0) {
// invalid value
log.log("Invalid value for key in config file - using default value: ", key);
tempValue = 12;
}
}
setValueLong("monitor_fullscan_frequency", to!long(tempValue));
}
Expand Down
24 changes: 15 additions & 9 deletions src/main.d
Original file line number Diff line number Diff line change
Expand Up @@ -718,15 +718,21 @@ int main(string[] cliArgs) {
fullScanFrequencyLoopCount++;
monitorLogOutputLoopCount++;

// Do we flag to perform a full scan of the online data?
if (fullScanFrequencyLoopCount > fullScanFrequency) {
// set full scan trigger for true up
log.vdebug("Enabling Full Scan True Up (fullScanFrequencyLoopCount > fullScanFrequency), resetting fullScanFrequencyLoopCount = 1");
fullScanFrequencyLoopCount = 1;
appConfig.fullScanTrueUpRequired = true;
// If full scan at a specific frequency enabled?
if (fullScanFrequency > 0) {
// Full Scan set for some 'frequency' - do we flag to perform a full scan of the online data?
if (fullScanFrequencyLoopCount > fullScanFrequency) {
// set full scan trigger for true up
log.vdebug("Enabling Full Scan True Up (fullScanFrequencyLoopCount > fullScanFrequency), resetting fullScanFrequencyLoopCount = 1");
fullScanFrequencyLoopCount = 1;
appConfig.fullScanTrueUpRequired = true;
} else {
// unset full scan trigger for true up
log.vdebug("Disabling Full Scan True Up");
appConfig.fullScanTrueUpRequired = false;
}
} else {
// unset full scan trigger for true up
log.vdebug("Disabling Full Scan True Up");
// No it is disabled - ensure this is false
appConfig.fullScanTrueUpRequired = false;
}

Expand Down Expand Up @@ -930,7 +936,7 @@ void performStandardSyncProcess(string localPath, Monitor filesystemMonitor = nu

// Perform the final true up scan to ensure we have correctly replicated the current online state locally
if (!appConfig.surpressLoggingOutput) {
log.log("Performing a final true-up scan of online data from Microsoft OneDrive");
log.log("Performing a last examination of the most recent online data within Microsoft OneDrive to complete the reconciliation process");
}
// We pass in the 'appConfig.fullScanTrueUpRequired' value which then flags do we use the configured 'deltaLink'
// If 'appConfig.fullScanTrueUpRequired' is true, we do not use the 'deltaLink' if we are in --monitor mode, thus forcing a full scan true up
Expand Down
14 changes: 6 additions & 8 deletions src/onedrive.d
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ class OneDriveApi {
string tenantId = "";
string authScope = "";
string refreshToken = "";
string accessToken = "";
SysTime accessTokenExpiration;
bool dryRun = false;
bool debugResponse = false;
ulong retryAfterValue = 0;
Expand Down Expand Up @@ -737,7 +735,7 @@ class OneDriveApi {
}

private void addAccessTokenHeader() {
curlEngine.http.addRequestHeader("Authorization", accessToken);
curlEngine.http.addRequestHeader("Authorization", appConfig.accessToken);
}

private void addIncludeFeatureRequestHeader() {
Expand Down Expand Up @@ -790,20 +788,20 @@ class OneDriveApi {
}

if ("access_token" in response){
accessToken = "bearer " ~ strip(response["access_token"].str);
appConfig.accessToken = "bearer " ~ strip(response["access_token"].str);

// Do we print the current access token
if (log.verbose > 1) {
if (appConfig.getValueBool("debug_https")) {
if (appConfig.getValueBool("print_token")) {
// This needs to be highly restricted in output ....
log.vdebug("CAUTION - KEEP THIS SAFE: Current access token: ", accessToken);
log.vdebug("CAUTION - KEEP THIS SAFE: Current access token: ", appConfig.accessToken);
}
}
}

refreshToken = strip(response["refresh_token"].str);
accessTokenExpiration = Clock.currTime() + dur!"seconds"(response["expires_in"].integer());
appConfig.accessTokenExpiration = Clock.currTime() + dur!"seconds"(response["expires_in"].integer());
if (!dryRun) {
// Update the refreshToken in appConfig so that we can reuse it
if (appConfig.refreshToken.empty) {
Expand Down Expand Up @@ -843,9 +841,9 @@ class OneDriveApi {

private void checkAccessTokenExpired() {
try {
if (Clock.currTime() >= accessTokenExpiration) {
if (Clock.currTime() >= appConfig.accessTokenExpiration) {
newToken();
}
}
} catch (OneDriveException e) {
if (e.httpStatusCode == 400 || e.httpStatusCode == 401) {
// flag error and notify
Expand Down
Loading

0 comments on commit 6db484c

Please sign in to comment.