@@ -93,12 +93,19 @@ func NewRepository(ctx context.Context, r db.Reader, w db.Writer, kms *kms.Kms,
93
93
// with its host source ids, credential source ids, and server certificate, if applicable. If the target is not
94
94
// found, it will return nil, nil.
95
95
// Supported option: WithAlias if the session authorization uses a target alias
96
- func (r * Repository ) LookupTargetForSessionAuthorization (ctx context.Context , publicId string , opt ... Option ) (Target , error ) {
96
+ func (r * Repository ) LookupTargetForSessionAuthorization (ctx context.Context , publicId string , projectId string , opt ... Option ) (Target , error ) {
97
97
const op = "target.(Repository).LookupTargetForSessionAuthorization"
98
98
opts := GetOpts (opt ... )
99
-
100
- if publicId == "" {
99
+ switch {
100
+ case publicId == "" :
101
101
return nil , errors .New (ctx , errors .InvalidParameter , op , "missing public id" )
102
+ case projectId == "" :
103
+ return nil , errors .New (ctx , errors .InvalidParameter , op , "missing project id" )
104
+ }
105
+
106
+ databaseWrapper , err := r .kms .GetWrapper (ctx , projectId , kms .KeyPurposeDatabase )
107
+ if err != nil {
108
+ return nil , errors .Wrap (ctx , err , op , errors .WithMsg ("unable to get database wrapper" ))
102
109
}
103
110
104
111
target := allocTargetView ()
@@ -107,7 +114,7 @@ func (r *Repository) LookupTargetForSessionAuthorization(ctx context.Context, pu
107
114
var hostSources []HostSource
108
115
var credSources []CredentialSource
109
116
var cert * ServerCertificate
110
- _ , err : = r .writer .DoTx (
117
+ _ , err = r .writer .DoTx (
111
118
ctx ,
112
119
db .StdRetryCnt ,
113
120
db.ExpBackoff {},
@@ -133,11 +140,6 @@ func (r *Repository) LookupTargetForSessionAuthorization(ctx context.Context, pu
133
140
address = targetAddress .GetAddress ()
134
141
}
135
142
136
- databaseWrapper , err := r .kms .GetWrapper (ctx , target .GetProjectId (), kms .KeyPurposeDatabase )
137
- if err != nil {
138
- return errors .Wrap (ctx , err , op , errors .WithMsg ("unable to get database wrapper" ))
139
- }
140
-
141
143
if opts .WithAlias != nil {
142
144
cert , err = fetchTargetAliasProxyServerCertificate (ctx , read , w , target .PublicId , target .ProjectId , opts .WithAlias , databaseWrapper , target .GetSessionMaxSeconds ())
143
145
if err != nil && ! errors .IsNotFoundError (err ) {
0 commit comments