mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-23 02:35:17 +01:00
refactor preheat model (#14858)
Move the notification to preheat models Signed-off-by: Wang Yan <wangyan@vmware.com>
This commit is contained in:
parent
17dd48e5a3
commit
ad9569da26
@ -12,7 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package models
|
||||
package notification
|
||||
|
||||
import (
|
||||
"time"
|
@ -3,11 +3,11 @@ package provider
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/goharbor/harbor/src/pkg/p2p/preheat/models/notification"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/docker/distribution/manifest/schema2"
|
||||
cm "github.com/goharbor/harbor/src/common/models"
|
||||
"github.com/goharbor/harbor/src/common/utils"
|
||||
"github.com/goharbor/harbor/src/pkg/p2p/preheat/models/provider"
|
||||
"github.com/goharbor/harbor/src/pkg/p2p/preheat/provider/auth"
|
||||
@ -67,13 +67,13 @@ func (kd *KrakenDriver) Preheat(preheatingImage *PreheatImage) (*PreheatingStatu
|
||||
}
|
||||
|
||||
url := fmt.Sprintf("%s%s", strings.TrimSuffix(kd.instance.Endpoint, "/"), krakenPreheatPath)
|
||||
var events = make([]cm.Event, 0)
|
||||
var events = make([]notification.Event, 0)
|
||||
eventID := utils.GenerateRandomString()
|
||||
event := cm.Event{
|
||||
event := notification.Event{
|
||||
ID: eventID,
|
||||
TimeStamp: time.Now().UTC(),
|
||||
Action: "push",
|
||||
Target: &cm.Target{
|
||||
Target: ¬ification.Target{
|
||||
MediaType: schema2.MediaTypeManifest,
|
||||
Digest: preheatingImage.Digest,
|
||||
Repository: preheatingImage.ImageName,
|
||||
@ -82,7 +82,7 @@ func (kd *KrakenDriver) Preheat(preheatingImage *PreheatImage) (*PreheatingStatu
|
||||
},
|
||||
}
|
||||
events = append(events, event)
|
||||
var payload = cm.Notification{
|
||||
var payload = notification.Notification{
|
||||
Events: events,
|
||||
}
|
||||
_, err := client.GetHTTPClient(kd.instance.Insecure).Post(url, kd.getCred(), payload, nil)
|
||||
|
@ -16,13 +16,12 @@ package provider
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/goharbor/harbor/src/pkg/p2p/preheat/models/notification"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
cm "github.com/goharbor/harbor/src/common/models"
|
||||
)
|
||||
|
||||
// This is a package to provide mock utilities.
|
||||
@ -111,8 +110,8 @@ func MockKrakenProvider() *httptest.Server {
|
||||
return
|
||||
}
|
||||
|
||||
var payload = &cm.Notification{
|
||||
Events: []cm.Event{},
|
||||
var payload = ¬ification.Notification{
|
||||
Events: []notification.Event{},
|
||||
}
|
||||
|
||||
if err := json.Unmarshal(data, payload); err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user