douglara / woofed-crm

137 stars 40 forks source link

Como configurar o storage para utilizar o S3 #411

Open GlauberF opened 2 months ago

GlauberF commented 2 months ago

Existe a posibilidade de configurar o crm para usar o storage S3 da aws ? Tentei com o código abaixo, mas não funciona e retorna o erro "Files Invalid files"

- ACTIVE_STORAGE_SERVICE=amazon
- S3_BUCKET_NAME=
- AWS_ACCESS_KEY_ID=
- AWS_SECRET_ACCESS_KEY=
- AWS_REGION=

O erro, acontece em varios formatos de arquivos, exemplo para a rota abaixo. POST /accounts/1/contacts/1/events?stage_id=1

Dados do envio

authenticity_token: vcGHvPy9...
event[kind]: note
event[from_me]: true
event[deal_id]: 1
event[contact_id]: 1
event[stage_id]: 
event[content]: <div>teste nota</div>
event[files][]: eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBEUT09IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--6cf462b0a1d77a246bc0fd498374304605ff4550
commit: Confirmar

Retorno com erro

Request URL: .../accounts/1/contacts/1/events?stage_id=1
Request Method: POST
Status Code: 422 Unprocessable Content
Remote Address: 54........:443
Referrer Policy:strict-origin-when-cross-origin

Config cors no S3

[
    {
        "AllowedHeaders": [
            "*"
        ],
        "AllowedMethods": [
            "PUT",
            "POST",
            "DELETE",
            "GET"
        ],
        "AllowedOrigins": [
            "https://.....com.br"
        ],
        "ExposeHeaders": [
            "Origin",
            "Content-Type",
            "Content-MD5",
            "Content-Disposition"
        ],
        "MaxAgeSeconds": 3600
    }
]
douglara commented 2 months ago

Olá GlauberF! Agradeço pelo seu feedback sobre o projeto Woofed.

Existem sim, segue os detalhes da documentação: https://docs.woofedcrm.com/docs/Developer%20Guides/Self%20hosted/Storage/supported-providers

Se as configurações estiverem de acordo favor encaminhar mais detalhes do erro como logs para conseguirmos analisar os detalhes.

Obrigado 🖖

GlauberF commented 2 months ago

Obrigado por responder @douglara, então, as configurações estao corretas, conforme primeira parte da issue e conforme a documentação que passou. Segue logs de erro.

Log de erro

I, [2024-09-18T19:35:05.725054 #1]  INFO -- : [8a983f29-2954-4ed1-bfcc-9f2d0dcd9f45] Started POST "/rails/active_storage/direct_uploads" for 177.221.165.100 at 2024-09-18 19:35:05 +0000
I, [2024-09-18T19:35:05.725731 #1]  INFO -- : [8a983f29-2954-4ed1-bfcc-9f2d0dcd9f45] Processing by ActiveStorage::DirectUploadsController#create as JSON
I, [2024-09-18T19:35:05.725779 #1]  INFO -- : [8a983f29-2954-4ed1-bfcc-9f2d0dcd9f45]   Parameters: {"blob"=>{"filename"=>"download.png", "content_type"=>"image/png", "byte_size"=>3470, "checksum"=>"PRAZ8SueUBEMofoHsQ6b9w=="}, "direct_upload"=>{"blob"=>{"filename"=>"download.png", "content_type"=>"image/png", "byte_size"=>3470, "checksum"=>"PRAZ8SueUBEMofoHsQ6b9w=="}}}
D, [2024-09-18T19:35:05.730499 #1] DEBUG -- : [8a983f29-2954-4ed1-bfcc-9f2d0dcd9f45]   TRANSACTION (0.7ms)  BEGIN
D, [2024-09-18T19:35:05.731733 #1] DEBUG -- : [8a983f29-2954-4ed1-bfcc-9f2d0dcd9f45]   ActiveStorage::Blob Create (0.9ms)  INSERT INTO "active_storage_blobs" ("key", "filename", "content_type", "metadata", "service_name", "byte_size", "checksum", "created_at") VALUES ($1, $2, $3, $4, $5, $6, $7, $8) RETURNING "id"  [["key", "t4lqiqkp2o5xyyg9eojl7f77rfru"], ["filename", "download.png"], ["content_type", "image/png"], ["metadata", nil], ["service_name", "amazon"], ["byte_size", 3470], ["checksum", "PRAZ8SueUBEMofoHsQ6b9w=="], ["created_at", "2024-09-18 19:35:05.729425"]]
D, [2024-09-18T19:35:05.734422 #1] DEBUG -- : [8a983f29-2954-4ed1-bfcc-9f2d0dcd9f45]   TRANSACTION (2.5ms)  COMMIT
D, [2024-09-18T19:35:05.737868 #1] DEBUG -- : [8a983f29-2954-4ed1-bfcc-9f2d0dcd9f45]   S3 Storage (2.8ms) Generated URL for file at key: t4lqiqkp2o5xyyg9eojl7f77rfru (https://--S3_BUCKET_NAME--.s3.sa-east-1.amazonaws.com/t4lqiqkp2o5xyyg9eojl7f77rfru?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=--AWS_ACCESS_KEY_ID--%2F20240918%2F--AWS_REGION--%2Fs3%2Faws4_request&X-Amz-Date=20240918T193505Z&X-Amz-Expires=3600&X-Amz-SignedHeaders=content-length%3Bcontent-md5%3Bcontent-type%3Bhost&X-Amz-Signature=e9cc633496aa4b575c6f9d8e97f0f6e2a5977ffdf5be556292f3e945802c525f)
I, [2024-09-18T19:35:05.738301 #1]  INFO -- : [8a983f29-2954-4ed1-bfcc-9f2d0dcd9f45] Completed 200 OK in 12ms (Views: 0.2ms | ActiveRecord: 4.1ms | Allocations: 2465)
I, [2024-09-18T19:35:07.839782 #1]  INFO -- : [eff154f1-2841-4587-9f11-eb0d155221d9] Started POST "/accounts/1/contacts/1/events?stage_id=1" for 177.221.165.100 at 2024-09-18 19:35:07 +0000
I, [2024-09-18T19:35:07.840477 #1]  INFO -- : [eff154f1-2841-4587-9f11-eb0d155221d9] Processing by Accounts::Contacts::EventsController#create as TURBO_STREAM
I, [2024-09-18T19:35:07.840533 #1]  INFO -- : [eff154f1-2841-4587-9f11-eb0d155221d9]   Parameters: {"authenticity_token"=>"[FILTERED]", "event"=>{"kind"=>"note", "from_me"=>"true", "deal_id"=>"1", "contact_id"=>"1", "stage_id"=>"", "content"=>"<div>teste</div>", "files"=>["eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBGZz09IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--3dde6bc103f17e7c7a08fd8244c668b473e7d978"]}, "commit"=>"Confirmar", "stage_id"=>"1", "account_id"=>"1", "contact_id"=>"1"}
D, [2024-09-18T19:35:07.842317 #1] DEBUG -- : [eff154f1-2841-4587-9f11-eb0d155221d9]   User Load (0.3ms)  SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT $2  [["id", 1], ["LIMIT", 1]]
D, [2024-09-18T19:35:07.843099 #1] DEBUG -- : [eff154f1-2841-4587-9f11-eb0d155221d9]   Account Load (0.2ms)  SELECT "accounts".* FROM "accounts" ORDER BY "accounts"."id" ASC LIMIT $1  [["LIMIT", 1]]
D, [2024-09-18T19:35:07.844640 #1] DEBUG -- : [eff154f1-2841-4587-9f11-eb0d155221d9]   CACHE Account Load (0.0ms)  SELECT "accounts".* FROM "accounts" ORDER BY "accounts"."id" ASC LIMIT $1  [["LIMIT", 1]]
D, [2024-09-18T19:35:07.844833 #1] DEBUG -- : [eff154f1-2841-4587-9f11-eb0d155221d9]   CACHE Account Load (0.0ms)  SELECT "accounts".* FROM "accounts" ORDER BY "accounts"."id" ASC LIMIT $1  [["LIMIT", 1]]
D, [2024-09-18T19:35:07.846110 #1] DEBUG -- : [eff154f1-2841-4587-9f11-eb0d155221d9]   Contact Load (0.3ms)  SELECT "contacts".* FROM "contacts" WHERE "contacts"."id" = $1 LIMIT $2  [["id", 1], ["LIMIT", 1]]
D, [2024-09-18T19:35:07.846835 #1] DEBUG -- : [eff154f1-2841-4587-9f11-eb0d155221d9]   Deal Load (0.3ms)  SELECT "deals".* FROM "deals" WHERE "deals"."id" = $1 LIMIT $2  [["id", 1], ["LIMIT", 1]]
D, [2024-09-18T19:35:07.849031 #1] DEBUG -- : [eff154f1-2841-4587-9f11-eb0d155221d9]   ActiveStorage::Blob Load (0.3ms)  SELECT "active_storage_blobs".* FROM "active_storage_blobs" WHERE "active_storage_blobs"."id" = $1 LIMIT $2  [["id", 17], ["LIMIT", 1]]
D, [2024-09-18T19:35:09.988987 #1] DEBUG -- : [eff154f1-2841-4587-9f11-eb0d155221d9]   Rendering layout layouts/internal.html.erb
D, [2024-09-18T19:35:09.989067 #1] DEBUG -- : [eff154f1-2841-4587-9f11-eb0d155221d9]   Rendering accounts/contacts/events/new.html.erb within layouts/internal
D, [2024-09-18T19:35:09.989490 #1] DEBUG -- : [eff154f1-2841-4587-9f11-eb0d155221d9]   CACHE Account Load (0.0ms)  SELECT "accounts".* FROM "accounts" ORDER BY "accounts"."id" ASC LIMIT $1  [["LIMIT", 1]]
D, [2024-09-18T19:35:09.990459 #1] DEBUG -- : [eff154f1-2841-4587-9f11-eb0d155221d9]   Pipeline Load (0.4ms)  SELECT "pipelines".* FROM "pipelines" WHERE "pipelines"."id" = $1 LIMIT $2  [["id", 1], ["LIMIT", 1]]
D, [2024-09-18T19:35:09.991045 #1] DEBUG -- : [eff154f1-2841-4587-9f11-eb0d155221d9]   CACHE Account Load (0.0ms)  SELECT "accounts".* FROM "accounts" ORDER BY "accounts"."id" ASC LIMIT $1  [["LIMIT", 1]]
D, [2024-09-18T19:35:09.991648 #1] DEBUG -- : [eff154f1-2841-4587-9f11-eb0d155221d9]   CACHE Account Load (0.0ms)  SELECT "accounts".* FROM "accounts" ORDER BY "accounts"."id" ASC LIMIT $1  [["LIMIT", 1]]
D, [2024-09-18T19:35:09.991926 #1] DEBUG -- : [eff154f1-2841-4587-9f11-eb0d155221d9]   CACHE Account Load (0.0ms)  SELECT "accounts".* FROM "accounts" ORDER BY "accounts"."id" ASC LIMIT $1  [["LIMIT", 1]]
D, [2024-09-18T19:35:09.993230 #1] DEBUG -- : [eff154f1-2841-4587-9f11-eb0d155221d9]   CACHE Account Load (0.0ms)  SELECT "accounts".* FROM "accounts" ORDER BY "accounts"."id" ASC LIMIT $1  [["LIMIT", 1]]
D, [2024-09-18T19:35:09.994066 #1] DEBUG -- : [eff154f1-2841-4587-9f11-eb0d155221d9]   Apps::Chatwoot Load (0.6ms)  SELECT "apps_chatwoots".* FROM "apps_chatwoots"
D, [2024-09-18T19:35:09.996122 #1] DEBUG -- : [eff154f1-2841-4587-9f11-eb0d155221d9]   CACHE Account Load (0.0ms)  SELECT "accounts".* FROM "accounts" ORDER BY "accounts"."id" ASC LIMIT $1  [["LIMIT", 1]]
D, [2024-09-18T19:35:09.996300 #1] DEBUG -- : [eff154f1-2841-4587-9f11-eb0d155221d9]   CACHE Apps::Chatwoot Load (0.0ms)  SELECT "apps_chatwoots".* FROM "apps_chatwoots"
D, [2024-09-18T19:35:09.997212 #1] DEBUG -- : [eff154f1-2841-4587-9f11-eb0d155221d9]   CACHE Account Load (0.0ms)  SELECT "accounts".* FROM "accounts" ORDER BY "accounts"."id" ASC LIMIT $1  [["LIMIT", 1]]
D, [2024-09-18T19:35:09.998523 #1] DEBUG -- : [eff154f1-2841-4587-9f11-eb0d155221d9]   Contact Load (0.8ms)  SELECT "contacts".* FROM "contacts" WHERE "contacts"."id" = $1 LIMIT $2  [["id", 1], ["LIMIT", 1]]
D, [2024-09-18T19:35:09.999263 #1] DEBUG -- : [eff154f1-2841-4587-9f11-eb0d155221d9]   Stage Load (0.2ms)  SELECT "stages".* FROM "stages" WHERE "stages"."id" = $1 LIMIT $2  [["id", 1], ["LIMIT", 1]]
D, [2024-09-18T19:35:09.999740 #1] DEBUG -- : [eff154f1-2841-4587-9f11-eb0d155221d9]   Rendered components/events/_drag_and_drop.html.erb (Duration: 0.1ms | Allocations: 58)
D, [2024-09-18T19:35:10.000012 #1] DEBUG -- : [eff154f1-2841-4587-9f11-eb0d155221d9]   Rendered components/events/form/_message_errors.html.erb (Duration: 0.2ms | Allocations: 156)
D, [2024-09-18T19:35:10.001234 #1] DEBUG -- : [eff154f1-2841-4587-9f11-eb0d155221d9]   Rendered components/events/form/_attachments.html.erb (Duration: 0.1ms | Allocations: 87)
D, [2024-09-18T19:35:10.001631 #1] DEBUG -- : [eff154f1-2841-4587-9f11-eb0d155221d9]   CACHE Account Load (0.0ms)  SELECT "accounts".* FROM "accounts" ORDER BY "accounts"."id" ASC LIMIT $1  [["LIMIT", 1]]
D, [2024-09-18T19:35:10.001836 #1] DEBUG -- : [eff154f1-2841-4587-9f11-eb0d155221d9]   Rendered components/events/form/_cancel_button.html.erb (Duration: 0.5ms | Allocations: 307)
D, [2024-09-18T19:35:10.002142 #1] DEBUG -- : [eff154f1-2841-4587-9f11-eb0d155221d9]   Rendered components/events/form/_note.html.erb (Duration: 2.6ms | Allocations: 2352)
D, [2024-09-18T19:35:10.002181 #1] DEBUG -- : [eff154f1-2841-4587-9f11-eb0d155221d9]   Rendered components/events/form/_deal.html.erb (Duration: 5.2ms | Allocations: 2998)
D, [2024-09-18T19:35:10.002245 #1] DEBUG -- : [eff154f1-2841-4587-9f11-eb0d155221d9]   Rendered components/events/_form.html.erb (Duration: 10.1ms | Allocations: 5197)
I, [2024-09-18T19:35:10.002390 #1]  INFO -- : [eff154f1-2841-4587-9f11-eb0d155221d9]   Rendered accounts/contacts/events/new.html.erb within layouts/internal (Duration: 13.2ms | Allocations: 6191)
D, [2024-09-18T19:35:10.003183 #1] DEBUG -- : [eff154f1-2841-4587-9f11-eb0d155221d9]   CACHE Account Load (0.0ms)  SELECT "accounts".* FROM "accounts" ORDER BY "accounts"."id" ASC LIMIT $1  [["LIMIT", 1]]
D, [2024-09-18T19:35:10.004722 #1] DEBUG -- : [eff154f1-2841-4587-9f11-eb0d155221d9]   CACHE Account Load (1.3ms)  SELECT "accounts".* FROM "accounts" ORDER BY "accounts"."id" ASC LIMIT $1  [["LIMIT", 1]]
D, [2024-09-18T19:35:10.004923 #1] DEBUG -- : [eff154f1-2841-4587-9f11-eb0d155221d9]   CACHE Account Load (0.0ms)  SELECT "accounts".* FROM "accounts" ORDER BY "accounts"."id" ASC LIMIT $1  [["LIMIT", 1]]
D, [2024-09-18T19:35:10.005072 #1] DEBUG -- : [eff154f1-2841-4587-9f11-eb0d155221d9]   CACHE Account Load (0.0ms)  SELECT "accounts".* FROM "accounts" ORDER BY "accounts"."id" ASC LIMIT $1  [["LIMIT", 1]]
D, [2024-09-18T19:35:10.005131 #1] DEBUG -- : [eff154f1-2841-4587-9f11-eb0d155221d9]   Rendered layouts/shared/_analytics_scripts.html.erb (Duration: 2.1ms | Allocations: 534)
D, [2024-09-18T19:35:10.005265 #1] DEBUG -- : [eff154f1-2841-4587-9f11-eb0d155221d9]   Rendered components/_flash_message.html.erb (Duration: 0.1ms | Allocations: 42)
D, [2024-09-18T19:35:10.005568 #1] DEBUG -- : [eff154f1-2841-4587-9f11-eb0d155221d9]   CACHE Account Load (0.0ms)  SELECT "accounts".* FROM "accounts" ORDER BY "accounts"."id" ASC LIMIT $1  [["LIMIT", 1]]
D, [2024-09-18T19:35:10.006358 #1] DEBUG -- : [eff154f1-2841-4587-9f11-eb0d155221d9]   CACHE Account Load (0.0ms)  SELECT "accounts".* FROM "accounts" ORDER BY "accounts"."id" ASC LIMIT $1  [["LIMIT", 1]]
D, [2024-09-18T19:35:10.007076 #1] DEBUG -- : [eff154f1-2841-4587-9f11-eb0d155221d9]   CACHE Account Load (0.0ms)  SELECT "accounts".* FROM "accounts" ORDER BY "accounts"."id" ASC LIMIT $1  [["LIMIT", 1]]
D, [2024-09-18T19:35:10.008485 #1] DEBUG -- : [eff154f1-2841-4587-9f11-eb0d155221d9]   CACHE Account Load (0.0ms)  SELECT "accounts".* FROM "accounts" ORDER BY "accounts"."id" ASC LIMIT $1  [["LIMIT", 1]]
D, [2024-09-18T19:35:10.009098 #1] DEBUG -- : [eff154f1-2841-4587-9f11-eb0d155221d9]   Rendered layouts/shared/_sidebar.html.erb (Duration: 3.8ms | Allocations: 2165)
D, [2024-09-18T19:35:10.009190 #1] DEBUG -- : [eff154f1-2841-4587-9f11-eb0d155221d9]   Rendered layouts/shared/_navbar.html.erb (Duration: 0.0ms | Allocations: 27)
I, [2024-09-18T19:35:10.009284 #1]  INFO -- : [eff154f1-2841-4587-9f11-eb0d155221d9]   Rendered layout layouts/internal.html.erb (Duration: 20.2ms | Allocations: 9837)
I, [2024-09-18T19:35:10.009470 #1]  INFO -- : [eff154f1-2841-4587-9f11-eb0d155221d9] Completed 422 Unprocessable Entity in 2169ms (Views: 17.1ms | ActiveRecord: 4.9ms | Allocations: 15209)
douglara commented 1 month ago

Tamo junto 👊

Você alterou os valores do log para não expor as informações? image image

GlauberF commented 1 month ago

Exato, @douglara. No lugar do valor, coloquei o nome da variável de ambiente que contém a informação que iria ali, com o intuito de não expor os dados. Seguindo o padrao --NOME_DA_ENV--

GlauberF commented 1 month ago

Consegue me ajudar @douglara ?