From 6e90f44cf2a4c8328caf76ddfce1460e18d8dec4 Mon Sep 17 00:00:00 2001 From: Allan Nava Date: Fri, 17 Nov 2023 10:09:46 +0100 Subject: [PATCH] feat: added credentials method (#5) --- compress/api_customer.go | 12 +++++++----- compress/compress.go | 18 ++++++++++-------- compress/model_customer.go | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 13 deletions(-) create mode 100644 compress/model_customer.go diff --git a/compress/api_customer.go b/compress/api_customer.go index d834be1..2837fed 100644 --- a/compress/api_customer.go +++ b/compress/api_customer.go @@ -8,16 +8,13 @@ import ( /* */ -func (o *compress) GetCredentials() (*ResponseServer, error) { +func (o *compress) GetCredentials() (*Credential, error) { // resp, err := o.restyPost(CREDENTIALS, BaseModel{ClientId: o.GetCliendId(), ApiKey: o.apiKey}) if err != nil { return nil, err } o.debugPrint(resp) - if resp.IsError() { - return nil, fmt.Errorf("") - } var obj ResponseServer if err := json.Unmarshal(resp.Body(), &obj); err != nil { return nil, err @@ -26,5 +23,10 @@ func (o *compress) GetCredentials() (*ResponseServer, error) { return nil, fmt.Errorf("Error %s", obj.Message) } o.debugPrint(obj) - return &obj, nil + // + var cred Credential + if err := json.Unmarshal(obj.Data, &cred); err != nil { + return nil, err + } + return &cred, nil } diff --git a/compress/compress.go b/compress/compress.go index 0540003..7b98d07 100644 --- a/compress/compress.go +++ b/compress/compress.go @@ -10,7 +10,7 @@ type ICompress interface { // HealthCheck() error IsDebug() bool - GetCredentials() (*ResponseServer, error) + GetCredentials() (*Credential, error) GetUploads(uploadsPaginated UploadsPaginated) ([]VideoUploadInfo, error) // need to change it with args GetSingleUpload(jobid int) (*VideoUploadInfo, error) GetJobidProgress(jobid int) (*VideoUploadInfo, error) @@ -20,13 +20,15 @@ type ICompress interface { CreateCategory(name string) (*Category, error) GetRestreamers() ([]Restreamer, error) // startFrom int, amount int GetSingleRestreamer(instanceName string) (*Restreamer, error) + // } type compress struct { - restClient *resty.Client - debug bool - customerName string - apiKey string + restClient *resty.Client + debug bool + customerName string + apiKey string + customerId int } func NewCompress(customerName, apiKey string, isDebug bool) (ICompress, error) { @@ -45,12 +47,12 @@ func NewCompress(customerName, apiKey string, isDebug bool) (ICompress, error) { c.restClient.SetBaseURL(TNGRM_BASE_URL) c.restClient.SetDebug(isDebug) // - _, err := c.GetCredentials() + cred, err := c.GetCredentials() if err != nil { return nil, err } + c.customerId = cred.CustomerID // return c, nil } - -// +// \ No newline at end of file diff --git a/compress/model_customer.go b/compress/model_customer.go new file mode 100644 index 0000000..ca55ab1 --- /dev/null +++ b/compress/model_customer.go @@ -0,0 +1,34 @@ +package compress + +/* +*/ +type Credential struct { + ID int `json:"id"` + CustomerID int `json:"customer_id" ` + S3Host string `json:"s3_host" ` + S3Bucket string `json:"s3_bucket" ` + S3AccessKey string `json:"s3_access_key" ` + S3SecretKey string `json:"s3_secret_key" ` + SftpUsername string `json:"sftp_username" ` + SftpPassword string `json:"sftp_password" ` + SftpRemoteHost string `json:"sftp_remote_host" ` + SftpRemotePort int `json:"sftp_remote_port" ` + SftpBasePath string `json:"sftp_base_path" ` + Protocol string `json:"protocol" ` + EndpointVisualization string `json:"endpoint_visualization" ` + NfsMount string `json:"nfs_mount" ` + VodesBaseURL string `json:"vodes_base_url" ` + LiveBaseURL string `json:"live_base_url" ` + LiveBaseURLDedicated string `json:"live_base_url_dedicated" ` + ExternalClusters string `json:"external_clusters" ` + RestreamerHlsBasePath string `json:"restreamer_hls_base_path" ` + RestreamerHlstmpBasePath string `json:"restreamer_hlstmp_base_path" ` + ClientID string `json:"client_id" ` + SSDMount string `json:"ssd_mount" ` + S3mount string `json:"s3_mount" ` + SlaveMount int `json:"slave_mount"` + LumenS3Host string `json:"lumen_s3_host" ` + LumenS3Bucket string `json:"lumen_s3_bucket" ` + LumenS3AccessKey string `json:"lumen_s3_access_key" ` + LumenS3SecretKey string `json:"lumen_s3_secret_key" ` +} \ No newline at end of file