# Integração GCP Storage

## Configuração Google Cloud Platform Storage (GCP)

Para utilizar as funcionalidades de integração com GCP é necessário configurar uma variável de ambiente chamada "**googleCloudCredentials**".  Essa variável deverá conter o seguinte json *encodado* em *base64.*

Por exemplo, se tivermos o seguinte json: {"type":"TYPE","project\_id":"PROJECT\_ID","private\_key\_id":"PRIVATE\_KEY\_ID","private\_key":"PRIVATE\_KEY","client\_email":"CLIENT\_EMAIL","client\_id":"CLIENT\_ID","auth\_uri":"AUTH\_URI","token\_uri":"TOKEN\_URI","auth\_provider\_x509\_cert\_url":"AUTH\_PROVIDER\_X509","client\_x509\_cert\_url":"CLIENT\_X509","read\_bucket":"READ\_BUCKET","write\_bucket":"WRITE\_BUCKET","base\_path":"BASE\_PATH"}

Deveremos configurar a variável de ambiente como: \
'googleCloudCredentials=eyJ0eXBlIjoiVFlQRSIsInByb2plY3RfaWQiOiJQUk9KRUNUX0lEIiwicHJpdmF0ZV9rZXlfaWQiOiJQUklWQVRFX0tFWV9JRCIsInByaXZhdGVfa2V5IjoiUFJJVkFURV9LRVkiLCJjbGllbnRfZW1haWwiOiJDTElFTlRfRU1BSUwiLCJjbGllbnRfaWQiOiJDTElFTlRfSUQiLCJhdXRoX3VyaSI6IkFVVEhfVVJJIiwidG9rZW5fdXJpIjoiVE9LRU5fVVJJIiwiYXV0aF9wcm92aWRlcl94NTA5X2NlcnRfdXJsIjoiQVVUSF9QUk9WSURFUl9YNTA5IiwiY2xpZW50X3g1MDlfY2VydF91cmwiOiJDTElFTlRfWDUwOSIsInJlYWRfYnVja2V0IjoiUkVBRF9CVUNLRVQiLCJ3cml0ZV9idWNrZXQiOiJXUklURV9CVUNLRVQiLCJiYXNlX3BhdGgiOiJCQVNFX1BBVEgifQ=='

**Observações**:

* Há duas configurações de bucket: um para leitura do objeto e outra para escrita. Ou seja, se você deseja que o CESS apenas leia o arquivo armazenado no GC, deverá preencher a chave "read\_bucket"; Caso você deseja que o CESS escreva no bucket, deverá preencher a chave "write\_bucket". E, consequentemente, se deseja ler/escrever no GCP, deverá configurar ambas chaves.
* A chave "base\_path" do json é utilizado apenas para escrita dos objetos. Ou seja, se você deseja que no momento de escrita do objeto no bucket seja adicionado o prefixo "integracao\_cess/", precisa configurá-la. Então, se pedir para salvar o arquivo com o nome "cliente1.p7s", o objeto terá o seguinte nome: "integracao\_cess/cliente1.p7s". Caso não deseja o prefixo, basta deixá-lo em branco.

## CESS lendo do bucket

Para o CESS ler o arquivo original do bucket é necessário, além das configuração anterior, especificar duas chaves na criação da transação: "documents\_source" : "**GCP\_STORAGE**" e no documents\[] {**"data": "nome\_do\_objeto\_no\_bucket".**

Por exemplo, se deseja que seja assinado o arquivo chamado "meu\_arquivo.txt", então poderá utilizar o seguinte json como chamada:

```
{
	"certificate_alias": "",
	"type": "CAdEs-detached",
	"hash_algorithm": "SHA256",
	"documents_source": "GCP_STORAGE", //OBRIGATÓRIO
	"policy": "AD_RB",
	"checksum_algorithm": "SHA256",
	"mode": "sync",
	"documents": [
		{
			"id": "0",
			"data": "meu_arquivo.txt", //OBRIGATÓRIO
		}
	]
}
```

## CESS escrevendo no bucket

Para o CESS escrever o arquivo assinado no Google Cloud é necessário, além das configuração anterior, especificar duas chaves na criação da transação: "documents\_destination" : "**GCP\_STORAGE**" e no documents\[] {**"destination\_file\_name": "nome\_do\_objeto\_no\_bucket"** (opcional).

Por exemplo, se deseja que o arquivo assinado seja armazenado com o nome "minha\_assinatura.p7s", então poderá utilizar o seguinte json como chamada:

```
{
	"certificate_alias": "",
	"type": "CAdEs-detached",
	"hash_algorithm": "SHA256",
	"documents_source": "DATA_URL",
	"documents_destination": "GCP_STORAGE", //OBRIGATÓRIO
	"policy": "AD_RB",
	"checksum_algorithm": "SHA256",
	"mode": "sync",
	"documents": [
		{
			"id": "0",
			"data": "data:text/plain;base64,Y2xldWJlcl90ZXN0ZQ==",
			"destination_file_name": "minha_assinatura.p7s" //OPCIONAL
		}
	]
}
```

```
"documents": [
        {
            "id": "0",
            "original_file_name": null,
            "mediatype": "data:text/plain",
            "status": "SIGNED",
            "lifetime": 4000,
            "result": "https://www.googleapis.com/storage/v1/b/example_bucket/o/minha_assinatura.p7s",
            "destination_file_name": "minha_assinatura.p7s",
            "checksum": "7bc054878b0e646c18efb4c06d660c9890a1e89e"
        }
    ]
```

**Observação**:

* Caso não seja definido um valor para variável "destination\_file\_name", será gerado um aleatório com a seguinte lei de formação: <*ano>***/**<*mês>***/**<*dia>***/**<*timestamp>***\_**<*numeroAleatório8Dígitos>.* Por exemplo: 2020/07/10/1594398391\_dc80d9b0.
* Quando cliente optar pelo documents\_source DATA\_URL, FILE\_PATH, AWS\_S3 ou GCP\_STORAGE, deverá passar, caso queira especificar um nome para o objeto, o "destination\_file\_name" no mesmo nível do "id" e "data". Quando optar pelo UPLOAD\_REFERENCE, ele tem a opção de criar a chave "documents\[]" e passar o "id" e o "destination\_file\_name" no mesmo nível; pois quando realizar o upload via rota /file-transferer/\<tcn> ocorrerá o match entre o document\[id] e o id definido na chave "documents\[]' na criação da transação


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.vaultid.com.br/workspace/cess/api/integracao-gcp-storage.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
