Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds to AMI Access Endpoint URL used for aws marketplace #463

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/model/ami.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@ Push items: AMI
:members:

.. autoclass:: pushsource.AmiSecurityGroup()
:members:

.. autoclass:: pushsource.AmiAccessEndpointUrl()
:members:
1 change: 1 addition & 0 deletions src/pushsource/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
VMIRelease,
AmiPushItem,
AmiRelease,
AmiAccessEndpointUrl,
AmiBillingCodes,
AmiSecurityGroup,
VHDPushItem,
Expand Down
1 change: 1 addition & 0 deletions src/pushsource/_impl/backend/staged/staged_ami.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ def __push_item(self, leafdir, metadata, entry):
"user_name",
"version_title",
"security_groups",
"access_endpoint_url",
]

for key in image_attrs:
Expand Down
8 changes: 7 additions & 1 deletion src/pushsource/_impl/model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@
from .modulemd import ModuleMdPushItem, ModuleMdSourcePushItem
from .comps import CompsXmlPushItem
from .productid import ProductIdPushItem
from .ami import AmiPushItem, AmiRelease, AmiBillingCodes, AmiSecurityGroup
from .ami import (
AmiPushItem,
AmiRelease,
AmiAccessEndpointUrl,
AmiBillingCodes,
AmiSecurityGroup,
)
from .azure import VHDPushItem
from .vms import BootMode, VMIPushItem, VMIRelease
33 changes: 33 additions & 0 deletions src/pushsource/_impl/model/ami.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,27 @@ def _from_data(cls, data):
return cls(**kwargs)


@attr.s()
class AmiAccessEndpointUrl(object):
"""Access Endpoint URL to be associated with a Marketplace VM."""

port = attr.ib(type=int, validator=instance_of(int))
"""Port to access the endpoint URL."""

protocol = attr.ib(type=str, validator=instance_of_str)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: I'm not sure if you are copying some existing AWS API which already uses the term "protocol". If so, ignore this.

But in the context of a URL, this part of a URL is referred to as a "scheme", not "protocol". For example the named tuple returned by https://docs.python.org/3/library/urllib.parse.html uses "scheme". Given that this class also represents a URL, it would be nice to be consistent with that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's part of the create changeset for product versions. They still don't have a doc showing all possible inputs for it in Boto3. So we're kinda left checking their own API inputs and going from there.

"""Protocol to access the endpoint URL (http, https)."""

@classmethod
def _from_data(cls, data):
"""Instantiate AccessEndpointUrl from raw dict"""

kwargs = {
"port": data["port"],
"protocol": data["protocol"],
}
return cls(**kwargs)


@attr.s()
class AmiPushItem(VMIPushItem):
"""A :class:`~pushsource.PushItem` representing an Amazon Machine Image (or "AMI").
Expand Down Expand Up @@ -180,6 +201,13 @@ class AmiPushItem(VMIPushItem):
)
"""Automatically created security groups for the product. """

access_endpoint_url = attr.ib(
type=AmiAccessEndpointUrl,
default=None,
validator=optional(instance_of(AmiAccessEndpointUrl)),
)
"""Access endpoint url associated with this image."""

@classmethod
def _from_data(cls, data):
"""Instantiate AmiPushItem from raw list or dict"""
Expand Down Expand Up @@ -224,6 +252,11 @@ def _from_data(cls, data):
AmiSecurityGroup._from_data(security_group)
for security_group in (data.get("security_groups") or [])
],
"access_endpoint_url": (
AmiAccessEndpointUrl._from_data(data.get("access_endpoint_url"))
if data.get("access_endpoint_url")
else None
),
}

return cls(**kwargs)
12 changes: 12 additions & 0 deletions src/pushsource/_impl/schema/staged-schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,18 @@ definitions:
minimum: 0
maximum: 65536

access_endpoint_url:
type:
- object
- "null"
properties:
port:
type: number
minimum: 0
maximum: 65536
protocol:
enum: ["http", "https"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you confirm the supported types are just these in some docs? Or are we just following the logic here as the endpoint must be a web one?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked via the WebUI when creating a version.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Related to my other comment about "scheme" vs "protocol", does this follow some existing API which uses "protocol"?


required:
- release
- region
Expand Down
1 change: 1 addition & 0 deletions tests/baseline/cases/staged-simple-ami-bc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ url: "staged:{{ src_dir }}/tests/staged/data/simple_ami_with_bc"
# Push items generated from above.
items:
- AmiPushItem:
access_endpoint_url: null
billing_codes:
codes:
- bp-1234
Expand Down
1 change: 1 addition & 0 deletions tests/baseline/cases/staged-simple-ami-bootmode.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ url: "staged:{{ src_dir }}/tests/staged/data/simple_ami_with_bootmode"
# Push items generated from above.
items:
- AmiPushItem:
access_endpoint_url: null
billing_codes: null
boot_mode: uefi
build: null
Expand Down
1 change: 1 addition & 0 deletions tests/baseline/cases/staged-simple-ami-uefi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ url: "staged:{{ src_dir }}/tests/staged/data/simple_ami_with_uefi"
# Push items generated from above.
items:
- AmiPushItem:
access_endpoint_url: null
billing_codes: null
boot_mode: null
build: null
Expand Down
1 change: 1 addition & 0 deletions tests/baseline/cases/staged-simple-ami.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ url: "staged:{{ src_dir }}/tests/staged/data/simple_ami"
# Push items generated from above.
items:
- AmiPushItem:
access_endpoint_url: null
billing_codes: null
boot_mode: null
build: null
Expand Down
6 changes: 5 additions & 1 deletion tests/pub/data/123456/images.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@
"security_groups": [
{"from_port":10, "ip_protocol": "udp", "ip_ranges":["8.1.8.8"], "to_port":90},
{"from_port":11, "ip_protocol": "tcp", "ip_ranges":["8.2.8.8"], "to_port":91}
]
],
"access_endpoint_url": {
"port": 10,
"protocol": "http"
}

}
]
12 changes: 10 additions & 2 deletions tests/pub/data/200/images.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@
"type": "hourly",
"virtualization": "hvm",
"volume": "gp2",
"security_groups": [{"from_port":-1, "ip_protocol": "icmpv6", "ip_ranges":["255.255.255.255"], "to_port":255}]
"security_groups": [{"from_port":-1, "ip_protocol": "icmpv6", "ip_ranges":["255.255.255.255"], "to_port":255}],
"access_endpoint_url": {
"port": 10,
"protocol": "https"
}

},
{
Expand Down Expand Up @@ -70,7 +74,11 @@
"type": "hourly",
"virtualization": "hvm",
"volume": "gp2",
"security_groups": [{"from_port":1, "ip_protocol": "icmp", "ip_ranges":["1.1.1.1"], "to_port":10}]
"security_groups": [{"from_port":1, "ip_protocol": "icmp", "ip_ranges":["1.1.1.1"], "to_port":10}],
"access_endpoint_url": {
"port": 10,
"protocol": "http"
}

}
]
6 changes: 6 additions & 0 deletions tests/pub/test_pub_amis.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import requests

from pushsource import (
AmiAccessEndpointUrl,
AmiBillingCodes,
AmiPushItem,
AmiRelease,
Expand Down Expand Up @@ -90,6 +91,7 @@ def test_get_ami_push_items_single_task(requests_mock):
from_port=11, ip_protocol="tcp", ip_ranges=["8.2.8.8"], to_port=91
),
],
access_endpoint_url=AmiAccessEndpointUrl(port=10, protocol="http"),
)
]

Expand Down Expand Up @@ -148,6 +150,7 @@ def test_get_ami_push_items_multiple_tasks(requests_mock):
ena_support=True,
billing_codes=AmiBillingCodes(name="Hourly2", codes=["bp-fake"]),
image_id="ami-fake-100",
access_endpoint_url=None,
),
AmiPushItem(
name="RHEL-SAP-8.4.0_HVM-20230109-x86_64-0-Hourly2-GP2",
Expand Down Expand Up @@ -196,6 +199,7 @@ def test_get_ami_push_items_multiple_tasks(requests_mock):
from_port=11, ip_protocol="tcp", ip_ranges=["8.2.8.8"], to_port=91
),
],
access_endpoint_url=AmiAccessEndpointUrl(port=10, protocol="http"),
),
AmiPushItem(
name="RHEL-SAP-8.4.0_HVM-20230109-x86_64-0-Hourly2-GP2",
Expand Down Expand Up @@ -237,6 +241,7 @@ def test_get_ami_push_items_multiple_tasks(requests_mock):
to_port=255,
)
],
access_endpoint_url=AmiAccessEndpointUrl(port=10, protocol="https"),
),
AmiPushItem(
name="RHEL-SAP-8.4.0_HVM-20230109-x86_64-0-Hourly2-GP2",
Expand Down Expand Up @@ -275,6 +280,7 @@ def test_get_ami_push_items_multiple_tasks(requests_mock):
from_port=1, ip_protocol="icmp", ip_ranges=["1.1.1.1"], to_port=10
)
],
access_endpoint_url=AmiAccessEndpointUrl(port=10, protocol="http"),
),
]

Expand Down
Loading