Compare commits

...

6 Commits

Author SHA1 Message Date
soukainna 5a67e2c377 fix aganda subscription 2024-10-30 09:16:16 +01:00
soukainna 0e42bd7f79 add id and fix err 2024-09-02 21:40:14 +02:00
Nicolas CARON 23c7b50d9b test actions
Build and Push Docker Image / build_and_push (push) Successful in 1m34s Details
2024-04-05 12:14:04 +02:00
Nicolas CARON 3028dde959 add .gitea/worflows/build.yml 2024-04-04 12:22:42 +02:00
mfrigo c71851add2 add Getsubscriber and getsubscriptionbyuser in comments for the moment to avoid crashing 2023-12-08 13:33:13 +01:00
mfrigo 86df552bd1 GetSubscriber in Mongodb 2023-12-06 16:12:29 +01:00
4 changed files with 154 additions and 6 deletions

View File

@ -0,0 +1,81 @@
name: Build and Push Docker Image
on:
push:
tags:
- '*'
branches:
- main
- dev
jobs:
build_and_push:
runs-on: ubuntu-latest
steps:
- name: Install Docker
run: |
apt-get update
apt-get install -y docker.io
- name: Checkout Repository
uses: actions/checkout@v4
- name: Set Kubernetes Context
uses: azure/k8s-set-context@v4
with:
method: kubeconfig
kubeconfig: ${{secrets.buildx_kubeconfig}}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
driver: kubernetes
driver-opts: |
namespace=gitea
- name: Login to Docker Registry
uses: docker/login-action@v3
with:
registry: git.coopgo.io
username: ${{ secrets.REGISTRY_USER }}
password: ${{ secrets.REGISTRY_TOKEN }}
- name: Extract metadata (tags, labels) for Docker image
id: metadata
uses: docker/metadata-action@v3
with:
images: git.coopgo.io/${{gitea.repository}}
tags: |
type=ref,event=branch
type=ref,event=tag
type=ref,event=pr
flavor: |
latest=auto
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: |
${{ steps.metadata.outputs.tags }}
build-args: |
ACCESS_TOKEN_USR=${{gitea.actor}}
ACCESS_TOKEN_PWD=${{gitea.token}}
# BUILD WITH KANIKO
# - name: Kaniko build and push
# uses: aevea/action-kaniko@master
# with:
# build_file: Dockerfile
# registry: git.coopgo.io
# username: ${{secrets.registry_user}}
# password: ${{secrets.registry_token}}
# image: ${{gitea.repository}}
# tag: ${{gitea.ref_name}}
# cache: true
# cache_registry: git.coopgo.io/${{gitea.repository}}/cache
# extra-args: |
# ACCESS_TOKEN_USR=${{gitea.actor}}
# ACCESS_TOKEN_PWD=${{gitea.token}}

View File

@ -59,6 +59,7 @@ func (h AgendaHandler) SubscribeEvent(eventid string, subscriber string, data ma
subscription := storage.Subscription{
ID: id,
Subscriber: subscriber,
EventID: eventid,
Tags: []string{},
CreatedAt: now,
Data: map[string]any{},
@ -80,6 +81,7 @@ func (h AgendaHandler) DeleteSubscription(eventid string, subscriber string, dat
deletesubscription := storage.Subscription{
ID: id,
Subscriber: subscriber,
EventID: eventid,
Tags: []string{},
CreatedAt: now,
Data: map[string]any{},
@ -101,6 +103,17 @@ func (h AgendaHandler) UpdateEvent(event storage.Event) (*storage.Event, error)
return &event, nil
}
func (h AgendaHandler) GetSubscriber(subscriber string) (results []storage.Subscription, err error) {
if subscriber == "" {
return nil, errors.New("missing subscriber")
}
results, err = h.storage.GetSubscriber(subscriber)
if err != nil {
return nil, err
}
return results, nil
}
func (h AgendaHandler) GetSubscriptionByUser(subscriber string) (results []storage.Subscription, err error) {
if subscriber == "" {
return nil, errors.New("missing subscriber")

View File

@ -98,8 +98,6 @@ func (s MongoDBStorage) GetEvents(namespaces []string) (events []Event, err erro
return events, err
}
// fmt.Println(elem)
// bsonBytes, _ := bson.Marshal(elem)
// fmt.Println(string(bsonBytes))
// bson.Unmarshal(bsonBytes, &event)
@ -154,10 +152,65 @@ func (s MongoDBStorage) UpdateEvent(event Event) error {
return nil
}
func (psql MongoDBStorage) GetSubscriber(subscriber string) ([]Subscription, error) {
return nil, nil
func (s MongoDBStorage) GetSubscriber(subscriber string) ([]Subscription, error) {
collection := s.Client.Database(s.DbName).Collection(s.Collections["events"])
subscriptions := []Subscription{}
var cur *mongo.Cursor
// findOptions := options.Find()
// cur, err := collection.Find(context.TODO(), bson.M{"subscriptions": subscriber}, findOptions)
cur, err := collection.Find(context.TODO(), bson.M{"subscriptions": bson.M{"$elemMatch": bson.M{"subscriber": subscriber}}})
if err != nil {
return subscriptions, err
}
for cur.Next(context.Background()) {
var event Event
if err := cur.Decode(&event); err != nil {
return subscriptions, err
}
for i := range event.Subscriptions {
if event.Subscriptions[i].Subscriber == subscriber {
subscriptions = append(subscriptions, event.Subscriptions[i])
}
}
}
fmt.Println(subscriptions)
return subscriptions, nil
//return nil, nil
// if err != nil {
// return subscriptions, err
// }
// for cur.Next(context.TODO()) {
// var event Event
// var elem bson.M
// if err := cur.Decode(&elem); err != nil {
// return subscriptions, err
// }
// for i := range event.Subscriptions {
// if event.Subscriptions[i].Subscriber == subscriber {
// subscriptions = append(subscriptions, event.Subscriptions[i])
// }
// }
// // bsonBytes, _ := bson.Marshal(elem)
// // bson.Unmarshal(bsonBytes, &event)
// // subscriptions = append(subscriptions, event.Subscriptions[1])
// }
// return subscriptions, nil
}
func (psql MongoDBStorage) GetSubscriptionByUser(subscriber string) ([]Subscription, error) {
return nil, nil
func (s MongoDBStorage) GetSubscriptionByUser(subscriber string) ([]Subscription, error) {
events, err := s.GetSubscriber(subscriber)
if err != nil {
panic(err)
}
fmt.Println(events)
return events, nil
//return nil, nil
}

View File

@ -13,6 +13,7 @@ type Storage interface {
AddSubscription(eventid string, subscription Subscription) error
UpdateSubscription(eventid string, subscriber string, deletesubscription Subscription) error
UpdateEvent(Event) error
GetSubscriber(subscriber string) ([]Subscription, error)
GetSubscriptionByUser(subscriber string) ([]Subscription, error)
}
type StorageImpl struct {