Skip to content

Commit

Permalink
Add comments to exported functions
Browse files Browse the repository at this point in the history
  • Loading branch information
ishank011 committed Feb 24, 2021
1 parent 5d0b3fd commit 5c31d43
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions pkg/cbox/publicshare/sql/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ func (m *manager) startJanitorRun() {
}
}

// New returns a new public share manager.
func New(m map[string]interface{}) (publicshare.Manager, error) {
c := &config{}
if err := mapstructure.Decode(m, c); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/cbox/share/sql/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ type mgr struct {
db *sql.DB
}

// New returns a new mgr.
// New returns a new share manager.
func New(m map[string]interface{}) (share.Manager, error) {
c, err := parseConfig(m)
if err != nil {
Expand Down
14 changes: 14 additions & 0 deletions pkg/cbox/utils/conversions.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
typespb "github.com/cs3org/go-cs3apis/cs3/types/v1beta1"
)

// DBShare stores information about user and public shares.
type DBShare struct {
ID string
UIDOwner string
Expand All @@ -48,6 +49,7 @@ type DBShare struct {
State int
}

// FormatGrantee formats a CS3API grantee to a string
func FormatGrantee(g *provider.Grantee) (int, string) {
var granteeType int
var formattedID string
Expand All @@ -64,6 +66,7 @@ func FormatGrantee(g *provider.Grantee) (int, string) {
return granteeType, formattedID
}

// ExtractGrantee retrieves the CS3API grantee from a formatted string
func ExtractGrantee(t int, g string) *provider.Grantee {
var grantee *provider.Grantee
switch t {
Expand All @@ -79,6 +82,7 @@ func ExtractGrantee(t int, g string) *provider.Grantee {
return grantee
}

// ResourceTypeToItem maps a resource type to an integer
func ResourceTypeToItem(r provider.ResourceType) string {
switch r {
case provider.ResourceType_RESOURCE_TYPE_FILE:
Expand All @@ -94,6 +98,7 @@ func ResourceTypeToItem(r provider.ResourceType) string {
}
}

// SharePermToInt maps read/write permissions to an integer
func SharePermToInt(p *provider.ResourcePermissions) int {
var perm int
if p.CreateContainer {
Expand All @@ -104,6 +109,7 @@ func SharePermToInt(p *provider.ResourcePermissions) int {
return perm
}

// IntTosharePerm retrieves read/write permissions from an integer
func IntTosharePerm(p int) *provider.ResourcePermissions {
switch p {
case 1:
Expand Down Expand Up @@ -141,6 +147,7 @@ func IntTosharePerm(p int) *provider.ResourcePermissions {
}
}

// IntToShareState retrieves the received share state from an integer
func IntToShareState(g int) collaboration.ShareState {
switch g {
case 0:
Expand All @@ -152,13 +159,15 @@ func IntToShareState(g int) collaboration.ShareState {
}
}

// FormatUserID formats a CS3API user ID to a string
func FormatUserID(u *userpb.UserId) string {
if u.Idp != "" {
return fmt.Sprintf("%s:%s", u.OpaqueId, u.Idp)
}
return u.OpaqueId
}

// ExtractUserID retrieves a CS3API user ID from a string
func ExtractUserID(u string) *userpb.UserId {
parts := strings.Split(u, ":")
if len(parts) > 1 {
Expand All @@ -167,13 +176,15 @@ func ExtractUserID(u string) *userpb.UserId {
return &userpb.UserId{OpaqueId: parts[0]}
}

// FormatGroupID formats a CS3API group ID to a string
func FormatGroupID(u *grouppb.GroupId) string {
if u.Idp != "" {
return fmt.Sprintf("%s:%s", u.OpaqueId, u.Idp)
}
return u.OpaqueId
}

// ExtractGroupID retrieves a CS3API group ID from a string
func ExtractGroupID(u string) *grouppb.GroupId {
parts := strings.Split(u, ":")
if len(parts) > 1 {
Expand All @@ -182,6 +193,7 @@ func ExtractGroupID(u string) *grouppb.GroupId {
return &grouppb.GroupId{OpaqueId: parts[0]}
}

// ConvertToCS3Share converts a DBShare to a CS3API collaboration share
func ConvertToCS3Share(s DBShare) *collaboration.Share {
ts := &typespb.Timestamp{
Seconds: uint64(s.STime),
Expand All @@ -200,6 +212,7 @@ func ConvertToCS3Share(s DBShare) *collaboration.Share {
}
}

// ConvertToCS3ReceivedShare converts a DBShare to a CS3API collaboration received share
func ConvertToCS3ReceivedShare(s DBShare) *collaboration.ReceivedShare {
share := ConvertToCS3Share(s)
return &collaboration.ReceivedShare{
Expand All @@ -208,6 +221,7 @@ func ConvertToCS3ReceivedShare(s DBShare) *collaboration.ReceivedShare {
}
}

// ConvertToCS3PublicShare converts a DBShare to a CS3API public share
func ConvertToCS3PublicShare(s DBShare) *link.PublicShare {
ts := &typespb.Timestamp{
Seconds: uint64(s.STime),
Expand Down

0 comments on commit 5c31d43

Please sign in to comment.