summaryrefslogtreecommitdiffstats
path: root/src/job/resource.rs
blob: d657599f28b60060c5894bfc31523e18fa28f46e (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
//
// Copyright (c) 2020-2021 science+computing ag and other contributors
//
// This program and the accompanying materials are made
// available under the terms of the Eclipse Public License 2.0
// which is available at https://www.eclipse.org/legal/epl-2.0/
//
// SPDX-License-Identifier: EPL-2.0
//

use crate::filestore::ArtifactPath;
use crate::util::EnvironmentVariableName;

#[derive(Clone, Debug)]
pub enum JobResource {
    Environment(EnvironmentVariableName, String),
    Artifact(ArtifactPath),
}

impl From<(EnvironmentVariableName, String)> for JobResource {
    fn from(tpl: (EnvironmentVariableName, String)) -> Self {
        JobResource::Environment(tpl.0, tpl.1)
    }
}

impl From<ArtifactPath> for JobResource {
    fn from(a: ArtifactPath) -> Self {
        JobResource::Artifact(a)
    }
}

impl JobResource {
    pub fn env(&self) -> Option<(&EnvironmentVariableName, &String)> {
        match self {
            JobResource::Environment(k, v) => Some((k, v)),
            _ => None,
        }
    }
    pub fn artifact(&self) -> Option<&ArtifactPath> {
        match self {
            JobResource::Artifact(a) => Some(a),
            _ => None,
        }
    }
}