github.com/pf-qiu/concourse/v6@v6.7.3-0.20201207032516-1f455d73275f/web/elm/src/Api/Endpoints.elm (about)

     1  module Api.Endpoints exposing
     2      ( BuildEndpoint(..)
     3      , Endpoint(..)
     4      , JobEndpoint(..)
     5      , PipelineEndpoint(..)
     6      , ResourceEndpoint(..)
     7      , ResourceVersionEndpoint(..)
     8      , TeamEndpoint(..)
     9      , toString
    10      )
    11  
    12  import Concourse
    13  import Url.Builder
    14  
    15  
    16  type Endpoint
    17      = PipelinesList
    18      | Pipeline Concourse.PipelineIdentifier PipelineEndpoint
    19      | JobsList
    20      | Job Concourse.JobIdentifier JobEndpoint
    21      | JobBuild Concourse.JobBuildIdentifier
    22      | Build Concourse.BuildId BuildEndpoint
    23      | ResourcesList
    24      | Resource Concourse.ResourceIdentifier ResourceEndpoint
    25      | ResourceVersion Concourse.VersionedResourceIdentifier ResourceVersionEndpoint
    26      | TeamsList
    27      | Team Concourse.TeamName TeamEndpoint
    28      | ClusterInfo
    29      | Cli
    30      | UserInfo
    31      | Logout
    32  
    33  
    34  type PipelineEndpoint
    35      = BasePipeline
    36      | PausePipeline
    37      | UnpausePipeline
    38      | ExposePipeline
    39      | HidePipeline
    40      | PipelineJobsList
    41      | PipelineResourcesList
    42  
    43  
    44  type JobEndpoint
    45      = BaseJob
    46      | PauseJob
    47      | UnpauseJob
    48      | JobBuildsList
    49  
    50  
    51  type BuildEndpoint
    52      = BaseBuild
    53      | BuildPlan
    54      | BuildPrep
    55      | AbortBuild
    56      | BuildResourcesList
    57      | BuildEventStream
    58  
    59  
    60  type ResourceEndpoint
    61      = BaseResource
    62      | ResourceVersionsList
    63      | UnpinResource
    64      | CheckResource
    65      | PinResourceComment
    66  
    67  
    68  type ResourceVersionEndpoint
    69      = ResourceVersionInputTo
    70      | ResourceVersionOutputOf
    71      | PinResourceVersion
    72      | EnableResourceVersion
    73      | DisableResourceVersion
    74  
    75  
    76  type TeamEndpoint
    77      = TeamPipelinesList
    78      | OrderTeamPipelines
    79  
    80  
    81  basePath : List String
    82  basePath =
    83      [ "api", "v1" ]
    84  
    85  
    86  baseSkyPath : List String
    87  baseSkyPath =
    88      [ "sky" ]
    89  
    90  
    91  pipelinePath : { r | pipelineName : String, teamName : String } -> List String
    92  pipelinePath { pipelineName, teamName } =
    93      basePath ++ [ "teams", teamName, "pipelines", pipelineName ]
    94  
    95  
    96  resourcePath : { r | pipelineName : String, teamName : String, resourceName : String } -> List String
    97  resourcePath { pipelineName, teamName, resourceName } =
    98      pipelinePath { pipelineName = pipelineName, teamName = teamName }
    99          ++ [ "resources", resourceName ]
   100  
   101  
   102  toString : List Url.Builder.QueryParameter -> Endpoint -> String
   103  toString query endpoint =
   104      Url.Builder.absolute (toPath endpoint) query
   105  
   106  
   107  toPath : Endpoint -> List String
   108  toPath endpoint =
   109      case endpoint of
   110          PipelinesList ->
   111              basePath ++ [ "pipelines" ]
   112  
   113          Pipeline id subEndpoint ->
   114              pipelinePath id ++ pipelineEndpointToPath subEndpoint
   115  
   116          JobsList ->
   117              basePath ++ [ "jobs" ]
   118  
   119          Job id subEndpoint ->
   120              pipelinePath id ++ [ "jobs", id.jobName ] ++ jobEndpointToPath subEndpoint
   121  
   122          JobBuild id ->
   123              pipelinePath id ++ [ "jobs", id.jobName, "builds", id.buildName ]
   124  
   125          Build id subEndpoint ->
   126              basePath ++ [ "builds", String.fromInt id ] ++ buildEndpointToPath subEndpoint
   127  
   128          ResourcesList ->
   129              basePath ++ [ "resources" ]
   130  
   131          Resource id subEndpoint ->
   132              resourcePath id ++ resourceEndpointToPath subEndpoint
   133  
   134          ResourceVersion id subEndpoint ->
   135              resourcePath id ++ [ "versions", String.fromInt id.versionID ] ++ resourceVersionEndpointToPath subEndpoint
   136  
   137          TeamsList ->
   138              basePath ++ [ "teams" ]
   139  
   140          Team teamName subEndpoint ->
   141              basePath ++ [ "teams", teamName ] ++ teamEndpointToPath subEndpoint
   142  
   143          ClusterInfo ->
   144              basePath ++ [ "info" ]
   145  
   146          Cli ->
   147              basePath ++ [ "cli" ]
   148  
   149          UserInfo ->
   150              basePath ++ [ "user" ]
   151  
   152          Logout ->
   153              baseSkyPath ++ [ "logout" ]
   154  
   155  
   156  pipelineEndpointToPath : PipelineEndpoint -> List String
   157  pipelineEndpointToPath endpoint =
   158      case endpoint of
   159          BasePipeline ->
   160              []
   161  
   162          PausePipeline ->
   163              [ "pause" ]
   164  
   165          UnpausePipeline ->
   166              [ "unpause" ]
   167  
   168          ExposePipeline ->
   169              [ "expose" ]
   170  
   171          HidePipeline ->
   172              [ "hide" ]
   173  
   174          PipelineJobsList ->
   175              [ "jobs" ]
   176  
   177          PipelineResourcesList ->
   178              [ "resources" ]
   179  
   180  
   181  jobEndpointToPath : JobEndpoint -> List String
   182  jobEndpointToPath endpoint =
   183      case endpoint of
   184          BaseJob ->
   185              []
   186  
   187          PauseJob ->
   188              [ "pause" ]
   189  
   190          UnpauseJob ->
   191              [ "unpause" ]
   192  
   193          JobBuildsList ->
   194              [ "builds" ]
   195  
   196  
   197  buildEndpointToPath : BuildEndpoint -> List String
   198  buildEndpointToPath endpoint =
   199      case endpoint of
   200          BaseBuild ->
   201              []
   202  
   203          BuildPlan ->
   204              [ "plan" ]
   205  
   206          BuildPrep ->
   207              [ "preparation" ]
   208  
   209          AbortBuild ->
   210              [ "abort" ]
   211  
   212          BuildResourcesList ->
   213              [ "resources" ]
   214  
   215          BuildEventStream ->
   216              [ "events" ]
   217  
   218  
   219  resourceEndpointToPath : ResourceEndpoint -> List String
   220  resourceEndpointToPath endpoint =
   221      case endpoint of
   222          BaseResource ->
   223              []
   224  
   225          ResourceVersionsList ->
   226              [ "versions" ]
   227  
   228          UnpinResource ->
   229              [ "unpin" ]
   230  
   231          CheckResource ->
   232              [ "check" ]
   233  
   234          PinResourceComment ->
   235              [ "pin_comment" ]
   236  
   237  
   238  resourceVersionEndpointToPath : ResourceVersionEndpoint -> List String
   239  resourceVersionEndpointToPath endpoint =
   240      case endpoint of
   241          ResourceVersionInputTo ->
   242              [ "input_to" ]
   243  
   244          ResourceVersionOutputOf ->
   245              [ "output_of" ]
   246  
   247          PinResourceVersion ->
   248              [ "pin" ]
   249  
   250          EnableResourceVersion ->
   251              [ "enable" ]
   252  
   253          DisableResourceVersion ->
   254              [ "disable" ]
   255  
   256  
   257  teamEndpointToPath : TeamEndpoint -> List String
   258  teamEndpointToPath endpoint =
   259      case endpoint of
   260          TeamPipelinesList ->
   261              [ "pipelines" ]
   262  
   263          OrderTeamPipelines ->
   264              [ "pipelines", "ordering" ]