cyclonedx-cocoapods 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +21 -0
- data/LICENSE +201 -0
- data/NOTICE +5 -0
- data/README.md +92 -0
- data/exe/cyclonedx-cocoapods +23 -0
- data/lib/cyclonedx/cocoapods/bom_builder.rb +158 -0
- data/lib/cyclonedx/cocoapods/cli_runner.rb +224 -0
- data/lib/cyclonedx/cocoapods/component.rb +37 -0
- data/lib/cyclonedx/cocoapods/license.rb +44 -0
- data/lib/cyclonedx/cocoapods/pod.rb +108 -0
- data/lib/cyclonedx/cocoapods/pod_attributes.rb +72 -0
- data/lib/cyclonedx/cocoapods/source.rb +59 -0
- data/lib/cyclonedx/cocoapods/spdx-licenses.json +485 -0
- data/lib/cyclonedx/cocoapods/version.rb +29 -0
- metadata +132 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e656666b5b0297c98ddebe571a31e68ada3ff7fa9a048fc10f4f824fee1982c8
|
4
|
+
data.tar.gz: d398292e90265bf460874a2db759fb20a7d596067c4aa35afdb07d942aead192
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1d7e28f6e783cc643d6563671412747c57ed8f26c49fdb34df1bc708662e6369027444f3ef2a4b0be84e1429538d12f80017a7ea61be0b5612210ae272ee00fa
|
7
|
+
data.tar.gz: 2e99db6f7a0f502190ace2511e954b6c43439eb21b5b13509165590ea3075b30ea8ee9fdb7f88a5986ae767c487abb941d6d5548e91448edc11784a377dec25b
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# Changelog
|
2
|
+
All notable changes to this project will be documented in this file.
|
3
|
+
|
4
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
5
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
6
|
+
|
7
|
+
## [1.0.0]
|
8
|
+
|
9
|
+
### Added
|
10
|
+
- Local pods now use the `file_name` purl qualifier ([Issue #11](https://github.com/CycloneDX/cyclonedx-cocoapods/issues/11)) [@macblazer](https://github.com/macblazer).
|
11
|
+
- Gathering more info for local pods, Git based pods, and podspec based pods ([Issues #11](https://github.com/CycloneDX/cyclonedx-cocoapods/issues/11), [#12](https://github.com/CycloneDX/cyclonedx-cocoapods/issues/12), and [#13](https://github.com/CycloneDX/cyclonedx-cocoapods/issues/13)) [@macblazer](https://github.com/macblazer).
|
12
|
+
- Added a small section in the README.md for contributors and how to set up for local development [@macblazer](https://github.com/macblazer).
|
13
|
+
- Added this CHANGELOG.md file [@macblazer](https://github.com/macblazer).
|
14
|
+
|
15
|
+
### Changed
|
16
|
+
- Removed the cyclonedx-cocoapods dependencies from the list of tools in the bom metadata ([Issue #29](https://github.com/CycloneDX/cyclonedx-cocoapods/issues/29)) [@macblazer](https://github.com/macblazer).
|
17
|
+
- Changed copyright to OWASP Foundation ([Issue #36](https://github.com/CycloneDX/cyclonedx-cocoapods/issues/36)) [@macblazer](https://github.com/macblazer).
|
18
|
+
|
19
|
+
## [0.1.1]
|
20
|
+
|
21
|
+
- Initial publication. [@jgongo](https://github.com/jgongo)
|
data/LICENSE
ADDED
@@ -0,0 +1,201 @@
|
|
1
|
+
Apache License
|
2
|
+
Version 2.0, January 2004
|
3
|
+
http://www.apache.org/licenses/
|
4
|
+
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
6
|
+
|
7
|
+
1. Definitions.
|
8
|
+
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
11
|
+
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
13
|
+
the copyright owner that is granting the License.
|
14
|
+
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
16
|
+
other entities that control, are controlled by, or are under common
|
17
|
+
control with that entity. For the purposes of this definition,
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
19
|
+
direction or management of such entity, whether by contract or
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
22
|
+
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
24
|
+
exercising permissions granted by this License.
|
25
|
+
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
27
|
+
including but not limited to software source code, documentation
|
28
|
+
source, and configuration files.
|
29
|
+
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
31
|
+
transformation or translation of a Source form, including but
|
32
|
+
not limited to compiled object code, generated documentation,
|
33
|
+
and conversions to other media types.
|
34
|
+
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
36
|
+
Object form, made available under the License, as indicated by a
|
37
|
+
copyright notice that is included in or attached to the work
|
38
|
+
(an example is provided in the Appendix below).
|
39
|
+
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
46
|
+
the Work and Derivative Works thereof.
|
47
|
+
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
49
|
+
the original version of the Work and any modifications or additions
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
61
|
+
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
64
|
+
subsequently incorporated within the Work.
|
65
|
+
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
72
|
+
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
78
|
+
where such license applies only to those patent claims licensable
|
79
|
+
by such Contributor that are necessarily infringed by their
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
82
|
+
institute patent litigation against any entity (including a
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
85
|
+
or contributory patent infringement, then any patent licenses
|
86
|
+
granted to You under this License for that Work shall terminate
|
87
|
+
as of the date such litigation is filed.
|
88
|
+
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
91
|
+
modifications, and in Source or Object form, provided that You
|
92
|
+
meet the following conditions:
|
93
|
+
|
94
|
+
(a) You must give any other recipients of the Work or
|
95
|
+
Derivative Works a copy of this License; and
|
96
|
+
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
98
|
+
stating that You changed the files; and
|
99
|
+
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
102
|
+
attribution notices from the Source form of the Work,
|
103
|
+
excluding those notices that do not pertain to any part of
|
104
|
+
the Derivative Works; and
|
105
|
+
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
108
|
+
include a readable copy of the attribution notices contained
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
111
|
+
of the following places: within a NOTICE text file distributed
|
112
|
+
as part of the Derivative Works; within the Source form or
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
114
|
+
within a display generated by the Derivative Works, if and
|
115
|
+
wherever such third-party notices normally appear. The contents
|
116
|
+
of the NOTICE file are for informational purposes only and
|
117
|
+
do not modify the License. You may add Your own attribution
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
120
|
+
that such additional attribution notices cannot be construed
|
121
|
+
as modifying the License.
|
122
|
+
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
124
|
+
may provide additional or different license terms and conditions
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
128
|
+
the conditions stated in this License.
|
129
|
+
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
133
|
+
this License, without any additional terms or conditions.
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
135
|
+
the terms of any separate license agreement you may have executed
|
136
|
+
with Licensor regarding such Contributions.
|
137
|
+
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
140
|
+
except as required for reasonable and customary use in describing the
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
142
|
+
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
152
|
+
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
158
|
+
incidental, or consequential damages of any character arising as a
|
159
|
+
result of this License or out of the use or inability to use the
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
162
|
+
other commercial damages or losses), even if such Contributor
|
163
|
+
has been advised of the possibility of such damages.
|
164
|
+
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
168
|
+
or other liability obligations and/or rights consistent with this
|
169
|
+
License. However, in accepting such obligations, You may act only
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
174
|
+
of your accepting any such warranty or additional liability.
|
175
|
+
|
176
|
+
END OF TERMS AND CONDITIONS
|
177
|
+
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
179
|
+
|
180
|
+
To apply the Apache License to your work, attach the following
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
182
|
+
replaced with your own identifying information. (Don't include
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
184
|
+
comment syntax for the file format. We also recommend that a
|
185
|
+
file or class name and description of purpose be included on the
|
186
|
+
same "printed page" as the copyright notice for easier
|
187
|
+
identification within third-party archives.
|
188
|
+
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
190
|
+
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
192
|
+
you may not use this file except in compliance with the License.
|
193
|
+
You may obtain a copy of the License at
|
194
|
+
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
196
|
+
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
200
|
+
See the License for the specific language governing permissions and
|
201
|
+
limitations under the License.
|
data/NOTICE
ADDED
data/README.md
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
[![Build Status](https://github.com/CycloneDX/cyclonedx-cocoapods/actions/workflows/ruby.yml/badge.svg)](https://github.com/CycloneDX/cyclonedx-cocoapods/actions/workflows/ruby.yml)
|
2
|
+
[![Gem Version](https://badge.fury.io/rb/cyclonedx-cocoapods.svg)](https://badge.fury.io/rb/cyclonedx-cocoapods)
|
3
|
+
[![License](https://img.shields.io/badge/license-Apache%202.0-brightgreen.svg)][License]
|
4
|
+
[![Website](https://img.shields.io/badge/https://-cyclonedx.org-blue.svg)](https://cyclonedx.org/)
|
5
|
+
[![Slack Invite](https://img.shields.io/badge/Slack-Join-blue?logo=slack&labelColor=393939)](https://cyclonedx.org/slack/invite)
|
6
|
+
[![Group Discussion](https://img.shields.io/badge/discussion-groups.io-blue.svg)](https://groups.io/g/CycloneDX)
|
7
|
+
[![Twitter](https://img.shields.io/twitter/url/http/shields.io.svg?style=social&label=Follow)](https://twitter.com/CycloneDX_Spec)
|
8
|
+
|
9
|
+
|
10
|
+
# CycloneDX CocoaPods (Objective-C/Swift)
|
11
|
+
|
12
|
+
The CycloneDX CocoaPods Gem creates a valid CycloneDX software bill-of-material document from all project dependencies. CycloneDX is a lightweight BoM specification that is easily created, human readable, and simple to parse.
|
13
|
+
|
14
|
+
## Installation
|
15
|
+
|
16
|
+
### From RubyGems
|
17
|
+
|
18
|
+
```shell
|
19
|
+
% gem install cyclonedx-cocoapods
|
20
|
+
```
|
21
|
+
|
22
|
+
### From Source
|
23
|
+
|
24
|
+
First, clone/copy the source code from GitHub. Then in the source code directory run these ommands:
|
25
|
+
|
26
|
+
```shell
|
27
|
+
gem build cyclonedx-cocoapods.gemspec
|
28
|
+
gem install cyclonedx-cocoapods-x.x.x.gem
|
29
|
+
```
|
30
|
+
|
31
|
+
Building from source requires Ruby 2.4.0 or newer.
|
32
|
+
|
33
|
+
## Compatibility
|
34
|
+
|
35
|
+
*cyclonedx-cocoapods* aims to produce SBOMs according to the latest CycloneDX specification, which currently is [1.4](https://cyclonedx.org/docs/1.4/).
|
36
|
+
You can use the [CycloneDX CLI](https://github.com/CycloneDX/cyclonedx-cli#convert-command) to convert between multiple BOM formats or specification versions.
|
37
|
+
|
38
|
+
## Usage
|
39
|
+
Usage: `cyclonedx-cocoapods` [options]
|
40
|
+
|
41
|
+
--[no-]verbose Run verbosely
|
42
|
+
-p, --path path (Optional) Path to CocoaPods project directory, current directory if missing
|
43
|
+
-o, --output bom_file_path (Optional) Path to output the bom.xml file to
|
44
|
+
-b, --bom-version bom_version (Optional) Version of the generated BOM, 1 if not provided
|
45
|
+
-g, --group group (Optional) Group of the component for which the BOM is generated
|
46
|
+
-n, --name name (Optional, if specified version and type are also required) Name of the component for which the BOM is generated
|
47
|
+
-v, --version version (Optional) Version of the component for which the BOM is generated
|
48
|
+
-t, --type type (Optional) Type of the component for which the BOM is generated (one of application|framework|library|container|operating-system|device|firmware|file)
|
49
|
+
-h, --help Show help message
|
50
|
+
|
51
|
+
**Output:** BoM file at specified location, `./bom.xml` if not specified
|
52
|
+
|
53
|
+
### Example
|
54
|
+
|
55
|
+
```shell
|
56
|
+
% cyclonedx-cocoapods --path /path/to/cocoapods/project --output /path/to/bom.xml --version 6
|
57
|
+
```
|
58
|
+
|
59
|
+
#### Specific example
|
60
|
+
|
61
|
+
This repo contains a file named `example_bom.xml` that was generated with this tool.
|
62
|
+
|
63
|
+
It represents the open source [PodsUpdater application](https://github.com/kizitonwose/PodsUpdater). The PodsUpdater code was checked out,
|
64
|
+
then these two commands were run in the checked out code directory.
|
65
|
+
|
66
|
+
```shell
|
67
|
+
% pod install
|
68
|
+
% cyclonedx-cocoapods -n "kizitonwose/PodsUpdater" -v 1.0.3 -t application --output example_bom.xml
|
69
|
+
```
|
70
|
+
|
71
|
+
## Contributing
|
72
|
+
|
73
|
+
To set up for local development, make a fork of this repo, make a branch on your fork named after the issue or workflow you are improving, checkout your branch, then run `bundle install`.
|
74
|
+
|
75
|
+
### Right to Contribute
|
76
|
+
|
77
|
+
This project runs the [DCO](https://probot.github.io/apps/dco/) checker to validate that the code author has the right to submit the code they are
|
78
|
+
contributing to the project. Please verify that you do have the right to contribute, then when running `git commit` add the `-s` flag to
|
79
|
+
automatically add the proper `Signed-off-by` line to the commit message.
|
80
|
+
|
81
|
+
### Pull requests
|
82
|
+
|
83
|
+
Before submitting your pull request, please do the following:
|
84
|
+
|
85
|
+
- Run `rake spec` and make sure all the tests pass. If you are adding new commands or features, they must include tests. If you are changing functionality, update the tests or add new tests as needed.
|
86
|
+
- Add a note to the CHANGELOG describing what you changed.
|
87
|
+
- Make your pull request. If it is related to an issue, add a link to the issue in the description.
|
88
|
+
|
89
|
+
## Copyright & License
|
90
|
+
Permission to modify and redistribute is granted under the terms of the Apache 2.0 license. See the [LICENSE] file for the full license.
|
91
|
+
|
92
|
+
[License]: https://github.com/CycloneDX/cyclonedx-cocoapods/blob/master/LICENSE
|
@@ -0,0 +1,23 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# This file is part of CycloneDX CocoaPods
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the “License”);
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an “AS IS” BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
# SPDX-License-Identifier: Apache-2.0
|
18
|
+
# Copyright (c) OWASP Foundation. All Rights Reserved.
|
19
|
+
#
|
20
|
+
|
21
|
+
require "cyclonedx/cocoapods/cli_runner"
|
22
|
+
|
23
|
+
CycloneDX::CocoaPods::CLIRunner.new().run
|
@@ -0,0 +1,158 @@
|
|
1
|
+
#
|
2
|
+
# This file is part of CycloneDX CocoaPods
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the “License”);
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an “AS IS” BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
# SPDX-License-Identifier: Apache-2.0
|
17
|
+
# Copyright (c) OWASP Foundation. All Rights Reserved.
|
18
|
+
#
|
19
|
+
|
20
|
+
require 'nokogiri'
|
21
|
+
require 'securerandom'
|
22
|
+
|
23
|
+
require_relative 'version'
|
24
|
+
|
25
|
+
module CycloneDX
|
26
|
+
module CocoaPods
|
27
|
+
module Source
|
28
|
+
class CocoaPodsRepository
|
29
|
+
LEGACY_REPOSITORY = 'https://github.com/CocoaPods/Specs.git'.freeze
|
30
|
+
CDN_REPOSITORY = 'trunk'.freeze
|
31
|
+
|
32
|
+
def source_qualifier
|
33
|
+
url == LEGACY_REPOSITORY || url == CDN_REPOSITORY ? {} : { repository_url: url }
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
class GitRepository
|
38
|
+
def source_qualifier
|
39
|
+
{ vcs_url: (label.nil? ? url : "#{url}@#{label}") }
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
class LocalPod
|
44
|
+
def source_qualifier
|
45
|
+
{ file_name: @path }
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
class Podspec
|
50
|
+
def source_qualifier
|
51
|
+
{ download_url: @url }
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
class Pod
|
57
|
+
CHECKSUM_ALGORITHM = 'SHA-1'.freeze
|
58
|
+
HOMEPAGE_REFERENCE_TYPE = 'website'.freeze
|
59
|
+
|
60
|
+
def purl
|
61
|
+
purl_name = CGI.escape(name.split('/').first)
|
62
|
+
source_qualifier = source.nil? || source.source_qualifier.empty? ? '' : "?#{source.source_qualifier.map { |key, value| "#{key}=#{CGI.escape(value)}" }.join('&')}"
|
63
|
+
purl_subpath = name.split('/').length > 1 ? "##{name.split('/').drop(1).map { |component| CGI.escape(component) }.join('/')}" : ''
|
64
|
+
return "pkg:cocoapods/#{purl_name}@#{CGI.escape(version.to_s)}#{source_qualifier}#{purl_subpath}"
|
65
|
+
end
|
66
|
+
|
67
|
+
def add_to_bom(xml)
|
68
|
+
xml.component(type: 'library') do
|
69
|
+
xml.author author unless author.nil?
|
70
|
+
xml.publisher author unless author.nil?
|
71
|
+
xml.name name
|
72
|
+
xml.version version.to_s
|
73
|
+
xml.description { xml.cdata description } unless description.nil?
|
74
|
+
unless checksum.nil?
|
75
|
+
xml.hashes do
|
76
|
+
xml.hash_(checksum, alg: CHECKSUM_ALGORITHM)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
unless license.nil?
|
80
|
+
xml.licenses do
|
81
|
+
license.add_to_bom(xml)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
xml.purl purl
|
85
|
+
unless homepage.nil?
|
86
|
+
xml.externalReferences do
|
87
|
+
xml.reference(type: HOMEPAGE_REFERENCE_TYPE) do
|
88
|
+
xml.url homepage
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
class License
|
96
|
+
def add_to_bom(xml)
|
97
|
+
xml.license do
|
98
|
+
xml.id identifier if identifier_type == :id
|
99
|
+
xml.name identifier if identifier_type == :name
|
100
|
+
xml.text_ text unless text.nil?
|
101
|
+
xml.url url unless url.nil?
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
class Component
|
108
|
+
def add_to_bom(xml)
|
109
|
+
xml.component(type: type) do
|
110
|
+
xml.group group unless group.nil?
|
111
|
+
xml.name name
|
112
|
+
xml.version version
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
class BOMBuilder
|
118
|
+
NAMESPACE = 'http://cyclonedx.org/schema/bom/1.4'.freeze
|
119
|
+
|
120
|
+
attr_reader :component, :pods
|
121
|
+
|
122
|
+
def initialize(component: nil, pods:)
|
123
|
+
@component, @pods = component, pods
|
124
|
+
end
|
125
|
+
|
126
|
+
def bom(version: 1)
|
127
|
+
raise ArgumentError, "Incorrect version: #{version} should be an integer greater than 0" unless version.to_i > 0
|
128
|
+
|
129
|
+
Nokogiri::XML::Builder.new(encoding: 'UTF-8') do |xml|
|
130
|
+
xml.bom('xmlns': NAMESPACE, 'version': version.to_i.to_s, 'serialNumber': "urn:uuid:#{SecureRandom.uuid}") do
|
131
|
+
bom_metadata(xml)
|
132
|
+
xml.components do
|
133
|
+
pods.each do |pod|
|
134
|
+
pod.add_to_bom(xml)
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end.to_xml
|
139
|
+
end
|
140
|
+
|
141
|
+
private
|
142
|
+
|
143
|
+
def bom_metadata(xml)
|
144
|
+
xml.metadata do
|
145
|
+
xml.timestamp Time.now.getutc.strftime('%Y-%m-%dT%H:%M:%SZ')
|
146
|
+
xml.tools do
|
147
|
+
xml.tool do
|
148
|
+
xml.vendor 'CycloneDX'
|
149
|
+
xml.name 'cyclonedx-cocoapods'
|
150
|
+
xml.version VERSION
|
151
|
+
end
|
152
|
+
end
|
153
|
+
component.add_to_bom(xml) unless component.nil?
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|