Ejemplo n.º 1
0
func publish(apihost, user, apikey, subject, repository, pkg, version string, isVerbose bool) error {
	resp, err := httpc.DoHttp("POST", apihost+"/content/"+subject+"/"+repository+"/"+pkg+"/"+version+"/publish", subject, user, apikey, "", nil, 0, isVerbose)
	if err == nil {
		log.Printf("Version published. %v", resp)
	}
	return err
}
Ejemplo n.º 2
0
func httpDeleteFile(config *httpTaskConfig, url string) error {
	res, err := httpc.DoHttp("DELETE", url, "", config.username, config.password, "", nil, 0, true)
	if err != nil {
		return err
	}
	if res.StatusCode/100 != 2 {
		return fmt.Errorf("Unable to delete %v: %v", url, res.Status)
	}
	return nil
}
Ejemplo n.º 3
0
func httpExistsFile(config *httpTaskConfig, url string) (bool, error) {
	res, err := httpc.DoHttp("HEAD", url, "", config.username, config.password, "", nil, 0, true)
	if err != nil {
		return false, err
	}
	switch res.StatusCode {
	case 200:
		return true, nil
	case 404:
		return false, nil
	default:
		return false, fmt.Errorf("Unexpected status code %v when testing for existence of %v", res.StatusCode, url)
	}
}
Ejemplo n.º 4
0
//NOTE: not necessary.
//POST /packages/:subject/:repo/:package/versions
func createVersion(apihost, user, apikey, subject, repository, pkg, version string, isVerbose bool) error {
	req := map[string]interface{}{"name": version, "release_notes": "built by goxc", "release_url": "http://x.x.x/x/x"}
	requestData, err := json.Marshal(req)
	if err != nil {
		return err
	}
	requestLength := len(requestData)
	reader := bytes.NewReader(requestData)
	resp, err := httpc.DoHttp("POST", apihost+"/packages/"+subject+"/"+repository+"/"+pkg+"/versions", subject, user, apikey, "", reader, int64(requestLength), isVerbose)
	if err == nil {
		if isVerbose {
			log.Printf("Created new version. %v", resp)
		}
	}
	return err
}
Ejemplo n.º 5
0
func httpUploadFile(config *httpTaskConfig, fullPath string, fi os.FileInfo, tp TaskParams) error {
	var urlb bytes.Buffer
	err := config.urlTemplate.Execute(&urlb, httpURLTemplateContext(tp, fi))
	if err != nil {
		return err
	}
	var url = urlb.String()
	exists, err := httpExistsFile(config, url)
	if err != nil {
		return err
	}
	if exists {
		switch config.exists {
		case "replace":
			if !tp.Settings.IsQuiet() {
				log.Printf("Deleting existent file %v at %v", fi.Name(), url)
			}
			if err := httpDeleteFile(config, url); err != nil {
				return err
			}
		case "omit":
			if !tp.Settings.IsQuiet() {
				log.Printf("Omitting existent file %v at %v", fi.Name(), url)
			}
			return nil
		case "fail":
			return fmt.Errorf("Failing http publish of %v because it already exists at %v", fi.Name(), url)
		}
	}
	if !tp.Settings.IsQuiet() {
		log.Printf("Putting %s to %s", fi.Name(), url)
	}
	b, err := os.Open(fullPath)
	if err != nil {
		return err
	}
	res, err := httpc.DoHttp("PUT", url, "", config.username, config.password, "application/octet-stream", b, fi.Size(), true)
	if err != nil {
		return err
	}
	if res.StatusCode/100 != 2 {
		return fmt.Errorf("Unexpected response: %v", res.Status)
	}
	return nil
}
Ejemplo n.º 6
0
func TestGetReleases(t *testing.T) {
	if *apikey == "" {
		t.Skip("api-key is required to run this integration test")
	}
	r, err := httpc.DoHttp("GET", apihost+"/repos/"+owner+"/"+repo+"/releases", "", owner, *apikey, "", nil, 0, isVerbose)
	if err != nil {
		t.Errorf("Error getting release %v", err)
	}
	a, err := httpc.ParseSlice(r, isVerbose)
	if err != nil {
		t.Errorf("Error getting release %v", err)
	}
	for _, i := range a {
		id := i["id"]
		name := i["name"]
		t.Logf("ID: %0.f  Name: %s", id, name)
		//		for k, v := range i {
		//			t.Logf("Entry: %s %+v", k, v)
		//		}
	}
	//t.Logf("Response data: %v", a)
}