diff options
author | 2021-07-13 16:47:08 +0200 | |
---|---|---|
committer | 2021-07-15 12:15:13 +0200 | |
commit | d63a4674317497fd6700c52c705649ce85ac3725 (patch) | |
tree | cd649e56e8eef1ba06ec89c164bbe8739dd0cd4b /certServiceK8sExternalProvider/src/certserviceclient/cert_service_client.go | |
parent | 78b60d22b8779d1fbf3e27287b9774862f71404b (diff) |
[OOM-K8S-CERT-EXTERNAL-PROVIDER] Add send update request functionality
Issue-ID: OOM-2753
Signed-off-by: Tomasz Wrobel <tomasz.wrobel@nokia.com>
Change-Id: I0637ded5c870cc66c7dc27dff269dab0f7d9015b
Diffstat (limited to 'certServiceK8sExternalProvider/src/certserviceclient/cert_service_client.go')
-rw-r--r-- | certServiceK8sExternalProvider/src/certserviceclient/cert_service_client.go | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/certServiceK8sExternalProvider/src/certserviceclient/cert_service_client.go b/certServiceK8sExternalProvider/src/certserviceclient/cert_service_client.go index 4806c4a1..f4cc9991 100644 --- a/certServiceK8sExternalProvider/src/certserviceclient/cert_service_client.go +++ b/certServiceK8sExternalProvider/src/certserviceclient/cert_service_client.go @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * oom-certservice-k8s-external-provider * ================================================================================ - * Copyright (C) 2020 Nokia. All rights reserved. + * Copyright (C) 2020-2021 Nokia. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,21 +25,27 @@ import ( "encoding/json" "fmt" "net/http" + + "onap.org/oom-certservice/k8s-external-provider/src/model" ) const ( - CsrHeaderName = "CSR" - PkHeaderName = "PK" + CsrHeaderName = "CSR" + PkHeaderName = "PK" + OldPkHeaderName = "OLD_PK" + OldCertificateHeaderName = "OLD_CERT" ) type CertServiceClient interface { GetCertificates(csr []byte, key []byte) (*CertificatesResponse, error) CheckHealth() error + UpdateCertificate(csr []byte, key []byte, signCertificateModel model.SignCertificateModel) (*CertificatesResponse, error) } type CertServiceClientImpl struct { healthUrl string certificationUrl string + updateUrl string httpClient HTTPClient } @@ -83,6 +89,25 @@ func (client *CertServiceClientImpl) GetCertificates(csr []byte, key []byte) (*C request.Header.Add(CsrHeaderName, base64.StdEncoding.EncodeToString(csr)) request.Header.Add(PkHeaderName, base64.StdEncoding.EncodeToString(key)) + + return client.executeRequest(request) +} + +func (client *CertServiceClientImpl) UpdateCertificate(csr []byte, key []byte, signCertificateModel model.SignCertificateModel) (*CertificatesResponse, error) { + request, err := http.NewRequest("GET", client.updateUrl, nil) + if err != nil { + return nil, err + } + + request.Header.Add(CsrHeaderName, base64.StdEncoding.EncodeToString(csr)) + request.Header.Add(PkHeaderName, base64.StdEncoding.EncodeToString(key)) + request.Header.Add(OldPkHeaderName, signCertificateModel.OldPrivateKey) + request.Header.Add(OldCertificateHeaderName, signCertificateModel.OldCertificate) + + return client.executeRequest(request) +} + +func (client *CertServiceClientImpl) executeRequest(request *http.Request) (*CertificatesResponse, error) { response, err := client.httpClient.Do(request) if err != nil { return nil, err |