trixie 0.1.1 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d9fb9e4a817416d5df9d692a6da48f03afc54c429b1956e6b74724739253776e
4
- data.tar.gz: f0cbfc84bccc590573c633fe8a36ee00762fd4d6a94748c928ebb55668730d64
3
+ metadata.gz: 4601cd84921ad3fca11a80ffb627ef4b5d44d9a404dc25ac1905d75ab12a0b96
4
+ data.tar.gz: fcd3bb97d53845a6cd7752c90305bd9641c7809d57e86fc2d9fd4a6bcab41e96
5
5
  SHA512:
6
- metadata.gz: d897d133563fc5ce764cb7dda155f58b9822191ae74d24113736626cab6a172acbc15cd316d18d9c43cc2b473a7d1dbf93c0b655acfb7373bf09ec6d67120eda
7
- data.tar.gz: 41c803e3e23ba1a91d2c523b98e95e053ef8a5a00c72f4cbfee3427aa73f7e8a577c57ac5abc72fcc4ca3e9836069c8479a3da016305fe98276a6520f559dd9f
6
+ metadata.gz: 558dbef73b15724f9559e64d9f20cfa736fddea2445d8a9edd7c7a8bd9ee514a4c8a244356095c470787e509df6af58c29a99525bd96f5ef94d718a287e75852
7
+ data.tar.gz: 8327f5fa9e8392e563e888fd981760ac6ec78438de8a28cf8b0c83691c8748dcdb6fd6156457977132421e6780b157c1eae17d5ab59ffd9921486e3f6345d732
@@ -0,0 +1,2 @@
1
+ # This owner will be the default owner of everything in the repo.
2
+ * @toptal/devx
data/Gemfile.lock CHANGED
@@ -1,8 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- trixie (0.1.1)
4
+ trixie (0.1.4)
5
5
  dry-cli (~> 0.7.0)
6
+ dry-schema (~> 1.10.0)
7
+ dry-validation (~> 1.8.0)
6
8
 
7
9
  GEM
8
10
  remote: https://rubygems.org/
@@ -10,8 +12,43 @@ GEM
10
12
  ast (2.4.2)
11
13
  byebug (11.1.3)
12
14
  coderay (1.1.3)
15
+ concurrent-ruby (1.1.10)
13
16
  diff-lcs (1.5.0)
14
17
  dry-cli (0.7.0)
18
+ dry-configurable (0.16.1)
19
+ dry-core (~> 0.6)
20
+ zeitwerk (~> 2.6)
21
+ dry-container (0.11.0)
22
+ concurrent-ruby (~> 1.0)
23
+ dry-core (0.9.1)
24
+ concurrent-ruby (~> 1.0)
25
+ zeitwerk (~> 2.6)
26
+ dry-inflector (0.3.0)
27
+ dry-initializer (3.1.1)
28
+ dry-logic (1.3.0)
29
+ concurrent-ruby (~> 1.0)
30
+ dry-core (~> 0.9, >= 0.9)
31
+ zeitwerk (~> 2.6)
32
+ dry-schema (1.10.6)
33
+ concurrent-ruby (~> 1.0)
34
+ dry-configurable (~> 0.13, >= 0.13.0)
35
+ dry-core (~> 0.5, >= 0.5)
36
+ dry-initializer (~> 3.0)
37
+ dry-logic (~> 1.2)
38
+ dry-types (~> 1.5)
39
+ dry-types (1.6.1)
40
+ concurrent-ruby (~> 1.0)
41
+ dry-container (~> 0.3)
42
+ dry-core (~> 0.9, >= 0.9)
43
+ dry-inflector (~> 0.1, >= 0.1.2)
44
+ dry-logic (~> 1.3, >= 1.3)
45
+ zeitwerk (~> 2.6)
46
+ dry-validation (1.8.1)
47
+ concurrent-ruby (~> 1.0)
48
+ dry-container (~> 0.7, >= 0.7.1)
49
+ dry-core (~> 0.5, >= 0.5)
50
+ dry-initializer (~> 3.0)
51
+ dry-schema (~> 1.8, >= 1.8.0)
15
52
  json (2.6.2)
16
53
  method_source (1.0.0)
17
54
  parallel (1.22.1)
@@ -54,6 +91,7 @@ GEM
54
91
  parser (>= 3.1.1.0)
55
92
  ruby-progressbar (1.11.0)
56
93
  unicode-display_width (2.2.0)
94
+ zeitwerk (2.6.6)
57
95
 
58
96
  PLATFORMS
59
97
  x86_64-linux
data/README.md CHANGED
@@ -18,7 +18,20 @@ secrets:
18
18
  value: "{{ op://Developers/NPM_TOKEN/SETUP_SECRET/value }}"
19
19
  ```
20
20
 
21
- Then you can run `trixie load > .env.secrets` to update your env file with the `NPM_TOKEN`
21
+ Then you can run `trixie load > .env.secrets` to update your env file with the `NPM_TOKEN`.
22
+
23
+ Alternatively, you can also leverage the following environment variables:
24
+ - TRIXIE_OP_ADDRESS - sets the authentication address for 1Password
25
+ - TRIXIE_OP_EMAIL - sets the user email address for 1Password
26
+
27
+ Example:
28
+ ```ssh
29
+ TRIXIE_OP_ADDRESS=https://{account}.1password.com \
30
+ TRIXIE_OP_EMAIL=john.doe@email.com \
31
+ trixie load > .env.secrets
32
+ ```
33
+ this will populate your env file with:
34
+ `export NPM_TOKEN={toptals-read-only-npm-token}`
22
35
 
23
36
  ### Groups
24
37
 
@@ -70,9 +83,7 @@ Or install it yourself as:
70
83
  ## TODO IDEAS
71
84
 
72
85
  1. Support Multiple Backends/Password Managers, Trixie::Loader can be refactored to be an adapter for the op CLI
73
- 2. Allow specific Backend options, eg: trixie load --backend op --backend-options '{ "email": "bar@foo.com", "address": "foo.1password.com"}'
74
- 3. Validate the `.trixie.yml`, check if we have the required values for trixie to run
75
- 4. Add a load --cache option, so fetched secrets could be retained for a while without using the Password Manager Backend
86
+ 2. Add a load --cache option, so fetched secrets could be retained for a while without using the Password Manager Backend
76
87
 
77
88
  ## Development
78
89
 
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Trixie
4
+ module Contracts
5
+ # class to validate .trixie.yml files
6
+ # Usage:
7
+ # config_contract = Trixie::Contracts::TrixieYml.new
8
+ # result = config_contract.call(config_options)
9
+ # result.sucess?
10
+ # result.errors.to_h
11
+ class TrixieYml < Dry::Validation::Contract
12
+ params do
13
+ required(:secrets).array(:hash) do
14
+ required(:env).filled(:string)
15
+ required(:value).filled(Types::Strict::String | Types::Strict::Bool | Types::Strict::Integer)
16
+ required(:groups).array(:string)
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Trixie
4
+ module Contracts
5
+ module Types
6
+ include Dry.Types
7
+ end
8
+ end
9
+ end
data/lib/trixie/load.rb CHANGED
@@ -4,6 +4,8 @@ module Trixie
4
4
  # Fetches the specified secrets with op cli and returns them formatted
5
5
  class Load
6
6
  OP_NOT_INSTALLED = "op cli is not installed please download and install at https://developer.1password.com/docs/cli/get-started#install"
7
+ OP_ADDRESS_ENV = "TRIXIE_OP_ADDRESS"
8
+ OP_EMAIL_ENV = "TRIXIE_OP_EMAIL"
7
9
 
8
10
  def initialize(file:, groups: [], format: "env")
9
11
  @file = file
@@ -13,6 +15,7 @@ module Trixie
13
15
 
14
16
  def call
15
17
  verify_op_installed!
18
+ verify_secrets_config!
16
19
 
17
20
  create_account unless account_is_configured?
18
21
 
@@ -20,7 +23,13 @@ module Trixie
20
23
  end
21
24
 
22
25
  def verify_op_installed!
23
- raise Trixie::OpCLINotInstalled, OP_NOT_INSTALLED unless system("which op > /dev/null")
26
+ raise Trixie::OpCLINotInstalledError, OP_NOT_INSTALLED unless system("which op > /dev/null")
27
+ end
28
+
29
+ def verify_secrets_config!
30
+ result = Trixie::Contracts::TrixieYml.new.call(secrets_config)
31
+
32
+ raise Trixie::InvalidConfigError, "Invalid .trixie.yml: #{result.errors.to_h}" if result.errors.any?
24
33
  end
25
34
 
26
35
  def account_is_configured?
@@ -31,7 +40,7 @@ module Trixie
31
40
  warn "* Configuring 1password Account"
32
41
  warn "To get the Secret Key take a look at https://support.1password.com/secret-key/"
33
42
 
34
- `op account add`
43
+ add_op_account
35
44
  end
36
45
 
37
46
  def fetch_secrets
@@ -51,5 +60,14 @@ module Trixie
51
60
  def formatted_secrets
52
61
  @formatter.call(filtered_secrets)
53
62
  end
63
+
64
+ def add_op_account
65
+ cmd = "op account add"
66
+
67
+ cmd += " --address #{ENV[OP_ADDRESS_ENV]}" if ENV[OP_ADDRESS_ENV]
68
+ cmd += " --email #{ENV[OP_EMAIL_ENV]}" if ENV[OP_EMAIL_ENV]
69
+
70
+ `#{cmd}`
71
+ end
54
72
  end
55
73
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Trixie
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.4"
5
5
  end
data/lib/trixie.rb CHANGED
@@ -5,16 +5,20 @@ require "yaml"
5
5
  require "json"
6
6
  require "pathname"
7
7
  require "dry/cli"
8
+ require "dry/validation"
8
9
 
9
10
  require_relative "trixie/version"
10
11
  require_relative "trixie/template"
11
12
  require_relative "trixie/formatter"
13
+ require_relative "trixie/contracts/types"
14
+ require_relative "trixie/contracts/trixie_yml"
12
15
  require_relative "trixie/load"
13
16
  require_relative "trixie/cli"
14
17
 
15
18
  module Trixie # rubocop:disable Style/Documentation
16
19
  class Error < StandardError; end
17
- class OpCLINotInstalled < Error; end
20
+ class OpCLINotInstalledError < Error; end
21
+ class InvalidConfigError < Error; end
18
22
 
19
23
  class << self
20
24
  def root_path
data/trixie.gemspec CHANGED
@@ -32,4 +32,6 @@ Gem::Specification.new do |spec|
32
32
  # For more information and examples about making a new gem, checkout our
33
33
  # guide at: https://bundler.io/guides/creating_gem.html
34
34
  spec.add_dependency "dry-cli", "~> 0.7.0"
35
+ spec.add_dependency "dry-schema", "~> 1.10.0"
36
+ spec.add_dependency "dry-validation", "~> 1.8.0"
35
37
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trixie
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Toptal, LLC
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-08-22 00:00:00.000000000 Z
11
+ date: 2022-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-cli
@@ -24,6 +24,34 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: 0.7.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: dry-schema
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.10.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.10.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: dry-validation
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 1.8.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 1.8.0
27
55
  description:
28
56
  email:
29
57
  - open-source@toptal.com
@@ -35,6 +63,7 @@ executables:
35
63
  extensions: []
36
64
  extra_rdoc_files: []
37
65
  files:
66
+ - ".github/CODEOWNERS"
38
67
  - ".github/workflows/main.yml"
39
68
  - ".gitignore"
40
69
  - ".rspec"
@@ -50,6 +79,8 @@ files:
50
79
  - exe/trixie
51
80
  - lib/trixie.rb
52
81
  - lib/trixie/cli.rb
82
+ - lib/trixie/contracts/trixie_yml.rb
83
+ - lib/trixie/contracts/types.rb
53
84
  - lib/trixie/formatter.rb
54
85
  - lib/trixie/load.rb
55
86
  - lib/trixie/template.rb