paasta-tools 1.21.3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (348) hide show
  1. k8s_itests/__init__.py +0 -0
  2. k8s_itests/test_autoscaling.py +23 -0
  3. k8s_itests/utils.py +38 -0
  4. paasta_tools/__init__.py +20 -0
  5. paasta_tools/adhoc_tools.py +142 -0
  6. paasta_tools/api/__init__.py +13 -0
  7. paasta_tools/api/api.py +330 -0
  8. paasta_tools/api/api_docs/swagger.json +2323 -0
  9. paasta_tools/api/client.py +106 -0
  10. paasta_tools/api/settings.py +33 -0
  11. paasta_tools/api/tweens/__init__.py +6 -0
  12. paasta_tools/api/tweens/auth.py +125 -0
  13. paasta_tools/api/tweens/profiling.py +108 -0
  14. paasta_tools/api/tweens/request_logger.py +124 -0
  15. paasta_tools/api/views/__init__.py +13 -0
  16. paasta_tools/api/views/autoscaler.py +100 -0
  17. paasta_tools/api/views/exception.py +45 -0
  18. paasta_tools/api/views/flink.py +73 -0
  19. paasta_tools/api/views/instance.py +395 -0
  20. paasta_tools/api/views/pause_autoscaler.py +71 -0
  21. paasta_tools/api/views/remote_run.py +113 -0
  22. paasta_tools/api/views/resources.py +76 -0
  23. paasta_tools/api/views/service.py +35 -0
  24. paasta_tools/api/views/version.py +25 -0
  25. paasta_tools/apply_external_resources.py +79 -0
  26. paasta_tools/async_utils.py +109 -0
  27. paasta_tools/autoscaling/__init__.py +0 -0
  28. paasta_tools/autoscaling/autoscaling_service_lib.py +57 -0
  29. paasta_tools/autoscaling/forecasting.py +106 -0
  30. paasta_tools/autoscaling/max_all_k8s_services.py +41 -0
  31. paasta_tools/autoscaling/pause_service_autoscaler.py +77 -0
  32. paasta_tools/autoscaling/utils.py +52 -0
  33. paasta_tools/bounce_lib.py +184 -0
  34. paasta_tools/broadcast_log_to_services.py +62 -0
  35. paasta_tools/cassandracluster_tools.py +210 -0
  36. paasta_tools/check_autoscaler_max_instances.py +212 -0
  37. paasta_tools/check_cassandracluster_services_replication.py +35 -0
  38. paasta_tools/check_flink_services_health.py +203 -0
  39. paasta_tools/check_kubernetes_api.py +57 -0
  40. paasta_tools/check_kubernetes_services_replication.py +141 -0
  41. paasta_tools/check_oom_events.py +244 -0
  42. paasta_tools/check_services_replication_tools.py +324 -0
  43. paasta_tools/check_spark_jobs.py +234 -0
  44. paasta_tools/cleanup_kubernetes_cr.py +138 -0
  45. paasta_tools/cleanup_kubernetes_crd.py +145 -0
  46. paasta_tools/cleanup_kubernetes_jobs.py +344 -0
  47. paasta_tools/cleanup_tron_namespaces.py +96 -0
  48. paasta_tools/cli/__init__.py +13 -0
  49. paasta_tools/cli/authentication.py +85 -0
  50. paasta_tools/cli/cli.py +260 -0
  51. paasta_tools/cli/cmds/__init__.py +13 -0
  52. paasta_tools/cli/cmds/autoscale.py +143 -0
  53. paasta_tools/cli/cmds/check.py +334 -0
  54. paasta_tools/cli/cmds/cook_image.py +147 -0
  55. paasta_tools/cli/cmds/get_docker_image.py +76 -0
  56. paasta_tools/cli/cmds/get_image_version.py +172 -0
  57. paasta_tools/cli/cmds/get_latest_deployment.py +93 -0
  58. paasta_tools/cli/cmds/info.py +155 -0
  59. paasta_tools/cli/cmds/itest.py +117 -0
  60. paasta_tools/cli/cmds/list.py +66 -0
  61. paasta_tools/cli/cmds/list_clusters.py +42 -0
  62. paasta_tools/cli/cmds/list_deploy_queue.py +171 -0
  63. paasta_tools/cli/cmds/list_namespaces.py +84 -0
  64. paasta_tools/cli/cmds/local_run.py +1396 -0
  65. paasta_tools/cli/cmds/logs.py +1601 -0
  66. paasta_tools/cli/cmds/mark_for_deployment.py +1988 -0
  67. paasta_tools/cli/cmds/mesh_status.py +174 -0
  68. paasta_tools/cli/cmds/pause_service_autoscaler.py +107 -0
  69. paasta_tools/cli/cmds/push_to_registry.py +275 -0
  70. paasta_tools/cli/cmds/remote_run.py +252 -0
  71. paasta_tools/cli/cmds/rollback.py +347 -0
  72. paasta_tools/cli/cmds/secret.py +549 -0
  73. paasta_tools/cli/cmds/security_check.py +59 -0
  74. paasta_tools/cli/cmds/spark_run.py +1400 -0
  75. paasta_tools/cli/cmds/start_stop_restart.py +401 -0
  76. paasta_tools/cli/cmds/status.py +2302 -0
  77. paasta_tools/cli/cmds/validate.py +1012 -0
  78. paasta_tools/cli/cmds/wait_for_deployment.py +275 -0
  79. paasta_tools/cli/fsm/__init__.py +13 -0
  80. paasta_tools/cli/fsm/autosuggest.py +82 -0
  81. paasta_tools/cli/fsm/template/README.md +8 -0
  82. paasta_tools/cli/fsm/template/cookiecutter.json +7 -0
  83. paasta_tools/cli/fsm/template/{{cookiecutter.service}}/kubernetes-PROD.yaml +91 -0
  84. paasta_tools/cli/fsm/template/{{cookiecutter.service}}/monitoring.yaml +20 -0
  85. paasta_tools/cli/fsm/template/{{cookiecutter.service}}/service.yaml +8 -0
  86. paasta_tools/cli/fsm/template/{{cookiecutter.service}}/smartstack.yaml +6 -0
  87. paasta_tools/cli/fsm_cmd.py +121 -0
  88. paasta_tools/cli/paasta_tabcomplete.sh +23 -0
  89. paasta_tools/cli/schemas/adhoc_schema.json +199 -0
  90. paasta_tools/cli/schemas/autoscaling_schema.json +91 -0
  91. paasta_tools/cli/schemas/autotuned_defaults/cassandracluster_schema.json +37 -0
  92. paasta_tools/cli/schemas/autotuned_defaults/kubernetes_schema.json +89 -0
  93. paasta_tools/cli/schemas/deploy_schema.json +173 -0
  94. paasta_tools/cli/schemas/eks_schema.json +970 -0
  95. paasta_tools/cli/schemas/kubernetes_schema.json +970 -0
  96. paasta_tools/cli/schemas/rollback_schema.json +160 -0
  97. paasta_tools/cli/schemas/service_schema.json +25 -0
  98. paasta_tools/cli/schemas/smartstack_schema.json +322 -0
  99. paasta_tools/cli/schemas/tron_schema.json +699 -0
  100. paasta_tools/cli/utils.py +1118 -0
  101. paasta_tools/clusterman.py +21 -0
  102. paasta_tools/config_utils.py +385 -0
  103. paasta_tools/contrib/__init__.py +0 -0
  104. paasta_tools/contrib/bounce_log_latency_parser.py +68 -0
  105. paasta_tools/contrib/check_manual_oapi_changes.sh +24 -0
  106. paasta_tools/contrib/check_orphans.py +306 -0
  107. paasta_tools/contrib/create_dynamodb_table.py +35 -0
  108. paasta_tools/contrib/create_paasta_playground.py +105 -0
  109. paasta_tools/contrib/emit_allocated_cpu_metrics.py +50 -0
  110. paasta_tools/contrib/get_running_task_allocation.py +346 -0
  111. paasta_tools/contrib/habitat_fixer.py +86 -0
  112. paasta_tools/contrib/ide_helper.py +316 -0
  113. paasta_tools/contrib/is_pod_healthy_in_proxy.py +139 -0
  114. paasta_tools/contrib/is_pod_healthy_in_smartstack.py +50 -0
  115. paasta_tools/contrib/kill_bad_containers.py +109 -0
  116. paasta_tools/contrib/mass-deploy-tag.sh +44 -0
  117. paasta_tools/contrib/mock_patch_checker.py +86 -0
  118. paasta_tools/contrib/paasta_update_soa_memcpu.py +520 -0
  119. paasta_tools/contrib/render_template.py +129 -0
  120. paasta_tools/contrib/rightsizer_soaconfigs_update.py +348 -0
  121. paasta_tools/contrib/service_shard_remove.py +157 -0
  122. paasta_tools/contrib/service_shard_update.py +373 -0
  123. paasta_tools/contrib/shared_ip_check.py +77 -0
  124. paasta_tools/contrib/timeouts_metrics_prom.py +64 -0
  125. paasta_tools/delete_kubernetes_deployments.py +89 -0
  126. paasta_tools/deployment_utils.py +44 -0
  127. paasta_tools/docker_wrapper.py +234 -0
  128. paasta_tools/docker_wrapper_imports.py +13 -0
  129. paasta_tools/drain_lib.py +351 -0
  130. paasta_tools/dump_locally_running_services.py +71 -0
  131. paasta_tools/eks_tools.py +119 -0
  132. paasta_tools/envoy_tools.py +373 -0
  133. paasta_tools/firewall.py +504 -0
  134. paasta_tools/firewall_logging.py +154 -0
  135. paasta_tools/firewall_update.py +172 -0
  136. paasta_tools/flink_tools.py +345 -0
  137. paasta_tools/flinkeks_tools.py +90 -0
  138. paasta_tools/frameworks/__init__.py +0 -0
  139. paasta_tools/frameworks/adhoc_scheduler.py +71 -0
  140. paasta_tools/frameworks/constraints.py +87 -0
  141. paasta_tools/frameworks/native_scheduler.py +652 -0
  142. paasta_tools/frameworks/native_service_config.py +301 -0
  143. paasta_tools/frameworks/task_store.py +245 -0
  144. paasta_tools/generate_all_deployments +9 -0
  145. paasta_tools/generate_authenticating_services.py +94 -0
  146. paasta_tools/generate_deployments_for_service.py +255 -0
  147. paasta_tools/generate_services_file.py +114 -0
  148. paasta_tools/generate_services_yaml.py +30 -0
  149. paasta_tools/hacheck.py +76 -0
  150. paasta_tools/instance/__init__.py +0 -0
  151. paasta_tools/instance/hpa_metrics_parser.py +122 -0
  152. paasta_tools/instance/kubernetes.py +1362 -0
  153. paasta_tools/iptables.py +240 -0
  154. paasta_tools/kafkacluster_tools.py +143 -0
  155. paasta_tools/kubernetes/__init__.py +0 -0
  156. paasta_tools/kubernetes/application/__init__.py +0 -0
  157. paasta_tools/kubernetes/application/controller_wrappers.py +476 -0
  158. paasta_tools/kubernetes/application/tools.py +90 -0
  159. paasta_tools/kubernetes/bin/__init__.py +0 -0
  160. paasta_tools/kubernetes/bin/kubernetes_remove_evicted_pods.py +164 -0
  161. paasta_tools/kubernetes/bin/paasta_cleanup_remote_run_resources.py +135 -0
  162. paasta_tools/kubernetes/bin/paasta_cleanup_stale_nodes.py +181 -0
  163. paasta_tools/kubernetes/bin/paasta_secrets_sync.py +758 -0
  164. paasta_tools/kubernetes/remote_run.py +558 -0
  165. paasta_tools/kubernetes_tools.py +4679 -0
  166. paasta_tools/list_kubernetes_service_instances.py +128 -0
  167. paasta_tools/list_tron_namespaces.py +60 -0
  168. paasta_tools/long_running_service_tools.py +678 -0
  169. paasta_tools/mac_address.py +44 -0
  170. paasta_tools/marathon_dashboard.py +0 -0
  171. paasta_tools/mesos/__init__.py +0 -0
  172. paasta_tools/mesos/cfg.py +46 -0
  173. paasta_tools/mesos/cluster.py +60 -0
  174. paasta_tools/mesos/exceptions.py +59 -0
  175. paasta_tools/mesos/framework.py +77 -0
  176. paasta_tools/mesos/log.py +48 -0
  177. paasta_tools/mesos/master.py +306 -0
  178. paasta_tools/mesos/mesos_file.py +169 -0
  179. paasta_tools/mesos/parallel.py +52 -0
  180. paasta_tools/mesos/slave.py +115 -0
  181. paasta_tools/mesos/task.py +94 -0
  182. paasta_tools/mesos/util.py +69 -0
  183. paasta_tools/mesos/zookeeper.py +37 -0
  184. paasta_tools/mesos_maintenance.py +848 -0
  185. paasta_tools/mesos_tools.py +1051 -0
  186. paasta_tools/metrics/__init__.py +0 -0
  187. paasta_tools/metrics/metastatus_lib.py +1110 -0
  188. paasta_tools/metrics/metrics_lib.py +217 -0
  189. paasta_tools/monitoring/__init__.py +13 -0
  190. paasta_tools/monitoring/check_k8s_api_performance.py +110 -0
  191. paasta_tools/monitoring_tools.py +652 -0
  192. paasta_tools/monkrelaycluster_tools.py +146 -0
  193. paasta_tools/nrtsearchservice_tools.py +143 -0
  194. paasta_tools/nrtsearchserviceeks_tools.py +68 -0
  195. paasta_tools/oom_logger.py +321 -0
  196. paasta_tools/paasta_deploy_tron_jobs +3 -0
  197. paasta_tools/paasta_execute_docker_command.py +123 -0
  198. paasta_tools/paasta_native_serviceinit.py +21 -0
  199. paasta_tools/paasta_service_config_loader.py +201 -0
  200. paasta_tools/paastaapi/__init__.py +29 -0
  201. paasta_tools/paastaapi/api/__init__.py +3 -0
  202. paasta_tools/paastaapi/api/autoscaler_api.py +302 -0
  203. paasta_tools/paastaapi/api/default_api.py +569 -0
  204. paasta_tools/paastaapi/api/remote_run_api.py +604 -0
  205. paasta_tools/paastaapi/api/resources_api.py +157 -0
  206. paasta_tools/paastaapi/api/service_api.py +1736 -0
  207. paasta_tools/paastaapi/api_client.py +818 -0
  208. paasta_tools/paastaapi/apis/__init__.py +22 -0
  209. paasta_tools/paastaapi/configuration.py +455 -0
  210. paasta_tools/paastaapi/exceptions.py +137 -0
  211. paasta_tools/paastaapi/model/__init__.py +5 -0
  212. paasta_tools/paastaapi/model/adhoc_launch_history.py +176 -0
  213. paasta_tools/paastaapi/model/autoscaler_count_msg.py +176 -0
  214. paasta_tools/paastaapi/model/deploy_queue.py +178 -0
  215. paasta_tools/paastaapi/model/deploy_queue_service_instance.py +194 -0
  216. paasta_tools/paastaapi/model/envoy_backend.py +185 -0
  217. paasta_tools/paastaapi/model/envoy_location.py +184 -0
  218. paasta_tools/paastaapi/model/envoy_status.py +181 -0
  219. paasta_tools/paastaapi/model/flink_cluster_overview.py +188 -0
  220. paasta_tools/paastaapi/model/flink_config.py +173 -0
  221. paasta_tools/paastaapi/model/flink_job.py +186 -0
  222. paasta_tools/paastaapi/model/flink_job_details.py +192 -0
  223. paasta_tools/paastaapi/model/flink_jobs.py +175 -0
  224. paasta_tools/paastaapi/model/float_and_error.py +173 -0
  225. paasta_tools/paastaapi/model/hpa_metric.py +176 -0
  226. paasta_tools/paastaapi/model/inline_object.py +170 -0
  227. paasta_tools/paastaapi/model/inline_response200.py +170 -0
  228. paasta_tools/paastaapi/model/inline_response2001.py +170 -0
  229. paasta_tools/paastaapi/model/instance_bounce_status.py +200 -0
  230. paasta_tools/paastaapi/model/instance_mesh_status.py +186 -0
  231. paasta_tools/paastaapi/model/instance_status.py +220 -0
  232. paasta_tools/paastaapi/model/instance_status_adhoc.py +187 -0
  233. paasta_tools/paastaapi/model/instance_status_cassandracluster.py +173 -0
  234. paasta_tools/paastaapi/model/instance_status_flink.py +173 -0
  235. paasta_tools/paastaapi/model/instance_status_kafkacluster.py +173 -0
  236. paasta_tools/paastaapi/model/instance_status_kubernetes.py +263 -0
  237. paasta_tools/paastaapi/model/instance_status_kubernetes_autoscaling_status.py +187 -0
  238. paasta_tools/paastaapi/model/instance_status_kubernetes_v2.py +197 -0
  239. paasta_tools/paastaapi/model/instance_status_tron.py +204 -0
  240. paasta_tools/paastaapi/model/instance_tasks.py +182 -0
  241. paasta_tools/paastaapi/model/integer_and_error.py +173 -0
  242. paasta_tools/paastaapi/model/kubernetes_container.py +178 -0
  243. paasta_tools/paastaapi/model/kubernetes_container_v2.py +219 -0
  244. paasta_tools/paastaapi/model/kubernetes_healthcheck.py +176 -0
  245. paasta_tools/paastaapi/model/kubernetes_pod.py +201 -0
  246. paasta_tools/paastaapi/model/kubernetes_pod_event.py +176 -0
  247. paasta_tools/paastaapi/model/kubernetes_pod_v2.py +213 -0
  248. paasta_tools/paastaapi/model/kubernetes_replica_set.py +185 -0
  249. paasta_tools/paastaapi/model/kubernetes_version.py +202 -0
  250. paasta_tools/paastaapi/model/remote_run_outcome.py +189 -0
  251. paasta_tools/paastaapi/model/remote_run_start.py +185 -0
  252. paasta_tools/paastaapi/model/remote_run_stop.py +176 -0
  253. paasta_tools/paastaapi/model/remote_run_token.py +173 -0
  254. paasta_tools/paastaapi/model/resource.py +187 -0
  255. paasta_tools/paastaapi/model/resource_item.py +187 -0
  256. paasta_tools/paastaapi/model/resource_value.py +176 -0
  257. paasta_tools/paastaapi/model/smartstack_backend.py +191 -0
  258. paasta_tools/paastaapi/model/smartstack_location.py +181 -0
  259. paasta_tools/paastaapi/model/smartstack_status.py +181 -0
  260. paasta_tools/paastaapi/model/task_tail_lines.py +176 -0
  261. paasta_tools/paastaapi/model_utils.py +1879 -0
  262. paasta_tools/paastaapi/models/__init__.py +62 -0
  263. paasta_tools/paastaapi/rest.py +287 -0
  264. paasta_tools/prune_completed_pods.py +220 -0
  265. paasta_tools/puppet_service_tools.py +59 -0
  266. paasta_tools/py.typed +1 -0
  267. paasta_tools/remote_git.py +127 -0
  268. paasta_tools/run-paasta-api-in-dev-mode.py +57 -0
  269. paasta_tools/run-paasta-api-playground.py +51 -0
  270. paasta_tools/secret_providers/__init__.py +66 -0
  271. paasta_tools/secret_providers/vault.py +214 -0
  272. paasta_tools/secret_tools.py +277 -0
  273. paasta_tools/setup_istio_mesh.py +353 -0
  274. paasta_tools/setup_kubernetes_cr.py +412 -0
  275. paasta_tools/setup_kubernetes_crd.py +138 -0
  276. paasta_tools/setup_kubernetes_internal_crd.py +154 -0
  277. paasta_tools/setup_kubernetes_job.py +353 -0
  278. paasta_tools/setup_prometheus_adapter_config.py +1028 -0
  279. paasta_tools/setup_tron_namespace.py +248 -0
  280. paasta_tools/slack.py +75 -0
  281. paasta_tools/smartstack_tools.py +676 -0
  282. paasta_tools/spark_tools.py +283 -0
  283. paasta_tools/synapse_srv_namespaces_fact.py +42 -0
  284. paasta_tools/tron/__init__.py +0 -0
  285. paasta_tools/tron/client.py +158 -0
  286. paasta_tools/tron/tron_command_context.py +194 -0
  287. paasta_tools/tron/tron_timeutils.py +101 -0
  288. paasta_tools/tron_tools.py +1448 -0
  289. paasta_tools/utils.py +4307 -0
  290. paasta_tools/yaml_tools.py +44 -0
  291. paasta_tools-1.21.3.data/scripts/apply_external_resources.py +79 -0
  292. paasta_tools-1.21.3.data/scripts/bounce_log_latency_parser.py +68 -0
  293. paasta_tools-1.21.3.data/scripts/check_autoscaler_max_instances.py +212 -0
  294. paasta_tools-1.21.3.data/scripts/check_cassandracluster_services_replication.py +35 -0
  295. paasta_tools-1.21.3.data/scripts/check_flink_services_health.py +203 -0
  296. paasta_tools-1.21.3.data/scripts/check_kubernetes_api.py +57 -0
  297. paasta_tools-1.21.3.data/scripts/check_kubernetes_services_replication.py +141 -0
  298. paasta_tools-1.21.3.data/scripts/check_manual_oapi_changes.sh +24 -0
  299. paasta_tools-1.21.3.data/scripts/check_oom_events.py +244 -0
  300. paasta_tools-1.21.3.data/scripts/check_orphans.py +306 -0
  301. paasta_tools-1.21.3.data/scripts/check_spark_jobs.py +234 -0
  302. paasta_tools-1.21.3.data/scripts/cleanup_kubernetes_cr.py +138 -0
  303. paasta_tools-1.21.3.data/scripts/cleanup_kubernetes_crd.py +145 -0
  304. paasta_tools-1.21.3.data/scripts/cleanup_kubernetes_jobs.py +344 -0
  305. paasta_tools-1.21.3.data/scripts/create_dynamodb_table.py +35 -0
  306. paasta_tools-1.21.3.data/scripts/create_paasta_playground.py +105 -0
  307. paasta_tools-1.21.3.data/scripts/delete_kubernetes_deployments.py +89 -0
  308. paasta_tools-1.21.3.data/scripts/emit_allocated_cpu_metrics.py +50 -0
  309. paasta_tools-1.21.3.data/scripts/generate_all_deployments +9 -0
  310. paasta_tools-1.21.3.data/scripts/generate_authenticating_services.py +94 -0
  311. paasta_tools-1.21.3.data/scripts/generate_deployments_for_service.py +255 -0
  312. paasta_tools-1.21.3.data/scripts/generate_services_file.py +114 -0
  313. paasta_tools-1.21.3.data/scripts/generate_services_yaml.py +30 -0
  314. paasta_tools-1.21.3.data/scripts/get_running_task_allocation.py +346 -0
  315. paasta_tools-1.21.3.data/scripts/habitat_fixer.py +86 -0
  316. paasta_tools-1.21.3.data/scripts/ide_helper.py +316 -0
  317. paasta_tools-1.21.3.data/scripts/is_pod_healthy_in_proxy.py +139 -0
  318. paasta_tools-1.21.3.data/scripts/is_pod_healthy_in_smartstack.py +50 -0
  319. paasta_tools-1.21.3.data/scripts/kill_bad_containers.py +109 -0
  320. paasta_tools-1.21.3.data/scripts/kubernetes_remove_evicted_pods.py +164 -0
  321. paasta_tools-1.21.3.data/scripts/mass-deploy-tag.sh +44 -0
  322. paasta_tools-1.21.3.data/scripts/mock_patch_checker.py +86 -0
  323. paasta_tools-1.21.3.data/scripts/paasta_cleanup_remote_run_resources.py +135 -0
  324. paasta_tools-1.21.3.data/scripts/paasta_cleanup_stale_nodes.py +181 -0
  325. paasta_tools-1.21.3.data/scripts/paasta_deploy_tron_jobs +3 -0
  326. paasta_tools-1.21.3.data/scripts/paasta_execute_docker_command.py +123 -0
  327. paasta_tools-1.21.3.data/scripts/paasta_secrets_sync.py +758 -0
  328. paasta_tools-1.21.3.data/scripts/paasta_tabcomplete.sh +23 -0
  329. paasta_tools-1.21.3.data/scripts/paasta_update_soa_memcpu.py +520 -0
  330. paasta_tools-1.21.3.data/scripts/render_template.py +129 -0
  331. paasta_tools-1.21.3.data/scripts/rightsizer_soaconfigs_update.py +348 -0
  332. paasta_tools-1.21.3.data/scripts/service_shard_remove.py +157 -0
  333. paasta_tools-1.21.3.data/scripts/service_shard_update.py +373 -0
  334. paasta_tools-1.21.3.data/scripts/setup_istio_mesh.py +353 -0
  335. paasta_tools-1.21.3.data/scripts/setup_kubernetes_cr.py +412 -0
  336. paasta_tools-1.21.3.data/scripts/setup_kubernetes_crd.py +138 -0
  337. paasta_tools-1.21.3.data/scripts/setup_kubernetes_internal_crd.py +154 -0
  338. paasta_tools-1.21.3.data/scripts/setup_kubernetes_job.py +353 -0
  339. paasta_tools-1.21.3.data/scripts/setup_prometheus_adapter_config.py +1028 -0
  340. paasta_tools-1.21.3.data/scripts/shared_ip_check.py +77 -0
  341. paasta_tools-1.21.3.data/scripts/synapse_srv_namespaces_fact.py +42 -0
  342. paasta_tools-1.21.3.data/scripts/timeouts_metrics_prom.py +64 -0
  343. paasta_tools-1.21.3.dist-info/LICENSE +201 -0
  344. paasta_tools-1.21.3.dist-info/METADATA +74 -0
  345. paasta_tools-1.21.3.dist-info/RECORD +348 -0
  346. paasta_tools-1.21.3.dist-info/WHEEL +5 -0
  347. paasta_tools-1.21.3.dist-info/entry_points.txt +20 -0
  348. paasta_tools-1.21.3.dist-info/top_level.txt +2 -0
@@ -0,0 +1,1879 @@
1
+ # coding: utf-8
2
+
3
+ """
4
+ Paasta API
5
+
6
+ No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) # noqa: E501
7
+
8
+ The version of the OpenAPI document: 1.2.0
9
+ Generated by: https://openapi-generator.tech
10
+ """
11
+
12
+
13
+ from datetime import date, datetime # noqa: F401
14
+ import inspect
15
+ import io
16
+ import os
17
+ import pprint
18
+ import re
19
+ import tempfile
20
+
21
+ from dateutil.parser import parse
22
+
23
+ from paasta_tools.paastaapi.exceptions import (
24
+ ApiKeyError,
25
+ ApiAttributeError,
26
+ ApiTypeError,
27
+ ApiValueError,
28
+ )
29
+
30
+ none_type = type(None)
31
+ file_type = io.IOBase
32
+
33
+
34
+ class cached_property(object):
35
+ # this caches the result of the function call for fn with no inputs
36
+ # use this as a decorator on fuction methods that you want converted
37
+ # into cached properties
38
+ result_key = '_results'
39
+
40
+ def __init__(self, fn):
41
+ self._fn = fn
42
+
43
+ def __get__(self, instance, cls=None):
44
+ if self.result_key in vars(self):
45
+ return vars(self)[self.result_key]
46
+ else:
47
+ result = self._fn()
48
+ setattr(self, self.result_key, result)
49
+ return result
50
+
51
+
52
+ PRIMITIVE_TYPES = (list, float, int, bool, datetime, date, str, file_type)
53
+
54
+ def allows_single_value_input(cls):
55
+ """
56
+ This function returns True if the input composed schema model or any
57
+ descendant model allows a value only input
58
+ This is true for cases where oneOf contains items like:
59
+ oneOf:
60
+ - float
61
+ - NumberWithValidation
62
+ - StringEnum
63
+ - ArrayModel
64
+ - null
65
+ TODO: lru_cache this
66
+ """
67
+ if (
68
+ issubclass(cls, ModelSimple) or
69
+ cls in PRIMITIVE_TYPES
70
+ ):
71
+ return True
72
+ elif issubclass(cls, ModelComposed):
73
+ if not cls._composed_schemas['oneOf']:
74
+ return False
75
+ return any(allows_single_value_input(c) for c in cls._composed_schemas['oneOf'])
76
+ return False
77
+
78
+ def composed_model_input_classes(cls):
79
+ """
80
+ This function returns a list of the possible models that can be accepted as
81
+ inputs.
82
+ TODO: lru_cache this
83
+ """
84
+ if issubclass(cls, ModelSimple) or cls in PRIMITIVE_TYPES:
85
+ return [cls]
86
+ elif issubclass(cls, ModelNormal):
87
+ if cls.discriminator is None:
88
+ return [cls]
89
+ else:
90
+ return get_discriminated_classes(cls)
91
+ elif issubclass(cls, ModelComposed):
92
+ if not cls._composed_schemas['oneOf']:
93
+ return []
94
+ if cls.discriminator is None:
95
+ input_classes = []
96
+ for c in cls._composed_schemas['oneOf']:
97
+ input_classes.extend(composed_model_input_classes(c))
98
+ return input_classes
99
+ else:
100
+ return get_discriminated_classes(cls)
101
+ return []
102
+
103
+
104
+ class OpenApiModel(object):
105
+ """The base class for all OpenAPIModels"""
106
+
107
+ def set_attribute(self, name, value):
108
+ # this is only used to set properties on self
109
+
110
+ path_to_item = []
111
+ if self._path_to_item:
112
+ path_to_item.extend(self._path_to_item)
113
+ path_to_item.append(name)
114
+
115
+ if name in self.openapi_types:
116
+ required_types_mixed = self.openapi_types[name]
117
+ elif self.additional_properties_type is None:
118
+ raise ApiAttributeError(
119
+ "{0} has no attribute '{1}'".format(
120
+ type(self).__name__, name),
121
+ path_to_item
122
+ )
123
+ elif self.additional_properties_type is not None:
124
+ required_types_mixed = self.additional_properties_type
125
+
126
+ if get_simple_class(name) != str:
127
+ error_msg = type_error_message(
128
+ var_name=name,
129
+ var_value=name,
130
+ valid_classes=(str,),
131
+ key_type=True
132
+ )
133
+ raise ApiTypeError(
134
+ error_msg,
135
+ path_to_item=path_to_item,
136
+ valid_classes=(str,),
137
+ key_type=True
138
+ )
139
+
140
+ if self._check_type:
141
+ value = validate_and_convert_types(
142
+ value, required_types_mixed, path_to_item, self._spec_property_naming,
143
+ self._check_type, configuration=self._configuration)
144
+ if (name,) in self.allowed_values:
145
+ check_allowed_values(
146
+ self.allowed_values,
147
+ (name,),
148
+ value
149
+ )
150
+ if (name,) in self.validations:
151
+ check_validations(
152
+ self.validations,
153
+ (name,),
154
+ value,
155
+ self._configuration
156
+ )
157
+ self.__dict__['_data_store'][name] = value
158
+
159
+ def __repr__(self):
160
+ """For `print` and `pprint`"""
161
+ return self.to_str()
162
+
163
+ def __ne__(self, other):
164
+ """Returns true if both objects are not equal"""
165
+ return not self == other
166
+
167
+ def __setattr__(self, attr, value):
168
+ """set the value of an attribute using dot notation: `instance.attr = val`"""
169
+ self[attr] = value
170
+
171
+ def __getattr__(self, attr):
172
+ """get the value of an attribute using dot notation: `instance.attr`"""
173
+ return self.get(attr)
174
+
175
+ def __new__(cls, *args, **kwargs):
176
+ # this function uses the discriminator to
177
+ # pick a new schema/class to instantiate because a discriminator
178
+ # propertyName value was passed in
179
+
180
+ if len(args) == 1:
181
+ arg = args[0]
182
+ if arg is None and is_type_nullable(cls):
183
+ # The input data is the 'null' value and the type is nullable.
184
+ return None
185
+
186
+ if issubclass(cls, ModelComposed) and allows_single_value_input(cls):
187
+ model_kwargs = {}
188
+ oneof_instance = get_oneof_instance(cls, model_kwargs, kwargs, model_arg=arg)
189
+ return oneof_instance
190
+
191
+
192
+ visited_composed_classes = kwargs.get('_visited_composed_classes', ())
193
+ if (
194
+ cls.discriminator is None or
195
+ cls in visited_composed_classes
196
+ ):
197
+ # Use case 1: this openapi schema (cls) does not have a discriminator
198
+ # Use case 2: we have already visited this class before and are sure that we
199
+ # want to instantiate it this time. We have visited this class deserializing
200
+ # a payload with a discriminator. During that process we traveled through
201
+ # this class but did not make an instance of it. Now we are making an
202
+ # instance of a composed class which contains cls in it, so this time make an instance of cls.
203
+ #
204
+ # Here's an example of use case 2: If Animal has a discriminator
205
+ # petType and we pass in "Dog", and the class Dog
206
+ # allOf includes Animal, we move through Animal
207
+ # once using the discriminator, and pick Dog.
208
+ # Then in the composed schema dog Dog, we will make an instance of the
209
+ # Animal class (because Dal has allOf: Animal) but this time we won't travel
210
+ # through Animal's discriminator because we passed in
211
+ # _visited_composed_classes = (Animal,)
212
+
213
+ return super(OpenApiModel, cls).__new__(cls)
214
+
215
+ # Get the name and value of the discriminator property.
216
+ # The discriminator name is obtained from the discriminator meta-data
217
+ # and the discriminator value is obtained from the input data.
218
+ discr_propertyname_py = list(cls.discriminator.keys())[0]
219
+ discr_propertyname_js = cls.attribute_map[discr_propertyname_py]
220
+ if discr_propertyname_js in kwargs:
221
+ discr_value = kwargs[discr_propertyname_js]
222
+ elif discr_propertyname_py in kwargs:
223
+ discr_value = kwargs[discr_propertyname_py]
224
+ else:
225
+ # The input data does not contain the discriminator property.
226
+ path_to_item = kwargs.get('_path_to_item', ())
227
+ raise ApiValueError(
228
+ "Cannot deserialize input data due to missing discriminator. "
229
+ "The discriminator property '%s' is missing at path: %s" %
230
+ (discr_propertyname_js, path_to_item)
231
+ )
232
+
233
+ # Implementation note: the last argument to get_discriminator_class
234
+ # is a list of visited classes. get_discriminator_class may recursively
235
+ # call itself and update the list of visited classes, and the initial
236
+ # value must be an empty list. Hence not using 'visited_composed_classes'
237
+ new_cls = get_discriminator_class(
238
+ cls, discr_propertyname_py, discr_value, [])
239
+ if new_cls is None:
240
+ path_to_item = kwargs.get('_path_to_item', ())
241
+ disc_prop_value = kwargs.get(
242
+ discr_propertyname_js, kwargs.get(discr_propertyname_py))
243
+ raise ApiValueError(
244
+ "Cannot deserialize input data due to invalid discriminator "
245
+ "value. The OpenAPI document has no mapping for discriminator "
246
+ "property '%s'='%s' at path: %s" %
247
+ (discr_propertyname_js, disc_prop_value, path_to_item)
248
+ )
249
+
250
+ if new_cls in visited_composed_classes:
251
+ # if we are making an instance of a composed schema Descendent
252
+ # which allOf includes Ancestor, then Ancestor contains
253
+ # a discriminator that includes Descendent.
254
+ # So if we make an instance of Descendent, we have to make an
255
+ # instance of Ancestor to hold the allOf properties.
256
+ # This code detects that use case and makes the instance of Ancestor
257
+ # For example:
258
+ # When making an instance of Dog, _visited_composed_classes = (Dog,)
259
+ # then we make an instance of Animal to include in dog._composed_instances
260
+ # so when we are here, cls is Animal
261
+ # cls.discriminator != None
262
+ # cls not in _visited_composed_classes
263
+ # new_cls = Dog
264
+ # but we know we know that we already have Dog
265
+ # because it is in visited_composed_classes
266
+ # so make Animal here
267
+ return super(OpenApiModel, cls).__new__(cls)
268
+
269
+ # Build a list containing all oneOf and anyOf descendants.
270
+ oneof_anyof_classes = None
271
+ if cls._composed_schemas is not None:
272
+ oneof_anyof_classes = (
273
+ cls._composed_schemas.get('oneOf', ()) +
274
+ cls._composed_schemas.get('anyOf', ()))
275
+ oneof_anyof_child = new_cls in oneof_anyof_classes
276
+ kwargs['_visited_composed_classes'] = visited_composed_classes + (cls,)
277
+
278
+ if cls._composed_schemas.get('allOf') and oneof_anyof_child:
279
+ # Validate that we can make self because when we make the
280
+ # new_cls it will not include the allOf validations in self
281
+ self_inst = super(OpenApiModel, cls).__new__(cls)
282
+ self_inst.__init__(*args, **kwargs)
283
+
284
+ new_inst = new_cls.__new__(new_cls, *args, **kwargs)
285
+ new_inst.__init__(*args, **kwargs)
286
+ return new_inst
287
+
288
+
289
+ class ModelSimple(OpenApiModel):
290
+ """the parent class of models whose type != object in their
291
+ swagger/openapi"""
292
+
293
+ def __setitem__(self, name, value):
294
+ """set the value of an attribute using square-bracket notation: `instance[attr] = val`"""
295
+ if name in self.required_properties:
296
+ self.__dict__[name] = value
297
+ return
298
+
299
+ self.set_attribute(name, value)
300
+
301
+ def get(self, name, default=None):
302
+ """returns the value of an attribute or some default value if the attribute was not set"""
303
+ if name in self.required_properties:
304
+ return self.__dict__[name]
305
+
306
+ return self.__dict__['_data_store'].get(name, default)
307
+
308
+ def __getitem__(self, name):
309
+ """get the value of an attribute using square-bracket notation: `instance[attr]`"""
310
+ if name in self:
311
+ return self.get(name)
312
+
313
+ raise ApiAttributeError(
314
+ "{0} has no attribute '{1}'".format(
315
+ type(self).__name__, name),
316
+ [e for e in [self._path_to_item, name] if e]
317
+ )
318
+
319
+ def __contains__(self, name):
320
+ """used by `in` operator to check if an attrbute value was set in an instance: `'attr' in instance`"""
321
+ if name in self.required_properties:
322
+ return name in self.__dict__
323
+
324
+ return name in self.__dict__['_data_store']
325
+
326
+ def to_str(self):
327
+ """Returns the string representation of the model"""
328
+ return str(self.value)
329
+
330
+ def __eq__(self, other):
331
+ """Returns true if both objects are equal"""
332
+ if not isinstance(other, self.__class__):
333
+ return False
334
+
335
+ this_val = self._data_store['value']
336
+ that_val = other._data_store['value']
337
+ types = set()
338
+ types.add(this_val.__class__)
339
+ types.add(that_val.__class__)
340
+ vals_equal = this_val == that_val
341
+ return vals_equal
342
+
343
+
344
+ class ModelNormal(OpenApiModel):
345
+ """the parent class of models whose type == object in their
346
+ swagger/openapi"""
347
+
348
+ def __setitem__(self, name, value):
349
+ """set the value of an attribute using square-bracket notation: `instance[attr] = val`"""
350
+ if name in self.required_properties:
351
+ self.__dict__[name] = value
352
+ return
353
+
354
+ self.set_attribute(name, value)
355
+
356
+ def get(self, name, default=None):
357
+ """returns the value of an attribute or some default value if the attribute was not set"""
358
+ if name in self.required_properties:
359
+ return self.__dict__[name]
360
+
361
+ return self.__dict__['_data_store'].get(name, default)
362
+
363
+ def __getitem__(self, name):
364
+ """get the value of an attribute using square-bracket notation: `instance[attr]`"""
365
+ if name in self:
366
+ return self.get(name)
367
+
368
+ raise ApiAttributeError(
369
+ "{0} has no attribute '{1}'".format(
370
+ type(self).__name__, name),
371
+ [e for e in [self._path_to_item, name] if e]
372
+ )
373
+
374
+ def __contains__(self, name):
375
+ """used by `in` operator to check if an attrbute value was set in an instance: `'attr' in instance`"""
376
+ if name in self.required_properties:
377
+ return name in self.__dict__
378
+
379
+ return name in self.__dict__['_data_store']
380
+
381
+ def to_dict(self):
382
+ """Returns the model properties as a dict"""
383
+ return model_to_dict(self, serialize=False)
384
+
385
+ def to_str(self):
386
+ """Returns the string representation of the model"""
387
+ return pprint.pformat(self.to_dict())
388
+
389
+ def __eq__(self, other):
390
+ """Returns true if both objects are equal"""
391
+ if not isinstance(other, self.__class__):
392
+ return False
393
+
394
+ if not set(self._data_store.keys()) == set(other._data_store.keys()):
395
+ return False
396
+ for _var_name, this_val in self._data_store.items():
397
+ that_val = other._data_store[_var_name]
398
+ types = set()
399
+ types.add(this_val.__class__)
400
+ types.add(that_val.__class__)
401
+ vals_equal = this_val == that_val
402
+ if not vals_equal:
403
+ return False
404
+ return True
405
+
406
+
407
+ class ModelComposed(OpenApiModel):
408
+ """the parent class of models whose type == object in their
409
+ swagger/openapi and have oneOf/allOf/anyOf
410
+
411
+ When one sets a property we use var_name_to_model_instances to store the value in
412
+ the correct class instances + run any type checking + validation code.
413
+ When one gets a property we use var_name_to_model_instances to get the value
414
+ from the correct class instances.
415
+ This allows multiple composed schemas to contain the same property with additive
416
+ constraints on the value.
417
+
418
+ _composed_schemas (dict) stores the anyOf/allOf/oneOf classes
419
+ key (str): allOf/oneOf/anyOf
420
+ value (list): the classes in the XOf definition.
421
+ Note: none_type can be included when the openapi document version >= 3.1.0
422
+ _composed_instances (list): stores a list of instances of the composed schemas
423
+ defined in _composed_schemas. When properties are accessed in the self instance,
424
+ they are returned from the self._data_store or the data stores in the instances
425
+ in self._composed_schemas
426
+ _var_name_to_model_instances (dict): maps between a variable name on self and
427
+ the composed instances (self included) which contain that data
428
+ key (str): property name
429
+ value (list): list of class instances, self or instances in _composed_instances
430
+ which contain the value that the key is referring to.
431
+ """
432
+
433
+ def __setitem__(self, name, value):
434
+ """set the value of an attribute using square-bracket notation: `instance[attr] = val`"""
435
+ if name in self.required_properties:
436
+ self.__dict__[name] = value
437
+ return
438
+
439
+ # set the attribute on the correct instance
440
+ model_instances = self._var_name_to_model_instances.get(
441
+ name, self._additional_properties_model_instances)
442
+ if model_instances:
443
+ for model_instance in model_instances:
444
+ if model_instance == self:
445
+ self.set_attribute(name, value)
446
+ else:
447
+ setattr(model_instance, name, value)
448
+ if name not in self._var_name_to_model_instances:
449
+ # we assigned an additional property
450
+ self.__dict__['_var_name_to_model_instances'][name] = (
451
+ model_instance
452
+ )
453
+ return None
454
+
455
+ raise ApiAttributeError(
456
+ "{0} has no attribute '{1}'".format(
457
+ type(self).__name__, name),
458
+ [e for e in [self._path_to_item, name] if e]
459
+ )
460
+
461
+ __unset_attribute_value__ = object()
462
+
463
+ def get(self, name, default=None):
464
+ """returns the value of an attribute or some default value if the attribute was not set"""
465
+ if name in self.required_properties:
466
+ return self.__dict__[name]
467
+
468
+ # get the attribute from the correct instance
469
+ model_instances = self._var_name_to_model_instances.get(
470
+ name, self._additional_properties_model_instances)
471
+ values = []
472
+ # A composed model stores child (oneof/anyOf/allOf) models under
473
+ # self._var_name_to_model_instances. A named property can exist in
474
+ # multiple child models. If the property is present in more than one
475
+ # child model, the value must be the same across all the child models.
476
+ if model_instances:
477
+ for model_instance in model_instances:
478
+ if name in model_instance._data_store:
479
+ v = model_instance._data_store[name]
480
+ if v not in values:
481
+ values.append(v)
482
+ len_values = len(values)
483
+ if len_values == 0:
484
+ return default
485
+ elif len_values == 1:
486
+ return values[0]
487
+ elif len_values > 1:
488
+ raise ApiValueError(
489
+ "Values stored for property {0} in {1} differ when looking "
490
+ "at self and self's composed instances. All values must be "
491
+ "the same".format(name, type(self).__name__),
492
+ [e for e in [self._path_to_item, name] if e]
493
+ )
494
+
495
+ def __getitem__(self, name):
496
+ """get the value of an attribute using square-bracket notation: `instance[attr]`"""
497
+ value = self.get(name, self.__unset_attribute_value__)
498
+ if value is self.__unset_attribute_value__:
499
+ raise ApiAttributeError(
500
+ "{0} has no attribute '{1}'".format(
501
+ type(self).__name__, name),
502
+ [e for e in [self._path_to_item, name] if e]
503
+ )
504
+ return value
505
+
506
+ def __contains__(self, name):
507
+ """used by `in` operator to check if an attrbute value was set in an instance: `'attr' in instance`"""
508
+
509
+ if name in self.required_properties:
510
+ return name in self.__dict__
511
+
512
+ model_instances = self._var_name_to_model_instances.get(
513
+ name, self._additional_properties_model_instances)
514
+
515
+ if model_instances:
516
+ for model_instance in model_instances:
517
+ if name in model_instance._data_store:
518
+ return True
519
+
520
+ return False
521
+
522
+ def to_dict(self):
523
+ """Returns the model properties as a dict"""
524
+ return model_to_dict(self, serialize=False)
525
+
526
+ def to_str(self):
527
+ """Returns the string representation of the model"""
528
+ return pprint.pformat(self.to_dict())
529
+
530
+ def __eq__(self, other):
531
+ """Returns true if both objects are equal"""
532
+ if not isinstance(other, self.__class__):
533
+ return False
534
+
535
+ if not set(self._data_store.keys()) == set(other._data_store.keys()):
536
+ return False
537
+ for _var_name, this_val in self._data_store.items():
538
+ that_val = other._data_store[_var_name]
539
+ types = set()
540
+ types.add(this_val.__class__)
541
+ types.add(that_val.__class__)
542
+ vals_equal = this_val == that_val
543
+ if not vals_equal:
544
+ return False
545
+ return True
546
+
547
+
548
+ COERCION_INDEX_BY_TYPE = {
549
+ ModelComposed: 0,
550
+ ModelNormal: 1,
551
+ ModelSimple: 2,
552
+ none_type: 3, # The type of 'None'.
553
+ list: 4,
554
+ dict: 5,
555
+ float: 6,
556
+ int: 7,
557
+ bool: 8,
558
+ datetime: 9,
559
+ date: 10,
560
+ str: 11,
561
+ file_type: 12, # 'file_type' is an alias for the built-in 'file' or 'io.IOBase' type.
562
+ }
563
+
564
+ # these are used to limit what type conversions we try to do
565
+ # when we have a valid type already and we want to try converting
566
+ # to another type
567
+ UPCONVERSION_TYPE_PAIRS = (
568
+ (str, datetime),
569
+ (str, date),
570
+ (int, float), # A float may be serialized as an integer, e.g. '3' is a valid serialized float.
571
+ (list, ModelComposed),
572
+ (dict, ModelComposed),
573
+ (str, ModelComposed),
574
+ (int, ModelComposed),
575
+ (float, ModelComposed),
576
+ (list, ModelComposed),
577
+ (list, ModelNormal),
578
+ (dict, ModelNormal),
579
+ (str, ModelSimple),
580
+ (int, ModelSimple),
581
+ (float, ModelSimple),
582
+ (list, ModelSimple),
583
+ )
584
+
585
+ COERCIBLE_TYPE_PAIRS = {
586
+ False: ( # client instantiation of a model with client data
587
+ # (dict, ModelComposed),
588
+ # (list, ModelComposed),
589
+ # (dict, ModelNormal),
590
+ # (list, ModelNormal),
591
+ # (str, ModelSimple),
592
+ # (int, ModelSimple),
593
+ # (float, ModelSimple),
594
+ # (list, ModelSimple),
595
+ # (str, int),
596
+ # (str, float),
597
+ # (str, datetime),
598
+ # (str, date),
599
+ # (int, str),
600
+ # (float, str),
601
+ ),
602
+ True: ( # server -> client data
603
+ (dict, ModelComposed),
604
+ (list, ModelComposed),
605
+ (dict, ModelNormal),
606
+ (list, ModelNormal),
607
+ (str, ModelSimple),
608
+ (int, ModelSimple),
609
+ (float, ModelSimple),
610
+ (list, ModelSimple),
611
+ # (str, int),
612
+ # (str, float),
613
+ (str, datetime),
614
+ (str, date),
615
+ # (int, str),
616
+ # (float, str),
617
+ (str, file_type)
618
+ ),
619
+ }
620
+
621
+
622
+ def get_simple_class(input_value):
623
+ """Returns an input_value's simple class that we will use for type checking
624
+ Python2:
625
+ float and int will return int, where int is the python3 int backport
626
+ str and unicode will return str, where str is the python3 str backport
627
+ Note: float and int ARE both instances of int backport
628
+ Note: str_py2 and unicode_py2 are NOT both instances of str backport
629
+
630
+ Args:
631
+ input_value (class/class_instance): the item for which we will return
632
+ the simple class
633
+ """
634
+ if isinstance(input_value, type):
635
+ # input_value is a class
636
+ return input_value
637
+ elif isinstance(input_value, tuple):
638
+ return tuple
639
+ elif isinstance(input_value, list):
640
+ return list
641
+ elif isinstance(input_value, dict):
642
+ return dict
643
+ elif isinstance(input_value, none_type):
644
+ return none_type
645
+ elif isinstance(input_value, file_type):
646
+ return file_type
647
+ elif isinstance(input_value, bool):
648
+ # this must be higher than the int check because
649
+ # isinstance(True, int) == True
650
+ return bool
651
+ elif isinstance(input_value, int):
652
+ return int
653
+ elif isinstance(input_value, datetime):
654
+ # this must be higher than the date check because
655
+ # isinstance(datetime_instance, date) == True
656
+ return datetime
657
+ elif isinstance(input_value, date):
658
+ return date
659
+ elif isinstance(input_value, str):
660
+ return str
661
+ return type(input_value)
662
+
663
+
664
+ def check_allowed_values(allowed_values, input_variable_path, input_values):
665
+ """Raises an exception if the input_values are not allowed
666
+
667
+ Args:
668
+ allowed_values (dict): the allowed_values dict
669
+ input_variable_path (tuple): the path to the input variable
670
+ input_values (list/str/int/float/date/datetime): the values that we
671
+ are checking to see if they are in allowed_values
672
+ """
673
+ these_allowed_values = list(allowed_values[input_variable_path].values())
674
+ if (isinstance(input_values, list)
675
+ and not set(input_values).issubset(
676
+ set(these_allowed_values))):
677
+ invalid_values = ", ".join(
678
+ map(str, set(input_values) - set(these_allowed_values))),
679
+ raise ApiValueError(
680
+ "Invalid values for `%s` [%s], must be a subset of [%s]" %
681
+ (
682
+ input_variable_path[0],
683
+ invalid_values,
684
+ ", ".join(map(str, these_allowed_values))
685
+ )
686
+ )
687
+ elif (isinstance(input_values, dict)
688
+ and not set(
689
+ input_values.keys()).issubset(set(these_allowed_values))):
690
+ invalid_values = ", ".join(
691
+ map(str, set(input_values.keys()) - set(these_allowed_values)))
692
+ raise ApiValueError(
693
+ "Invalid keys in `%s` [%s], must be a subset of [%s]" %
694
+ (
695
+ input_variable_path[0],
696
+ invalid_values,
697
+ ", ".join(map(str, these_allowed_values))
698
+ )
699
+ )
700
+ elif (not isinstance(input_values, (list, dict))
701
+ and input_values not in these_allowed_values):
702
+ raise ApiValueError(
703
+ "Invalid value for `%s` (%s), must be one of %s" %
704
+ (
705
+ input_variable_path[0],
706
+ input_values,
707
+ these_allowed_values
708
+ )
709
+ )
710
+
711
+
712
+ def is_json_validation_enabled(schema_keyword, configuration=None):
713
+ """Returns true if JSON schema validation is enabled for the specified
714
+ validation keyword. This can be used to skip JSON schema structural validation
715
+ as requested in the configuration.
716
+
717
+ Args:
718
+ schema_keyword (string): the name of a JSON schema validation keyword.
719
+ configuration (Configuration): the configuration class.
720
+ """
721
+
722
+ return (configuration is None or
723
+ not hasattr(configuration, '_disabled_client_side_validations') or
724
+ schema_keyword not in configuration._disabled_client_side_validations)
725
+
726
+
727
+ def check_validations(
728
+ validations, input_variable_path, input_values,
729
+ configuration=None):
730
+ """Raises an exception if the input_values are invalid
731
+
732
+ Args:
733
+ validations (dict): the validation dictionary.
734
+ input_variable_path (tuple): the path to the input variable.
735
+ input_values (list/str/int/float/date/datetime): the values that we
736
+ are checking.
737
+ configuration (Configuration): the configuration class.
738
+ """
739
+
740
+ current_validations = validations[input_variable_path]
741
+ if (is_json_validation_enabled('multipleOf', configuration) and
742
+ 'multiple_of' in current_validations and
743
+ isinstance(input_values, (int, float)) and
744
+ not (float(input_values) / current_validations['multiple_of']).is_integer()):
745
+ # Note 'multipleOf' will be as good as the floating point arithmetic.
746
+ raise ApiValueError(
747
+ "Invalid value for `%s`, value must be a multiple of "
748
+ "`%s`" % (
749
+ input_variable_path[0],
750
+ current_validations['multiple_of']
751
+ )
752
+ )
753
+
754
+ if (is_json_validation_enabled('maxLength', configuration) and
755
+ 'max_length' in current_validations and
756
+ len(input_values) > current_validations['max_length']):
757
+ raise ApiValueError(
758
+ "Invalid value for `%s`, length must be less than or equal to "
759
+ "`%s`" % (
760
+ input_variable_path[0],
761
+ current_validations['max_length']
762
+ )
763
+ )
764
+
765
+ if (is_json_validation_enabled('minLength', configuration) and
766
+ 'min_length' in current_validations and
767
+ len(input_values) < current_validations['min_length']):
768
+ raise ApiValueError(
769
+ "Invalid value for `%s`, length must be greater than or equal to "
770
+ "`%s`" % (
771
+ input_variable_path[0],
772
+ current_validations['min_length']
773
+ )
774
+ )
775
+
776
+ if (is_json_validation_enabled('maxItems', configuration) and
777
+ 'max_items' in current_validations and
778
+ len(input_values) > current_validations['max_items']):
779
+ raise ApiValueError(
780
+ "Invalid value for `%s`, number of items must be less than or "
781
+ "equal to `%s`" % (
782
+ input_variable_path[0],
783
+ current_validations['max_items']
784
+ )
785
+ )
786
+
787
+ if (is_json_validation_enabled('minItems', configuration) and
788
+ 'min_items' in current_validations and
789
+ len(input_values) < current_validations['min_items']):
790
+ raise ValueError(
791
+ "Invalid value for `%s`, number of items must be greater than or "
792
+ "equal to `%s`" % (
793
+ input_variable_path[0],
794
+ current_validations['min_items']
795
+ )
796
+ )
797
+
798
+ items = ('exclusive_maximum', 'inclusive_maximum', 'exclusive_minimum',
799
+ 'inclusive_minimum')
800
+ if (any(item in current_validations for item in items)):
801
+ if isinstance(input_values, list):
802
+ max_val = max(input_values)
803
+ min_val = min(input_values)
804
+ elif isinstance(input_values, dict):
805
+ max_val = max(input_values.values())
806
+ min_val = min(input_values.values())
807
+ else:
808
+ max_val = input_values
809
+ min_val = input_values
810
+
811
+ if (is_json_validation_enabled('exclusiveMaximum', configuration) and
812
+ 'exclusive_maximum' in current_validations and
813
+ max_val >= current_validations['exclusive_maximum']):
814
+ raise ApiValueError(
815
+ "Invalid value for `%s`, must be a value less than `%s`" % (
816
+ input_variable_path[0],
817
+ current_validations['exclusive_maximum']
818
+ )
819
+ )
820
+
821
+ if (is_json_validation_enabled('maximum', configuration) and
822
+ 'inclusive_maximum' in current_validations and
823
+ max_val > current_validations['inclusive_maximum']):
824
+ raise ApiValueError(
825
+ "Invalid value for `%s`, must be a value less than or equal to "
826
+ "`%s`" % (
827
+ input_variable_path[0],
828
+ current_validations['inclusive_maximum']
829
+ )
830
+ )
831
+
832
+ if (is_json_validation_enabled('exclusiveMinimum', configuration) and
833
+ 'exclusive_minimum' in current_validations and
834
+ min_val <= current_validations['exclusive_minimum']):
835
+ raise ApiValueError(
836
+ "Invalid value for `%s`, must be a value greater than `%s`" %
837
+ (
838
+ input_variable_path[0],
839
+ current_validations['exclusive_maximum']
840
+ )
841
+ )
842
+
843
+ if (is_json_validation_enabled('minimum', configuration) and
844
+ 'inclusive_minimum' in current_validations and
845
+ min_val < current_validations['inclusive_minimum']):
846
+ raise ApiValueError(
847
+ "Invalid value for `%s`, must be a value greater than or equal "
848
+ "to `%s`" % (
849
+ input_variable_path[0],
850
+ current_validations['inclusive_minimum']
851
+ )
852
+ )
853
+ flags = current_validations.get('regex', {}).get('flags', 0)
854
+ if (is_json_validation_enabled('pattern', configuration) and
855
+ 'regex' in current_validations and
856
+ not re.search(current_validations['regex']['pattern'],
857
+ input_values, flags=flags)):
858
+ err_msg = r"Invalid value for `%s`, must match regular expression `%s`" % (
859
+ input_variable_path[0],
860
+ current_validations['regex']['pattern']
861
+ )
862
+ if flags != 0:
863
+ # Don't print the regex flags if the flags are not
864
+ # specified in the OAS document.
865
+ err_msg = r"%s with flags=`%s`" % (err_msg, flags)
866
+ raise ApiValueError(err_msg)
867
+
868
+
869
+ def order_response_types(required_types):
870
+ """Returns the required types sorted in coercion order
871
+
872
+ Args:
873
+ required_types (list/tuple): collection of classes or instance of
874
+ list or dict with class information inside it.
875
+
876
+ Returns:
877
+ (list): coercion order sorted collection of classes or instance
878
+ of list or dict with class information inside it.
879
+ """
880
+
881
+ def index_getter(class_or_instance):
882
+ if isinstance(class_or_instance, list):
883
+ return COERCION_INDEX_BY_TYPE[list]
884
+ elif isinstance(class_or_instance, dict):
885
+ return COERCION_INDEX_BY_TYPE[dict]
886
+ elif (inspect.isclass(class_or_instance)
887
+ and issubclass(class_or_instance, ModelComposed)):
888
+ return COERCION_INDEX_BY_TYPE[ModelComposed]
889
+ elif (inspect.isclass(class_or_instance)
890
+ and issubclass(class_or_instance, ModelNormal)):
891
+ return COERCION_INDEX_BY_TYPE[ModelNormal]
892
+ elif (inspect.isclass(class_or_instance)
893
+ and issubclass(class_or_instance, ModelSimple)):
894
+ return COERCION_INDEX_BY_TYPE[ModelSimple]
895
+ elif class_or_instance in COERCION_INDEX_BY_TYPE:
896
+ return COERCION_INDEX_BY_TYPE[class_or_instance]
897
+ raise ApiValueError("Unsupported type: %s" % class_or_instance)
898
+
899
+ sorted_types = sorted(
900
+ required_types,
901
+ key=lambda class_or_instance: index_getter(class_or_instance)
902
+ )
903
+ return sorted_types
904
+
905
+
906
+ def remove_uncoercible(required_types_classes, current_item, spec_property_naming,
907
+ must_convert=True):
908
+ """Only keeps the type conversions that are possible
909
+
910
+ Args:
911
+ required_types_classes (tuple): tuple of classes that are required
912
+ these should be ordered by COERCION_INDEX_BY_TYPE
913
+ spec_property_naming (bool): True if the variable names in the input
914
+ data are serialized names as specified in the OpenAPI document.
915
+ False if the variables names in the input data are python
916
+ variable names in PEP-8 snake case.
917
+ current_item (any): the current item (input data) to be converted
918
+
919
+ Keyword Args:
920
+ must_convert (bool): if True the item to convert is of the wrong
921
+ type and we want a big list of coercibles
922
+ if False, we want a limited list of coercibles
923
+
924
+ Returns:
925
+ (list): the remaining coercible required types, classes only
926
+ """
927
+ current_type_simple = get_simple_class(current_item)
928
+
929
+ results_classes = []
930
+ for required_type_class in required_types_classes:
931
+ # convert our models to OpenApiModel
932
+ required_type_class_simplified = required_type_class
933
+ if isinstance(required_type_class_simplified, type):
934
+ if issubclass(required_type_class_simplified, ModelComposed):
935
+ required_type_class_simplified = ModelComposed
936
+ elif issubclass(required_type_class_simplified, ModelNormal):
937
+ required_type_class_simplified = ModelNormal
938
+ elif issubclass(required_type_class_simplified, ModelSimple):
939
+ required_type_class_simplified = ModelSimple
940
+
941
+ if required_type_class_simplified == current_type_simple:
942
+ # don't consider converting to one's own class
943
+ continue
944
+
945
+ class_pair = (current_type_simple, required_type_class_simplified)
946
+ if must_convert and class_pair in COERCIBLE_TYPE_PAIRS[spec_property_naming]:
947
+ results_classes.append(required_type_class)
948
+ elif class_pair in UPCONVERSION_TYPE_PAIRS:
949
+ results_classes.append(required_type_class)
950
+ return results_classes
951
+
952
+ def get_discriminated_classes(cls):
953
+ """
954
+ Returns all the classes that a discriminator converts to
955
+ TODO: lru_cache this
956
+ """
957
+ possible_classes = []
958
+ key = list(cls.discriminator.keys())[0]
959
+ if is_type_nullable(cls):
960
+ possible_classes.append(cls)
961
+ for discr_cls in cls.discriminator[key].values():
962
+ if hasattr(discr_cls, 'discriminator') and discr_cls.discriminator is not None:
963
+ possible_classes.extend(get_discriminated_classes(discr_cls))
964
+ else:
965
+ possible_classes.append(discr_cls)
966
+ return possible_classes
967
+
968
+
969
+ def get_possible_classes(cls, from_server_context):
970
+ # TODO: lru_cache this
971
+ possible_classes = [cls]
972
+ if from_server_context:
973
+ return possible_classes
974
+ if hasattr(cls, 'discriminator') and cls.discriminator is not None:
975
+ possible_classes = []
976
+ possible_classes.extend(get_discriminated_classes(cls))
977
+ elif issubclass(cls, ModelComposed):
978
+ possible_classes.extend(composed_model_input_classes(cls))
979
+ return possible_classes
980
+
981
+
982
+ def get_required_type_classes(required_types_mixed, spec_property_naming):
983
+ """Converts the tuple required_types into a tuple and a dict described
984
+ below
985
+
986
+ Args:
987
+ required_types_mixed (tuple/list): will contain either classes or
988
+ instance of list or dict
989
+ spec_property_naming (bool): if True these values came from the
990
+ server, and we use the data types in our endpoints.
991
+ If False, we are client side and we need to include
992
+ oneOf and discriminator classes inside the data types in our endpoints
993
+
994
+ Returns:
995
+ (valid_classes, dict_valid_class_to_child_types_mixed):
996
+ valid_classes (tuple): the valid classes that the current item
997
+ should be
998
+ dict_valid_class_to_child_types_mixed (dict):
999
+ valid_class (class): this is the key
1000
+ child_types_mixed (list/dict/tuple): describes the valid child
1001
+ types
1002
+ """
1003
+ valid_classes = []
1004
+ child_req_types_by_current_type = {}
1005
+ for required_type in required_types_mixed:
1006
+ if isinstance(required_type, list):
1007
+ valid_classes.append(list)
1008
+ child_req_types_by_current_type[list] = required_type
1009
+ elif isinstance(required_type, tuple):
1010
+ valid_classes.append(tuple)
1011
+ child_req_types_by_current_type[tuple] = required_type
1012
+ elif isinstance(required_type, dict):
1013
+ valid_classes.append(dict)
1014
+ child_req_types_by_current_type[dict] = required_type[str]
1015
+ else:
1016
+ valid_classes.extend(get_possible_classes(required_type, spec_property_naming))
1017
+ return tuple(valid_classes), child_req_types_by_current_type
1018
+
1019
+
1020
+ def change_keys_js_to_python(input_dict, model_class):
1021
+ """
1022
+ Converts from javascript_key keys in the input_dict to python_keys in
1023
+ the output dict using the mapping in model_class.
1024
+ If the input_dict contains a key which does not declared in the model_class,
1025
+ the key is added to the output dict as is. The assumption is the model_class
1026
+ may have undeclared properties (additionalProperties attribute in the OAS
1027
+ document).
1028
+ """
1029
+
1030
+ if getattr(model_class, 'attribute_map', None) is None:
1031
+ return input_dict
1032
+ output_dict = {}
1033
+ reversed_attr_map = {value: key for key, value in
1034
+ model_class.attribute_map.items()}
1035
+ for javascript_key, value in input_dict.items():
1036
+ python_key = reversed_attr_map.get(javascript_key)
1037
+ if python_key is None:
1038
+ # if the key is unknown, it is in error or it is an
1039
+ # additionalProperties variable
1040
+ python_key = javascript_key
1041
+ output_dict[python_key] = value
1042
+ return output_dict
1043
+
1044
+
1045
+ def get_type_error(var_value, path_to_item, valid_classes, key_type=False):
1046
+ error_msg = type_error_message(
1047
+ var_name=path_to_item[-1],
1048
+ var_value=var_value,
1049
+ valid_classes=valid_classes,
1050
+ key_type=key_type
1051
+ )
1052
+ return ApiTypeError(
1053
+ error_msg,
1054
+ path_to_item=path_to_item,
1055
+ valid_classes=valid_classes,
1056
+ key_type=key_type
1057
+ )
1058
+
1059
+
1060
+ def deserialize_primitive(data, klass, path_to_item):
1061
+ """Deserializes string to primitive type.
1062
+
1063
+ :param data: str/int/float
1064
+ :param klass: str/class the class to convert to
1065
+
1066
+ :return: int, float, str, bool, date, datetime
1067
+ """
1068
+ additional_message = ""
1069
+ try:
1070
+ if klass in {datetime, date}:
1071
+ additional_message = (
1072
+ "If you need your parameter to have a fallback "
1073
+ "string value, please set its type as `type: {}` in your "
1074
+ "spec. That allows the value to be any type. "
1075
+ )
1076
+ if klass == datetime:
1077
+ if len(data) < 8:
1078
+ raise ValueError("This is not a datetime")
1079
+ # The string should be in iso8601 datetime format.
1080
+ parsed_datetime = parse(data)
1081
+ date_only = (
1082
+ parsed_datetime.hour == 0 and
1083
+ parsed_datetime.minute == 0 and
1084
+ parsed_datetime.second == 0 and
1085
+ parsed_datetime.tzinfo is None and
1086
+ 8 <= len(data) <= 10
1087
+ )
1088
+ if date_only:
1089
+ raise ValueError("This is a date, not a datetime")
1090
+ return parsed_datetime
1091
+ elif klass == date:
1092
+ if len(data) < 8:
1093
+ raise ValueError("This is not a date")
1094
+ return parse(data).date()
1095
+ else:
1096
+ converted_value = klass(data)
1097
+ if isinstance(data, str) and klass == float:
1098
+ if str(converted_value) != data:
1099
+ # '7' -> 7.0 -> '7.0' != '7'
1100
+ raise ValueError('This is not a float')
1101
+ return converted_value
1102
+ except (OverflowError, ValueError) as ex:
1103
+ # parse can raise OverflowError
1104
+ raise ApiValueError(
1105
+ "{0}Failed to parse {1} as {2}".format(
1106
+ additional_message, repr(data), klass.__name__
1107
+ ),
1108
+ path_to_item=path_to_item
1109
+ ) from ex
1110
+
1111
+
1112
+ def get_discriminator_class(model_class,
1113
+ discr_name,
1114
+ discr_value, cls_visited):
1115
+ """Returns the child class specified by the discriminator.
1116
+
1117
+ Args:
1118
+ model_class (OpenApiModel): the model class.
1119
+ discr_name (string): the name of the discriminator property.
1120
+ discr_value (any): the discriminator value.
1121
+ cls_visited (list): list of model classes that have been visited.
1122
+ Used to determine the discriminator class without
1123
+ visiting circular references indefinitely.
1124
+
1125
+ Returns:
1126
+ used_model_class (class/None): the chosen child class that will be used
1127
+ to deserialize the data, for example dog.Dog.
1128
+ If a class is not found, None is returned.
1129
+ """
1130
+
1131
+ if model_class in cls_visited:
1132
+ # The class has already been visited and no suitable class was found.
1133
+ return None
1134
+ cls_visited.append(model_class)
1135
+ used_model_class = None
1136
+ if discr_name in model_class.discriminator:
1137
+ class_name_to_discr_class = model_class.discriminator[discr_name]
1138
+ used_model_class = class_name_to_discr_class.get(discr_value)
1139
+ if used_model_class is None:
1140
+ # We didn't find a discriminated class in class_name_to_discr_class.
1141
+ # So look in the ancestor or descendant discriminators
1142
+ # The discriminator mapping may exist in a descendant (anyOf, oneOf)
1143
+ # or ancestor (allOf).
1144
+ # Ancestor example: in the GrandparentAnimal -> ParentPet -> ChildCat
1145
+ # hierarchy, the discriminator mappings may be defined at any level
1146
+ # in the hierarchy.
1147
+ # Descendant example: mammal -> whale/zebra/Pig -> BasquePig/DanishPig
1148
+ # if we try to make BasquePig from mammal, we need to travel through
1149
+ # the oneOf descendant discriminators to find BasquePig
1150
+ descendant_classes = model_class._composed_schemas.get('oneOf', ()) + \
1151
+ model_class._composed_schemas.get('anyOf', ())
1152
+ ancestor_classes = model_class._composed_schemas.get('allOf', ())
1153
+ possible_classes = descendant_classes + ancestor_classes
1154
+ for cls in possible_classes:
1155
+ # Check if the schema has inherited discriminators.
1156
+ if hasattr(cls, 'discriminator') and cls.discriminator is not None:
1157
+ used_model_class = get_discriminator_class(
1158
+ cls, discr_name, discr_value, cls_visited)
1159
+ if used_model_class is not None:
1160
+ return used_model_class
1161
+ return used_model_class
1162
+
1163
+
1164
+ def deserialize_model(model_data, model_class, path_to_item, check_type,
1165
+ configuration, spec_property_naming):
1166
+ """Deserializes model_data to model instance.
1167
+
1168
+ Args:
1169
+ model_data (int/str/float/bool/none_type/list/dict): data to instantiate the model
1170
+ model_class (OpenApiModel): the model class
1171
+ path_to_item (list): path to the model in the received data
1172
+ check_type (bool): whether to check the data tupe for the values in
1173
+ the model
1174
+ configuration (Configuration): the instance to use to convert files
1175
+ spec_property_naming (bool): True if the variable names in the input
1176
+ data are serialized names as specified in the OpenAPI document.
1177
+ False if the variables names in the input data are python
1178
+ variable names in PEP-8 snake case.
1179
+
1180
+ Returns:
1181
+ model instance
1182
+
1183
+ Raise:
1184
+ ApiTypeError
1185
+ ApiValueError
1186
+ ApiKeyError
1187
+ """
1188
+
1189
+ kw_args = dict(_check_type=check_type,
1190
+ _path_to_item=path_to_item,
1191
+ _configuration=configuration,
1192
+ _spec_property_naming=spec_property_naming)
1193
+
1194
+ if issubclass(model_class, ModelSimple):
1195
+ return model_class(model_data, **kw_args)
1196
+ elif isinstance(model_data, list):
1197
+ return model_class(*model_data, **kw_args)
1198
+ if isinstance(model_data, dict):
1199
+ kw_args.update(model_data)
1200
+ return model_class(**kw_args)
1201
+ elif isinstance(model_data, PRIMITIVE_TYPES):
1202
+ return model_class(model_data, **kw_args)
1203
+
1204
+
1205
+ def deserialize_file(response_data, configuration, content_disposition=None):
1206
+ """Deserializes body to file
1207
+
1208
+ Saves response body into a file in a temporary folder,
1209
+ using the filename from the `Content-Disposition` header if provided.
1210
+
1211
+ Args:
1212
+ param response_data (str): the file data to write
1213
+ configuration (Configuration): the instance to use to convert files
1214
+
1215
+ Keyword Args:
1216
+ content_disposition (str): the value of the Content-Disposition
1217
+ header
1218
+
1219
+ Returns:
1220
+ (file_type): the deserialized file which is open
1221
+ The user is responsible for closing and reading the file
1222
+ """
1223
+ fd, path = tempfile.mkstemp(dir=configuration.temp_folder_path)
1224
+ os.close(fd)
1225
+ os.remove(path)
1226
+
1227
+ if content_disposition:
1228
+ filename = re.search(r'filename=[\'"]?([^\'"\s]+)[\'"]?',
1229
+ content_disposition).group(1)
1230
+ path = os.path.join(os.path.dirname(path), filename)
1231
+
1232
+ with open(path, "wb") as f:
1233
+ if isinstance(response_data, str):
1234
+ # change str to bytes so we can write it
1235
+ response_data = response_data.encode('utf-8')
1236
+ f.write(response_data)
1237
+
1238
+ f = open(path, "rb")
1239
+ return f
1240
+
1241
+
1242
+ def attempt_convert_item(input_value, valid_classes, path_to_item,
1243
+ configuration, spec_property_naming, key_type=False,
1244
+ must_convert=False, check_type=True):
1245
+ """
1246
+ Args:
1247
+ input_value (any): the data to convert
1248
+ valid_classes (any): the classes that are valid
1249
+ path_to_item (list): the path to the item to convert
1250
+ configuration (Configuration): the instance to use to convert files
1251
+ spec_property_naming (bool): True if the variable names in the input
1252
+ data are serialized names as specified in the OpenAPI document.
1253
+ False if the variables names in the input data are python
1254
+ variable names in PEP-8 snake case.
1255
+ key_type (bool): if True we need to convert a key type (not supported)
1256
+ must_convert (bool): if True we must convert
1257
+ check_type (bool): if True we check the type or the returned data in
1258
+ ModelComposed/ModelNormal/ModelSimple instances
1259
+
1260
+ Returns:
1261
+ instance (any) the fixed item
1262
+
1263
+ Raises:
1264
+ ApiTypeError
1265
+ ApiValueError
1266
+ ApiKeyError
1267
+ """
1268
+ valid_classes_ordered = order_response_types(valid_classes)
1269
+ valid_classes_coercible = remove_uncoercible(
1270
+ valid_classes_ordered, input_value, spec_property_naming)
1271
+ if not valid_classes_coercible or key_type:
1272
+ # we do not handle keytype errors, json will take care
1273
+ # of this for us
1274
+ if configuration is None or not configuration.discard_unknown_keys:
1275
+ raise get_type_error(input_value, path_to_item, valid_classes,
1276
+ key_type=key_type)
1277
+ for valid_class in valid_classes_coercible:
1278
+ try:
1279
+ if issubclass(valid_class, OpenApiModel):
1280
+ return deserialize_model(input_value, valid_class,
1281
+ path_to_item, check_type,
1282
+ configuration, spec_property_naming)
1283
+ elif valid_class == file_type:
1284
+ return deserialize_file(input_value, configuration)
1285
+ return deserialize_primitive(input_value, valid_class,
1286
+ path_to_item)
1287
+ except (ApiTypeError, ApiValueError, ApiKeyError) as conversion_exc:
1288
+ if must_convert:
1289
+ raise conversion_exc
1290
+ # if we have conversion errors when must_convert == False
1291
+ # we ignore the exception and move on to the next class
1292
+ continue
1293
+ # we were unable to convert, must_convert == False
1294
+ return input_value
1295
+
1296
+
1297
+ def is_type_nullable(input_type):
1298
+ """
1299
+ Returns true if None is an allowed value for the specified input_type.
1300
+
1301
+ A type is nullable if at least one of the following conditions is true:
1302
+ 1. The OAS 'nullable' attribute has been specified,
1303
+ 1. The type is the 'null' type,
1304
+ 1. The type is a anyOf/oneOf composed schema, and a child schema is
1305
+ the 'null' type.
1306
+ Args:
1307
+ input_type (type): the class of the input_value that we are
1308
+ checking
1309
+ Returns:
1310
+ bool
1311
+ """
1312
+ if input_type is none_type:
1313
+ return True
1314
+ if issubclass(input_type, OpenApiModel) and input_type._nullable:
1315
+ return True
1316
+ if issubclass(input_type, ModelComposed):
1317
+ # If oneOf/anyOf, check if the 'null' type is one of the allowed types.
1318
+ for t in input_type._composed_schemas.get('oneOf', ()):
1319
+ if is_type_nullable(t): return True
1320
+ for t in input_type._composed_schemas.get('anyOf', ()):
1321
+ if is_type_nullable(t): return True
1322
+ return False
1323
+
1324
+
1325
+ def is_valid_type(input_class_simple, valid_classes):
1326
+ """
1327
+ Args:
1328
+ input_class_simple (class): the class of the input_value that we are
1329
+ checking
1330
+ valid_classes (tuple): the valid classes that the current item
1331
+ should be
1332
+ Returns:
1333
+ bool
1334
+ """
1335
+ valid_type = input_class_simple in valid_classes
1336
+ if not valid_type and (
1337
+ issubclass(input_class_simple, OpenApiModel) or
1338
+ input_class_simple is none_type):
1339
+ for valid_class in valid_classes:
1340
+ if input_class_simple is none_type and is_type_nullable(valid_class):
1341
+ # Schema is oneOf/anyOf and the 'null' type is one of the allowed types.
1342
+ return True
1343
+ if not (issubclass(valid_class, OpenApiModel) and valid_class.discriminator):
1344
+ continue
1345
+ discr_propertyname_py = list(valid_class.discriminator.keys())[0]
1346
+ discriminator_classes = (
1347
+ valid_class.discriminator[discr_propertyname_py].values()
1348
+ )
1349
+ valid_type = is_valid_type(input_class_simple, discriminator_classes)
1350
+ if valid_type:
1351
+ return True
1352
+ return valid_type
1353
+
1354
+
1355
+ def validate_and_convert_types(input_value, required_types_mixed, path_to_item,
1356
+ spec_property_naming, _check_type, configuration=None):
1357
+ """Raises a TypeError is there is a problem, otherwise returns value
1358
+
1359
+ Args:
1360
+ input_value (any): the data to validate/convert
1361
+ required_types_mixed (list/dict/tuple): A list of
1362
+ valid classes, or a list tuples of valid classes, or a dict where
1363
+ the value is a tuple of value classes
1364
+ path_to_item: (list) the path to the data being validated
1365
+ this stores a list of keys or indices to get to the data being
1366
+ validated
1367
+ spec_property_naming (bool): True if the variable names in the input
1368
+ data are serialized names as specified in the OpenAPI document.
1369
+ False if the variables names in the input data are python
1370
+ variable names in PEP-8 snake case.
1371
+ _check_type: (boolean) if true, type will be checked and conversion
1372
+ will be attempted.
1373
+ configuration: (Configuration): the configuration class to use
1374
+ when converting file_type items.
1375
+ If passed, conversion will be attempted when possible
1376
+ If not passed, no conversions will be attempted and
1377
+ exceptions will be raised
1378
+
1379
+ Returns:
1380
+ the correctly typed value
1381
+
1382
+ Raises:
1383
+ ApiTypeError
1384
+ """
1385
+ results = get_required_type_classes(required_types_mixed, spec_property_naming)
1386
+ valid_classes, child_req_types_by_current_type = results
1387
+
1388
+ input_class_simple = get_simple_class(input_value)
1389
+ valid_type = is_valid_type(input_class_simple, valid_classes)
1390
+ if not valid_type:
1391
+ if configuration:
1392
+ # if input_value is not valid_type try to convert it
1393
+ converted_instance = attempt_convert_item(
1394
+ input_value,
1395
+ valid_classes,
1396
+ path_to_item,
1397
+ configuration,
1398
+ spec_property_naming,
1399
+ key_type=False,
1400
+ must_convert=True
1401
+ )
1402
+ return converted_instance
1403
+ else:
1404
+ raise get_type_error(input_value, path_to_item, valid_classes,
1405
+ key_type=False)
1406
+
1407
+ # input_value's type is in valid_classes
1408
+ if len(valid_classes) > 1 and configuration:
1409
+ # there are valid classes which are not the current class
1410
+ valid_classes_coercible = remove_uncoercible(
1411
+ valid_classes, input_value, spec_property_naming, must_convert=False)
1412
+ if valid_classes_coercible:
1413
+ converted_instance = attempt_convert_item(
1414
+ input_value,
1415
+ valid_classes_coercible,
1416
+ path_to_item,
1417
+ configuration,
1418
+ spec_property_naming,
1419
+ key_type=False,
1420
+ must_convert=False
1421
+ )
1422
+ return converted_instance
1423
+
1424
+ if child_req_types_by_current_type == {}:
1425
+ # all types are of the required types and there are no more inner
1426
+ # variables left to look at
1427
+ return input_value
1428
+ inner_required_types = child_req_types_by_current_type.get(
1429
+ type(input_value)
1430
+ )
1431
+ if inner_required_types is None:
1432
+ # for this type, there are not more inner variables left to look at
1433
+ return input_value
1434
+ if isinstance(input_value, list):
1435
+ if input_value == []:
1436
+ # allow an empty list
1437
+ return input_value
1438
+ for index, inner_value in enumerate(input_value):
1439
+ inner_path = list(path_to_item)
1440
+ inner_path.append(index)
1441
+ input_value[index] = validate_and_convert_types(
1442
+ inner_value,
1443
+ inner_required_types,
1444
+ inner_path,
1445
+ spec_property_naming,
1446
+ _check_type,
1447
+ configuration=configuration
1448
+ )
1449
+ elif isinstance(input_value, dict):
1450
+ if input_value == {}:
1451
+ # allow an empty dict
1452
+ return input_value
1453
+ for inner_key, inner_val in input_value.items():
1454
+ inner_path = list(path_to_item)
1455
+ inner_path.append(inner_key)
1456
+ if get_simple_class(inner_key) != str:
1457
+ raise get_type_error(inner_key, inner_path, valid_classes,
1458
+ key_type=True)
1459
+ input_value[inner_key] = validate_and_convert_types(
1460
+ inner_val,
1461
+ inner_required_types,
1462
+ inner_path,
1463
+ spec_property_naming,
1464
+ _check_type,
1465
+ configuration=configuration
1466
+ )
1467
+ return input_value
1468
+
1469
+
1470
+ def model_to_dict(model_instance, serialize=True):
1471
+ """Returns the model properties as a dict
1472
+
1473
+ Args:
1474
+ model_instance (one of your model instances): the model instance that
1475
+ will be converted to a dict.
1476
+
1477
+ Keyword Args:
1478
+ serialize (bool): if True, the keys in the dict will be values from
1479
+ attribute_map
1480
+ """
1481
+ result = {}
1482
+
1483
+ model_instances = [model_instance]
1484
+ if model_instance._composed_schemas:
1485
+ model_instances.extend(model_instance._composed_instances)
1486
+ for model_instance in model_instances:
1487
+ for attr, value in model_instance._data_store.items():
1488
+ if serialize:
1489
+ # we use get here because additional property key names do not
1490
+ # exist in attribute_map
1491
+ attr = model_instance.attribute_map.get(attr, attr)
1492
+ if isinstance(value, list):
1493
+ result[attr] = list(map(
1494
+ lambda x: model_to_dict(x, serialize=serialize)
1495
+ if hasattr(x, '_data_store') else x, value
1496
+ ))
1497
+ elif isinstance(value, dict):
1498
+ result[attr] = dict(map(
1499
+ lambda item: (item[0],
1500
+ model_to_dict(item[1], serialize=serialize))
1501
+ if hasattr(item[1], '_data_store') else item,
1502
+ value.items()
1503
+ ))
1504
+ elif isinstance(value, ModelSimple):
1505
+ result[attr] = value.value
1506
+ elif hasattr(value, '_data_store'):
1507
+ result[attr] = model_to_dict(value, serialize=serialize)
1508
+ else:
1509
+ result[attr] = value
1510
+
1511
+ return result
1512
+
1513
+
1514
+ def type_error_message(var_value=None, var_name=None, valid_classes=None,
1515
+ key_type=None):
1516
+ """
1517
+ Keyword Args:
1518
+ var_value (any): the variable which has the type_error
1519
+ var_name (str): the name of the variable which has the typ error
1520
+ valid_classes (tuple): the accepted classes for current_item's
1521
+ value
1522
+ key_type (bool): False if our value is a value in a dict
1523
+ True if it is a key in a dict
1524
+ False if our item is an item in a list
1525
+ """
1526
+ key_or_value = 'value'
1527
+ if key_type:
1528
+ key_or_value = 'key'
1529
+ valid_classes_phrase = get_valid_classes_phrase(valid_classes)
1530
+ msg = (
1531
+ "Invalid type for variable '{0}'. Required {1} type {2} and "
1532
+ "passed type was {3}".format(
1533
+ var_name,
1534
+ key_or_value,
1535
+ valid_classes_phrase,
1536
+ type(var_value).__name__,
1537
+ )
1538
+ )
1539
+ return msg
1540
+
1541
+
1542
+ def get_valid_classes_phrase(input_classes):
1543
+ """Returns a string phrase describing what types are allowed
1544
+ """
1545
+ all_classes = list(input_classes)
1546
+ all_classes = sorted(all_classes, key=lambda cls: cls.__name__)
1547
+ all_class_names = [cls.__name__ for cls in all_classes]
1548
+ if len(all_class_names) == 1:
1549
+ return 'is {0}'.format(all_class_names[0])
1550
+ return "is one of [{0}]".format(", ".join(all_class_names))
1551
+
1552
+
1553
+ def convert_js_args_to_python_args(fn):
1554
+ from functools import wraps
1555
+ @wraps(fn)
1556
+ def wrapped_init(self, *args, **kwargs):
1557
+ spec_property_naming = kwargs.get('_spec_property_naming', False)
1558
+ if spec_property_naming:
1559
+ kwargs = change_keys_js_to_python(kwargs, self.__class__)
1560
+ return fn(self, *args, **kwargs)
1561
+ return wrapped_init
1562
+
1563
+
1564
+ def get_allof_instances(self, model_args, constant_args):
1565
+ """
1566
+ Args:
1567
+ self: the class we are handling
1568
+ model_args (dict): var_name to var_value
1569
+ used to make instances
1570
+ constant_args (dict): var_name to var_value
1571
+ used to make instances
1572
+
1573
+ Returns
1574
+ composed_instances (list)
1575
+ """
1576
+ composed_instances = []
1577
+ for allof_class in self._composed_schemas['allOf']:
1578
+
1579
+ # no need to handle changing js keys to python because
1580
+ # for composed schemas, allof parameters are included in the
1581
+ # composed schema and were changed to python keys in __new__
1582
+ # extract a dict of only required keys from fixed_model_args
1583
+ kwargs = {}
1584
+ var_names = set(allof_class.openapi_types.keys())
1585
+ for var_name in var_names:
1586
+ if var_name in model_args:
1587
+ kwargs[var_name] = model_args[var_name]
1588
+
1589
+ # and use it to make the instance
1590
+ kwargs.update(constant_args)
1591
+ try:
1592
+ allof_instance = allof_class(**kwargs)
1593
+ composed_instances.append(allof_instance)
1594
+ except Exception as ex:
1595
+ raise ApiValueError(
1596
+ "Invalid inputs given to generate an instance of '%s'. The "
1597
+ "input data was invalid for the allOf schema '%s' in the composed "
1598
+ "schema '%s'. Error=%s" % (
1599
+ allof_class.__name__,
1600
+ allof_class.__name__,
1601
+ self.__class__.__name__,
1602
+ str(ex)
1603
+ )
1604
+ ) from ex
1605
+ return composed_instances
1606
+
1607
+
1608
+ def get_oneof_instance(cls, model_kwargs, constant_kwargs, model_arg=None):
1609
+ """
1610
+ Find the oneOf schema that matches the input data (e.g. payload).
1611
+ If exactly one schema matches the input data, an instance of that schema
1612
+ is returned.
1613
+ If zero or more than one schema match the input data, an exception is raised.
1614
+ In OAS 3.x, the payload MUST, by validation, match exactly one of the
1615
+ schemas described by oneOf.
1616
+
1617
+ Args:
1618
+ cls: the class we are handling
1619
+ model_kwargs (dict): var_name to var_value
1620
+ The input data, e.g. the payload that must match a oneOf schema
1621
+ in the OpenAPI document.
1622
+ constant_kwargs (dict): var_name to var_value
1623
+ args that every model requires, including configuration, server
1624
+ and path to item.
1625
+
1626
+ Kwargs:
1627
+ model_arg: (int, float, bool, str, date, datetime, ModelSimple, None):
1628
+ the value to assign to a primitive class or ModelSimple class
1629
+ Notes:
1630
+ - this is only passed in when oneOf includes types which are not object
1631
+ - None is used to suppress handling of model_arg, nullable models are handled in __new__
1632
+
1633
+ Returns
1634
+ oneof_instance (instance)
1635
+ """
1636
+ if len(cls._composed_schemas['oneOf']) == 0:
1637
+ return None
1638
+
1639
+ oneof_instances = []
1640
+ # Iterate over each oneOf schema and determine if the input data
1641
+ # matches the oneOf schemas.
1642
+ for oneof_class in cls._composed_schemas['oneOf']:
1643
+ # The composed oneOf schema allows the 'null' type and the input data
1644
+ # is the null value. This is a OAS >= 3.1 feature.
1645
+ if oneof_class is none_type:
1646
+ # skip none_types because we are deserializing dict data.
1647
+ # none_type deserialization is handled in the __new__ method
1648
+ continue
1649
+
1650
+ single_value_input = allows_single_value_input(oneof_class)
1651
+
1652
+ if not single_value_input:
1653
+ # transform js keys from input data to python keys in fixed_model_args
1654
+ fixed_model_args = change_keys_js_to_python(
1655
+ model_kwargs, oneof_class)
1656
+
1657
+ # Extract a dict with the properties that are declared in the oneOf schema.
1658
+ # Undeclared properties (e.g. properties that are allowed because of the
1659
+ # additionalProperties attribute in the OAS document) are not added to
1660
+ # the dict.
1661
+ kwargs = {}
1662
+ var_names = set(oneof_class.openapi_types.keys())
1663
+ for var_name in var_names:
1664
+ if var_name in fixed_model_args:
1665
+ kwargs[var_name] = fixed_model_args[var_name]
1666
+
1667
+ # do not try to make a model with no input args
1668
+ if len(kwargs) == 0:
1669
+ continue
1670
+
1671
+ # and use it to make the instance
1672
+ kwargs.update(constant_kwargs)
1673
+
1674
+ try:
1675
+ if not single_value_input:
1676
+ oneof_instance = oneof_class(**kwargs)
1677
+ else:
1678
+ if issubclass(oneof_class, ModelSimple):
1679
+ oneof_instance = oneof_class(model_arg, **constant_kwargs)
1680
+ elif oneof_class in PRIMITIVE_TYPES:
1681
+ oneof_instance = validate_and_convert_types(
1682
+ model_arg,
1683
+ (oneof_class,),
1684
+ constant_kwargs['_path_to_item'],
1685
+ constant_kwargs['_spec_property_naming'],
1686
+ constant_kwargs['_check_type'],
1687
+ configuration=constant_kwargs['_configuration']
1688
+ )
1689
+ oneof_instances.append(oneof_instance)
1690
+ except Exception:
1691
+ pass
1692
+ if len(oneof_instances) == 0:
1693
+ raise ApiValueError(
1694
+ "Invalid inputs given to generate an instance of %s. None "
1695
+ "of the oneOf schemas matched the input data." %
1696
+ cls.__name__
1697
+ )
1698
+ elif len(oneof_instances) > 1:
1699
+ raise ApiValueError(
1700
+ "Invalid inputs given to generate an instance of %s. Multiple "
1701
+ "oneOf schemas matched the inputs, but a max of one is allowed." %
1702
+ cls.__name__
1703
+ )
1704
+ return oneof_instances[0]
1705
+
1706
+
1707
+ def get_anyof_instances(self, model_args, constant_args):
1708
+ """
1709
+ Args:
1710
+ self: the class we are handling
1711
+ model_args (dict): var_name to var_value
1712
+ The input data, e.g. the payload that must match at least one
1713
+ anyOf child schema in the OpenAPI document.
1714
+ constant_args (dict): var_name to var_value
1715
+ args that every model requires, including configuration, server
1716
+ and path to item.
1717
+
1718
+ Returns
1719
+ anyof_instances (list)
1720
+ """
1721
+ anyof_instances = []
1722
+ if len(self._composed_schemas['anyOf']) == 0:
1723
+ return anyof_instances
1724
+
1725
+ for anyof_class in self._composed_schemas['anyOf']:
1726
+ # The composed oneOf schema allows the 'null' type and the input data
1727
+ # is the null value. This is a OAS >= 3.1 feature.
1728
+ if anyof_class is none_type:
1729
+ # skip none_types because we are deserializing dict data.
1730
+ # none_type deserialization is handled in the __new__ method
1731
+ continue
1732
+
1733
+ # transform js keys to python keys in fixed_model_args
1734
+ fixed_model_args = change_keys_js_to_python(model_args, anyof_class)
1735
+
1736
+ # extract a dict of only required keys from these_model_vars
1737
+ kwargs = {}
1738
+ var_names = set(anyof_class.openapi_types.keys())
1739
+ for var_name in var_names:
1740
+ if var_name in fixed_model_args:
1741
+ kwargs[var_name] = fixed_model_args[var_name]
1742
+
1743
+ # do not try to make a model with no input args
1744
+ if len(kwargs) == 0:
1745
+ continue
1746
+
1747
+ # and use it to make the instance
1748
+ kwargs.update(constant_args)
1749
+ try:
1750
+ anyof_instance = anyof_class(**kwargs)
1751
+ anyof_instances.append(anyof_instance)
1752
+ except Exception:
1753
+ pass
1754
+ if len(anyof_instances) == 0:
1755
+ raise ApiValueError(
1756
+ "Invalid inputs given to generate an instance of %s. None of the "
1757
+ "anyOf schemas matched the inputs." %
1758
+ self.__class__.__name__
1759
+ )
1760
+ return anyof_instances
1761
+
1762
+
1763
+ def get_additional_properties_model_instances(
1764
+ composed_instances, self):
1765
+ additional_properties_model_instances = []
1766
+ all_instances = [self]
1767
+ all_instances.extend(composed_instances)
1768
+ for instance in all_instances:
1769
+ if instance.additional_properties_type is not None:
1770
+ additional_properties_model_instances.append(instance)
1771
+ return additional_properties_model_instances
1772
+
1773
+
1774
+ def get_var_name_to_model_instances(self, composed_instances):
1775
+ var_name_to_model_instances = {}
1776
+ all_instances = [self]
1777
+ all_instances.extend(composed_instances)
1778
+ for instance in all_instances:
1779
+ for var_name in instance.openapi_types:
1780
+ if var_name not in var_name_to_model_instances:
1781
+ var_name_to_model_instances[var_name] = [instance]
1782
+ else:
1783
+ var_name_to_model_instances[var_name].append(instance)
1784
+ return var_name_to_model_instances
1785
+
1786
+
1787
+ def get_unused_args(self, composed_instances, model_args):
1788
+ unused_args = dict(model_args)
1789
+ # arguments apssed to self were already converted to python names
1790
+ # before __init__ was called
1791
+ for var_name_py in self.attribute_map:
1792
+ if var_name_py in unused_args:
1793
+ del unused_args[var_name_py]
1794
+ for instance in composed_instances:
1795
+ if instance.__class__ in self._composed_schemas['allOf']:
1796
+ for var_name_py in instance.attribute_map:
1797
+ if var_name_py in unused_args:
1798
+ del unused_args[var_name_py]
1799
+ else:
1800
+ for var_name_js in instance.attribute_map.values():
1801
+ if var_name_js in unused_args:
1802
+ del unused_args[var_name_js]
1803
+ return unused_args
1804
+
1805
+
1806
+ def validate_get_composed_info(constant_args, model_args, self):
1807
+ """
1808
+ For composed schemas, generate schema instances for
1809
+ all schemas in the oneOf/anyOf/allOf definition. If additional
1810
+ properties are allowed, also assign those properties on
1811
+ all matched schemas that contain additionalProperties.
1812
+ Openapi schemas are python classes.
1813
+
1814
+ Exceptions are raised if:
1815
+ - 0 or > 1 oneOf schema matches the model_args input data
1816
+ - no anyOf schema matches the model_args input data
1817
+ - any of the allOf schemas do not match the model_args input data
1818
+
1819
+ Args:
1820
+ constant_args (dict): these are the args that every model requires
1821
+ model_args (dict): these are the required and optional spec args that
1822
+ were passed in to make this model
1823
+ self (class): the class that we are instantiating
1824
+ This class contains self._composed_schemas
1825
+
1826
+ Returns:
1827
+ composed_info (list): length three
1828
+ composed_instances (list): the composed instances which are not
1829
+ self
1830
+ var_name_to_model_instances (dict): a dict going from var_name
1831
+ to the model_instance which holds that var_name
1832
+ the model_instance may be self or an instance of one of the
1833
+ classes in self.composed_instances()
1834
+ additional_properties_model_instances (list): a list of the
1835
+ model instances which have the property
1836
+ additional_properties_type. This list can include self
1837
+ """
1838
+ # create composed_instances
1839
+ composed_instances = []
1840
+ allof_instances = get_allof_instances(self, model_args, constant_args)
1841
+ composed_instances.extend(allof_instances)
1842
+ oneof_instance = get_oneof_instance(self.__class__, model_args, constant_args)
1843
+ if oneof_instance is not None:
1844
+ composed_instances.append(oneof_instance)
1845
+ anyof_instances = get_anyof_instances(self, model_args, constant_args)
1846
+ composed_instances.extend(anyof_instances)
1847
+
1848
+ # map variable names to composed_instances
1849
+ var_name_to_model_instances = get_var_name_to_model_instances(
1850
+ self, composed_instances)
1851
+
1852
+ # set additional_properties_model_instances
1853
+ additional_properties_model_instances = (
1854
+ get_additional_properties_model_instances(composed_instances, self)
1855
+ )
1856
+
1857
+ # set any remaining values
1858
+ unused_args = get_unused_args(self, composed_instances, model_args)
1859
+ if len(unused_args) > 0 and \
1860
+ len(additional_properties_model_instances) == 0 and \
1861
+ (self._configuration is None or
1862
+ not self._configuration.discard_unknown_keys):
1863
+ raise ApiValueError(
1864
+ "Invalid input arguments input when making an instance of "
1865
+ "class %s. Not all inputs were used. The unused input data "
1866
+ "is %s" % (self.__class__.__name__, unused_args)
1867
+ )
1868
+
1869
+ # no need to add additional_properties to var_name_to_model_instances here
1870
+ # because additional_properties_model_instances will direct us to that
1871
+ # instance when we use getattr or setattr
1872
+ # and we update var_name_to_model_instances in setattr
1873
+
1874
+ return [
1875
+ composed_instances,
1876
+ var_name_to_model_instances,
1877
+ additional_properties_model_instances,
1878
+ unused_args
1879
+ ]