Skip to content
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

extend_content does not receive the security context in cube.py #8753

Open
igorlukanin opened this issue Sep 27, 2024 · 0 comments
Open

extend_content does not receive the security context in cube.py #8753

igorlukanin opened this issue Sep 27, 2024 · 0 comments
Assignees
Labels
bug Something isn't working configuration

Comments

@igorlukanin
Copy link
Member

Describe the bug
extend_context configuration parameter allows to extend the security context, as described in the docs and as expected, when provided via the cube.js file.

However, when provided via the cube.py file, the res (first) parameter to extend_context does not contain securityContext, so there's no way to extend it, just provide a new one from scratch.

To Reproduce
Steps to reproduce the behavior:

  1. Use the following cube.py file:
from cube import config
 
@config('check_auth')
def check_auth(ctx: dict, token: str) -> None:
  new_ctx = {
    'security_context': {
      'user_id': 42
    }
  }

  return new_ctx
 
@config('extend_context')
def extend_context(req: dict) -> dict:
  req.setdefault('securityContext', {})
  print(req['securityContext'])

  return req

@config('context_to_app_id')
def context_to_app_id(ctx: dict) -> dict:
  return f"CUBE_APP_{str(ctx['securityContext'])}"
  1. Run a query
  2. See only empty objects/dictionaries ({}) printed in the console
  3. Alternatively, try the following, equivalent cube.js file
module.exports = {
  checkAuth: (ctx, token) => {
    let new_ctx = {
      'security_context': {
        'user_id': 42
      }
    }

    return new_ctx
  },

  extendContext: (req) => {
    console.log(req['securityContext'])

    return req
  },

  contextToAppId: (ctx) => {
    return `CUBE_APP_${JSON.stringify(ctx['securityContext'])}`
  }
}
  1. See extended security context printed in the console

Expected behavior
extend_context works as described in docs in both cube.js and cube.py files.

Version:
v0.36.3

Additional context
Discovered via Slack: https://cube-js.slack.com/archives/C04NYBJP7RQ/p1727431492374679?thread_ts=1727361286.150869&cid=C04NYBJP7RQ

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working configuration
Projects
None yet
Development

No branches or pull requests

2 participants