Skip to content

Commit 7272fa3

Browse files
Clean up and update README
Signed-off-by: Roumen Roupski <[email protected]>
1 parent 4ed91f9 commit 7272fa3

File tree

4 files changed

+43
-95
lines changed

4 files changed

+43
-95
lines changed

.env.sample

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
SCHEMA_PATH=./modules/schema # Set the local schema path, eg. ../ocsf-schema, defaults to ./modules/schema
1+
SCHEMA_PATH=../ocsf-schema # Set the local schema path, eg. ../ocsf-schema, defaults to ./modules/schema
22
OCSF_SERVER_PORT=8080 # Set the port for Docker to listen on for forwarding traffic to the Schema Server, defaults to 8080
33
ELIXIR_VERSION=1.14-alpine # Set the Elixir container version for development, defaults to 1.14-alpine

README.md

+39-91
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,40 @@
11
# Open Cybersecurity Schema Framework Server
22

3-
This is the Open Cybersecurity Schema Framework (OCSF) server source code repository.
3+
This repository contains the Open Cybersecurity Schema Framework (OCSF) Schema Server source code.
4+
The schema server is an HTTP server that provides a convenient way to browse and use the OCSF schema.
45

5-
## Obtaining the source code
6+
You can access the OCSF schema server, which is running the latest released schema, at [schema.ocsf.io](https://schema.ocsf.io).
67

7-
Clone the GitHub OCFS WEB Server repository. Use `--recurse-submodules` to the `git clone` command, which will automatically initialize and update the schema submodule in the repository:
8+
The schema server can be also used locally. To do that clone the `ocsf-server` and `ocsf-schema` repositories and follow the instruction below to build and run the schema server.
89

9-
```bash
10-
git clone --recurse-submodules https://github.com/ocsf/ocsf-server.git
10+
## Clone the OCFS schema (`ocsf-schema`) repository
11+
```shell
12+
git clone https://github.com/ocsf/ocsf-schema.git
1113
```
1214

13-
## Build and run a schema server docker image
15+
## Clone the OCFS schema server (`ocsf-server`) repository
16+
```shell
17+
git clone https://github.com/ocsf/ocsf-server.git
18+
```
1419

15-
```bash
20+
## Build a server docker image
21+
```shell
1622
cd ocsf-server
17-
docker build -t ocsf-server:0.0.0 .
18-
docker run -it --rm -p 8080:8080 ocsf-server:0.0.0
23+
docker build -t ocsf-server .
1924
```
2025

21-
Run the docker schema server with local schema extensions:
22-
```bash
23-
docker run -it --rm --volume /opt/sandbox/splunk:/app/schema/splunk -e SCHEMA_EXTENSION="splunk" -p 8080:8080 -p 8443:8443 ocsf-server:0.0.0
24-
```
26+
## Run the server docker image
27+
Change the `path/to` to your local OCSF schema directory (use an absolute path). Note, the `-p 8443:8443` parameter enables HTTPS with a self-signed SSL certificate.
2528

26-
Run the docker schema server with added local schema extensions:
27-
```bash
28-
docker run -it --rm --volume /opt/sandbox/splunk:/app/schema/extensions/splunk -e SCHEMA_EXTENSION="extensions" -p 8080:8080 -p 8443:8443 ocsf-server:0.0.0
29+
```shell
30+
docker run -it --rm --volume /path/to/ocsf-schema:/app/schema -p 8080:8080 -p 8443:8443 ocsf-server
2931
```
3032

31-
Run the docker schema server using a local schema:
32-
```bash
33-
docker run -it --rm --volume /opt/sandbox/ocsf-schema:/app/schema -p 8080:8080 -p 8443:8443 ocsf-server:0.0.0
33+
To access the schema server, open [`localhost:8080`](http://localhost:8080) or [`localhost:8443`](https://localhost:8443) in your Web browser.
34+
35+
## Run the server docker image with a local schema extension:
36+
```shell
37+
docker run -it --rm --volume /path/to/ocsf-schema:/app/schema --volume /path/to/ocsf-schema:/app/extension -e SCHEMA_EXTENSION="/app/extension" -p 8080:8080 -p 8443:8443 ocsf-server
3438
```
3539

3640
## Development with docker-compose
@@ -90,70 +94,64 @@ Optional environment variables can be placed in a `.env` file in the root of the
9094
An `.env.sample` is provided, and the following options are available:
9195

9296
```
93-
SCHEMA_PATH=./modules/schema # Set the local schema path, eg. ../ocsf-schema, defaults to ./modules/schema
94-
OCSF_SERVER_PORT=8080 # Set the port for Docker to listen on for forwarding traffic to the Schema Server, defaults to 8080
97+
SCHEMA_PATH=../ocsf-schema # Set the local schema path, eg. ../ocsf-schema, defaults to ../ocsf-schema
98+
OCSF_SERVER_PORT=8080 # Set the port for Docker to listen on for forwarding traffic to the Schema server, defaults to 8080
9599
ELIXIR_VERSION=otp-25-alpine # Set the Elixir container version for development, defaults to otp-25-alpine
96100
```
97101

98102
## Local Usage
99103

100-
This section describes how to build and run the OCSF Schema Schema server.
104+
This section describes how to build and run the OCSF Schema server.
101105

102106
### Required build tools
103107

104-
The Schema Server is written in [Elixir](https://elixir-lang.org) using the [Phoenix](https://phoenixframework.org/) web framework.
108+
The Schema server is written in [Elixir](https://elixir-lang.org) using the [Phoenix](https://phoenixframework.org/) Web framework.
105109

106110
The Elixir site maintains a great installation page, see https://elixir-lang.org/install.html for help.
107111

108112
### Building the schema server
109113

110-
Elixir uses the [`mix`](https://hexdocs.pm/mix/Mix.html) build tool, which is included in the Elixir installation package..
114+
Elixir uses the [`mix`](https://hexdocs.pm/mix/Mix.html) build tool, which is included in the Elixir installation package.
111115

112116
#### Install the build tools
113117

114-
```bash
118+
```shell
115119
mix local.hex --force && mix local.rebar --force
116120
```
117121

118122
#### Get the dependencies
119123

120124
Change to the schema directory, fetch and compile the dependencies:
121125

122-
```bash
126+
```shell
123127
cd ocsf-server
124128
mix do deps.get, deps.compile
125129
```
126130

127131
#### Compile the source code
128132

129-
```bash
133+
```shell
130134
mix compile
131135
```
132136

133137
### Testing local schema changes
134138

135-
You can use Elixir `mix test` to test the changes made to the schema. For example to ensure the JSON files are correct or the attributes are defined.
139+
You can use `mix test` command to test the changes made to the schema. For example to ensure the JSON files are correct or the attributes are defined.
136140

137141
Assuming the schema repo has been cloned in `../ocsf-schema` directory, then you can test the schema with this command:
138142

139143
```shell
140144
SCHEMA_DIR=../ocsf-schema SCHEMA_EXTENSION=extensions mix test
141145
```
142146

143-
Or, test the schema using the `module/schema` folder:
144-
145-
```shell
146-
SCHEMA_DIR=modules/schema SCHEMA_EXTENSION=extensions mix test
147-
```
148-
149147
If everything is correct, then you should not see any errors or warnings.
150148

151149
### Running the schema server
152150

153151
You can use the Elixir's interactive shell, [IEx](https://hexdocs.pm/iex/IEx.html), to start the schema server use:
154152

155-
```bash
156-
iex -S mix phx.server
153+
```shell
154+
SCHEMA_DIR=../ocsf-schema SCHEMA_EXTENSION=extensions iex -S mix phx.server
157155
```
158156

159157
Now you can access the Schema server at [`localhost:8080`](http://localhost:8080) or [`localhost:8443`](https://localhost:8443).
@@ -166,60 +164,10 @@ The schema server uses a number of environment variables.
166164
| ---------------- | ----------- |
167165
| HTTP_PORT | The server HTTP port number, default: `8080`|
168166
| HTTPS_PORT | The server HTTPS port number, default: `8443`|
169-
| SCHEMA_DIR | The directory containing the schema, default: `modules/schema` |
170-
| SCHEMA_EXTENSION | The directory containing the schema extensions, relative to the SCHEMA_DIR |
171-
| RELEASE_NODE | The Erlang node name. Set ti if you want to run more than one server on the same computer |
172-
173-
```bash
174-
SCHEMA_DIR=modules/schema SCHEMA_EXTENSION=extensions iex -S mix phx.server
175-
```
176-
177-
## Releasing the schema server
178-
179-
This section describes how to make a release of the event schema server.
167+
| SCHEMA_DIR | The directory containing the schema, default: `../ocsf-schema` |
168+
| SCHEMA_EXTENSION | The directory containing the schema extensions, relative to SCHEMA_DIR or absolute path |
169+
| RELEASE_NODE | The Erlang node name. Set it if you want to run more than one server on the same computer |
180170

181-
### Create a release
182-
183-
The schema server project uses the [`Elixir Releases`](https://hexdocs.pm/mix/Mix.Tasks.Release.html) to produce an Erlang/OTP release package. To make a production release package, run this command:
184-
185-
```bash
186-
MIX_ENV=prod mix release --path dist
187-
```
188-
189-
This command creates the release in the `./dist` directory.
190-
191-
You can use one of the following options to start the Schema server (see the above environment variables):
192-
193-
```bash
194-
# starts the schema server in the foreground
195-
> bin/schema_server start
196-
197-
# starts the schema server with IEx attached, like 'iex -S mix phx.server'
198-
> bin/schema_server start_iex
199-
200-
# starts the schema server in the background, must be stopped with the 'bin/schema_server stop' command
201-
> bin/schema_server daemon
202-
```
203-
204-
For example to start the schema server, with all extensions, from the `dist` folder use:
205-
206-
```bash
207-
cd dist
208-
SCHEMA_DIR=schema SCHEMA_EXTENSION=extensions bin/schema_server start
209-
```
210-
211-
For a complete listing of commands use:
212-
213-
```bash
214-
bin/schema_server
171+
```shell
172+
SCHEMA_DIR=../ocsf-schema SCHEMA_EXTENSION=extensions iex -S mix phx.server
215173
```
216-
217-
### Deploy the release
218-
219-
A release is built on a **host**, a machine which contains Erlang, Elixir, and any other dependencies needed to compile the schema server. A release is then deployed to a **target**, potentially the same machine as the host, but usually a separate target host.
220-
221-
To deploy the schema server, copy the release archive file (`dist/schema_server-<version>.tar.gz`) from the release folder to the target. Extract the release files to disk from the archive. Note, the following must be the same between the **host** and the **target**:
222-
223-
- Target architecture (for example, x86_64 or ARM)
224-
- Target vendor + operating system (for example, Windows, Linux, or Darwin/macOS)
225-
- Target ABI (for example, musl or gnu)

config/config.exs

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ config :schema_server, :phoenix_swagger,
4242
config :phoenix_swagger, json_library: Jason
4343

4444
# Configures the location of the schema files
45-
config :schema_server, Schema.JsonReader, home: System.get_env("SCHEMA_DIR") || "modules/schema"
45+
config :schema_server, Schema.JsonReader, home: System.get_env("SCHEMA_DIR") || "../ocsf-schema"
4646
config :schema_server, Schema.Application, extension: System.get_env("SCHEMA_EXTENSION")
4747

4848
# Configure the schema example's repo path and local dicrectory

docker-compose.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ services:
99
- "SCHEMA_DIR=/app/schema"
1010
volumes:
1111
- "./:/ocsf-server:z"
12-
- "${SCHEMA_PATH:-./modules/schema}:/app/schema:z"
12+
- "${SCHEMA_PATH:-../ocsf-schema}:/app/schema:z"
1313

1414
ocsf-elixir:
1515
image: "elixir:${ELIXIR_VERSION:-1.14-alpine}"
@@ -21,5 +21,5 @@ services:
2121
- "MIX_HOME=/ocsf-server/.mix"
2222
volumes:
2323
- "./:/ocsf-server:z"
24-
- "${SCHEMA_PATH:-./modules/schema}:/app/schema:z"
24+
- "${SCHEMA_PATH:-../ocsf-schema}:/app/schema:z"
2525
- "./docker-entrypoint-dev.sh:/docker-entrypoint-dev.sh"

0 commit comments

Comments
 (0)