Skip to content
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
6 changes: 3 additions & 3 deletions api/cmd/midas-api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

func main() {
ctx := context.Background()
cfg := config.NewApiConfig()
cfg := config.NewAPIConfig()
l := logger.NewLogger(&cfg.LoggerConfig)

if err := run(ctx, cfg, l); err != nil {
Expand All @@ -22,8 +22,8 @@ func main() {
}
}

func run(ctx context.Context, cfg *config.ApiConfig, l *logger.Logger) (err error) {
h, err := handler.NewApi(ctx, cfg, l)
func run(ctx context.Context, cfg *config.APIConfig, l *logger.Logger) (err error) {
h, err := handler.NewAPI(ctx, cfg, l)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions api/cmd/midas-sql/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ func main() {
}

func migrateDBConfig(cfg *config.MigrateConfig) migrate.DBConfig {
dbUrl := strings.TrimPrefix(cfg.DBUrl, "jdbc:postgresql://")
DBUrl := strings.TrimPrefix(cfg.DBUrl, "jdbc:postgresql://")

dd := strings.Split(dbUrl, "/")
dd := strings.Split(DBUrl, "/")

if len(dd) == 0 {
log.Fatal("invalid database url")
Expand Down
7 changes: 4 additions & 3 deletions api/internal/alertscheduler/alertscheduler.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package alertscheduler provides functionality to schedule alert notification jobs for submittals.
package alertscheduler

import (
Expand Down Expand Up @@ -41,7 +42,7 @@ func New(queuer pgqueue.PGQueueClient, dbtx db.DBTX, querier db.Querier, opts ..
return a
}

// JobAddForSubmittal adds a job to be scheduled for a Submittal and given NotificationType. It does not insert the job to the queue (see InsertJobs).
// PrepareSubmittalJob adds a job to be scheduled for a Submittal and given NotificationType. It does not insert the job to the queue (see InsertJobs).
//
// For each alert config id that is a "reminder" type, we want to ensure the job does not run more than once in a 24 hour period.
func (a *AlertScheduler) PrepareSubmittalJob(ctx context.Context, sub db.VSubmittal, nt dto.NotificationType) error {
Expand Down Expand Up @@ -84,7 +85,7 @@ func (a *AlertScheduler) PrepareSubmittalJob(ctx context.Context, sub db.VSubmit
return nil
}

// JobInsertForSubmittal inserts jobs added with JobAddForSubmittal into the queue. It does not commit the transaction.
// InsertPreparedSubmittalJobs inserts jobs added with JobAddForSubmittal into the queue. It does not commit the transaction.
func (a *AlertScheduler) InsertPreparedSubmittalJobs(ctx context.Context, sub db.VSubmittal) error {
if a.disabled || len(a.jobs) == 0 {
return nil
Expand Down Expand Up @@ -131,7 +132,7 @@ func (a *AlertScheduler) CancelJobsForAlertConfig(ctx context.Context, acID uuid
return nil
}

// SubmittalCreateWithAlertScheduleJobs creates a new submittal and schedules jobs for the alert config.
// SubmittalCreateAndPrepareJobs creates a new submittal and schedules jobs for the alert config.
//
// The new submittal due date is calculated based on the "createAt" date passed + the schedule interval.
// NOTE: Tx must be commited by the caller.
Expand Down
12 changes: 6 additions & 6 deletions api/internal/cloud/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
_ "gocloud.dev/pubsub/awssnssqs"
)

// ApiServices provides services for the API
type ApiServices struct {
// APIServices provides services for the API
type APIServices struct {
// MediaBucket reads and writes application media to and from a bucket
MediaBucket *blob.Bucket
// ReportTaskPub publishes report jobs to a queue that are sent to an async PDF report renderer
Expand All @@ -24,8 +24,8 @@ type ApiServices struct {
AlertEventBatcherSub *pubsub.Subscription
}

// NewApiServices creates a new ApiServices instance
func NewApiServices(ctx context.Context, cfg *config.ApiConfig) (*ApiServices, error) {
// NewAPIServices creates a new ApiServices instance
func NewAPIServices(ctx context.Context, cfg *config.APIConfig) (*APIServices, error) {
mediaBucket, err := blob.OpenBucket(ctx, cfg.MediaBucketURI)
if err != nil {
return nil, err
Expand All @@ -47,7 +47,7 @@ func NewApiServices(ctx context.Context, cfg *config.ApiConfig) (*ApiServices, e
return nil, err
}

return &ApiServices{
return &APIServices{
MediaBucket: mediaBucket,
ReportTaskPub: reportTaskPub,
AlertEventBatcherPub: alertEventBatcherPub,
Expand All @@ -56,7 +56,7 @@ func NewApiServices(ctx context.Context, cfg *config.ApiConfig) (*ApiServices, e
}

// Shutdown closes the ApiServices and its resources
func (s *ApiServices) Shutdown(ctx context.Context) error {
func (s *APIServices) Shutdown(ctx context.Context) error {
errs := make([]error, 0)
if a := s.MediaBucket; a != nil {
errs = append(errs, a.Close())
Expand Down
2 changes: 2 additions & 0 deletions api/internal/cloud/cloud.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Package cloud provides cloud-related utilities and abstractions.
package cloud
2 changes: 1 addition & 1 deletion api/internal/cloud/dcsloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (s *DcsLoaderServices) Shutdown(ctx context.Context) error {
return errors.Join(errs...)
}

// messageToS3Event converts a pubsub message to an S3 event
// MessageToS3Event converts a pubsub message to an S3 event
func MessageToS3Event(ctx context.Context, msg *pubsub.Message, l *logger.Logger) (events.S3Event, error) {
var evt events.S3Event

Expand Down
18 changes: 9 additions & 9 deletions api/internal/config/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"github.com/USACE/instrumentation-api/api/v4/internal/tz"
)

// Config stores configuration information stored in environment variables
type ApiConfig struct {
// APIConfig stores configuration information stored in environment variables
type APIConfig struct {
LoggerConfig
DBConfig
ServerConfig
Expand All @@ -25,23 +25,23 @@ type ApiConfig struct {
CwmsProxyURL string `env:"CWMS_PROXY_URL" envDefault:"https://cwms-data.usace.army.mil/cwms-data/"`
}

// GetConfig returns environment variable config
func NewApiConfig() *ApiConfig {
var cfg ApiConfig
// NewAPIConfig returns environment variable config
func NewAPIConfig() *APIConfig {
var cfg APIConfig
cfg.BuildTag = os.Getenv("BUILD_TAG")
if err := parsePrefix("INSTRUMENTATION_", &cfg); err != nil {
panic(err)
}

switch cfg.BuildTag {
case "local":
cfg.ServerBaseUrl = "http://localhost:8080"
cfg.ServerBaseURL = "http://localhost:8080"
case "develop":
cfg.ServerBaseUrl = "https://develop-midas-api.rsgis.dev"
cfg.ServerBaseURL = "https://develop-midas-api.rsgis.dev"
case "test":
cfg.ServerBaseUrl = "https://midas-test.cwbi.us/api"
cfg.ServerBaseURL = "https://midas-test.cwbi.us/api"
case "prod":
cfg.ServerBaseUrl = "https://midas.sec.usace.army.mil/api"
cfg.ServerBaseURL = "https://midas.sec.usace.army.mil/api"
default:
}

Expand Down
1 change: 1 addition & 0 deletions api/internal/config/config.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package config provides functionality to parse environment variables into configuration structs with a specified prefix.
package config

import (
Expand Down
2 changes: 1 addition & 1 deletion api/internal/config/dcsloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package config
// Note awsSQSQueueURL private variable. Public method is AWSSQSQueueURL()
type DcsLoaderConfig struct {
LoggerConfig
ApiHost string `env:"API_HOST"`
APIHost string `env:"API_HOST"`
APIKey string `env:"API_KEY"`
MaxConcurrentHandlers int `env:"MAX_CONCURRENT_HANDLERS" envDefault:"10"`
IncomingDataBucketURI string `env:"INCOMING_DATA_BUCKET_URI"`
Expand Down
2 changes: 1 addition & 1 deletion api/internal/config/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type ServerConfig struct {
ReportDownloadJobMocked bool `env:"REPORT_DOWNLOAD_JOB_MOCKED"`
RequestLoggerEnabled bool `env:"REQUEST_LOGGER_ENABLED"`
RoutePrefix string `env:"ROUTE_PREFIX"`
ServerBaseUrl string `env:"SERVER_BASE_URL"`
ServerBaseURL string `env:"SERVER_BASE_URL"`
StackSizeKB int `env:"STACK_SIZE_KB" envDefault:"1"`
AvailableTimezones []string
}
2 changes: 1 addition & 1 deletion api/internal/config/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package config
type TelemetryConfig struct {
LoggerConfig
ServerConfig
ApiHost string `env:"API_HOST"`
APIHost string `env:"API_HOST"`
}

func NewTelemetryConfig() *TelemetryConfig {
Expand Down
2 changes: 1 addition & 1 deletion api/internal/config/thinglogix.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package config
type ThinglogixConfig struct {
ThinglogixCognitoPool string `env:"THINGLOGIX_COGNITO_POOL"`
ThinglogixProviderName string `env:"THINGLOGIX_PROVIDER_NAME"`
ThinglogixApiGatewayEndpoint string `env:"THINGLOGIX_API_GATEWAY_ENDPOINT"`
ThinglogixAPIGatewayEndpoint string `env:"THINGLOGIX_API_GATEWAY_ENDPOINT"`
ThinglogixUser string `env:"THINGLOGIX_USER"`
ThinglogixPassword string `env:"THINGLOGIX_PASSWORD"`
ThinglogixAccountID string `env:"THINGLOGIX_ACCOUNT_ID"`
Expand Down
1 change: 1 addition & 0 deletions api/internal/ctxkey/ctxkey.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package ctxkey defines context keys used throughout the application.
package ctxkey

type ContextKey string
Expand Down
7 changes: 4 additions & 3 deletions api/internal/db/overrides.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package db

// database overrides for scanning json into nested structs
// Package db contains type-safe sql query bindings generated by sqlc
//
// This file contains database overrides for scanning json into nested structs
// see sqlc.generate.yaml overrides
package db

// NOTE: use internal FloatNanInf type instead of float64 to
// avoid errors with json.Marshal/Unmarshal with NaN and Inf values
Expand Down
2 changes: 2 additions & 0 deletions api/internal/dto/dto.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Package dto contains data transfer objects used to bind to request bodies.
package dto
2 changes: 2 additions & 0 deletions api/internal/dto/worker_alert_schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ type WorkerAlertCheckScheduleV1Args struct{}

func (WorkerAlertCheckScheduleV1Args) Kind() string { return "AlertCheckScheduleV1" }

// WorkerAlertCheckScheduleV2Args defines the arguments for the AlertCheckScheduleV2 worker.
//
// NotificationType and AlertConfigID are used as unique keys for the "reminder" NotificationType
// to ensure duplicate reminders are not sent for the same AlertConfigID.
type WorkerAlertCheckScheduleV2Args struct {
Expand Down
1 change: 1 addition & 0 deletions api/internal/email/ses/ses.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package ses provides an email client that sends emails using AWS Simple Email Service (SES).
package ses

import (
Expand Down
1 change: 1 addition & 0 deletions api/internal/email/smtp/smtp.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package smtp implements an email client that sends emails using the SMTP protocol.
package smtp

import (
Expand Down
2 changes: 1 addition & 1 deletion api/internal/handler/alert.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type AlertIDParam struct {
AlertID UUID `path:"alert_id"`
}

func (h *ApiHandler) RegisterAlert(api huma.API) {
func (h *APIHandler) RegisterAlert(api huma.API) {
huma.Register(api, huma.Operation{
Middlewares: h.Public,
OperationID: "alert-list-for-instrument",
Expand Down
2 changes: 1 addition & 1 deletion api/internal/handler/alert_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type AlertTypeParam struct {
AlertType string `path:"alert_type" example:"thresholds" oneOf:"thresholds,changes,"`
}

func (h *ApiHandler) RegisterAlertConfig(api huma.API) {
func (h *APIHandler) RegisterAlertConfig(api huma.API) {
registry := api.OpenAPI().Components.Schemas
// TODO: for now it's fine to use the DTO types, would prefer composite types over
// json if available: https://github.com/sqlc-dev/sqlc/issues/2760
Expand Down
2 changes: 1 addition & 1 deletion api/internal/handler/alert_subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type AlertSubscriptionIDParam struct {
AlertSubscriptionID UUID `path:"alert_subscription_id" example:"a7540f69-c41e-43b3-b655-6e44097edb7e"`
}

func (h *ApiHandler) RegisterAlertSubscription(api huma.API) {
func (h *APIHandler) RegisterAlertSubscription(api huma.API) {
huma.Register(api, huma.Operation{
Middlewares: h.Private,
Security: privateSecurity,
Expand Down
2 changes: 0 additions & 2 deletions api/internal/handler/alert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,6 @@ const alertConfigSchemaTemplate = `{

var alertConfigSchema = fmt.Sprintf(alertConfigSchemaTemplate, alertConfigTimeseriesSchema, alertConfigInstrumentSchema, alertConfigEmailSchema, alertConfigScheduleOptsSchema)

var alertConfigObjectLoader = gojsonschema.NewStringLoader(alertConfigSchema)

var alertConfigArrayLoader = gojsonschema.NewStringLoader(fmt.Sprintf(`{
"type": "array",
"items": %s
Expand Down
Loading