Skip to content

Commit

Permalink
Merge pull request #170 from Azure/ipam-vite
Browse files Browse the repository at this point in the history
Azure IPAM 2.0 Updates
  • Loading branch information
DCMattyG authored Sep 19, 2023
2 parents a354f6f + e9d7c3e commit b4dd183
Show file tree
Hide file tree
Showing 96 changed files with 5,888 additions and 29,755 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
node_modules
build
dist
.dockerignore
Dockerfile
Dockerfile.prod
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# syntax=docker/dockerfile:1
FROM node:16-slim AS builder
FROM node:18-slim AS builder

# Set Working Directory
WORKDIR /app
Expand Down Expand Up @@ -41,7 +41,7 @@ RUN mkdir /var/run/sshd

# Install NodeJS 16.x
RUN apt install curl -y
RUN curl -sL https://deb.nodesource.com/setup_16.x -o nodesource_setup.sh
RUN curl -sL https://deb.nodesource.com/setup_18.x -o nodesource_setup.sh
RUN bash ./nodesource_setup.sh
RUN apt install nodejs
RUN npm install -g react-inject-env
Expand Down
6 changes: 3 additions & 3 deletions deploy/deploy.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,7 @@ process {
Extension = "deb"
Port = 80
Images = @{
UI = 'node:16-slim'
UI = 'node:18-slim'
Engine = 'python:3.9-slim'
LB = 'nginx:alpine'
}
Expand All @@ -887,9 +887,9 @@ process {
Extension = "rhel"
Port = 8080
Images = @{
UI = 'registry.access.redhat.com/ubi8/nodejs-16'
UI = 'registry.access.redhat.com/ubi8/nodejs-18'
Engine = 'registry.access.redhat.com/ubi8/python-39'
LB = 'registry.access.redhat.com/ubi8/nginx-120'
LB = 'registry.access.redhat.com/ubi8/nginx-122'
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ version: '3.8'
services:
ipam-ui:
environment:
REACT_APP_AZURE_ENV: ${AZURE_ENV}
REACT_APP_UI_ID: ${UI_APP_ID}
REACT_APP_ENGINE_ID: ${ENGINE_APP_ID}
REACT_APP_TENANT_ID: ${TENANT_ID}
VITE_AZURE_ENV: ${AZURE_ENV}
VITE_UI_ID: ${UI_APP_ID}
VITE_ENGINE_ID: ${ENGINE_APP_ID}
VITE_TENANT_ID: ${TENANT_ID}
image: azureipam.azurecr.io/ipam-ui:latest
ipam-engine:
environment:
Expand Down
8 changes: 4 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ services:
args:
PORT: 8080
environment:
REACT_APP_AZURE_ENV: ${AZURE_ENV}
REACT_APP_UI_ID: ${UI_APP_ID}
REACT_APP_ENGINE_ID: ${ENGINE_APP_ID}
REACT_APP_TENANT_ID: ${TENANT_ID}
VITE_AZURE_ENV: ${AZURE_ENV}
VITE_UI_ID: ${UI_APP_ID}
VITE_ENGINE_ID: ${ENGINE_APP_ID}
VITE_TENANT_ID: ${TENANT_ID}
WDS_SOCKET_PORT: 3000
volumes:
- ./ui:/app
Expand Down
12 changes: 12 additions & 0 deletions engine/app/globals.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import os
import aiohttp

from azure.identity import AzureAuthorityHosts

from azure.core.pipeline.transport import AioHttpTransport

AZURE_ENV_MAP = {
'AZURE_PUBLIC': {
'AZURE_ARM': 'management.azure.com',
Expand All @@ -26,6 +29,11 @@
}

class Globals:
def __init__(self):
conn = aiohttp.TCPConnector(limit=100)
session = aiohttp.ClientSession(connector=conn)
self.shared_transport = AioHttpTransport(session=session, session_owner=False)

@property
def CLIENT_ID(self):
return os.environ.get('CLIENT_ID')
Expand Down Expand Up @@ -88,5 +96,9 @@ def CONTAINER_NAME(self):
ctr_name = os.environ.get('CONTAINER_NAME')

return ctr_name if ctr_name else 'ipam-ctr'

@property
def SHARED_TRANSPORT(self):
return self.shared_transport

globals = Globals()
6 changes: 3 additions & 3 deletions engine/app/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from fastapi import FastAPI, Request, HTTPException, Header
from fastapi.responses import JSONResponse, RedirectResponse, FileResponse
from fastapi.responses import JSONResponse, FileResponse
from fastapi.staticfiles import StaticFiles
from fastapi.exceptions import HTTPException as StarletteHTTPException
from fastapi.middleware.cors import CORSMiddleware
Expand Down Expand Up @@ -46,15 +46,15 @@
app = FastAPI(
title = "Azure IPAM",
description = description,
version = "1.0.0",
version = "2.0.0",
contact = {
"name": "Azure IPAM Team",
"url": "https://github.com/azure/ipam",
"email": "[email protected]",
},
openapi_url = "/api/openapi.json",
docs_url = "/api/docs",
redoc_url = "/api/docs"
redoc_url = "/api/redoc"
)

app.logger = logger
Expand Down
6 changes: 2 additions & 4 deletions engine/app/models.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
from pydantic import BaseModel, ValidationError, EmailStr, root_validator, validator
from pydantic import BaseModel, EmailStr, root_validator, validator
from typing import Optional, Union, Literal, List, Dict, Any

from netaddr import IPSet, IPNetwork, IPAddress
from datetime import datetime
from netaddr import IPNetwork, IPAddress
from uuid import UUID
import json

class IPv4Network(str):
"""
Expand Down
11 changes: 3 additions & 8 deletions engine/app/routers/admin.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
from fastapi import APIRouter, Depends, Request, Response, HTTPException, Header, Path, status
from fastapi.responses import JSONResponse, PlainTextResponse
from fastapi.exceptions import HTTPException as StarletteHTTPException
from fastapi import APIRouter, Depends, Response, HTTPException, Header, Path, status
from fastapi.responses import PlainTextResponse
from fastapi.encoders import jsonable_encoder

import azure.cosmos.exceptions as exceptions

from pydantic import BaseModel, EmailStr, constr
from typing import Optional, List
from typing import List

import copy
import uuid
Expand All @@ -24,7 +20,6 @@
cosmos_query,
cosmos_upsert,
cosmos_replace,
cosmos_delete,
cosmos_retry,
arg_query
)
Expand Down
29 changes: 12 additions & 17 deletions engine/app/routers/azure.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,19 @@
from fastapi import APIRouter, Depends, Request, Response, HTTPException, Header, status
from fastapi.responses import JSONResponse
from fastapi.exceptions import HTTPException as StarletteHTTPException
from fastapi.encoders import jsonable_encoder
from fastapi import APIRouter, Depends, HTTPException, Header

from azure.core.exceptions import ClientAuthenticationError, HttpResponseError
from azure.mgmt.compute.aio import ComputeManagementClient
from azure.mgmt.network.aio import NetworkManagementClient
from azure.mgmt.resource.subscriptions.aio import SubscriptionClient

import azure.cosmos.exceptions as exceptions

from typing import Optional, List
from typing import List

import re
import copy
import time
import asyncio
from ipaddress import IPv4Network
from netaddr import IPSet, IPNetwork
from uuid import uuid4

from sqlalchemy import true

from app.dependencies import (
check_token_expired,
get_admin,
Expand All @@ -35,7 +27,6 @@
get_client_credentials,
get_obo_credentials,
cosmos_query,
cosmos_upsert,
cosmos_replace,
cosmos_retry,
arg_query,
Expand Down Expand Up @@ -75,14 +66,15 @@ async def get_subscriptions_sdk(credentials):
azure_arm_url = 'https://{}'.format(globals.AZURE_ARM_URL)
azure_arm_scope = '{}/.default'.format(azure_arm_url)

subscriptions = []

subscription_client = SubscriptionClient(
credential=credentials,
base_url=azure_arm_url,
credential_scopes=[azure_arm_scope]
credential_scopes=[azure_arm_scope],
transport=globals.SHARED_TRANSPORT
)

subscriptions = []

async for poll in subscription_client.subscriptions.list():
quota_id = poll.subscription_policies.quota_id
quota_id_parts = quota_id.split("_")
Expand Down Expand Up @@ -123,7 +115,8 @@ async def update_vhub_data(auth, admin, hubs):
credential=creds,
subscription_id=hub['subscription_id'],
base_url=azure_arm_url,
credential_scopes=[azure_arm_scope]
credential_scopes=[azure_arm_scope],
transport=globals.SHARED_TRANSPORT
)

hub['peerings'] = []
Expand Down Expand Up @@ -191,7 +184,8 @@ async def get_vmss_list_sdk_helper(credentials, subscription, list):
credential=credentials,
subscription_id=subscription['subscription_id'],
base_url=azure_arm_url,
credential_scopes=[azure_arm_scope]
credential_scopes=[azure_arm_scope],
transport=globals.SHARED_TRANSPORT
)

try:
Expand Down Expand Up @@ -241,7 +235,8 @@ async def get_vmss_interfaces_sdk_helper(credentials, vmss, list):
credential=credentials,
subscription_id=vmss['subscription']['subscription_id'],
base_url=azure_arm_url,
credential_scopes=[azure_arm_scope]
credential_scopes=[azure_arm_scope],
transport=globals.SHARED_TRANSPORT
)

try:
Expand Down
41 changes: 21 additions & 20 deletions engine/app/routers/common/helper.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from fastapi import HTTPException
from fastapi.responses import JSONResponse

from azure.identity.aio import OnBehalfOfCredential, ClientSecretCredential

Expand All @@ -13,16 +12,17 @@
from azure.cosmos.aio import CosmosClient
import azure.cosmos.exceptions as exceptions

import os
import jwt
from netaddr import IPNetwork
from functools import wraps

from requests import options

from app.globals import globals

# SCOPE = "https://management.azure.com/user_impersonation"
cosmos_client = CosmosClient(
url=globals.COSMOS_URL,
credential=globals.COSMOS_KEY,
transport=globals.SHARED_TRANSPORT
)

def valid_ipv4(addr):
try:
Expand Down Expand Up @@ -139,7 +139,7 @@ async def get_mgmt_group_name(tenant_id):
async def cosmos_query(query: str, tenant_id: str):
"""DOCSTRING"""

cosmos_client = CosmosClient(globals.COSMOS_URL, credential=globals.COSMOS_KEY)
# cosmos_client = CosmosClient(globals.COSMOS_URL, credential=globals.COSMOS_KEY)

database_name = globals.DATABASE_NAME
database = cosmos_client.get_database_client(database_name)
Expand All @@ -155,14 +155,14 @@ async def cosmos_query(query: str, tenant_id: str):

result_array = [result async for result in query_results]

await cosmos_client.close()
# await cosmos_client.close()

return result_array

async def cosmos_upsert(data):
"""DOCSTRING"""

cosmos_client = CosmosClient(globals.COSMOS_URL, credential=globals.COSMOS_KEY)
# cosmos_client = CosmosClient(globals.COSMOS_URL, credential=globals.COSMOS_KEY)

database_name = globals.DATABASE_NAME
database = cosmos_client.get_database_client(database_name)
Expand All @@ -174,17 +174,17 @@ async def cosmos_upsert(data):
res = await container.upsert_item(data)
except:
raise
finally:
await cosmos_client.close()
# finally:
# await cosmos_client.close()

await cosmos_client.close()
# await cosmos_client.close()

return res

async def cosmos_replace(old, new):
"""DOCSTRING"""

cosmos_client = CosmosClient(globals.COSMOS_URL, credential=globals.COSMOS_KEY)
# cosmos_client = CosmosClient(globals.COSMOS_URL, credential=globals.COSMOS_KEY)

database_name = globals.DATABASE_NAME
database = cosmos_client.get_database_client(database_name)
Expand All @@ -201,17 +201,17 @@ async def cosmos_replace(old, new):
)
except:
raise
finally:
await cosmos_client.close()
# finally:
# await cosmos_client.close()

await cosmos_client.close()
# await cosmos_client.close()

return

async def cosmos_delete(item, tenant_id: str):
"""DOCSTRING"""

cosmos_client = CosmosClient(globals.COSMOS_URL, credential=globals.COSMOS_KEY)
# cosmos_client = CosmosClient(globals.COSMOS_URL, credential=globals.COSMOS_KEY)

database_name = globals.DATABASE_NAME
database = cosmos_client.get_database_client(database_name)
Expand All @@ -226,10 +226,10 @@ async def cosmos_delete(item, tenant_id: str):
)
except:
raise
finally:
await cosmos_client.close()
# finally:
# await cosmos_client.close()

await cosmos_client.close()
# await cosmos_client.close()

return

Expand Down Expand Up @@ -331,7 +331,8 @@ async def arg_query_helper(credentials, query):
resource_graph_client = ResourceGraphClient(
credential=credentials,
base_url=azure_arm_url,
credential_scopes=[azure_arm_scope]
credential_scopes=[azure_arm_scope],
transport=globals.SHARED_TRANSPORT
)

try:
Expand Down
Loading

0 comments on commit b4dd183

Please sign in to comment.