-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
152 changed files
with
3,292 additions
and
3,238 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ runs: | |
- uses: actions/checkout@v4 | ||
- name: check cache | ||
id: cache | ||
uses: actions/cache@v4 | ||
uses: ubicloud/cache@v4 | ||
with: | ||
path: | | ||
./flow/generated/protos | ||
|
@@ -17,10 +17,12 @@ runs: | |
- if: steps.cache.outputs.cache-hit != 'true' | ||
uses: actions/setup-go@v5 | ||
with: | ||
go-version: '1.22.3' | ||
go-version: '1.22.5' | ||
cache: false | ||
- if: steps.cache.outputs.cache-hit != 'true' | ||
uses: bufbuild/[email protected] | ||
with: | ||
github_token: ${{ github.token }} | ||
- if: steps.cache.outputs.cache-hit != 'true' | ||
uses: dtolnay/rust-toolchain@stable | ||
- if: steps.cache.outputs.cache-hit != 'true' | ||
|
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
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,83 @@ | ||
package cmd | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/jackc/pgx/v5" | ||
|
||
"github.com/PeerDB-io/peer-flow/generated/protos" | ||
"github.com/PeerDB-io/peer-flow/peerdbenv" | ||
"github.com/PeerDB-io/peer-flow/shared" | ||
) | ||
|
||
func (h *FlowRequestHandler) GetAlertConfigs(ctx context.Context, req *protos.GetAlertConfigsRequest) (*protos.GetAlertConfigsResponse, error) { | ||
rows, err := h.pool.Query(ctx, "select id, service_type, service_config, enc_key_id from peerdb_stats.alerting_config") | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
configs, err := pgx.CollectRows(rows, func(row pgx.CollectableRow) (*protos.AlertConfig, error) { | ||
var serviceConfigPayload []byte | ||
var encKeyID string | ||
config := &protos.AlertConfig{} | ||
if err := row.Scan(&config.Id, &config.ServiceType, &serviceConfigPayload, &encKeyID); err != nil { | ||
return nil, err | ||
} | ||
serviceConfig, err := peerdbenv.Decrypt(encKeyID, serviceConfigPayload) | ||
if err != nil { | ||
return nil, err | ||
} | ||
config.ServiceConfig = string(serviceConfig) | ||
return config, nil | ||
}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &protos.GetAlertConfigsResponse{Configs: configs}, nil | ||
} | ||
|
||
func (h *FlowRequestHandler) PostAlertConfig(ctx context.Context, req *protos.PostAlertConfigRequest) (*protos.PostAlertConfigResponse, error) { | ||
key, err := peerdbenv.PeerDBCurrentEncKey() | ||
if err != nil { | ||
return nil, err | ||
} | ||
serviceConfig, err := key.Encrypt(shared.UnsafeFastStringToReadOnlyBytes(req.ServiceConfig)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if req.Id == -1 { | ||
var id int32 | ||
if err := h.pool.QueryRow( | ||
ctx, | ||
"insert into peerdb_stats.alerting_config (service_type, service_config, enc_key_id) values ($1, $2, $3) returning id", | ||
req.ServiceType, | ||
serviceConfig, | ||
key.ID, | ||
).Scan(&id); err != nil { | ||
return nil, err | ||
} | ||
return &protos.PostAlertConfigResponse{Id: id}, nil | ||
} else if _, err := h.pool.Exec( | ||
ctx, | ||
"update peerdb_stats.alerting_config set service_type = $1, service_config = $2, enc_key_id = $3 where id = $4", | ||
req.ServiceType, | ||
serviceConfig, | ||
key.ID, | ||
req.Id, | ||
); err != nil { | ||
return nil, err | ||
} | ||
return &protos.PostAlertConfigResponse{Id: req.Id}, nil | ||
} | ||
|
||
func (h *FlowRequestHandler) DeleteAlertConfig( | ||
ctx context.Context, | ||
req *protos.DeleteAlertConfigRequest, | ||
) (*protos.DeleteAlertConfigResponse, error) { | ||
if _, err := h.pool.Exec(ctx, "delete from peerdb_stats.alerting_config where id = $1", req.Id); err != nil { | ||
return nil, err | ||
} | ||
return &protos.DeleteAlertConfigResponse{}, nil | ||
} |
Oops, something went wrong.