Skip to content

Instantly share code, notes, and snippets.

View abhi2495's full-sized avatar
🏠
Working from home

Abhinaba Chakraborty abhi2495

🏠
Working from home
View GitHub Profile
Extract UserId , Password from connection string like this:
"Server=sampledb.database.windows.net;Database=dynamicpricing;User Id=dummyuser;Password=abcd"
userId=$(echo "${{ secrets.DATABASE_CONNECTION_STRING }}" | sed -n "s/^.*User\sId=\([^;]*\).*$/\1/p")
password=$(echo "${{ secrets.DATABASE_CONNECTION_STRING }}" | sed -n "s/^.*Password=\([^\"]*\).*$/\1/p")
----------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------
@abhi2495
abhi2495 / delete-blackduck-versions.sh
Created February 9, 2022 20:57
Shell Script to delete a bunch of blackduck versions for a given project id
#! /usr/bin/env bash
blackduckHostName="${1}"
blackduckApiKey="${2}"
blackduckProjectId="${3}"
BEARER_TOKEN_RESPONSE=$(curl -X POST -H "Content-Length: 0" -H "Authorization: token $blackduckApiKey" "$blackduckHostName/api/tokens/authenticate")
BEARER_TOKEN=$(echo $BEARER_TOKEN_RESPONSE | jq -r '.bearerToken')
PROJECT_VERSIONS_LIST_RESPONSE=$(curl -X GET -H "Authorization: Bearer $BEARER_TOKEN" "$blackduckHostName/api/projects/$blackduckProjectId/versions?limit=100")

Using @JsonDeserialize at Class Level.

For simple custom constraints (which do not make a DB call or need autowiring inside the validation class), please refer to here. This Gist is about how to make Database calls through autowired Spring JPA Repositories as part of the constraint validation.

Use Case:

  • My Table has 3 columns - id, role and user_id. Now there can be only 1 row for which role can take the value ROLE_ROOT. And once that record is inserted, it can't be updated.

How I am implementing:

A simple example to remove/manipulate json nodes is by using JsonPath

This gist describes usage of helm umbrella charts to manage deployment of multiple micro-services to kubernetes

Developers can maintain a separate Github repo for base helm charts.

A base-microservice chart will have all sorts of kubernetes templates like HPA,ConfigMap,Secrets,Deployment,Service,Ingress etc , each having the option to be enabled or disabled.

And the base chart can even contain other public charts as dependency.

Now in each microservice, we will have a dedicated chart defining a dependency of this base-microservice chart

Two approaches to handle error responses from Spring WebClient calls globally:

  • Exceptions with webclients are all wrapped in WebClientResponseException class. So we can handle that using Spring's ExceptionHandler annotation.

  • Using ExchangeFilterFunction while constructing the webclient bean.

A demo Java code using ExecutorService to perform two tasks in parallel and then return after both finish

A sample Integration Test for a reactive webapplication written using Spring WebFlux

An example demonstrating usage of Spring's @WebFluxTest in Junit Tests