piątek, 28 stycznia 2022

Terraform, DigitalOcean, Failed to query available provider packages

There is slight chance that during getting started with Digital Ocean tutorial you encountered the following error
$ terraform init                

Initializing the backend...

Initializing provider plugins...
- Finding latest version of hashicorp/digitalocean...
│ Error: Failed to query available provider packages
The solution to that is deliver required_providers section into your main.tf
terraform {
    required_providers {
        digitalocean = {
            source = "digitalocean/digitalocean"
            version = ">= 2.4.0"
        kubernetes = {
            source = "hashicorp/kubernetes"
            version = ">= 2.0.0"
Now the terraform init command should be executed successfully

piątek, 14 stycznia 2022

Minikube - Failed to pull image - connection refused

Failed to pull image "nginx": rpc error: code = Unknown desc = Error response from daemon: Get "https://registry-1.docker.io/v2/": dial tcp: lookup registry-1.docker.io on read udp> read: connection refused
Below yuo can find a sequence of commands that worked for me. First go to minicube shell and try to re the registry-1.docker.io
$ minikube ssh
$ nslookup registry-1.docker.io
If it does not show the list of ips we've got the culprit.
$ su - root
# vi /etc/resolv.conf
# put a your favourite public DNS instead the one its defined
One extra thing you need to do is stop the systemd-resolved process
# systemctl stop systemd-resolved
Now there should fine, kuberetes will be able to download images.

wtorek, 29 grudnia 2020

How to setup php.ini for PHP develpement server

Php development server is excellent thing for quick development. But seems not very clear how to setup custom php parameters such as upload_max_filesize. Putting php.ini into main folder does not work for me, and even setting with ini_set failed. Desperatly I desided to read manual. Yes, sometimes it is worth do so ;>. But
/usr/local/Cellar/php/7.4.8/bin/php -S localhost:8081 -d upload_max_filesize=12M
And remember phpinfo() function is your friend. alternatively you can always set global value in the vi /usr/local/etc/php/7.4/php.ini file.

poniedziałek, 15 lipca 2019

Wiremock standalone - SLF4J: Failed to load logger implementation

Seems like `wiremock-standlone` comes without SLF4J implementation (?).
$ java -wiremock-standalone-2.23.2.jar com.github.tomakehurst.wiremock.standalone.WireMockServerRunner --proxy-all="http://localhost:8090" --verbose
2019-07-15 11:41:35.091 Verbose logging enabled
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
2019-07-15 11:41:35.650 Verbose logging enabled
Let's fix it by adding simple implementation on the classpath:
$ java -cp ~/.m2/repository/org/slf4j/slf4j-simple/1.7.12/slf4j-simple-1.7.12.jar:wiremock-standalone-2.23.2.jar \
  com.github.tomakehurst.wiremock.standalone.WireMockServerRunner \
  --proxy-all="http://localhost:8090" \
  --port 0 \
  --verbose \

czwartek, 15 listopada 2018

How to install SSL certificate in java keystore

The Problem:

After adding maven repository secured with https protocol the following error appeared:

sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.
certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
But how to get the certificate and make java can find it? Step 1. Fetching the certificate
echo | openssl s_client -showcerts -connect nexus:443 2>/dev/null | \
 awk '/-----BEGIN CERTIFICATE-----/, /-----END CERTIFICATE-----/' > nexus.crt
Step 2. Find out where the java keystore is located The following command will show java home dir
$ /usr/libexec/java_home
The keystore is jre/lib/security/cacerts file. Step 3. Install the certificate with keytool command
sudo keytool -importcert -alias nexus01 -keystore /Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home/jre/lib/security/cacerts -file nexus.crt 
Hint: use changeit or changeme as a default password. Step 4. Verify your certificate is on the list
$ keytool -list -keystore /Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home/jre/lib/security/cacerts | grep nexus01
nexus01, Nov 15, 2018, trustedCertEntry, 

środa, 14 lutego 2018

Spring MVC - Redirect 404 when Optional.empty returned

Optional returned from controllers method

If you need to show 404 error page when no object found in your backend you can think of returning Optional from the controller's method and may expect Spring MVC takes care of exposing the value if present and throws 404 if empty.


The mechanism of controller advice comes to play. We can create a class that will be used to modify controller responses.

There are actually two features used:

  • @ExceptionHandler which is used for translation exceptions into 404 error response
  • ResponseBodyAdvice interface which cause body will be processed before been returned from controller endpoint.

Here you are piece of code that should gather above mentioned into one universal class

public class OptionalResponseControllerAdvice implements ResponseBodyAdvice {

 public boolean supports(MethodParameter returnType, Class converterType) {
  return returnType.getParameterType().equals(Optional.class);

 public Object beforeBodyWrite(Object body, MethodParameter returnType, MediaType selectedContentType,
   Class selectedConverterType, ServerHttpRequest request, ServerHttpResponse response) {
  if (returnType.getParameterType().equals(Optional.class)) {
   return ((Optional<?>) body).orElseThrow(() -> new NotFoundException("No object found: " + request.getURI()));
  return body;

 public ResponseEntity<Map<String, Serializable>> handle(NotFoundException e) {
  return ResponseEntity.status(HttpStatus.NOT_FOUND).body(e.getMessage());


wtorek, 13 lutego 2018

Angular 5 and underscore library

Are you missing the underscore library in your most recent Angular 5 project?

It is easier than you may think - the only you need to do is just add two dependencies to your package.json file.

Step 1. Install dependencies

You can do this with npm command.

npm install --save @types/underscore
and next
npm install --save underscore

Step 2. Use it

In order to use underscore library in your component or service class you have to import library in the following way:
import * as _ from "underscore";
That is basically all - now you can take all the goodies from underscore. For example, to fetch all unique key values from an array of key-value struct we can do this way:
public uniqueKeys(input: {[key: string]: string}[]): string[] {

   let keys = _
     .map(a => _.keys(a))