...

Source file src/github.com/xanzy/go-gitlab/applications.go

Documentation: github.com/xanzy/go-gitlab

     1  //
     2  // Copyright 2021, Sander van Harmelen
     3  //
     4  // Licensed under the Apache License, Version 2.0 (the "License");
     5  // you may not use this file except in compliance with the License.
     6  // You may obtain a copy of the License at
     7  //
     8  //     http://www.apache.org/licenses/LICENSE-2.0
     9  //
    10  // Unless required by applicable law or agreed to in writing, software
    11  // distributed under the License is distributed on an "AS IS" BASIS,
    12  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  // See the License for the specific language governing permissions and
    14  // limitations under the License.
    15  //
    16  
    17  package gitlab
    18  
    19  import (
    20  	"fmt"
    21  	"net/http"
    22  )
    23  
    24  // ApplicationsService handles communication with administrables applications
    25  // of the Gitlab API.
    26  //
    27  // Gitlab API docs : https://docs.gitlab.com/ee/api/applications.html
    28  type ApplicationsService struct {
    29  	client *Client
    30  }
    31  
    32  // Application represents a GitLab application
    33  type Application struct {
    34  	ID              int    `json:"id"`
    35  	ApplicationID   string `json:"application_id"`
    36  	ApplicationName string `json:"application_name"`
    37  	Secret          string `json:"secret"`
    38  	CallbackURL     string `json:"callback_url"`
    39  	Confidential    bool   `json:"confidential"`
    40  }
    41  
    42  // CreateApplicationOptions represents the available CreateApplication() options.
    43  //
    44  // GitLab API docs:
    45  // https://docs.gitlab.com/ee/api/applications.html#create-an-application
    46  type CreateApplicationOptions struct {
    47  	Name         *string `url:"name,omitempty" json:"name,omitempty"`
    48  	RedirectURI  *string `url:"redirect_uri,omitempty" json:"redirect_uri,omitempty"`
    49  	Scopes       *string `url:"scopes,omitempty" json:"scopes,omitempty"`
    50  	Confidential *bool   `url:"confidential,omitempty" json:"confidential,omitempty"`
    51  }
    52  
    53  // CreateApplication creates a new application owned by the authenticated user.
    54  //
    55  // Gitlab API docs : https://docs.gitlab.com/ee/api/applications.html#create-an-application
    56  func (s *ApplicationsService) CreateApplication(opt *CreateApplicationOptions, options ...RequestOptionFunc) (*Application, *Response, error) {
    57  	req, err := s.client.NewRequest(http.MethodPost, "applications", opt, options)
    58  	if err != nil {
    59  		return nil, nil, err
    60  	}
    61  
    62  	a := new(Application)
    63  	resp, err := s.client.Do(req, a)
    64  	if err != nil {
    65  		return nil, resp, err
    66  	}
    67  
    68  	return a, resp, nil
    69  }
    70  
    71  // ListApplicationsOptions represents the available
    72  // ListApplications() options.
    73  type ListApplicationsOptions ListOptions
    74  
    75  // ListApplications get a list of administrables applications by the authenticated user
    76  //
    77  // Gitlab API docs : https://docs.gitlab.com/ee/api/applications.html#list-all-applications
    78  func (s *ApplicationsService) ListApplications(opt *ListApplicationsOptions, options ...RequestOptionFunc) ([]*Application, *Response, error) {
    79  	req, err := s.client.NewRequest(http.MethodGet, "applications", opt, options)
    80  	if err != nil {
    81  		return nil, nil, err
    82  	}
    83  
    84  	var as []*Application
    85  	resp, err := s.client.Do(req, &as)
    86  	if err != nil {
    87  		return nil, resp, err
    88  	}
    89  
    90  	return as, resp, nil
    91  }
    92  
    93  // DeleteApplication removes a specific application.
    94  //
    95  // GitLab API docs:
    96  // https://docs.gitlab.com/ee/api/applications.html#delete-an-application
    97  func (s *ApplicationsService) DeleteApplication(application int, options ...RequestOptionFunc) (*Response, error) {
    98  	u := fmt.Sprintf("applications/%d", application)
    99  
   100  	req, err := s.client.NewRequest(http.MethodDelete, u, nil, options)
   101  	if err != nil {
   102  		return nil, err
   103  	}
   104  
   105  	return s.client.Do(req, nil)
   106  }
   107  

View as plain text