class_docstr: Security configuration for a Dask cluster.
  
  Default values are loaded from Dask's configuration files, and can be
  overridden in the constructor.
  
  Parameters
  ----------
  require_encryption : bool, optional
      Whether TLS encryption is required for all connections.
  tls_ca_file : str, optional
      Path to a CA certificate file encoded in PEM format.
  tls_ciphers : str, optional
      An OpenSSL cipher string of allowed ciphers. If not provided, the
      system defaults will be used.
  tls_min_version : ssl.TLSVersion, optional
      The minimum TLS version to support. Defaults to TLS 1.2.
  tls_max_version : ssl.TLSVersion, optional
      The maximum TLS version to support. Defaults to the maximum version
      supported.
  tls_client_cert : str, optional
      Path to a certificate file for the client, encoded in PEM format.
  tls_client_key : str, optional
      Path to a key file for the client, encoded in PEM format.
      Alternatively, the key may be appended to the cert file, and this
      parameter be omitted.
  tls_scheduler_cert : str, optional
      Path to a certificate file for the scheduler, encoded in PEM format.
  tls_scheduler_key : str, optional
      Path to a key file for the scheduler, encoded in PEM format.
      Alternatively, the key may be appended to the cert file, and this
      parameter be omitted.
  tls_worker_cert : str, optional
      Path to a certificate file for a worker, encoded in PEM format.
  tls_worker_key : str, optional
      Path to a key file for a worker, encoded in PEM format.
      Alternatively, the key may be appended to the cert file, and this
      parameter be omitted.
  extra_conn_args : mapping, optional
      Mapping with keyword arguments to pass down to connections.
class_docstr_tok: ["Security","configuration","for","a","Dask","cluster",".","Default","values","are","loaded","from","Dask","'s","configuration","files",",","and","can","be","overridden","in","the","constructor",".","Parameters","--","--","--","--","--","require_encryption",":","bool",",","optional","Whether","TLS","encryption","is","required","for","all","connections",".","tls_ca_file",":","str",",","optional","Path","to","a","CA","certificate","file","encoded","in","PEM","format",".","tls_ciphers",":","str",",","optional","An","OpenSSL","cipher","string","of","allowed","ciphers",".","If","not","provided",",","the","system","defaults","will","be","used",".","tls_min_version",":","ssl.TLSVersion",",","optional","The","minimum","TLS","version","to","support",".","Defaults","to","TLS","1.2.","tls_max_version",":","ssl.TLSVersion",",","optional","The","maximum","TLS","version","to","support",".","Defaults","to","the","maximum","version","supported",".","tls_client_cert",":","str",",","optional","Path","to","a","certificate","file","for","the","client",",","encoded","in","PEM","format",".","tls_client_key",":","str",",","optional","Path","to","a","key","file","for","the","client",",","encoded","in","PEM","format",".","Alternatively",",","the","key","may","be","appended","to","the","cert","file",",","and","this","parameter","be","omitted",".","tls_scheduler_cert",":","str",",","optional","Path","to","a","certificate","file","for","the","scheduler",",","encoded","in","PEM","format",".","tls_scheduler_key",":","str",",","optional","Path","to","a","key","file","for","the","scheduler",",","encoded","in","PEM","format",".","Alternatively",",","the","key","may","be","appended","to","the","cert","file",",","and","this","parameter","be","omitted",".","tls_worker_cert",":","str",",","optional","Path","to","a","certificate","file","for","a","worker",",","encoded","in","PEM","format",".","tls_worker_key",":","str",",","optional","Path","to","a","key","file","for","a","worker",",","encoded","in","PEM","format",".","Alternatively",",","the","key","may","be","appended","to","the","cert","file",",","and","this","parameter","be","omitted",".","extra_conn_args",":","mapping",",","optional","Mapping","with","keyword","arguments","to","pass","down","to","connections","."]
code: def _get_tls_context(self, tls, purpose):
      if tls.get("ca_file") and tls.get("cert"):
          ca = tls["ca_file"]
          cert_path = cert = tls["cert"]
          key_path = key = tls.get("key")
  
          if "\n" in ca:
              ctx = ssl.create_default_context(
                  purpose=purpose, cadata=ca
              )
          else:
              ctx = ssl.create_default_context(
                  purpose=purpose, cafile=ca
              )
  
          # the _set_tls_version_field method enforces that
          # self.tls_min_version is TLSv1_2, or TLSv1_3
          _set_minimum_version(ctx, self.tls_min_version)
          if self.tls_max_version is not None:
              _set_maximum_version(ctx, self.tls_max_version)
  
          cert_in_memory = "\n" in cert
          key_in_memory = key is not None and "\n" in key
          if cert_in_memory or key_in_memory:
              with tempfile.TemporaryDirectory() as tempdir:
                  if cert_in_memory:
                      cert_path = os.path.join(tempdir, "dask.crt")
                      with open(cert_path, "w") as f:
                          f.write(cert)
                  if key_in_memory:
                      key_path = os.path.join(tempdir, "dask.pem")
                      with open(key_path, "w") as f:
                          f.write(key)
                  ctx.load_cert_chain(cert_path, key_path)
          else:
              ctx.load_cert_chain(cert_path, key_path)
  
          # Bidirectional authentication
          ctx.verify_mode = ssl.CERT_REQUIRED
  
          # We expect a dedicated CA for the cluster and people using
          # IP addresses rather than hostnames
          ctx.check_hostname = False
  
          if tls.get("ciphers"):
              ctx.set_ciphers(tls.get("ciphers"))
  
          return ctx
  
imports: from __future__ import annotations
  import datetime
  import os
  import ssl
  import sys
  import tempfile
  import warnings
  import dask
  from dask.widgets import get_template
label_desc: Use image node_id 9 for calling the Security obj's underlying member method code with example usage: obj._get_tls_context(tls, purpose) and returns: ctx