@@ -28,16 +28,10 @@ type repositoryConfigDaoImpl struct {
2828 db * gorm.DB
2929 yumRepo yum.YumRepository
3030 pulpClient pulp_client.PulpClient
31+ ctx context.Context
3132}
3233
33- func GetRepositoryConfigDao (db * gorm.DB ) RepositoryConfigDao {
34- return & repositoryConfigDaoImpl {
35- db : db ,
36- yumRepo : & yum.Repository {},
37- }
38- }
39-
40- func GetRepositoryConfigDaoWithPulpClient (db * gorm.DB , pulpClient pulp_client.PulpClient ) RepositoryConfigDao {
34+ func GetRepositoryConfigDao (db * gorm.DB , pulpClient pulp_client.PulpClient ) RepositoryConfigDao {
4135 return & repositoryConfigDaoImpl {
4236 db : db ,
4337 yumRepo : & yum.Repository {},
@@ -79,20 +73,10 @@ func DBErrorToApi(e error) *ce.DaoError {
7973 }
8074}
8175
82- func (r * repositoryConfigDaoImpl ) InitializePulpClient (ctx context.Context , orgID string ) error {
83- if ! config .Get ().Features .Snapshots .Enabled {
84- return nil
85- }
86-
87- dDao := GetDomainDao (r .db )
88- domainName , err := dDao .Fetch (orgID )
89- if err != nil {
90- return err
91- }
92-
93- pulpClient := pulp_client .GetPulpClientWithDomain (context .TODO (), domainName )
94- r .pulpClient = pulpClient
95- return nil
76+ func (r * repositoryConfigDaoImpl ) WithContext (ctx context.Context ) RepositoryConfigDao {
77+ cpy := * r
78+ cpy .ctx = ctx
79+ return & cpy
9680}
9781
9882func (r repositoryConfigDaoImpl ) Create (newRepoReq api.RepositoryRequest ) (api.RepositoryResponse , error ) {
@@ -265,7 +249,6 @@ func (r repositoryConfigDaoImpl) List(
265249) (api.RepositoryCollectionResponse , int64 , error ) {
266250 var totalRepos int64
267251 repoConfigs := make ([]models.RepositoryConfiguration , 0 )
268- var err error
269252 var contentPath string
270253
271254 filteredDB := r .filteredDbForList (OrgID , r .db , filterData )
@@ -304,8 +287,14 @@ func (r repositoryConfigDaoImpl) List(
304287 return api.RepositoryCollectionResponse {}, totalRepos , filteredDB .Error
305288 }
306289
307- if r .pulpClient != nil && config .Get ().Features .Snapshots .Enabled {
308- contentPath , err = r .pulpClient .GetContentPath ()
290+ if config .Get ().Features .Snapshots .Enabled {
291+ dDao := domainDaoImpl {db : r .db }
292+ domain , err := dDao .Fetch (OrgID )
293+ if err != nil {
294+ return api.RepositoryCollectionResponse {}, totalRepos , err
295+ }
296+
297+ contentPath , err = r .pulpClient .WithContext (r .ctx ).WithDomain (domain ).GetContentPath ()
309298 if err != nil {
310299 return api.RepositoryCollectionResponse {}, totalRepos , err
311300 }
@@ -404,10 +393,12 @@ func (r repositoryConfigDaoImpl) Fetch(orgID string, uuid string) (api.Repositor
404393 ModelToApiFields (repoConfig , & repo )
405394
406395 if repoConfig .LastSnapshot != nil && config .Get ().Features .Snapshots .Enabled {
407- if r .pulpClient == nil {
408- return api.RepositoryResponse {}, fmt .Errorf ("pulpClient cannot be nil" )
396+ dDao := domainDaoImpl {db : r .db }
397+ domainName , err := dDao .Fetch (orgID )
398+ if err != nil {
399+ return api.RepositoryResponse {}, err
409400 }
410- contentPath , err := r .pulpClient .GetContentPath ()
401+ contentPath , err := r .pulpClient .WithContext ( r . ctx ). WithDomain ( domainName ). GetContentPath ()
411402 if err != nil {
412403 return api.RepositoryResponse {}, err
413404 }
0 commit comments