How to purge directory with puppet and keep the dot files - puppet

Is there a way to purge the folder and keep the dotfiles? I'd like to purge the /root.
Something like:
file { '/root':
ensure => present,
owner => 'root',
group => 'root',
mode => 0550,
purge => true,
recurse => true,
}
file { '/root/.*':
ensure => present,
owner => 'root',
group => 'root',
}

Either go for the ignore param as h2ooooooo correctly stated.
You may find it cleaner to not recurse and use the tidy type and its matches parameter instead.
tidy { "/root": recurse => 1, matches => '[a-zA-Z0-9_]*' }

My final solution looks like this:
file { '/root':
ensure => present,
owner => 'root',
group => 'root',
mode => 0550,
purge => true,
recurse => true,
force => true,
ignore => ['.*',
'bullx_yum_install.log',
'install.log',
'install.log.syslog'],
}

Related

Magento 2 Multi select custom product attribute options not showing

In my custom module, used installData.php to create a custom multiselect attribute. Where i have set the option values from my source class (using Magento\Eav\Model\Entity\Attribute\Source\AbstractSource) which is working fine after installation. I can see the options while editing the product.
But the options are not visible while editing the attribute. Im not able to add/remove option after this.
Please advise.
$eavSetup->addAttribute(
\Magento\Catalog\Model\Product::ENTITY,
'my_option',
[
'group' => 'General',
'label' => 'My Label',
'type' => 'text',
'input' => 'multiselect',
'user_defined' => true,
'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
'source' => 'Vendor\Module\Model\Attribute\Source\Options',
'required' => false,
'filterable' => true,
'filterable_in_search' => true,
'is_searchable_in_grid' => false,
'is_used_in_grid' => false,
'is_visible_in_grid' => false,
'is_filterable_in_grid' => false,
'sort_order' => 200,
'used_in_product_listing' => true,
'backend' => 'Magento\Eav\Model\Entity\Attribute\Backend\ArrayBackend',
'visible' => true,
'visible_on_front' => true,
'searchable' => false,
'comparable' => false,
]
);
1. Create InstallData.php file at Vendor\Extension\Setup\ folder.
<?php
namespace Vendor\Extension\Setup;
use Magento\Eav\Setup\EavSetupFactory;
use Magento\Framework\Setup\InstallDataInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
class InstallData implements InstallDataInterface
{
private $eavSetupFactory;
public function __construct(EavSetupFactory $eavSetupFactory)
{
$this->eavSetupFactory = $eavSetupFactory;
}
public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
$setup->startSetup();
$eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
$eavSetup->addAttribute(
\Magento\Catalog\Model\Product::ENTITY,
'eway_option',
[
'group' => 'Groupe Name',
'label' => 'Multiselect Attribute',
'type' => 'text',
'input' => 'multiselect',
'source' => 'Vendor\Extension\Model\Config\Product\Extensionoption',
'required' => false,
'sort_order' => 30,
'global' => \Magento\Catalog\Model\ResourceModel\Eav\Attribute::SCOPE_STORE,
'used_in_product_listing' => true,
'backend' => 'Magento\Eav\Model\Entity\Attribute\Backend\ArrayBackend',
'visible_on_front' => false
]
);
$setup->endSetup();
}
}
2. Create Extensionoption.php file at Vendor\Extension\Model\Config\Product folder.
<?php
namespace Vendor\Extension\Model\Config\Product;
use Magento\Eav\Model\Entity\Attribute\Source\AbstractSource;
class Extensionoption extends AbstractSource
{
protected $optionFactory;
public function getAllOptions()
{
$this->_options = [];
$this->_options[] = ['label' => 'Label 1', 'value' => 'value 1'];
$this->_options[] = ['label' => 'Label 2', 'value' => 'value 2'];
return $this->_options;
}
}

Find key contain specific key value pair in Puppet Hash

I am still a beginner in Puppet. So please bear with me. Let's assume i have this hash created in Puppet through some module
account = {
user#desktop1 => {
owner => john,
type => ssh-rsa,
public => SomePublicKey
},
user#desktop2 => {
owner => mary,
type => ssh-rsa,
public => SomePublicKey
},
user#desktop3 => {
owner => john,
type => ssh-rsa,
public => SomePublicKey
},
user#desktop4 => {
owner => matt,
type => ssh-rsa,
public => SomePublicKey
}
}
How can i find find the key for specific key and value pair inside the hash? which in this case just for example i want to find all the key owned by john. So the expected result would be something like:
[user#desktop1, user#desktop3]
Thanks in advance
The question asks about how to do this in Puppet, although, confusingly, the Hash is a Ruby Hash and the question also has a Ruby tag.
Anyway, this is how you do it in Puppet:
$account = {
'user#desktop1' => {
'owner' => 'john',
'type' => 'ssh-rsa',
'public' => 'SomePublicKey',
},
'user#desktop2' => {
'owner' => 'mary',
'type' => 'ssh-rsa',
'public' => 'SomePublicKey',
},
'user#desktop3' => {
'owner' => 'john',
'type' => 'ssh-rsa',
'public' => 'SomePublicKey',
},
'user#desktop4' => {
'owner' => 'matt',
'type' => 'ssh-rsa',
'public' => 'SomePublicKey',
}
}
$users = $account.filter |$k, $v| { $v['owner'] == 'john' }.keys
notice($users)
Puppet applying that leads to:
Notice: Scope(Class[main]): [user#desktop1, user#desktop3]
https://ruby-doc.org/core-2.5.1/Hash.html#method-i-select
account.select {|key, value| value['owner'] == 'john'}.keys
Another option using Enumerable#each_with_object:
account.each_with_object([]) { |(k, v), a| a << k if v['owner'] == 'john'}
#=> ["user#desktop1", "user#desktop3"]
Supposing keys and values to be String.

lumen-passport Authentication - $request->user() not setting

I am struggling to login a user using lumen-passport. I have followed the instructions in the link I just supplied but cannot seem to set the user to use in the $request variable of via the Auth facade.
As long as I have my guard driver set to passport in auth.php I cannot get into this block inside AuthServiceProvider.php boot() method no matter what I seem to do:
Auth::viaRequest('api', function ($request) {
if ($request->input('api_token')) {
return User::where('api_token', $request->input('api_token'))->first();
}
});
But even if I try manually return a User record before that call the user is never set, and if I try the following:
Auth::setUser(User::where('id', 1);
I get this message:
InvalidArgumentException in AuthManager.php line 99:
Auth guard driver [api] is not defined.
My query above is definitely returning a record from the User table as well. It's just I cannot get around to setting it so I can access it in my application via the $request->user() method.
Any help would be greatly appreciated as this really has me puzzled. If it helps at all this is my auth.php config.
'defaults' => [
//'guard' => env('AUTH_GUARD', 'api'),
'guard' => 'api',
'passwords' => 'users',
],
'guards' => [
//'api' => ['driver' => 'api'],
'api' => [
'driver' => 'passport',
'provider' => 'users',
],
],
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => \App\User::class
]
],
'passwords' => [
//
],
];

CakePHP Bake Error: Database connection “Mysql” is missing, or could not be created

i just download the cakephp 2.5.1 extract and create a database.
now i am try to using cake bake but terminal showing that error (i am using ubuntu)
Error: Database connection “Mysql” is missing, or could not be created
also no issue with database connection.just tested with pages/index function. its working fine.
should i used empty table ? currently i am using current project database.
database.php
class DATABASE_CONFIG {
public $default = array(
'datasource' => 'Database/Mysql',
'persistent' => false,
'host' => 'localhost',
'login' => 'root',
'password' => '',
'database' => 'abcd',
'prefix' => 'lab_',
'encoding' => 'utf8',
);
public $test = array(
'datasource' => 'Database/Mysql',
'persistent' => false,
'host' => 'localhost',
'login' => 'user',
'password' => 'password',
'database' => 'test_database_name',
'encoding' => 'utf8',
);
}
Sql connect working fine ( find query result ) >
Thanks
update >
Connection, not database
The question is asking which database connection to use - not which database to use i.e.
Which of these to use?
public $default = array();
^ This one?
public $test = array();
^ Or this one?
Answering abcd will cause bake to look for and use public $abcd in the database config class - which evidently is misconfigured.
Try locating 'mysql.sock' and add the path (eg: /tmp/mysql.sock) of this file to the database config entry 'unix_socket'. so your database config looks like this:
public $default = array(
'datasource' => 'Database/Mysql',
'persistent' => false,
'host' => 'localhost',
'login' => 'root',
'password' => '',
'database' => 'abcd',
'prefix' => 'lab_',
'encoding' => 'utf8',
'unix_socket' => '/tmp/mysql.sock',
);

Different database instance in Kohana App and Module

I need to make an integration for my application with Wordpress. I have a module for that. But I need to use different database instances. In my App I use 'default' and in Wordpress module I want to use 'wordpress' database instance. How can I do that? Because Database::$default = 'wordpress' in modules\wordpress\init.php sets instances for Module and App.
If you have defined two database connections in your configuration files like this:
config/database.php (can be in APPPATH, MODPATH, etc.)
return array
(
'default' => array
(
'type' => 'mysql',
'connection' => array(
'hostname' => 'localhost',
'username' => 'dbuser',
'password' => 'mypassword',
'persistent' => FALSE,
'database' => 'my_db_name',
),
'table_prefix' => '',
'charset' => 'utf8',
),
'wordpress' => array(
'type' => 'mysql',
'connection' => array(
'hostname' => 'localhost',
'username' => 'other_user',
'password' => 'mypassword',
'persistent' => FALSE,
'database' => 'wordpress',
),
'table_prefix' => '',
'charset' => 'utf8',
),
);
then you can refer to them like this:
// This would connect to the database defined as 'default'
$default = Database::instance();
// This would connect to the database defined as 'wordpress'
$remote = Database::instance('wordpress');
If you are using the ORM module, you do it like this in each Model that uses the WordPress database:
protected String $_db_group = 'wordpress';
(Or, you can create an abstract class...
abstract class Model_WordPress extends ORM
{
protected String $_db_group = 'wordpress';
}
...and then have your WordPress Models extend Model_WordPress instead of directly from ORM. For example, class Model_WordPress_Post extends Model_WordPress ....)

Resources