cfc 0.1.3 → 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 +4 -4
- data/README.md +32 -3
- data/lib/cfc/objects/api_token_policy.rb +9 -0
- data/lib/cfc/objects/object.rb +10 -0
- data/lib/cfc/objects/permission_group.rb +10 -0
- data/lib/cfc/objects/user_api_token.rb +6 -0
- data/lib/cfc/objects/zone.rb +5 -0
- data/lib/cfc/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3f5f2aefe1d6f36747241422a791bfa619b4d6dc53b9ef5e93a191b3162eed1a
|
4
|
+
data.tar.gz: 3a0d745cdc585a8290ab9bd0623299968e70fc344a638586115bc16cc35008ad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e0d898e56d580631ab901c37453419d54d7a079378932af2518220294769122f3803d0db4b65b90f99fc1671294edc0973fcf244aee7c854be62ec5a4d37ba21
|
7
|
+
data.tar.gz: 66859b84c931ec9519afe931edb9ec48662607c886a030151dbc82f633056245b5a269a7e7c861745fdca1733da86e21d62bca7fa8ff07e177a2e96aeb9bad01
|
data/README.md
CHANGED
@@ -19,10 +19,39 @@ CFC::Config.configure do |config|
|
|
19
19
|
end
|
20
20
|
```
|
21
21
|
|
22
|
+
Alternatively, you can authenticate with your API key and email address:
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
CFC::Config.configure do |config|
|
26
|
+
config.api_key = 'your_api_key_here'
|
27
|
+
config.api_email = 'your_email_here'
|
28
|
+
end
|
29
|
+
```
|
30
|
+
|
22
31
|
You can then use the library either by instantiating `CFC::API` and using that class to send API requests directly,
|
23
|
-
or,
|
24
|
-
|
25
|
-
|
32
|
+
or, you can use pre-provided objects in `lib/objects/`, which represent a data type from the Cloudflare API and may
|
33
|
+
provide methods to perform common or simple tasks on those types. For instance, to list DNS records in all zones you
|
34
|
+
administer (assuming you've already configured the gem as above):
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
CFC::Zone.list.each do |zone|
|
38
|
+
puts zone.records
|
39
|
+
end
|
40
|
+
```
|
41
|
+
|
42
|
+
Or if you need to roll all of your current API tokens:
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
new_tokens = CFC::UserAPIToken.list.each do |token|
|
46
|
+
token.roll['result']
|
47
|
+
end
|
48
|
+
|
49
|
+
# Once you've rolled tokens, of course, your existing token won't work, so you
|
50
|
+
# probably want to update that.
|
51
|
+
CFC::Config.configure do |config|
|
52
|
+
config.token = new_tokens[0]
|
53
|
+
end
|
54
|
+
```
|
26
55
|
|
27
56
|
## Contributing
|
28
57
|
As with all Codidact projects, contributions are welcome and must adhere to the
|
@@ -1,8 +1,17 @@
|
|
1
|
+
require 'json'
|
1
2
|
require_relative 'object'
|
2
3
|
require_relative 'permission_group'
|
3
4
|
|
4
5
|
module CFC
|
5
6
|
class APITokenPolicy < CFC::APIObject
|
6
7
|
relationship :permission_groups, CFC::PermissionGroup, multiple: true
|
8
|
+
|
9
|
+
def self.build(effect:, resources:, permission_groups:)
|
10
|
+
new(JSON.parse(JSON.dump({
|
11
|
+
effect: effect,
|
12
|
+
resources: resources&.map { |k, v| [k.to_json, v] }&.to_h,
|
13
|
+
permission_groups: permission_groups
|
14
|
+
}.compact)))
|
15
|
+
end
|
7
16
|
end
|
8
17
|
end
|
data/lib/cfc/objects/object.rb
CHANGED
@@ -34,6 +34,16 @@ module CFC
|
|
34
34
|
|
35
35
|
alias to_s inspect
|
36
36
|
|
37
|
+
def to_h
|
38
|
+
@data
|
39
|
+
end
|
40
|
+
|
41
|
+
alias as_json to_h
|
42
|
+
|
43
|
+
def to_json(*args)
|
44
|
+
as_json.to_json(*args)
|
45
|
+
end
|
46
|
+
|
37
47
|
def self.relationship(property, cls, multiple: false)
|
38
48
|
unless defined?(@relationships)
|
39
49
|
@relationships = []
|
@@ -1,6 +1,16 @@
|
|
1
|
+
require 'json'
|
1
2
|
require_relative 'object'
|
2
3
|
|
3
4
|
module CFC
|
4
5
|
class PermissionGroup < CFC::APIObject
|
6
|
+
@api = CFC::API.new
|
7
|
+
|
8
|
+
def self.list
|
9
|
+
@api.get_json('user/tokens/permission_groups')['result'].map { |pg| new(pg) }
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_json(*_args)
|
13
|
+
JSON.dump({ id: id, name: name })
|
14
|
+
end
|
5
15
|
end
|
6
16
|
end
|
@@ -24,6 +24,12 @@ module CFC
|
|
24
24
|
@api.put_to_json("user/tokens/#{identifier}/value", {})
|
25
25
|
end
|
26
26
|
|
27
|
+
def self.create(name:, policies:, not_before: nil, expires_on: nil, condition: nil)
|
28
|
+
data = { name: name, policies: policies, not_before: not_before, expires_on: expires_on, condition: condition }
|
29
|
+
data = data.compact
|
30
|
+
new(@api.post_to_json('user/tokens', data)['result'])
|
31
|
+
end
|
32
|
+
|
27
33
|
def details
|
28
34
|
CFC::UserAPIToken.details(id)
|
29
35
|
end
|
data/lib/cfc/objects/zone.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'json'
|
1
2
|
require_relative 'object'
|
2
3
|
require_relative 'user'
|
3
4
|
require_relative 'account'
|
@@ -23,5 +24,9 @@ module CFC
|
|
23
24
|
data = @api.get_json("zones/#{id}/dns_records")['result']
|
24
25
|
data.map { |r| CFC::Record.new(r) }
|
25
26
|
end
|
27
|
+
|
28
|
+
def to_json(*_args)
|
29
|
+
"com.cloudflare.api.account.zone.#{id}"
|
30
|
+
end
|
26
31
|
end
|
27
32
|
end
|
data/lib/cfc/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cfc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- The Codidact Foundation
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-01-
|
11
|
+
date: 2021-01-07 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: 'Simple API library for interacting with the Cloudflare API. See GitHub
|
14
14
|
for usage details: https://github.com/codidact/cfc'
|