Uso servicio con Python

Los programas han sido implementados para python3 en la distribución Ubuntu.

Para instalar la librería python de esta versión que permite la conexión al servicio OpenCayle ejecute:

  • Instalación en Ubuntu
apt install python3-boto
  • Instalación en CentOS
yum install python-boto
  • Instalación en MacOS High Sierra y posteriores

Ejecutar en la terminal:

pkgutil --pkg-info=com.apple.pkg.CLTools_Executables | grep version

si no está instalado retorna “ No receipt for 'com.apple.pkg.CLTools_Executables' found at '/'. “

Instalar Xcode por primera vez:

 xcode-select --install

Comprueba si está instalado Homebrew:

 which brew

Si no retorna nada, Homebrew no está instalado.

Instala Homebrew:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

Inserta el directorio Homebrew al principio del PATH:

export PATH="/usr/local/opt/python/libexec/bin:$PATH"

Instala python3:

brew install python3

Comprueba la versión de Python:

python3 --version

Si retorna Python 3.X.X Python3 se ha instalado en tu equipo.

Instala la librería de compatibilidad six de python para ejecutar el script de OpenCayle:

pip install six

Instala la librería boto 2 (la prueba de la conexión funciona con la librería boto 2):

pip install boto

Programa: s3CheckConnection.py (para descargar el archivo botón derecho guardar como extensión .py).
Parámetros:

  • AccessKey : Token to connect to OpenCayle service

Ejecución con AccessKey erróneo:

python3 s3CheckConnection.py failedtoken
    The connection to OpenCayle service is not possible.
    Please, check the following issues to solve it before connect to Scayle:
    1) You have internet access
    2) Your internet access is not through a VPN
    3) When you generate the access key the USERID and PASSWORD were correct
    4) Your IP internet address is available on OpenCayle service

Ejecución con AccessKey correcto:

python3 s3CheckConnection.py XXXX  (Where XXX is the correct AccessKey for the user)
    Your AccessKey connects successfully to OpenCayle.

Programa: s3CreateBucket.py (para descargar el archivo botón derecho guardar como extensión .py).
Parametros:

  • Access Key: Token to connect to OpenCayle service.
  • Bucket Name: The name associated to the new bucket.

Ejecución con AccessKey erróneo:

python3 s3CreateBucket.py XXerrXX buckecillo

    !!! WARNING Bucket pepe can not be created. 
    Review S3ResponseError: 403 Forbidden
    <?xml version="1.0" encoding="UTF-8"?><Error><Code>AccessDenied</Code><RequestId>tx000000000000000296bd3-005ee33619-cbcb5-default</RequestId><HostId>cbcb5-default-default</HostId></Error> log information. 
    Please attention to field CODE if exists. 
    When CODE is AccessDenied then Connection to OpenCayle can not be done, please review 
    your AccessKey:
    1) Run program s3AccessKey.py
    2) Run program s3CheckConnection.py
    If problem persists then contact to Scayle through HelpDesk tool.

Ejecución cuando se ha excedido el número de buckets:

python3 s3CreateBucket.py XXXX  buckecillo
    PARAMETERS: Access Key <XXXX Bucket <buckecillo>.
    !!! WARNING Bucket buckecillo can not be created.
    Review S3ResponseError: 400 Bad Request
    <?xml version="1.0" encoding="UTF-8"?><Error><Code>TooManyBuckets</Code><BucketName>buckecillo</BucketName><RequestId>tx00000000000000000472c-005e6a087f-196c5-default</RequestId><HostId>196c5-default-default</HostId></Error> log information.
    Please attention to field CODE if exists
    When CODE is AccessDenied then Connection to OpenCayle can not be done, please review your AccessKey:
    1) Run program s3AccessKey.py
    2) Run program s3CheckConnection.py
    If problem persists then contact to Scayle through HelpDesk tool.

Ejecución correcta:

python3 s3CreateBucket.py XXXX buckecillo
    PARAMETERS: Access Key XXXX Bucket <buckecillo>.
    Bucket buckecillo created successfully.

Programa: s3CreateKey.py (para descargar el archivo botón derecho guardar como extensión .py).
Parametros:

  • Access Key: Token to connect to OpenCayle service.
  • Bucket Name: The name associated to the bucket which contains the object.
  • Key Name: The name associated to the new object of the bucket.
  • File Name: Absolute path of file associated to key.
  • Is Private 0 Public /1 Private.
  • Expiration time: Time on seconds to expiration URL (Private mode).

Ejecución con AccessKey erróneo:

python3 s3CreateKey.py XXerrXX buckecillo pepe
    Connection to OpenCayle can not be done, please review your AccessKey:
    1) Run program s3AccessKey.py
    2) Run program s3CheckConnection.py
    If problem persists then contact to Scayle through HelpDesk tool.

Ejecución si el fichero no existe:

python3 s3CreateKey.py XXXXX buckecillo pepe xx.csv 0 280
    PARAMETERS: Access Key <XXXXX> Bucket Name <buckecillo> Key Name <pepe> File Name <xx.csv> Is Private (0 Not/1 Yes) <0> ExpirationTime (0 not expiration) <280>.
    File <xx.csv> does not exist. Key pepe can be created on bucket buckecillo

Ejecución para asignar una key a un bucket inexistente:

python3 s3CreateKey.py  XXXXX buckecillo pepe data.csv 0 280
    PARAMETERS: Access Key  <XXXXX> Bucket Name <buckecillo> Key Name <pepe> File Name <data.csv> Is Private (0 Not/1 Yes) <0> ExpirationTime (0 not expiration) <280>.
    Bucket, whose name is buckecillo, does not exist

Ejecución cuando se ha excedido cuota (espacio reservado para uso de servicio OpenCayle):

python3 s3CreateKey.py XXXXX buckecillo pepe /home/cephuser/data/data.csv 0 280
    PARAMETERS: Access Key <XXXXX> Bucket Name <buckecillo> Key Name <pepe> File Name </home/cephuser/data/data.csv> Is Private (0 Not/1 Yes) <0> ExpirationTime (0 not expiration) <280>.
    !!! KEY WARNING. Error during key pepe creation.  
    Error description S3ResponseError: 403 Forbidden
    <?xml version="1.0" encoding="UTF-8"?><Error><Code>QuotaExceeded</Code><BucketName>buckecillo</BucketName><RequestId>tx000000000000000004b06-005e6a1b18-196b3-default</RequestId><HostId>196b3-default-default</HostId></Error>.
    Review field CODE

Creacción correcta de key en bucket:

python3 s3CreateKey.py XXXXX buckecillo pepe /home/cephuser/data/data.csv 0 280
    PARAMETERS: Access Key <XXXXX> Bucket Name <buckecillo> Key Name <pepe> File Name </home/cephuser/data/data.csv> Is Private (0 Not/1 Yes) <0> ExpirationTime (0 not expiration) <280>.
    Key pepe on bucket buckecillo created on mode public-read and security False. If it is secure, its expiration time is 0.
    URL associated is: https://ss3.scayle.es:443/buckecillo/pepe
    Key pepe associated to Bucket buckecillo created successfully.

Go to your browser and navigate to the URL associated:  
    https://ss3.scayle.es:443/buckecillo/pepe
    * On Explorer and Firefox browser will appear a message whick ask you about open or save the file associated to the key
    * On Chrome the browser download the file and you can access to the file associated to the key on the download folder of the machine which is using the OpenCayle service.

Programa: s3DeleteKey.py (para descargar el archivo botón derecho guardar como extensión .py).

Parametros:

  • Access Key: Token to connect to OpenCayle service.
  • Bucket Name: The name associated to the bucket which contains the object.
  • Bucket Key: The name associated to the object to delete.

Ejecución con AccessKey erróneo:

python3 s3DeleteKeyt.py XXerrXX  buckecillo dolores
    Connection to OpenCayle can not be done, please review your AccessKey:
    1) Run program s3AccessKey.py
    2) Run program s3CheckConnection.py
    If problem persists then contact to Scayle through HelpDesk tool.

Ejecución errónea, intento de borrado de key en un bucket inexistente:

python3 s3DeleteKey.py XXXX  buckecillo pepe
    PARAMETERS: Access Key <XXXX> Bucket Name <buck> Key Name <pepe>.
    Bucket buckecillo or Key pepe associated to this bucket does not exist. Please review your S3 data.

Ejecución errónea, intento de borrado de key inexistente en un bucket existente:

python3 s3DeleteKey.py XXXX  buckecillo dolores
    PARAMETERS: Access Key <XXXX> Bucket Name <buckecillo> Key Name <dolores>.
    Bucket buckecillo or Key dolores associated to this bucket does not exist. Please review your S3 data.

Ejecución borrado key correcto (Key existe en bucket):

python3 s3DeleteKey.py XXXX  buckecillo pepe
    PARAMETERS: Access Key <XXXX> Bucket Name <buckecillo> Key Name <pepe>.
    Key pepe deleted from bucket buckecillo successfully

Programa: s3DeleteBucket.py (para descargar el archivo botón derecho guardar como extensión .py).
Parametros:

  • AccessKey : Token to connect to OpenCayle service.
  • BucketName: The name associated to the bucket to delete.

Ejecución con AccessKey erróneo:

python3 s3DeleteBucket.py XXerrXX  buckell
    Connection to OpenCayle can not be done, please review your AccessKey:
    1) Run program s3AccessKey.py
    2) Run program s3CheckConnection.py
    If problem persists then contact to Scayle through HelpDesk tool.

Ejecución errónea: Borrado bucket inexistente:

python3 s3DeleteBucket.py XXXXX  buckell
    PARAMETERS: Access Key  XXXXX Bucket <buckell>.
    Bucket buckell does not exist. Please review your S3 data

Ejecución borrado bucket con keys existentes:

Paso 1) Creamos una nueva key en el bucket.

python3 s3CreateKey.py XXXXX buckecillo lola /home/cephuser/data/data.csv 0 280
    PARAMETERS: Access Key <XXXXX> Bucket Name <buckecillo> Key Name <pepe> File Name </home/cephuser/data/data.csv> Is Private (0 Not/1 Yes) <0> ExpirationTime (0 not expiration) <280>.
    Key pepe on bucket buckecillo created on mode public-read and security False. If it is secure, its expiration time is 0.
    URL associated is: https://ss3.scayle.es:443/buckecillo/lola
    Key lola associated to Bucket buckecillo created successfully.

Paso 2) Borramos el bucket que tiene key asociada (key lola).

python3 s3DeleteBucket.py XXXXX buckecillo
    PARAMETERS: Access Key <XXXXX> Bucket <buckecillo>.
    Bucket buckecillo deleted successfully. All their keys were deleted previously

Programa: s3Resources.py (para descargar el archivo botón derecho guardar como extensión .py).
Parametros:

  • Access Key: Token to connect to OpenCayle service.

Ejecución con AccessKey erróneo:

python3 s3Resources.py  XX
    PARAMETERS: Access Key <XX>
-----------------------------------------------------------------------------------------
                         Open Scayle Resources associated to user.  
-----------------------------------------------------------------------------------------
    Connection to OpenCayle can not be done, please review your AccessKey:
    1) Run program s3AccessKey.py
    2) Run program s3CheckConnection.py
    If problem persists then contact to Scayle through HelpDesk tool.

Mostrar información para un usuario con datos de acceso incorrectos:

python s3Resources.py  XX
    PARAMETERS: Access Key <XX>
    boto.exception.S3ResponseError: S3ResponseError: 403 Forbidden
    <?xml version="1.0" encoding="UTF-8"?><Error><Code>AccessDenied</Code><RequestId>tx000000000000000004fbf-005e6a2b79-196b3-default</RequestId><HostId>196b3-default-default</HostId></Error>

Mostrar información para un usuario con datos de acceso correctos:

python s3Resources.py  XXXX
    PARAMETERS: Access Key <XXXX>
-----------------------------------------------------------------------------------------
                         OpenCayle Resources associated to user.  
-----------------------------------------------------------------------------------------
    - BUCKET bucket1 2020-03-12T12:22:39.216Z
      - OBJECT/KEY alejandra        2020-03-12T12:24:01.011Z
      - OBJECT/KEY alex     2020-03-12T12:23:53.648Z
    - BUCKET bucket2 2020-03-12T12:22:42.362Z
      - OBJECT/KEY juan     2020-03-12T12:23:28.295Z
      - OBJECT/KEY lola     2020-03-12T12:23:43.375Z
-----------------------------------------------------------------------------------------
                         END OpenCayle Resources