Skip to content

Conversation

@callmefisher
Copy link
Collaborator

No description provided.

@gemini-code-assist
Copy link

Summary of Changes

Hello @callmefisher, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refactors the authentication mechanism within the LiveStreamingService to improve clarity and correctness in how API keys and Qiniu access credentials are prioritized and used. It also includes a minor update to the Qiniu token generation logic to handle empty paths more precisely, ensuring more accurate request signing.

Highlights

  • Authentication Logic Refinement: The priority and handling of API keys (live_api_key) and Qiniu access/secret keys for authentication have been reordered and clarified within the _get_auth_header method.
  • API Key Renaming: The api_key attribute in LiveStreamingService has been renamed to live_api_key for better clarity and consistency.
  • Qiniu Token Path Handling: A minor adjustment was made to how the path is included when generating Qiniu tokens, removing the default '/' for empty paths.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the Miku MCP tools, primarily focusing on the authentication logic within the LiveStreamingService. The changes refactor the API key handling for better consistency and modify the authentication priority.

My review has identified two key issues:

  1. A critical bug has been introduced in the _get_auth_header method. The removal of error handling for cases where no authentication credentials are provided will lead to a TypeError at runtime.
  2. An issue in the _generate_qiniu_token method where the URL path handling for signature generation has been changed incorrectly, which will likely cause authentication to fail for certain requests.

I have provided detailed comments and code suggestions to address these issues. Please review them carefully.


# 1. Add Method and Path
data = f"{method} {parsed.path or '/'}"
data = f"{method} {parsed.path}"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The change from parsed.path or '/' to parsed.path is incorrect. urlparse(url).path can return an empty string for URLs without a path component (e.g., http://example.com). In such cases, the path for signature calculation should be /. The previous implementation handled this correctly. This change will likely lead to authentication failures for some API calls, such as create_bucket. Please revert this change.

Suggested change
data = f"{method} {parsed.path}"
data = f"{method} {parsed.path or '/'}"

self.secret_key = cfg.secret_key if cfg else None


def _get_auth_header(self, method: str, url: str, content_type: Optional[str] = None, body: Optional[str] = None) -> Dict[str, str]:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CRITICAL: Missing error handling for unconfigured authentication

This method now returns None implicitly when neither authentication method is configured, which will cause runtime errors in all API methods. The removed error handling should be restored:

Suggested change
def _get_auth_header(self, method: str, url: str, content_type: Optional[str] = None, body: Optional[str] = None) -> Dict[str, str]:
def _get_auth_header(self, method: str, url: str, content_type: Optional[str] = None, body: Optional[str] = None) -> Dict[str, str]:
"""
Generate authentication header for API requests.
Priority order:
1. API KEY authentication (Bearer token) - if configured
2. ACCESS_KEY/SECRET_KEY authentication (Qiniu token) - if API KEY not available
Raises:
ValueError: If neither authentication method is properly configured
"""
# Priority 1: Use API KEY authentication if configured
if self.live_api_key and self.live_api_key != "YOUR_QINIU_LIVE_API_KEY":
return {
"Authorization": f"Bearer {self.live_api_key}"
}
# Priority 2: Fall back to ACCESS_KEY/SECRET_KEY authentication
if self.access_key and self.secret_key and \
self.access_key != "YOUR_QINIU_ACCESS_KEY" and \
self.secret_key != "YOUR_QINIU_SECRET_KEY":
token = self._generate_qiniu_token(method, url, content_type, body)
return {
"Authorization": f"Qiniu {token}"
}
raise ValueError(
"Authentication not configured: Either LIVE_API_KEY or both ACCESS_KEY/SECRET_KEY must be set"
)

Issues:

  • Security: Allows unauthenticated requests to be attempted
  • Reliability: Causes TypeError when headers=None is passed to aiohttp
  • Performance: Fails late with network errors instead of failing fast with clear config errors

"""
# Priority 1: Use QINIU_ACCESS_KEY/QINIU_SECRET_KEY if configured

# Priority 1: Fall back to API KEY if ACCESS_KEY/SECRET_KEY not configured
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Misleading comment: This says "Fall back to API KEY" but API KEY is checked first (Priority 1), not as a fallback. The comment contradicts the code behavior.

Should be: # Priority 1: Use API KEY authentication if configured

"Authorization": f"Bearer {self.live_api_key}"
}

# Priority 2: Use QINIU_ACCESS_KEY/QINIU_SECRET_KEY if configured
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Misleading comment: This should say "Fall back to" since ACCESS_KEY/SECRET_KEY is now the secondary authentication method (Priority 2).

Should be: # Priority 2: Fall back to ACCESS_KEY/SECRET_KEY authentication if API KEY not available


# 1. Add Method and Path
data = f"{method} {parsed.path or '/'}"
data = f"{method} {parsed.path}"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potential authentication issue: Removing the or '/' fallback means empty paths will be used as-is in signature generation. If the Qiniu API expects paths to be normalized to / when empty, this will cause authentication failures.

Recommend restoring the fallback unless this was intentionally tested:

Suggested change
data = f"{method} {parsed.path}"
data = f"{method} {parsed.path or '/'}"

@xgopilot
Copy link

xgopilot bot commented Nov 21, 2025

Code Review Summary

This PR reverses authentication priority and renames api_key to live_api_key. However, critical error handling was removed that will cause runtime failures.

Must Fix:

  • Missing error handling when auth is unconfigured (returns None → crashes)
  • Misleading comments that contradict the authentication priority

Positive: Variable rename to live_api_key improves clarity

See inline comments for specific fixes.

@callmefisher callmefisher merged commit 34653ef into qiniu:main Nov 22, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant