how to override host at Amazon S3 client? - php

im using symfony2 as framework form my application, i want to connect to my ceph client as it is said in API (same as amazon s3).
composer.json:
"knplabs/knp-gaufrette-bundle": "dev-master",
"aws/aws-sdk-php": "*",
"amazonwebservices/aws-sdk-for-php": "*"
im using gaufrette bundle to manage my filesystem
what i got so far is:
config.yml
mydrive.aws_s3.client:
class: Aws\S3\S3Client
factory_class: Aws\S3\S3Client
factory_method: 'factory'
arguments:
-
key: %my_drive_s3_key%
secret: %my_drive_s3_secret_key%
region: %my_drive_s3_region%
knp_gaufrette:
adapters:
my_drive_s3_v2:
aws_s3:
service_id: 'mydrive.aws_s3.client'
bucket_name: '%my_drive_s3_bucket_name%'
options:
create: true
directory: '%my_drive_s3_directory%'
filesystems:
user_fs:
adapter: my_drive_s3_v2
alias: my_drive_filesystem
stream_wrapper:
protocol: data
so following the api's this is the way i'm connecting to amazon s3 serwers
but im not using amazon s3 serwers im using my own ceph serwers.
and my question is how i change the host in amazon s3 client ?
now it's like this:
[curl] 56: Problem (2) in the Chunked-Encoded data [url] https://mybucket.s3.amazonaws.com
and i want this
https://mybucket.s3.amazonaws.com to be https://mybucket.s3.custom.com
here is the api i followed: https://github.com/KnpLabs/KnpGaufretteBundle#awss3

Try setting the base_url parameter.
config.yml
mydrive.aws_s3.client:
class: Aws\S3\S3Client
factory_class: Aws\S3\S3Client
factory_method: 'factory'
arguments:
-
key: %my_drive_s3_key%
secret: %my_drive_s3_secret_key%
region: %my_drive_s3_region%
base_url: https://mybucket.s3.custom.com
Please check the AWS SDK for PHP User Guide to see all of the client configuration options.

Related

Symfony Redis keeps connecting to localhost instead of defined host in env file

We have a new Symfony setup with Redis as cache mechanism. We want to connect to a specific host, not the default localhost. On production, the ./bin/console debug:dotenv gives the correct REDIS_HOST. This is configured in our .env and .env.local.php.
The error we get is:
Connection refused: tcp:127.0.0.1/6379
This is our config:
services.yml
services:
Redis:
# you can also use \RedisArray, \RedisCluster or \Predis\Client classes
class: \Predis\Client
calls:
- connect:
- '%env(REDIS_HOST)%'
- '%env(int:REDIS_PORT)%'
Symfony\Component\HttpFoundation\Session\Storage\Handler\RedisSessionHandler:
arguments:
- '#Redis'
- prefix: sp_ss_
- ttl: 1800
cache.yml
framework:
cache:
app: cache.adapter.redis
default_redis_provider: 'Redis'
pools:
site.cache:
adapter: cache.app
And our .env file:
APP_ENV=prod
APP_SECRET=****
MESSENGER_TRANSPORT_DSN=redis://redis.local:6379/messages
REDIS_HOST=redis.local
REDIS_PORT=6379
REDIS_URL=redis://redis.local:6379
The Symfony's documentation suggest to use "calls -> connect", but it's used only when you was defined the class as 'Redis'. When you use '\Predis\Client', you need to use the settings bellow:
"config/services.yaml"
Redis:
# you can also use \RedisArray, \RedisCluster or \Predis\Client classes
class: \Predis\Client
# See all parameters here: https://github.com/predis/predis/wiki/Connection-Parameters#list-of-connection-parameters
arguments:
- host: '%env(REDIS_HOST)%'
- port: '%env(int:REDIS_PORT)%'
# uncomment the following if your Redis server requires a password
# - password: '%env(REDIS_PASSWORD)%'
I'm also using the '\Predis\Client' and after to change to 'arguments' the connection was worked here.
For more parameters references, please check this link (List of connection parameters).
There might be hidden other .env files. May you check out the files list with the following code at the root of your projects? Are there other env files such as .env.prod, .env.local?
ls -lah

Configure Monolog to send GELF via TCP in Symfony 4

I have the following configuration in my monolog.yaml file:
monolog:
handlers:
main:
type: stream
path: "php://stdout"
level: debug
channels: ["!event"]
gelf:
type: gelf
publisher:
hostname: mygelfhost.com
port: 12201
console:
type: console
process_psr_3_messages: false
channels: ["!event", "!doctrine", "!console"]
But it only sends messages to mygelfhost.com using UDP. When I tried to put:
hostname: tcp://mygelfhost.com
I receive the following error:
Failed to create socket-client for udp://tcp://log-dev.hpa.lis-dev.net:12201: php_network_getaddresses: getaddrinfo failed: Name or service not known (0)
My goal is to send the logs via TCP to the same host, I have checked the configuration here: https://github.com/symfony/monolog-bundle/blob/master/DependencyInjection/Configuration.php#L25 with no possible solution.
Building off of #Chase's answer:
monolog:
handlers:
gelf:
type: gelf
publisher: my_tcp_gelf_publisher
The difference above is my_tcp_gelf_publisher is a Publisher object, not a Handler object. You want to tell the handler, which publisher to use "my_tcp_gelf_publisher", since that's what's being defined in services.yaml
In services.yaml:
services:
my_tcp_gelf_publisher:
class: Gelf\Publisher
arguments: ["#gelf.tcp_transport"]
gelf.tcp_transport:
class: Gelf\Transport\TcpTransport
arguments:
- "mygelfhost.com" # Hostname
- 12201 #port
This is pretty much the same, except you'll need to put the #gelf.tcp_transport service reference in quotes, otherwise you'll get a scaler error.
A bonus tip, if by chance you decide to configure your transport to use port 12202 (Gelf\Transport\TcpTransport's SSL port) be sure to ensure your endpoint supports ssl and you provide the correctly configured SslOptions object, otherwise use standard port 12201 (or any other port).
You need to specify the transport for Gelf. By default it uses UDP.
monolog:
handlers:
gelf:
type: gelf
id: my_tcp_gelf_publisher
In your services:
services:
my_tcp_gelf_publisher:
class: Gelf\Publisher
arguments: [#gelf.tcp_transport]
gelf.tcp_transport:
class: Gelf\Transport\TcpTransport
arguments:
- "mygelfhost.com" # Hostname
- 12201 #port
Something like this should work, I havent tested the code though. Based on the defining a publisher and the config example from: https://github.com/bzikarsky/gelf-php

Missing region parameter in AWS S3?

I am implementing Amazon Web Services in my Symofony 3.4 project but when I trigger my testing url it throws:
Missing required client configuration options:
region: (string) A region configuration value is required.
My region is console is EU(Ireland) and I have checked documentation and put parameter by that.
This is my service.yml
demo_storage:
class: App\Service\S3\S3Service
arguments:
- "test.app" # Name of Bucket
- credentials:
key: "%amazon_key%"
secret: "%amazon_secret%"
region: "eu-west-1"
version: "2006-03-01"
public: true

Firebase on Symfony4

I use Firebase on my Symfony application.So, I install kreait/firebase-bundle but I don't know which file I can configure this bundle on symfony4.
This configuration:
kreait_firebase:
connections:
main:
host:
secret:
references:
users:
Which file I can use this configuration??
in the documentation packagist you can configure your settup in :
config/packages/firebase.yaml
thanks :)

Symfony 4: Reusable code in "src"

I'm trying to update a Symfony 3.4 application to Symfony 4. On my current applications I always share a local AdminBundle folder inside src. I know Symfony 4 recommends to be "bundle-less" now. But this AdminBundle is the base for most of my projects, and sometimes I make some updates to it that can be deployed to all my projects just pushing to the repository.
I tried to move by AdminBundle inside src but obviously that's not working. Could anyone detail the recipe or configuration needed to make this Bundle work under Symfony 4 in a generic way?
If this is not possible what's the best way to create a reusable code in symfony 4?
I'm currently using a similiar approach:
I've got a "CoreBundle" for shared Services, Entites, Subscribers etc under "src".
In order to make this usable i had to edit the following:
config/maker.yaml -> to use make:entity and create under CoreBundle
maker:
root_namespace: 'App\CoreBundle'
config/packages/doctrine.yaml modify -> to get the Entities from CoreBundle
orm:
auto_generate_proxy_classes: true
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
auto_mapping: true
mappings:
App:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/CoreBundle/Entity'
prefix: 'App\CoreBundle\Entity'
alias: App
config/services.yaml add -> to import all SymfonyLike Classes
###> CoreBundle ###
App\CoreBundle\:
resource: '../src/CoreBundle/*'
exclude: '../src/CoreBundle/{DependencyInjection,Entity,Model,Migrations,Tests}'
App\CoreBundle\Controller\:
resource: '../src/CoreBundle/Controller'
tags: ['controller.service_arguments']
###< CoreBundle ###
config/* add -> where i wanted to import a separate config file
imports:
- { resource: '../../src/CoreBundle/Resources/config/*.yaml' }

Categories