1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-14 11:03:09 +02:00
sap-jenkins-library/pkg/abap/aakaas/package.go
tiloKo 3c87648c00
AAKaaS: 6 release package (#2043)
* adding my steps

* messy step

* Update abapEnvironmentAssembly.go

* clean up

* change yaml

* corrections

* Update cloudFoundryDeploy.go

* update

* delete simulation step

* remove simulate

* Update PiperGoUtils.groovy

* Update PiperGoUtils.groovy

* Update CommonStepsTest.groovy

* add docu

* Update abapEnvironmentAssembly.md

* changes due to PR

* Update .gitignore

* b

* CV list

* Update abapEnvironmentAssembly.go

* testing with simulation

* Update abapEnvironmentAssembly.go

* remove simulation

* renaming

* Update mkdocs.yml

* moving service key to yaml and fixing code climate

* Update abapEnvironmentAssemblePackages.go

* Update abapEnvironmentAssemblePackages.go

* Update abapEnvironmentAssemblePackages.go

* Update abapEnvironmentAssemblePackages.go

* change input

* Update abapEnvironmentAssemblePackages.go

* change json tag

* fixed error handling

* documentation

* Update abapEnvironmentAssemblePackages.md

* Update abapEnvironmentAssemblePackages.md

* fixing code climate issues

* fixing code climate issues

* Update abapEnvironmentAssemblePackages.yaml

* fixing code climate issues

* Update abapEnvironmentAssemblePackages.yaml

* adding unittests

* adding unittests and improved logging

* yaml -> json

* change scope of cfServiceKeyName

* correct indentation

* Update CommonStepsTest.groovy

* maintain correct step order

* AAKaaS register package

* AAKaaS register package #2

* Update documentation/docs/steps/abapAddonAssemblyKitPublishTargetVector.md

Co-authored-by: Daniel Mieg <56156797+DanielMieg@users.noreply.github.com>

* AAKaaS register package #3

* AAKaaS release package

* Update abapAddonAssemblyKitReleasePackages.go

* AAKaas release package #2

Co-authored-by: rosemarieB <45030247+rosemarieB@users.noreply.github.com>
Co-authored-by: Daniel Mieg <56156797+DanielMieg@users.noreply.github.com>
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
2020-09-18 16:40:49 +02:00

151 lines
4.9 KiB
Go

package aakaas
import (
"encoding/json"
"errors"
abapbuild "github.com/SAP/jenkins-library/pkg/abap/build"
"github.com/SAP/jenkins-library/pkg/abaputils"
"github.com/SAP/jenkins-library/pkg/log"
)
// PackageStatus : Status of an ABAP delivery package
type PackageStatus string
const (
// PackageStatusPlanned : Package is Planned
PackageStatusPlanned PackageStatus = "P"
// PackageStatusLocked : Package is Locked
PackageStatusLocked PackageStatus = "L"
// PackageStatusReleased : Package is Released
PackageStatusReleased PackageStatus = "R"
// PackageStatusCreationTriggered : Package was Released but Release procedure is not yet finished
PackageStatusCreationTriggered PackageStatus = "C"
)
type jsonPackageDeterminePackageForScv struct {
DeterminePackage struct {
Package *Package `json:"DeterminePackageForScv"`
} `json:"d"`
}
type jsonPackage struct {
Package *Package `json:"d"`
}
// Package : ABAP delivery package
type Package struct {
abapbuild.Connector
ComponentName string
PackageName string `json:"Name"`
VersionYAML string
Type string `json:"Type"`
PredecessorCommitID string `json:"PredecessorCommitId"`
Status PackageStatus `json:"Status"`
Namespace string `json:"Namespace"`
}
// PackageWithRepository : pack'n repo
type PackageWithRepository struct {
Package Package
Repo abaputils.Repository
}
// InitPackage : initialize package attributes from the repository
func (p *Package) InitPackage(repo abaputils.Repository, conn abapbuild.Connector) {
p.Connector = conn
p.ComponentName = repo.Name
p.VersionYAML = repo.VersionYAML
p.PackageName = repo.PackageName
p.Status = PackageStatus(repo.Status)
}
// CopyFieldsToRepo : copy package attributes to the repository
func (p *Package) CopyFieldsToRepo(initialRepo *abaputils.Repository) {
initialRepo.PackageName = p.PackageName
initialRepo.PackageType = p.Type
initialRepo.PredecessorCommitID = p.PredecessorCommitID
initialRepo.Status = string(p.Status)
initialRepo.Namespace = p.Namespace
log.Entry().Infof("Package name %s, type %s, status %s, namespace %s, predecessorCommitID %s", p.PackageName, p.Type, p.Status, p.Namespace, p.PredecessorCommitID)
}
// ReserveNext : reserve next delivery package for this software component version
func (p *Package) ReserveNext() error {
if p.ComponentName == "" || p.VersionYAML == "" {
return errors.New("Parameters missing. Please provide the name and version of the component")
}
log.Entry().Infof("Reserve package for %s version %s", p.ComponentName, p.VersionYAML)
p.Connector.GetToken("/odata/aas_ocs_package")
appendum := "/odata/aas_ocs_package/DeterminePackageForScv?Name='" + p.ComponentName + "'&Version='" + p.VersionYAML + "'"
body, err := p.Connector.Post(appendum, "")
if err != nil {
return err
}
var jPck jsonPackageDeterminePackageForScv
json.Unmarshal(body, &jPck)
p.PackageName = jPck.DeterminePackage.Package.PackageName
p.Type = jPck.DeterminePackage.Package.Type
p.PredecessorCommitID = jPck.DeterminePackage.Package.PredecessorCommitID
p.Status = jPck.DeterminePackage.Package.Status
p.Namespace = jPck.DeterminePackage.Package.Namespace
log.Entry().Infof("Reservation of package %s started", p.PackageName)
return nil
}
// GetPackageAndNamespace : retrieve attributes of the package from AAKaaS
func (p *Package) GetPackageAndNamespace() error {
appendum := "/odata/aas_ocs_package/OcsPackageSet('" + p.PackageName + "')"
body, err := p.Connector.Get(appendum)
if err != nil {
return err
}
var jPck jsonPackage
json.Unmarshal(body, &jPck)
p.Status = jPck.Package.Status
p.Namespace = jPck.Package.Namespace
return nil
}
// ChangeStatus : change status of the package in the repository
func (p *Package) ChangeStatus(initialRepo *abaputils.Repository) {
initialRepo.Status = string(p.Status)
}
// Register : register package in AAKaaS
func (p *Package) Register() error {
if p.PackageName == "" {
return errors.New("Parameter missing. Please provide the name of the package which should be registered")
}
log.Entry().Infof("Register package %s", p.PackageName)
p.Connector.GetToken("/odata/aas_ocs_package")
appendum := "/odata/aas_ocs_package/RegisterPackage?Name='" + p.PackageName + "'"
body, err := p.Connector.Post(appendum, "")
if err != nil {
return err
}
var jPck jsonPackage
json.Unmarshal(body, &jPck)
p.Status = jPck.Package.Status
log.Entry().Infof("Package status %s", p.Status)
return nil
}
// Release : release package in AAKaaS
func (p *Package) Release() error {
var body []byte
var err error
log.Entry().Infof("Release package %s", p.PackageName)
p.Connector.GetToken("/odata/aas_ocs_package")
appendum := "/odata/aas_ocs_package/ReleasePackage?Name='" + p.PackageName + "'"
body, err = p.Connector.Post(appendum, "")
if err != nil {
return err
}
var jPck jsonPackage
json.Unmarshal(body, &jPck)
p.Status = jPck.Package.Status
return nil
}