Skip to content

Commit

Permalink
feat: Support filtering app registrations by tag
Browse files Browse the repository at this point in the history
  • Loading branch information
dploeger committed Jul 26, 2024
1 parent d4c05c4 commit 5292d93
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 3 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,11 @@ The service authenticates against Azure using [Environmental Credentials](https:
- AZURE_CLIENT_SECRET: one of the service principal's client secrets

The Service Principal should have at least API permission `Application.Read.All` (Graph & Active Directory)

## Filtering for tags

While it is not officially possible to tag app registrations, you can still open the manifest json in the
Azure portal, manually change the "tags" property and save it.

Use the FILTER_TAGS environment variable with a comma separated list of tags to only retrive the app
registrations that have one of the given tags attached.
4 changes: 2 additions & 2 deletions charts/azure-app-exporter/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ apiVersion: v2
name: azure-app-exporter
description: Exposing Prometheus Metrics for Azure Service Principals
type: application
version: 0.3.1
appVersion: "0.1.36"
version: 0.4.0
appVersion: "0.2.0"
keywords:
- azure
- prometheus
Expand Down
4 changes: 4 additions & 0 deletions charts/azure-app-exporter/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ spec:
secretKeyRef:
name: {{ template "azure-app-exporter.secretName" . }}
key: azure-tenant-id
{{- if .Values.azure.tagsFilter }}
- name: FILTER_TAGS
value: {{ .Values.azure.tagsFilter | join "," | quote }}
{{- end }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
Expand Down
2 changes: 2 additions & 0 deletions charts/azure-app-exporter/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ azure:
secret: "-unset-"
# -- Your Azure Tenant Id
tenant: "-unset-"
# -- a list of tags. Only the apps having one of the tags are returned
tagsFilter: []

metrics:
# -- Enable Prometheus metrics
Expand Down
12 changes: 11 additions & 1 deletion src/services/azure_app_service.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
from datetime import datetime
from typing import List, Optional

Expand Down Expand Up @@ -33,7 +34,16 @@ async def get_all(self) -> List[AppRegistration]:
result = await self.client.applications.get()
apps = []
while result is not None:
apps += [await self._map_app(a) for a in result.value]
for app in result.value:
found = True
if "FILTER_TAGS" in os.environ:
found = False
for tag in os.environ.get('FILTER_TAGS').split(','):
if tag in app.tags:
found = True
break
if found:
apps += [await self._map_app(app)]
if result.odata_next_link is None:
break
result = await self.client.applications.with_url(result.odata_next_link).get()
Expand Down

0 comments on commit 5292d93

Please sign in to comment.