I had given application.yml like below
spring:
datasource:
driverClassName: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost:3306/user
username: root
password: abc123
jpa:
hibernate.ddl-auto: update
generate-ddl: true
show-sql: true
But I am getting
Failed to configure a DataSource: 'url' attribute is not specified and
no embedded datasource could be configured.
Help me to sort out this.
change the name of your database, 'user' is a reserved keyword!!!
Related
When creating a publicly accessible Amazon MQ instance (with RabbitMQ under the hood), I can easily log in to the web console.
However when creating an MQ instance using the same settings and credentials through CDK I can't log in to the web console. The only response from the RabbitMQ service is
{
"error": "not_authorised",
"reason": "Login failed"
}
The Cloudwatch logs indicate that the user was created, but also warn that the user tried to log in using invalid credentials:
2021-07-02 14:20:54.867 [info] <0.1474.0> Created user 'admin'
2021-07-02 14:20:55.587 [info] <0.1481.0> Successfully set user tags for user 'admin' to [administrator]
2021-07-02 14:20:56.295 [info] <0.1488.0> Successfully set permissions for 'admin' in virtual host '/' to '.*', '.*', '.*'
2021-07-02 14:26:14.529 [warning] <0.1639.0> HTTP access denied: user 'admin' - invalid credentials
The construction of the Broker looks like this:
private createMessageBroker(vpc: Vpc, stage: Stage) {
const password: Secret = new Secret(this, 'BrokerAdminPassword', {
generateSecretString: { excludePunctuation: true },
description: 'Password for the Message Broker User',
});
const user: CfnBroker.UserProperty = {
consoleAccess: true,
username: 'admin',
password: password.toString(),
};
new CfnBroker(this, 'TaskMessageBroker', {
autoMinorVersionUpgrade: true,
brokerName: 'MessageBroker',
deploymentMode: 'SINGLE_INSTANCE',
engineType: 'RABBITMQ',
engineVersion: '3.8.11',
hostInstanceType: 'mq.t3.micro',
publiclyAccessible: true,
users: [user],
logs: { general: true },
});
}
Try using the following instead when instantiating your UserProperty
const user: CfnBroker.UserProperty = {
consoleAccess: true,
username: 'admin',
password: password.secretValue.toString(),
}
I have a simple Ansible playbook to
Fetch a database connection config from an RestAPI,
Extract the config object from the payload,
Using the config JSON (as request body) to create a PUT request to another RestAPI.
At the 3rd stage I found that the database username and password combination is wrong. Later, while I print the outputs, I have found that the password has been replaced with a string named "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER".
After some googling, I found that this is a security feature by Ansible. Unfortunately, I haven't found any configuration or something like this to disable this feature. Is it possible to disable this feature? Or any other workaround?
---
- name: my-playbook
gather_facts: no
hosts: all
vars_files:
- secret
tasks:
- name: Fetch the config payload from the API
uri:
url: "{{get_config}}"
method: GET
user: "{{username}}"
password: "{{password}}"
validate_certs: no
return_content: yes
status_code: 200
body_format: json
register: config
- name: Extract the config object
set_fact:
config_raw: "{{ config.json | json_query(jmesquery) }}"
vars:
jmesquery: '{{name}}.config'
- name: print the config
debug:
msg: "{{config_raw}}"
- name: Creating object using config
uri:
url: "{{create_ocject}}"
method: PUT
user: "{{username}}"
password: "{{password}}"
validate_certs: no
body: "{{config_raw}}"
body_format: json
return_content: yes
status_code: 200
headers:
Content-Type: "application/json"
register: test_res
- name: output value
debug:
msg: "{{test_res.json}}"
In the following Ansible Playbook, I am trying to create a user's password using predefined variables from defaults/main.yml which in return calls password from vars/passwords.yml. this file will be vaulted later.
vars/passwords
---
passwords:
foobar:
password: pass1234
defaults/main.yml
users:
- username: foobar
group: barfoo
password: "{{passwords.foobar}}"
tasks/main.yml
- include_vars: passwords.yml
- name: Create user
user:
name: "{{item.username}}"
group: "{{item.group}}"
password: "{{item.password | password_hash('sha512') }}"
When I run this playbook, I get the following error:
ERROR:
{
"msg": "[{u'username': u'foobar',
u'group': u'barfoo',
u'password': u'{{passwords.username}}'}]: 'list object' has no attribute 'username'"
}
Any idea how can I achieve assigning a variable by referencing another one.
the first file you provided, has passwords as a list variable, while in your defaults/main.yml file you are expecting a dictionary variable (passwords.foobar).
please change 1st file contents to:
---
passwords:
foobar: pass1234
cant comment about the rest, it looks to me that the tasks/main.yml is missing a line, probably a line including with_items statement. I dont imply its a problem in your code, you just probably didn't paste all your code to this question.
With the current variables files (defaults and vars), the solution for me was to call the password for user bar using the username as a key. I currently have:
- include_vars: passwords.yml
- name: Create user
user:
name: "{{item.username}}"
group: "{{item.group}}"
password: "{{item.password | password_hash('sha512') }}"
the new defaults/main.yml will not have a password key/value:
users:
- username: foobar
group: barfoo
Now with vars/passwords.yml :
---
passwords:
foobar:
password: pass1234
I can edit my change my task to:
- include_vars: passwords.yml
- name: Create user
user:
name: "{{item.username}}"
group: "{{item.group}}"
password: "{{passwords[item.username].password | password_hash('sha512') }}"
This solved my problem, and allows me to vault passwords.yml.
Please let me know if you have any improvements or suggestions.
I have recently added a new database to my Symfony 3.3 application.
Then my services with injected entity manager are no longer working and return the following error:
Cannot autowire service "RouterBundle\Utils\RoutersUtils": argument
"$em" of method "__construct()" references class
"Doctrine\ORM\EntityManager" but no such service exists. Try changing
the type-hint to one of its parents: interface
"Doctrine\ORM\EntityManagerInterface", or interface
"Doctrine\Common\Persistence\ObjectManager".
So my config.yml file is now like :
# Doctrine Configuration
doctrine:
dbal:
default_connection: router
connections:
router:
driver: pdo_mysql
host: '%database_host%'
port: '%database_port%'
dbname: '%database_router_name%'
user: '%database_router_user%'
password: '%database_router_password%'
charset: utf8mb4
default_table_options:
charset: utf8mb4
collate: utf8mb4_unicode_ci
row_format: DYNAMIC
app:
driver: pdo_mysql
host: '%database_host%'
port: '%database_port%'
dbname: '%database_app_name%'
user: '%database_app_user%'
password: '%database_app_password%'
charset: utf8mb4
default_table_options:
charset: utf8mb4
collate: utf8mb4_unicode_ci
orm:
default_entity_manager: router
entity_managers:
router:
connection: router
mappings:
RouterBundle: ~
dql:
string_functions:
# Match agains should have the path to the Sha1 class created in the previous step
SHA1: RouterBundle\Extensions\Doctrine\Sha1
app:
connection: app
mappings:
AppBundle: ~
One of my service like :
<?php
namespace RouterBundle\Utils;
use Doctrine\ORM\EntityManager;
class RoutersUtils
{
protected $em;
public function __construct(EntityManager $em)
{
$this->em = $em;
}
...
and my services.yml ( I tried to add this arguments but doesn't work)
...
RouterBundle\Utils:
public: true
arguments:
- '#doctrine.dbal.router_connection'
...
Any idea how to inject the correct Entity Manager?
Can I also inject entity manager by default using the "default_entity_manager: router" parameters in teh config file ?
Thanks for the help !
Pierre
You cannot autowiring by using the EntityManagerInterface if you have many managers. You will have to pick the right manager in your service definition for each service.
RouterBundle\Utils:
$em: '#your_entity_manager_service'
PS : You should consider upgrading to sf3.4 as 3.3 is not maintenaited anymore. It also comes with local binding, which will be really useful for what you want to do.
See:
https://symfony.com/blog/new-in-symfony-3-4-local-service-binding
Hello everyone, I'm trying to have 2 entityManagers for one entity in Symfony4 but I have some trouble to do this.
When I persist an entity it works,(For example if have two entity Mananagers : Customer and Default ,when I use Customer or Default to persist) but when I want to use Repository, The first entity Managare in doctrine.yaml is always used.
I have to do this because I have 2 databases. One in internet and one inside my intranet that i have created and I search to do is that when the user click one button for example. It update the database on internet.
config/packages/doctrine.yaml
doctrine:
dbal:
default_connection: default
connections:
default:
driver: pdo_mysql
host: **************
port: 3306
dbname: intranetDb
user: **********
password: *****
charset: UTF8
customer:
driver: pdo_mysql
host: internetDb
port: 3306
dbname: *********
user: *********
password: *********
charset: UTF8
orm:
default_entity_manager: default
entity_managers:
default:
connection: default
auto_mapping: false
mappings:
Main:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity'
prefix: 'App\Entity'
alias: Main
customer:
connection: customer
auto_mapping: false
mappings:
Customer:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity'
prefix: 'App\Entity'
alias: Main
MyController.php
..
$drug = $this->getDoctrine()->getRepository(Drug::class,'customer')->findAll() ;
..
This code always give me the data inside of default and if I put customer first inside of orm the customer is always given.
Some help will be welcome because I have this problem in few days and I have no Idea to solve this(It's probably because of symfony version that I didn't found solution inside forum).
Thank you.(And sorry for my bad English)
You can get the repository from an entity manager, instead of getting it from the ManagerRegistry returned by getDoctrine().
Example:
[...]
$this->getDoctrine()->getManager('manager_name')->getRepository('class_name');
[...]