github.com/minio/madmin-go/v3@v3.0.51/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  	"net/http"
    26  )
    27  
    28  // ExportIAM makes an admin call to export IAM data
    29  func (adm *AdminClient) ExportIAM(ctx context.Context) (io.ReadCloser, error) {
    30  	path := adminAPIPrefix + "/export-iam"
    31  
    32  	resp, err := adm.executeMethod(ctx,
    33  		http.MethodGet, requestData{
    34  			relPath: path,
    35  		},
    36  	)
    37  	if err != nil {
    38  		return nil, err
    39  	}
    40  
    41  	if resp.StatusCode != http.StatusOK {
    42  		closeResponse(resp)
    43  		return nil, httpRespToErrorResponse(resp)
    44  	}
    45  	return resp.Body, nil
    46  }
    47  
    48  // ImportIAM makes an admin call to setup IAM  from imported content
    49  func (adm *AdminClient) ImportIAM(ctx context.Context, contentReader io.ReadCloser) error {
    50  	content, err := io.ReadAll(contentReader)
    51  	if err != nil {
    52  		return err
    53  	}
    54  
    55  	path := adminAPIPrefix + "/import-iam"
    56  	resp, err := adm.executeMethod(ctx,
    57  		http.MethodPut, requestData{
    58  			relPath: path,
    59  			content: content,
    60  		},
    61  	)
    62  	defer closeResponse(resp)
    63  	if err != nil {
    64  		return err
    65  	}
    66  
    67  	if resp.StatusCode != http.StatusOK {
    68  		return httpRespToErrorResponse(resp)
    69  	}
    70  	return nil
    71  }