func addImgTransferTransition(sm *SM) { base := replication.InitBaseHandler(sm.Parms.Repository, sm.Parms.LocalRegURL, config.UISecret(), sm.Parms.TargetURL, sm.Parms.TargetUsername, sm.Parms.TargetPassword, sm.Parms.Insecure, sm.Parms.Tags, sm.Logger) sm.AddTransition(models.JobRunning, replication.StateInitialize, &replication.Initializer{BaseHandler: base}) sm.AddTransition(replication.StateInitialize, replication.StateCheck, &replication.Checker{BaseHandler: base}) sm.AddTransition(replication.StateCheck, replication.StatePullManifest, &replication.ManifestPuller{BaseHandler: base}) sm.AddTransition(replication.StatePullManifest, replication.StateTransferBlob, &replication.BlobTransfer{BaseHandler: base}) sm.AddTransition(replication.StatePullManifest, models.JobFinished, &StatusUpdater{sm.JobID, models.JobFinished}) sm.AddTransition(replication.StateTransferBlob, replication.StatePushManifest, &replication.ManifestPusher{BaseHandler: base}) sm.AddTransition(replication.StatePushManifest, replication.StatePullManifest, &replication.ManifestPuller{BaseHandler: base}) }
func (rj *ReplicationJob) authenticate() { cookie, err := rj.Ctx.Request.Cookie(models.UISecretCookie) if err != nil && err != http.ErrNoCookie { log.Errorf("failed to get cookie %s: %v", models.UISecretCookie, err) rj.CustomAbort(http.StatusInternalServerError, "") } if err == http.ErrNoCookie { rj.CustomAbort(http.StatusUnauthorized, "") } if cookie.Value != config.UISecret() { rj.CustomAbort(http.StatusForbidden, "") } }
// calls the api from UI to get repo list func getRepoList(projectID int64) ([]string, error) { repositories := []string{} client := &http.Client{} uiURL := config.LocalUIURL() next := "/api/repositories?project_id=" + strconv.Itoa(int(projectID)) for len(next) != 0 { req, err := http.NewRequest("GET", uiURL+next, nil) if err != nil { return repositories, err } req.AddCookie(&http.Cookie{Name: models.UISecretCookie, Value: config.UISecret()}) resp, err := client.Do(req) if err != nil { return repositories, err } defer resp.Body.Close() if resp.StatusCode != http.StatusOK { dump, _ := httputil.DumpResponse(resp, true) log.Debugf("response: %q", dump) return repositories, fmt.Errorf("Unexpected status code when getting repository list: %d", resp.StatusCode) } body, err := ioutil.ReadAll(resp.Body) if err != nil { return repositories, err } var list []string if err = json.Unmarshal(body, &list); err != nil { return repositories, err } repositories = append(repositories, list...) links := u.ParseLink(resp.Header.Get(http.CanonicalHeaderKey("link"))) next = links.Next() } return repositories, nil }