=begin
#NSX-T Manager API

#VMware NSX-T Manager REST API

OpenAPI spec version: 2.5.1.0.0

Generated by: https://github.com/swagger-api/swagger-codegen.git
Swagger Codegen version: 2.4.7

=end

require 'uri'

module NSXT
  class ManagementPlaneApiNsxComponentAdministrationTrustManagementCsrApi
    attr_accessor :api_client

    def initialize(api_client = ApiClient.default)
      @api_client = api_client
    end
    # Delete a CSR
    # Removes a specified CSR. If a CSR is not used for verification, you can delete it. Note that the CSR import and upload POST actions automatically delete the associated CSR. 
    # @param csr_id ID of CSR to delete
    # @param [Hash] opts the optional parameters
    # @return [nil]
    def delete_csr(csr_id, opts = {})
      delete_csr_with_http_info(csr_id, opts)
      nil
    end

    # Delete a CSR
    # Removes a specified CSR. If a CSR is not used for verification, you can delete it. Note that the CSR import and upload POST actions automatically delete the associated CSR. 
    # @param csr_id ID of CSR to delete
    # @param [Hash] opts the optional parameters
    # @return [Array<(nil, Fixnum, Hash)>] nil, response status code and response headers
    def delete_csr_with_http_info(csr_id, opts = {})
      if @api_client.config.debugging
        @api_client.config.logger.debug 'Calling API: ManagementPlaneApiNsxComponentAdministrationTrustManagementCsrApi.delete_csr ...'
      end
      # verify the required parameter 'csr_id' is set
      if @api_client.config.client_side_validation && csr_id.nil?
        fail ArgumentError, "Missing the required parameter 'csr_id' when calling ManagementPlaneApiNsxComponentAdministrationTrustManagementCsrApi.delete_csr"
      end
      # resource path
      local_var_path = '/trust-management/csrs/{csr-id}'.sub('{' + 'csr-id' + '}', csr_id.to_s)

      # query parameters
      query_params = {}

      # header parameters
      header_params = {}
      # HTTP header 'Accept' (if needed)
      header_params['Accept'] = @api_client.select_header_accept(['application/json'])
      # HTTP header 'Content-Type'
      header_params['Content-Type'] = @api_client.select_header_content_type(['application/json'])

      # form parameters
      form_params = {}

      # http body (model)
      post_body = nil
      auth_names = ['BasicAuth']
      data, status_code, headers = @api_client.call_api(:DELETE, local_var_path,
        :header_params => header_params,
        :query_params => query_params,
        :form_params => form_params,
        :body => post_body,
        :auth_names => auth_names)
      if @api_client.config.debugging
        @api_client.config.logger.debug "API called: ManagementPlaneApiNsxComponentAdministrationTrustManagementCsrApi#delete_csr\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
      end
      return data, status_code, headers
    end
    # Generate a New Certificate Signing Request
    # Creates a new certificate signing request (CSR). A CSR is encrypted text that contains information about your organization (organization name, country, and so on) and your Web server's public key, which is a public certificate the is generated on the server that can be used to forward this request to a certificate authority (CA). A private key is also usually created at the same time as the CSR. 
    # @param csr 
    # @param [Hash] opts the optional parameters
    # @return [Csr]
    def generate_csr(csr, opts = {})
      data, _status_code, _headers = generate_csr_with_http_info(csr, opts)
      data
    end

    # Generate a New Certificate Signing Request
    # Creates a new certificate signing request (CSR). A CSR is encrypted text that contains information about your organization (organization name, country, and so on) and your Web server&#39;s public key, which is a public certificate the is generated on the server that can be used to forward this request to a certificate authority (CA). A private key is also usually created at the same time as the CSR. 
    # @param csr 
    # @param [Hash] opts the optional parameters
    # @return [Array<(Csr, Fixnum, Hash)>] Csr data, response status code and response headers
    def generate_csr_with_http_info(csr, opts = {})
      if @api_client.config.debugging
        @api_client.config.logger.debug 'Calling API: ManagementPlaneApiNsxComponentAdministrationTrustManagementCsrApi.generate_csr ...'
      end
      # verify the required parameter 'csr' is set
      if @api_client.config.client_side_validation && csr.nil?
        fail ArgumentError, "Missing the required parameter 'csr' when calling ManagementPlaneApiNsxComponentAdministrationTrustManagementCsrApi.generate_csr"
      end
      # resource path
      local_var_path = '/trust-management/csrs'

      # query parameters
      query_params = {}

      # header parameters
      header_params = {}
      # HTTP header 'Accept' (if needed)
      header_params['Accept'] = @api_client.select_header_accept(['application/json'])
      # HTTP header 'Content-Type'
      header_params['Content-Type'] = @api_client.select_header_content_type(['application/json'])

      # form parameters
      form_params = {}

      # http body (model)
      post_body = @api_client.object_to_http_body(csr)
      auth_names = ['BasicAuth']
      data, status_code, headers = @api_client.call_api(:POST, local_var_path,
        :header_params => header_params,
        :query_params => query_params,
        :form_params => form_params,
        :body => post_body,
        :auth_names => auth_names,
        :return_type => 'Csr')
      if @api_client.config.debugging
        @api_client.config.logger.debug "API called: ManagementPlaneApiNsxComponentAdministrationTrustManagementCsrApi#generate_csr\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
      end
      return data, status_code, headers
    end
    # Show CSR Data for the Given CSR ID
    # Returns information about the specified CSR.
    # @param csr_id ID of CSR to read
    # @param [Hash] opts the optional parameters
    # @return [Csr]
    def get_csr(csr_id, opts = {})
      data, _status_code, _headers = get_csr_with_http_info(csr_id, opts)
      data
    end

    # Show CSR Data for the Given CSR ID
    # Returns information about the specified CSR.
    # @param csr_id ID of CSR to read
    # @param [Hash] opts the optional parameters
    # @return [Array<(Csr, Fixnum, Hash)>] Csr data, response status code and response headers
    def get_csr_with_http_info(csr_id, opts = {})
      if @api_client.config.debugging
        @api_client.config.logger.debug 'Calling API: ManagementPlaneApiNsxComponentAdministrationTrustManagementCsrApi.get_csr ...'
      end
      # verify the required parameter 'csr_id' is set
      if @api_client.config.client_side_validation && csr_id.nil?
        fail ArgumentError, "Missing the required parameter 'csr_id' when calling ManagementPlaneApiNsxComponentAdministrationTrustManagementCsrApi.get_csr"
      end
      # resource path
      local_var_path = '/trust-management/csrs/{csr-id}'.sub('{' + 'csr-id' + '}', csr_id.to_s)

      # query parameters
      query_params = {}

      # header parameters
      header_params = {}
      # HTTP header 'Accept' (if needed)
      header_params['Accept'] = @api_client.select_header_accept(['application/json'])
      # HTTP header 'Content-Type'
      header_params['Content-Type'] = @api_client.select_header_content_type(['application/json'])

      # form parameters
      form_params = {}

      # http body (model)
      post_body = nil
      auth_names = ['BasicAuth']
      data, status_code, headers = @api_client.call_api(:GET, local_var_path,
        :header_params => header_params,
        :query_params => query_params,
        :form_params => form_params,
        :body => post_body,
        :auth_names => auth_names,
        :return_type => 'Csr')
      if @api_client.config.debugging
        @api_client.config.logger.debug "API called: ManagementPlaneApiNsxComponentAdministrationTrustManagementCsrApi#get_csr\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
      end
      return data, status_code, headers
    end
    # Get CSR PEM File for the Given CSR ID
    # Downloads the CSR PEM file for a specified CSR. Clients must include an Accept: text/plain request header.
    # @param csr_id ID of CSR to read
    # @param [Hash] opts the optional parameters
    # @return [String]
    def get_csr_pem(csr_id, opts = {})
      data, _status_code, _headers = get_csr_pem_with_http_info(csr_id, opts)
      data
    end

    # Get CSR PEM File for the Given CSR ID
    # Downloads the CSR PEM file for a specified CSR. Clients must include an Accept: text/plain request header.
    # @param csr_id ID of CSR to read
    # @param [Hash] opts the optional parameters
    # @return [Array<(String, Fixnum, Hash)>] String data, response status code and response headers
    def get_csr_pem_with_http_info(csr_id, opts = {})
      if @api_client.config.debugging
        @api_client.config.logger.debug 'Calling API: ManagementPlaneApiNsxComponentAdministrationTrustManagementCsrApi.get_csr_pem ...'
      end
      # verify the required parameter 'csr_id' is set
      if @api_client.config.client_side_validation && csr_id.nil?
        fail ArgumentError, "Missing the required parameter 'csr_id' when calling ManagementPlaneApiNsxComponentAdministrationTrustManagementCsrApi.get_csr_pem"
      end
      # resource path
      local_var_path = '/trust-management/csrs/{csr-id}/pem-file'.sub('{' + 'csr-id' + '}', csr_id.to_s)

      # query parameters
      query_params = {}

      # header parameters
      header_params = {}
      # HTTP header 'Accept' (if needed)
      header_params['Accept'] = @api_client.select_header_accept(['text/plain;charset=UTF-8'])
      # HTTP header 'Content-Type'
      header_params['Content-Type'] = @api_client.select_header_content_type(['application/json'])

      # form parameters
      form_params = {}

      # http body (model)
      post_body = nil
      auth_names = ['BasicAuth']
      data, status_code, headers = @api_client.call_api(:GET, local_var_path,
        :header_params => header_params,
        :query_params => query_params,
        :form_params => form_params,
        :body => post_body,
        :auth_names => auth_names,
        :return_type => 'String')
      if @api_client.config.debugging
        @api_client.config.logger.debug "API called: ManagementPlaneApiNsxComponentAdministrationTrustManagementCsrApi#get_csr_pem\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
      end
      return data, status_code, headers
    end
    # Return All the Generated CSRs
    # Returns information about all of the CSRs that have been created.
    # @param [Hash] opts the optional parameters
    # @option opts [String] :cursor Opaque cursor to be used for getting next page of records (supplied by current result page)
    # @option opts [String] :included_fields Comma separated list of fields that should be included in query result
    # @option opts [Integer] :page_size Maximum number of results to return in this page (server may return fewer) (default to 1000)
    # @option opts [BOOLEAN] :sort_ascending 
    # @option opts [String] :sort_by Field by which records are sorted
    # @return [CsrList]
    def get_csrs(opts = {})
      data, _status_code, _headers = get_csrs_with_http_info(opts)
      data
    end

    # Return All the Generated CSRs
    # Returns information about all of the CSRs that have been created.
    # @param [Hash] opts the optional parameters
    # @option opts [String] :cursor Opaque cursor to be used for getting next page of records (supplied by current result page)
    # @option opts [String] :included_fields Comma separated list of fields that should be included in query result
    # @option opts [Integer] :page_size Maximum number of results to return in this page (server may return fewer)
    # @option opts [BOOLEAN] :sort_ascending 
    # @option opts [String] :sort_by Field by which records are sorted
    # @return [Array<(CsrList, Fixnum, Hash)>] CsrList data, response status code and response headers
    def get_csrs_with_http_info(opts = {})
      if @api_client.config.debugging
        @api_client.config.logger.debug 'Calling API: ManagementPlaneApiNsxComponentAdministrationTrustManagementCsrApi.get_csrs ...'
      end
      if @api_client.config.client_side_validation && !opts[:'page_size'].nil? && opts[:'page_size'] > 1000
        fail ArgumentError, 'invalid value for "opts[:"page_size"]" when calling ManagementPlaneApiNsxComponentAdministrationTrustManagementCsrApi.get_csrs, must be smaller than or equal to 1000.'
      end

      if @api_client.config.client_side_validation && !opts[:'page_size'].nil? && opts[:'page_size'] < 0
        fail ArgumentError, 'invalid value for "opts[:"page_size"]" when calling ManagementPlaneApiNsxComponentAdministrationTrustManagementCsrApi.get_csrs, must be greater than or equal to 0.'
      end

      # resource path
      local_var_path = '/trust-management/csrs'

      # query parameters
      query_params = {}
      query_params[:'cursor'] = opts[:'cursor'] if !opts[:'cursor'].nil?
      query_params[:'included_fields'] = opts[:'included_fields'] if !opts[:'included_fields'].nil?
      query_params[:'page_size'] = opts[:'page_size'] if !opts[:'page_size'].nil?
      query_params[:'sort_ascending'] = opts[:'sort_ascending'] if !opts[:'sort_ascending'].nil?
      query_params[:'sort_by'] = opts[:'sort_by'] if !opts[:'sort_by'].nil?

      # header parameters
      header_params = {}
      # HTTP header 'Accept' (if needed)
      header_params['Accept'] = @api_client.select_header_accept(['application/json'])
      # HTTP header 'Content-Type'
      header_params['Content-Type'] = @api_client.select_header_content_type(['application/json'])

      # form parameters
      form_params = {}

      # http body (model)
      post_body = nil
      auth_names = ['BasicAuth']
      data, status_code, headers = @api_client.call_api(:GET, local_var_path,
        :header_params => header_params,
        :query_params => query_params,
        :form_params => form_params,
        :body => post_body,
        :auth_names => auth_names,
        :return_type => 'CsrList')
      if @api_client.config.debugging
        @api_client.config.logger.debug "API called: ManagementPlaneApiNsxComponentAdministrationTrustManagementCsrApi#get_csrs\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
      end
      return data, status_code, headers
    end
    # Import a Certificate Associated with an Approved CSR
    # Imports a certificate authority (CA)-signed certificate for a CSR. This action links the certificate to the private key created by the CSR. The pem_encoded string in the request body is the signed certificate provided by your CA in response to the CSR that you provide to them. The import POST action automatically deletes the associated CSR. 
    # @param csr_id CSR this certificate is associated with
    # @param trust_object_data 
    # @param [Hash] opts the optional parameters
    # @return [CertificateList]
    def import_certificate_import(csr_id, trust_object_data, opts = {})
      data, _status_code, _headers = import_certificate_import_with_http_info(csr_id, trust_object_data, opts)
      data
    end

    # Import a Certificate Associated with an Approved CSR
    # Imports a certificate authority (CA)-signed certificate for a CSR. This action links the certificate to the private key created by the CSR. The pem_encoded string in the request body is the signed certificate provided by your CA in response to the CSR that you provide to them. The import POST action automatically deletes the associated CSR. 
    # @param csr_id CSR this certificate is associated with
    # @param trust_object_data 
    # @param [Hash] opts the optional parameters
    # @return [Array<(CertificateList, Fixnum, Hash)>] CertificateList data, response status code and response headers
    def import_certificate_import_with_http_info(csr_id, trust_object_data, opts = {})
      if @api_client.config.debugging
        @api_client.config.logger.debug 'Calling API: ManagementPlaneApiNsxComponentAdministrationTrustManagementCsrApi.import_certificate_import ...'
      end
      # verify the required parameter 'csr_id' is set
      if @api_client.config.client_side_validation && csr_id.nil?
        fail ArgumentError, "Missing the required parameter 'csr_id' when calling ManagementPlaneApiNsxComponentAdministrationTrustManagementCsrApi.import_certificate_import"
      end
      # verify the required parameter 'trust_object_data' is set
      if @api_client.config.client_side_validation && trust_object_data.nil?
        fail ArgumentError, "Missing the required parameter 'trust_object_data' when calling ManagementPlaneApiNsxComponentAdministrationTrustManagementCsrApi.import_certificate_import"
      end
      # resource path
      local_var_path = '/trust-management/csrs/{csr-id}?action=import'.sub('{' + 'csr-id' + '}', csr_id.to_s)

      # query parameters
      query_params = {}

      # header parameters
      header_params = {}
      # HTTP header 'Accept' (if needed)
      header_params['Accept'] = @api_client.select_header_accept(['application/json'])
      # HTTP header 'Content-Type'
      header_params['Content-Type'] = @api_client.select_header_content_type(['application/json'])

      # form parameters
      form_params = {}

      # http body (model)
      post_body = @api_client.object_to_http_body(trust_object_data)
      auth_names = ['BasicAuth']
      data, status_code, headers = @api_client.call_api(:POST, local_var_path,
        :header_params => header_params,
        :query_params => query_params,
        :form_params => form_params,
        :body => post_body,
        :auth_names => auth_names,
        :return_type => 'CertificateList')
      if @api_client.config.debugging
        @api_client.config.logger.debug "API called: ManagementPlaneApiNsxComponentAdministrationTrustManagementCsrApi#import_certificate_import\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
      end
      return data, status_code, headers
    end
    # Self-Sign the CSR
    # Self-signs the previously generated CSR. This action is similar to the import certificate action, but instead of using a public certificate signed by a CA, the self_sign POST action uses a certificate that is signed with NSX's own private key. 
    # @param csr_id CSR this certificate is associated with
    # @param days_valid Number of days the certificate will be valid, default 10 years
    # @param [Hash] opts the optional parameters
    # @return [Certificate]
    def self_sign_certificate_self_sign(csr_id, days_valid, opts = {})
      data, _status_code, _headers = self_sign_certificate_self_sign_with_http_info(csr_id, days_valid, opts)
      data
    end

    # Self-Sign the CSR
    # Self-signs the previously generated CSR. This action is similar to the import certificate action, but instead of using a public certificate signed by a CA, the self_sign POST action uses a certificate that is signed with NSX&#39;s own private key. 
    # @param csr_id CSR this certificate is associated with
    # @param days_valid Number of days the certificate will be valid, default 10 years
    # @param [Hash] opts the optional parameters
    # @return [Array<(Certificate, Fixnum, Hash)>] Certificate data, response status code and response headers
    def self_sign_certificate_self_sign_with_http_info(csr_id, days_valid, opts = {})
      if @api_client.config.debugging
        @api_client.config.logger.debug 'Calling API: ManagementPlaneApiNsxComponentAdministrationTrustManagementCsrApi.self_sign_certificate_self_sign ...'
      end
      # verify the required parameter 'csr_id' is set
      if @api_client.config.client_side_validation && csr_id.nil?
        fail ArgumentError, "Missing the required parameter 'csr_id' when calling ManagementPlaneApiNsxComponentAdministrationTrustManagementCsrApi.self_sign_certificate_self_sign"
      end
      # verify the required parameter 'days_valid' is set
      if @api_client.config.client_side_validation && days_valid.nil?
        fail ArgumentError, "Missing the required parameter 'days_valid' when calling ManagementPlaneApiNsxComponentAdministrationTrustManagementCsrApi.self_sign_certificate_self_sign"
      end
      if @api_client.config.client_side_validation && days_valid > 10000
        fail ArgumentError, 'invalid value for "days_valid" when calling ManagementPlaneApiNsxComponentAdministrationTrustManagementCsrApi.self_sign_certificate_self_sign, must be smaller than or equal to 10000.'
      end

      if @api_client.config.client_side_validation && days_valid < 1
        fail ArgumentError, 'invalid value for "days_valid" when calling ManagementPlaneApiNsxComponentAdministrationTrustManagementCsrApi.self_sign_certificate_self_sign, must be greater than or equal to 1.'
      end

      # resource path
      local_var_path = '/trust-management/csrs/{csr-id}?action=self_sign'.sub('{' + 'csr-id' + '}', csr_id.to_s)

      # query parameters
      query_params = {}
      query_params[:'days_valid'] = days_valid

      # header parameters
      header_params = {}
      # HTTP header 'Accept' (if needed)
      header_params['Accept'] = @api_client.select_header_accept(['application/json'])
      # HTTP header 'Content-Type'
      header_params['Content-Type'] = @api_client.select_header_content_type(['application/json'])

      # form parameters
      form_params = {}

      # http body (model)
      post_body = nil
      auth_names = ['BasicAuth']
      data, status_code, headers = @api_client.call_api(:POST, local_var_path,
        :header_params => header_params,
        :query_params => query_params,
        :form_params => form_params,
        :body => post_body,
        :auth_names => auth_names,
        :return_type => 'Certificate')
      if @api_client.config.debugging
        @api_client.config.logger.debug "API called: ManagementPlaneApiNsxComponentAdministrationTrustManagementCsrApi#self_sign_certificate_self_sign\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
      end
      return data, status_code, headers
    end
  end
end
