summaryrefslogtreecommitdiff
path: root/src/components/ScanView.js
blob: aefd28748d5d3d18f6903418aae14c7333b75cf9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import React from "react";

import ScanDetail from "./ScanDetail";

class ScanView extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            object: null
        };

        this.getData = this.getData.bind(this);
    }

    componentDidMount() {
        this.getData();
    }

    getData() {
        fetch(
            `${window.injectedEnv.COLLECTOR_URL}/sc/v0/get/${this.props.id}`,
            {
                headers: {
                    Authorization: "Bearer " + this.props.token
                }
            }
        )
            // TODO: Look at `status` or return code or both?
            .then(resp => {
                if (resp.status !== 200)
                    throw new Error(
                        `Unexpected HTTP response code from soc_collector: ${resp.status} ${resp.statusText}`
                    );
                return resp.json();
            })
            .then(json => {
                if (json.status != "success")
                    throw new Error(
                        `Unexpected status from soc_collector: ${json.status}`
                    );
                this.setState({
                    object: json.docs
                });
            })
            .catch(e => this.props.setError(e));
    }

    render() {
        return this.state.object === null ? null : (
            <ScanDetail {...this.state.object} />
        );
    }
}

export default ScanView;