pal_tool 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +3 -0
- data/.rubocop.yml +132 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/Dockerfile +10 -0
- data/Gemfile +14 -0
- data/Gemfile.lock +72 -0
- data/LICENSE.txt +21 -0
- data/README.md +124 -0
- data/Rakefile +12 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/exe/pal +47 -0
- data/lib/pal/common/local_file_utils.rb +37 -0
- data/lib/pal/common/object_helpers.rb +27 -0
- data/lib/pal/common/safe_hash_parse.rb +87 -0
- data/lib/pal/configuration.rb +77 -0
- data/lib/pal/handler/base.rb +138 -0
- data/lib/pal/handler/definitions/aws_cur.json +8 -0
- data/lib/pal/handler/manager.rb +30 -0
- data/lib/pal/handler/processor.rb +84 -0
- data/lib/pal/log.rb +29 -0
- data/lib/pal/main.rb +63 -0
- data/lib/pal/operation/actions.rb +106 -0
- data/lib/pal/operation/exporter.rb +183 -0
- data/lib/pal/operation/filter_evaluator.rb +249 -0
- data/lib/pal/operation/processor_context.rb +50 -0
- data/lib/pal/operation/projection.rb +302 -0
- data/lib/pal/plugin.rb +61 -0
- data/lib/pal/request/metadata.rb +19 -0
- data/lib/pal/request/runbook.rb +54 -0
- data/lib/pal/version.rb +5 -0
- data/lib/pal.rb +43 -0
- data/plugins/PLUGINS.md +1 -0
- data/plugins/operation/terminal_exporter_impl.rb +14 -0
- data/templates/DOCUMENTATION.md +46 -0
- data/templates/aws/data_transfer/data_transfer_breakdown.json +93 -0
- data/templates/aws/ec2/ec2_compute_hourly_breakdown.json +63 -0
- data/templates/aws/ec2/ec2_operation_breakdown.json +64 -0
- data/templates/aws/ec2/ec2_spend_breakdown.json +63 -0
- data/templates/aws/global_resource_and_usage_type_costs.json +41 -0
- data/templates/aws/kms/kms_usage_counts.json +52 -0
- data/templates/aws/kms/kms_usage_list.json +80 -0
- data/templates/aws/kms/list_of_kms_keys.json +57 -0
- data/templates/aws/reserved_instances/all_reserved_instance_expiries.json +41 -0
- data/templates/aws/reserved_instances/reserved_instance_opportunities.json +60 -0
- data/templates/aws/summary_cost_between_date_range.json +43 -0
- data/templates/aws/summary_daily_breakdown_costs.json +39 -0
- data/templates/azure/global_resource_type_summary.json +47 -0
- metadata +136 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e5f67faa3445eeb19902f29060727941545cd135f8ba3f63a743880c5ab4bbe8
|
4
|
+
data.tar.gz: b8637e50cea0501daf9bb845341e8f1b2cc3e84e2e45cef8fec1a1a326ce4423
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8c1dea3e1bacb580495000ed681d1d4e7a1f080dd6f5d4734bfeadba7c7bd6229b7a11fc0a1401b03a5703321a016f1a370c62e507911b5f48715339899ed383
|
7
|
+
data.tar.gz: 3c84a52fd6e66aa093d36b6fa8b5799468ef8a1292b9bb50dfe51c057b2ba57bf0ae4c303e8bb33b9b56c0a6b7107f2f5268e7b18547674579aad162ee91b2c1
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.6
|
3
|
+
|
4
|
+
Style/StringLiterals:
|
5
|
+
Enabled: true
|
6
|
+
EnforcedStyle: double_quotes
|
7
|
+
|
8
|
+
Style/StringLiteralsInInterpolation:
|
9
|
+
Enabled: true
|
10
|
+
EnforcedStyle: double_quotes
|
11
|
+
|
12
|
+
Layout/LineLength:
|
13
|
+
Max: 120
|
14
|
+
|
15
|
+
# Too short methods lead to extraction of single-use methods, which can make
|
16
|
+
# the code easier to read (by naming things), but can also clutter the class
|
17
|
+
Metrics/MethodLength:
|
18
|
+
Max: 20
|
19
|
+
|
20
|
+
# The guiding principle of classes is SRP, SRP can't be accurately measured by LoC
|
21
|
+
Metrics/ClassLength:
|
22
|
+
Max: 1500
|
23
|
+
|
24
|
+
# No space makes the method definition shorter and differentiates
|
25
|
+
# from a regular assignment.
|
26
|
+
Layout/SpaceAroundEqualsInParameterDefault:
|
27
|
+
EnforcedStyle: no_space
|
28
|
+
|
29
|
+
# We do not need to support Ruby 1.9, so this is good to use.
|
30
|
+
Style/SymbolArray:
|
31
|
+
Enabled: true
|
32
|
+
|
33
|
+
# Most readable form.
|
34
|
+
Style/OptionHash:
|
35
|
+
EnforcedHashRocketStyle: table
|
36
|
+
EnforcedColonStyle: table
|
37
|
+
|
38
|
+
# Mixing the styles looks just silly.
|
39
|
+
Style/HashSyntax:
|
40
|
+
EnforcedStyle: ruby19_no_mixed_keys
|
41
|
+
|
42
|
+
# has_key? and has_value? are far more readable than key? and value?
|
43
|
+
Style/PreferredHashMethods:
|
44
|
+
Enabled: false
|
45
|
+
|
46
|
+
# String#% is by far the least verbose and only object oriented variant.
|
47
|
+
Style/FormatString:
|
48
|
+
EnforcedStyle: percent
|
49
|
+
|
50
|
+
Style/CollectionMethods:
|
51
|
+
Enabled: true
|
52
|
+
PreferredMethods:
|
53
|
+
# inject seems more common in the community.
|
54
|
+
reduce: "inject"
|
55
|
+
|
56
|
+
|
57
|
+
# Either allow this style or don't. Marking it as safe with parenthesis
|
58
|
+
# is silly. Let's try to live without them for now.
|
59
|
+
Style/ParenthesesAroundCondition:
|
60
|
+
AllowSafeAssignment: false
|
61
|
+
Lint/AssignmentInCondition:
|
62
|
+
AllowSafeAssignment: false
|
63
|
+
|
64
|
+
# A specialized exception class will take one or more arguments and construct the message from it.
|
65
|
+
# So both variants make sense.
|
66
|
+
Style/RaiseArgs:
|
67
|
+
Enabled: false
|
68
|
+
|
69
|
+
# Indenting the chained dots beneath each other is not supported by this cop,
|
70
|
+
# see https://github.com/bbatsov/rubocop/issues/1633
|
71
|
+
Layout/MultilineOperationIndentation:
|
72
|
+
Enabled: false
|
73
|
+
|
74
|
+
# Fail is an alias of raise. Avoid aliases, it's more cognitive load for no gain.
|
75
|
+
# The argument that fail should be used to abort the program is wrong too,
|
76
|
+
# there's Kernel#abort for that.
|
77
|
+
Style/SignalException:
|
78
|
+
EnforcedStyle: only_raise
|
79
|
+
|
80
|
+
# Suppressing exceptions can be perfectly fine, and be it to avoid to
|
81
|
+
# explicitly type nil into the rescue since that's what you want to return,
|
82
|
+
# or suppressing LoadError for optional dependencies
|
83
|
+
Lint/SuppressedException:
|
84
|
+
Enabled: false
|
85
|
+
|
86
|
+
#Layout/SpaceInsideBlockBraces:
|
87
|
+
# # The space here provides no real gain in readability while consuming
|
88
|
+
# # horizontal space that could be used for a better parameter name.
|
89
|
+
# # Also {| differentiates better from a hash than { | does.
|
90
|
+
# SpaceBeforeBlockParameters: false
|
91
|
+
|
92
|
+
# No trailing space differentiates better from the block:
|
93
|
+
# foo} means hash, foo } means block.
|
94
|
+
Layout/SpaceInsideHashLiteralBraces:
|
95
|
+
EnforcedStyle: no_space
|
96
|
+
|
97
|
+
# { ... } for multi-line blocks is okay, follow Weirichs rule instead:
|
98
|
+
# https://web.archive.org/web/20140221124509/http://onestepback.org/index.cgi/Tech/Ruby/BraceVsDoEnd.rdoc
|
99
|
+
Style/BlockDelimiters:
|
100
|
+
Enabled: false
|
101
|
+
|
102
|
+
# do / end blocks should be used for side effects,
|
103
|
+
# methods that run a block for side effects and have
|
104
|
+
# a useful return value are rare, assign the return
|
105
|
+
# value to a local variable for those cases.
|
106
|
+
Style/MethodCalledOnDoEndBlock:
|
107
|
+
Enabled: true
|
108
|
+
|
109
|
+
# Enforcing the names of variables? To single letter ones? Just no.
|
110
|
+
Style/SingleLineBlockParams:
|
111
|
+
Enabled: false
|
112
|
+
|
113
|
+
# Shadowing outer local variables with block parameters is often useful
|
114
|
+
# to not reinvent a new name for the same thing, it highlights the relation
|
115
|
+
# between the outer variable and the parameter. The cases where it's actually
|
116
|
+
# confusing are rare, and usually bad for other reasons already, for example
|
117
|
+
# because the method is too long.
|
118
|
+
Lint/ShadowingOuterLocalVariable:
|
119
|
+
Enabled: false
|
120
|
+
|
121
|
+
# Check with yard instead.
|
122
|
+
Style/Documentation:
|
123
|
+
Enabled: false
|
124
|
+
|
125
|
+
# There are valid cases, for example debugging Cucumber steps,
|
126
|
+
# also they'll fail CI anyway
|
127
|
+
Lint/Debugger:
|
128
|
+
Enabled: false
|
129
|
+
|
130
|
+
# Style preference
|
131
|
+
Style/MethodDefParentheses:
|
132
|
+
Enabled: false
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
6
|
+
|
7
|
+
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
|
8
|
+
|
9
|
+
## Our Standards
|
10
|
+
|
11
|
+
Examples of behavior that contributes to a positive environment for our community include:
|
12
|
+
|
13
|
+
* Demonstrating empathy and kindness toward other people
|
14
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
15
|
+
* Giving and gracefully accepting constructive feedback
|
16
|
+
* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
|
17
|
+
* Focusing on what is best not just for us as individuals, but for the overall community
|
18
|
+
|
19
|
+
Examples of unacceptable behavior include:
|
20
|
+
|
21
|
+
* The use of sexualized language or imagery, and sexual attention or
|
22
|
+
advances of any kind
|
23
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
24
|
+
* Public or private harassment
|
25
|
+
* Publishing others' private information, such as a physical or email
|
26
|
+
address, without their explicit permission
|
27
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
28
|
+
professional setting
|
29
|
+
|
30
|
+
## Enforcement Responsibilities
|
31
|
+
|
32
|
+
Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
|
33
|
+
|
34
|
+
Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
|
35
|
+
|
36
|
+
## Scope
|
37
|
+
|
38
|
+
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
|
39
|
+
|
40
|
+
## Enforcement
|
41
|
+
|
42
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at me@williamthom.as. All complaints will be reviewed and investigated promptly and fairly.
|
43
|
+
|
44
|
+
All community leaders are obligated to respect the privacy and security of the reporter of any incident.
|
45
|
+
|
46
|
+
## Enforcement Guidelines
|
47
|
+
|
48
|
+
Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
|
49
|
+
|
50
|
+
### 1. Correction
|
51
|
+
|
52
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
|
53
|
+
|
54
|
+
**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
|
55
|
+
|
56
|
+
### 2. Warning
|
57
|
+
|
58
|
+
**Community Impact**: A violation through a single incident or series of actions.
|
59
|
+
|
60
|
+
**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
|
61
|
+
|
62
|
+
### 3. Temporary Ban
|
63
|
+
|
64
|
+
**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
|
65
|
+
|
66
|
+
**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
|
67
|
+
|
68
|
+
### 4. Permanent Ban
|
69
|
+
|
70
|
+
**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
|
71
|
+
|
72
|
+
**Consequence**: A permanent ban from any sort of public interaction within the community.
|
73
|
+
|
74
|
+
## Attribution
|
75
|
+
|
76
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
|
77
|
+
available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
78
|
+
|
79
|
+
Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
|
80
|
+
|
81
|
+
[homepage]: https://www.contributor-covenant.org
|
82
|
+
|
83
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
84
|
+
https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
|
data/Dockerfile
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
# Specify your gem's dependencies in pal.gemspec
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
gem 'jsonpath', '~> 1.1', '>= 1.1.2'
|
9
|
+
|
10
|
+
gem "rake", "~> 13.0"
|
11
|
+
|
12
|
+
gem "rspec", "~> 3.0"
|
13
|
+
|
14
|
+
gem "rubocop", "~> 1.21"
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
pal_tool (0.2.1)
|
5
|
+
rcsv
|
6
|
+
terminal-table
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
ast (2.4.2)
|
12
|
+
diff-lcs (1.4.4)
|
13
|
+
docile (1.4.0)
|
14
|
+
jsonpath (1.1.2)
|
15
|
+
multi_json
|
16
|
+
multi_json (1.15.0)
|
17
|
+
parallel (1.21.0)
|
18
|
+
parser (3.0.2.0)
|
19
|
+
ast (~> 2.4.1)
|
20
|
+
rainbow (3.0.0)
|
21
|
+
rake (13.0.6)
|
22
|
+
rcsv (0.3.1)
|
23
|
+
regexp_parser (2.1.1)
|
24
|
+
rexml (3.2.5)
|
25
|
+
rspec (3.10.0)
|
26
|
+
rspec-core (~> 3.10.0)
|
27
|
+
rspec-expectations (~> 3.10.0)
|
28
|
+
rspec-mocks (~> 3.10.0)
|
29
|
+
rspec-core (3.10.1)
|
30
|
+
rspec-support (~> 3.10.0)
|
31
|
+
rspec-expectations (3.10.1)
|
32
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
33
|
+
rspec-support (~> 3.10.0)
|
34
|
+
rspec-mocks (3.10.2)
|
35
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
36
|
+
rspec-support (~> 3.10.0)
|
37
|
+
rspec-support (3.10.3)
|
38
|
+
rubocop (1.22.3)
|
39
|
+
parallel (~> 1.10)
|
40
|
+
parser (>= 3.0.0.0)
|
41
|
+
rainbow (>= 2.2.2, < 4.0)
|
42
|
+
regexp_parser (>= 1.8, < 3.0)
|
43
|
+
rexml
|
44
|
+
rubocop-ast (>= 1.12.0, < 2.0)
|
45
|
+
ruby-progressbar (~> 1.7)
|
46
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
47
|
+
rubocop-ast (1.13.0)
|
48
|
+
parser (>= 3.0.1.1)
|
49
|
+
ruby-progressbar (1.11.0)
|
50
|
+
simplecov (0.21.2)
|
51
|
+
docile (~> 1.1)
|
52
|
+
simplecov-html (~> 0.11)
|
53
|
+
simplecov_json_formatter (~> 0.1)
|
54
|
+
simplecov-html (0.12.3)
|
55
|
+
simplecov_json_formatter (0.1.4)
|
56
|
+
terminal-table (3.0.2)
|
57
|
+
unicode-display_width (>= 1.1.1, < 3)
|
58
|
+
unicode-display_width (2.1.0)
|
59
|
+
|
60
|
+
PLATFORMS
|
61
|
+
x86_64-linux
|
62
|
+
|
63
|
+
DEPENDENCIES
|
64
|
+
jsonpath (~> 1.1, >= 1.1.2)
|
65
|
+
pal_tool!
|
66
|
+
rake (~> 13.0)
|
67
|
+
rspec (~> 3.0)
|
68
|
+
rubocop (~> 1.21)
|
69
|
+
simplecov
|
70
|
+
|
71
|
+
BUNDLED WITH
|
72
|
+
2.2.30
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2022 william
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
# Pal
|
2
|
+
|
3
|
+
![run tests](https://github.com/williamthom-as/pal/actions/workflows/rspec.yml/badge.svg)
|
4
|
+
|
5
|
+
Pal is a tool for automating simple tabular data analysis. It provides just enough features to be useful.
|
6
|
+
It has been primarily designed to assist with cloud billing reports, but can work generically across any tabular CSV file.
|
7
|
+
- **Reporting as Code**: Describe simple routines to **extract**, **filter** and **manipulate** data from spreadsheets.
|
8
|
+
- Quickly filter, manipulate and transform your spreadsheet into consumable, understandable insight using one or more provided export functions (including CSV, chart, table, interactive report).
|
9
|
+
- Export filtered data into common data formats for further analysis or visualisation in a different tool.
|
10
|
+
- Run, version and share report template definitions with others.
|
11
|
+
- **Plugins**: Extend Pal hooks with your own functionality. Read more about it [here](plugins/PLUGINS.md).
|
12
|
+
|
13
|
+
## Use Cases
|
14
|
+
|
15
|
+
Common use cases are:
|
16
|
+
- Analyse data using a "write once, run any time" templating approach [see examples below].
|
17
|
+
- Analysing cloud spend can be a complex task, use Pal to help start the conversation or drill deep into specifics.
|
18
|
+
- Automate the break down of large and unwieldy provider spreadsheets into more digestable and "Excel friendly" files.
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
Two things are needed to run Pal, the *spreadsheet* and a *template* file. Optionally, you can provide an output directory, otherwise it will use ``/tmp/pal``.
|
23
|
+
|
24
|
+
Provide these to Pal as arguments as follows:
|
25
|
+
|
26
|
+
$ pal -t /file/path/to/template.json -s /file/path/to/billing_file.csv -o /my/output/folder
|
27
|
+
|
28
|
+
## Example
|
29
|
+
|
30
|
+
Below shows the template and export from a simple request.
|
31
|
+
|
32
|
+
It shows grouping all records from an AWS Cost and Usage Report by product and usage type, summing blended cost fields.
|
33
|
+
|
34
|
+
#### Template
|
35
|
+
```json
|
36
|
+
{
|
37
|
+
...
|
38
|
+
"filters": {
|
39
|
+
"condition": "AND",
|
40
|
+
"rules": [{
|
41
|
+
"field": "lineItem/BlendedCost",
|
42
|
+
"type": "number",
|
43
|
+
"operator": "greater",
|
44
|
+
"value": 0
|
45
|
+
}
|
46
|
+
]
|
47
|
+
},
|
48
|
+
"exporter" : {
|
49
|
+
"types" : [{
|
50
|
+
"name" : "table",
|
51
|
+
...
|
52
|
+
}],
|
53
|
+
"properties" : [
|
54
|
+
"lineItem/ProductCode",
|
55
|
+
"lineItem/UsageType",
|
56
|
+
"lineItem/BlendedCost"
|
57
|
+
],
|
58
|
+
"actions" : {
|
59
|
+
"group_by" : ["lineItem/ProductCode", "lineItem/UsageType"],
|
60
|
+
"sort_by" : "sum_lineItem/BlendedCost",
|
61
|
+
"projection" : {
|
62
|
+
"type" : "sum",
|
63
|
+
"property" : "lineItem/BlendedCost"
|
64
|
+
}
|
65
|
+
}
|
66
|
+
}
|
67
|
+
}
|
68
|
+
```
|
69
|
+
*Find full template [here](templates/aws/global_resource_and_usage_type_costs.json)*.
|
70
|
+
|
71
|
+
#### Exported
|
72
|
+
```bash
|
73
|
+
+------------------------------------------------------------------------------------+
|
74
|
+
| AWS CUR Product/Usage Type Combined Costs |
|
75
|
+
+----------------------+----------------------------------+--------------------------+
|
76
|
+
| lineItem/ProductCode | lineItem/UsageType | sum_lineItem/BlendedCost |
|
77
|
+
+----------------------+----------------------------------+--------------------------+
|
78
|
+
| AmazonEC2 | APS2-EBS:VolumeUsage.gp2 | 48.80 |
|
79
|
+
| AmazonRDS | APS2-RDS:ChargedBackupUsage | 8.12 |
|
80
|
+
| AmazonEC2 | APS2-ElasticIP:IdleAddress | 6.71 |
|
81
|
+
| AmazonEC2 | APS2-EBS:SnapshotUsage | 5.64 |
|
82
|
+
...
|
83
|
+
```
|
84
|
+
|
85
|
+
Understand more about how templates work by clicking [here](templates/DOCUMENTATION.md).
|
86
|
+
|
87
|
+
## Installation
|
88
|
+
|
89
|
+
Install it yourself as:
|
90
|
+
|
91
|
+
$ gem install pal
|
92
|
+
|
93
|
+
### Getting started *quickly*
|
94
|
+
To quickly spin up a development environment, please use the Dockerfile provided. Run:
|
95
|
+
|
96
|
+
$ docker build -t pal .
|
97
|
+
$ docker run -it --rm pal bash
|
98
|
+
|
99
|
+
Please do not forget to mount any volumes which may have templates that you wish to use. Default templates are available too, found under `/app/templates`.
|
100
|
+
|
101
|
+
Once set up and connected to your container, run:
|
102
|
+
|
103
|
+
$ pal -t /file/path/to/template.json -s /file/path/to/billing_file.csv -o /my/output/folder
|
104
|
+
|
105
|
+
## Upcoming changes
|
106
|
+
1. Provide the ability to format exports
|
107
|
+
|
108
|
+
## Development
|
109
|
+
|
110
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
111
|
+
|
112
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
113
|
+
|
114
|
+
## Contributing
|
115
|
+
|
116
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/williamthom-as/pal. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/pal/blob/master/CODE_OF_CONDUCT.md).
|
117
|
+
|
118
|
+
## License
|
119
|
+
|
120
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
121
|
+
|
122
|
+
## Code of Conduct
|
123
|
+
|
124
|
+
Everyone interacting in the Pal project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/pal/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
require "pal"
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require "irb"
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/exe/pal
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "optparse"
|
5
|
+
require "pal"
|
6
|
+
|
7
|
+
include Pal::Configuration
|
8
|
+
include Pal::Log
|
9
|
+
|
10
|
+
request_config = Config.new
|
11
|
+
|
12
|
+
OptionParser.new do |opts|
|
13
|
+
opts.banner = "Usage: pal_cli [options]"
|
14
|
+
|
15
|
+
opts.on("-t", "--template_file=template_file", "Template definition file") do |t|
|
16
|
+
request_config.template_file_loc = t
|
17
|
+
end
|
18
|
+
|
19
|
+
opts.on("-s", "--source_file=source_file", "Source file") do |s|
|
20
|
+
request_config.source_file_loc = s
|
21
|
+
end
|
22
|
+
|
23
|
+
opts.on("-o", "--output_dir=output_dir", "Output directory") do |o|
|
24
|
+
request_config.output_dir = o
|
25
|
+
end
|
26
|
+
|
27
|
+
opts.on("-h", "--help", "Prints this help") do
|
28
|
+
puts opts
|
29
|
+
exit
|
30
|
+
end
|
31
|
+
end.parse!
|
32
|
+
|
33
|
+
begin
|
34
|
+
request_config.validate
|
35
|
+
rescue Pal::ValidationError
|
36
|
+
log_error("The request provided was invalid, please fix the validation errors and try again.")
|
37
|
+
return
|
38
|
+
end
|
39
|
+
|
40
|
+
log_info "Config loaded successfully"
|
41
|
+
main = Pal::Main.new(request_config)
|
42
|
+
|
43
|
+
log_info "Setting up runbooks to be processed ..."
|
44
|
+
main.setup
|
45
|
+
|
46
|
+
log_info "... set up complete. Beginning process"
|
47
|
+
main.process
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "pal"
|
4
|
+
require "fileutils"
|
5
|
+
|
6
|
+
module Pal
|
7
|
+
module Common
|
8
|
+
class LocalFileUtils
|
9
|
+
def self.with_file(path, extension, &block)
|
10
|
+
dir = File.dirname(path)
|
11
|
+
|
12
|
+
FileUtils.mkdir_p(dir) unless File.directory?(dir)
|
13
|
+
|
14
|
+
path << ".#{extension}"
|
15
|
+
File.open(path, "w", &block)
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.clean_dir(path)
|
19
|
+
dir = File.dirname(path)
|
20
|
+
|
21
|
+
FileUtils.rm_rf(dir) if File.directory?(dir)
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.remove_file(path_to_file)
|
25
|
+
File.delete(path_to_file) if File.exist?(path_to_file)
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.read_file(file_location)
|
29
|
+
result = file_location.start_with?("/") ? file_location : File.join(File.dirname(__FILE__), file_location)
|
30
|
+
|
31
|
+
raise "No file found at [#{result}]" unless File.exist? result
|
32
|
+
|
33
|
+
File.read(result)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "pal"
|
4
|
+
|
5
|
+
module Pal
|
6
|
+
# Object helper module
|
7
|
+
module ObjectHelpers
|
8
|
+
def attributes=(hash)
|
9
|
+
hash.each do |key, value|
|
10
|
+
send("#{key}=", value)
|
11
|
+
rescue NoMethodError
|
12
|
+
Pal.logger.warn("Error deserializing object: No property for #{key}")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def from_json(json)
|
17
|
+
return from_hash(json) if json.is_a?(Hash) # Just a guard in case serialisation is done
|
18
|
+
|
19
|
+
from_hash(JSON.parse(json))
|
20
|
+
end
|
21
|
+
|
22
|
+
def from_hash(hash)
|
23
|
+
self.attributes = hash
|
24
|
+
self
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|