Merge branch '16265-security-updates' into dependabot/bundler/apps/workbench/nokogiri...
[arvados.git] / sdk / go / arvados / collection.go
index 136159a7e02897b825ce7f6b5c87c74798f38255..030665d77f7a075f289c92d4a715f1d414de9a9b 100644 (file)
@@ -6,23 +6,28 @@ package arvados
 
 import (
        "bufio"
+       "crypto/md5"
        "fmt"
+       "regexp"
        "strings"
        "time"
 
-       "git.curoverse.com/arvados.git/sdk/go/blockdigest"
+       "git.arvados.org/arvados.git/sdk/go/blockdigest"
 )
 
 // Collection is an arvados#collection resource.
 type Collection struct {
        UUID                      string                 `json:"uuid"`
+       Etag                      string                 `json:"etag"`
        OwnerUUID                 string                 `json:"owner_uuid"`
        TrashAt                   *time.Time             `json:"trash_at"`
        ManifestText              string                 `json:"manifest_text"`
        UnsignedManifestText      string                 `json:"unsigned_manifest_text"`
        Name                      string                 `json:"name"`
-       CreatedAt                 *time.Time             `json:"created_at"`
-       ModifiedAt                *time.Time             `json:"modified_at"`
+       CreatedAt                 time.Time              `json:"created_at"`
+       ModifiedAt                time.Time              `json:"modified_at"`
+       ModifiedByClientUUID      string                 `json:"modified_by_client_uuid"`
+       ModifiedByUserUUID        string                 `json:"modified_by_user_uuid"`
        PortableDataHash          string                 `json:"portable_data_hash"`
        ReplicationConfirmed      *int                   `json:"replication_confirmed"`
        ReplicationConfirmedAt    *time.Time             `json:"replication_confirmed_at"`
@@ -33,6 +38,13 @@ type Collection struct {
        DeleteAt                  *time.Time             `json:"delete_at"`
        IsTrashed                 bool                   `json:"is_trashed"`
        Properties                map[string]interface{} `json:"properties"`
+       WritableBy                []string               `json:"writable_by,omitempty"`
+       FileCount                 int                    `json:"file_count"`
+       FileSizeTotal             int64                  `json:"file_size_total"`
+       Version                   int                    `json:"version"`
+       PreserveVersion           bool                   `json:"preserve_version"`
+       CurrentVersionUUID        string                 `json:"current_version_uuid"`
+       Description               string                 `json:"description"`
 }
 
 func (c Collection) resourceName() string {
@@ -80,3 +92,28 @@ type CollectionList struct {
        Offset         int          `json:"offset"`
        Limit          int          `json:"limit"`
 }
+
+var (
+       blkRe = regexp.MustCompile(`^ [0-9a-f]{32}\+\d+`)
+       tokRe = regexp.MustCompile(` ?[^ ]*`)
+)
+
+// PortableDataHash computes the portable data hash of the given
+// manifest.
+func PortableDataHash(mt string) string {
+       h := md5.New()
+       size := 0
+       _ = tokRe.ReplaceAllFunc([]byte(mt), func(tok []byte) []byte {
+               if m := blkRe.Find(tok); m != nil {
+                       // write hash+size, ignore remaining block hints
+                       tok = m
+               }
+               n, err := h.Write(tok)
+               if err != nil {
+                       panic(err)
+               }
+               size += n
+               return nil
+       })
+       return fmt.Sprintf("%x+%d", h.Sum(nil), size)
+}