Skip to content

Instantly share code, notes, and snippets.

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

unclebean

🏠
Working from home
View GitHub Profile
@unclebean
unclebean / h2
Last active October 16, 2024 03:32
maven local dependency
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>3.0.0-M1</version>
<executions>
<execution>
<id>install-jar</id>
<phase>validate</phase>
@unclebean
unclebean / gist:ae6ac6963bbbf444f627c35db0188383
Last active October 11, 2024 06:20
spn vs uami vs sami
| **Feature** | **Service Principal** | **System-Assigned Managed Identity (SAMI)** | **User-Assigned Managed Identity (UAMI)** |
|---------------------------------|--------------------------------------------------------------------|----------------------------------------------------------------------|----------------------------------------------------------------------|
| **Creation** | Created manually in Azure AD by registering an application. | Automatically created and managed by Azure for a resource. | Created manually and assigned to resources as needed. |
| **Assignment to Resources** | Can be assigned roles or permissions to access resources. | Tied to a single Azure resource (VM, App Service, etc.). | Can be shared and assigned to multiple resources. |
| **Lifecycle** | Sta
@unclebean
unclebean / yml
Created October 10, 2024 09:21
ci/cd
stages:
- build
- deploy
# Variables for your project
variables:
IMAGE_NAME: "registry.example.com/your-project/your-image" # Docker image path
DOCKER_TAG: "${CI_COMMIT_SHA:0:8}" # Tag Docker image with commit SHA
# Build and push Docker image
@unclebean
unclebean / maven-jar-plugin
Last active October 22, 2024 02:44
add repo config in pom
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>my-app</artifactId>
<version>1.0-SNAPSHOT</version>
<!-- Add repositories for dependencies -->
@unclebean
unclebean / AKS deployment
Created October 10, 2024 05:51
docker for AKS deployment
spec:
containers:
- name: your-app
image: your-app:dev
ports:
- containerPort: 8080
env:
- name: SPRING_PROFILES_ACTIVE
value: "dev"
<!-- Spring Cloud Azure Starter -->
<dependency>
<groupId>com.azure.spring</groupId>
<artifactId>spring-cloud-azure-starter</artifactId>
</dependency>
<!-- Azure Blob Storage -->
<dependency>
<groupId>com.azure.spring</groupId>
<artifactId>spring-cloud-azure-starter-storage-blob</artifactId>
import com.azure.identity.ManagedIdentityCredential;
import com.azure.identity.ManagedIdentityCredentialBuilder;
import com.azure.core.credential.TokenRequestContext;
import com.azure.core.credential.AccessToken;
public class AccessTokenFetcher {
public static void main(String[] args) {
// Define the resource you are requesting the token for (e.g., Azure Cognitive Search)
String resource = "https://search.azure.com/";
@unclebean
unclebean / check client id
Last active October 4, 2024 04:03
umi verify aks token
az identity show --name <umi-name> --resource-group <resource-group-name> --query clientId
ManagedIdentityCredential managedIdentityCredential = new ManagedIdentityCredentialBuilder()
.clientId("your-umi-client-id") // User Managed Identity Client ID
.build();
String token = managedIdentityCredential.getToken(
new TokenRequestContext().addScopes("https://ossrdbms-aad.database.windows.net/.default")
).block().getToken();
@Bean
public CorsConfigurationSource corsConfigurationSource() {
CorsConfiguration configuration = new CorsConfiguration();
configuration.setAllowedOrigins(List.of("*")); // Allow all origins, or specify specific ones
configuration.setAllowedMethods(List.of("GET", "POST", "PUT", "DELETE", "OPTIONS")); // Allow all methods
configuration.setAllowedHeaders(List.of("*")); // Allow all headers
configuration.setAllowCredentials(true); // Allow credentials like cookies
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", configuration); // Apply CORS config to all endpoints