@@ -22,8 +22,8 @@ const (
22
22
)
23
23
24
24
type ProjectManager interface {
25
- CreateProject (orgName string , projectName string , projectUUID string , project * nexus. RuntimeprojectRuntimeProject )
26
- DeleteProject (orgName string , projectName string , projectUUID string , project * nexus. RuntimeprojectRuntimeProject )
25
+ CreateProject (orgName string , projectName string , projectUUID string , project NexusProjectInterface )
26
+ DeleteProject (orgName string , projectName string , projectUUID string , project NexusProjectInterface )
27
27
}
28
28
29
29
type Hook struct {
@@ -65,12 +65,12 @@ func (h *Hook) Subscribe() error {
65
65
// API to subscribe and register a callback function that is invoked when a Project is added in the datamodel.
66
66
// Register*Callback() has the effect of subscription and also invoking a callback to the application code
67
67
// when there are datamodel changes to the objects of interest.
68
- if _ , err := h .nexusClient .TenancyMultiTenancy ().Runtime ().Orgs ("*" ).Folders ("*" ).Projects ("*" ).RegisterAddCallback (h .projectCreated ); err != nil {
68
+ if _ , err := h .nexusClient .TenancyMultiTenancy ().Runtime ().Orgs ("*" ).Folders ("*" ).Projects ("*" ).RegisterAddCallback (h .projectCreatedCallback ); err != nil {
69
69
log .Errorf ("Unable to register project creation callback: %+v" , err )
70
70
return err
71
71
}
72
72
73
- if _ , err := h .nexusClient .TenancyMultiTenancy ().Runtime ().Orgs ("*" ).Folders ("*" ).Projects ("*" ).RegisterUpdateCallback (h .projectUpdated ); err != nil {
73
+ if _ , err := h .nexusClient .TenancyMultiTenancy ().Runtime ().Orgs ("*" ).Folders ("*" ).Projects ("*" ).RegisterUpdateCallback (h .projectUpdatedCallback ); err != nil {
74
74
log .Errorf ("Unable to register project deletion callback: %+v" , err )
75
75
return err
76
76
}
@@ -119,7 +119,7 @@ func (h *Hook) setProjWatcherStatus(watcherObj *nexus.ProjectactivewatcherProjec
119
119
return nil
120
120
}
121
121
122
- func (h * Hook ) SetWatcherStatusIdle (proj * nexus. RuntimeprojectRuntimeProject ) error {
122
+ func (h * Hook ) SetWatcherStatusIdle (proj NexusProjectInterface ) error {
123
123
watcherObj , err := proj .GetActiveWatchers (context .Background (), appName )
124
124
if err == nil && watcherObj != nil {
125
125
// If watcher exists and is IDLE, simply return.
@@ -139,7 +139,7 @@ func (h *Hook) SetWatcherStatusIdle(proj *nexus.RuntimeprojectRuntimeProject) er
139
139
return err
140
140
}
141
141
142
- func (h * Hook ) SetWatcherStatusError (proj * nexus. RuntimeprojectRuntimeProject , message string ) error {
142
+ func (h * Hook ) SetWatcherStatusError (proj NexusProjectInterface , message string ) error {
143
143
watcherObj , err := proj .GetActiveWatchers (context .Background (), appName )
144
144
if err == nil && watcherObj != nil {
145
145
setStatusErr := h .setProjWatcherStatus (watcherObj , projectActiveWatcherv1 .StatusIndicationError , message )
@@ -152,7 +152,7 @@ func (h *Hook) SetWatcherStatusError(proj *nexus.RuntimeprojectRuntimeProject, m
152
152
return err
153
153
}
154
154
155
- func (h * Hook ) SetWatcherStatusInProgress (proj * nexus. RuntimeprojectRuntimeProject , message string ) error {
155
+ func (h * Hook ) SetWatcherStatusInProgress (proj NexusProjectInterface , message string ) error {
156
156
watcherObj , err := proj .GetActiveWatchers (context .Background (), appName )
157
157
log .Infof ("Setting watcher status to InProgress for project %s to %s" , proj .DisplayName (), message )
158
158
if err == nil && watcherObj != nil {
@@ -166,7 +166,7 @@ func (h *Hook) SetWatcherStatusInProgress(proj *nexus.RuntimeprojectRuntimeProje
166
166
return err
167
167
}
168
168
169
- func (h * Hook ) StopWatchingProject (project * nexus. RuntimeprojectRuntimeProject ) {
169
+ func (h * Hook ) StopWatchingProject (project NexusProjectInterface ) {
170
170
ctx , cancel := context .WithTimeout (context .Background (), nexusTimeout )
171
171
defer cancel ()
172
172
@@ -183,18 +183,23 @@ func (h *Hook) StopWatchingProject(project *nexus.RuntimeprojectRuntimeProject)
183
183
log .Infof ("Active watcher %s deleted for project %s" , appName , project .DisplayName ())
184
184
}
185
185
186
- func (h * Hook ) deleteProject (project * nexus. RuntimeprojectRuntimeProject ) {
186
+ func (h * Hook ) deleteProject (project NexusProjectInterface ) {
187
187
log .Infof ("Project: %+v marked for deletion" , project .DisplayName ())
188
188
189
189
organizationName := h .getOrganizationName (project )
190
- h .dispatcher .DeleteProject (organizationName , project .DisplayName (), string (project .UID ), project )
190
+ h .dispatcher .DeleteProject (organizationName , project .DisplayName (), project .GetUID (), project )
191
+ }
192
+
193
+ func (h * Hook ) projectCreatedCallback (nexusProject * nexus.RuntimeprojectRuntimeProject ) {
194
+ project := (* NexusProject )(nexusProject )
195
+ h .projectCreated (project )
191
196
}
192
197
193
198
// Callback function to be invoked when Project is added.
194
- func (h * Hook ) projectCreated (project * nexus. RuntimeprojectRuntimeProject ) {
195
- log .Infof ("Runtime Project: %+v created" , * project )
199
+ func (h * Hook ) projectCreated (project NexusProjectInterface ) {
200
+ log .Infof ("Runtime Project: %+v created" , project . DisplayName () )
196
201
197
- if project .Spec . Deleted {
202
+ if project .IsDeleted () {
198
203
log .Info ("Created event for deleted project, dispatching delete event" )
199
204
h .deleteProject (project )
200
205
return
@@ -228,12 +233,12 @@ func (h *Hook) projectCreated(project *nexus.RuntimeprojectRuntimeProject) {
228
233
229
234
// handle the creation of the project
230
235
organizationName := h .getOrganizationName (project )
231
- h .dispatcher .CreateProject (organizationName , project .DisplayName (), string ( project .UID ), project )
236
+ h .dispatcher .CreateProject (organizationName , project .DisplayName (), project .GetUID ( ), project )
232
237
233
238
log .Infof ("Active watcher %s created for Project %s" , watcherObj .DisplayName (), project .DisplayName ())
234
239
}
235
240
236
- func (h * Hook ) getOrganizationName (project * nexus. RuntimeprojectRuntimeProject ) string {
241
+ func (h * Hook ) getOrganizationName (project NexusProjectInterface ) string {
237
242
ctx , cancel := context .WithTimeout (context .Background (), nexusTimeout )
238
243
defer cancel ()
239
244
@@ -253,8 +258,13 @@ func (h *Hook) getOrganizationName(project *nexus.RuntimeprojectRuntimeProject)
253
258
}
254
259
255
260
// Callback function to be invoked when Project is deleted.
256
- func (h * Hook ) projectUpdated (_ , project * nexus.RuntimeprojectRuntimeProject ) {
257
- if project .Spec .Deleted {
261
+ func (h * Hook ) projectUpdatedCallback (_ , nexusProject * nexus.RuntimeprojectRuntimeProject ) {
262
+ project := (* NexusProject )(nexusProject )
263
+ h .projectUpdated (project )
264
+ }
265
+
266
+ func (h * Hook ) projectUpdated (project NexusProjectInterface ) {
267
+ if project .IsDeleted () {
258
268
h .deleteProject (project )
259
269
}
260
270
}
0 commit comments