Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore:file name linting #239

Merged
merged 7 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@ jobs:
- run: bash server/api/installBuf.bash
- name: pre-commit
uses: pre-commit/[email protected]
- uses: ls-lint/[email protected]
with:
config: .ls-lint.yaml
8 changes: 8 additions & 0 deletions .ls-lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
ls:
.dir: lowercase
.pb.gw.go: snake_case
.pb.go: snake_case
.go: snake_case

ignore:
- swagger
2 changes: 1 addition & 1 deletion client/localServer/client.go → client/local/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (

const (
localAddress = "127.0.0.1:50051"
testImage = "./localServer/images/sampleimage.jpeg"
testImage = "./local/images/sampleimage.jpeg"
)

// main connects to a seperatly started local server and creates ratings for both, canteens and dishes.
Expand Down
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions server/backend/cron/cronjobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package cron
import (
"time"

"github.com/TUM-Dev/Campus-Backend/server/backend/ios_notifications/ios_apns"
"github.com/TUM-Dev/Campus-Backend/server/backend/ios_notifications/apns"
"github.com/TUM-Dev/Campus-Backend/server/env"

"github.com/TUM-Dev/Campus-Backend/server/model"
Expand All @@ -16,7 +16,7 @@ import (
type CronService struct {
db *gorm.DB
gf *gofeed.Parser
APNs *ios_apns.Service
APNs *apns.Service
}

const StorageDir = "/Storage/" // target location of files
Expand All @@ -41,7 +41,7 @@ func New(db *gorm.DB) *CronService {
return &CronService{
db: db,
gf: gofeed.NewParser(),
APNs: ios_apns.NewCronService(db),
APNs: apns.NewCronService(db),
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
package cron

import (
"github.com/TUM-Dev/Campus-Backend/server/backend/ios_notifications/ios_device"
"github.com/TUM-Dev/Campus-Backend/server/backend/ios_notifications/ios_devices_activity_reset"
"github.com/TUM-Dev/Campus-Backend/server/backend/ios_notifications/ios_scheduled_update_log"
"github.com/TUM-Dev/Campus-Backend/server/backend/ios_notifications/ios_scheduling"
"github.com/TUM-Dev/Campus-Backend/server/backend/ios_notifications/device"
"github.com/TUM-Dev/Campus-Backend/server/backend/ios_notifications/devices_activity_reset"
"github.com/TUM-Dev/Campus-Backend/server/backend/ios_notifications/scheduled_update_log"
"github.com/TUM-Dev/Campus-Backend/server/backend/ios_notifications/scheduling"
)

// Starts the cron job for sending iOS notifications reuses
// the APNs client (ios_apns.Service) stored in CronService
// the APNs client (apns.Service) stored in CronService
func (c *CronService) iosNotificationsCron() error {
if !c.APNs.IsActive {
return nil
}

repo := ios_scheduling.NewRepository(c.db)
devicesRepo := ios_device.NewRepository(c.db)
schedulerRepo := ios_scheduled_update_log.NewRepository(c.db)
repo := scheduling.NewRepository(c.db)
devicesRepo := device.NewRepository(c.db)
schedulerRepo := scheduled_update_log.NewRepository(c.db)

service := ios_scheduling.NewService(repo, devicesRepo, schedulerRepo, c.APNs)
service := scheduling.NewService(repo, devicesRepo, schedulerRepo, c.APNs)

return service.HandleScheduledCron()
}

// Resets the activity of all devices to 0 every day, week, month or year
func (c *CronService) iosActivityReset() error {
service := ios_devices_activity_reset.NewService(c.db)
service := devices_activity_reset.NewService(c.db)

return service.HandleScheduledActivityReset()
}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package cron

import (
"github.com/TUM-Dev/Campus-Backend/server/backend/ios_notifications/ios_device"
"github.com/TUM-Dev/Campus-Backend/server/backend/ios_notifications/device"
"github.com/TUM-Dev/Campus-Backend/server/backend/new_exam_results_hook/new_exam_results_scheduling"
)

func (c *CronService) newExamResultsHookCron() error {
repo := new_exam_results_scheduling.NewRepository(c.db)
devicesRepo := ios_device.NewRepository(c.db)
devicesRepo := device.NewRepository(c.db)

service := new_exam_results_scheduling.NewService(repo, devicesRepo, c.APNs)

Expand Down
41 changes: 0 additions & 41 deletions server/backend/iosNotifications.go

This file was deleted.

40 changes: 40 additions & 0 deletions server/backend/ios_notifications.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package backend

import (
"context"

pb "github.com/TUM-Dev/Campus-Backend/server/api/tumdev"
"github.com/TUM-Dev/Campus-Backend/server/backend/ios_notifications/apns"
"github.com/TUM-Dev/Campus-Backend/server/backend/ios_notifications/device"
"github.com/TUM-Dev/Campus-Backend/server/backend/ios_notifications/request_response"
"gorm.io/gorm"
)

type IOSNotificationsService struct {
DB *gorm.DB
APNSToken *apns.JWTToken
IsActive bool
}

func (s *CampusServer) GetIOSDeviceService() *device.Service {
repository := device.NewRepository(s.db)

return device.NewService(repository)
}

func (s *CampusServer) GetIOSAPNsService() *apns.Service {
repository := apns.NewRepository(s.db, s.GetIOSNotificationsService().APNSToken)

return apns.NewService(repository)
}

func (s *CampusServer) GetIOSRequestResponseService() *request_response.Service {
repository := request_response.NewRepository(s.db, s.GetIOSNotificationsService().APNSToken)

return request_response.NewService(repository)
}

func (s *CampusServer) IOSDeviceRequestResponse(_ context.Context, req *pb.IOSDeviceRequestResponseRequest) (*pb.IOSDeviceRequestResponseReply, error) {
service := s.GetIOSRequestResponseService()
return service.HandleDeviceRequestResponse(req, s.iOSNotificationsService.IsActive)
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Package ios_apns_jwt handles the generation and validation of the JWT token for the APNs service
package ios_apns_jwt
// Package apns handles the generation and validation of the JWT token for the APNs service
package apns

import (
"crypto/ecdsa"
Expand Down Expand Up @@ -29,7 +29,7 @@ var (
ApnsP8FilePath = os.Getenv("APNS_P8_FILE_PATH")
)

type Token struct {
type JWTToken struct {
sync.Mutex
EncryptionKey *ecdsa.PrivateKey
KeyId string
Expand All @@ -38,13 +38,13 @@ type Token struct {
Bearer string
}

func NewToken() (*Token, error) {
func NewToken() (*JWTToken, error) {
encryptionKey, err := APNsEncryptionKeyFromFile()
if err != nil {
return nil, err
}

token := Token{
token := JWTToken{
EncryptionKey: encryptionKey,
KeyId: ApnsKeyId,
TeamId: ApnsTeamId,
Expand Down Expand Up @@ -99,7 +99,7 @@ func APNsEncryptionKeyFromFile() (*ecdsa.PrivateKey, error) {
return nil, ErrorAuthKeyNotEcdsa
}

func (t *Token) GenerateNewTokenIfExpired() (bearer string) {
func (t *JWTToken) GenerateNewTokenIfExpired() (bearer string) {
t.Lock()
defer t.Unlock()

Expand All @@ -113,11 +113,11 @@ func (t *Token) GenerateNewTokenIfExpired() (bearer string) {
return t.Bearer
}

func (t *Token) IsExpired() bool {
func (t *JWTToken) IsExpired() bool {
return currentTimestamp() >= (t.IssuedAt + TokenTimeout)
}

func (t *Token) Generate() error {
func (t *JWTToken) Generate() error {
if t.EncryptionKey == nil {
return ErrorAuthKeyNil
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ios_apns
package apns

import (
"bytes"
Expand All @@ -9,7 +9,6 @@ import (
"strconv"
"time"

"github.com/TUM-Dev/Campus-Backend/server/backend/ios_notifications/ios_apns/ios_apns_jwt"
"github.com/TUM-Dev/Campus-Backend/server/env"
"github.com/TUM-Dev/Campus-Backend/server/model"
log "github.com/sirupsen/logrus"
Expand Down Expand Up @@ -38,7 +37,7 @@ var (

type Repository struct {
DB gorm.DB
Token *ios_apns_jwt.Token
Token *JWTToken
httpClient *http.Client
}

Expand Down Expand Up @@ -117,7 +116,7 @@ func (r *Repository) SendNotification(notification *model.IOSNotificationPayload
return &response, nil
}

func NewRepository(db *gorm.DB, token *ios_apns_jwt.Token) *Repository {
func NewRepository(db *gorm.DB, token *JWTToken) *Repository {
transport := &http2.Transport{
ReadIdleTimeout: ReadIdleTimeout,
}
Expand All @@ -138,7 +137,7 @@ func NewCronRepository(db *gorm.DB) (*Repository, error) {
return nil, err
}

token, err := ios_apns_jwt.NewToken()
token, err := NewToken()
if err != nil {
log.WithError(err).Error("Could not create APNs token")
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
// Package ios_apns contains the logic for sending push notifications to iOS devices.
// Package apns contains the logic for sending push notifications to iOS devices.
// and communicating with the Apple Push Notification Service (APNs).
package ios_apns
package apns

import (
"errors"

"github.com/TUM-Dev/Campus-Backend/server/backend/ios_notifications/ios_apns/ios_apns_jwt"
"github.com/TUM-Dev/Campus-Backend/server/model"
log "github.com/sirupsen/logrus"
"gorm.io/gorm"
Expand Down Expand Up @@ -41,19 +40,19 @@ func (s *Service) RequestGradeUpdateForDevice(deviceID string) error {
}

func ValidateRequirementsForIOSNotificationsService() error {
if ios_apns_jwt.ApnsKeyId == "" {
if ApnsKeyId == "" {
return errors.New("APNS_KEY_ID env variable is not set")
}

if ios_apns_jwt.ApnsTeamId == "" {
if ApnsTeamId == "" {
return errors.New("APNS_TEAM_ID env variable is not set")
}

if ios_apns_jwt.ApnsP8FilePath == "" {
if ApnsP8FilePath == "" {
return errors.New("APNS_P8_FILE_PATH env variable is not set")
}

if _, err := ios_apns_jwt.APNsEncryptionKeyFromFile(); err != nil {
if _, err := APNsEncryptionKeyFromFile(); err != nil {
return errors.New("APNS P8 token is not valid or not set")
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Package ios_crypto provides functions for encrypting and decrypting strings using AES-256-GCM.
package ios_crypto
// Package crypto provides functions for encrypting and decrypting strings using AES-256-GCM.
package crypto

import (
"crypto/aes"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ios_device
package device

import (
"errors"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Package ios_device provides functions to register and remove ios devices
package ios_device
// Package device provides functions to register and remove ios devices
package device

import (
pb "github.com/TUM-Dev/Campus-Backend/server/api/tumdev"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ios_devices_activity_reset
package devices_activity_reset

import (
"time"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package ios_devices_activity_reset
package devices_activity_reset

import (
"time"

"github.com/TUM-Dev/Campus-Backend/server/backend/ios_notifications/ios_device"
"github.com/TUM-Dev/Campus-Backend/server/backend/ios_notifications/device"
log "github.com/sirupsen/logrus"
"gorm.io/gorm"
)
Expand Down Expand Up @@ -41,7 +41,7 @@ func (service *Service) HandleScheduledActivityReset() error {

now := time.Now()

devicesRepo := ios_device.NewRepository(service.Repository.DB)
devicesRepo := device.NewRepository(service.Repository.DB)

if now.Sub(daily.LastReset).Hours() > 24 {
if err := service.Repository.ResettedDevicesDaily(); err != nil {
Expand Down
Loading