icfs 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/data/icfs.css +1 -0
- data/{bin/icfs_dev_todo.rb → devel/create.sh} +4 -9
- data/devel/elastic.sh +20 -0
- data/devel/icfs-wrk/Dockerfile +27 -0
- data/devel/minio.sh +22 -0
- data/devel/redis.sh +18 -0
- data/devel/server.sh +18 -0
- data/devel/test/es-s3-fs-init.rb +93 -0
- data/devel/test/es-s3-fs-webrick.rb +79 -0
- data/devel/test/es-s3-restore.rb +56 -0
- data/devel/test/init.rb +93 -0
- data/devel/test/run.rb +96 -0
- data/lib/icfs/api.rb +22 -11
- data/lib/icfs/cache_elastic.rb +9 -1
- data/lib/icfs/demo/auth.rb +7 -1
- data/lib/icfs/store.rb +6 -12
- data/lib/icfs/store_fs.rb +5 -1
- data/lib/icfs/users.rb +0 -3
- data/lib/icfs/users_fs.rb +19 -70
- data/lib/icfs/users_redis.rb +127 -0
- data/lib/icfs/users_s3.rb +68 -0
- data/lib/icfs/utils/backup.rb +212 -7
- data/lib/icfs/utils/check.rb +1 -5
- data/lib/icfs/web/client.rb +101 -8
- data/lib/icfs/web/config.rb +108 -0
- data/lib/icfs/web/config_redis.rb +78 -0
- data/lib/icfs/web/config_s3.rb +66 -0
- data/lib/icfs.rb +0 -2
- metadata +18 -4
- data/lib/icfs/users_elastic.rb +0 -168
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b0469a0b363219f00dc2955e61bc1dcd6a89743f5cceb53f82a340956f2eac5d
|
4
|
+
data.tar.gz: f2091feb2f38b17ea38d870dd35d287fe6a2a8deada2e51b4e14e58ce45e4c3e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 867f463393cac2ce8c22ef835ce86ab36ce6fc96167427c118c332d0dc465a5ec09effd43bff7011c6ae6388c458b34f7e2e82953c6757e4fb60d80939f67a21
|
7
|
+
data.tar.gz: 46f9e799ebbb39eb0d2c87affd84efa2fc1205e88a9c777f9d5c5dc67ca4bd8a3ab9712ccee45fca26fe1fc1ff18b10dd5cc36ffb31118043fde3d917f6204c7
|
data/data/icfs.css
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#!/
|
1
|
+
#!/bin/bash
|
2
2
|
#
|
3
3
|
# Investigative Case File System
|
4
4
|
#
|
@@ -10,11 +10,6 @@
|
|
10
10
|
# This program is distributed WITHOUT ANY WARRANTY; without even the
|
11
11
|
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
YARD::Registry.load!.all.each do |o|
|
17
|
-
todo = o.tags(:todo)
|
18
|
-
next if todo.empty?
|
19
|
-
todo.each{|tg| puts "%s\n %s\n\n" % [o.path, tg.text] }
|
20
|
-
end
|
13
|
+
docker network create icfs
|
14
|
+
docker volume create icfs-es
|
15
|
+
docker volume create icfs-obj
|
data/devel/elastic.sh
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
#
|
3
|
+
# Investigative Case File System
|
4
|
+
#
|
5
|
+
# Copyright 2019 by Graham A. Field
|
6
|
+
#
|
7
|
+
# This program is free software: you can redistribute it and/or modify
|
8
|
+
# it under the terms of the GNU General Public License version 3.
|
9
|
+
#
|
10
|
+
# This program is distributed WITHOUT ANY WARRANTY; without even the
|
11
|
+
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
12
|
+
|
13
|
+
# run elasticsearch
|
14
|
+
docker run -d --rm \
|
15
|
+
-e "discovery.type=single-node" \
|
16
|
+
-v icfs-es:/usr/share/elasticsearch/data \
|
17
|
+
-p "127.0.0.1:9200:9200" \
|
18
|
+
--network icfs \
|
19
|
+
--name icfs-elastic \
|
20
|
+
docker.elastic.co/elasticsearch/elasticsearch:6.7.2
|
@@ -0,0 +1,27 @@
|
|
1
|
+
#
|
2
|
+
# Investigative Case File System
|
3
|
+
#
|
4
|
+
# Copyright 2019 by Graham A. Field
|
5
|
+
#
|
6
|
+
# This program is free software: you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU General Public License version 3.
|
8
|
+
#
|
9
|
+
# This program is distributed WITHOUT ANY WARRANTY; without even the
|
10
|
+
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
11
|
+
|
12
|
+
FROM alpine:latest
|
13
|
+
|
14
|
+
# install software
|
15
|
+
RUN apk update && \
|
16
|
+
apk upgrade && \
|
17
|
+
apk --update add ruby fcgi ruby-json tzdata vim curl git bash && \
|
18
|
+
apk --update add --virtual build-deps ruby-dev build-base fcgi-dev && \
|
19
|
+
gem install -N rack webrick etc faraday yard aws-sdk-s3 redis && \
|
20
|
+
apk del build-deps && \
|
21
|
+
rm -rf /var/cache/apk/*
|
22
|
+
|
23
|
+
# add user
|
24
|
+
RUN addgroup -S icfsgrp && \
|
25
|
+
adduser -S icfsusr -G icfsgrp
|
26
|
+
|
27
|
+
USER icfsusr
|
data/devel/minio.sh
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
#
|
3
|
+
# Investigative Case File System
|
4
|
+
#
|
5
|
+
# Copyright 2019 by Graham A. Field
|
6
|
+
#
|
7
|
+
# This program is free software: you can redistribute it and/or modify
|
8
|
+
# it under the terms of the GNU General Public License version 3.
|
9
|
+
#
|
10
|
+
# This program is distributed WITHOUT ANY WARRANTY; without even the
|
11
|
+
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
12
|
+
|
13
|
+
# run minio
|
14
|
+
# to debug add -e "MINIO_HTTP_TRACE=/dev/stdout" \
|
15
|
+
docker run -d --rm \
|
16
|
+
-v icfs-obj:/data \
|
17
|
+
-p "127.0.0.1:9000:9000" \
|
18
|
+
-e "MINIO_ACCESS_KEY=minio_key" \
|
19
|
+
-e "MINIO_SECRET_KEY=minio_secret" \
|
20
|
+
--network icfs \
|
21
|
+
--name icfs-minio \
|
22
|
+
minio/minio server /data
|
data/devel/redis.sh
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
#
|
3
|
+
# Investigative Case File System
|
4
|
+
#
|
5
|
+
# Copyright 2019 by Graham A. Field
|
6
|
+
#
|
7
|
+
# This program is free software: you can redistribute it and/or modify
|
8
|
+
# it under the terms of the GNU General Public License version 3.
|
9
|
+
#
|
10
|
+
# This program is distributed WITHOUT ANY WARRANTY; without even the
|
11
|
+
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
12
|
+
|
13
|
+
# run redis
|
14
|
+
docker run -d --rm \
|
15
|
+
--network icfs \
|
16
|
+
--name icfs-redis \
|
17
|
+
redis:alpine
|
18
|
+
# to run the CLI: docker exec -it icfs-redis redis-cli
|
data/devel/server.sh
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
#
|
3
|
+
# Investigative Case File System
|
4
|
+
#
|
5
|
+
# Copyright 2019 by Graham A. Field
|
6
|
+
#
|
7
|
+
# This program is free software: you can redistribute it and/or modify
|
8
|
+
# it under the terms of the GNU General Public License version 3.
|
9
|
+
#
|
10
|
+
# This program is distributed WITHOUT ANY WARRANTY; without even the
|
11
|
+
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
12
|
+
|
13
|
+
# run the server
|
14
|
+
docker run \
|
15
|
+
-v $1:/icfs \
|
16
|
+
-p "127.0.0.1:80:8080" \
|
17
|
+
--network icfs \
|
18
|
+
-it --rm icfs-wrk
|
@@ -0,0 +1,93 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Investigative Case File System
|
4
|
+
#
|
5
|
+
# Copyright 2019 by Graham A. Field
|
6
|
+
#
|
7
|
+
# This program is free software: you can redistribute it and/or modify
|
8
|
+
# it under the terms of the GNU General Public License version 3.
|
9
|
+
#
|
10
|
+
# This program is distributed WITHOUT ANY WARRANTY; without even the
|
11
|
+
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
12
|
+
|
13
|
+
require 'json'
|
14
|
+
require 'faraday'
|
15
|
+
require 'fileutils'
|
16
|
+
require 'aws-sdk-s3'
|
17
|
+
|
18
|
+
require_relative '../../lib/icfs'
|
19
|
+
require_relative '../../lib/icfs/cache_elastic'
|
20
|
+
require_relative '../../lib/icfs/store_s3'
|
21
|
+
require_relative '../../lib/icfs/users_fs'
|
22
|
+
|
23
|
+
# Minio config
|
24
|
+
Aws.config.update(
|
25
|
+
endpoint: 'http://icfs-minio:9000',
|
26
|
+
access_key_id: 'minio_key',
|
27
|
+
secret_access_key: 'minio_secret',
|
28
|
+
force_path_style: true,
|
29
|
+
region: 'use-east-1'
|
30
|
+
)
|
31
|
+
|
32
|
+
# default mapping
|
33
|
+
map = {
|
34
|
+
entry: 'entry',
|
35
|
+
case: 'case',
|
36
|
+
action: 'action',
|
37
|
+
index: 'index',
|
38
|
+
log: 'log',
|
39
|
+
lock: 'lock',
|
40
|
+
current: 'current',
|
41
|
+
}.freeze
|
42
|
+
|
43
|
+
# base items
|
44
|
+
s3 = Aws::S3::Client.new
|
45
|
+
es = Faraday.new('http://icfs-elastic:9200')
|
46
|
+
cache = ICFS::CacheElastic.new(map, es)
|
47
|
+
store = ICFS::StoreS3.new(s3, 'icfs-cache')
|
48
|
+
users = ICFS::UsersFs.new('/var/lib/icfs/users')
|
49
|
+
|
50
|
+
# create users dir
|
51
|
+
FileUtils.mkdir_p('/var/lib/icfs/users')
|
52
|
+
puts "Created users directory"
|
53
|
+
|
54
|
+
# put a testuser
|
55
|
+
tusr = {
|
56
|
+
'name' => 'testuser',
|
57
|
+
'type' => 'user',
|
58
|
+
}
|
59
|
+
users.write(tusr)
|
60
|
+
puts "Added testuser"
|
61
|
+
|
62
|
+
# create the indexes
|
63
|
+
cache.create(ICFS::CacheElastic::Maps)
|
64
|
+
puts "Indexes created"
|
65
|
+
|
66
|
+
# create a bucket
|
67
|
+
s3.create_bucket(bucket: 'icfs-cache')
|
68
|
+
puts "Bucket created"
|
69
|
+
|
70
|
+
api = ICFS::Api.new([], users, cache, store)
|
71
|
+
api.user = 'testuser'
|
72
|
+
|
73
|
+
# add a template
|
74
|
+
tmpl = {
|
75
|
+
'template' => true,
|
76
|
+
'status' => true,
|
77
|
+
'title' => 'Test template',
|
78
|
+
'access' => [
|
79
|
+
{
|
80
|
+
'perm' => '[manage]',
|
81
|
+
'grant' => [
|
82
|
+
'testuser'
|
83
|
+
]
|
84
|
+
}
|
85
|
+
]
|
86
|
+
}
|
87
|
+
ent = {
|
88
|
+
'caseid' => 'test_tmpl',
|
89
|
+
'title' => 'Create template',
|
90
|
+
'content' => 'To test'
|
91
|
+
}
|
92
|
+
api.case_create(ent, tmpl)
|
93
|
+
puts "Create template"
|
@@ -0,0 +1,79 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Investigative Case File System
|
4
|
+
#
|
5
|
+
# Copyright 2019 by Graham A. Field
|
6
|
+
#
|
7
|
+
# This program is free software: you can redistribute it and/or modify
|
8
|
+
# it under the terms of the GNU General Public License version 3.
|
9
|
+
#
|
10
|
+
# This program is distributed WITHOUT ANY WARRANTY; without even the
|
11
|
+
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
12
|
+
|
13
|
+
require 'json'
|
14
|
+
require 'faraday'
|
15
|
+
require 'fileutils'
|
16
|
+
require 'aws-sdk-s3'
|
17
|
+
|
18
|
+
require_relative '../../lib/icfs'
|
19
|
+
require_relative '../../lib/icfs/cache_elastic'
|
20
|
+
require_relative '../../lib/icfs/store_s3'
|
21
|
+
require_relative '../../lib/icfs/users_fs'
|
22
|
+
require_relative '../../lib/icfs/web/client'
|
23
|
+
require_relative '../../lib/icfs/demo/auth'
|
24
|
+
require_relative '../../lib/icfs/demo/static'
|
25
|
+
require_relative '../../lib/icfs/demo/timezone'
|
26
|
+
|
27
|
+
# Minio config
|
28
|
+
Aws.config.update(
|
29
|
+
endpoint: 'http://icfs-minio:9000',
|
30
|
+
access_key_id: 'minio_key',
|
31
|
+
secret_access_key: 'minio_secret',
|
32
|
+
force_path_style: true,
|
33
|
+
region: 'use-east-1'
|
34
|
+
)
|
35
|
+
|
36
|
+
# default mapping
|
37
|
+
map = {
|
38
|
+
entry: 'entry',
|
39
|
+
case: 'case',
|
40
|
+
action: 'action',
|
41
|
+
index: 'index',
|
42
|
+
log: 'log',
|
43
|
+
lock: 'lock',
|
44
|
+
current: 'current',
|
45
|
+
}.freeze
|
46
|
+
|
47
|
+
# base items
|
48
|
+
s3 = Aws::S3::Client.new
|
49
|
+
es = Faraday.new('http://icfs-elastic:9200')
|
50
|
+
cache = ICFS::CacheElastic.new(map, es)
|
51
|
+
store = ICFS::StoreS3.new(s3, 'icfs-cache')
|
52
|
+
users = ICFS::UsersFs.new('/var/lib/icfs/users')
|
53
|
+
api = ICFS::Api.new([], users, cache, store)
|
54
|
+
web = ICFS::Web::Client.new('/static/icfs.css', '/static/icfs.js')
|
55
|
+
|
56
|
+
# static files
|
57
|
+
static = {
|
58
|
+
'/static/icfs.css' => {
|
59
|
+
'path' => 'data/icfs.css',
|
60
|
+
'mime' => 'text/css; charset=utf-8'
|
61
|
+
},
|
62
|
+
'/static/icfs.js' => {
|
63
|
+
'path' => 'data/icfs.js',
|
64
|
+
'mime' => 'application/javascript; charset=utf-8'
|
65
|
+
}
|
66
|
+
}
|
67
|
+
|
68
|
+
app = Rack::Builder.new do
|
69
|
+
use(ICFS::Demo::Auth, api)
|
70
|
+
use(ICFS::Demo::Static, static)
|
71
|
+
use(ICFS::Demo::Timezone, '-04:00')
|
72
|
+
run web
|
73
|
+
end
|
74
|
+
|
75
|
+
opts = {}
|
76
|
+
opts[:Host] = "0.0.0.0"
|
77
|
+
opts[:Port] = 8080
|
78
|
+
|
79
|
+
Rack::Handler::WEBrick.run(app, opts)
|
@@ -0,0 +1,56 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Investigative Case File System
|
4
|
+
#
|
5
|
+
# Copyright 2019 by Graham A. Field
|
6
|
+
#
|
7
|
+
# This program is free software: you can redistribute it and/or modify
|
8
|
+
# it under the terms of the GNU General Public License version 3.
|
9
|
+
#
|
10
|
+
# This program is distributed WITHOUT ANY WARRANTY; without even the
|
11
|
+
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
12
|
+
|
13
|
+
|
14
|
+
# usage <caseid> <store_fs>
|
15
|
+
|
16
|
+
require 'json'
|
17
|
+
require 'faraday'
|
18
|
+
require 'aws-sdk-s3'
|
19
|
+
|
20
|
+
require_relative '../../lib/icfs'
|
21
|
+
require_relative '../../lib/icfs/cache_elastic'
|
22
|
+
require_relative '../../lib/icfs/store_s3'
|
23
|
+
require_relative '../../lib/icfs/store_fs'
|
24
|
+
require_relative '../../lib/icfs/utils/backup'
|
25
|
+
|
26
|
+
# Minio config
|
27
|
+
Aws.config.update(
|
28
|
+
endpoint: 'http://icfs-minio:9000',
|
29
|
+
access_key_id: 'minio_key',
|
30
|
+
secret_access_key: 'minio_secret',
|
31
|
+
force_path_style: true,
|
32
|
+
region: 'use-east-1'
|
33
|
+
)
|
34
|
+
|
35
|
+
# default mapping
|
36
|
+
map = {
|
37
|
+
entry: 'entry',
|
38
|
+
case: 'case',
|
39
|
+
action: 'action',
|
40
|
+
index: 'index',
|
41
|
+
log: 'log',
|
42
|
+
lock: 'lock',
|
43
|
+
current: 'current',
|
44
|
+
}.freeze
|
45
|
+
|
46
|
+
# base items
|
47
|
+
s3 = Aws::S3::Client.new
|
48
|
+
es = Faraday.new('http://icfs-elastic:9200')
|
49
|
+
cache = ICFS::CacheElastic.new(map, es)
|
50
|
+
store = ICFS::StoreS3.new(s3, 'icfs-cache')
|
51
|
+
log = Logger.new(STDOUT, level: Logger::DEBUG)
|
52
|
+
|
53
|
+
src = ICFS::StoreFs.new(ARGV[1])
|
54
|
+
backup = ICFS::Utils::Backup.new(cache, store, log)
|
55
|
+
backup.restore(ARGV[0], src)
|
56
|
+
|
data/devel/test/init.rb
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Investigative Case File System
|
4
|
+
#
|
5
|
+
# Copyright 2019 by Graham A. Field
|
6
|
+
#
|
7
|
+
# This program is free software: you can redistribute it and/or modify
|
8
|
+
# it under the terms of the GNU General Public License version 3.
|
9
|
+
#
|
10
|
+
# This program is distributed WITHOUT ANY WARRANTY; without even the
|
11
|
+
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
12
|
+
|
13
|
+
# Elasticsearch cache
|
14
|
+
# S3 item store
|
15
|
+
# S3 & Redis Users
|
16
|
+
|
17
|
+
require 'json'
|
18
|
+
require 'faraday'
|
19
|
+
require 'fileutils'
|
20
|
+
require 'aws-sdk-s3'
|
21
|
+
require 'redis'
|
22
|
+
|
23
|
+
require_relative '../../lib/icfs'
|
24
|
+
require_relative '../../lib/icfs/cache_elastic'
|
25
|
+
require_relative '../../lib/icfs/store_s3'
|
26
|
+
require_relative '../../lib/icfs/users_fs'
|
27
|
+
require_relative '../../lib/icfs/users_redis'
|
28
|
+
|
29
|
+
|
30
|
+
# Minio config
|
31
|
+
Aws.config.update(
|
32
|
+
endpoint: 'http://icfs-minio:9000',
|
33
|
+
access_key_id: 'minio_key',
|
34
|
+
secret_access_key: 'minio_secret',
|
35
|
+
force_path_style: true,
|
36
|
+
region: 'use-east-1'
|
37
|
+
)
|
38
|
+
|
39
|
+
# default mapping
|
40
|
+
map = {
|
41
|
+
entry: 'entry',
|
42
|
+
case: 'case',
|
43
|
+
action: 'action',
|
44
|
+
index: 'index',
|
45
|
+
log: 'log',
|
46
|
+
lock: 'lock',
|
47
|
+
current: 'current',
|
48
|
+
}.freeze
|
49
|
+
|
50
|
+
# base items
|
51
|
+
s3 = Aws::S3::Client.new
|
52
|
+
redis = Redis.new(host: 'icfs-redis')
|
53
|
+
es = Faraday.new('http://icfs-elastic:9200')
|
54
|
+
cache = ICFS::CacheElastic.new(map, es)
|
55
|
+
store = ICFS::StoreS3.new(s3, 'icfs', 'case/')
|
56
|
+
users_base = ICFS::UsersFs.new(ARGV[0])
|
57
|
+
users = ICFS::UsersRedis.new(redis, users_base, {
|
58
|
+
prefix: 'users/'.freeze,
|
59
|
+
expires: 60, # one minute cache for testing
|
60
|
+
})
|
61
|
+
|
62
|
+
# create the indexes
|
63
|
+
cache.create(ICFS::CacheElastic::Maps)
|
64
|
+
puts "Indexes created"
|
65
|
+
|
66
|
+
# create a bucket
|
67
|
+
s3.create_bucket(bucket: 'icfs')
|
68
|
+
puts "S3 bucket created"
|
69
|
+
|
70
|
+
api = ICFS::Api.new([], users, cache, store)
|
71
|
+
api.user = 'user1'
|
72
|
+
|
73
|
+
# add a template
|
74
|
+
tmpl = {
|
75
|
+
'template' => true,
|
76
|
+
'status' => true,
|
77
|
+
'title' => 'Test template',
|
78
|
+
'access' => [
|
79
|
+
{
|
80
|
+
'perm' => '[manage]',
|
81
|
+
'grant' => [
|
82
|
+
'role2'
|
83
|
+
]
|
84
|
+
}
|
85
|
+
]
|
86
|
+
}
|
87
|
+
ent = {
|
88
|
+
'caseid' => 'test_tmpl',
|
89
|
+
'title' => 'Create template',
|
90
|
+
'content' => 'To test'
|
91
|
+
}
|
92
|
+
api.case_create(ent, tmpl)
|
93
|
+
puts "Create template"
|
data/devel/test/run.rb
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Investigative Case File System
|
4
|
+
#
|
5
|
+
# Copyright 2019 by Graham A. Field
|
6
|
+
#
|
7
|
+
# This program is free software: you can redistribute it and/or modify
|
8
|
+
# it under the terms of the GNU General Public License version 3.
|
9
|
+
#
|
10
|
+
# This program is distributed WITHOUT ANY WARRANTY; without even the
|
11
|
+
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
12
|
+
|
13
|
+
require 'json'
|
14
|
+
require 'faraday'
|
15
|
+
require 'fileutils'
|
16
|
+
require 'aws-sdk-s3'
|
17
|
+
require 'redis'
|
18
|
+
|
19
|
+
require_relative '../../lib/icfs'
|
20
|
+
require_relative '../../lib/icfs/cache_elastic'
|
21
|
+
require_relative '../../lib/icfs/store_s3'
|
22
|
+
require_relative '../../lib/icfs/users_fs'
|
23
|
+
require_relative '../../lib/icfs/users_redis'
|
24
|
+
require_relative '../../lib/icfs/web/client'
|
25
|
+
require_relative '../../lib/icfs/web/config_s3'
|
26
|
+
require_relative '../../lib/icfs/web/config_redis'
|
27
|
+
require_relative '../../lib/icfs/demo/auth'
|
28
|
+
require_relative '../../lib/icfs/demo/static'
|
29
|
+
|
30
|
+
# Minio config
|
31
|
+
Aws.config.update(
|
32
|
+
endpoint: 'http://icfs-minio:9000',
|
33
|
+
access_key_id: 'minio_key',
|
34
|
+
secret_access_key: 'minio_secret',
|
35
|
+
force_path_style: true,
|
36
|
+
region: 'use-east-1'
|
37
|
+
)
|
38
|
+
|
39
|
+
# default mapping
|
40
|
+
map = {
|
41
|
+
entry: 'entry',
|
42
|
+
case: 'case',
|
43
|
+
action: 'action',
|
44
|
+
index: 'index',
|
45
|
+
log: 'log',
|
46
|
+
lock: 'lock',
|
47
|
+
current: 'current',
|
48
|
+
}.freeze
|
49
|
+
|
50
|
+
# default config
|
51
|
+
defaults = {
|
52
|
+
'tz' => '-04:00'
|
53
|
+
}
|
54
|
+
|
55
|
+
# base items
|
56
|
+
s3 = Aws::S3::Client.new
|
57
|
+
redis = Redis.new(host: 'icfs-redis')
|
58
|
+
es = Faraday.new('http://icfs-elastic:9200')
|
59
|
+
cache = ICFS::CacheElastic.new(map, es)
|
60
|
+
store = ICFS::StoreS3.new(s3, 'icfs', 'case/')
|
61
|
+
users_base = ICFS::UsersFs.new(ARGV[0])
|
62
|
+
users = ICFS::UsersRedis.new(redis, users_base, {
|
63
|
+
prefix: 'users/'.freeze,
|
64
|
+
expires: 60, # one minute cache for testing
|
65
|
+
})
|
66
|
+
api = ICFS::Api.new([], users, cache, store)
|
67
|
+
config_base = ICFS::Web::ConfigS3.new(defaults, s3, 'icfs', 'config/')
|
68
|
+
config = ICFS::Web::ConfigRedis.new(redis, config_base, {
|
69
|
+
prefix: 'config/',
|
70
|
+
expires: 60, # debug, only cache for one minute
|
71
|
+
})
|
72
|
+
web = ICFS::Web::Client.new('/static/icfs.css', '/static/icfs.js')
|
73
|
+
|
74
|
+
# static files
|
75
|
+
static = {
|
76
|
+
'/static/icfs.css' => {
|
77
|
+
'path' => 'data/icfs.css',
|
78
|
+
'mime' => 'text/css; charset=utf-8'
|
79
|
+
},
|
80
|
+
'/static/icfs.js' => {
|
81
|
+
'path' => 'data/icfs.js',
|
82
|
+
'mime' => 'application/javascript; charset=utf-8'
|
83
|
+
}
|
84
|
+
}
|
85
|
+
|
86
|
+
app = Rack::Builder.new do
|
87
|
+
use(ICFS::Demo::Auth, api, config)
|
88
|
+
use(ICFS::Demo::Static, static)
|
89
|
+
run web
|
90
|
+
end
|
91
|
+
|
92
|
+
opts = {}
|
93
|
+
opts[:Host] = "0.0.0.0"
|
94
|
+
opts[:Port] = 8080
|
95
|
+
|
96
|
+
Rack::Handler::WEBrick.run(app, opts)
|
data/lib/icfs/api.rb
CHANGED
@@ -15,8 +15,6 @@ module ICFS
|
|
15
15
|
##########################################################################
|
16
16
|
# Api
|
17
17
|
#
|
18
|
-
# @todo Add event logging
|
19
|
-
#
|
20
18
|
class Api
|
21
19
|
|
22
20
|
# Validate a size
|
@@ -71,19 +69,31 @@ class Api
|
|
71
69
|
urgp = @users.read(uname)
|
72
70
|
raise(Error::NotFound, 'User name not found'.freeze) if !urgp
|
73
71
|
raise(Error::Value, 'Not a user'.freeze) if urgp['type'] != 'user'
|
74
|
-
|
75
|
-
|
76
|
-
|
72
|
+
if urgp['roles']
|
73
|
+
@roles = urgp['roles'].map{|rn| rn.freeze }.freeze
|
74
|
+
else
|
75
|
+
@roles = [].freeze
|
76
|
+
end
|
77
|
+
if urgp['groups']
|
78
|
+
@groups = urgp['groups'].map{ |gn| gn.freeze }.freeze
|
79
|
+
else
|
80
|
+
@groups = [].freeze
|
81
|
+
end
|
82
|
+
if urgp['perms']
|
83
|
+
@perms = urgp['perms'].map{|pn| pn.freeze }.freeze
|
84
|
+
else
|
85
|
+
@perms = [].freeze
|
86
|
+
end
|
77
87
|
|
78
88
|
@urg = Set.new
|
79
|
-
@urg.add user
|
80
|
-
@urg.merge roles
|
81
|
-
@urg.merge groups
|
89
|
+
@urg.add @user
|
90
|
+
@urg.merge @roles
|
91
|
+
@urg.merge @groups
|
82
92
|
@urg.freeze
|
83
93
|
|
84
94
|
@ur = Set.new
|
85
|
-
@ur.add user
|
86
|
-
@ur.merge roles
|
95
|
+
@ur.add @user
|
96
|
+
@ur.merge @roles
|
87
97
|
@ur.freeze
|
88
98
|
|
89
99
|
reset
|
@@ -444,7 +454,7 @@ class Api
|
|
444
454
|
end
|
445
455
|
|
446
456
|
json = @cache.current_read(cid)
|
447
|
-
return Items.parse(json, 'current'.
|
457
|
+
return Items.parse(json, 'current'.freeze, Items::ItemCurrent)
|
448
458
|
end # end def current_read()
|
449
459
|
|
450
460
|
|
@@ -1424,6 +1434,7 @@ class Api
|
|
1424
1434
|
fhash << ICFS.hash_temp(fi)
|
1425
1435
|
end
|
1426
1436
|
end
|
1437
|
+
fhash = nil if fhash.empty?
|
1427
1438
|
end
|
1428
1439
|
|
1429
1440
|
return [files, fhash]
|
data/lib/icfs/cache_elastic.rb
CHANGED
@@ -685,11 +685,19 @@ class CacheElastic < Cache
|
|
685
685
|
{ 'title.raw' => 'desc' },
|
686
686
|
{ '_id' => 'desc' },
|
687
687
|
]
|
688
|
-
when 'title_asc'
|
688
|
+
when 'title_asc'
|
689
689
|
req['sort'] = [
|
690
690
|
{ 'title.raw' => 'asc' },
|
691
691
|
{ '_id' => 'desc' },
|
692
692
|
]
|
693
|
+
else
|
694
|
+
# default if not a title/content query
|
695
|
+
if must.empty?
|
696
|
+
req['sort'] = [
|
697
|
+
{ 'title.raw' => 'asc' },
|
698
|
+
{ '_id' => 'desc' },
|
699
|
+
]
|
700
|
+
end
|
693
701
|
end
|
694
702
|
|
695
703
|
# paging
|
data/lib/icfs/demo/auth.rb
CHANGED
@@ -27,10 +27,12 @@ class Auth
|
|
27
27
|
#
|
28
28
|
# @param app [Object] The rack app
|
29
29
|
# @param api [Object] the ICFS API
|
30
|
+
# @param cfg [Object] the ICFS Web Config object
|
30
31
|
#
|
31
|
-
def initialize(app, api)
|
32
|
+
def initialize(app, api, cfg)
|
32
33
|
@app = app
|
33
34
|
@api = api
|
35
|
+
@cfg = cfg
|
34
36
|
end
|
35
37
|
|
36
38
|
|
@@ -59,8 +61,12 @@ class Auth
|
|
59
61
|
if !user
|
60
62
|
return [400, {'Content-Type' => 'text/plain'}, ['Login first'.freeze]]
|
61
63
|
end
|
64
|
+
|
65
|
+
# set up for the call
|
62
66
|
@api.user = user
|
63
67
|
env['icfs'] = @api
|
68
|
+
@cfg.load(user)
|
69
|
+
env['icfs.config'] = @cfg
|
64
70
|
return @app.call(env)
|
65
71
|
|
66
72
|
rescue ICFS::Error::NotFound, ICFS::Error::Value => err
|