-
Notifications
You must be signed in to change notification settings - Fork 22
/
dao_interfaces.go
126 lines (95 loc) · 5.67 KB
/
dao_interfaces.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// Package dao provides a Database Access Object interface to stored data.
//
// All functions require the following variables to be set in the context:
//
// * Logger: for all context-aware logging.
// * Account ID: for multi-tenancy, unless marked with UNSCOPED word.
//
// Functions marked as UNSCOPED can be safely used from contexts where there is
// exactly zero function arguments coming from an user (e.g. ID was retrieved via
// another DAO call that was scoped).
package dao
import (
"context"
"github.com/RHEnVision/provisioning-backend/internal/clients"
"github.com/RHEnVision/provisioning-backend/internal/models"
)
var GetAccountDao func(ctx context.Context) AccountDao
// AccountDao represents an account (tenant)
type AccountDao interface {
// Create is meant for integration tests, use GetOrCreateByIdentity instead.
Create(ctx context.Context, pk *models.Account) error
GetById(ctx context.Context, id int64) (*models.Account, error)
GetOrCreateByIdentity(ctx context.Context, orgId string, accountNumber string) (*models.Account, error)
GetByOrgId(ctx context.Context, orgId string) (*models.Account, error)
List(ctx context.Context, limit, offset int64) ([]*models.Account, error)
}
var GetPubkeyDao func(ctx context.Context) PubkeyDao
// PubkeyDao represents Pubkeys (public part of ssh key pair) and corresponding Resources (uploaded pubkeys
// to specific cloud providers in specific regions).
type PubkeyDao interface {
Create(ctx context.Context, pk *models.Pubkey) error
Update(ctx context.Context, pk *models.Pubkey) error
GetById(ctx context.Context, id int64) (*models.Pubkey, error)
List(ctx context.Context, limit, offset int64) ([]*models.Pubkey, error)
Count(ctx context.Context) (int, error)
Delete(ctx context.Context, id int64) error
UnscopedCreateResource(ctx context.Context, pkr *models.PubkeyResource) error
UnscopedGetResourceBySourceAndRegion(ctx context.Context, pubkeyId int64, sourceId string, region string) (*models.PubkeyResource, error)
UnscopedListResourcesByPubkeyId(ctx context.Context, pkId int64) ([]*models.PubkeyResource, error)
UnscopedDeleteResource(ctx context.Context, id int64) error
}
var GetReservationDao func(ctx context.Context) ReservationDao
// ReservationDao represents a reservation, an abstraction of one or more background jobs with
// associated detail information different for different cloud providers (like number of vCPUs,
// instance IDs created etc).
type ReservationDao interface {
// CreateNoop creates no operation reservation with details in a single transaction.
CreateNoop(ctx context.Context, reservation *models.NoopReservation) error
// CreateAWS creates AWS reservation with details in a single transaction.
CreateAWS(ctx context.Context, reservation *models.AWSReservation) error
// CreateAzure creates Azure reservation with details in a single transaction.
CreateAzure(ctx context.Context, reservation *models.AzureReservation) error
// CreateGCP creates GCP reservation with details in a single transaction.
CreateGCP(ctx context.Context, reservation *models.GCPReservation) error
// CreateInstance inserts instance associated to a reservation.
CreateInstance(ctx context.Context, reservation *models.ReservationInstance) error
// GetById returns reservation for a particular account.
GetById(ctx context.Context, id int64) (*models.Reservation, error)
// GetAWSById returns reservation for a particular account.
GetAWSById(ctx context.Context, id int64) (*models.AWSReservation, error)
// GetAzureById returns Azure reservation for a given id.
GetAzureById(ctx context.Context, id int64) (*models.AzureReservation, error)
// GetGCPById returns reservation for a particular account.
GetGCPById(ctx context.Context, id int64) (*models.GCPReservation, error)
// Count returns total reservations for a particular account.
Count(ctx context.Context) (int, error)
// List returns reservation for a particular account.
List(ctx context.Context, limit, offset int64) ([]*models.Reservation, error)
// ListInstances returns instances associated to a reservation. UNSCOPED.
// It currently lists all instances and not instances for a reservation, this is a TODO.
ListInstances(ctx context.Context, reservationId int64) ([]*models.ReservationInstance, error)
// UpdateStatus sets status field and increment step counter by addSteps. UNSCOPED.
UpdateStatus(ctx context.Context, id int64, status string, addSteps int32) error
// UnscopedUpdateAWSDetail updates details of the AWS reservation. UNSCOPED.
UnscopedUpdateAWSDetail(ctx context.Context, id int64, awsDetail *models.AWSDetail) error
// UpdateReservationIDForAWS updates AWS reservation id field. UNSCOPED.
UpdateReservationIDForAWS(ctx context.Context, id int64, awsReservationId string) error
// UpdateOperationNameForGCP updates GCP operation name field. UNSCOPED.
UpdateOperationNameForGCP(ctx context.Context, id int64, gcpOperationName string) error
// UpdateReservationInstance updates an instance with its description
UpdateReservationInstance(ctx context.Context, reservationID int64, instance *clients.InstanceDescription) error
// FinishWithSuccess sets Success flag. UNSCOPED.
FinishWithSuccess(ctx context.Context, id int64) error
// FinishWithError sets Success flag and Error flag. UNSCOPED.
FinishWithError(ctx context.Context, id int64, errorString string) error
// Delete deletes a reservation. Only used in tests and background cleanup job. UNSCOPED.
Delete(ctx context.Context, id int64) error
// Cleanup old reservations
Cleanup(ctx context.Context) error
}
var GetStatDao func(ctx context.Context) StatDao
// StatDao represents stats about the application run
type StatDao interface {
Get(ctx context.Context, delayMin int) (*models.Statistics, error)
}