-
Notifications
You must be signed in to change notification settings - Fork 26
refactor: Update User-Agent #103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ayeshurun
wants to merge
48
commits into
microsoft:main
Choose a base branch
from
ayeshurun:host-app-user-agent
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
48 commits
Select commit
Hold shift + click to select a range
36520e2
Change pull_request to pull_request_target
ayeshurun 444d351
Merge pull request #4 from ayeshurun/fix-semantic-pr
ayeshurun 8b34e28
Merge branch 'microsoft:main' into main
ayeshurun 0c47fda
Merge branch 'microsoft:main' into main
ayeshurun ccd7b91
Merge branch 'microsoft:main' into main
ayeshurun 43cc353
Merge branch 'microsoft:main' into main
ayeshurun ea76426
Merge branch 'microsoft:main' into main
ayeshurun c702b91
Merge branch 'microsoft:main' into main
ayeshurun 5e847ef
Merge branch 'microsoft:main' into main
ayeshurun 69c733e
Merge branch 'microsoft:main' into main
ayeshurun 5d5f1ad
Merge branch 'microsoft:main' into main
ayeshurun 0c5de9c
Merge branch 'microsoft:main' into main
ayeshurun 025f456
Merge branch 'microsoft:main' into main
ayeshurun df0c5a4
Merge branch 'microsoft:main' into main
ayeshurun c6892ed
Merge branch 'microsoft:main' into main
ayeshurun f30ce9b
Merge branch 'microsoft:main' into main
ayeshurun cf7e06b
Merge branch 'microsoft:main' into main
ayeshurun 3a727dd
Merge branch 'main' of https://github.com/ayeshurun/fabric-cli
1de4d6b
Support host app
d3cfbb4
Merge branch 'main' of https://github.com/ayeshurun/fabric-cli
bb051b1
Merge branch 'main' of https://github.com/ayeshurun/fabric-cli
f46f685
Merge branch 'microsoft:main' into main
ayeshurun 19e3a75
Merge branch 'main' of https://github.com/ayeshurun/fabric-cli
55020f0
Fix new functionality section in release notes
0c08fb5
Merge branch 'microsoft:main' into main
ayeshurun beb0149
Fix new functionality section in release notes
c0e3672
Merge branch 'main' of https://github.com/ayeshurun/fabric-cli
ca313c3
Introduce release workflow
8aa05e7
Merge pull request #14 from ayeshurun/release-workflow
ayeshurun 39f2d85
Add GH_TOKEN to create release step
ayeshurun 5e3b68e
Initial plan
Copilot 7c573b0
Enhance create-release workflow with GITHUB_STEP_SUMMARY and optional…
Copilot f9a4bb2
Refactor GITHUB_STEP_SUMMARY messages to use heredoc syntax
Copilot f04c7b7
Merge pull request #16 from ayeshurun/copilot/enhance-create-release-…
ayeshurun 641c4e7
Update release notes for v1.3.1
ayeshurun 516dbb8
Fix new functionality section in release notes
484993f
Introduce release workflow
3a42a5c
Add GH_TOKEN to create release step
ayeshurun 0755733
Initial plan
Copilot 5917da7
Enhance create-release workflow with GITHUB_STEP_SUMMARY and optional…
Copilot 635eadc
Refactor GITHUB_STEP_SUMMARY messages to use heredoc syntax
Copilot 22cc9cb
Update release notes for v1.3.1
ayeshurun 44f44b3
Merge branch 'main' of https://github.com/ayeshurun/fabric-cli
d9c9eaf
Merge branch 'main' of https://github.com/ayeshurun/fabric-cli into h…
bd2ad0f
Add changelog entry
aa06952
Remove changelog
756dd40
Update host app value
ec9ee93
Add fab host app version
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |
| # Licensed under the MIT License. | ||
|
|
||
| import json | ||
| import os | ||
| import platform | ||
| import re | ||
| import time | ||
|
|
@@ -96,9 +97,10 @@ def do_request( | |
| from fabric_cli.core.fab_context import Context as FabContext | ||
|
|
||
| ctxt_cmd = FabContext().command | ||
|
|
||
| headers = { | ||
| "Authorization": "Bearer " + str(token), | ||
| "User-Agent": f"{fab_constant.API_USER_AGENT}/{fab_constant.FAB_VERSION} ({ctxt_cmd}; {platform.system()}; {platform.machine()}; {platform.release()})", | ||
| "User-Agent": _build_user_agent(ctxt_cmd), | ||
| } | ||
|
|
||
| if files is None: | ||
|
|
@@ -279,6 +281,54 @@ def _handle_successful_response(args: Namespace, response: ApiResponse) -> ApiRe | |
| return response | ||
|
|
||
|
|
||
| def _build_user_agent(ctxt_cmd: str) -> str: | ||
| """Build the User-Agent header for API requests. | ||
|
|
||
| Example: | ||
| ms-fabric-cli/1.0.0 (create; Windows/10; Python/3.10.2) host-app/ado/2.0.0 | ||
| """ | ||
| user_agent = f"{fab_constant.API_USER_AGENT}/{fab_constant.FAB_VERSION} ({ctxt_cmd}; {platform.system()}/{platform.release()}; Python/{platform.python_version()})" | ||
| host_app = _get_host_app() | ||
| if host_app: | ||
| user_agent += host_app | ||
|
|
||
| return user_agent | ||
|
|
||
|
|
||
| def _get_host_app() -> str: | ||
| """Get the HostApp suffix for the User-Agent header based on environment variables. | ||
|
|
||
| Returns an empty string if the environment variable is not set or has an invalid value. | ||
| """ | ||
| _host_app_in_env = os.environ.get(fab_constant.FAB_HOST_APP_ENV_VAR) | ||
| if not _host_app_in_env: | ||
| return "" | ||
|
|
||
| host_app_name = next( | ||
| ( | ||
| allowed_app | ||
| for allowed_app in fab_constant.ALLOWED_FAB_HOST_APP_VALUES | ||
| if _host_app_in_env.lower() == allowed_app.lower() | ||
| ), | ||
| None, | ||
| ) | ||
|
|
||
| if not host_app_name: | ||
| return "" | ||
|
|
||
| host_app = f" host-app/{host_app_name.lower()}" | ||
|
|
||
| # Check for optional version | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit - remove "what" comment |
||
| host_app_version = os.environ.get(fab_constant.FAB_HOST_APP_VERSION_ENV_VAR) | ||
|
|
||
| # validate host_app_version format is a valid version (e.g., 1.0.0) | ||
| if host_app_version and re.match( | ||
| r"^\d+(\.\d+){0,2}(-[a-zA-Z0-9\.-]+)?$", host_app_version | ||
| ): | ||
| host_app += f"/{host_app_version}" | ||
| return host_app | ||
|
|
||
|
|
||
| def _print_response_details(response: ApiResponse) -> None: | ||
| response_details = dict( | ||
| { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to print warning in those cases?
More broadly, what is the purpose of the host_app value in the request headers?