Skip to content

Commit

Permalink
Add flags and docs (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
torosent committed Dec 24, 2018
1 parent 8b642e2 commit 565cfa4
Show file tree
Hide file tree
Showing 25 changed files with 382 additions and 203 deletions.
9 changes: 6 additions & 3 deletions README.MD
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
[![Build status](https://dev.azure.com/csedevil/Presidio/_apis/build/status/Presidio-CI)](https://dev.azure.com/csedevil/Presidio/_build/latest?definitionId=48)
[![Go Report Card](https://goreportcard.com/badge/github.com/Microsoft/presidio)](https://goreportcard.com/report/github.com/Microsoft/presidio)
[![MIT license](https://img.shields.io/badge/license-MIT-brightgreen.svg)](http://opensource.org/licenses/MIT)
![](https://img.shields.io/github/release/Microsoft/presidio.svg)

---

# Presidio - Data Loss Prevention API

Expand Down Expand Up @@ -46,7 +51,6 @@ Presidio leverages:
* [Redis](https://redis.io/)
* [GRPC](https://grpc.io)


The [design document](https://microsoft.github.io/presidio/design.html) introduces Presidio concepts and architecture.

## Quickstart
Expand All @@ -55,7 +59,6 @@ The [design document](https://microsoft.github.io/presidio/design.html) introduc
2. Create a Presidio project
3. Start using the Presidio analyze and anonymize services


**Note:** Examples are made with [HTTPie](https://httpie.org/)

***Sample 1***
Expand Down Expand Up @@ -135,7 +138,7 @@ You can also create reusable templates

This project welcomes contributions and suggestions. Most contributions require you to agree to a
Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
the rights to use your contribution. For details, visit https://cla.microsoft.com.
the rights to use your contribution. For details, visit [https://cla.microsoft.com](https://cla.microsoft.com).

When you submit a pull request, a CLA-bot will automatically determine whether you need to provide
a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions
Expand Down
7 changes: 5 additions & 2 deletions charts/presidio/templates/analyzer-deployment.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{ $fullname := include "presidio.analyzer.fullname" . }}
apiVersion: extensions/v1beta1
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ $fullname }}
Expand All @@ -10,14 +10,17 @@ metadata:
heritage: "{{ .Release.Service }}"
spec:
replicas: 1
selector:
matchLabels:
app: {{ $fullname }}
template:
metadata:
labels:
app: {{ $fullname }}
spec:
containers:
- name: {{ .Chart.Name }}
image: "{{ .Values.registry }}/{{ .Values.analyzer.name }}:{{ default .Chart.Version .Values.analyzer.tag }}"
image: "{{ .Values.registry }}/{{ .Values.analyzer.name }}:{{ default .Chart.AppVersion .Values.analyzer.tag }}"
imagePullPolicy: {{ default "IfNotPresent" .Values.analyzer.imagePullPolicy }}
ports:
- containerPort: {{ .Values.analyzer.service.internalPort }}
Expand Down
7 changes: 5 additions & 2 deletions charts/presidio/templates/anonymizer-deployment.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{ $fullname := include "presidio.anonymizer.fullname" . }}
apiVersion: extensions/v1beta1
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ $fullname }}
Expand All @@ -10,14 +10,17 @@ metadata:
heritage: "{{ .Release.Service }}"
spec:
replicas: 1
selector:
matchLabels:
app: {{ $fullname }}
template:
metadata:
labels:
app: {{ $fullname }}
spec:
containers:
- name: {{ .Chart.Name }}
image: "{{ .Values.registry }}/{{ .Values.anonymizer.name }}:{{ default .Chart.Version .Values.anonymizer.tag }}"
image: "{{ .Values.registry }}/{{ .Values.anonymizer.name }}:{{ default .Chart.AppVersion .Values.anonymizer.tag }}"
imagePullPolicy: {{ default "IfNotPresent" .Values.anonymizer.imagePullPolicy }}
ports:
- containerPort: {{ .Values.anonymizer.service.internalPort }}
Expand Down
9 changes: 7 additions & 2 deletions charts/presidio/templates/api-deployment.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{ $fullname := include "presidio.api.fullname" . }}
apiVersion: apps/v1beta1
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ $fullname }}
Expand All @@ -10,6 +10,9 @@ metadata:
heritage: "{{ .Release.Service }}"
spec:
replicas: 1
selector:
matchLabels:
app: {{ $fullname }}
template:
metadata:
labels:
Expand All @@ -18,7 +21,7 @@ spec:
serviceAccountName: {{ $fullname }}
containers:
- name: {{ .Chart.Name }}
image: "{{ .Values.registry }}/{{ .Values.api.name }}:{{ default .Chart.Version .Values.api.tag }}"
image: "{{ .Values.registry }}/{{ .Values.api.name }}:{{ default .Chart.AppVersion .Values.api.tag }}"
imagePullPolicy: {{ default "IfNotPresent" .Values.api.imagePullPolicy }}
ports:
- containerPort: {{ .Values.api.service.internalPort }}
Expand Down Expand Up @@ -47,5 +50,7 @@ spec:
value: {{ template "presidio.anonymizer.address" . }}
- name: SCHEDULER_SVC_ADDRESS
value: {{ template "presidio.scheduler.address" . }}
- name: GIN_MODE
value: release
{{ if .Values.privateRegistry }}imagePullSecrets:
- name: {{.Values.privateRegistry}}{{ end }}
11 changes: 7 additions & 4 deletions charts/presidio/templates/scheduler-deployment.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{{ $fullname := include "presidio.scheduler.fullname" . }}

apiVersion: extensions/v1beta1
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ $fullname }}
Expand All @@ -11,6 +11,9 @@ metadata:
heritage: "{{ .Release.Service }}"
spec:
replicas: 1
selector:
matchLabels:
app: {{ $fullname }}
template:
metadata:
labels:
Expand All @@ -19,7 +22,7 @@ spec:
serviceAccountName: {{ $fullname }}
containers:
- name: {{ .Chart.Name }}
image: "{{ .Values.registry }}/{{ .Values.scheduler.name }}:{{ default .Chart.Version .Values.scheduler.tag }}"
image: "{{ .Values.registry }}/{{ .Values.scheduler.name }}:{{ default .Chart.AppVersion .Values.scheduler.tag }}"
imagePullPolicy: {{ default "IfNotPresent" .Values.scheduler.imagePullPolicy }}
ports:
- containerPort: {{ .Values.scheduler.service.internalPort }}
Expand All @@ -39,11 +42,11 @@ spec:
- name: DATASINK_GRPC_PORT
value: "5000"
- name: DATASINK_IMAGE_NAME
value: {{ .Values.registry }}/{{ .Values.datasink.name }}:{{ default .Chart.Version .Values.datasink.tag }}
value: {{ .Values.registry }}/{{ .Values.datasink.name }}:{{ default .Chart.AppVersion .Values.datasink.tag }}
- name: DATASINK_PULL_POLICY
value: {{ default "IfNotPresent" .Values.datasink.imagePullPolicy }}
- name: COLLECTOR_IMAGE_NAME
value: {{ .Values.registry }}/{{ .Values.collector.name }}:{{ default .Chart.Version .Values.collector.tag }}
value: {{ .Values.registry }}/{{ .Values.collector.name }}:{{ default .Chart.AppVersion .Values.collector.tag }}
- name: COLLECTOR_IMAGE_PULL_POLICY
value: {{ default "IfNotPresent" .Values.collector.imagePullPolicy }}
{{ if .Values.privateRegistry }}imagePullSecrets:
Expand Down
2 changes: 1 addition & 1 deletion charts/presidio/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ api:

ingress:
enabled: true
class: traefik
class: nginx

analyzer:
name: presidio-analyzer
Expand Down
12 changes: 5 additions & 7 deletions docs/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,17 @@ $ docker run --rm --name presidio-api --network mynetwork -d -p 8080:8080 -e WEB
$ helm install --name redis stable/redis --set usePassword=false,rbac.create=true --namespace presidio-system
```

3. Install [Traefik](https://github.com/kubernetes/charts/tree/master/stable/traefik) (Optional - Ingress controller for presidio API)
3. Optional - Ingress controller for presidio API.
- [Traefik](https://docs.traefik.io/user-guide/kubernetes/)
- [NGINX](https://docs.microsoft.com/en-us/azure/aks/ingress-tls)

```sh
$ helm install --name traefik --set rbac.enabled=true stable/traefik --version 1.33.1 --namespace kube-system
```

4. Verify that Redis and Traefik are installed correctly
4. Verify that Redis and Traefik/NGINX are installed correctly

5. Deploy from `/charts/presidio`

```sh
# Based on the DOCKER_REGISTRY and PRESIDIO_LABEL from the previous steps
$ helm install --name presidio-demo --set registry=${DOCKER_REGISTRY} . --namespace presidio --version ${PRESIDIO_LABEL}
$ helm install --name presidio-demo --set registry=${DOCKER_REGISTRY},analyzer.tag=${PRESIDIO_LABEL},anonymizer.tag=${PRESIDIO_LABEL},scheduler.tag=${PRESIDIO_LABEL},api.tag=${PRESIDIO_LABEL},collector.tag=${PRESIDIO_LABEL},datasink.tag=${PRESIDIO_LABEL} . --namespace presidio
```

---
Expand Down
42 changes: 28 additions & 14 deletions pkg/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package logger
import (
"os"
"strings"
"sync"

"github.com/spf13/pflag"
"github.com/spf13/viper"

"go.uber.org/zap"
"go.uber.org/zap/zapcore"
Expand All @@ -13,18 +15,8 @@ import (
var sugaredLogger *zap.SugaredLogger
var logger *zap.Logger

//var logs *observer.ObservedLogs
var once sync.Once

// Init initializes a thread-safe singleton logger
// This would be called from a main method when the application starts up
// This function would ideally, take zap configuration, but is left out
// in favor of simplicity using the example logger.
func init() {
// once ensures the singleton is initialized only once
once.Do(func() {
initLogger()
})
pflag.String("log_level", "info", "Log level - debug/info/warn/error")
}

func initLogger() {
Expand All @@ -49,10 +41,13 @@ func initLogger() {
panic(err.Error())
}
}

func getLogLevel() zapcore.Level {
logLevel := viper.GetString("LOG_LEVEL")

logLevel := os.Getenv("LOG_LEVEL")
switch strings.ToLower(logLevel) {
case "debug":
return zapcore.DebugLevel
case "info":
return zapcore.InfoLevel
case "warn":
Expand All @@ -66,12 +61,15 @@ func getLogLevel() zapcore.Level {
case "fatal":
return zapcore.FatalLevel
default:
return zapcore.DebugLevel
return zapcore.InfoLevel
}
}

// GetLogger get native not sugared logger
func GetLogger() *zap.Logger {
if logger == nil {
initLogger()
}
return logger
}

Expand All @@ -85,26 +83,42 @@ func ObserveLogging(level zapcore.Level) *observer.ObservedLogs {

// Debug logs a debug message with the given fields
func Debug(message string, fields ...interface{}) {
if sugaredLogger == nil {
initLogger()
}
sugaredLogger.Debugf(message, fields...)
}

// Info logs a debug message with the given fields
func Info(message string, fields ...interface{}) {
if sugaredLogger == nil {
initLogger()
}
sugaredLogger.Infof(message, fields...)
}

// Warn logs a debug message with the given fields
func Warn(message string, fields ...interface{}) {
if sugaredLogger == nil {
initLogger()
}
sugaredLogger.Warnf(message, fields...)
}

// Error logs a debug message with the given fields
func Error(message string, fields ...interface{}) {
if sugaredLogger == nil {
initLogger()
}
sugaredLogger.Errorf(message, fields...)
}

// Fatal logs a message than calls os.Exit(1)
func Fatal(message string, fields ...interface{}) {
if sugaredLogger == nil {
initLogger()
}
sugaredLogger.Fatalf(message, fields...)
sugaredLogger.Sync()
os.Exit(1)
}
Loading

0 comments on commit 565cfa4

Please sign in to comment.