copy_users.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #!/usr/bin/env python3
  2. #
  3. # Copyright (c) 2017-2020 Joe Clarke <jclarke@cisco.com>
  4. # All rights reserved.
  5. #
  6. # Redistribution and use in source and binary forms, with or without
  7. # modification, are permitted provided that the following conditions
  8. # are met:
  9. # 1. Redistributions of source code must retain the above copyright
  10. # notice, this list of conditions and the following disclaimer.
  11. # 2. Redistributions in binary form must reproduce the above copyright
  12. # notice, this list of conditions and the following disclaimer in the
  13. # documentation and/or other materials provided with the distribution.
  14. #
  15. # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  16. # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17. # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  18. # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  19. # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  20. # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  21. # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  22. # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  23. # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  24. # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  25. # SUCH DAMAGE.
  26. from __future__ import print_function
  27. import sys
  28. import json
  29. from argparse import ArgumentParser
  30. from sparker import Sparker, ResourceType
  31. def main():
  32. parser = ArgumentParser(description="Usage: ")
  33. parser.add_argument("-S", "--source-team", type=str, help="Name of the source Team of the Room")
  34. parser.add_argument("-s", "--source-room", type=str, help="Name of the source Room")
  35. parser.add_argument("-D", "--dest-team", type=str, help="Name of the destination Team of the Room")
  36. parser.add_argument("-d", "--dest-room", type=str, help="Name of the destination Room")
  37. parser.add_argument("-t", "--token", type=str, help="Webex Teams Token", required=True)
  38. args = parser.parse_args()
  39. spark = Sparker(token=args.token)
  40. resource = None
  41. if args.source_team:
  42. resource = args.source_team
  43. type = ResourceType.TEAM
  44. elif args.source_room:
  45. resource = args.source_room
  46. type = ResourceType.ROOM
  47. else:
  48. print("ERROR: Either a source Room or source Team must be specified")
  49. sys.exit(1)
  50. members = spark.get_members(resource, type)
  51. if not members:
  52. print("ERROR: Failed to get members")
  53. sys.exit(1)
  54. if args.dest_team:
  55. resource = args.dest_team
  56. type = ResourceType.TEAM
  57. elif args.dest_room:
  58. resource = args.dest_room
  59. type = ResourceType.ROOM
  60. else:
  61. print("ERROR: Either a destination Room or destination Team must be specified")
  62. sys.exit(1)
  63. if not spark.add_members(members, resource, type):
  64. print("ERROR: Failed to add one or more members")
  65. sys.exit(1)
  66. if __name__ == "__main__":
  67. main()