Skip to content

Commit 5a9e2f7

Browse files
authored
Replace "base url" with "organization url" (#4)
* Replace "base url" with "organization url" * Try to fix tests * Fix tests
1 parent 9566386 commit 5a9e2f7

File tree

7 files changed

+116
-99
lines changed

7 files changed

+116
-99
lines changed

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
cocoapods-azure-universal-packages (0.0.2)
4+
cocoapods-azure-universal-packages (0.1.0)
55
addressable (~> 2.6)
66
cocoapods (~> 1.0)
77
cocoapods-downloader (~> 1.0)

README.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,21 @@ _Note:_ The plugin will install the Azure CLI [DevOps extension](https://github.
3030
Add to your Podfile
3131
```Ruby
3232
plugin 'cocoapods-azure-universal-packages', {
33-
:base_url => '{{BASE_URL}}'
33+
:organization => '{{ORGANIZATION_URL}}'
3434
}
3535
```
36-
replacing `{{BASE_URL}}` with the base URL of your Azure Artifacts feed (for example, `https://pkgs.dev.azure.com/`).
36+
replacing `{{ORGANIZATION_URL}}` with the base URL of your Azure Artifacts feed (for example: `https://pkgs.dev.azure.com/myorg`).
3737

3838
Then, in your podspec set the pod's source to
3939
```Ruby
4040
# For project scoped feeds:
41-
spec.source = { :http => '{{BASE_URL}}/{{ORGANIZATION}}/{{PROJECT}}/_apis/packaging/feeds/{{FEED}}/upack/packages/{{PACKAGE}}/versions/{{VERSION}}' }
41+
spec.source = { :http => '{{ORGANIZATION_URL}}/{{PROJECT}}/_apis/packaging/feeds/{{FEED}}/upack/packages/{{PACKAGE}}/versions/{{VERSION}}' }
4242

4343
# For organization scoped feeds:
44-
spec.source = { :http => '{{BASE_URL}}/{{ORGANIZATION}}/_apis/packaging/feeds/{{FEED}}/upack/packages/{{PACKAGE}}/versions/{{VERSION}}' }
44+
spec.source = { :http => '{{ORGANIZATION_URL}}/_apis/packaging/feeds/{{FEED}}/upack/packages/{{PACKAGE}}/versions/{{VERSION}}' }
4545
```
4646
where:
47-
- `{{BASE_URL}}` is the base URL you chose above
48-
- `{{ORGANIZATION}}` is the name of your feed's organization
47+
- `{{ORGANIZATION_URL}}` is the URL of your feed's organization
4948
- `{{PROJECT}}` is the name of your feed's project (you must specify this only if your feed is a project scoped feed)
5049
- `{{PACKAGE}}` is the name of your universal package
5150
- `{{VERSION}}` is the version of your universal package
@@ -54,8 +53,8 @@ where:
5453

5554
| Parameter | Description |
5655
| --------- | ----------- |
57-
| `base_url` | The base URL of the Azure Artifacts feed. Required unless `base_urls` is specified. |
58-
| `base_urls` | An array of base URLs of possible Azure Artifacts feeds. Required unless `base_url` is specified. |
56+
| `organization` | The URL of the Azure Artifacts feed's orgnization. Required unless `organizations` is specified. |
57+
| `organizations` | An array of URLs of possible Azure Artifacts feeds' organizations. Required unless `organization` is specified. |
5958
| `update_cli_extension` | Whether to update the Azure CLI DevOps extensions automatically. Default to `false`. |
6059

6160
## Run tests for this plugin

lib/cocoapods-azure-universal-packages/azure_universal_package_downloader.rb

Lines changed: 41 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
module Pod
66
module Downloader
77

8-
@azure_base_urls = []
8+
@azure_organizations = []
99

1010
class << self
11-
attr_accessor :azure_base_urls
11+
attr_accessor :azure_organizations
1212
end
1313

1414
class Http
@@ -20,39 +20,49 @@ class Http
2020
executable :az
2121

2222
def download!
23-
aup_uri_template = Addressable::Template.new(
24-
'{scheme}://{host}/{organization}{/project}/_apis/packaging/feeds/{feed}/upack/packages/{package}/versions/{version}'
25-
)
26-
uri = Addressable::URI.parse(url)
27-
aup_uri_components = aup_uri_template.extract(uri)
23+
# Check if the url matches any known Azure organization
24+
organization = Downloader.azure_organizations.find { |org| url.to_s.start_with?(org) }
2825

29-
if !aup_uri_components.nil? && Downloader.azure_base_urls.include?("#{aup_uri_components['scheme']}://#{aup_uri_components['host']}")
30-
download_azure_universal_package!(aup_uri_components)
26+
if organization.nil?
27+
aliased_download!
28+
else
29+
# Parse the url
30+
organization.delete_suffix!('/')
31+
aup_uri_template = Addressable::Template.new(
32+
"#{organization}{/project}/_apis/packaging/feeds/{feed}/upack/packages/{package}/versions/{version}"
33+
)
34+
uri = Addressable::URI.parse(url)
35+
aup_uri_components = aup_uri_template.extract(uri)
3136

32-
# Extract the file if it's the only one in the package
33-
package_files = target_path.glob('*')
34-
if package_files.count == 1 && package_files.first.file?
35-
file = package_files.first
36-
file_type = begin
37-
case file.to_s
38-
when /\.zip$/
39-
:zip
40-
when /\.(tgz|tar\.gz)$/
41-
:tgz
42-
when /\.tar$/
43-
:tar
44-
when /\.(tbz|tar\.bz2)$/
45-
:tbz
46-
when /\.(txz|tar\.xz)$/
47-
:txz
48-
when /\.dmg$/
49-
:dmg
37+
if !aup_uri_components.nil?
38+
download_azure_universal_package!(aup_uri_components.merge({ 'organization' => organization }))
39+
40+
# Extract the file if it's the only one in the package
41+
package_files = target_path.glob('*')
42+
if package_files.count == 1 && package_files.first.file?
43+
file = package_files.first
44+
file_type = begin
45+
case file.to_s
46+
when /\.zip$/
47+
:zip
48+
when /\.(tgz|tar\.gz)$/
49+
:tgz
50+
when /\.tar$/
51+
:tar
52+
when /\.(tbz|tar\.bz2)$/
53+
:tbz
54+
when /\.(txz|tar\.xz)$/
55+
:txz
56+
when /\.dmg$/
57+
:dmg
58+
end
5059
end
60+
extract_with_type(file, file_type) unless file_type.nil?
5161
end
52-
extract_with_type(file, file_type) unless file_type.nil?
62+
else
63+
Pod::UserInterface.warn("#{url} looks like a Azure artifact feed but it's malformed")
64+
aliased_download!
5365
end
54-
else
55-
aliased_download!
5666
end
5767
end
5868

@@ -62,7 +72,7 @@ def download_azure_universal_package!(params)
6272
'artifacts',
6373
'universal',
6474
'download',
65-
'--organization', "#{params['scheme']}://#{params['host']}/#{params['organization']}/",
75+
'--organization', params['organization'],
6676
'--feed', params['feed'],
6777
'--name', params['package'],
6878
'--version', params['version'],
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module CocoapodsAzureUniversalPackages
2-
VERSION = "0.0.2"
2+
VERSION = "0.1.0"
33
end

lib/cocoapods-azure-universal-packages/pre_install.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ def pre_install(options)
1818
end
1919

2020
# Now we can configure the downloader to use the Azure CLI for downloading pods from the given hosts
21-
azure_base_urls = options[:base_url] || options[:base_urls]
22-
raise Pod::Informative, 'You must configure at least one Azure base url' unless azure_base_urls
21+
azure_organizations = options[:organization] || options[:organizations]
22+
raise Pod::Informative, 'You must configure at least one Azure organization' unless azure_organizations
2323

24-
Pod::Downloader.azure_base_urls = ([] << azure_base_urls).flatten.map { |url| url.delete_suffix('/') }
25-
raise Pod::Informative, 'You must configure at least one Azure base url' if Pod::Downloader.azure_base_urls.empty?
24+
Pod::Downloader.azure_organizations = ([] << azure_organizations).flatten.map { |url| url.delete_suffix('/') }
25+
raise Pod::Informative, 'You must configure at least one Azure organization' if Pod::Downloader.azure_organizations.empty?
2626
end
2727

2828
end

spec/cocoapods-azure-universal-packages/azure_universal_package_downloader_spec.rb

Lines changed: 48 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
describe "#download!" do
66

77
before(:each) do
8-
Pod::Downloader.azure_base_urls = ["https://pkgs.dev.azure.com"]
8+
Pod::Downloader.azure_organizations = ["https://pkgs.dev.azure.com/test_org"]
99
end
1010

11-
context 'when not downloading a pod from one of the configured base urls' do
11+
context 'when not downloading a pod from one of the configured Azure organizations' do
1212
it 'calls #aliased_download!' do
1313
downloader = Pod::Downloader::Http.new("/tmp", "https://www.microsoft.com", {})
1414

@@ -19,45 +19,53 @@
1919
end
2020
end
2121

22-
context 'when downloading a pod from one of the configured base urls' do
23-
it 'can download universal packages from organization feeds' do
24-
downloader = Pod::Downloader::Http.new("/tmp", "https://pkgs.dev.azure.com/test_org/_apis/packaging/feeds/org_feed/upack/packages/test_package/versions/1.2.3", {})
25-
parameters = [
26-
'artifacts',
27-
'universal',
28-
'download',
29-
'--organization', 'https://pkgs.dev.azure.com/test_org/',
30-
'--feed', 'org_feed',
31-
'--name', 'test_package',
32-
'--version', '1.2.3',
33-
'--path', '/tmp'
34-
]
22+
context 'when downloading a pod from one of the configured Azure organizations' do
3523

36-
downloader.target_path.stubs(:mkpath)
37-
downloader.target_path.stubs(:glob).returns([])
38-
downloader.expects(:execute_command).with('az', parameters, anything)
39-
downloader.download
40-
end
41-
42-
it 'can download universal packages from project feeds' do
43-
downloader = Pod::Downloader::Http.new("/tmp", "https://pkgs.dev.azure.com/test_org/test_project/_apis/packaging/feeds/project_feed/upack/packages/test_package/versions/1.2.3", {})
44-
parameters = [
45-
'artifacts',
46-
'universal',
47-
'download',
48-
'--organization', 'https://pkgs.dev.azure.com/test_org/',
49-
'--feed', 'project_feed',
50-
'--name', 'test_package',
51-
'--version', '1.2.3',
52-
'--path', '/tmp',
53-
'--project', 'test_project',
54-
'--scope', 'project'
55-
]
56-
57-
downloader.target_path.stubs(:mkpath)
58-
downloader.target_path.stubs(:glob).returns([])
59-
downloader.expects(:execute_command).with('az', parameters, anything)
60-
downloader.download
24+
[
25+
"https://dev.azure.com/test_org",
26+
"https://test_org.azure.com"
27+
].each do |org|
28+
it "can download universal packages from organization feeds with an organization url like #{org}" do
29+
Pod::Downloader.azure_organizations = [org]
30+
downloader = Pod::Downloader::Http.new("/tmp", "#{org}/_apis/packaging/feeds/org_feed/upack/packages/test_package/versions/1.2.3", {})
31+
parameters = [
32+
'artifacts',
33+
'universal',
34+
'download',
35+
'--organization', org,
36+
'--feed', 'org_feed',
37+
'--name', 'test_package',
38+
'--version', '1.2.3',
39+
'--path', '/tmp'
40+
]
41+
42+
downloader.target_path.stubs(:mkpath)
43+
downloader.target_path.stubs(:glob).returns([])
44+
downloader.expects(:execute_command).with('az', parameters, anything)
45+
downloader.download
46+
end
47+
48+
it "can download universal packages from project feeds with an organization url like #{org}" do
49+
Pod::Downloader.azure_organizations = [org]
50+
downloader = Pod::Downloader::Http.new("/tmp", "#{org}/test_project/_apis/packaging/feeds/project_feed/upack/packages/test_package/versions/1.2.3", {})
51+
parameters = [
52+
'artifacts',
53+
'universal',
54+
'download',
55+
'--organization', org,
56+
'--feed', 'project_feed',
57+
'--name', 'test_package',
58+
'--version', '1.2.3',
59+
'--path', '/tmp',
60+
'--project', 'test_project',
61+
'--scope', 'project'
62+
]
63+
64+
downloader.target_path.stubs(:mkpath)
65+
downloader.target_path.stubs(:glob).returns([])
66+
downloader.expects(:execute_command).with('az', parameters, anything)
67+
downloader.download
68+
end
6169
end
6270
end
6371

spec/cocoapods-azure-universal-packages/pre_install_spec.rb

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
describe ".pre_install" do
66

77
before(:each) do
8-
Pod::Downloader.azure_base_urls = []
8+
Pod::Downloader.azure_organizations = []
99
end
1010

1111
context 'when Azure CLI is not installed' do
12-
let(:options) { {:base_url => "https://dev.azure.com/"} }
12+
let(:options) { {:organization => "https://dev.azure.com/test_org"} }
1313

1414
it 'raises an exception' do
1515
Pod::Executable.expects(:which).with('az').returns(nil)
@@ -18,7 +18,7 @@
1818
end
1919

2020
context 'when Azure CLI is installed' do
21-
let(:base_options) { {:base_url => "https://dev.azure.com/"} }
21+
let(:base_options) { {:organization => "https://dev.azure.com/test_org"} }
2222

2323
before(:each) do
2424
Pod::Executable.stubs(:which).with('az').returns('az')
@@ -44,36 +44,36 @@
4444
end
4545
end
4646

47-
%w[base_url base_urls].each do |url_option|
47+
%w[organization organizations].each do |url_option|
4848
context "with a string specified in '#{url_option}'" do
4949
it 'adds the url to the downloader' do
50-
Pod::Downloader.expects(:azure_base_urls=).with(includes("https://dev.azure.com"))
51-
Pod::Downloader.stubs(:azure_base_urls).returns(["https://dev.azure.com"])
50+
Pod::Downloader.expects(:azure_organizations=).with(includes("https://dev.azure.com"))
51+
Pod::Downloader.stubs(:azure_organizations).returns(["https://dev.azure.com"])
5252
CocoapodsAzureUniversalPackages.pre_install({url_option.to_sym => "https://dev.azure.com/"})
5353
end
5454
end
5555

5656
context "with an array specified in '#{url_option}'" do
5757
it 'adds the url to the downloader' do
58-
Pod::Downloader.expects(:azure_base_urls=).with(all_of(includes("https://dev.azure.com"), includes("https://pkgs.dev.azure.com")))
59-
Pod::Downloader.stubs(:azure_base_urls).returns(["https://dev.azure.com", "https://pkgs.dev.azure.com"])
58+
Pod::Downloader.expects(:azure_organizations=).with(all_of(includes("https://dev.azure.com"), includes("https://pkgs.dev.azure.com")))
59+
Pod::Downloader.stubs(:azure_organizations).returns(["https://dev.azure.com", "https://pkgs.dev.azure.com"])
6060
CocoapodsAzureUniversalPackages.pre_install({url_option.to_sym => ["https://dev.azure.com/", "https://pkgs.dev.azure.com/"]})
6161
end
6262
end
6363

6464
context "with an empty array specified in '#{url_option}'" do
6565
it 'raises an exception' do
66-
Pod::Downloader.expects(:azure_base_urls=).with(equals([]))
67-
Pod::Downloader.stubs(:azure_base_urls).returns([])
68-
expect { CocoapodsAzureUniversalPackages.pre_install({url_option.to_sym => []}) }.to raise_error(Pod::Informative, '[!] You must configure at least one Azure base url'.red)
66+
Pod::Downloader.expects(:azure_organizations=).with(equals([]))
67+
Pod::Downloader.stubs(:azure_organizations).returns([])
68+
expect { CocoapodsAzureUniversalPackages.pre_install({url_option.to_sym => []}) }.to raise_error(Pod::Informative, '[!] You must configure at least one Azure organization'.red)
6969
end
7070
end
7171
end
7272

73-
context "without a base url argument" do
73+
context "without an organization argument" do
7474
it 'raises an exception' do
75-
Pod::Downloader.expects(:azure_base_urls=).never
76-
expect { CocoapodsAzureUniversalPackages.pre_install({}) }.to raise_error(Pod::Informative, '[!] You must configure at least one Azure base url'.red)
75+
Pod::Downloader.expects(:azure_organizations=).never
76+
expect { CocoapodsAzureUniversalPackages.pre_install({}) }.to raise_error(Pod::Informative, '[!] You must configure at least one Azure organization'.red)
7777
end
7878
end
7979
end

0 commit comments

Comments
 (0)