-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from AlertFlow/release/1.0.0-beta9
Release Version 1.0.0 beta9
- Loading branch information
Showing
34 changed files
with
512 additions
and
302 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package auth | ||
|
||
import ( | ||
"alertflow-backend/models" | ||
"time" | ||
|
||
"github.com/golang-jwt/jwt/v5" | ||
"github.com/google/uuid" | ||
) | ||
|
||
func GenerateProjectAutoRunnerJWT(projectID string, id uuid.UUID) (tokenString string, err error) { | ||
expirationTime := time.Now().Add(50 * 365 * 24 * time.Hour) // 10 years | ||
claims := &models.JWTProjectClaim{ | ||
ProjectID: projectID, | ||
ID: id, | ||
Type: "project_auto_runner", | ||
RegisteredClaims: jwt.RegisteredClaims{ | ||
ExpiresAt: jwt.NewNumericDate(expirationTime), | ||
}, | ||
} | ||
token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims) | ||
tokenString, err = token.SignedString(jwtKey) | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
services/backend/functions/background_checks/checkDisconnectedAutoRunners.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package background_checks | ||
|
||
import ( | ||
"alertflow-backend/models" | ||
"context" | ||
"fmt" | ||
|
||
log "github.com/sirupsen/logrus" | ||
"github.com/uptrace/bun" | ||
) | ||
|
||
func checkDisconnectedAutoRunners(db *bun.DB) { | ||
context := context.Background() | ||
|
||
log.Info("Bot: Checking for disconnected runners") | ||
|
||
// get all executions that are not finished | ||
var runners []models.Runners | ||
err := db.NewSelect().Model(&runners).Where("last_heartbeat < NOW() - INTERVAL '30 minutes'").Scan(context) | ||
if err != nil { | ||
log.Error("Bot: Error getting running runners. ", err) | ||
} | ||
|
||
for _, runner := range runners { | ||
log.Info(fmt.Sprintf("Bot: Runner %s seems to be not connected anymore. Removing it", runner.ID)) | ||
_, err := db.NewDelete().Model(&runner).Where("id = ?", runner.ID).Exec(context) | ||
if err != nil { | ||
log.Error(fmt.Sprintf("Bot: Error removing runner %s. ", runner.ID), err) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
services/backend/functions/runner/generate_project_auto_join_token.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package functions_runner | ||
|
||
import ( | ||
"alertflow-backend/functions/auth" | ||
"alertflow-backend/models" | ||
"context" | ||
"time" | ||
|
||
"github.com/google/uuid" | ||
"github.com/uptrace/bun" | ||
) | ||
|
||
func GenerateProjectAutoJoinToken(projectID string, db *bun.DB) (token string, err error) { | ||
var key models.Tokens | ||
|
||
key.ID = uuid.New() | ||
key.CreatedAt = time.Now() | ||
key.ProjectID = projectID | ||
key.Type = "project_auto_runner" | ||
key.Description = "Token for Project Auto Runner Join" | ||
|
||
key.Key, err = auth.GenerateProjectAutoRunnerJWT(projectID, key.ID) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
_, err = db.NewInsert().Model(&key).Exec(context.Background()) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
return key.Key, nil | ||
} |
33 changes: 33 additions & 0 deletions
33
services/backend/functions/runner/generate_runner_token.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package functions_runner | ||
|
||
import ( | ||
"alertflow-backend/functions/auth" | ||
"alertflow-backend/models" | ||
"context" | ||
"time" | ||
|
||
"github.com/google/uuid" | ||
"github.com/uptrace/bun" | ||
) | ||
|
||
func GenerateRunnerToken(projectID string, runnerID string, db *bun.DB) (token string, err error) { | ||
var key models.Tokens | ||
|
||
key.ID = uuid.New() | ||
key.CreatedAt = time.Now() | ||
key.ProjectID = projectID | ||
key.Type = "runner" | ||
key.Description = "Token for runner " + runnerID | ||
|
||
key.Key, err = auth.GenerateRunnerJWT(runnerID, projectID, key.ID) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
_, err = db.NewInsert().Model(&key).Exec(context.Background()) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
return key.Key, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.