Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable inspec compliance cli support automate #1297

Merged
merged 3 commits into from
Nov 30, 2016

Conversation

vjeffrey
Copy link

@vjeffrey vjeffrey commented Nov 16, 2016

fixes #1295

b inspec compliance login_automate http://delivery --user admin --dctoken $DC_TOKEN --ent $AUTOMATE_ENT

b inspec compliance login_automate http://delivery --user $AUTOMATE_USER --usertoken $AUTOMATE_TOKEN --ent $AUTOMATE_ENT

b inspec compliance profiles

b inspec compliance upload ~/linux.tar.gz

b inspec compliance logout <-- just destroys config when automate

b inspec compliance version <-- returns msg saying that's not available with automate

b inspec compliance exec admin/linux

@vjeffrey vjeffrey force-pushed the vj/support-asset-store-compliance-cli branch 7 times, most recently from 284a9ac to e57036a Compare November 17, 2016 03:22
@vjeffrey vjeffrey changed the title wip: enable inspec compliance cli support automate enable inspec compliance cli support automate Nov 17, 2016
@vjeffrey vjeffrey force-pushed the vj/support-asset-store-compliance-cli branch from e57036a to 9038be7 Compare November 17, 2016 03:43
@vjeffrey
Copy link
Author

vjeffrey commented Nov 17, 2016

@alexpop could you test this out please?

@vjeffrey vjeffrey force-pushed the vj/support-asset-store-compliance-cli branch 4 times, most recently from fa6aeef to dbf37eb Compare November 17, 2016 13:32
Copy link
Contributor

@chris-rock chris-rock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work @vjeffrey

@@ -56,6 +57,32 @@ def login(server) # rubocop:disable Metrics/AbcSize
puts '', msg
end

desc "automate SERVER --user='USER' --dctoken='DATA_COLLECTOR_TOKEN' or --usertoken='AUTOMATE_TOKEN' --ent='ENT'", 'Log in to an Automate SERVER'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we call it login-automate?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not 100% sure on this. What would be a better way to name it? Another option could be to just stick with inspec compliance login and just offer more options there. On the other hand this may become more complex for a user to understand which config is for which server? What are you thinking?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had started out with just making it an extension of inspec compliance login, but then i couldn't display the desc well with the different options...which is why I went this route. I'm up for a rename to login-automate, i think that makes sense.

# iterate over tests and add compliance scheme
tests = tests.map { |t| 'compliance://' + t }

config['automate'][0] ? tests = tests.map { |t| 'automate://' + t } : tests = tests.map { |t| 'compliance://' + t }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer if we could stick to compliance:// no matter if the profiles are stored in Chef Compliance or Chef Automate

uri = if target.is_a?(String) && URI(target).scheme == 'compliance'
URI(target)
elsif target.is_a?(String) && URI(target).scheme == 'automate'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we do not need the automate scheme

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh ya, you're right - i'll change that

@vjeffrey
Copy link
Author

vjeffrey commented Nov 21, 2016

conversation with hannah:

inspec compliance

inspec compliance login > automate http://delivery --user=admin --ent=cd

Please specify a token using --dctoken='DATA_COLLECTOR_TOKEN' or usertoken='AUTOMATE_TOKEN'

--dctoken='fnjknefkje'

@hannah-radish
Copy link
Contributor

@vjeffrey Does this make sense to you?
automate-login-cli
automate-login-cli2

@vjeffrey
Copy link
Author

thanks hannah!!!!!
coloring and prompt will be taken care of in separate issues, referenced above (1310 and 1311)

@vjeffrey
Copy link
Author

i'll update this change to address comments later today/wednesday morning at latest

@hannah-radish
Copy link
Contributor

screen shot 2016-11-22 at 4 09 40 pm

Updated the color pallet here as well: https://github.com/chef/inspec/pull/1313/files

@vjeffrey
Copy link
Author

updated to name it login_automate and removed the unnecessary automate scheme logic

@vjeffrey vjeffrey force-pushed the vj/support-asset-store-compliance-cli branch 6 times, most recently from 2d6e29e to 1d5530b Compare November 27, 2016 18:28
@vjeffrey vjeffrey force-pushed the vj/support-asset-store-compliance-cli branch 3 times, most recently from 625c206 to bc48d59 Compare November 27, 2016 18:58
config = Compliance::Configuration.new
url = "#{config['server']}/logout"
Compliance::API.post(url, config['token'], config['insecure'], !config.supported?(:oidc))
end

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should clear the token information of the config

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also we should remove the the server information from the config. This was missing even before

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@@ -198,6 +228,29 @@ def logout

private

def login_automate_config(url, user, dctoken, usertoken, ent)
config = Compliance::Configuration.new
config['server'] = url
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should have a config['server_type'] to indicate the type of server. At the moment that is compliance and automate

def login_automate_config(url, user, dctoken, usertoken, ent)
config = Compliance::Configuration.new
config['server'] = url
config['ent'] = ent
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should store all automate specific config under the section config['automate']

# return all compliance profiles available for the user
def self.profiles(config)
url = "#{config['server']}/user/compliance"
config['automate'][0] ? url = "#{config['server']}/#{config['user']}" : url = "#{config['server']}/user/compliance"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not fan of config['automate'][0]. We should ask directly for the information we need: config['automate']['ent']. For this case I propose config['server_type']

@@ -56,6 +57,33 @@ def login(server) # rubocop:disable Metrics/AbcSize
puts '', msg
end

desc "login_automate SERVER --user='USER' --ent='ENT' --dctoken or --usertoken='TOKEN'", 'Log in to an Automate SERVER'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the login_automate approach

@@ -26,14 +25,21 @@ def self.resolve(target)
# check if we have a compliance token
config = Compliance::Configuration.new
if config['token'].nil?
if config['automate'][0]
server = 'automate'
msg = 'inspec compliance automate https://your_automate_server --user USER --ent ENT --dctoken DCTOKEN or --usertoken USERTOKEN'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be inspec compliance login_automate ...

@@ -26,14 +25,21 @@ def self.resolve(target)
# check if we have a compliance token
config = Compliance::Configuration.new
if config['token'].nil?
if config['automate'][0]
server = 'automate'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets use this in config['server_type']

@@ -126,7 +126,19 @@ def download_archive_to_temp
Inspec::Log.debug("Fetching URL: #{@target}")
http_opts = {}
http_opts['ssl_verify_mode'.to_sym] = OpenSSL::SSL::VERIFY_NONE if @insecure
http_opts['Authorization'] = "Bearer #{@token}" if @token
if @config
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we have the server_type, lets do a simple if then clause

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@chris-rock chris-rock force-pushed the vj/support-asset-store-compliance-cli branch from bc48d59 to 8c69a97 Compare November 29, 2016 11:29
@vjeffrey vjeffrey force-pushed the vj/support-asset-store-compliance-cli branch 2 times, most recently from 777ef1a to 7e0c7c8 Compare November 29, 2016 14:52
@chris-rock chris-rock force-pushed the vj/support-asset-store-compliance-cli branch from 7e0c7c8 to e2d5b0e Compare November 30, 2016 09:20
Victoria Jeffrey added 2 commits November 30, 2016 13:27
Signed-off-by: Victoria Jeffrey <vjeffrey@chef.io>
Signed-off-by: Victoria Jeffrey <vjeffrey@chef.io>
@chris-rock chris-rock force-pushed the vj/support-asset-store-compliance-cli branch from e2d5b0e to 60009b2 Compare November 30, 2016 12:28
{ org: owner, name: name }
end
end.flatten
if config['server_type'] == 'automate'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as discussed with @Vj we talk with @alexpop to find a way to harmonize this part

@@ -9,13 +9,21 @@ module Compliance
# implements a simple http abstraction on top of Net::HTTP
class HTTP
# generic get requires
def self.get(url, token, insecure, basic_auth = false)
def self.get(url, token, insecure, user, basic_auth = false, automate = nil, server_type) # rubocop:disable Metrics/ParameterLists
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed with @vjeffrey we think we can abstract that even further:

def self.get(url, headers, insecure). This would allow us to pass in the required headers from outside:

headers = {
  'x-data-collector-token': token
}

headers = {
  'chef-delivery-user': user,
  'chef-delivery-token': token,
}

headers = {
  'Authorization', "Bearer #{token}",
}

@vjeffrey vjeffrey force-pushed the vj/support-asset-store-compliance-cli branch from c6e725e to 6aeba49 Compare November 30, 2016 14:32
@vjeffrey
Copy link
Author

@chris-rock pushed up a commit with updated headers stuffs

@chris-rock chris-rock force-pushed the vj/support-asset-store-compliance-cli branch from 6aeba49 to 544784b Compare November 30, 2016 16:49
Signed-off-by: Victoria Jeffrey <vjeffrey@chef.io>
@chris-rock chris-rock force-pushed the vj/support-asset-store-compliance-cli branch from 544784b to d8b512e Compare November 30, 2016 17:10
@chris-rock
Copy link
Contributor

Awesome. Thank you @vjeffrey

@chris-rock chris-rock merged commit 939e6ca into master Nov 30, 2016
@chris-rock chris-rock deleted the vj/support-asset-store-compliance-cli branch November 30, 2016 17:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

inspec compliance profiles should support automate as a backend
3 participants