...

Source file src/github.com/xanzy/go-gitlab/pages_domains.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  	"time"
    23  )
    24  
    25  // PagesDomainsService handles communication with the pages domains
    26  // related methods of the GitLab API.
    27  //
    28  // GitLab API docs: https://docs.gitlab.com/ee/api/pages_domains.html
    29  type PagesDomainsService struct {
    30  	client *Client
    31  }
    32  
    33  // PagesDomain represents a pages domain.
    34  //
    35  // GitLab API docs: https://docs.gitlab.com/ee/api/pages_domains.html
    36  type PagesDomain struct {
    37  	Domain           string     `json:"domain"`
    38  	AutoSslEnabled   bool       `json:"auto_ssl_enabled"`
    39  	URL              string     `json:"url"`
    40  	ProjectID        int        `json:"project_id"`
    41  	Verified         bool       `json:"verified"`
    42  	VerificationCode string     `json:"verification_code"`
    43  	EnabledUntil     *time.Time `json:"enabled_until"`
    44  	Certificate      struct {
    45  		Subject         string     `json:"subject"`
    46  		Expired         bool       `json:"expired"`
    47  		Expiration      *time.Time `json:"expiration"`
    48  		Certificate     string     `json:"certificate"`
    49  		CertificateText string     `json:"certificate_text"`
    50  	} `json:"certificate"`
    51  }
    52  
    53  // ListPagesDomainsOptions represents the available ListPagesDomains() options.
    54  //
    55  // GitLab API docs:
    56  // https://docs.gitlab.com/ee/api/pages_domains.html#list-pages-domains
    57  type ListPagesDomainsOptions ListOptions
    58  
    59  // ListPagesDomains gets a list of project pages domains.
    60  //
    61  // GitLab API docs:
    62  // https://docs.gitlab.com/ee/api/pages_domains.html#list-pages-domains
    63  func (s *PagesDomainsService) ListPagesDomains(pid interface{}, opt *ListPagesDomainsOptions, options ...RequestOptionFunc) ([]*PagesDomain, *Response, error) {
    64  	project, err := parseID(pid)
    65  	if err != nil {
    66  		return nil, nil, err
    67  	}
    68  	u := fmt.Sprintf("projects/%s/pages/domains", PathEscape(project))
    69  
    70  	req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
    71  	if err != nil {
    72  		return nil, nil, err
    73  	}
    74  
    75  	var pd []*PagesDomain
    76  	resp, err := s.client.Do(req, &pd)
    77  	if err != nil {
    78  		return nil, resp, err
    79  	}
    80  
    81  	return pd, resp, nil
    82  }
    83  
    84  // ListAllPagesDomains gets a list of all pages domains.
    85  //
    86  // GitLab API docs:
    87  // https://docs.gitlab.com/ee/api/pages_domains.html#list-all-pages-domains
    88  func (s *PagesDomainsService) ListAllPagesDomains(options ...RequestOptionFunc) ([]*PagesDomain, *Response, error) {
    89  	req, err := s.client.NewRequest(http.MethodGet, "pages/domains", nil, options)
    90  	if err != nil {
    91  		return nil, nil, err
    92  	}
    93  
    94  	var pd []*PagesDomain
    95  	resp, err := s.client.Do(req, &pd)
    96  	if err != nil {
    97  		return nil, resp, err
    98  	}
    99  
   100  	return pd, resp, nil
   101  }
   102  
   103  // GetPagesDomain get a specific pages domain for a project.
   104  //
   105  // GitLab API docs:
   106  // https://docs.gitlab.com/ee/api/pages_domains.html#single-pages-domain
   107  func (s *PagesDomainsService) GetPagesDomain(pid interface{}, domain string, options ...RequestOptionFunc) (*PagesDomain, *Response, error) {
   108  	project, err := parseID(pid)
   109  	if err != nil {
   110  		return nil, nil, err
   111  	}
   112  	u := fmt.Sprintf("projects/%s/pages/domains/%s", PathEscape(project), domain)
   113  
   114  	req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
   115  	if err != nil {
   116  		return nil, nil, err
   117  	}
   118  
   119  	pd := new(PagesDomain)
   120  	resp, err := s.client.Do(req, pd)
   121  	if err != nil {
   122  		return nil, resp, err
   123  	}
   124  
   125  	return pd, resp, nil
   126  }
   127  
   128  // CreatePagesDomainOptions represents the available CreatePagesDomain() options.
   129  //
   130  // GitLab API docs:
   131  // https://docs.gitlab.com/ee/api/pages_domains.html#create-new-pages-domain
   132  type CreatePagesDomainOptions struct {
   133  	Domain         *string `url:"domain,omitempty" json:"domain,omitempty"`
   134  	AutoSslEnabled *bool   `url:"auto_ssl_enabled,omitempty" json:"auto_ssl_enabled,omitempty"`
   135  	Certificate    *string `url:"certificate,omitempty" json:"certificate,omitempty"`
   136  	Key            *string `url:"key,omitempty" json:"key,omitempty"`
   137  }
   138  
   139  // CreatePagesDomain creates a new project pages domain.
   140  //
   141  // GitLab API docs:
   142  // https://docs.gitlab.com/ee/api/pages_domains.html#create-new-pages-domain
   143  func (s *PagesDomainsService) CreatePagesDomain(pid interface{}, opt *CreatePagesDomainOptions, options ...RequestOptionFunc) (*PagesDomain, *Response, error) {
   144  	project, err := parseID(pid)
   145  	if err != nil {
   146  		return nil, nil, err
   147  	}
   148  	u := fmt.Sprintf("projects/%s/pages/domains", PathEscape(project))
   149  
   150  	req, err := s.client.NewRequest(http.MethodPost, u, opt, options)
   151  	if err != nil {
   152  		return nil, nil, err
   153  	}
   154  
   155  	pd := new(PagesDomain)
   156  	resp, err := s.client.Do(req, pd)
   157  	if err != nil {
   158  		return nil, resp, err
   159  	}
   160  
   161  	return pd, resp, nil
   162  }
   163  
   164  // UpdatePagesDomainOptions represents the available UpdatePagesDomain() options.
   165  //
   166  // GitLab API docs:
   167  // https://docs.gitlab.com/ee/api/pages_domains.html#update-pages-domain
   168  type UpdatePagesDomainOptions struct {
   169  	AutoSslEnabled *bool   `url:"auto_ssl_enabled,omitempty" json:"auto_ssl_enabled,omitempty"`
   170  	Certificate    *string `url:"certificate,omitempty" json:"certificate,omitempty"`
   171  	Key            *string `url:"key,omitempty" json:"key,omitempty"`
   172  }
   173  
   174  // UpdatePagesDomain updates an existing project pages domain.
   175  //
   176  // GitLab API docs:
   177  // https://docs.gitlab.com/ee/api/pages_domains.html#update-pages-domain
   178  func (s *PagesDomainsService) UpdatePagesDomain(pid interface{}, domain string, opt *UpdatePagesDomainOptions, options ...RequestOptionFunc) (*PagesDomain, *Response, error) {
   179  	project, err := parseID(pid)
   180  	if err != nil {
   181  		return nil, nil, err
   182  	}
   183  	u := fmt.Sprintf("projects/%s/pages/domains/%s", PathEscape(project), domain)
   184  
   185  	req, err := s.client.NewRequest(http.MethodPut, u, opt, options)
   186  	if err != nil {
   187  		return nil, nil, err
   188  	}
   189  
   190  	pd := new(PagesDomain)
   191  	resp, err := s.client.Do(req, pd)
   192  	if err != nil {
   193  		return nil, resp, err
   194  	}
   195  
   196  	return pd, resp, nil
   197  }
   198  
   199  // DeletePagesDomain deletes an existing prject pages domain.
   200  //
   201  // GitLab API docs:
   202  // https://docs.gitlab.com/ee/api/pages_domains.html#delete-pages-domain
   203  func (s *PagesDomainsService) DeletePagesDomain(pid interface{}, domain string, options ...RequestOptionFunc) (*Response, error) {
   204  	project, err := parseID(pid)
   205  	if err != nil {
   206  		return nil, err
   207  	}
   208  	u := fmt.Sprintf("projects/%s/pages/domains/%s", PathEscape(project), domain)
   209  
   210  	req, err := s.client.NewRequest(http.MethodDelete, u, nil, options)
   211  	if err != nil {
   212  		return nil, err
   213  	}
   214  
   215  	return s.client.Do(req, nil)
   216  }
   217  

View as plain text