Skip to content

Instantly share code, notes, and snippets.

@ryancragun
Last active October 13, 2015 18:28

Revisions

  1. Ryan Cragun revised this gist Jan 3, 2013. 1 changed file with 4 additions and 3 deletions.
    7 changes: 4 additions & 3 deletions gistfile1.rb
    Original file line number Diff line number Diff line change
    @@ -4,6 +4,7 @@

    require 'rubygems'
    require 'right_api_client'
    require 'highline/import'

    raise "right_api_client version 1.5.9 is required for this script" unless Gem.loaded_specs['right_api_client'].version.to_s == "1.5.9"

    @@ -43,8 +44,7 @@ def collect_user_attributes
    end
    end
    elsif res =~ /p/
    puts "What would you like the users password to be?"
    attrs[:password] = gets.chomp
    attrs[:password] = ask("What would you like the users password to be? ") { |q| q.echo = false }
    else
    puts "Unrecognized option, please try again" && collect_user_attributes()
    end
    @@ -54,10 +54,11 @@ def collect_user_attributes
    def client_login
    login={}
    puts "Admin Login:\n"
    %w{account_id email password}.each do |attr|
    %w{account_id email}.each do |attr|
    puts "What is your #{attr}?"
    login[attr.to_sym] = gets.chomp
    end
    login[:password] = ask("What is your password?") { |q| q.echo = false }
    @client = RightApi::Client.new(:account_id => login[:account_id], :email => login[:email], :password => login[:password])
    puts "You've successfully authenticated with RightScale!"
    @client
  2. Ryan Cragun revised this gist Dec 12, 2012. 1 changed file with 20 additions and 14 deletions.
    34 changes: 20 additions & 14 deletions gistfile1.rb
    Original file line number Diff line number Diff line change
    @@ -20,20 +20,26 @@ def collect_user_attributes
    if res =~ /s/
    puts "What is the users principal_uid (idP NameID)?"
    attrs[:principal_uid] = gets.chomp
    puts "What is account SAML IdP name? (leave blank if unsure)"
    attrs[:idp_name] = gets.chomp
    puts "What is the SAML idP 'Discovery Hint'? (leave blank if unsure)"
    attrs[:idp_hint] = gets.chomp
    @client.identity_providers.index.each do |idp|
    if attrs[:idp_name].length > 0
    (attrs[:identity_provider_href] = idp.href) && break if idp.name == attrs[:idp_name]
    elsif attrs[:idp_hint].length > 0
    (attrs[:identity_provider_href] = idp.href) && break if idp.discovery_hint == attrs[:idp_hint]
    else
    next unless (attrs[:idp_hint].empty? && attrs[:idp_name].empty?)
    puts "You must supply either a Discovery Hint or SAML idP Name when using SSO"
    puts "Please try again or contact Support for assistance in locating these values"
    collect_user_attributes()
    idps = @client.identity_providers.index
    if idps.length == 1
    attrs[:identity_provider_href] = idps.first.href
    puts "Only 1 Identity Provider was found, defaulting to '#{idps.first.name}'"
    else
    puts "What is account SAML IdP name? (leave blank if unsure)"
    attrs[:idp_name] = gets.chomp
    puts "What is the SAML idP 'Discovery Hint'? (leave blank if unsure)"
    attrs[:idp_hint] = gets.chomp
    idps.each do |idp|
    if attrs[:idp_name].length > 0
    (attrs[:identity_provider_href] = idp.href) && break if idp.name == attrs[:idp_name]
    elsif attrs[:idp_hint].length > 0
    (attrs[:identity_provider_href] = idp.href) && break if idp.discovery_hint == attrs[:idp_hint]
    else
    next unless (attrs[:idp_hint].empty? && attrs[:idp_name].empty?)
    puts "You must supply either a Discovery Hint or SAML idP Name when using SSO"
    puts "Please try again or contact Support for assistance in locating these values"
    collect_user_attributes()
    end
    end
    end
    elsif res =~ /p/
  3. Ryan Cragun revised this gist Dec 12, 2012. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions gistfile1.rb
    Original file line number Diff line number Diff line change
    @@ -26,9 +26,9 @@ def collect_user_attributes
    attrs[:idp_hint] = gets.chomp
    @client.identity_providers.index.each do |idp|
    if attrs[:idp_name].length > 0
    attrs[:identity_provider_href] = idp.href && break if idp.name == attrs[:idp_name]
    (attrs[:identity_provider_href] = idp.href) && break if idp.name == attrs[:idp_name]
    elsif attrs[:idp_hint].length > 0
    attrs[:identity_provider_href] = idp.href && break if idp.discovery_hint == attrs[:idp_hint]
    (attrs[:identity_provider_href] = idp.href) && break if idp.discovery_hint == attrs[:idp_hint]
    else
    next unless (attrs[:idp_hint].empty? && attrs[:idp_name].empty?)
    puts "You must supply either a Discovery Hint or SAML idP Name when using SSO"
    @@ -42,7 +42,7 @@ def collect_user_attributes
    else
    puts "Unrecognized option, please try again" && collect_user_attributes()
    end
    p attrs
    attrs
    end

    def client_login
  4. Ryan Cragun revised this gist Dec 12, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.rb
    Original file line number Diff line number Diff line change
    @@ -42,7 +42,7 @@ def collect_user_attributes
    else
    puts "Unrecognized option, please try again" && collect_user_attributes()
    end
    attrs
    p attrs
    end

    def client_login
  5. Ryan Cragun revised this gist Dec 12, 2012. 1 changed file with 3 additions and 7 deletions.
    10 changes: 3 additions & 7 deletions gistfile1.rb
    Original file line number Diff line number Diff line change
    @@ -26,13 +26,9 @@ def collect_user_attributes
    attrs[:idp_hint] = gets.chomp
    @client.identity_providers.index.each do |idp|
    if attrs[:idp_name].length > 0
    (attrs[:identity_provider_href] = idp.href) && break if idp.name == attrs[:idp_name]
    attrs[:identity_provider_href] = idp.href && break if idp.name == attrs[:idp_name]
    elsif attrs[:idp_hint].length > 0
    puts attrs[:idp_hint]
    if idp.discovery_hint == attrs[:idp_hint]
    attrs[:identity_provider_href] = idp.href
    break
    end
    attrs[:identity_provider_href] = idp.href && break if idp.discovery_hint == attrs[:idp_hint]
    else
    next unless (attrs[:idp_hint].empty? && attrs[:idp_name].empty?)
    puts "You must supply either a Discovery Hint or SAML idP Name when using SSO"
    @@ -87,4 +83,4 @@ def apply_permissions(user, roles)
    puts "User successfully added"
    puts "(q)uit or (a)dd another user?"
    break unless gets.chomp =~ /a/
    end
    end
  6. Ryan Cragun revised this gist Dec 12, 2012. 1 changed file with 33 additions and 2 deletions.
    35 changes: 33 additions & 2 deletions gistfile1.rb
    Original file line number Diff line number Diff line change
    @@ -10,11 +10,42 @@
    def collect_user_attributes
    attrs={}
    puts "New User information:"
    %w{first_name last_name email company phone password identity_provider_href principal_uid}.each do |attr|
    puts "What is the the users #{attr}?\n"
    %w{first_name last_name email company phone}.each do |attr|
    puts "What is the the users #{attr}?"
    res = gets.chomp
    attrs[attr.to_sym] = res unless res.empty?
    end
    puts "Do you want to enable (P)assword or (S)ingle Sign-on authentication?"
    res = gets.chomp.downcase
    if res =~ /s/
    puts "What is the users principal_uid (idP NameID)?"
    attrs[:principal_uid] = gets.chomp
    puts "What is account SAML IdP name? (leave blank if unsure)"
    attrs[:idp_name] = gets.chomp
    puts "What is the SAML idP 'Discovery Hint'? (leave blank if unsure)"
    attrs[:idp_hint] = gets.chomp
    @client.identity_providers.index.each do |idp|
    if attrs[:idp_name].length > 0
    (attrs[:identity_provider_href] = idp.href) && break if idp.name == attrs[:idp_name]
    elsif attrs[:idp_hint].length > 0
    puts attrs[:idp_hint]
    if idp.discovery_hint == attrs[:idp_hint]
    attrs[:identity_provider_href] = idp.href
    break
    end
    else
    next unless (attrs[:idp_hint].empty? && attrs[:idp_name].empty?)
    puts "You must supply either a Discovery Hint or SAML idP Name when using SSO"
    puts "Please try again or contact Support for assistance in locating these values"
    collect_user_attributes()
    end
    end
    elsif res =~ /p/
    puts "What would you like the users password to be?"
    attrs[:password] = gets.chomp
    else
    puts "Unrecognized option, please try again" && collect_user_attributes()
    end
    attrs
    end

  7. Ryan Cragun revised this gist Dec 11, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.rb
    Original file line number Diff line number Diff line change
    @@ -10,7 +10,7 @@
    def collect_user_attributes
    attrs={}
    puts "New User information:"
    %w{first_name last_name email company phone password identity_provider_href principle_uid}.each do |attr|
    %w{first_name last_name email company phone password identity_provider_href principal_uid}.each do |attr|
    puts "What is the the users #{attr}?\n"
    res = gets.chomp
    attrs[attr.to_sym] = res unless res.empty?
  8. Ryan Cragun revised this gist Dec 11, 2012. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions gistfile1.rb
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,6 @@
    #!/usr/bin/env ruby
    # provisions a user and sets permissions
    # [email protected]

    require 'rubygems'
    require 'right_api_client'
  9. Ryan Cragun revised this gist Dec 11, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.rb
    Original file line number Diff line number Diff line change
    @@ -33,7 +33,7 @@ def collect_user_roles
    roles=["observer"]
    %w{admin actor designer library security_manager server_login}.each do |role|
    puts "Do you want to enable the #{role} role on the account? [Y/n]"
    roles.push(role) unless getc.chomp.downcase =~ /n/
    roles.push(role) unless gets.chomp.downcase =~ /n/
    end
    roles
    end
  10. Ryan Cragun revised this gist Dec 11, 2012. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions gistfile1.rb
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,7 @@
    #!/usr/bin/env ruby
    # provisions a user and sets permissions

    require 'rubygems'
    require 'right_api_client'

    raise "right_api_client version 1.5.9 is required for this script" unless Gem.loaded_specs['right_api_client'].version.to_s == "1.5.9"
  11. Ryan Cragun revised this gist Dec 11, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.rb
    Original file line number Diff line number Diff line change
    @@ -49,7 +49,7 @@ def apply_permissions(user, roles)
    attrs = collect_user_attributes()
    roles = collect_user_roles()
    puts "Creating new user..."
    user = @client.users.create({user: attrs})
    user = @client.users.create({:user => attrs})
    apply_permissions(user, roles)
    puts "User successfully added"
    puts "(q)uit or (a)dd another user?"
  12. Ryan Cragun revised this gist Dec 11, 2012. 1 changed file with 5 additions and 5 deletions.
    10 changes: 5 additions & 5 deletions gistfile1.rb
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,10 @@
    #!/usr/bin/env ruby
    # provisions a user and sets permissions
    # [email protected]

    require 'rubygems'
    require 'right_api_client'

    raise "right_api_client version 1.5.9 is required for this script" unless Gem.loaded_specs['right_api_client'].version.to_s == "1.5.9"

    def collect_user_attributes
    attrs={}
    puts "New User information:"
    @@ -32,12 +32,13 @@ def collect_user_roles
    roles=["observer"]
    %w{admin actor designer library security_manager server_login}.each do |role|
    puts "Do you want to enable the #{role} role on the account? [Y/n]"
    roles.push(role) unless gets.chomp.downcase =~ /n/
    roles.push(role) unless getc.chomp.downcase =~ /n/
    end
    roles
    end

    def apply_permissions(user, roles)
    puts "Applying roles..."
    roles.each do |role|
    res = @client.permissions.create({:permission => {:role_title => role, :user_href => user.href}})
    end
    @@ -48,8 +49,7 @@ def apply_permissions(user, roles)
    attrs = collect_user_attributes()
    roles = collect_user_roles()
    puts "Creating new user..."
    user = @client.users.create({:user => attrs})
    puts "Applying roles..."
    user = @client.users.create({user: attrs})
    apply_permissions(user, roles)
    puts "User successfully added"
    puts "(q)uit or (a)dd another user?"
  13. Ryan Cragun revised this gist Dec 10, 2012. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions gistfile1.rb
    Original file line number Diff line number Diff line change
    @@ -2,6 +2,7 @@
    # provisions a user and sets permissions
    # [email protected]

    require 'rubygems'
    require 'right_api_client'

    def collect_user_attributes
  14. Ryan Cragun revised this gist Dec 10, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.rb
    Original file line number Diff line number Diff line change
    @@ -47,7 +47,7 @@ def apply_permissions(user, roles)
    attrs = collect_user_attributes()
    roles = collect_user_roles()
    puts "Creating new user..."
    user = @client.users.create({user: attrs})
    user = @client.users.create({:user => attrs})
    puts "Applying roles..."
    apply_permissions(user, roles)
    puts "User successfully added"
  15. @invalid-email-address Anonymous created this gist Dec 8, 2012.
    56 changes: 56 additions & 0 deletions gistfile1.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,56 @@
    #!/usr/bin/env ruby
    # provisions a user and sets permissions
    # [email protected]

    require 'right_api_client'

    def collect_user_attributes
    attrs={}
    puts "New User information:"
    %w{first_name last_name email company phone password identity_provider_href principle_uid}.each do |attr|
    puts "What is the the users #{attr}?\n"
    res = gets.chomp
    attrs[attr.to_sym] = res unless res.empty?
    end
    attrs
    end

    def client_login
    login={}
    puts "Admin Login:\n"
    %w{account_id email password}.each do |attr|
    puts "What is your #{attr}?"
    login[attr.to_sym] = gets.chomp
    end
    @client = RightApi::Client.new(:account_id => login[:account_id], :email => login[:email], :password => login[:password])
    puts "You've successfully authenticated with RightScale!"
    @client
    end

    def collect_user_roles
    roles=["observer"]
    %w{admin actor designer library security_manager server_login}.each do |role|
    puts "Do you want to enable the #{role} role on the account? [Y/n]"
    roles.push(role) unless gets.chomp.downcase =~ /n/
    end
    roles
    end

    def apply_permissions(user, roles)
    roles.each do |role|
    res = @client.permissions.create({:permission => {:role_title => role, :user_href => user.href}})
    end
    end

    loop do
    @client ||= client_login()
    attrs = collect_user_attributes()
    roles = collect_user_roles()
    puts "Creating new user..."
    user = @client.users.create({user: attrs})
    puts "Applying roles..."
    apply_permissions(user, roles)
    puts "User successfully added"
    puts "(q)uit or (a)dd another user?"
    break unless gets.chomp =~ /a/
    end