Skip to content

Commit

Permalink
Merge pull request #10 from x-qdo/refactoring/postgre
Browse files Browse the repository at this point in the history
using postgres to store jira and clickup accounts
  • Loading branch information
astreter committed Mar 20, 2021
2 parents c86cd7b + 480bb57 commit 2fc9e36
Show file tree
Hide file tree
Showing 25 changed files with 599 additions and 192 deletions.
27 changes: 7 additions & 20 deletions .helm/secrets.yaml
Original file line number Diff line number Diff line change
@@ -1,31 +1,18 @@
clickup:
CQYUVTWH2:
webhooksecret: ENC[AES256_GCM,data:5aqOpuxv+xP7ZQ+QowvoE901OwIg/C13nfCzVr9Pt5T/UiwUoaObM80nRvUCQG2bJdqYS57ivqshyV+45HwxZA==,iv:rBXqwEZH7E6oTX9IhPGJZplG9C3H1cZQxNAY9KwA/vE=,tag:nlTN2gY1VTYBzY82q+WE5Q==,type:str]
token: ENC[AES256_GCM,data:YmTuVzn5rG80zG0vn7HELWc6pCd84Y9jrHimIFtsfAn2U9zNm/y37VUyrQ==,iv:VXq7Enqem+Glr0qUDJleYef+V0jF/WxayvQ4nXZhcKg=,tag:L7S7S0VgXhwhsp3U3l0EOw==,type:str]
CQTG74FUH:
webhooksecret: ENC[AES256_GCM,data:SfdhjQRGFmR/1OIEyI6YTCgaUl4eU0go1oWEPSiuz/W0zgduJZ+8YKo5oLJvxvSSPuzPWRagGfyj9sI/NhovDA==,iv:+kpxnsUwniW8Pkmgh6p9q8KbtNDvqhzJkCbvkCZmK0E=,tag:l4sTsi4wV8/QnkxOOZGcEw==,type:str]
token: ENC[AES256_GCM,data:IS3clf4eOUXm41bR4Yx3i/cxcpkbjM4uD6ph1BpOvd2+i+1JMRFypyy3xg==,iv:FUHovxCASXtv4T3m59YRpvTasMwkYwEA+uHnQ4SeDAA=,tag:ypXgtIFOANDF7oUwAebu/Q==,type:str]
jira:
CQYUVTWH2:
username: ENC[AES256_GCM,data:lV5SOUkWgOzQbEWlNU8H5o8+SxoERicczg6qtwEmFw==,iv:n5SfpRCUQsHDWdD/5i8ApKfRpFKwtzRPaTEUySJ7xAE=,tag:9nRHdp8NUGg0yvzlFT9cOg==,type:str]
apitoken: ENC[AES256_GCM,data:ueeQyfgXcPhFwgGkZYSf8HvdTk42gpKQ,iv:eKQiDkGYV/yyyEsLEO+fakCmgBivJvOXMhXKNJqYZ40=,tag:q2rvl8n4jd8K3iic9TtqQQ==,type:str]
CQTG74FUH:
username: ENC[AES256_GCM,data:DVkwxwUJgXV4zKPRm54/y1AjnMi80RogDddTpkH++w==,iv:+90pn34S3CyYGCHaTCqiM74uB9U1ojoCAtv4KOkQMag=,tag:je7qngRRcF0LIOfoz/dvow==,type:str]
apitoken: ENC[AES256_GCM,data:0UXsS51RyV7+094doIyh3sF8GLTMGBvu,iv:FerK8QUHyFDd3PAi7pf1mnSrlw6/SPhfStAtE2tVxTw=,tag:hQLAmdU5Z8vDApB+8VAeHA==,type:str]
rabbitmq:
url: ENC[AES256_GCM,data:Fo2/iS70gkUewEdS6luIjKnNxCQVuDLGXKLtwTjINcPntR4tknJx4mljqhwV3r5Yi7Zeu5LIzZZ+x6cwj6nvnXmW41+q7M+f1z66Y+zupg+HB/s9og==,iv:PJnZ1AtudatxjqWT7i1Q/i1McsNSJT2rb3khQwfmoiU=,tag:ULtjrAGUoKwIQT2d+ADPNw==,type:str]
config_content: ENC[AES256_GCM,data:Yxf+/uQ+5jXsfGf+9vWvlcaJdTzQZRbF7L67GZXQj9+4sss6xALpV91yTvUD+P+r5tg1VcaTovHDp2CPlnQw3Ia4YgPJtvpopyIGnxTuDBuYMGu7orfpu7ll4dVYMipKhCZbBP3Rf9oOfjCMqCUKgmWCZcgyAZk/Ai5hzDveYMZEci4n9hYWZq09AvFr/eiNz4vVR+NUViWkCelLNY9MJ68/YnTcnhdi8nZUElkwkOZnkJMZ3dD8eixac9DjE68UykxG8laIgElMVmCk3+qyguk//jU3BShDfBhlrFSPd1vOreWQ/HnEI0ndZVrjXT/P6BkmEyn/uI562cVcwISxywej2cgXH/F0NtPfK4X8Kzt7Qxzsw9tKG7zM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[AES256_GCM,data:fRhIVX2ZWqZe44jfBrGlkdOqWkVEbj0rIO092uGy7iygjqCi9CJYezw9CkzcgvNPqv4qSDOXlsW/o/8aKAIPpFJJQbI2T50CJaRj6BtzUE4Pz9puFob03diV8MtpdNu78a7bKVEuox28AtjXwZ/RO8lkkLlyVSI=,iv:y+0RWrKKhMOCIJbslbskmMZMLz4IxijdgiKJjkFxuU4=,tag:ZCVuF8zAAX9Z4KyZuZcmog==,type:str]
sops:
kms:
- arn: arn:aws:kms:eu-west-1:238081171252:key/68e2dba1-98bb-4318-8842-2b4d72ea3540
created_at: '2021-01-18T09:53:31Z'
enc: AQICAHg2EwUnvIhDKVygdmQaZAvlrojBkFNXcLhPB3LohD1h0wF8aGJ0SmbIUHWAcngwS0AxAAAAfjB8BgkqhkiG9w0BBwagbzBtAgEAMGgGCSqGSIb3DQEHATAeBglghkgBZQMEAS4wEQQMm+5djspSrYklvQUiAgEQgDvXvJ2sY14qaLkaC0+WCgjIiynhIR5pLsZnO2dUcYInUE2jKwoTBpmPO+YLrwANHS3bZA9cKwMQMFD3WQ==
created_at: '2021-01-28T22:09:14Z'
enc: AQICAHg2EwUnvIhDKVygdmQaZAvlrojBkFNXcLhPB3LohD1h0wEiE5Nd/zN2e7oDYZaRNmGeAAAAfjB8BgkqhkiG9w0BBwagbzBtAgEAMGgGCSqGSIb3DQEHATAeBglghkgBZQMEAS4wEQQMfnLaEBNXzqWtyy9YAgEQgDuOKfa/q7DveyLY6ChniqQjYn0jxaZoOPLAhl0muQMsXe2jyMKNZntO7qtt/5WGC2DVsmJ6gIdGBk4K1Q==
aws_profile: ""
gcp_kms: []
azure_kv: []
hc_vault: []
lastmodified: '2021-01-18T09:53:31Z'
mac: ENC[AES256_GCM,data:I4fUmx/QutrcpI27NHvOc9ihrdVjsdfW/pz3LRXco1hGVmorshiSUwrqsrJTz5yAOCxlgPp9qmaS2MhDeW3BROz3Wf1YbI3zTej5hOTx5XDwidIPeif31bl8SDIhbPy7wi5EQZN4gUESfRiNZGhUDykH2gPCJ7UZsfA1FH+gl9k=,iv:TEhUBZ/zIT1A2AFlHTUVwBM51atK6Hscd1kDfmfCBiw=,tag:oVwHnjUsI/Uu/YHT4S/cpA==,type:str]
lastmodified: '2021-01-28T22:09:14Z'
mac: ENC[AES256_GCM,data:g4SWLLOvg3/qVj448lgQCJm0/ACh9ZEUPAnT4EGelaBgdObIggQqQ/Wjr3EKt4V9Vki4UjsKT/WZkb7cYncQnOvAgxfUWwmiXmNSKzlrOSIGTgrVsMpaEL9WnIU6mW9QL+c+wq3UPwUDCdkYMvecELqwEOMBmvrIbNiWBiwe/gU=,iv:nFqTb+UIE8jTgjxuaZZysDKSFec4G1tedxbFNi0aPWw=,tag:oTXDKl4dTy9UT6gNaD0/Gg==,type:str]
pgp: []
unencrypted_suffix: _unencrypted
version: 3.6.1
46 changes: 7 additions & 39 deletions .helm/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -71,47 +71,15 @@ Create the name of the service account to use
secretKeyRef:
key: rabbitmq_url
name: {{ $name }}
- name: POSTGRES_URL
valueFrom:
secretKeyRef:
key: postgres_url
name: {{ $name }}
- name: POSTGRES_INSECURE
value: "true"
- name: CONFIG_PATH
value: "/"
- name: HTTPHANDLER_PORT
value: "8080"
{{- range $key, $value := .Values.clickup }}
- name: CLICKUP_{{$key}}_TOKEN
valueFrom:
secretKeyRef:
key: clickup_{{$key}}_token
name: {{ $name }}
- name: CLICKUP_{{$key}}_WEBHOOKSECRET
valueFrom:
secretKeyRef:
key: clickup_{{$key}}_webhooksecret
name: {{ $name }}
{{- end }}
{{- range $key, $value := .Values.jira }}
- name: JIRA_{{$key}}_USERNAME
valueFrom:
secretKeyRef:
key: jira_{{$key}}_username
name: {{ $name }}
- name: JIRA_{{$key}}_APITOKEN
valueFrom:
secretKeyRef:
key: jira_{{$key}}_apitoken
name: {{ $name }}
{{- end }}
{{- end -}}

{{- define "jiraclick.config_mount" -}}
- mountPath: "/etc/jiraclick/"
name: config
readOnly: true
{{- end -}}

{{- define "jiraclick.config_volume" -}}
- name: config
secret:
secretName: {{ include "jiraclick.fullname" . }}
items:
- key: config_content
path: config.yaml
{{- end -}}
4 changes: 0 additions & 4 deletions .helm/templates/deployment-api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ spec:
- name: http-handler
containerPort: 8080
protocol: TCP
volumeMounts:
{{ include "jiraclick.config_mount" . | nindent 12 }}
livenessProbe:
httpGet:
path: /health-check
Expand All @@ -52,8 +50,6 @@ spec:
port: http-handler
resources:
{{- toYaml .Values.resources | nindent 12 }}
volumes:
{{ include "jiraclick.config_volume" . | nindent 8 }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
Expand Down
4 changes: 0 additions & 4 deletions .helm/templates/deployment-worker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,8 @@ spec:
- worker
env:
{{ include "jiraclick.common_env" . | nindent 12 }}
volumeMounts:
{{ include "jiraclick.config_mount" . | nindent 12 }}
resources:
{{- toYaml .Values.resources | nindent 12 }}
volumes:
{{ include "jiraclick.config_volume" . | nindent 8 }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
Expand Down
10 changes: 1 addition & 9 deletions .helm/templates/secret.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,5 @@ metadata:
name: {{ include "jiraclick.fullname" . }}
labels: {{- include "jiraclick.labels" . | nindent 4 }}
data:
{{- range $key, $value := .Values.clickup }}
clickup_{{$key}}_webhooksecret: {{$value.webhooksecret | b64enc | quote}}
clickup_{{$key}}_token: {{$value.token | b64enc | quote}}
{{- end }}
{{- range $key, $value := .Values.jira }}
jira_{{$key}}_username: {{$value.username | b64enc | quote}}
jira_{{$key}}_apitoken: {{$value.apitoken | b64enc | quote}}
{{- end }}
rabbitmq_url: {{.Values.rabbitmq.url | b64enc | quote}}
config_content: {{.Values.config_content | b64enc | quote}}
postgres_url: {{.Values.postgres.url | b64enc | quote}}
24 changes: 4 additions & 20 deletions .helm/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,31 +36,15 @@ securityContext: {}
service:
type: ClusterIP

config_content: ""

clickup:
CQYUVTWH2:
webhooksecret: ""
token: "pk_"
list: "10942379"
host: "https://api.clickup.com/api/v2"
CQTG74FUH:
webhooksecret: ""
token: "pk_"
list: "10942379"
host: "https://api.clickup.com/api/v2"
jira:
GQCCU8SCW:
username: "andrei.tratsiakou@insly.com"
apitoken: ""
baseurl: "https://iiziservices.atlassian.net"
project: "DOPS"

debug: true

rabbitmq:
url: ""

postgres:
url: ""
insecure: true

ingress:
enabled: true
annotations:
Expand Down
4 changes: 3 additions & 1 deletion cmd/httphandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"x-qdo/jiraclick/pkg/contract"

"x-qdo/jiraclick/pkg/config"
"x-qdo/jiraclick/pkg/handler"
Expand All @@ -16,6 +17,7 @@ func NewHTTPHandlerCmd(
logger *logrus.Logger,
queue *provider.RabbitChannel,
clickup *clickup.ConnectorPool,
db contract.Storage,
) *cobra.Command {
return &cobra.Command{
Use: "http-handler",
Expand All @@ -28,7 +30,7 @@ func NewHTTPHandlerCmd(
gin.SetMode(gin.DebugMode)
}

clickUpHandler, err := handler.NewClickUpWebhooksHandler(cfg, logger, queue, clickup)
clickUpHandler, err := handler.NewClickUpWebhooksHandler(cfg, logger, queue, clickup, db)
if err != nil {
panic(err)
}
Expand Down
22 changes: 0 additions & 22 deletions config.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,3 @@ httphandler:
port: 8080
metrics:
port: 9090
clickup:
CQYUVTWH2:
webhooksecret: ""
token: "pk_"
list: "10942379"
host: "https://api.clickup.com/api/v2"
CQTG74FUH:
webhooksecret: ""
token: "pk_"
list: "10942379"
host: "https://api.clickup.com/api/v2"
jira:
CQYUVTWH2:
username: ""
apitoken: ""
baseurl: "https://iiziservices.atlassian.net"
project: "DOPS"
CQTG74FUH:
username: ""
apitoken: ""
baseurl: "https://iiziservices.atlassian.net"
project: "DOPS"
27 changes: 21 additions & 6 deletions context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package context
import (
"context"
"sync"
"x-qdo/jiraclick/pkg/contract"

"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
Expand All @@ -22,11 +23,11 @@ type Context struct {
WaitGroup *sync.WaitGroup
}

func NewContext(configPath string) (*Context, error) {
func NewContext() (*Context, error) {
var ctx Context
ctx.Ctx, ctx.CancelF = context.WithCancel(context.Background())

cfg, err := config.NewConfig(configPath)
cfg, err := config.NewConfig()
if err != nil {
panic(err)
}
Expand All @@ -44,17 +45,30 @@ func NewContext(configPath string) (*Context, error) {
panic(err)
}

clickupProvider, err := clickup.NewClickUpConnector(cfg)
db, err := provider.NewPostgres(cfg)
if err != nil {
panic(err)
}

jiraProvider, err := jira.NewJiraConnector(cfg)
clickUpAccounts, err := db.GetClickUpAccounts(ctx.Ctx)
if err != nil {
panic(err)
}
clickupProvider, err := clickup.NewClickUpConnector(clickUpAccounts)
if err != nil {
panic(err)
}

jiraAccounts, err := db.GetJiraAccounts(ctx.Ctx)
if err != nil {
panic(err)
}
jiraProvider, err := jira.NewJiraConnector(jiraAccounts)
if err != nil {
panic(err)
}

setCommands(&ctx, cfg, amqpProvider, clickupProvider, jiraProvider, logger)
setCommands(&ctx, cfg, amqpProvider, clickupProvider, jiraProvider, logger, db)

return &ctx, nil
}
Expand All @@ -66,9 +80,10 @@ func setCommands(
clickup *clickup.ConnectorPool,
jira *jira.ConnectorPool,
logger *logrus.Logger,
db contract.Storage,
) {
workerCmd := cmd.NewWorkerCmd(queue, clickup, jira)
httpHandlerCmd := cmd.NewHTTPHandlerCmd(cfg, logger, queue, clickup)
httpHandlerCmd := cmd.NewHTTPHandlerCmd(cfg, logger, queue, clickup, db)

rootCmd := cmd.NewRootCmd()

Expand Down
20 changes: 20 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
version: '3.7'

services:

postgres:
image: postgres:12.4-alpine
environment:
- POSTGRES_USER=root
- POSTGRES_PASSWORD=root
- POSTGRES_DB=jiraclick
volumes:
- postgres-jiraclick-db:/var/lib/postgresql/data:cached
ports:
- "127.0.0.1:${POSTGRES_PORT}:${POSTGRES_PORT}"
expose:
- "${POSTGRES_PORT}"
command: -p ${POSTGRES_PORT}

volumes:
postgres-jiraclick-db:
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ require (
github.com/andygrunwald/go-jira v1.13.0
github.com/araddon/dateparse v0.0.0-20201001162425-8aadafed4dc4
github.com/gin-gonic/gin v1.6.3
github.com/go-pg/migrations/v8 v8.0.1 // indirect
github.com/go-pg/pg/v10 v10.7.4
github.com/google/uuid v1.2.0 // indirect
github.com/pkg/errors v0.8.1
github.com/sirupsen/logrus v1.7.0
github.com/spf13/cobra v1.0.0
Expand Down
Loading

0 comments on commit 2fc9e36

Please sign in to comment.