|
| 1 | +package info |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + |
| 6 | + "github.com/sktelecom/tks-contract/pkg/log" |
| 7 | + "github.com/sktelecom/tks-info/pkg/info/csp" |
| 8 | + pb "github.com/sktelecom/tks-proto/pbgo" |
| 9 | + "google.golang.org/protobuf/types/known/emptypb" |
| 10 | +) |
| 11 | + |
| 12 | +var ( |
| 13 | + cspAccessor *csp.Accessor |
| 14 | +) |
| 15 | + |
| 16 | +type Server struct { |
| 17 | + pb.UnimplementedInfoServiceServer |
| 18 | +} |
| 19 | + |
| 20 | +func init() { |
| 21 | + cspAccessor = csp.NewCSPAccessor() |
| 22 | +} |
| 23 | + |
| 24 | +// CreateCSPInfo create new CSP Info for the contract id. |
| 25 | +func (s *Server) CreateCSPInfo(ctx context.Context, in *pb.CreateCSPInfoRequest) (*pb.IDResponse, error) { |
| 26 | + log.Debug("request CreateCSPInfo for contractID ", in.GetContractId()) |
| 27 | + id, err := cspAccessor.Create(csp.ID(in.GetContractId()), in.GetAuth()) |
| 28 | + if err != nil { |
| 29 | + return &pb.IDResponse{ |
| 30 | + Code: pb.Code_INTERNAL, |
| 31 | + Error: &pb.Error{ |
| 32 | + Msg: err.Error(), |
| 33 | + }, |
| 34 | + }, err |
| 35 | + } |
| 36 | + return &pb.IDResponse{ |
| 37 | + Code: pb.Code_OK_UNSPECIFIED, |
| 38 | + Error: nil, |
| 39 | + Id: string(id), |
| 40 | + }, nil |
| 41 | +} |
| 42 | + |
| 43 | +// GetCSPIDs returns all CSP ids. |
| 44 | +func (s *Server) GetCSPIDs(ctx context.Context, empty *emptypb.Empty) (*pb.IDsResponse, error) { |
| 45 | + log.Debug("request GetCSPIDs") |
| 46 | + cspinfos := cspAccessor.List() |
| 47 | + ids := []string{} |
| 48 | + |
| 49 | + for _, csp := range cspinfos { |
| 50 | + ids = append(ids, string(csp.ID)) |
| 51 | + } |
| 52 | + |
| 53 | + return &pb.IDsResponse{ |
| 54 | + Code: pb.Code_OK_UNSPECIFIED, |
| 55 | + Error: nil, |
| 56 | + Ids: ids, |
| 57 | + }, nil |
| 58 | +} |
| 59 | + |
| 60 | +// GetCSPIDsByContractID returns the CSP ids by the contract id. |
| 61 | +func (s *Server) GetCSPIDsByContractID(ctx context.Context, in *pb.IDRequest) (*pb.IDsResponse, error) { |
| 62 | + log.Debug("request GetCSPIDsByContractID for contract ID ", in.GetId()) |
| 63 | + ids, err := cspAccessor.GetCSPIDsByContractID(csp.ID(in.GetId())) |
| 64 | + if err != nil { |
| 65 | + return &pb.IDsResponse{ |
| 66 | + Code: pb.Code_NOT_FOUND, |
| 67 | + Error: &pb.Error{ |
| 68 | + Msg: err.Error(), |
| 69 | + }, |
| 70 | + }, err |
| 71 | + } |
| 72 | + |
| 73 | + res := []string{} |
| 74 | + for _, id := range ids { |
| 75 | + res = append(res, string(id)) |
| 76 | + } |
| 77 | + return &pb.IDsResponse{ |
| 78 | + Code: pb.Code_OK_UNSPECIFIED, |
| 79 | + Error: nil, |
| 80 | + Ids: res, |
| 81 | + }, nil |
| 82 | +} |
| 83 | + |
| 84 | +// UpdateCSPInfo updates an authentication config for CSP. |
| 85 | +func (s *Server) UpdateCSPInfo(ctx context.Context, in *pb.UpdateCSPInfoRequest) (*pb.SimpleResponse, error) { |
| 86 | + log.Debug("request UpdateCSPInfo for CSP ID ", in.GetCspId()) |
| 87 | + if err := cspAccessor.Update(csp.ID(in.GetCspId()), in.GetAuth()); err != nil { |
| 88 | + return &pb.SimpleResponse{ |
| 89 | + Code: pb.Code_INTERNAL, |
| 90 | + Error: &pb.Error{ |
| 91 | + Msg: err.Error(), |
| 92 | + }, |
| 93 | + }, err |
| 94 | + } |
| 95 | + return &pb.SimpleResponse{ |
| 96 | + Code: pb.Code_OK_UNSPECIFIED, |
| 97 | + Error: nil, |
| 98 | + }, nil |
| 99 | +} |
| 100 | + |
| 101 | +// GetCSPAuth returns an authentication info by csp id. |
| 102 | +func (s *Server) GetCSPAuth(ctx context.Context, in *pb.IDRequest) (*pb.GetCSPAuthResponse, error) { |
| 103 | + log.Debug("request GetCSPAuth for CSP ID ", in.GetId()) |
| 104 | + csp, err := cspAccessor.Get(csp.ID(in.GetId())) |
| 105 | + if err != nil { |
| 106 | + return &pb.GetCSPAuthResponse{ |
| 107 | + Code: pb.Code_NOT_FOUND, |
| 108 | + Error: &pb.Error{ |
| 109 | + Msg: err.Error(), |
| 110 | + }, |
| 111 | + }, err |
| 112 | + } |
| 113 | + return &pb.GetCSPAuthResponse{ |
| 114 | + Code: pb.Code_OK_UNSPECIFIED, |
| 115 | + Error: nil, |
| 116 | + Auth: csp.Auth, |
| 117 | + }, nil |
| 118 | +} |
| 119 | + |
| 120 | +// CreateCluster create cluster on the multicuster with csp id |
| 121 | +func (s *Server) CreateCluster(ctx context.Context, in *pb.CreateClusterRequest) (*pb.IDResponse, error) { |
| 122 | + return nil, nil |
| 123 | +} |
| 124 | + |
| 125 | +// GetClusterget cluster for the id of the cluster |
| 126 | +func (s *Server) GetCluster(ctx context.Context, in *pb.GetClusterRequest) (*pb.GetClusterResponse, error) { |
| 127 | + return nil, nil |
| 128 | +} |
| 129 | + |
| 130 | +// GetClusters get every clusters on the mutlcluster |
| 131 | +func (s *Server) GetClusters(ctx context.Context, in *pb.GetClustersRequest) (*pb.GetClustersResponse, error) { |
| 132 | + return nil, nil |
| 133 | +} |
| 134 | + |
| 135 | +// UpdateClusterStatus update Status of the Cluster |
| 136 | +func (s *Server) UpdateClusterStatus(ctx context.Context, in *pb.UpdateClusterStatusRequest) (*pb.SimpleResponse, error) { |
| 137 | + return nil, nil |
| 138 | +} |
| 139 | + |
| 140 | +// ValidateLabelUniqueness check uniqueness of the label |
| 141 | +func (s *Server) ValidateLabelUniqueness(ctx context.Context, in *pb.ValidateLabelUniquenessRequest) (*pb.ValidateLabelUniquenessResponse, error) { |
| 142 | + return nil, nil |
| 143 | +} |
0 commit comments