HOME BLOG

Archive for August, 2021

How to prevent web application from revealing git repository details

Posted on: August 21st, 2021 by Olu No Comments

Hi folks,

In this post I will discuss a security tip. If your web application uses Git for version control, then there would usually be a .git folder in the project’s root folder. Here’s a quick way to prevent users from accessing details under your .git folder from a web browser.

Implement a 404 redirect for any request starting with /.git.

If you use Apache web server and your project users a .htaccess file, you can do this by adding a simple rule to your .htaccess file as follows:

RedirectMatch 404 /\.git

That’s all for now. Happy software development.

How to get process id of last executed background process in Shell script

Posted on: August 10th, 2021 by Olu No Comments

Hi folks,

In this short post I will describe how to get the process id of the last process that was executed in the background.

You do that using the symbol $!

E.g. If you run the commands:

date &
echo $!

you will get an id like 12345 corresponding of the process id for the date command you ran in the background previously.

The process id of the last run background process could be very useful if you want to do things like killing the process when a certain condition is meant. For example, when deploying multicontainer pods in Kubernetes using the sidecar pattern, you may want to terminate the sidecar container once the main container’s process finishes. One way to do this is in the sidecar is to start the sidecar process in the background, fetch its process id, wait for a trigger file which will be written by main container to signal process completion, then kill the sidecar process once the trigger file is found.

See the article How to terminate a side-car container in Kubernetes Job [1] for details.

That’s all for now. Happy software development.

 

Reference

1. How to terminate a side-car container in Kubernetes Job https://cotton-ori.medium.com/how-to-terminate-a-side-car-container-in-kubernetes-job-2468f435ca99

2. Does $! mean something in shell scripting. Stackoverflow. https://stackoverflow.com/questions/18462916/does-mean-something-in-shell-scripting

How to add Search feature to your Dango app with Haystack and Solr

Posted on: August 4th, 2021 by Olu No Comments

Hi folks,

In this post I talk briefly about how you can add search functionality to your Django app. Why add search platforms like Solr, Elasticsearch,e tc. to your app? Because it makes it easier for users to find relevant information, especially when it may be resource-intensive to perform those searches with your database alone. There’s an interesting article on this topic: Solr and RDBMS: Designing your application for the best of both. https://lucidworks.com/post/solr-and-rdbms-the-basics-of-designing-your-application-for-the-best-of-both/. There are several search tools you can use including Solr, Sphinx, etc. let’s assume you want to use Solr.

There’s a modular library you can use called Haystack (https://django-haystack.readthedocs.io/en/master/toc.html). Haystack supports several search tools, including Solr, Elasticsearch, etc.

If you want to use Haystack with Solr, you’ll need to have Solr running first. You can install Solr on different platforms. Haystack config details are foundĀ  at https://django-haystack.readthedocs.io/en/master/tutorial.html#installation.

Details about installing Solr for use with Haystack can be found here https://django-haystack.readthedocs.io/en/master/installing_search_engines.html.

When you install and start Solr, you would usually want to create something called a core. You perform indexing in that core and perform your searches against the core. Multiple cores can be created on a single Solr instance. When referencing Solr in an application, you would usually use a url like http://127.0.0.1/solr/<yourcore>. Haystack provides management command for interacting building search index and updating search index. You can install Solr using a docker container. See https://hub.docker.com/r/geerlingguy/solr/.

That’s all for now. Till next time, happy software development.