From eb60b4972d79167b5145f4bb8c5b38251c0a41d7 Mon Sep 17 00:00:00 2001 From: Max Jacobson Date: Thu, 29 Jun 2017 11:11:21 -0400 Subject: [PATCH] Add Token marker type This will make it simpler for us to identify which fields are sensitive by type, rather than by field name. --- lib/axiom/types/token.rb | 7 +++++++ lib/cc/service.rb | 1 + lib/cc/services/asana.rb | 4 ++-- lib/cc/services/campfire.rb | 2 +- lib/cc/services/flowdock.rb | 2 +- lib/cc/services/github_issues.rb | 2 +- lib/cc/services/github_pull_requests.rb | 2 +- lib/cc/services/gitlab_merge_requests.rb | 2 +- lib/cc/services/hipchat.rb | 2 +- lib/cc/services/lighthouse.rb | 2 +- lib/cc/services/pivotal_tracker.rb | 2 +- spec/axiom/types/token_spec.rb | 14 ++++++++++++++ 12 files changed, 32 insertions(+), 10 deletions(-) create mode 100644 lib/axiom/types/token.rb create mode 100644 spec/axiom/types/token_spec.rb diff --git a/lib/axiom/types/token.rb b/lib/axiom/types/token.rb new file mode 100644 index 0000000..f8266ba --- /dev/null +++ b/lib/axiom/types/token.rb @@ -0,0 +1,7 @@ +class Axiom::Types::Token < Axiom::Types::String + def self.infer(object) + if object == Axiom::Types::Token + self + end + end +end diff --git a/lib/cc/service.rb b/lib/cc/service.rb index 2edbb94..8873122 100644 --- a/lib/cc/service.rb +++ b/lib/cc/service.rb @@ -6,6 +6,7 @@ class Service require "cc/service/formatter" require "cc/service/invocation" require "axiom/types/password" + require "axiom/types/token" dir = File.expand_path "../helpers", __FILE__ Dir["#{dir}/*_helper.rb"].sort.each do |helper| diff --git a/lib/cc/services/asana.rb b/lib/cc/services/asana.rb index 2895d0e..0ff8e10 100644 --- a/lib/cc/services/asana.rb +++ b/lib/cc/services/asana.rb @@ -1,7 +1,7 @@ class CC::Service::Asana < CC::Service class Config < CC::Service::Config - attribute :personal_access_token, Axiom::Types::String, label: "Personal Access Token" - attribute :api_key, Axiom::Types::String, label: "API key (Deprecated)" + attribute :personal_access_token, Axiom::Types::Token, label: "Personal Access Token" + attribute :api_key, Axiom::Types::Token, label: "API key (Deprecated)" attribute :workspace_id, Axiom::Types::String, label: "Workspace ID" diff --git a/lib/cc/services/campfire.rb b/lib/cc/services/campfire.rb index ae1362d..701ea8d 100644 --- a/lib/cc/services/campfire.rb +++ b/lib/cc/services/campfire.rb @@ -2,7 +2,7 @@ class CC::Service::Campfire < CC::Service class Config < CC::Service::Config attribute :subdomain, Axiom::Types::String, description: "The Campfire subdomain for the account" - attribute :token, Axiom::Types::String, + attribute :token, Axiom::Types::Token, description: "Your Campfire API auth token" attribute :room_id, Axiom::Types::String, description: "Check your campfire URL for a room ID. Usually 6 digits." diff --git a/lib/cc/services/flowdock.rb b/lib/cc/services/flowdock.rb index 5a0a09f..1793b17 100644 --- a/lib/cc/services/flowdock.rb +++ b/lib/cc/services/flowdock.rb @@ -1,6 +1,6 @@ class CC::Service::Flowdock < CC::Service class Config < CC::Service::Config - attribute :api_token, Axiom::Types::String, + attribute :api_token, Axiom::Types::Token, label: "API Token", description: "The API token of the Flow to send notifications to", link: "https://www.flowdock.com/account/tokens" diff --git a/lib/cc/services/github_issues.rb b/lib/cc/services/github_issues.rb index dd3005f..54bdbe2 100644 --- a/lib/cc/services/github_issues.rb +++ b/lib/cc/services/github_issues.rb @@ -1,6 +1,6 @@ class CC::Service::GitHubIssues < CC::Service class Config < CC::Service::Config - attribute :oauth_token, Axiom::Types::String, + attribute :oauth_token, Axiom::Types::Token, label: "OAuth Token", description: "A personal OAuth token with permissions for the repo" attribute :project, Axiom::Types::String, diff --git a/lib/cc/services/github_pull_requests.rb b/lib/cc/services/github_pull_requests.rb index a7838b9..3238842 100644 --- a/lib/cc/services/github_pull_requests.rb +++ b/lib/cc/services/github_pull_requests.rb @@ -2,7 +2,7 @@ class CC::Service::GitHubPullRequests < CC::PullRequests class Config < CC::Service::Config - attribute :oauth_token, Axiom::Types::String, + attribute :oauth_token, Axiom::Types::Token, label: "OAuth Token", description: "A personal OAuth token with permissions for the repo." attribute :base_url, Axiom::Types::String, diff --git a/lib/cc/services/gitlab_merge_requests.rb b/lib/cc/services/gitlab_merge_requests.rb index 960defd..da15cf1 100644 --- a/lib/cc/services/gitlab_merge_requests.rb +++ b/lib/cc/services/gitlab_merge_requests.rb @@ -4,7 +4,7 @@ class CC::Service::GitlabMergeRequests < CC::PullRequests class Config < CC::Service::Config CONTEXT = "codeclimate".freeze - attribute :access_token, Axiom::Types::String, + attribute :access_token, Axiom::Types::Token, label: "Access Token", description: "A personal access token with permissions for the repo." attribute :base_url, Axiom::Types::String, diff --git a/lib/cc/services/hipchat.rb b/lib/cc/services/hipchat.rb index ce8ca20..44cde76 100644 --- a/lib/cc/services/hipchat.rb +++ b/lib/cc/services/hipchat.rb @@ -1,6 +1,6 @@ class CC::Service::HipChat < CC::Service class Config < CC::Service::Config - attribute :auth_token, Axiom::Types::String, + attribute :auth_token, Axiom::Types::Token, description: "Your HipChat API auth token" attribute :room_id, Axiom::Types::String, diff --git a/lib/cc/services/lighthouse.rb b/lib/cc/services/lighthouse.rb index 30bc9a1..3b58e03 100644 --- a/lib/cc/services/lighthouse.rb +++ b/lib/cc/services/lighthouse.rb @@ -3,7 +3,7 @@ class Config < CC::Service::Config attribute :subdomain, Axiom::Types::String, description: "Your Lighthouse subdomain" - attribute :api_token, Axiom::Types::String, + attribute :api_token, Axiom::Types::Token, label: "API Token", description: "Your Lighthouse API Key (http://help.lighthouseapp.com/kb/api/how-do-i-get-an-api-token)" diff --git a/lib/cc/services/pivotal_tracker.rb b/lib/cc/services/pivotal_tracker.rb index dceb25a..9e95121 100644 --- a/lib/cc/services/pivotal_tracker.rb +++ b/lib/cc/services/pivotal_tracker.rb @@ -1,6 +1,6 @@ class CC::Service::PivotalTracker < CC::Service class Config < CC::Service::Config - attribute :api_token, Axiom::Types::String, + attribute :api_token, Axiom::Types::Token, description: "Your Pivotal Tracker API Token, from your profile page" attribute :project_id, Axiom::Types::String, diff --git a/spec/axiom/types/token_spec.rb b/spec/axiom/types/token_spec.rb new file mode 100644 index 0000000..5bd2eeb --- /dev/null +++ b/spec/axiom/types/token_spec.rb @@ -0,0 +1,14 @@ +describe Axiom::Types::Token do + class TestConfiguration < CC::Service::Config + attribute :token_attribute, Token + attribute :str_attribute, String + end + + it "token type inference" do + expect(Axiom::Types::Token).to eq(TestConfiguration.attribute_set[:token_attribute].type) + end + + it "string type inference" do + expect(Axiom::Types::String).to eq(TestConfiguration.attribute_set[:str_attribute].type) + end +end