refactor preheat model (#14858)

Move the notification to preheat models

Signed-off-by: Wang Yan <wangyan@vmware.com>
This commit is contained in:
Wang Yan 2021-05-12 22:29:01 +08:00 committed by GitHub
parent 17dd48e5a3
commit ad9569da26
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 10 deletions

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package models
package notification
import (
"time"

View File

@ -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: &notification.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)

View File

@ -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 = &notification.Notification{
Events: []notification.Event{},
}
if err := json.Unmarshal(data, payload); err != nil {