github.com/sacloud/iaas-api-go@v1.12.0/naked/sim.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 naked
    16  
    17  import (
    18  	"encoding/json"
    19  	"strings"
    20  	"time"
    21  
    22  	"github.com/sacloud/iaas-api-go/types"
    23  )
    24  
    25  // SIM SIM
    26  type SIM struct {
    27  	ID           types.ID     `json:",omitempty" yaml:"id,omitempty" structs:",omitempty"`
    28  	Name         string       `json:",omitempty" yaml:"name,omitempty" structs:",omitempty"`
    29  	Description  string       `yaml:"description"`
    30  	Tags         types.Tags   `yaml:"tags"`
    31  	Status       *SIMStatus   `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
    32  	ServiceClass string       `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
    33  	Availability string       `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
    34  	CreatedAt    time.Time    `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
    35  	ModifiedAt   time.Time    `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
    36  	Provider     *SIMProvider `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
    37  	Icon         *Icon        `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
    38  	Remark       *SIMRemark   `json:",omitempty" yaml:",omitempty" structs:",omitempty"` // Remark
    39  }
    40  
    41  // SIMStatus SIMステータス
    42  type SIMStatus struct {
    43  	ICCID   string   `json:",omitempty" yaml:"iccid,omitempty" structs:",omitempty"`  // ICCID
    44  	SIMInfo *SIMInfo `json:"sim,omitempty" yaml:"sim,omitempty" structs:",omitempty"` // SIM詳細情報
    45  }
    46  
    47  // SIMInfo SIM詳細情報
    48  type SIMInfo struct {
    49  	ICCID                      string           `json:"iccid,omitempty" yaml:"iccid,omitempty" structs:",omitempty"`
    50  	IMSI                       []string         `json:"imsi,omitempty" yaml:"imsi,omitempty" structs:",omitempty"`
    51  	IMEI                       string           `json:"imei,omitempty" yaml:"imei,omitempty" structs:",omitempty"`
    52  	IP                         string           `json:"ip,omitempty" yaml:"ip,omitempty" structs:",omitempty"`
    53  	SessionStatus              string           `json:"session_status,omitempty" yaml:"session_status,omitempty" structs:",omitempty"`
    54  	IMEILock                   bool             `json:"imei_lock" yaml:"imei_lock"`
    55  	Registered                 bool             `json:"registered" yaml:"registered"`
    56  	Activated                  bool             `json:"activated" yaml:"activated"`
    57  	ResourceID                 string           `json:"resource_id,omitempty" yaml:"resource_id,omitempty" structs:",omitempty"`
    58  	RegisteredDate             time.Time        `json:"registered_date,omitempty" yaml:"registered_date,omitempty" structs:",omitempty"`
    59  	ActivatedDate              time.Time        `json:"activated_date,omitempty" yaml:"activated_date,omitempty" structs:",omitempty"`
    60  	DeactivatedDate            time.Time        `json:"deactivated_date,omitempty" yaml:"deactivated_date,omitempty" structs:",omitempty"`
    61  	SIMGroupID                 string           `json:"simgroup_id,omitempty" yaml:"simgroup_id,omitempty" structs:",omitempty"`
    62  	TrafficBytesOfCurrentMonth *SIMTrafficBytes `json:"traffic_bytes_of_current_month,omitempty" yaml:"traffic_bytes_of_current_month,omitempty" structs:",omitempty"`
    63  	ConnectedIMEI              string           `json:"connected_imei,omitempty" yaml:"connected_imei,omitempty" structs:",omitempty"`
    64  }
    65  
    66  // SIMTrafficBytes 当月通信量
    67  type SIMTrafficBytes struct {
    68  	UplinkBytes   types.StringNumber `json:"uplink_bytes,omitempty" yaml:"uplink_bytes,omitempty" structs:",omitempty"`
    69  	DownlinkBytes types.StringNumber `json:"downlink_bytes,omitempty" yaml:"downlink_bytes,omitempty" structs:",omitempty"`
    70  }
    71  
    72  // SIMProvider SIMプロバイダー
    73  type SIMProvider struct {
    74  	ID           int    `json:",omitempty" yaml:"id,omitempty" structs:",omitempty"`
    75  	Class        string `json:",omitempty" yaml:"class,omitempty" structs:",omitempty"`
    76  	Name         string `json:",omitempty" yaml:"name,omitempty" structs:",omitempty"`
    77  	ServiceClass string `json:",omitempty" yaml:"service_class,omitempty" structs:",omitempty"`
    78  }
    79  
    80  // SIMRemark remark
    81  type SIMRemark struct {
    82  	PassCode string `json:",omitempty" yaml:"pass_code,omitempty" structs:",omitempty"`
    83  }
    84  
    85  // UnmarshalJSON JSONアンマーシャル(配列、オブジェクトが混在するためここで対応)
    86  func (s *SIMTrafficBytes) UnmarshalJSON(data []byte) error {
    87  	targetData := strings.ReplaceAll(strings.ReplaceAll(string(data), " ", ""), "\n", "")
    88  	if targetData == `[]` {
    89  		return nil
    90  	}
    91  	type alias SIMTrafficBytes
    92  	tmp := alias{}
    93  	if err := json.Unmarshal(data, &tmp); err != nil {
    94  		return err
    95  	}
    96  
    97  	*s = SIMTrafficBytes(tmp)
    98  	return nil
    99  }
   100  
   101  // SIMLog SIMログ
   102  type SIMLog struct {
   103  	Date          *time.Time `json:"date,omitempty" yaml:"date,omitempty" structs:",omitempty"`
   104  	SessionStatus string     `json:"session_status,omitempty" yaml:"session_status,omitempty" structs:",omitempty"`
   105  	ResourceID    string     `json:"resource_id,omitempty" yaml:"resource_id,omitempty" structs:",omitempty"`
   106  	IMEI          string     `json:"imei,omitempty" yaml:"imei,omitempty" structs:",omitempty"`
   107  	IMSI          string     `json:"imsi,omitempty" yaml:"imsi,omitempty" structs:",omitempty"`
   108  }
   109  
   110  // SIMNetworkOperatorConfig SIM通信キャリア設定
   111  type SIMNetworkOperatorConfig struct {
   112  	Allow       bool   `json:"allow" yaml:"allow"`
   113  	CountryCode string `json:"country_code,omitempty" yaml:"country_code,omitempty" structs:",omitempty"`
   114  	Name        string `json:"name,omitempty" yaml:"name,omitempty" structs:",omitempty"`
   115  }
   116  
   117  // SIMNetworkOperatorConfigs SIM通信キャリア設定 リクエストパラメータ
   118  type SIMNetworkOperatorConfigs struct {
   119  	NetworkOperatorConfigs []*SIMNetworkOperatorConfig `json:"network_operator_config,omitempty" yaml:"network_operator_config,omitempty" structs:",omitempty"`
   120  }
   121  
   122  // SIMAssignIPRequest IPアドレスアサイン リクエストパラメータ
   123  type SIMAssignIPRequest struct {
   124  	IP string `json:"ip"`
   125  }
   126  
   127  // SIMIMEILockRequest IMEIロック リクエストパラメータ
   128  type SIMIMEILockRequest struct {
   129  	IMEI string `json:"imei"`
   130  }