Assigning a class to a custom stage (Puppet) - rvm

I'm working on my first Puppet file for provisioning a Vagrant setup, and I'm sort of stuck.
I'm using the RVM module to handle Ruby and RubyGem installations, but apparently they use their own custom stage called 'rvm-install' that runs BEFORE the main stage.
In order to get the dependencies for RVM installed (Package resources), I need to run them before the 'rvm-install' stage. I realized this means I need a custom stage to have run before that.
I've written this class that encompasses the things needing done...but I don't understand how to assign the class to a stage...the documentation at PuppetLabs didn't seem to cover how you're supposed to do it when you already have a block of stuff in the class.
class before-rm {
exec { "apt-get update":
command => "/usr/bin/apt-get update"
}
package { "libxml2":
ensure => present,
require => Exec['apt-get update']
}
package { "nodejs":
ensure => present,
require => Exec['apt-get update']
}
}
Any help would be greatly appreciated. This is how I've got the Stage defined in the same file:
# Custom stage!
stage { 'before-rvm':
before => Stage['rvm-install']
}
Stage['before-rvm'] -> Stage['rvm-install']

Normally you would instantiate the before-rm class like this for the main stage:
include before-rm
which is equivalent to
class { 'before-rm': }
To instantiate a class for another stage you can use the metaparameter (not a parameter of the class, of all classes in general) stage.
class { 'before-rm':
stage => before-rvm
}
Here is a link to this in the docs: http://docs.puppetlabs.com/puppet/2.7/reference/lang_run_stages.html#assigning-classes-to-stages

Related

how to using plugin with inherited auth as child of other plugin

for my application i want to write an "admin" plugin, named "db" with own auth-component. To manage acl i tried to implement ivanamat/cakephp3-aclmanager as part of my admin tool, because my app won't need user authentification, maybe later.
i load AclManager in plugins/db/Plugin.php
public function bootstrap(PluginApplicationInterface $app)
{
Configure::write('AclManager.aros', array('DbGroups', 'DbRoles', 'DbUsers'));
parent::bootstrap($app);
$app->addPlugin('AclManager', ['routes' => false]);
}
I set up Routing Rules in db/config/routes.php
Router::connect(
'db/acl',
['plugin' => 'AclManager', 'controller' => 'Acl', 'action' => 'index']
);
Router::connect(
'db/acl/:action/*',
['plugin' => 'AclManager', 'controller' => 'Acl']
);
And i set up Auth Configuration in plugins/db/Controller/AppController.php
It's loaded and aside a "Auth not found"-error it works, but this is my problem.
When i debug $this->Auth in app.local/db/ it's filled. But not when i debug in app.local/db/acl. even when i load this plugin in my plugin, it's using Base AppController, not Plugin AppController.
Is it possible to inherit auth from plugin to plugin or load plugins with parent-child-association?
You cannot change what a (controller) class inherits, that is compile time information, and once it's processed, it is what it is, the controller classes of the AclManager plugin do extend App\AppController.
There's lots of different ways to solve your problem, one would for example be to dynamically configure the authentication in your application's base App\AppController class, rather than in your Db plugin's Db\AppController class.
You can check the routing information whether it's a request for the Db plugin or the AclManager plugin, and only load the auth component in that case, something like this:
public function initialize()
{
if (in_array($this->request->getParam('plugin'), ['Db', 'AclManager'], true)) {
$this->loadComponent('Auth', [
// ...
]);
}
}
That way the Db and AclManager plugin controller classes will inherit the authenticaton setup while your main application and possible other plugins are being excluded.
ps. if you're just starting to implement authentication, then I'd strongly suggest that you try the new authentication and authorization plugins, they're much more versatile than the (deprecated) auth component!

Ninject intercept throwing error. Dynamic proxy

I have a class which I use to bootstrap.
as part of the object creation I use by convention to bind to interfaces.
All works OK until I try to add an interceptor.
public class ContainerBootstrapper : IDisposable
{
StandardKernel _c;
public ContainerBootstrapper()
{
_c =new StandardKernel();
_c.Bind(b => b.FromAssembliesMatching("Facade*.*").SelectAllClasses().BindDefaultInterfaces());
_c.Bind(b => b.FromAssembliesMatching("Object*.*").SelectAllClasses().BindDefaultInterfaces());
_c.Bind(b => b.FromAssembliesMatching("Logger*.*").SelectAllClasses().BindDefaultInterfaces());
//even using the built in ActionInterceptor like this:
_c.Intercept(c => true)
.With(new ActionInterceptor(invocation =>
Console.Write(invocation.Request.Method.Name)));
When this line is hit, I get an error - Error loading Ninject component IAdviceFactory
No such component has been registered in the kernel's component container.
Suggestions:
1) If you have created a custom subclass for KernelBase, ensure that you have properly
implemented the AddComponents() method.
2) Ensure that you have not removed the component from the container via a call to RemoveAll().
3) Ensure you have not accidentally created more than one kernel.
I have at the top:
using Ninject.Extensions.Conventions;
using Ninject.Extensions.Interception.Injection.Dynamic;
using Ninject.Extensions.Interception.Infrastructure.Language;
using Ninject.Extensions.Interception;
and used NuGet for packages. Tried both Dynamic Proxies and LinFu. Both gave same error.
Anyone have any ideas to try?
Thanks in advance.
Turns out that even though I had a reference to the project doing the bootstrapping and I thought all my dlls for ninject where being copied over automatically this was not the case. After moving them manually it worked.

Extending Laravel 5.1 Mess Detection the right way

Laravel 5.1 has only one built-in hardcoded Mess Detection, it searches to see if #package tag is the same with /namespace, like so:
preg_match('/namespace\ ' . self::REQUIRED_NAMESPACE . '\\\(.*);/isU', $content, $namespace);
preg_match('/\/*( )+#package\ (.*)[\r?\n]/isU', $content, $package);
if (!isset($namespace[1]) || empty($namespace[1])) {
continue;
}
I want to extend this to add multiple detection classes.
My folder structure currently looks like this:
Helpers >
Commands >
MessDetector >
Detector >
DetectorInterface.php
DetectorAbstract.php
PackageTagDetector.php
MessDetector.php
The file MessDetector is made as an Artisan Command, that means it extends \Illuminate\Console\Command
I have a config file called mess_detection.php which has the detection rules like so:
return [
'rules' => [
'\Helpers\Commands\MessDetector\PackageTagDetector' =>
[
'rule' => '/\/*( )+#package\ (.*)[\r?\n]/isU',
'path' => app_path(),
'info' => 'Checking for #package tag',
'error'=> 'Malformed or missing package tag'
]
]
];
But got stuck with figuring out how exactly to instantiate PackageTagDetector class in MessDetector class.
Any ideas design pattern wise?
Laravel has no built in mess detector.
Also checking if package tags matches the namespace is a custom convention, Laravel doesn't use package tags at all.
It seems like you are using a third party library?
I have made an abstract class and interfaces for every rule I needed.
Each rule had it's own class.
The rules extended the abstract and in the abstract most of the logic was used.
The rules themselves where stored in a config file, in the config file I also mentioned the class and class specific actions.

RquireJS with Module in TypeScript

I'm studing TypeScript and RequireJS.
I want to simple module require but module type information missing.
Is there smart solution in such situation?
requirejs(['backbone'], (Backbone) => {
// In this function.
// Backbone is 'any'
});
requirejs(['backbone'], (BackboneRef: Backbone) => {
// error : Type reference cannot refer to container
// 型参照でコンテナー 'Backbone' を参照できません。
});
To do so you need to do the following:
Download backbone.d.ts from https://github.com/borisyankov/DefinitelyTyped, the backbone.d.ts provides typescript strongly-typed interface, if you use IDE like Visual Studio, you can have all the intellisense support to Backbone
(Optional) Config backbone in RequireJS
In your TypeScript class, you can reference Backbone like the following
`
/// <amd-dependency path="backbone" />;
/// <reference path="path/to//backbone.d.ts" />;
export class YourModel extends Backbone.Model {
}
The amd-dependency tells the compiler how to reference backbone, so it would generate the correct define statement in JavaScript.
The reference provides a way to Backbone's definition for typed check.
Hope this helps! TypeScript eliminates the hell of writing long define or require js statement, which can be error-prone in situation where there are lots of dependencies.

Protractor and Typescript: Class defined in different file but the same module causes 'declaration exception'

I am completely confused what I am doing wrong here.
Say I have a test file 'SimpleTest.ts' containing the following:
/// <reference path="../otherdir/simpleclass.ts" />
module MyModule.SubModule {
describe("this test", () => {
var myObject: SimpleClass = new SimpleClass("");
it("doesn't even get here!", () => {
expect(myObject).toBeDefined();
});
});
}
The class here is defined in a different file, but in the same module, like this:
module MyModule.SubModule {
export class SimpleClass {
constructor(private myMember: string) {}
}
}
So both definitions reside in the same module. Typescript compiles fine, everything looks OK.
But when I start protractor (yes, I have configured 'specs:' path to the files correctly), it stops with the error
this test
encountered a declaration exception - fail
I know that I could get it to work by using module.export and require, but this is not a good solution.
First, I loose the type checking of typescript, when I use javascript 'require', and the type checking is one of the reasons why I'm using it in the first place.
Second, I think this is bad style to mix plain javascript into typescript code.
Any help would be appreciated!
Thanks in advance,
Regards,
Jörg
Stop using internal modules.
It honestly helped me a lot when trying to understand TypeScript.
My experiences with internal TypeScript modules are answered here
.
You can read the article of Steve Fenton here for more details.
I hope this is of any help still to you.