Skip to content
Snippets Groups Projects

Implemented POST and PUT methods for Restream Destinations

Description

This merge request introduces new POST and PUT methods for managing restream destinations in the api_1_GetRestreams resource. The POST method allows users to add new restream destinations to a specific channel, and the PUT method enables users to update existing restream destinations. Both methods include authorization checks and error handling.

Motivation and Context

The motivation for this change is to provide users with greater control over their restreaming settings through the API. Prior to this update, users could only retrieve restream destinations but could not add new ones or modify existing ones. By enabling these functionalities, we are enhancing the usability and flexibility of our service. This change does not fix an open issue but represents an enhancement of existing functionalities.

How Has This Been Tested?

The new methods have been tested locally to ensure they correctly add and update restream destinations in the database. The authorization checks and error handling have also been verified. Further testing may be required in different environments and with different test cases to ensure robustness and compatibility.

Screenshots (if appropriate):

N/A

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • Merge Request Follows the Merge Request Guidelines
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
426 def post(self, channelEndpointID):
427 """Add a new restream destination for a channel"""
428 # Check API Key
429 if "X-API-KEY" in request.headers:
430 requestAPIKey = apikey.apikey.query.filter_by(key=request.headers["X-API-KEY"]).first()
431 if requestAPIKey is not None and requestAPIKey.isValid():
432 channelData = (
433 Channel.Channel.query.filter_by(
434 channelLoc=channelEndpointID,
435 owningUser=requestAPIKey.userID,
436 )
437 .with_entities(Channel.Channel.id)
438 .first()
439 )
440 else:
441 authorized = checkRTMPAuthIP(request)
  • 480 args = request.json
    481
    482 # Check API Key
    483 if "X-API-KEY" in request.headers:
    484 requestAPIKey = apikey.apikey.query.filter_by(key=request.headers["X-API-KEY"]).first()
    485 if requestAPIKey is not None and requestAPIKey.isValid():
    486 channelData = (
    487 Channel.Channel.query.filter_by(
    488 channelLoc=channelEndpointID,
    489 owningUser=requestAPIKey.userID,
    490 )
    491 .with_entities(Channel.Channel.id)
    492 .first()
    493 )
    494 else:
    495 authorized = checkRTMPAuthIP(request)
  • 441 authorized = checkRTMPAuthIP(request)
    442 if authorized[0] is False:
    443 return {"results": {"message": "Unauthorized RTMP Server or Missing User API Key - " + authorized[1]}}, 400
    444 channelData = cachedDbCalls.getChannelByLoc(channelEndpointID)
    445
    446 # Check if channel exists
    447 if channelData is None:
    448 return {"results": "error", "reason": "channelNotFound"}
    449
    450 # Get request arguments
    451 args = request.json
    452
    453 # Create new restream destination
    454 new_restreamDestination = Channel.restreamDestinations(
    455 channel=channelData.id,
    456 name=args['name'],
  • 442 if authorized[0] is False:
    443 return {"results": {"message": "Unauthorized RTMP Server or Missing User API Key - " + authorized[1]}}, 400
    444 channelData = cachedDbCalls.getChannelByLoc(channelEndpointID)
    445
    446 # Check if channel exists
    447 if channelData is None:
    448 return {"results": "error", "reason": "channelNotFound"}
    449
    450 # Get request arguments
    451 args = request.json
    452
    453 # Create new restream destination
    454 new_restreamDestination = Channel.restreamDestinations(
    455 channel=channelData.id,
    456 name=args['name'],
    457 url=args['url']
  • 446 # Check if channel exists
    447 if channelData is None:
    448 return {"results": "error", "reason": "channelNotFound"}
    449
    450 # Get request arguments
    451 args = request.json
    452
    453 # Create new restream destination
    454 new_restreamDestination = Channel.restreamDestinations(
    455 channel=channelData.id,
    456 name=args['name'],
    457 url=args['url']
    458 )
    459
    460 # Convert 'enabled' to a boolean
    461 enabled_str = args.get('enabled', 'False')
  • 496 if authorized[0] is False:
    497 return {"results": {"message": "Unauthorized RTMP Server or Missing User API Key - " + authorized[1]}}, 400
    498 channelData = cachedDbCalls.getChannelByLoc(channelEndpointID)
    499
    500 # Check if channel exists
    501 if channelData is not None:
    502 # Get the restream destination to update
    503 restreamDestination = Channel.restreamDestinations.query.filter_by(id=args['id']).first()
    504
    505 if restreamDestination is not None:
    506 # Update the restream destination fields
    507 restreamDestination.name = args['name']
    508 restreamDestination.url = args['url']
    509
    510 # Convert 'enabled' to a boolean
    511 enabled_str = args.get('enabled', 'False')
  • 492 .first()
    493 )
    494 else:
    495 authorized = checkRTMPAuthIP(request)
    496 if authorized[0] is False:
    497 return {"results": {"message": "Unauthorized RTMP Server or Missing User API Key - " + authorized[1]}}, 400
    498 channelData = cachedDbCalls.getChannelByLoc(channelEndpointID)
    499
    500 # Check if channel exists
    501 if channelData is not None:
    502 # Get the restream destination to update
    503 restreamDestination = Channel.restreamDestinations.query.filter_by(id=args['id']).first()
    504
    505 if restreamDestination is not None:
    506 # Update the restream destination fields
    507 restreamDestination.name = args['name']
  • 493 )
    494 else:
    495 authorized = checkRTMPAuthIP(request)
    496 if authorized[0] is False:
    497 return {"results": {"message": "Unauthorized RTMP Server or Missing User API Key - " + authorized[1]}}, 400
    498 channelData = cachedDbCalls.getChannelByLoc(channelEndpointID)
    499
    500 # Check if channel exists
    501 if channelData is not None:
    502 # Get the restream destination to update
    503 restreamDestination = Channel.restreamDestinations.query.filter_by(id=args['id']).first()
    504
    505 if restreamDestination is not None:
    506 # Update the restream destination fields
    507 restreamDestination.name = args['name']
    508 restreamDestination.url = args['url']
  • Rizwan Ahmed added 65 commits

    added 65 commits

    • 2b2929f0...7f36ff60 - 63 commits from branch osp-group:nightly
    • 65feb1a5 - Merge branch 'nightly' into 'master'
    • 3dca81a1 - Merge branch flask-nginx-rtmp-manager:master into master

    Compare with previous version

  • Rizwan Ahmed added 1 commit

    added 1 commit

    • b89c24ab - Added the API params to swagger

    Compare with previous version

  • Rizwan Ahmed added 1 commit

    added 1 commit

    • cd3e37cf - removed the authorized check

    Compare with previous version

  • Rizwan Ahmed added 1 commit

    added 1 commit

    • 9c630802 - Added the provision to fetch channels using userID.

    Compare with previous version

  • Rizwan Ahmed added 1 commit

    added 1 commit

    • 35a1e5af - Modified the authorization checks

    Compare with previous version

  • Rizwan Ahmed added 1 commit

    added 1 commit

    • 5324bac9 - Added fetch by userID functionality.

    Compare with previous version

  • Rizwan Ahmed added 1 commit

    added 1 commit

    Compare with previous version

  • Rizwan Ahmed added 1 commit

    added 1 commit

    Compare with previous version

  • Rizwan Ahmed added 1 commit

    added 1 commit

    • ff8a46a6 - Changed the requestAPIKey.userID to args[userID]

    Compare with previous version

  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Please register or sign in to reply
    Loading