Skip to main content

¡Conecta a los Microservicios de CodeFlex desde una Sola Librería!

Project description

MIT License


Logo

CODEFLEX CLOUD S.A.S | DIAN

Codificación y Almacenamiento Simplificados | IDE
Explore the docs »

About The Project

miniatura

Installation

pip install codeflexDian

Usage

  • Example 1 | Lambda Function | GetNumberingRange
    import lxml.etree as ET
    from codeflexDian.SOAPSing import SOAPSing
    from codeflexDian.Signing import Signing
    import boto3
    import os
    from string import Template
    
    def lambda_handler(event, context):
    
      # VARIABLES
      ProviderSub = event['ProviderSub']
      accountCode = event['accountCode']
      accountCodeT = event['accountCodeT']
      softwareCode = event['softwareCode']
      
    
      s3subir = boto3.client('s3')
      s3 = boto3.resource('s3')
    
      pathCert = "/tmp/" + ProviderSub + "/certificado.pfx"
      pathClave = "/tmp/" + ProviderSub + "/clave.txt"
      
      metodo = "GetNumberingRange"
    
      # CREA DIRECTORIO DE TRABAJO SI NO EXISTE
      directory = "/tmp/" + ProviderSub
      if not os.path.exists(directory):
          os.makedirs(directory)
      
      # Descarga el certificado
      s3.Bucket(ProviderSub).download_file("certificado.pfx", pathCert)
      
      # Descarga la clave
      s3.Bucket(ProviderSub).download_file("clave.txt", pathClave)
      
      # Lee la clave
      with open(pathClave) as f:
          passwordCert = f.readline().strip()
    
      # Si la clave es NA entonces la clave será un blanco
      if (passwordCert == "NA"):
          passwordCert = ""
      
      signing = Signing(pathCert, passwordCert)
      signer = SOAPSing(signing, metodo)
      template = Template('''<wcf:GetNumberingRange xmlns:wcf="http://wcf.dian.colombia"><wcf:accountCode>${accountCode}</wcf:accountCode><wcf:accountCodeT>${accountCodeT}</wcf:accountCodeT><wcf:softwareCode>${softwareCode}</wcf:softwareCode></wcf:GetNumberingRange>''')      
      value = {
          'accountCode': accountCode,
          'accountCodeT': accountCodeT,
          'softwareCode': softwareCode
      }
      templateOk = template.substitute(value)
      element = ET.fromstring(templateOk)
      soapSigned = signer.sing(element)
      soapSingedStrin = ET.tostring(soapSigned)
    
      # Escribe Request firmado en /tmp
      open('/tmp/'+ProviderSub+'/'+'RANGOS-SIGN.xml', 'wb').write(soapSingedStrin)
      
      # Sube Request firmado de /tmp a s3
      s3subir.upload_file('/tmp/'+ProviderSub+'/'+'RANGOS-SIGN.xml', ProviderSub, 'RANGOS-SIGN.xml')
      
      # Retorno de información de destino
      return {
          'ProviderSub': event['ProviderSub'],
          'ProviderEmail': event['ProviderEmail']
      }
    

For more examples, please refer to the Documentation

CODEFLEX CLOUD S.A.S.

License

Distributed under the MIT License. See LICENSE for more information.

Contact

Telefono: +57 3008130562 | Email: info@codeflex.com.co

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

codeflexdian-1.1.0.tar.gz (10.2 kB view details)

Uploaded Source

Built Distribution

codeflexDian-1.1.0-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file codeflexdian-1.1.0.tar.gz.

File metadata

  • Download URL: codeflexdian-1.1.0.tar.gz
  • Upload date:
  • Size: 10.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.9

File hashes

Hashes for codeflexdian-1.1.0.tar.gz
Algorithm Hash digest
SHA256 f082d64ab0e91f8d13e8b2b491a9ecdc56920e321f03e264a7eb2d7530622b39
MD5 183ed44481988f35191efeaca1636c1d
BLAKE2b-256 728e4dcaed0e3889d707c784ce967e18f466f6f8398daff9adbda7211bc1578a

See more details on using hashes here.

File details

Details for the file codeflexDian-1.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for codeflexDian-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3558729d35a0fd1c8ad39b69445b4e27c54882424238855141c87e573c4781dc
MD5 2ff4cd16265e2d36741dc173e1783b68
BLAKE2b-256 2d30a1e25f7b03547935a905d3dc74c45f3b082572b8f4b19a93f444bec4fdae

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page