cloud-sh 1.0.1 → 1.0.2

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: 7d542846c4ade970de1b85af0ea33def7b5c4d373c82e70b33e961f3cfbb6c51
4
- data.tar.gz: cb699d91552a1174d7e424d20e5be9767b575be019bb62bc25293fdad3c91414
3
+ metadata.gz: fb6f375062f21115ff9b54d8acd36b5769531f9e0ee6e84e1e064bf45d7e049b
4
+ data.tar.gz: 6a93eaebf5227c3bd988ad8b1407689bd10dd0f1b2b1a5f310dd31db284a6e89
5
5
  SHA512:
6
- metadata.gz: 30425d3f24bfb1481adf1ea89dc120e4e1f19ebea5b1b635ecbb03769831f29f738f572b94995e6459c68d7493076b5cfe4e53ce012eb5c83f8771a7de35fe8a
7
- data.tar.gz: a71f8117f7909c240eea82d4f4aafb458aebca95a6b41852d0c18b4138c747e5023a4d6ea6098a4c5f371553699dd511a1ae367ace37dda894064608362f0830
6
+ metadata.gz: aac2cef05fe9cac7e3b327e772c2b5c9e94144f4e5686383dcb896b2afc48bee784c805f1ad8d0aa940773786415af1c04b0462d6b0644626ea665b6583a8a5d
7
+ data.tar.gz: cc74cd7a0da0c3c2a415d1a647d6c6e2a4ab18a75a484b5c9b6955ebd90e94feec10838bc144c0578360e43981a128d19f6bc243896a90164c8c378c4dcaf206
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cloud-sh (1.0.0)
4
+ cloud-sh (1.0.2)
5
5
  gli
6
6
 
7
7
  GEM
data/lib/cloud/sh/cli.rb CHANGED
@@ -10,6 +10,7 @@ module Cloud
10
10
 
11
11
  desc "Refresh aliases"
12
12
  command :refresh do |c|
13
+ c.switch :force, negatable: false, default_value: false, desc: "Force refresh"
13
14
  c.action do |global_options, options, args|
14
15
  Cloud::Sh::Commands::Refresh.execute(global_options, options, args)
15
16
  end
@@ -9,7 +9,7 @@ module Cloud
9
9
  attr_reader :aliases
10
10
 
11
11
  def execute
12
- Cloud::Sh::Providers::DigitalOcean.refresh_k8s_configs
12
+ Cloud::Sh::Providers::DigitalOcean.refresh_k8s_configs(force: options[:force])
13
13
  build_aliases
14
14
  save_aliases
15
15
  end
@@ -3,7 +3,7 @@
3
3
  module Cloud
4
4
  module Sh
5
5
  class Config
6
- attr_reader :accounts
6
+ attr_reader :accounts, :raw
7
7
 
8
8
  def initialize
9
9
  @accounts = []
@@ -12,8 +12,12 @@ module Cloud
12
12
 
13
13
  def read_config
14
14
  return unless File.exist?(config_file)
15
- config = YAML.safe_load(File.read(config_file))
16
- config.each do |account_config|
15
+ @raw = YAML.safe_load(File.read(config_file))
16
+ load_accounts
17
+ end
18
+
19
+ def load_accounts
20
+ raw["accounts"].each do |account_config|
17
21
  accounts << Account.new(account_config)
18
22
  end
19
23
  end
@@ -56,11 +60,11 @@ module Cloud
56
60
  end
57
61
 
58
62
  def find_cluster(name)
59
- clusters.find { |cluster| cluster.name == name }
63
+ clusters.find { |cluster| cluster.name == name } || clusters.push(Cluster.new("name" => name)).last
60
64
  end
61
65
 
62
66
  def find_database(name)
63
- databases.find { |database| database.name == name }
67
+ databases.find { |database| database.name == name } || databases.push(Database.new("name" => name)).last
64
68
  end
65
69
 
66
70
  def ignore_database?(name)
@@ -7,8 +7,8 @@ module Cloud
7
7
  module Sh
8
8
  module Providers
9
9
  class DigitalOcean < Base
10
- def self.refresh_k8s_configs
11
- return if File.exist?(kube_config) && (Time.now.to_i - File.mtime(kube_config).to_i) < 3600
10
+ def self.refresh_k8s_configs(force: false)
11
+ return if !force && File.exist?(kube_config) && (Time.now.to_i - File.mtime(kube_config).to_i) < 3600
12
12
  configs = Cloud::Sh.config.accounts.map { |account| new(account).k8s_configs }.flatten.compact
13
13
  config = configs.shift
14
14
  configs.each do |cfg|
@@ -16,7 +16,7 @@ module Cloud
16
16
  config["contexts"] += cfg["contexts"]
17
17
  config["users"] += cfg["users"]
18
18
  end
19
- config["current-context"] = config["contexts"].first["name"]
19
+ config["current-context"] = Cloud::Sh.config.raw["default_kubectl_context"] || config["contexts"].first["name"]
20
20
  File.write(kube_config, YAML.dump(config))
21
21
  end
22
22
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Cloud
4
4
  module Sh
5
- VERSION = "1.0.1"
5
+ VERSION = "1.0.2"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloud-sh
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cristian Bica