github.com/minio/madmin-go/v2@v2.2.1/iam-migrate.go (about)

     1  //
     2  // Copyright (c) 2015-2022 MinIO, Inc.
     3  //
     4  // This file is part of MinIO Object Storage stack
     5  //
     6  // This program is free software: you can redistribute it and/or modify
     7  // it under the terms of the GNU Affero General Public License as
     8  // published by the Free Software Foundation, either version 3 of the
     9  // License, or (at your option) any later version.
    10  //
    11  // This program is distributed in the hope that it will be useful,
    12  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    13  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    14  // GNU Affero General Public License for more details.
    15  //
    16  // You should have received a copy of the GNU Affero General Public License
    17  // along with this program. If not, see <http://www.gnu.org/licenses/>.
    18  //
    19  
    20  package madmin
    21  
    22  import (
    23  	"context"
    24  	"io"
    25  	"io/ioutil"
    26  	"net/http"
    27  )
    28  
    29  // ExportIAM makes an admin call to export IAM data
    30  func (adm *AdminClient) ExportIAM(ctx context.Context) (io.ReadCloser, error) {
    31  	path := adminAPIPrefix + "/export-iam"
    32  
    33  	resp, err := adm.executeMethod(ctx,
    34  		http.MethodGet, requestData{
    35  			relPath: path,
    36  		},
    37  	)
    38  	if err != nil {
    39  		return nil, err
    40  	}
    41  
    42  	if resp.StatusCode != http.StatusOK {
    43  		closeResponse(resp)
    44  		return nil, httpRespToErrorResponse(resp)
    45  	}
    46  	return resp.Body, nil
    47  }
    48  
    49  // ImportIAM makes an admin call to setup IAM  from imported content
    50  func (adm *AdminClient) ImportIAM(ctx context.Context, contentReader io.ReadCloser) error {
    51  	content, err := ioutil.ReadAll(contentReader)
    52  	if err != nil {
    53  		return err
    54  	}
    55  
    56  	path := adminAPIPrefix + "/import-iam"
    57  	resp, err := adm.executeMethod(ctx,
    58  		http.MethodPut, requestData{
    59  			relPath: path,
    60  			content: content,
    61  		},
    62  	)
    63  	defer closeResponse(resp)
    64  	if err != nil {
    65  		return err
    66  	}
    67  
    68  	if resp.StatusCode != http.StatusOK {
    69  		return httpRespToErrorResponse(resp)
    70  	}
    71  	return nil
    72  }