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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
// Copyright (C) 2018-2021 Rafael Caricio and Contributors // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, // MA 02110-1301 USA //! Fully featured AWS Infinidash client for Rust applications. You can use the AWS Infinidash client to make AWS API calls, and //! to get your application to scale on the AWS infrastructure automagically. AWS Infinidash leverages the blockchain to provide the //! ultimate security and scalability. The decentrality of the blockchain ensures that no single point of failure can be used to //! access the application. Using the Infinidash client, you can scale your application to any available AWS region, and you can //! scale your application to any available AWS account. Using assimetric cryptography, the Infinidash client can be used to //! encrypt data between any two AWS regions with no need for any shared secret. //! //! ## Getting Started //! //! To use the Infinidash client, you need to first install it. To do so, run the following command: //! ~~~ //! cargo install infinidash //! ~~~ //! //! This will install the Infinidash client in your local repository. //! //! To use the Infinidash client, you need to first create a configuration file. To do so, run the following command: //! ~~~ //! infinidash config --create //! ~~~ //! //! This will create a configuration file in the current directory. //! /// Represents all the results of the Infinidash client. type Result<T> = std::result::Result<T, InifinidashError>; /// The InfinidashError type represents an error that occurs when making an AWS API call. /// /// This type is used as the return type of the `infinidash::Client::call` method. #[derive(Debug, Eq, PartialEq, Copy, Clone, Hash)] pub enum InifinidashError { /// The operation failed. Error, /// The operation timed out. Timeout, /// The operation was canceled. Canceled, /// The operation was interrupted. Interrupted, } pub struct InfiniConfig { /// The name of the configuration file. name: String, /// The AWS region to use. region: String, /// The AWS account ID to use. account: String, /// The AWS access key ID to use. access_key: Option<String>, /// The AWS secret key to use. secret_key: Option<String>, } impl InfiniConfig { fn new() -> InfiniConfig { InfiniConfig { name: "infini.config".to_string(), region: "us-east-1".to_string(), account: "".to_string(), access_key: None, secret_key: None, } } } #[derive(Debug, Default)] pub struct InfiniConfigBuilder { /// The name of the configuration file. name: Option<String>, /// The AWS region to use. region: Option<String>, /// The AWS account ID to use. account: Option<String>, /// The AWS access key ID to use. access_key: Option<String>, /// The AWS secret key to use. secret_key: Option<String>, } impl InfiniConfigBuilder { /// Create a new builder. pub fn new() -> InfiniConfigBuilder { InfiniConfigBuilder::default() } /// Set the name of the configuration file. pub fn name(mut self, name: String) -> InfiniConfigBuilder { self.name = Some(name); self } /// Set the AWS region to use. pub fn region(mut self, region: String) -> InfiniConfigBuilder { self.region = Some(region); self } // Set the AWS account ID to use. pub fn account(mut self, account: String) -> InfiniConfigBuilder { self.account = Some(account); self } // build the configuration. pub fn build(self) -> InfiniConfig { InfiniConfig { name: self.name.unwrap_or("infini.config".into()), region: self.region.unwrap_or("us-east-1".into()), account: self.account.unwrap_or("".into()), access_key: self.access_key, secret_key: self.secret_key, } } } struct Application(); impl Application { /// Run the application on the Infinidash infrstructure. pub fn run(config: InfiniConfig) -> Result<()> { Backend::with_app(config).run() } } struct Backend { /// The InfiniDash client. infini: Client, } impl Backend { fn with_app(config: InfiniConfig) -> Backend { Backend { infini: Client::new(config), } } /// Run the backend. fn run(&mut self) -> Result<()> { println!("{}", "Hello world!"); Ok(()) } } struct Client { /// The InfiniDash client configuration. config: InfiniConfig, } impl Client { /// Create a new InfiniDash client. pub fn new(config: InfiniConfig) -> Client { Client { config: config } } } #[cfg(test)] mod tests { use super::*; #[test] fn it_works() { let config = InfiniConfigBuilder::new() .name("infini.config".to_string()) .region("us-east-1".to_string()) .account("".to_string()) .build(); assert!(config.name == "infini.config".to_string()); assert!(config.region == "us-east-1".to_string()) } }