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

api/auth: Add capacity to authorize via playback ID #1714

Merged
merged 13 commits into from
May 9, 2023

Conversation

victorges
Copy link
Member

@victorges victorges commented May 3, 2023

What does this pull request do? Explain your changes. (required)
This is to increment the /api/auth API, used by external services that need to
build on top of the API authorization, to also support authorizing access to a
given playback ID. This playback ID can not only be the canonical playback ID of
assets/streams, but can also be the "aliased" IDs like a dStorage ID.

This will be used in the viewership v2 API when it is accessed with a playback ID filter.

Specific updates (required)

  • Refactor "playback info" implementation to have a separate "get resource by playback ID" function
  • Add x-livepeer-playback-id header support to auth API
  • Parallelize the authorization checks just in case
    • (also need to optimize the getResourceByPlaybackId at some point)

How did you test each of these updates (required)
yarn test

Does this pull request close any open issues?
Implements API-50

Checklist

  • I have read the CONTRIBUTING document.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.

@vercel
Copy link

vercel bot commented May 3, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
livepeer-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 8, 2023 3:23pm

@codecov
Copy link

codecov bot commented May 3, 2023

Codecov Report

Merging #1714 (d38012a) into master (b959d4e) will increase coverage by 0.25254%.
The diff coverage is 97.72727%.

Impacted file tree graph

@@                 Coverage Diff                 @@
##              master       #1714         +/-   ##
===================================================
+ Coverage   53.61029%   53.86283%   +0.25254%     
===================================================
  Files             75          75                 
  Lines           5055        5074         +19     
  Branches        1008        1017          +9     
===================================================
+ Hits            2710        2733         +23     
+ Misses          2001        1999          -2     
+ Partials         344         342          -2     
Impacted Files Coverage Δ
packages/api/src/middleware/auth.ts 91.34615% <ø> (ø)
packages/api/src/controllers/auth.ts 95.23810% <90.90909%> (-4.76190%) ⬇️
packages/api/src/controllers/playback.ts 85.71429% <100.00000%> (+3.89611%) ⬆️

... and 1 file with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b959d4e...d38012a. Read the comment docs.

Impacted Files Coverage Δ
packages/api/src/middleware/auth.ts 91.34615% <ø> (ø)
packages/api/src/controllers/auth.ts 95.23810% <90.90909%> (-4.76190%) ⬇️
packages/api/src/controllers/playback.ts 85.71429% <100.00000%> (+3.89611%) ⬆️

... and 1 file with indirect coverage changes

@victorges victorges changed the title Vg/feat/viewership auth api/auth: Add capacity to authorize via playback ID May 4, 2023
@victorges victorges marked this pull request as ready for review May 4, 2023 15:25
@victorges victorges requested a review from a team as a code owner May 4, 2023 15:25
Copy link
Contributor

@leszko leszko left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@@ -16,30 +17,51 @@ type UserOwnedObj = { id: string; deleted?: boolean; userId?: string };
async function checkUserOwned(
req: Request,
headerName: string,
table: Table<UserOwnedObj>
getter: (id: string) => Promise<UserOwnedObj>
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice abstraction!

@victorges victorges merged commit ca14ed1 into master May 9, 2023
12 checks passed
@victorges victorges deleted the vg/feat/viewership-auth branch May 9, 2023 15:46
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.

None yet

2 participants