# coding=utf-8
# *** WARNING: this file was generated by pulumi-language-python. ***
# *** Do not edit by hand unless you're certain you know what you are doing! ***

import builtins as _builtins
import warnings
import sys
import pulumi
import pulumi.runtime
from typing import Any, Mapping, Optional, Sequence, Union, overload
if sys.version_info >= (3, 11):
    from typing import NotRequired, TypedDict, TypeAlias
else:
    from typing_extensions import NotRequired, TypedDict, TypeAlias
from . import _utilities

__all__ = [
    'GetArtifactFileResult',
    'AwaitableGetArtifactFileResult',
    'get_artifact_file',
    'get_artifact_file_output',
]

@pulumi.output_type
class GetArtifactFileResult:
    """
    A collection of values returned by getArtifactFile.
    """
    def __init__(__self__, artifact_path=None, content=None, content_base64=None, id=None, job=None, max_size_bytes=None, project=None, ref=None):
        if artifact_path and not isinstance(artifact_path, str):
            raise TypeError("Expected argument 'artifact_path' to be a str")
        pulumi.set(__self__, "artifact_path", artifact_path)
        if content and not isinstance(content, str):
            raise TypeError("Expected argument 'content' to be a str")
        pulumi.set(__self__, "content", content)
        if content_base64 and not isinstance(content_base64, str):
            raise TypeError("Expected argument 'content_base64' to be a str")
        pulumi.set(__self__, "content_base64", content_base64)
        if id and not isinstance(id, str):
            raise TypeError("Expected argument 'id' to be a str")
        pulumi.set(__self__, "id", id)
        if job and not isinstance(job, str):
            raise TypeError("Expected argument 'job' to be a str")
        pulumi.set(__self__, "job", job)
        if max_size_bytes and not isinstance(max_size_bytes, int):
            raise TypeError("Expected argument 'max_size_bytes' to be a int")
        pulumi.set(__self__, "max_size_bytes", max_size_bytes)
        if project and not isinstance(project, str):
            raise TypeError("Expected argument 'project' to be a str")
        pulumi.set(__self__, "project", project)
        if ref and not isinstance(ref, str):
            raise TypeError("Expected argument 'ref' to be a str")
        pulumi.set(__self__, "ref", ref)

    @_builtins.property
    @pulumi.getter(name="artifactPath")
    def artifact_path(self) -> _builtins.str:
        """
        Path to the artifact file within the job's artifacts archive. This path is relative to the archive contents (not the local filesystem). Ensure each `get_artifact_file` data source in your configuration uses a unique artifact_path to avoid ambiguity.
        """
        return pulumi.get(self, "artifact_path")

    @_builtins.property
    @pulumi.getter
    def content(self) -> _builtins.str:
        """
        The content of the artifact file as a UTF-8 string. Use `content_base64` for binary files.
        """
        return pulumi.get(self, "content")

    @_builtins.property
    @pulumi.getter(name="contentBase64")
    def content_base64(self) -> _builtins.str:
        """
        The content of the artifact file as a base64-encoded string. Useful for binary files.
        """
        return pulumi.get(self, "content_base64")

    @_builtins.property
    @pulumi.getter
    def id(self) -> _builtins.str:
        """
        The ID of this datasource. In the format `<project>:<ref>:<job>:<artifact_path>`.
        """
        return pulumi.get(self, "id")

    @_builtins.property
    @pulumi.getter
    def job(self) -> _builtins.str:
        """
        The name of the job.
        """
        return pulumi.get(self, "job")

    @_builtins.property
    @pulumi.getter(name="maxSizeBytes")
    def max_size_bytes(self) -> Optional[_builtins.int]:
        """
        Maximum bytes to read from the artifact. Defaults to 10MB (10485760 bytes).
        """
        return pulumi.get(self, "max_size_bytes")

    @_builtins.property
    @pulumi.getter
    def project(self) -> _builtins.str:
        """
        The ID or URL-encoded path of the project.
        """
        return pulumi.get(self, "project")

    @_builtins.property
    @pulumi.getter
    def ref(self) -> _builtins.str:
        """
        The name of the branch, tag, or commit SHA.
        """
        return pulumi.get(self, "ref")


class AwaitableGetArtifactFileResult(GetArtifactFileResult):
    # pylint: disable=using-constant-test
    def __await__(self):
        if False:
            yield self
        return GetArtifactFileResult(
            artifact_path=self.artifact_path,
            content=self.content,
            content_base64=self.content_base64,
            id=self.id,
            job=self.job,
            max_size_bytes=self.max_size_bytes,
            project=self.project,
            ref=self.ref)


def get_artifact_file(artifact_path: Optional[_builtins.str] = None,
                      job: Optional[_builtins.str] = None,
                      max_size_bytes: Optional[_builtins.int] = None,
                      project: Optional[_builtins.str] = None,
                      ref: Optional[_builtins.str] = None,
                      opts: Optional[pulumi.InvokeOptions] = None) -> AwaitableGetArtifactFileResult:
    """
    The `get_artifact_file` data source allows downloading a single artifact file from a specific job in the latest successful pipeline for a given reference (branch, tag, or commit).
    **Upstream API**: [GitLab REST API docs](https://docs.gitlab.com/api/job_artifacts/#download-a-single-artifact-file-by-reference-name)

    ## Example Usage

    ```python
    import pulumi
    import pulumi_gitlab as gitlab

    # Download a text artifact file from the latest successful pipeline
    config = gitlab.get_artifact_file(project="namespace/myproject",
        job="build-job",
        ref="main",
        artifact_path="config/settings.json")
    pulumi.export("configContent", config.content)
    # Download a binary artifact file using base64 encoding
    binary = gitlab.get_artifact_file(project="namespace/myproject",
        job="build-job",
        ref="v1.0.0",
        artifact_path="dist/app.zip")
    pulumi.export("binaryContentBase64", binary.content_base64)
    # Download artifact from a specific tag
    release = gitlab.get_artifact_file(project="12345",
        job="release-job",
        ref="v2.1.0",
        artifact_path="release-notes.txt")
    # Download a larger artifact with custom size limit
    large_artifact = gitlab.get_artifact_file(project="namespace/myproject",
        job="build-job",
        ref="main",
        artifact_path="dist/large-file.zip",
        max_size_bytes=20971520)
    ```


    :param _builtins.str artifact_path: Path to the artifact file within the job's artifacts archive. This path is relative to the archive contents (not the local filesystem). Ensure each `get_artifact_file` data source in your configuration uses a unique artifact_path to avoid ambiguity.
    :param _builtins.str job: The name of the job.
    :param _builtins.int max_size_bytes: Maximum bytes to read from the artifact. Defaults to 10MB (10485760 bytes).
    :param _builtins.str project: The ID or URL-encoded path of the project.
    :param _builtins.str ref: The name of the branch, tag, or commit SHA.
    """
    __args__ = dict()
    __args__['artifactPath'] = artifact_path
    __args__['job'] = job
    __args__['maxSizeBytes'] = max_size_bytes
    __args__['project'] = project
    __args__['ref'] = ref
    opts = pulumi.InvokeOptions.merge(_utilities.get_invoke_opts_defaults(), opts)
    __ret__ = pulumi.runtime.invoke('gitlab:index/getArtifactFile:getArtifactFile', __args__, opts=opts, typ=GetArtifactFileResult).value

    return AwaitableGetArtifactFileResult(
        artifact_path=pulumi.get(__ret__, 'artifact_path'),
        content=pulumi.get(__ret__, 'content'),
        content_base64=pulumi.get(__ret__, 'content_base64'),
        id=pulumi.get(__ret__, 'id'),
        job=pulumi.get(__ret__, 'job'),
        max_size_bytes=pulumi.get(__ret__, 'max_size_bytes'),
        project=pulumi.get(__ret__, 'project'),
        ref=pulumi.get(__ret__, 'ref'))
def get_artifact_file_output(artifact_path: Optional[pulumi.Input[_builtins.str]] = None,
                             job: Optional[pulumi.Input[_builtins.str]] = None,
                             max_size_bytes: Optional[pulumi.Input[Optional[_builtins.int]]] = None,
                             project: Optional[pulumi.Input[_builtins.str]] = None,
                             ref: Optional[pulumi.Input[_builtins.str]] = None,
                             opts: Optional[Union[pulumi.InvokeOptions, pulumi.InvokeOutputOptions]] = None) -> pulumi.Output[GetArtifactFileResult]:
    """
    The `get_artifact_file` data source allows downloading a single artifact file from a specific job in the latest successful pipeline for a given reference (branch, tag, or commit).
    **Upstream API**: [GitLab REST API docs](https://docs.gitlab.com/api/job_artifacts/#download-a-single-artifact-file-by-reference-name)

    ## Example Usage

    ```python
    import pulumi
    import pulumi_gitlab as gitlab

    # Download a text artifact file from the latest successful pipeline
    config = gitlab.get_artifact_file(project="namespace/myproject",
        job="build-job",
        ref="main",
        artifact_path="config/settings.json")
    pulumi.export("configContent", config.content)
    # Download a binary artifact file using base64 encoding
    binary = gitlab.get_artifact_file(project="namespace/myproject",
        job="build-job",
        ref="v1.0.0",
        artifact_path="dist/app.zip")
    pulumi.export("binaryContentBase64", binary.content_base64)
    # Download artifact from a specific tag
    release = gitlab.get_artifact_file(project="12345",
        job="release-job",
        ref="v2.1.0",
        artifact_path="release-notes.txt")
    # Download a larger artifact with custom size limit
    large_artifact = gitlab.get_artifact_file(project="namespace/myproject",
        job="build-job",
        ref="main",
        artifact_path="dist/large-file.zip",
        max_size_bytes=20971520)
    ```


    :param _builtins.str artifact_path: Path to the artifact file within the job's artifacts archive. This path is relative to the archive contents (not the local filesystem). Ensure each `get_artifact_file` data source in your configuration uses a unique artifact_path to avoid ambiguity.
    :param _builtins.str job: The name of the job.
    :param _builtins.int max_size_bytes: Maximum bytes to read from the artifact. Defaults to 10MB (10485760 bytes).
    :param _builtins.str project: The ID or URL-encoded path of the project.
    :param _builtins.str ref: The name of the branch, tag, or commit SHA.
    """
    __args__ = dict()
    __args__['artifactPath'] = artifact_path
    __args__['job'] = job
    __args__['maxSizeBytes'] = max_size_bytes
    __args__['project'] = project
    __args__['ref'] = ref
    opts = pulumi.InvokeOutputOptions.merge(_utilities.get_invoke_opts_defaults(), opts)
    __ret__ = pulumi.runtime.invoke_output('gitlab:index/getArtifactFile:getArtifactFile', __args__, opts=opts, typ=GetArtifactFileResult)
    return __ret__.apply(lambda __response__: GetArtifactFileResult(
        artifact_path=pulumi.get(__response__, 'artifact_path'),
        content=pulumi.get(__response__, 'content'),
        content_base64=pulumi.get(__response__, 'content_base64'),
        id=pulumi.get(__response__, 'id'),
        job=pulumi.get(__response__, 'job'),
        max_size_bytes=pulumi.get(__response__, 'max_size_bytes'),
        project=pulumi.get(__response__, 'project'),
        ref=pulumi.get(__response__, 'ref')))
