Class: SchwarmCli::Commands::Secrets

Inherits:
Base
  • Object
show all
Defined in:
lib/schwarm_cli/commands/secrets.rb

Constant Summary

Constants inherited from Base

Base::DEFAULT_LIST_LIMIT, Base::INHERITED_OPTIONS

Instance Method Summary collapse

Methods inherited from Base

exit_on_failure?, pagination_options

Instance Method Details

#createObject



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/schwarm_cli/commands/secrets.rb', line 37

def create
  handle_errors do
    attrs = {
      github_repository_id: resolve_repo(options[:repo]),
      path: options[:path], content: read_content(required: true)
    }

    data = client.secrets.create(**attrs)
    output_record(data, fields: { "ID" => "id", "Path" => "path" })
  end
end

#delete(id) ⇒ Object



61
62
63
64
65
66
# File 'lib/schwarm_cli/commands/secrets.rb', line 61

def delete(id)
  handle_errors do
    client.secrets.destroy(id)
    puts "Secret #{id} deleted."
  end
end

#listObject



10
11
12
13
14
15
16
17
18
19
# File 'lib/schwarm_cli/commands/secrets.rb', line 10

def list
  handle_errors do
    data = fetch_paged do |page_params|
      client.secrets.list(
        repository_id: resolve_repo(options[:repo]), query: options[:query], **page_params
      )
    end
    output_list(data, columns: [%w[ID id], %w[REPO github_repository_name], %w[PATH path]])
  end
end

#show(id) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/schwarm_cli/commands/secrets.rb', line 22

def show(id)
  handle_errors do
    data = client.secrets.find(id)
    output_record(data, fields: {
                    "ID" => "id", "Repository" => "github_repository_name",
                    "Path" => "path", "Created" => "created_at", "Updated" => "updated_at"
                  })
  end
end

#update(id) ⇒ Object



53
54
55
56
57
58
# File 'lib/schwarm_cli/commands/secrets.rb', line 53

def update(id)
  handle_errors do
    data = client.secrets.update(id, **update_attrs)
    output_record(data, fields: { "ID" => "id", "Path" => "path" })
  end
end