| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent ef2adf6 commit d982be3
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -348,9 +348,10 @@ func slurpQuoted(r *bufio.Reader, out *bytes.Buffer) error { | |||
| 348 | 348 | } | |
| 349 | 349 | } | |
| 350 | 350 | ||
| 351 | - // FileReader returns an open reader and file on the given file. Gzip-compressed input is detected | ||
| 352 | - // and decompressed automatically even without the gz extension. The caller is responsible for | ||
| 353 | - // calling the returned cleanup function when done with the reader. | ||
| 351 | + // FileReader returns an open reader on the given file. Gzip-compressed input is detected | ||
| 352 | + // and decompressed automatically even without the gz extension. The keyfile, if non-nil, | ||
| 353 | + // is used to decrypt the file. The caller is responsible for calling the returned cleanup | ||
| 354 | + // function when done with the reader. | ||
| 354 | 355 | func FileReader(file string, keyfile string) (rd *bufio.Reader, cleanup func()) { | |
| 355 | 356 | var f *os.File | |
| 356 | 357 | var err error | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -63,6 +63,7 @@ type options struct { | |||
| 63 | 63 | CustomTokenizers string | |
| 64 | 64 | NewUids bool | |
| 65 | 65 | ClientDir string | |
| 66 | + Encrypted bool | ||
| 66 | 67 | ||
| 67 | 68 | MapShards int | |
| 68 | 69 | ReduceShards int | |
@@ -116,7 +117,7 @@ func newLoader(opt *options) *loader { | |||
| 116 | 117 | readerChunkCh: make(chan *bytes.Buffer, opt.NumGoroutines), | |
| 117 | 118 | writeTs: getWriteTimestamp(zero), | |
| 118 | 119 | } | |
| 119 | - st.schema = newSchemaStore(readSchema(opt.SchemaFile, opt.BadgerKeyFile), opt, st) | ||
| 120 | + st.schema = newSchemaStore(readSchema(opt), opt, st) | ||
| 120 | 121 | ld := &loader{ | |
| 121 | 122 | state: st, | |
| 122 | 123 | mappers: make([]*mapper, opt.NumGoroutines), | |
@@ -143,13 +144,18 @@ func getWriteTimestamp(zero *grpc.ClientConn) uint64 { | |||
| 143 | 144 | } | |
| 144 | 145 | } | |
| 145 | 146 | ||
| 146 | - func readSchema(filename string, keyfile string) *schema.ParsedSchema { | ||
| 147 | - f, err := os.Open(filename) | ||
| 147 | + func readSchema(opt *options) *schema.ParsedSchema { | ||
| 148 | + f, err := os.Open(opt.SchemaFile) | ||
| 148 | 149 | x.Check(err) | |
| 149 | 150 | defer f.Close() | |
| 151 | + | ||
| 152 | + keyfile := opt.BadgerKeyFile | ||
| 153 | + if !opt.Encrypted { | ||
| 154 | + keyfile = "" | ||
| 155 | + } | ||
| 150 | 156 | r, err := enc.GetReader(keyfile, f) | |
| 151 | 157 | x.Check(err) | |
| 152 | - if filepath.Ext(filename) == ".gz" { | ||
| 158 | + if filepath.Ext(opt.SchemaFile) == ".gz" { | ||
| 153 | 159 | r, err = gzip.NewReader(r) | |
| 154 | 160 | x.Check(err) | |
| 155 | 161 | } | |
@@ -208,7 +214,11 @@ func (ld *loader) mapStage() { | |||
| 208 | 214 | go func(file string) { | |
| 209 | 215 | defer thr.Done(nil) | |
| 210 | 216 | ||
| 211 | - r, cleanup := chunker.FileReader(file, ld.opt.BadgerKeyFile) | ||
| 217 | + keyfile := ld.opt.BadgerKeyFile | ||
| 218 | + if !ld.opt.Encrypted { | ||
| 219 | + keyfile = "" | ||
| 220 | + } | ||
| 221 | + r, cleanup := chunker.FileReader(file, keyfile) | ||
| 212 | 222 | defer cleanup() | |
| 213 | 223 | ||
| 214 | 224 | chunk := chunker.NewChunker(loadType, 1000) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -58,6 +58,8 @@ func init() { | |||
| 58 | 58 | "Location of schema file.") | |
| 59 | 59 | flag.String("format", "", | |
| 60 | 60 | "Specify file format (rdf or json) instead of getting it from filename.") | |
| 61 | + flag.Bool("encrypted", false, | ||
| 62 | + "Flag to indicate whether schema and data files are encrypted.") | ||
| 61 | 63 | flag.String("out", defaultOutDir, | |
| 62 | 64 | "Location to write the final dgraph data directories.") | |
| 63 | 65 | flag.Bool("replace_out", false, | |
@@ -101,9 +103,10 @@ func init() { | |||
| 101 | 103 | ||
| 102 | 104 | // Options around how to set up Badger. | |
| 103 | 105 | flag.String("encryption_key_file", "", | |
| 104 | - "The file that stores the encryption key. The key size must be 16, 24, or 32 bytes long. "+ | ||
| 105 | - "The key size determines the corresponding block size for AES encryption "+ | ||
| 106 | - "(AES-128, AES-192, and AES-256 respectively). Enterprise feature.") | ||
| 106 | + "The file that stores the encryption key. The key size must be 16/24/32 bytes long."+ | ||
| 107 | + " The key size indicates the chosen AES encryption (AES-128/192/256 respectively). "+ | ||
| 108 | + " This key is used to encrypt the output data directories and to decrypt the input "+ | ||
| 109 | + " schema and data files (if encrytped). Enterprise feature.") | ||
| 107 | 110 | flag.Int("badger.compression_level", 1, | |
| 108 | 111 | "The compression level for Badger. A higher value uses more resources.") | |
| 109 | 112 | } | |
@@ -113,6 +116,7 @@ func run() { | |||
| 113 | 116 | DataFiles: Bulk.Conf.GetString("files"), | |
| 114 | 117 | DataFormat: Bulk.Conf.GetString("format"), | |
| 115 | 118 | SchemaFile: Bulk.Conf.GetString("schema"), | |
| 119 | + Encrypted: Bulk.Conf.GetBool("encrypted"), | ||
| 116 | 120 | OutDir: Bulk.Conf.GetString("out"), | |
| 117 | 121 | ReplaceOutDir: Bulk.Conf.GetBool("replace_out"), | |
| 118 | 122 | TmpDir: Bulk.Conf.GetString("tmp"), | |
@@ -145,6 +149,10 @@ func run() { | |||
| 145 | 149 | fmt.Printf("Cannot enable encryption: %s", x.ErrNotSupported) | |
| 146 | 150 | os.Exit(1) | |
| 147 | 151 | } | |
| 152 | + if opt.Encrypted && opt.BadgerKeyFile == "" { | ||
| 153 | + fmt.Printf("Must use --encryption_key_file option with --encrypted option.\n") | ||
| 154 | + os.Exit(1) | ||
| 155 | + } | ||
| 148 | 156 | if opt.SchemaFile == "" { | |
| 149 | 157 | fmt.Fprint(os.Stderr, "Schema file must be specified.\n") | |
| 150 | 158 | os.Exit(1) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments