Пример #1
0
func parseMessage(message string) (hkid objects.HKID, hcid objects.HCID, typeString string, nameSegment string, url string) {
	var Message map[string]interface{}

	err := json.Unmarshal([]byte(message), &Message)
	if err != nil {
		log.Printf("Error %s\n", err)
	}

	if Message["hcid"] != nil {
		hcid, err = objects.HcidFromHex(Message["hcid"].(string))
	}
	if err != nil {
		log.Printf("Error with hex to string %s", err)
	}

	if Message["hkid"] != nil {
		hkid, err = objects.HkidFromHex(Message["hkid"].(string))
	}
	if err != nil {
		log.Printf("Error with hex to string %s", err)
	}

	if Message["type"] != nil {
		typeString = Message["type"].(string)
	}

	if Message["namesegment"] != nil {
		nameSegment = Message["namesegment"].(string)
	}
	if Message["URL"] != nil {
		url = Message["URL"].(string)
	}
	return hkid, hcid, typeString, nameSegment, url

}
Пример #2
0
func fsFromHKIDString(HKIDstring string, mountpoint string) fileSystem {
	//get hkid from hex
	h, err := objects.HkidFromHex(HKIDstring)
	//check if err is not nil else return h = NULL
	if err != nil {
		log.Printf("Invalid initializing filesystem FS: %s", err)
		return fileSystem{}
	}
	//return filesystem
	return fileSystem{h, mountpoint}
}
Пример #3
0
func TestAppsscriptservice_getCommit(t *testing.T) {
	//t.Skip("Cause")
	h, err := objects.HkidFromHex(
		"c09b2765c6fd4b999d47c82f9cdf7f4b659bf7c29487cc0b357b8fc92ac8ad02",
	)
	c, err := Instance.GetCommit(h)
	if err != nil || c.Verify() == false {
		log.Println(err, "\n", c)
		t.Fail()
	}
}
Пример #4
0
func TestAppsscriptservice_getTag(t *testing.T) {
	//t.Skip()
	h, err := objects.HkidFromHex(
		"f65b92b9ce15e167b98fc896f0a365c87c39565642a59ba0060db3b33be6d885",
	)
	tt, err := Instance.GetTag(h, "testBlob")
	if err != nil || tt.Verify() == false {
		log.Println(err, "\n", tt)
		t.Fail()
	}
}
Пример #5
0
func TestGoogledriveservice_GetTag(t *testing.T) {
	t.Skip("skipping google drive tests")
	//googledriveservice_setup()
	ht, err := objects.HkidFromHex("f65b92b9ce15e167b98fc896f0a365c87c39565642a59ba0060db3b33be6d885")
	tt, err := Instance.GetTag(ht, "testBlob")
	if err != nil || tt.Verify() == false {
		log.Println(err, "\n", tt)
		t.Fail()
	}
	//log.Printf("\n\tTag Contents: %v \n\tError: %v", tt.Verifiy(), err)
}
Пример #6
0
func TestGoogledriveservice_GetCommit(t *testing.T) {
	t.Skip("skipping google drive tests")
	//googledriveservice_setup()
	hc, err := objects.HkidFromHex("c09b2765c6fd4b999d47c82f9cdf7f4b659bf7c29487cc0b357b8fc92ac8ad02")
	c, err := Instance.GetCommit(hc)
	if err != nil || c.Verify() == false {
		log.Println(err, "\n", c)
		t.Fail()
	}
	//log.Printf("\n\tCommit Contents: %v \n\tError: %v", c.Verifiy(), err)
}
Пример #7
0
func TestGoogledriveservice_GetKey(t *testing.T) {
	t.Skip("skipping google drive tests")
	//googledriveservice_setup()
	hk, err := objects.HkidFromHex("f65b92b9ce15e167b98fc896f0a365c87c39565642a59ba0060db3b33be6d885")
	k, err := Instance.GetKey(hk)
	if err != nil {
		t.Fail()
	}
	if k.Hash().Hex() != "478025f8e8d4f769986232ca120be2b9c51a184455f6de1925a62a6f46df15b1" {
		t.Fail()
	}
	//log.Printf("\n\tKey Contents: %s \n\tError: %v", k.Hash(), err)
}
Пример #8
0
func KeyLocalSeed() {
	HKIDstring := GetLocalSeed()
	h, er := objects.HkidFromHex(HKIDstring)
	if er != nil {
		log.Printf("local seed not valid hex /n")
	}
	_, err := services.GetKey(h)
	if err != nil {
		objects.HkidFromDString("65232373562705602286177837897283294165955126"+
			"49112249373497830592072241416893611216069423804730437860475300564272"+
			"976762085068519188612732562106886379081213385", 10)
	}
	return
}
Пример #9
0
func TestAppsscriptservice_getKey(t *testing.T) {
	//t.Skip()
	h, err := objects.HkidFromHex(
		"f65b92b9ce15e167b98fc896f0a365c87c39565642a59ba0060db3b33be6d885",
	)
	k, err := Instance.GetKey(h)
	if err != nil {
		log.Println(err)
		t.Fail()
	}
	if k.Hash().Hex() != "478025f8e8d4f769986232ca120be2b9c51a184455f6de1925a62a6f46df15b1" {
		log.Println(k.Hash().Hex())
		t.Fail()
	}
}
Пример #10
0
func fileSystemPath2CollectionPath(fileSystemPath *string) (objects.HKID, string) {
	h, err := objects.HkidFromHex("c09b2765c6fd4b999d47c82f9cdf7f4b659bf7c29487cc0b357b8fc92ac8ad02")
	wd, err := os.Getwd()
	path := filepath.Join(wd, "../mountpoint")
	//log.Printf("%s", *fileSystemPath)
	//LEFT OFF HERE- so fileSystemPath isnt what I want it to be
	*fileSystemPath = strings.Trim(*fileSystemPath, "\"")
	collectionPath, err := filepath.Rel(string(path), *fileSystemPath)
	if err != nil {
		log.Printf("OH NO! An Error %s", err)
		os.Exit(2)
	}

	return h, collectionPath
}
Пример #11
0
func parseQuery(message string) (typestring string, hash objects.HKID, namesegment string) {
	arrMessage := strings.SplitN(message, ",", 3)
	if len(arrMessage) < 2 {
		panic("error: malformed parseQuery")
	}
	typestring = arrMessage[0]

	hash, err := objects.HkidFromHex(arrMessage[1])
	if err != nil {
		panic("error: malformed hexadecimal")
	}
	if len(arrMessage) > 2 {
		namesegment = arrMessage[2]
	} else {
		namesegment = ""
	}
	fmt.Println("Error")
	return typestring, hash, namesegment
}
Пример #12
0
func webDomainHandler(w http.ResponseWriter, r *http.Request) {
	parts := strings.SplitN(r.RequestURI[3:], "/", 2)
	hkidhex := parts[0]
	path := ""
	if len(parts) > 1 {
		path = parts[1]
	}
	err := error(nil)
	if len(hkidhex) == 64 {
		h, err := objects.HkidFromHex(hkidhex)
		if err == nil {
			b, err := services.GetD(h, path)
			if err == nil {
				w.Write(b.Bytes())
				return
			}
			http.Error(w, fmt.Sprint(
				"HTTP Error 500 Internal server error\n\n", err), 500)
		}
	}
	w.Write([]byte(fmt.Sprintf("Invalid HKID\nerr: %v", err)))
	return
}
Пример #13
0
func addCurators(inCommand struct {
	createDomain     *bool
	createRepository *bool
	insertDomain     *bool
	insertRepository *bool
	path             *string
	hkid             *string
}) {

	if *inCommand.path != "" {
		//log.Printf("HKID: %s", *hkid)
		in := bufio.NewReader(os.Stdin)
		var err error
		h, collectionPath := fileSystemPath2CollectionPath(inCommand.path)
		//log.Printf("systemPath %s", *path)
		//log.Printf("collectionPath %s", collectionPath)

		FileInfos, err := ioutil.ReadDir(*inCommand.path)
		if err != nil {
			log.Printf("Error reading directory %s", err)
			os.Exit(2)
			return
		}

		if len(FileInfos) != 0 {
			fmt.Printf("The folder is not empty")
			os.Exit(2)
			return // Ends function
		}

		collectionName := filepath.Base(*inCommand.path)
		//fmt.Printf("Name of Collection: %s\n", collectionName)

		switch {
		case *inCommand.createDomain:
			//err = InitDomain(h, fmt.Sprintf("%s/%s", collectionPath, collectionName))
			err = services.InitDomain(h, collectionPath)
			if err != nil {
				log.Println(err)
				return
			}

		case *inCommand.createRepository:
			//err = InitRepo(h, fmt.Sprintf("%s/%s", collectionPath, collectionName))
			err = services.InitRepo(h, collectionPath)
			if err != nil {
				log.Println(err)
				return
			}
		case *inCommand.insertDomain:
			fmt.Println("Insert HKID as a hexadecimal number:")
			hex := *inCommand.hkid
			if *inCommand.hkid == "" {
				hex, _ = in.ReadString('\n')
				hex = strings.Trim(hex, "\n")
			}
			log.Print(len(hex))
			foreignHkid, err := objects.HkidFromHex(hex)
			if err != nil {
				log.Printf("Somethng went wrong in insertDomain %s", err)
				os.Exit(2)
			}
			log.Printf("hkid: %s\n", h)
			err = services.InsertDomain(h, fmt.Sprintf("%s/%s", collectionPath, collectionName), foreignHkid)
			if err != nil {
				log.Println(err)
				return
			}
		case *inCommand.insertRepository:
			fmt.Println("Insert HKID as a hexadecimal number:")
			hex := *inCommand.hkid
			if *inCommand.hkid == "" {
				hex, _ = in.ReadString('\n')
				hex = strings.Trim(hex, "\n")
			}
			fmt.Printf("%s", hex)
			foreignHkid, err := objects.HkidFromHex(hex)
			if err != nil {
				log.Printf("Somethng went wrong in insertRepo %s", err)
				os.Exit(2)

			}
			fmt.Printf("hkid: %s", h)
			err = services.InsertRepo(h, fmt.Sprintf("%s/%s", collectionPath, collectionName), foreignHkid)
			if err != nil {
				log.Println(err)
				return
			}
		}
	}

}