sawtooth/permissions/state_source.rs
1/*
2 * Copyright 2020 Cargill Incorporated
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 * ------------------------------------------------------------------------------
16 */
17
18use crate::protocol::identity::{Policy, Role};
19use crate::state::identity_view::IdentityView;
20
21use super::{IdentityError, IdentitySource};
22
23impl IdentitySource for IdentityView {
24 fn get_role(&self, name: &str) -> Result<Option<Role>, IdentityError> {
25 IdentityView::get_role(self, name).map_err(|err| {
26 IdentityError::ReadError(format!("unable to read role from state: {:?}", err))
27 })
28 }
29
30 fn get_policy_by_name(&self, name: &str) -> Result<Option<Policy>, IdentityError> {
31 IdentityView::get_policy(self, name).map_err(|err| {
32 IdentityError::ReadError(format!("unable to read policy from state: {:?}", err))
33 })
34 }
35}