github.com/minio/minio@v0.0.0-20240328213742-3f72439b8a27/internal/config/lambda/event/arn.go (about) 1 // Copyright (c) 2015-2023 MinIO, Inc. 2 // 3 // This file is part of MinIO Object Storage stack 4 // 5 // This program is free software: you can redistribute it and/or modify 6 // it under the terms of the GNU Affero General Public License as published by 7 // the Free Software Foundation, either version 3 of the License, or 8 // (at your option) any later version. 9 // 10 // This program is distributed in the hope that it will be useful 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU Affero General Public License for more details. 14 // 15 // You should have received a copy of the GNU Affero General Public License 16 // along with this program. If not, see <http://www.gnu.org/licenses/>. 17 18 package event 19 20 import ( 21 "strings" 22 ) 23 24 // ARN - SQS resource name representation. 25 type ARN struct { 26 TargetID 27 region string 28 } 29 30 // String - returns string representation. 31 func (arn ARN) String() string { 32 if arn.TargetID.ID == "" && arn.TargetID.Name == "" && arn.region == "" { 33 return "" 34 } 35 36 return "arn:minio:s3-object-lambda:" + arn.region + ":" + arn.TargetID.String() 37 } 38 39 // ParseARN - parses string to ARN. 40 func ParseARN(s string) (*ARN, error) { 41 // ARN must be in the format of arn:minio:s3-object-lambda:<REGION>:<ID>:<TYPE> 42 if !strings.HasPrefix(s, "arn:minio:s3-object-lambda:") { 43 return nil, &ErrInvalidARN{s} 44 } 45 46 tokens := strings.Split(s, ":") 47 if len(tokens) != 6 { 48 return nil, &ErrInvalidARN{s} 49 } 50 51 if tokens[4] == "" || tokens[5] == "" { 52 return nil, &ErrInvalidARN{s} 53 } 54 55 return &ARN{ 56 region: tokens[3], 57 TargetID: TargetID{ 58 ID: tokens[4], 59 Name: tokens[5], 60 }, 61 }, nil 62 }