github.com/sacloud/iaas-api-go@v1.12.0/types/archive_share_key.go (about)

     1  // Copyright 2022-2023 The sacloud/iaas-api-go Authors
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package types
    16  
    17  import "strings"
    18  
    19  // ArchiveShareKey アーカイブ共有キー
    20  type ArchiveShareKey string
    21  
    22  // ArchiveShareKeyDelimiter アーカイブ共有キーのデリミタ
    23  const ArchiveShareKeyDelimiter = ":"
    24  
    25  // String ArchiveShareKey全体を表す文字列
    26  func (key ArchiveShareKey) String() string {
    27  	return string(key)
    28  }
    29  
    30  // Zone キーに含まれるゾーン名
    31  func (key ArchiveShareKey) Zone() string {
    32  	tokens := key.tokens()
    33  	if len(tokens) > 0 {
    34  		return tokens[0]
    35  	}
    36  	return ""
    37  }
    38  
    39  // SourceArchiveID 共有元となるアーカイブのID
    40  func (key ArchiveShareKey) SourceArchiveID() ID {
    41  	tokens := key.tokens()
    42  	if len(tokens) > 1 {
    43  		return StringID(tokens[1])
    44  	}
    45  	return ID(0)
    46  }
    47  
    48  // Token 認証キー本体
    49  func (key ArchiveShareKey) Token() string {
    50  	tokens := key.tokens()
    51  	if len(tokens) > 2 {
    52  		return tokens[2]
    53  	}
    54  	return ""
    55  }
    56  
    57  // ValidFormat 有効なキーフォーマットか
    58  func (key ArchiveShareKey) ValidFormat() bool {
    59  	return len(key.tokens()) == 3
    60  }
    61  
    62  func (key ArchiveShareKey) tokens() []string {
    63  	return strings.Split(key.String(), ArchiveShareKeyDelimiter)
    64  }