datastructures

package
v0.0.0-...-0858c29 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 27, 2020 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

this package contains the different datastructures used to model data setting and getting in the got system. It has structs to model the following: repositories, branches, commits, access to repository

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func UnmarashalKeyAnnouncements

func UnmarashalKeyAnnouncements(objectString string) (map[string]KeyAnnouncement, error)

This function takes a json string that represents the marshalling of map that has an encryption key's hash as its key and a KeyAnnouncement as its value. It returns this specified map. The returned data is valid and consistent

Types

type AccessLog

type AccessLog struct {
	Authorizer string `json:"authorizer"`
	Authorized string `json:"authorized"`
	UserAccess `json:"userAccess"`
}

A struct that contains the required data to keep track about who is responsible of another user's access in the repository.

type CommitLog

type CommitLog struct {
	Message            string            `json:"message"`
	Author             string            `json:"author"`
	Committer          string            `json:"committer"`
	CommitterTimestamp int               `json:"CommitterTimestamp"`
	Hash               string            `json:"hash"`
	Parenthashes       []string          `json:"parentHashes"`
	Signature          []byte            `json:"signature"`
	EncryptionKey      string            `json:"encryptionKey"`
	StorageHashes      map[string]string `json:"storageHashes"`
}

This structure is modeling the necessary data to be stored for each commit including data nomrally stored through git and data required to get the git objects through the GoT IPFS Cluster. The EncryptionKey stored inside this object represents the hash of the symmetric encryption key used to encrypt the git objects. However, when a query is done in the block chain, this field is filled with the encrypted form of the EncryptionKey instead of its hash.

func CreateNewCommitLog

func CreateNewCommitLog(message string, author string, commiter string, timestamp int, hash string, parenthashes []string, signature []byte, encryptionKey string, storageHashes map[string]string) (CommitLog, error)

this is a helper function to initialize a new CommitLog object instance

type KeyAnnouncement

type KeyAnnouncement struct {
	KeyHash       string            `json:"keyHash"`
	EncryptedKeys map[string]string `json:"encryptedKeys"`
}

KeyAnnouncement is struct that is used to keep information about the avaiable symmetric encryption keys. it maps the has of the symmetric encryption key to the encrypted version of the key that a user can then decrypt using their private key.

func UnmarashalKeyAnnouncement

func UnmarashalKeyAnnouncement(objectString string) (KeyAnnouncement, error)

This function takes a json string that represents the marshalling of KeyAnnouncement and returns a KeyAnnouncement. The returned data is valid and consistent

type PushLog

type PushLog struct {
	BranchName   string      `json:"branchName"`
	DirectoryCID string      `json:"directoryCID"`
	Logs         []CommitLog `json:"logs"`
}

This struct is used to model the required data to add a push to a got project

func CreateNewPushLog

func CreateNewPushLog(branchname string, directoryCID string, logs []CommitLog) (PushLog, error)

Helper function that creates a new object instance of a PushLog

func UnmarashalPushLog

func UnmarashalPushLog(objectString string) (PushLog, error)

This function takes a json string that represents the marshalling of PushLog and returns a PushLog. The returned data is valid and consistent

type Repo

type Repo struct {
	Name         string `json:"repoName"`
	Author       string `json:"author"`
	DirectoryCID string `json:"directoryCID"`
	Timestamp    int    `json:"timeStamp"`

	CommitHashes map[string]struct{}   `json:"hashes"`
	Branches     map[string]RepoBranch `json:"branches"`

	EncryptionKey    KeyAnnouncement            `json:"encryptionKey"`
	Users            map[string]UserAccess      `json:"users"`
	AccessLogs       []AccessLog                `json:"accessLogs"`
	KeyAnnouncements map[string]KeyAnnouncement `json:"keyAnnouncements"`
}

This structis the entry point to store all the needed data for repo to ensure that it's working smoothly whether it's metadata or data required for access control or storage access.

func CreateNewRepo

func CreateNewRepo(name string, author string, directoryCID string, timestamp int, branches map[string]RepoBranch, encryptionKey KeyAnnouncement, users map[string]UserAccess) (Repo, error)

helper function that is needed to create a new Repo instance

func UnmarashalRepo

func UnmarashalRepo(objectString string) (Repo, error)

This function takes a json string that represents the marshalling of Repo and returns a Repo. The returned data is valid and consistent

func (*Repo) AddBranch

func (repo *Repo) AddBranch(branch RepoBranch) (bool, error)

Adds a new beanch to the repo if it creates a new valid state a new branch must have a new unique name and it must be consistent and builds on the current repo state

func (*Repo) AddCommitHash

func (repo *Repo) AddCommitHash(commitLog CommitLog) bool

func (*Repo) AddCommitHashes

func (repo *Repo) AddCommitHashes(commitLogs []CommitLog) bool

func (*Repo) AddCommitLog

func (repo *Repo) AddCommitLog(commitLog CommitLog, branchName string, passValidation bool) (bool, error)

Adds a commitLog to a branch if it creates a new valid state

func (*Repo) AddCommitLogs

func (repo *Repo) AddCommitLogs(commitLogs []CommitLog, branchName string, passValidation bool) (bool, error)

Adds a list of commitLogs to a branch if it creates a new valid state

func (*Repo) CanAuthorize

func (repo *Repo) CanAuthorize(userName string) bool

checks if the mentioned userName belongs to user that is authorized to authorize or revoke ReadWriteAccess for the repository. Only collaborators and owners CanAuthorize

func (*Repo) CanAuthorizeCollaborator

func (repo *Repo) CanAuthorizeCollaborator(userName string) bool

checks if the mentioned userName belongs to user that is authorized to authorize or revoke CollaboratorAccess for the repository. Only owners CanAuthorizeCollaborator

func (*Repo) CanEdit

func (repo *Repo) CanEdit(userName string) bool

checks if the mentioned userName belongs to user that is authorized to do read/write for the repository. anyone included in the repo can read / write

func (*Repo) GetBranches

func (repo *Repo) GetBranches() []string

returns a list that contains the names of branches in a project

func (*Repo) GetUserAccess

func (repo *Repo) GetUserAccess(userName string) UserAccess

returns the current access type of the specified user's userName

func (*Repo) IsBranch

func (repo *Repo) IsBranch(branchName string) bool

checks if the mentioned branch Name belongs to this repo.

func (*Repo) IsCommitHash

func (repo *Repo) IsCommitHash(hashName string) bool

checks if the provided hash has belonged to one of the repo's branches

func (*Repo) UpdateAccess

func (repo *Repo) UpdateAccess(authorized string, userAccess UserAccess, authorizer string, keyAnnouncement KeyAnnouncement) bool

It does the required data writing work to update a user's access type in case, the user access update is valid.

func (*Repo) UpdateCommitsForUser

func (repo *Repo) UpdateCommitsForUser(userName string) bool

Originally the encryptedKey inside each CommitLog contains the hash of the encrytion key this functions replaces each hash with a user's encryted version of the key.

func (*Repo) ValidBranch

func (repo *Repo) ValidBranch(Branch RepoBranch) (bool, error)

need to check commits in the branch

func (*Repo) ValidCommitLog

func (repo *Repo) ValidCommitLog(commitLog CommitLog, branchName string) (bool, error)

checks that all hash parents are hashes in the repository

func (*Repo) ValidCommitLogs

func (repo *Repo) ValidCommitLogs(commitLogs []CommitLog, branchName string) (bool, error)

Check that all parents hashes are current hashes or previous ones in the new hashes list

func (*Repo) ValidUpdateAccess

func (repo *Repo) ValidUpdateAccess(authorized string, userAccess UserAccess, authorizer string) bool

check if the authorized has enough permissions to update the authorized's current access type to the mentioned value.

type RepoBranch

type RepoBranch struct {
	Name      string               `json:"branchName"`
	Author    string               `json:"author"`
	Timestamp int                  `json:"timeStamp"`
	Logs      map[string]CommitLog `json:"logs"`
}

func CreateNewRepoBranch

func CreateNewRepoBranch(name string, author string, timestamp int, logs map[string]CommitLog) (RepoBranch, error)

func UnmarashalRepoBranch

func UnmarashalRepoBranch(objectString string) (RepoBranch, error)

This function takes a json string that represents the marshalling of RepoBranch and returns a RepoBranch. The returned data is valid and consistent

func (*RepoBranch) AddCommitLog

func (branch *RepoBranch) AddCommitLog(commitLog CommitLog, passValidation bool) (bool, error)

Adds a CommitLog to the branch if it can be added according to the info avaiable to the branch.

func (*RepoBranch) IsCommitHash

func (branch *RepoBranch) IsCommitHash(hashName string) bool

Check if the hash has been added to the branch before.

func (*RepoBranch) RemoveLog

func (branch *RepoBranch) RemoveLog(commitLogName string) (bool, error)

Removes a Log from the branch it exists, useful for rolling back cases.

func (*RepoBranch) ValidLog

func (branch *RepoBranch) ValidLog(commitLog CommitLog) (bool, error)

Checks if a log has at least one parent in the branch.

type UserAccess

type UserAccess int

This enum represents the type of access a user has for a repo

const (
	ReadWriteAccess    UserAccess = 1
	CollaboratorAccess UserAccess = 2
	OwnerAccess        UserAccess = 3
	ReovkedAccess      UserAccess = 4
	NeverSetAccess     UserAccess = 5
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL