|
| 1 | +module AccountHelpers |
| 2 | + def account_named(name) |
| 3 | + client.accounts.first(name: name) |
| 4 | + end |
| 5 | + |
| 6 | + def known_accounts |
| 7 | + begin |
| 8 | + recall_fact(:known_accounts) |
| 9 | + rescue |
| 10 | + memorize_fact(:known_accounts, []) |
| 11 | + end |
| 12 | + end |
| 13 | + |
| 14 | + def first_account |
| 15 | + known_accounts.first.reload |
| 16 | + end |
| 17 | + |
| 18 | + def last_account |
| 19 | + known_accounts.last.reload |
| 20 | + end |
| 21 | + |
| 22 | + def create_account(options={}) |
| 23 | + creator = options[:creator] || create_client |
| 24 | + client = options[:client] |
| 25 | + |
| 26 | + attributes = options[:account] || {} |
| 27 | + attributes[:type] ||= "beta" # get around awsm billing requirements for tests |
| 28 | + attributes[:name] ||= SecureRandom.hex(6) |
| 29 | + |
| 30 | + if client |
| 31 | + attributes[:owner] ||= begin |
| 32 | + client.users.current |
| 33 | + rescue Ey::Core::Response::NotFound |
| 34 | + end |
| 35 | + end |
| 36 | + attributes[:owner] ||= create_user(client: client) |
| 37 | + |
| 38 | + created_account = (client || creator).accounts.create!(attributes) |
| 39 | + |
| 40 | + if client |
| 41 | + client.accounts.get!(created_account.identity) |
| 42 | + else |
| 43 | + created_account |
| 44 | + end |
| 45 | + end |
| 46 | + |
| 47 | + def create_user(options={}) |
| 48 | + creator = options[:creator] || create_client |
| 49 | + client = options[:client] |
| 50 | + |
| 51 | + attributes = options[:user] || {} |
| 52 | + attributes[:name] ||= Faker::Name.name |
| 53 | + attributes[:email] ||= Faker::Internet.email |
| 54 | + |
| 55 | + created_user = creator.users.create!(attributes) |
| 56 | + |
| 57 | + if client |
| 58 | + client.users.get!(created_user.identity) |
| 59 | + else |
| 60 | + created_user |
| 61 | + end |
| 62 | + end |
| 63 | + |
| 64 | + def create_provider(options={}) |
| 65 | + account = options[:account] || create_account(options) |
| 66 | + |
| 67 | + attributes = options[:provider] || {} |
| 68 | + attributes[:type] ||= :aws |
| 69 | + attributes[:provisioned_id] ||= SecureRandom.hex(8) |
| 70 | + attributes[:credentials] ||= case attributes[:type] |
| 71 | + when :aws then |
| 72 | + { |
| 73 | + :instance_aws_secret_id => SecureRandom.hex(6), |
| 74 | + :instance_aws_secret_key => SecureRandom.hex(6), |
| 75 | + :aws_secret_id => SecureRandom.hex(6), |
| 76 | + :aws_secret_key => SecureRandom.hex(6), |
| 77 | + :aws_login => Faker::Internet.email, |
| 78 | + :aws_pass => SecureRandom.hex(6), |
| 79 | + } |
| 80 | + when :azure then |
| 81 | + { |
| 82 | + } |
| 83 | + end |
| 84 | + |
| 85 | + account.providers.create!(attributes).resource! |
| 86 | + end |
| 87 | +end |
| 88 | + |
| 89 | +World(AccountHelpers) |
0 commit comments