Skip to content

Commit

Permalink
Merge pull request #668 from reef-technologies/ua-append
Browse files Browse the repository at this point in the history
Add a possibility to append a string to the User-Agent
  • Loading branch information
mlech-reef authored Nov 3, 2020
2 parents 1af7dbb + 8d5dce4 commit 48ea5e3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added
* Add support for Python 3.9
* Add a possibility to append a string to the User-Agent via `B2_USER_AGENT_APPEND` env

### Changed
* Update `b2 sync` usage text for bucket-to-bucket sync
Expand Down
11 changes: 10 additions & 1 deletion b2/console_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
parse_sync_folder,
AuthInfoCache,
B2Api,
B2Http,
B2RawApi,
Synchronizer,
SyncReport,
NewerFileSyncMode,
Expand All @@ -58,6 +60,8 @@
# Optional Env variable to use for getting account info while authorizing
B2_APPLICATION_KEY_ID_ENV_VAR = 'B2_APPLICATION_KEY_ID'
B2_APPLICATION_KEY_ENV_VAR = 'B2_APPLICATION_KEY'
# Optional Env variable to use for adding custom string to the User Agent
B2_USER_AGENT_APPEND_ENV_VAR = 'B2_USER_AGENT_APPEND'

# Enable to get 0.* behavior in the command-line tool.
# Disable for 1.* behavior.
Expand All @@ -75,6 +79,7 @@
B2_ACCOUNT_INFO_DEFAULT_FILE=B2_ACCOUNT_INFO_DEFAULT_FILE,
B2_APPLICATION_KEY_ID_ENV_VAR=B2_APPLICATION_KEY_ID_ENV_VAR,
B2_APPLICATION_KEY_ENV_VAR=B2_APPLICATION_KEY_ENV_VAR,
B2_USER_AGENT_APPEND_ENV_VAR=B2_USER_AGENT_APPEND_ENV_VAR,
)


Expand Down Expand Up @@ -249,6 +254,9 @@ class B2(Command):
B2 Storage service. Each different command may required additional
capabilities. You can find the details for each command in the help for
that command.
A string provided via an optional environment variable {B2_USER_AGENT_APPEND_ENV_VAR}
will be appended to the User-Agent.
"""

subcommands_registry = ClassRegistry()
Expand Down Expand Up @@ -1607,7 +1615,8 @@ def __str__(self):
def main():
info = SqliteAccountInfo()
cache = AuthInfoCache(info)
b2_api = B2Api(info, cache=cache)
raw_api = B2RawApi(B2Http(user_agent_append=os.environ.get(B2_USER_AGENT_APPEND_ENV_VAR)))
b2_api = B2Api(info, cache=cache, raw_api=raw_api)
ct = ConsoleTool(b2_api=b2_api, stdout=sys.stdout, stderr=sys.stderr)
exit_status = ct.run_command(sys.argv)
logger.info('\\\\ %s %s %s //', SEPARATOR, ('exit=%s' % exit_status).center(8), SEPARATOR)
Expand Down

0 comments on commit 48ea5e3

Please sign in to comment.