copy_users.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. parser.add_argument("-f", "--source-file", type=str, help="Path to file containing list of emails")
  39. args = parser.parse_args()
  40. spark = Sparker(token=args.token)
  41. resource = None
  42. if args.source_team:
  43. resource = args.source_team
  44. type = ResourceType.TEAM
  45. elif args.source_room:
  46. resource = args.source_room
  47. type = ResourceType.ROOM
  48. elif not args.source_file:
  49. print("ERROR: Either a source Room, source Team, or source file must be specified")
  50. sys.exit(1)
  51. if not args.source_file:
  52. members = spark.get_members(resource, type)
  53. if not members:
  54. print("ERROR: Failed to get members")
  55. sys.exit(1)
  56. else:
  57. with open(args.source_file, "rb") as fd:
  58. contents = fd.read().decode("utf-8")
  59. members = [x.strip() for x in contents.split("\n")]
  60. if args.dest_team:
  61. resource = args.dest_team
  62. type = ResourceType.TEAM
  63. elif args.dest_room:
  64. resource = args.dest_room
  65. type = ResourceType.ROOM
  66. else:
  67. print("ERROR: Either a destination Room or destination Team must be specified")
  68. sys.exit(1)
  69. if not spark.add_members(members, resource, type):
  70. print("ERROR: Failed to add one or more members")
  71. sys.exit(1)
  72. if __name__ == "__main__":
  73. main()