Reformatting dir

This commit is contained in:
0x6f736f646f
2020-03-06 23:53:48 +03:00
parent 9d538ecb5b
commit c152a58b76
14 changed files with 1452 additions and 0 deletions
+110
View File
@@ -0,0 +1,110 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
target/
# Jupyter Notebook
.ipynb_checkpoints
# pyenv
.python-version
# celery beat schedule file
celerybeat-schedule
# SageMath parsed files
*.sage.py
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
# Weights
yolov3.weights
#vscode
.vscode/
+15
View File
@@ -0,0 +1,15 @@
from confluent_kafka import Consumer, KafkaError
c = Consumer({'bootstrap.servers': 'localhost:9092', 'group.id': 'mygroup',
'default.topic.config': {'auto.offset.reset': 'smallest'}})
c.subscribe(['Qualis'])
running = True
while running:
msg = c.poll()
if not msg.error():
m = msg.value()
print('Received message: %s' % m)
elif msg.error().code() != KafkaError._PARTITION_EOF:
print(msg.error())
running = False
c.close()
+28
View File
@@ -0,0 +1,28 @@
from confluent_kafka import Producer, KafkaError, KafkaException
import time
import sys
def callback(err, msg):
if err:
sys.stderr.write("Message failed: ", err)
else:
sys.stderr.write("Message delivered to ", msg.topic())
if __name__ == "__main__":
counter = 0
while True:
producer = Producer({'bootstrap.servers': 'localhost:9092'})
topic = "Qualis"
try:
message = "{} Test message {}".format(counter, time.asctime()[11:][:8])
producer.produce(topic, key="Osodo Rodney", value=message)
counter = counter + 1
#producer.produce(topic, b'Test message')#, callback=callback)
except BufferError:
pass
#sys.stderr.write("Local producer queue is full")
producer.flush()
# time.sleep(1)
+566
View File
@@ -0,0 +1,566 @@
apiVersion: v1
items:
- apiVersion: v1
kind: Service
metadata:
annotations:
kompose.cmd: kompose convert -f docker-compose.yml -o kube.yaml
kompose.version: 1.19.0 (f63a961c)
creationTimestamp: null
labels:
io.kompose.service: broker
name: broker
spec:
ports:
- name: "9092"
port: 9092
targetPort: 9092
selector:
io.kompose.service: broker
status:
loadBalancer: {}
- apiVersion: v1
kind: Service
metadata:
annotations:
kompose.cmd: kompose convert -f docker-compose.yml -o kube.yaml
kompose.version: 1.19.0 (f63a961c)
creationTimestamp: null
labels:
io.kompose.service: connect
name: connect
spec:
ports:
- name: "8083"
port: 8083
targetPort: 8083
selector:
io.kompose.service: connect
status:
loadBalancer: {}
- apiVersion: v1
kind: Service
metadata:
annotations:
kompose.cmd: kompose convert -f docker-compose.yml -o kube.yaml
kompose.version: 1.19.0 (f63a961c)
creationTimestamp: null
labels:
io.kompose.service: control-center
name: control-center
spec:
ports:
- name: "9021"
port: 9021
targetPort: 9021
selector:
io.kompose.service: control-center
status:
loadBalancer: {}
- apiVersion: v1
kind: Service
metadata:
annotations:
kompose.cmd: kompose convert -f docker-compose.yml -o kube.yaml
kompose.version: 1.19.0 (f63a961c)
creationTimestamp: null
labels:
io.kompose.service: ksql-server
name: ksql-server
spec:
ports:
- name: "8088"
port: 8088
targetPort: 8088
selector:
io.kompose.service: ksql-server
status:
loadBalancer: {}
- apiVersion: v1
kind: Service
metadata:
annotations:
kompose.cmd: kompose convert -f docker-compose.yml -o kube.yaml
kompose.version: 1.19.0 (f63a961c)
creationTimestamp: null
labels:
io.kompose.service: rest-proxy
name: rest-proxy
spec:
ports:
- name: "8082"
port: 8082
targetPort: 8082
selector:
io.kompose.service: rest-proxy
status:
loadBalancer: {}
- apiVersion: v1
kind: Service
metadata:
annotations:
kompose.cmd: kompose convert -f docker-compose.yml -o kube.yaml
kompose.version: 1.19.0 (f63a961c)
creationTimestamp: null
labels:
io.kompose.service: schema-registry
name: schema-registry
spec:
ports:
- name: "8081"
port: 8081
targetPort: 8081
selector:
io.kompose.service: schema-registry
status:
loadBalancer: {}
- apiVersion: v1
kind: Service
metadata:
annotations:
kompose.cmd: kompose convert -f docker-compose.yml -o kube.yaml
kompose.version: 1.19.0 (f63a961c)
creationTimestamp: null
labels:
io.kompose.service: zookeeper
name: zookeeper
spec:
ports:
- name: "2181"
port: 2181
targetPort: 2181
selector:
io.kompose.service: zookeeper
status:
loadBalancer: {}
- apiVersion: extensions/v1beta1
kind: Deployment
metadata:
annotations:
kompose.cmd: kompose convert -f docker-compose.yml -o kube.yaml
kompose.version: 1.19.0 (f63a961c)
creationTimestamp: null
labels:
io.kompose.service: broker
name: broker
spec:
replicas: 1
strategy: {}
template:
metadata:
annotations:
kompose.cmd: kompose convert -f docker-compose.yml -o kube.yaml
kompose.version: 1.19.0 (f63a961c)
creationTimestamp: null
labels:
io.kompose.service: broker
spec:
containers:
- env:
- name: CONFLUENT_METRICS_ENABLE
value: "true"
- name: CONFLUENT_METRICS_REPORTER_BOOTSTRAP_SERVERS
value: broker:29092
- name: CONFLUENT_METRICS_REPORTER_TOPIC_REPLICAS
value: "1"
- name: CONFLUENT_METRICS_REPORTER_ZOOKEEPER_CONNECT
value: zookeeper:2181
- name: CONFLUENT_SUPPORT_CUSTOMER_ID
value: anonymous
- name: KAFKA_ADVERTISED_LISTENERS
value: PLAINTEXT://broker:29092,PLAINTEXT_HOST://localhost:9092
- name: KAFKA_BROKER_ID
value: "1"
- name: KAFKA_CONFLUENT_LICENSE_TOPIC_REPLICATION_FACTOR
value: "1"
- name: KAFKA_GROUP_INITIAL_REBALANCE_DELAY_MS
value: "0"
- name: KAFKA_LISTENER_SECURITY_PROTOCOL_MAP
value: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
- name: KAFKA_METRIC_REPORTERS
value: io.confluent.metrics.reporter.ConfluentMetricsReporter
- name: KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR
value: "1"
- name: KAFKA_ZOOKEEPER_CONNECT
value: zookeeper:2181
image: confluentinc/cp-server:5.4.0
name: broker
ports:
- containerPort: 9092
resources: {}
hostname: broker
restartPolicy: Always
status: {}
- apiVersion: extensions/v1beta1
kind: Deployment
metadata:
annotations:
kompose.cmd: kompose convert -f docker-compose.yml -o kube.yaml
kompose.version: 1.19.0 (f63a961c)
creationTimestamp: null
labels:
io.kompose.service: connect
name: connect
spec:
replicas: 1
strategy: {}
template:
metadata:
annotations:
kompose.cmd: kompose convert -f docker-compose.yml -o kube.yaml
kompose.version: 1.19.0 (f63a961c)
creationTimestamp: null
labels:
io.kompose.service: connect
spec:
containers:
- env:
- name: CLASSPATH
value: /usr/share/java/monitoring-interceptors/monitoring-interceptors-5.4.0.jar
- name: CONNECT_BOOTSTRAP_SERVERS
value: broker:29092
- name: CONNECT_CONFIG_STORAGE_REPLICATION_FACTOR
value: "1"
- name: CONNECT_CONFIG_STORAGE_TOPIC
value: docker-connect-configs
- name: CONNECT_CONSUMER_INTERCEPTOR_CLASSES
value: io.confluent.monitoring.clients.interceptor.MonitoringConsumerInterceptor
- name: CONNECT_GROUP_ID
value: compose-connect-group
- name: CONNECT_INTERNAL_KEY_CONVERTER
value: org.apache.kafka.connect.json.JsonConverter
- name: CONNECT_INTERNAL_VALUE_CONVERTER
value: org.apache.kafka.connect.json.JsonConverter
- name: CONNECT_KEY_CONVERTER
value: org.apache.kafka.connect.storage.StringConverter
- name: CONNECT_LOG4J_LOGGERS
value: org.apache.zookeeper=ERROR,org.I0Itec.zkclient=ERROR,org.reflections=ERROR
- name: CONNECT_OFFSET_FLUSH_INTERVAL_MS
value: "10000"
- name: CONNECT_OFFSET_STORAGE_REPLICATION_FACTOR
value: "1"
- name: CONNECT_OFFSET_STORAGE_TOPIC
value: docker-connect-offsets
- name: CONNECT_PLUGIN_PATH
value: /usr/share/java,/usr/share/confluent-hub-components
- name: CONNECT_PRODUCER_INTERCEPTOR_CLASSES
value: io.confluent.monitoring.clients.interceptor.MonitoringProducerInterceptor
- name: CONNECT_REST_ADVERTISED_HOST_NAME
value: connect
- name: CONNECT_REST_PORT
value: "8083"
- name: CONNECT_STATUS_STORAGE_REPLICATION_FACTOR
value: "1"
- name: CONNECT_STATUS_STORAGE_TOPIC
value: docker-connect-status
- name: CONNECT_VALUE_CONVERTER
value: io.confluent.connect.avro.AvroConverter
- name: CONNECT_VALUE_CONVERTER_SCHEMA_REGISTRY_URL
value: http://schema-registry:8081
- name: CONNECT_ZOOKEEPER_CONNECT
value: zookeeper:2181
image: cnfldemos/cp-server-connect-datagen:0.2.0-5.4.0
name: connect
ports:
- containerPort: 8083
resources: {}
hostname: connect
restartPolicy: Always
status: {}
- apiVersion: extensions/v1beta1
kind: Deployment
metadata:
annotations:
kompose.cmd: kompose convert -f docker-compose.yml -o kube.yaml
kompose.version: 1.19.0 (f63a961c)
creationTimestamp: null
labels:
io.kompose.service: control-center
name: control-center
spec:
replicas: 1
strategy: {}
template:
metadata:
annotations:
kompose.cmd: kompose convert -f docker-compose.yml -o kube.yaml
kompose.version: 1.19.0 (f63a961c)
creationTimestamp: null
labels:
io.kompose.service: control-center
spec:
containers:
- env:
- name: CONFLUENT_METRICS_TOPIC_REPLICATION
value: "1"
- name: CONTROL_CENTER_BOOTSTRAP_SERVERS
value: broker:29092
- name: CONTROL_CENTER_CONNECT_CLUSTER
value: connect:8083
- name: CONTROL_CENTER_INTERNAL_TOPICS_PARTITIONS
value: "1"
- name: CONTROL_CENTER_KSQL_ADVERTISED_URL
value: http://localhost:8088
- name: CONTROL_CENTER_KSQL_URL
value: http://ksql-server:8088
- name: CONTROL_CENTER_MONITORING_INTERCEPTOR_TOPIC_PARTITIONS
value: "1"
- name: CONTROL_CENTER_REPLICATION_FACTOR
value: "1"
- name: CONTROL_CENTER_SCHEMA_REGISTRY_URL
value: http://schema-registry:8081
- name: CONTROL_CENTER_ZOOKEEPER_CONNECT
value: zookeeper:2181
- name: PORT
value: "9021"
image: confluentinc/cp-enterprise-control-center:5.4.0
name: control-center
ports:
- containerPort: 9021
resources: {}
hostname: control-center
restartPolicy: Always
status: {}
- apiVersion: extensions/v1beta1
kind: Deployment
metadata:
annotations:
kompose.cmd: kompose convert -f docker-compose.yml -o kube.yaml
kompose.version: 1.19.0 (f63a961c)
creationTimestamp: null
labels:
io.kompose.service: ksql-cli
name: ksql-cli
spec:
replicas: 1
strategy: {}
template:
metadata:
annotations:
kompose.cmd: kompose convert -f docker-compose.yml -o kube.yaml
kompose.version: 1.19.0 (f63a961c)
creationTimestamp: null
labels:
io.kompose.service: ksql-cli
spec:
containers:
- command:
- /bin/sh
image: confluentinc/cp-ksql-cli:5.4.0
name: ksql-cli
resources: {}
tty: true
restartPolicy: Always
status: {}
- apiVersion: extensions/v1beta1
kind: Deployment
metadata:
annotations:
kompose.cmd: kompose convert -f docker-compose.yml -o kube.yaml
kompose.version: 1.19.0 (f63a961c)
creationTimestamp: null
labels:
io.kompose.service: ksql-datagen
name: ksql-datagen
spec:
replicas: 1
strategy: {}
template:
metadata:
annotations:
kompose.cmd: kompose convert -f docker-compose.yml -o kube.yaml
kompose.version: 1.19.0 (f63a961c)
creationTimestamp: null
labels:
io.kompose.service: ksql-datagen
spec:
containers:
- args:
- bash
- -c
- echo Waiting for Kafka to be ready... && cub kafka-ready -b broker:29092
1 40 && echo Waiting for Confluent Schema Registry to be ready... && cub
sr-ready schema-registry 8081 40 && echo Waiting a few seconds for topic
creation to finish... && sleep 11 && tail -f /dev/null
env:
- name: KSQL_CONFIG_DIR
value: /etc/ksql
- name: KSQL_LOG4J_OPTS
value: -Dlog4j.configuration=file:/etc/ksql/log4j-rolling.properties
- name: STREAMS_BOOTSTRAP_SERVERS
value: broker:29092
- name: STREAMS_SCHEMA_REGISTRY_HOST
value: schema-registry
- name: STREAMS_SCHEMA_REGISTRY_PORT
value: "8081"
image: confluentinc/ksql-examples:5.4.0
name: ksql-datagen
resources: {}
hostname: ksql-datagen
restartPolicy: Always
status: {}
- apiVersion: extensions/v1beta1
kind: Deployment
metadata:
annotations:
kompose.cmd: kompose convert -f docker-compose.yml -o kube.yaml
kompose.version: 1.19.0 (f63a961c)
creationTimestamp: null
labels:
io.kompose.service: ksql-server
name: ksql-server
spec:
replicas: 1
strategy: {}
template:
metadata:
annotations:
kompose.cmd: kompose convert -f docker-compose.yml -o kube.yaml
kompose.version: 1.19.0 (f63a961c)
creationTimestamp: null
labels:
io.kompose.service: ksql-server
spec:
containers:
- env:
- name: KSQL_BOOTSTRAP_SERVERS
value: broker:29092
- name: KSQL_CACHE_MAX_BYTES_BUFFERING
value: "0"
- name: KSQL_CONFIG_DIR
value: /etc/ksql
- name: KSQL_CONSUMER_INTERCEPTOR_CLASSES
value: io.confluent.monitoring.clients.interceptor.MonitoringConsumerInterceptor
- name: KSQL_HOST_NAME
value: ksql-server
- name: KSQL_KSQL_SCHEMA_REGISTRY_URL
value: http://schema-registry:8081
- name: KSQL_LISTENERS
value: http://0.0.0.0:8088
- name: KSQL_LOG4J_OPTS
value: -Dlog4j.configuration=file:/etc/ksql/log4j-rolling.properties
- name: KSQL_PRODUCER_INTERCEPTOR_CLASSES
value: io.confluent.monitoring.clients.interceptor.MonitoringProducerInterceptor
image: confluentinc/cp-ksql-server:5.4.0
name: ksql-server
ports:
- containerPort: 8088
resources: {}
hostname: ksql-server
restartPolicy: Always
status: {}
- apiVersion: extensions/v1beta1
kind: Deployment
metadata:
annotations:
kompose.cmd: kompose convert -f docker-compose.yml -o kube.yaml
kompose.version: 1.19.0 (f63a961c)
creationTimestamp: null
labels:
io.kompose.service: rest-proxy
name: rest-proxy
spec:
replicas: 1
strategy: {}
template:
metadata:
annotations:
kompose.cmd: kompose convert -f docker-compose.yml -o kube.yaml
kompose.version: 1.19.0 (f63a961c)
creationTimestamp: null
labels:
io.kompose.service: rest-proxy
spec:
containers:
- env:
- name: KAFKA_REST_BOOTSTRAP_SERVERS
value: broker:29092
- name: KAFKA_REST_HOST_NAME
value: rest-proxy
- name: KAFKA_REST_LISTENERS
value: http://0.0.0.0:8082
- name: KAFKA_REST_SCHEMA_REGISTRY_URL
value: http://schema-registry:8081
image: confluentinc/cp-kafka-rest:5.4.0
name: rest-proxy
ports:
- containerPort: 8082
resources: {}
hostname: rest-proxy
restartPolicy: Always
status: {}
- apiVersion: extensions/v1beta1
kind: Deployment
metadata:
annotations:
kompose.cmd: kompose convert -f docker-compose.yml -o kube.yaml
kompose.version: 1.19.0 (f63a961c)
creationTimestamp: null
labels:
io.kompose.service: schema-registry
name: schema-registry
spec:
replicas: 1
strategy: {}
template:
metadata:
annotations:
kompose.cmd: kompose convert -f docker-compose.yml -o kube.yaml
kompose.version: 1.19.0 (f63a961c)
creationTimestamp: null
labels:
io.kompose.service: schema-registry
spec:
containers:
- env:
- name: SCHEMA_REGISTRY_HOST_NAME
value: schema-registry
- name: SCHEMA_REGISTRY_KAFKASTORE_CONNECTION_URL
value: zookeeper:2181
image: confluentinc/cp-schema-registry:5.4.0
name: schema-registry
ports:
- containerPort: 8081
resources: {}
hostname: schema-registry
restartPolicy: Always
status: {}
- apiVersion: extensions/v1beta1
kind: Deployment
metadata:
annotations:
kompose.cmd: kompose convert -f docker-compose.yml -o kube.yaml
kompose.version: 1.19.0 (f63a961c)
creationTimestamp: null
labels:
io.kompose.service: zookeeper
name: zookeeper
spec:
replicas: 1
strategy: {}
template:
metadata:
annotations:
kompose.cmd: kompose convert -f docker-compose.yml -o kube.yaml
kompose.version: 1.19.0 (f63a961c)
creationTimestamp: null
labels:
io.kompose.service: zookeeper
spec:
containers:
- env:
- name: ZOOKEEPER_CLIENT_PORT
value: "2181"
- name: ZOOKEEPER_TICK_TIME
value: "2000"
image: confluentinc/cp-zookeeper:5.4.0
name: zookeeper
ports:
- containerPort: 2181
resources: {}
hostname: zookeeper
restartPolicy: Always
status: {}
kind: List
metadata: {}
+2
View File
@@ -0,0 +1,2 @@
confluent-kafka==1.3.0
pkg-resources==0.0.0
+4
View File
@@ -0,0 +1,4 @@
FROM scratch
WORKDIR /app
COPY server/main /app
CMD ["./main"]
Binary file not shown.
+26
View File
@@ -0,0 +1,26 @@
package main
import (
"log"
"qualEATS/userPB"
"golang.org/x/net/context"
"google.golang.org/grpc"
)
func main() {
var conn *grpc.ClientConn
conn, err := grpc.Dial(":7777", grpc.WithInsecure())
if err != nil {
log.Fatalf("did not connect: %s", err)
}
defer conn.Close()
defer conn.Close()
c := userPB.NewAuthServiceClient(conn)
response, err := c.Signup(context.Background(), &userPB.RegDetails{Username: "Sam", Password: "qualis", Usertype: "client", Company: "Dummy", Email: "anemailaddress"})
if err != nil {
log.Fatalf("Error when calling Login: %s", err)
}
log.Printf("Response from server: %s", response.Token)
}
BIN
View File
Binary file not shown.
Binary file not shown.
+170
View File
@@ -0,0 +1,170 @@
package main
import (
"context"
"fmt"
"log"
"net"
"time"
userPB "qualEATS/userPB"
"github.com/dgrijalva/jwt-go"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
"google.golang.org/grpc"
)
type Users struct {
Id string `bson:"_id"`
Username string `bson:"name"`
Password string `bson:"password"`
}
type Regst struct {
Username string `bson:"name"`
Password string `bson:"password"`
Usertype string `bson:"usertype"`
Company string `bson:"company"`
Email string `bson:"email"`
}
var jwtKey = []byte("affd25090f0b173ca7ce22837167579e")
type AuthServiceServer struct {
}
type Claims struct {
Username string `json:"username"`
jwt.StandardClaims
}
func (s *AuthServiceServer) Login(ctx context.Context, req *userPB.LoginReq) (*userPB.LoginRes, error) {
uName := req.Username
pWD := req.Pwad
expirationTime := time.Now().Add(5 * time.Minute)
//fmt.Printf("%s", pWD)
clientOptions := options.Client().ApplyURI("mongodb://localhost:27017")
client, err := mongo.Connect(context.TODO(), clientOptions)
if err != nil {
log.Fatal(err)
}
// Check the connection
err = client.Ping(context.TODO(), nil)
if err != nil {
log.Fatal(err)
}
//fmt.Println("Connected to MongoDB!")
collection := client.Database("qualEATS").Collection("users")
var result Users
filter := bson.D{{"name", uName}}
var ntx int64 = 0
err = collection.FindOne(context.TODO(), filter).Decode(&result)
if err != nil {
ntx = 1
//log.Fatal(err)
}
//fmt.Printf("Found a single document: %+v\n", result.Password)
if ntx == 0 {
if pWD == result.Password {
claims := &Claims{
Username: uName,
StandardClaims: jwt.StandardClaims{
ExpiresAt: expirationTime.Unix(),
},
}
token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
tokenString, err := token.SignedString(jwtKey)
if err != nil {
return &userPB.LoginRes{Token: "Internal Error"}, nil
}
return &userPB.LoginRes{Token: tokenString}, nil
} else {
return &userPB.LoginRes{Token: "Wrong password"}, nil
}
} else {
return &userPB.LoginRes{Token: "User does not exist"}, nil
}
}
func (s *AuthServiceServer) Signup(ctx context.Context, req1 *userPB.RegDetails) (*userPB.LoginRes, error) {
uName1 := req1.Username
Pwad1 := req1.Password
uType := req1.Usertype
comp := req1.Company
email := req1.Email
expirationTime := time.Now().Add(5 * time.Minute)
clientOptions := options.Client().ApplyURI("mongodb://localhost:27017")
client, err := mongo.Connect(context.TODO(), clientOptions)
if err != nil {
log.Fatal(err)
}
// Check the connection
err = client.Ping(context.TODO(), nil)
if err != nil {
log.Fatal(err)
}
//fmt.Println("Connected to MongoDB!")
collection := client.Database("qualEATS").Collection("users")
var result Regst
filter := bson.D{{"name", uName1}}
var ntx int64 = 0
err = collection.FindOne(context.TODO(), filter).Decode(&result)
if err != nil {
ntx = 1
//log.Fatal(err)
}
tokenString := ""
if ntx == 1 {
newUser := Regst{uName1, Pwad1, uType, comp, email}
insertResult, err := collection.InsertOne(context.TODO(), newUser)
if err != nil {
log.Fatal(err)
}
if insertResult.InsertedID != nil {
claims := &Claims{
Username: uName1,
StandardClaims: jwt.StandardClaims{
ExpiresAt: expirationTime.Unix(),
},
}
token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
tokenString, err = token.SignedString(jwtKey)
} else {
tokenString = "Internal error"
}
} else {
tokenString = "Username exists"
}
return &userPB.LoginRes{Token: tokenString}, nil
}
func main() {
//ctx := context.Background()
lis, err := net.Listen("tcp", fmt.Sprintf(":%d", 7777))
if err != nil {
log.Fatalf("failed to listen: %v", err)
}
s := AuthServiceServer{}
grpcServer := grpc.NewServer()
userPB.RegisterAuthServiceServer(grpcServer, &s)
if err := grpcServer.Serve(lis); err != nil {
log.Fatalf("failed to serve: %s", err)
}
}
+325
View File
@@ -0,0 +1,325 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// source: userPB.proto
package userPB
import (
context "context"
fmt "fmt"
proto "github.com/golang/protobuf/proto"
grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"
math "math"
)
// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
var _ = fmt.Errorf
var _ = math.Inf
// This is a compile-time assertion to ensure that this generated file
// is compatible with the proto package it is being compiled against.
// A compilation error at this line likely means your copy of the
// proto package needs to be updated.
const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package
type LoginReq struct {
Username string `protobuf:"bytes,1,opt,name=username,proto3" json:"username,omitempty"`
Pwad string `protobuf:"bytes,2,opt,name=pwad,proto3" json:"pwad,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *LoginReq) Reset() { *m = LoginReq{} }
func (m *LoginReq) String() string { return proto.CompactTextString(m) }
func (*LoginReq) ProtoMessage() {}
func (*LoginReq) Descriptor() ([]byte, []int) {
return fileDescriptor_08d451189a7398cb, []int{0}
}
func (m *LoginReq) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_LoginReq.Unmarshal(m, b)
}
func (m *LoginReq) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_LoginReq.Marshal(b, m, deterministic)
}
func (m *LoginReq) XXX_Merge(src proto.Message) {
xxx_messageInfo_LoginReq.Merge(m, src)
}
func (m *LoginReq) XXX_Size() int {
return xxx_messageInfo_LoginReq.Size(m)
}
func (m *LoginReq) XXX_DiscardUnknown() {
xxx_messageInfo_LoginReq.DiscardUnknown(m)
}
var xxx_messageInfo_LoginReq proto.InternalMessageInfo
func (m *LoginReq) GetUsername() string {
if m != nil {
return m.Username
}
return ""
}
func (m *LoginReq) GetPwad() string {
if m != nil {
return m.Pwad
}
return ""
}
type LoginRes struct {
Token string `protobuf:"bytes,1,opt,name=token,proto3" json:"token,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *LoginRes) Reset() { *m = LoginRes{} }
func (m *LoginRes) String() string { return proto.CompactTextString(m) }
func (*LoginRes) ProtoMessage() {}
func (*LoginRes) Descriptor() ([]byte, []int) {
return fileDescriptor_08d451189a7398cb, []int{1}
}
func (m *LoginRes) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_LoginRes.Unmarshal(m, b)
}
func (m *LoginRes) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_LoginRes.Marshal(b, m, deterministic)
}
func (m *LoginRes) XXX_Merge(src proto.Message) {
xxx_messageInfo_LoginRes.Merge(m, src)
}
func (m *LoginRes) XXX_Size() int {
return xxx_messageInfo_LoginRes.Size(m)
}
func (m *LoginRes) XXX_DiscardUnknown() {
xxx_messageInfo_LoginRes.DiscardUnknown(m)
}
var xxx_messageInfo_LoginRes proto.InternalMessageInfo
func (m *LoginRes) GetToken() string {
if m != nil {
return m.Token
}
return ""
}
type RegDetails struct {
Username string `protobuf:"bytes,1,opt,name=username,proto3" json:"username,omitempty"`
Password string `protobuf:"bytes,2,opt,name=password,proto3" json:"password,omitempty"`
Usertype string `protobuf:"bytes,3,opt,name=usertype,proto3" json:"usertype,omitempty"`
Company string `protobuf:"bytes,4,opt,name=company,proto3" json:"company,omitempty"`
Email string `protobuf:"bytes,5,opt,name=email,proto3" json:"email,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *RegDetails) Reset() { *m = RegDetails{} }
func (m *RegDetails) String() string { return proto.CompactTextString(m) }
func (*RegDetails) ProtoMessage() {}
func (*RegDetails) Descriptor() ([]byte, []int) {
return fileDescriptor_08d451189a7398cb, []int{2}
}
func (m *RegDetails) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_RegDetails.Unmarshal(m, b)
}
func (m *RegDetails) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_RegDetails.Marshal(b, m, deterministic)
}
func (m *RegDetails) XXX_Merge(src proto.Message) {
xxx_messageInfo_RegDetails.Merge(m, src)
}
func (m *RegDetails) XXX_Size() int {
return xxx_messageInfo_RegDetails.Size(m)
}
func (m *RegDetails) XXX_DiscardUnknown() {
xxx_messageInfo_RegDetails.DiscardUnknown(m)
}
var xxx_messageInfo_RegDetails proto.InternalMessageInfo
func (m *RegDetails) GetUsername() string {
if m != nil {
return m.Username
}
return ""
}
func (m *RegDetails) GetPassword() string {
if m != nil {
return m.Password
}
return ""
}
func (m *RegDetails) GetUsertype() string {
if m != nil {
return m.Usertype
}
return ""
}
func (m *RegDetails) GetCompany() string {
if m != nil {
return m.Company
}
return ""
}
func (m *RegDetails) GetEmail() string {
if m != nil {
return m.Email
}
return ""
}
func init() {
proto.RegisterType((*LoginReq)(nil), "userPB.loginReq")
proto.RegisterType((*LoginRes)(nil), "userPB.loginRes")
proto.RegisterType((*RegDetails)(nil), "userPB.regDetails")
}
func init() { proto.RegisterFile("userPB.proto", fileDescriptor_08d451189a7398cb) }
var fileDescriptor_08d451189a7398cb = []byte{
// 231 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x90, 0x31, 0x4f, 0x85, 0x30,
0x14, 0x85, 0x83, 0x3e, 0x10, 0xaf, 0x0e, 0xe6, 0xc6, 0xa1, 0x61, 0x7a, 0x61, 0x32, 0x31, 0x61,
0xd0, 0xcd, 0xd1, 0x38, 0x3a, 0x98, 0xc7, 0x2f, 0xa8, 0x78, 0x83, 0x55, 0x68, 0x6b, 0x5b, 0x24,
0xfc, 0x0b, 0x7f, 0xb2, 0x69, 0xa1, 0x90, 0x68, 0xf2, 0xb6, 0x7e, 0xe7, 0xf6, 0xe4, 0xde, 0x73,
0xe0, 0x72, 0xb0, 0x64, 0x5e, 0x1e, 0x2b, 0x6d, 0x94, 0x53, 0x98, 0xcd, 0x54, 0x3e, 0x40, 0xde,
0xa9, 0x56, 0xc8, 0x03, 0x7d, 0x61, 0x01, 0xb9, 0x57, 0x25, 0xef, 0x89, 0x25, 0xfb, 0xe4, 0xe6,
0xfc, 0xb0, 0x32, 0x22, 0xec, 0xf4, 0xc8, 0xdf, 0xd8, 0x49, 0xd0, 0xc3, 0xbb, 0xdc, 0xaf, 0x5e,
0x8b, 0xd7, 0x90, 0x3a, 0xf5, 0x49, 0x72, 0x31, 0xce, 0x50, 0xfe, 0x24, 0x00, 0x86, 0xda, 0x27,
0x72, 0x5c, 0x74, 0xf6, 0xe8, 0x82, 0x02, 0x72, 0xcd, 0xad, 0x1d, 0x95, 0x89, 0x4b, 0x56, 0x8e,
0x3e, 0x37, 0x69, 0x62, 0xa7, 0x9b, 0xcf, 0x33, 0x32, 0x38, 0x6b, 0x54, 0xaf, 0xb9, 0x9c, 0xd8,
0x2e, 0x8c, 0x22, 0xfa, 0x93, 0xa8, 0xe7, 0xa2, 0x63, 0xe9, 0x7c, 0x52, 0x80, 0xbb, 0x0f, 0xb8,
0xe0, 0x83, 0x7b, 0xaf, 0xc9, 0x7c, 0x8b, 0x86, 0xf0, 0x16, 0xd2, 0x67, 0x9f, 0x01, 0xaf, 0xaa,
0xa5, 0x9f, 0x58, 0x47, 0xf1, 0x57, 0xb1, 0x58, 0x41, 0x56, 0x8b, 0x56, 0x0e, 0x1a, 0x31, 0xce,
0xb6, 0x74, 0xff, 0xff, 0xbf, 0x66, 0xa1, 0xeb, 0xfb, 0xdf, 0x00, 0x00, 0x00, 0xff, 0xff, 0x69,
0x84, 0xa0, 0xd2, 0x7b, 0x01, 0x00, 0x00,
}
// Reference imports to suppress errors if they are not otherwise used.
var _ context.Context
var _ grpc.ClientConnInterface
// This is a compile-time assertion to ensure that this generated file
// is compatible with the grpc package it is being compiled against.
const _ = grpc.SupportPackageIsVersion6
// AuthServiceClient is the client API for AuthService service.
//
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream.
type AuthServiceClient interface {
Login(ctx context.Context, in *LoginReq, opts ...grpc.CallOption) (*LoginRes, error)
Signup(ctx context.Context, in *RegDetails, opts ...grpc.CallOption) (*LoginRes, error)
}
type authServiceClient struct {
cc grpc.ClientConnInterface
}
func NewAuthServiceClient(cc grpc.ClientConnInterface) AuthServiceClient {
return &authServiceClient{cc}
}
func (c *authServiceClient) Login(ctx context.Context, in *LoginReq, opts ...grpc.CallOption) (*LoginRes, error) {
out := new(LoginRes)
err := c.cc.Invoke(ctx, "/userPB.authService/Login", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *authServiceClient) Signup(ctx context.Context, in *RegDetails, opts ...grpc.CallOption) (*LoginRes, error) {
out := new(LoginRes)
err := c.cc.Invoke(ctx, "/userPB.authService/Signup", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// AuthServiceServer is the server API for AuthService service.
type AuthServiceServer interface {
Login(context.Context, *LoginReq) (*LoginRes, error)
Signup(context.Context, *RegDetails) (*LoginRes, error)
}
// UnimplementedAuthServiceServer can be embedded to have forward compatible implementations.
type UnimplementedAuthServiceServer struct {
}
func (*UnimplementedAuthServiceServer) Login(ctx context.Context, req *LoginReq) (*LoginRes, error) {
return nil, status.Errorf(codes.Unimplemented, "method Login not implemented")
}
func (*UnimplementedAuthServiceServer) Signup(ctx context.Context, req *RegDetails) (*LoginRes, error) {
return nil, status.Errorf(codes.Unimplemented, "method Signup not implemented")
}
func RegisterAuthServiceServer(s *grpc.Server, srv AuthServiceServer) {
s.RegisterService(&_AuthService_serviceDesc, srv)
}
func _AuthService_Login_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(LoginReq)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(AuthServiceServer).Login(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/userPB.authService/Login",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(AuthServiceServer).Login(ctx, req.(*LoginReq))
}
return interceptor(ctx, in, info, handler)
}
func _AuthService_Signup_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(RegDetails)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(AuthServiceServer).Signup(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/userPB.authService/Signup",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(AuthServiceServer).Signup(ctx, req.(*RegDetails))
}
return interceptor(ctx, in, info, handler)
}
var _AuthService_serviceDesc = grpc.ServiceDesc{
ServiceName: "userPB.authService",
HandlerType: (*AuthServiceServer)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "Login",
Handler: _AuthService_Login_Handler,
},
{
MethodName: "Signup",
Handler: _AuthService_Signup_Handler,
},
},
Streams: []grpc.StreamDesc{},
Metadata: "userPB.proto",
}
+22
View File
@@ -0,0 +1,22 @@
//protoc -I userPB/ userPB/userPB.proto --go_out=plugins=grpc:userPB
syntax = "proto3";
package userPB;
message loginReq{
string username = 1;
string pwad = 2;
}
message loginRes{
string token = 1;
}
message regDetails{
string username = 1;
string password = 2;
string usertype = 3;
string company = 4;
string email =5;
}
service authService{
rpc Login(loginReq) returns (loginRes);
rpc Signup(regDetails) returns (loginRes);
}
+184
View File
@@ -0,0 +1,184 @@
---
version: '2'
services:
zookeeper:
image: confluentinc/cp-zookeeper:5.4.0
hostname: zookeeper
container_name: zookeeper
ports:
- "2181:2181"
environment:
ZOOKEEPER_CLIENT_PORT: 2181
ZOOKEEPER_TICK_TIME: 2000
broker:
image: confluentinc/cp-server:5.4.0
hostname: broker
container_name: broker
depends_on:
- zookeeper
ports:
- "9092:9092"
environment:
KAFKA_BROKER_ID: 1
KAFKA_ZOOKEEPER_CONNECT: 'zookeeper:2181'
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://broker:29092,PLAINTEXT_HOST://localhost:9092
KAFKA_METRIC_REPORTERS: io.confluent.metrics.reporter.ConfluentMetricsReporter
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
KAFKA_GROUP_INITIAL_REBALANCE_DELAY_MS: 0
KAFKA_CONFLUENT_LICENSE_TOPIC_REPLICATION_FACTOR: 1
CONFLUENT_METRICS_REPORTER_BOOTSTRAP_SERVERS: broker:29092
CONFLUENT_METRICS_REPORTER_ZOOKEEPER_CONNECT: zookeeper:2181
CONFLUENT_METRICS_REPORTER_TOPIC_REPLICAS: 1
CONFLUENT_METRICS_ENABLE: 'true'
CONFLUENT_SUPPORT_CUSTOMER_ID: 'anonymous'
schema-registry:
image: confluentinc/cp-schema-registry:5.4.0
hostname: schema-registry
container_name: schema-registry
depends_on:
- zookeeper
- broker
ports:
- "8081:8081"
environment:
SCHEMA_REGISTRY_HOST_NAME: schema-registry
SCHEMA_REGISTRY_KAFKASTORE_CONNECTION_URL: 'zookeeper:2181'
connect:
image: cnfldemos/cp-server-connect-datagen:0.2.0-5.4.0
hostname: connect
container_name: connect
depends_on:
- zookeeper
- broker
- schema-registry
ports:
- "8083:8083"
environment:
CONNECT_BOOTSTRAP_SERVERS: 'broker:29092'
CONNECT_REST_ADVERTISED_HOST_NAME: connect
CONNECT_REST_PORT: 8083
CONNECT_GROUP_ID: compose-connect-group
CONNECT_CONFIG_STORAGE_TOPIC: docker-connect-configs
CONNECT_CONFIG_STORAGE_REPLICATION_FACTOR: 1
CONNECT_OFFSET_FLUSH_INTERVAL_MS: 10000
CONNECT_OFFSET_STORAGE_TOPIC: docker-connect-offsets
CONNECT_OFFSET_STORAGE_REPLICATION_FACTOR: 1
CONNECT_STATUS_STORAGE_TOPIC: docker-connect-status
CONNECT_STATUS_STORAGE_REPLICATION_FACTOR: 1
CONNECT_KEY_CONVERTER: org.apache.kafka.connect.storage.StringConverter
CONNECT_VALUE_CONVERTER: io.confluent.connect.avro.AvroConverter
CONNECT_VALUE_CONVERTER_SCHEMA_REGISTRY_URL: http://schema-registry:8081
CONNECT_INTERNAL_KEY_CONVERTER: "org.apache.kafka.connect.json.JsonConverter"
CONNECT_INTERNAL_VALUE_CONVERTER: "org.apache.kafka.connect.json.JsonConverter"
CONNECT_ZOOKEEPER_CONNECT: 'zookeeper:2181'
# CLASSPATH required due to CC-2422
CLASSPATH: /usr/share/java/monitoring-interceptors/monitoring-interceptors-5.4.0.jar
CONNECT_PRODUCER_INTERCEPTOR_CLASSES: "io.confluent.monitoring.clients.interceptor.MonitoringProducerInterceptor"
CONNECT_CONSUMER_INTERCEPTOR_CLASSES: "io.confluent.monitoring.clients.interceptor.MonitoringConsumerInterceptor"
CONNECT_PLUGIN_PATH: "/usr/share/java,/usr/share/confluent-hub-components"
CONNECT_LOG4J_LOGGERS: org.apache.zookeeper=ERROR,org.I0Itec.zkclient=ERROR,org.reflections=ERROR
control-center:
image: confluentinc/cp-enterprise-control-center:5.4.0
hostname: control-center
container_name: control-center
depends_on:
- zookeeper
- broker
- schema-registry
- connect
- ksql-server
ports:
- "9021:9021"
environment:
CONTROL_CENTER_BOOTSTRAP_SERVERS: 'broker:29092'
CONTROL_CENTER_ZOOKEEPER_CONNECT: 'zookeeper:2181'
CONTROL_CENTER_CONNECT_CLUSTER: 'connect:8083'
CONTROL_CENTER_KSQL_URL: "http://ksql-server:8088"
CONTROL_CENTER_KSQL_ADVERTISED_URL: "http://localhost:8088"
CONTROL_CENTER_SCHEMA_REGISTRY_URL: "http://schema-registry:8081"
CONTROL_CENTER_REPLICATION_FACTOR: 1
CONTROL_CENTER_INTERNAL_TOPICS_PARTITIONS: 1
CONTROL_CENTER_MONITORING_INTERCEPTOR_TOPIC_PARTITIONS: 1
CONFLUENT_METRICS_TOPIC_REPLICATION: 1
PORT: 9021
ksql-server:
image: confluentinc/cp-ksql-server:5.4.0
hostname: ksql-server
container_name: ksql-server
depends_on:
- broker
- connect
ports:
- "8088:8088"
environment:
KSQL_CONFIG_DIR: "/etc/ksql"
KSQL_LOG4J_OPTS: "-Dlog4j.configuration=file:/etc/ksql/log4j-rolling.properties"
KSQL_BOOTSTRAP_SERVERS: "broker:29092"
KSQL_HOST_NAME: ksql-server
KSQL_LISTENERS: "http://0.0.0.0:8088"
KSQL_CACHE_MAX_BYTES_BUFFERING: 0
KSQL_KSQL_SCHEMA_REGISTRY_URL: "http://schema-registry:8081"
KSQL_PRODUCER_INTERCEPTOR_CLASSES: "io.confluent.monitoring.clients.interceptor.MonitoringProducerInterceptor"
KSQL_CONSUMER_INTERCEPTOR_CLASSES: "io.confluent.monitoring.clients.interceptor.MonitoringConsumerInterceptor"
ksql-cli:
image: confluentinc/cp-ksql-cli:5.4.0
container_name: ksql-cli
depends_on:
- broker
- connect
- ksql-server
entrypoint: /bin/sh
tty: true
ksql-datagen:
# Downrev ksql-examples to 5.1.2 due to DEVX-798 (work around issues in 5.2.0)
image: confluentinc/ksql-examples:5.4.0
hostname: ksql-datagen
container_name: ksql-datagen
depends_on:
- ksql-server
- broker
- schema-registry
- connect
command: "bash -c 'echo Waiting for Kafka to be ready... && \
cub kafka-ready -b broker:29092 1 40 && \
echo Waiting for Confluent Schema Registry to be ready... && \
cub sr-ready schema-registry 8081 40 && \
echo Waiting a few seconds for topic creation to finish... && \
sleep 11 && \
tail -f /dev/null'"
environment:
KSQL_CONFIG_DIR: "/etc/ksql"
KSQL_LOG4J_OPTS: "-Dlog4j.configuration=file:/etc/ksql/log4j-rolling.properties"
STREAMS_BOOTSTRAP_SERVERS: broker:29092
STREAMS_SCHEMA_REGISTRY_HOST: schema-registry
STREAMS_SCHEMA_REGISTRY_PORT: 8081
rest-proxy:
image: confluentinc/cp-kafka-rest:5.4.0
depends_on:
- zookeeper
- broker
- schema-registry
ports:
- 8082:8082
hostname: rest-proxy
container_name: rest-proxy
environment:
KAFKA_REST_HOST_NAME: rest-proxy
KAFKA_REST_BOOTSTRAP_SERVERS: 'broker:29092'
KAFKA_REST_LISTENERS: "http://0.0.0.0:8082"
KAFKA_REST_SCHEMA_REGISTRY_URL: 'http://schema-registry:8081'
rest-proxy:
build: ./Users/.
ports:
- 7777:7777
hostname: users-service
container_name: users-service