Class: Fizzy::Auth

Inherits:
Object
  • Object
show all
Defined in:
lib/fizzy/auth.rb

Constant Summary collapse

CONFIG_DIR =
File.expand_path("~/.config/fizzy-cli")
TOKEN_FILE =
File.join(CONFIG_DIR, "tokens.yml")

Class Method Summary collapse

Class Method Details

.normalize_slug(slug) ⇒ Object



18
19
20
# File 'lib/fizzy/auth.rb', line 18

def self.normalize_slug(slug)
  slug&.delete_prefix("/")
end

.resolve(account_slug = nil) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'lib/fizzy/auth.rb', line 8

def self.resolve( = nil)
  if ENV["FIZZY_TOKEN"]
    raise AuthError, "--account required with FIZZY_TOKEN" unless 

    return { "access_token" => ENV["FIZZY_TOKEN"], "account_slug" => normalize_slug() }
  end

  resolve_from_file()
end

.token_dataObject



22
23
24
25
26
27
28
29
# File 'lib/fizzy/auth.rb', line 22

def self.token_data
  unless File.exist?(TOKEN_FILE)
    raise AuthError,
          "No tokens file at #{TOKEN_FILE}. Run: fizzy auth login --token TOKEN"
  end

  YAML.safe_load_file(TOKEN_FILE, permitted_classes: [Time])
end