How to ensure directory path exists on symlinking in Chef? - symlink

Creating a symlink in Chef:
link "#{node[:tomcat][:home]}/webapps/myface.war" do
to "/srv/scafandru/current/myface.war"
end
fails, since at that time the parent directory is missing on the node.
In the link resource I couldn't see any attribute similar to the directory resource's recursive true, so my current approach is to ensure that the directory structure exists by running
directory "#{node[:tomcat][:home]}/webapps" do
recursive true
end
right before linking.
Is there any elegant way to encapsulate this behaviour inside the link resource?

Your solution is the best one if you don't want to write code.
If you are willing to have a better solution, you may extend the provider for link to add the recursive attribute.
To do that, you can refer to opscode documentation that states:
Extending An Existing Provider
If you'd like to write a LWP that
extends another provider class, you can accomplish that as a mixin,
which you would then place in a library under the library directory of
the cookbook using that extended class.
Your LWRP would then be written to include that library in the
provider implementation to get access to the extended core resource.
For an example, see the Transmission Cookbook, which includes a
transmission_torrent_file LWRP that allows you to download a file
via the BitTorrent protocol. This transmission_torrent_file LWRP are
an extension of the existing file and remote_file resources.

Related

I am looking for code policy enforcement tool for xml and Python

I have projects that are developed with xml and python code mostly (Odoo modules). There is a bit of .po files for translation and csv fields for data.
I would like to enforce specific policies in xml files, for example:
No duplicate id attributes.
A specific attribute must be present if child elements contain a specific tags.
On python, I want to enforce rules like:
Look for SQL queries, and make sure that they use specific parameter methods to prevent SQL injection
Follow a specific naming convention
Some attributes are required in classes that inherit a specific class
I hope that the idea is clear.
Is there any open source solution for this? Preferably linked with github and checks on every commit!
I found a python package made specifically for this, pylint-odoo, here.
It can also be installed with pip install pylint-odoo.
An example .pylintrc config file can be found at the web OCA module, here. They also have another file named .pylintrc-mandatory.
There is even a warning for duplicate xml id attribute W7902.

Shared libraries "vars" folder structure - can I add subfolders?

From Extending with Shared Libraries - Directory structure I created a shared library where I have multiple *.groovy files implementing global variables in the vars folder.
Can I add subfolders to vars to organize better my files? I tried, with no luck at the moment of consuming the global variable. Is there a specific syntax I need to use to reference a file in a subfolder? or subfolder are just not supported?
Unfortunately, no, you cannot. There is a declined improvement request at Jenkins' issue tracker. The given reason is that filenames are mapped directly to variable names.
Other approaches typical in Groovy like
evaluate(new File("../tools/Tools.groovy"))
do not work as well, because the Jenkins global vars files are not native Groovy code but processed.
However, there is something you can use to better organize helper functions for those which are not custom pipeline steps.
I have an includes.groovy file containing different functions like
def doSomething() {
}
def doSomethingElse() {
}
In a customPipelineStep.groovy file I can then access them with
def call() {
includes.doSomethingElse()
}
So includes works somehow like a namespace, and you could have multiple such utility files. They are no folders, but help organizing stuff.
Instead of defining custom steps in individual files, you could also group them together in files, but then you would have to wrap them in a script block within your pipeline to access them, as pointed out in the documentation. In the same way, include-functions are also publicly available in script-blocks, so be aware that they are not private.

Get content of module file from Ruby custom type in Puppet

I am currently writing a Ruby custom type for Puppet and I must load the content of a file which is located in the same module in the 'files' folder. Is there a function accessible from the provider that can give me the content of the file addressed by "puppet:///modules/my_module/test.yaml"?
I found a way to get it working... Is this a proper solution?
file = Puppet::Parser::Files.find_file("my_module/my_file",
Puppet::Module.find('my_module').environment)
File.open('/tmp/test', 'w') { |f| f.write(File.read(file)) }
No, I don't think there is.
The manifest of your module should take care of copying the file to the agent through a file resource, so that the provider can use it from a known location.
Functions run on the server, types in the agent. If you create a function that returns the content of the file at the server, using standard Ruby code, you could use that function to inject the value in your type.
There are some caveats about what you can do with functions though.

Utility Classes In Ruby on Rails

This is probably a stupid question, but I'm new to Ruby on Rails and I could use a little guidance. I want to have a helper/utility class that performs a group of network operations and returns results. Where do I put that class and how do I use it.
I've created network_helper.rb in my app/modulename/helpers directory. In my controller when I try to do
myNetworkHelper = ModuleName::NetworkHelper.new
results = myNetworkHelper.getResults
I get an error
undefined method `new' for MyModule::NetworkHelper:Module
I'm sure this is just a misunderstanding of how ruby on rails works. Can I get some clarification?
Would it be better to make this a class instead of a module and put it in libs? And can I add subfolders in libs and have them automatically loaded?
Lib or Classes
Little utility classes like this typically go in the lib folder, though some people prefer to create a folder called classes. Whichever you choose, make sure you import the folder in config/application.rb, as the lib folder is not autoloaded:
config.autoload_paths += %W(#{config.root}/lib)
Concerns
If instead of a utility class, you want to extend some of your models with reusable code, you may also wish to look at the new Rails 4 concerns folders which encourage you to extract reusable modules:
see: How to use concerns in Rails 4
To use new, the thing your calling it on must be a class, not a module. You're using a module. Change module to class in lib/utilities/network_utility.rb.
I cannot verify this at the moment, however I believe one place you can store your custom modules and classes is the lib directory. Alternatively, you should be able to store them in the app directory in the manner you have indicated by adding the following line to your environment.rb:
config.load_paths << File.join(Rails.root, "app", "modulename")
Also, check out Yehuda Katz's answer, which I think not only answers your question better, but also contains some very interesting and useful information and concepts relating to your situation. Hope that helps!
Add your class to app/lib folder instead of lib, so that you don't change autoload paths!
Explanations:
The accepted answer suggests adding the classes to lib.
But according to this discussion:
The lib folder does not belong to the autoload paths since Rails 3.
So it's discouraged to add lib under autoload path. Use app/lib instead.

How To Use Model Of Another Application in Codeigniter

I am working on a project where I create Two Application hosted in same site.
My structure is given below…
SITE
SYSTEM
APPLICATION
font_end
back_end
Now my question is,is it possible to access model of one application from another application.
As example, I have a model named ‘User_model’ in font_end application. Is it possible to use this model from back_end application.
Thanks.
Yes, it is possible, but there is a but. It doesn't matter where your files are in an absolute sense, but it is not necessarily the easiest thing in the world to accomplish.
Your best bet is to use symlinks if you can and link them into a sub-directory of your models directory. This would be simple and clean.
Barring that, you should extend Loader and overwrite the &model method to look in the secondary directory (perhaps reassign $path to the alternate application's model folder if $path == 'frontend').
If that also isn't an option, loading is done through APPPATH.'models/'.$path . '/' .$model.EXT. This means you can access the model by the relative path to APPPATH.'models/'. Don't do that if you can possibly avoid it, however. It is non-obvious and an invitation to errors.
I tried your last version (error prone I know) and got this result:
Unable to locate the model you have specified: ext.
I used this load code to access the frontend model from my backend:
$this->load->model('APPPATH.'/models/frontend/'Frontend_Model'.'EXT');
apppath and ext constants should be used like variables, but if I put it this way my notepad ++ highlighting goes wrong:
$this->load->model(APPPATH.'/models/hp/'Homepage_Model'.EXT)
admin/application/model/accounts_model.php
application/controller/home.php
Put this code in home.php to use model of admin applicaton
$this->load->model('../../../Unicorn/application/models/accounts_model');

Resources