You are given a code snippet that tests two methods `build_url_for_servers()` and `build_url_for_plugins()` in the `Utils` class. These methods are responsible for constructing URLs based on the provided parameters.

The `build_url_for_servers()` method takes two arguments, `version` (a string representing the version number) and `type` (a string representing the type of server).

The `build_url_for_plugins()` method takes three arguments, `version` (a string representing the version number), `type` (a string representing the type of plugin), and `plugin_name` (a string representing the name of the plugin).

The expected result of each method call is checked using the `assert` statement against the expected URL.

Your task is to implement the `build_url()` method in the `Utils` class that constructs the URL based on the provided arguments.

The URL structure is defined as follows:
- The base URL is `https://dist.xebialabs.com`.
- For `build_url_for_servers()`, the URL follows the pattern `{base_url}/xl-deploy/{version}/xl-deploy-{version}-{type}.zip`, where `version` is the version number and `type` is the server type.
- For `build_url_for_plugins()`, the URL follows the pattern `{base_url}/plugins/{plugin_name}/{version}/{plugin_name}-{version}.jar`, where `version` is the version number and `plugin_name` is the name of the plugin.
user
Sure, here's a function `build_url()` that should do what you're looking for:

```python
import structlog

class Utils:
    def __init__(self):
        self.log = structlog.get_logger(__name__)

    def build_url(self, version, type):
        base_url = 'https://dist.xebialabs.com'
        if type == 'servers':
            url = f'{base_url}/xl-deploy/{version}/xl-deploy-{version}-{type}.zip'
            self.log.info(url)
            assert url == f'https://dist.xebialabs.com/xl-deploy/{version}/xl-deploy-{version}-{type}.zip'
        else:
            url = f'{base_url}/plugins/{type}/{version}/{type}-{version}.jar'
            self.log.info(url)
            assert url == f'https://dist.xebialabs.com/plugins/{type}/{version}/{type}-{version}.jar'

    def build_url_for_servers(self, version, type):
        url = self.build_url(version, type)

    def build_url_for_plugins(self, version, type, plugin_name):
        url = self.build_url(version, type, plugin_name)

utils = Utils()
utils.build_url_for_servers('1.0.0', 'web')
utils.build_url_for_plugins('1.0.0', 'logstash', 'logstash.log4j.properties')
```

Explanation:

- `structlog` is a logging library in Python that provides useful context to log messages.
- `Utils` is a class that wraps the `build_url()` function. It includes a static logger to trace and validate the function result.
- `build_url()` takes three arguments and constructs a URL based on the provided inputs. It logs both the constructed URL and the expected URL for comparison purposes.
- `build_url_for_servers()` and `build_url_for_plugins()` are instance methods that call `build_url()` with default arguments.
- Finally, there's an object of `Utils` instantiated with `utils = Utils()` and invoking instance methods.
assistant
You are given a code snippet that tests two methods `build_url_for_servers()` and `build_url_for_plugins()` in the `Utils` class. These methods are responsible for constructing URLs based on the provided parameters.

The `build_url_for_servers()` method takes two arguments, `version` (a string representing the version number) and `type` (a string representing the type of server).

The `build_url_for_plugins()` method takes three arguments, `version` (a string representing the version number), `type` (a string representing the type of plugin), and `plugin_name` (a string representing the name of the plugin).

The expected result of each method call is checked using the `assert` statement against the expected URL.

Your task is to implement the `build_url()` method in the `Utils` class that constructs the URL based on the provided arguments.

The URL structure is defined as follows:
- The base URL is `https://dist.xebialabs.com`.
- For `build_url_for_servers()`, the URL follows the pattern `{base_url}/xl-deploy/{version}/xl-deploy-{version}-{type}.zip`, where `version` is the version number and `type` is the server type.
- For `build_url_for_plugins()`, the URL follows the pattern `{base_url}/plugins/{plugin_name}/{version}/{plugin_name}-{version}.jar`, where `version` is the version number and `plugin_name` is the name of the plugin.
user
Sure, I can help you implement the `build_url()` method in the `Utils` class. Here's a Python implementation based on the URL structures you provided:

```python
class Utils:
    BASE_URL = "https://dist.xebialabs.com"

    @staticmethod
    def build_url(version, type=None, plugin_name=None):
        if plugin_name:
            return f"{Utils.BASE_URL}/plugins/{plugin_name}/{version}/{plugin_name}-{version}.jar"
        else:
            return f"{Utils.BASE_URL}/xl-deploy/{version}/xl-deploy-{version}-{type}.zip"

# Usage
url_for_server = Utils.build_url("7.0.0", "server")
url_for_plugin = Utils.build_url("1.0.0", plugin_name="my_plugin")
```

In this implementation, the `build_url()` method checks if `plugin_name` is provided. If it is, the method constructs a URL for a plugin; otherwise, it constructs a URL for a server. The `type` parameter is optional and is only used when constructing a URL for a server.
assistant