Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Broker API #78

Merged

Conversation

eamonnotoole
Copy link
Contributor

In this PR we add support for the Broker API. The Broker API will be used for two calls:

  • to get Subscription Details, from which we extract the Subscription ID and the Morpheus URL
  • to exchange the IAM API Client token for Morpheus access and refresh tokens

The Morpheus URL and both tokens will then be returned to the calling terraform provider code.

The Changes:

  • we add pkg/models/broker.go to define three structs, two for use with each broker API call and the third returned to the calling terraform provider code
  • we add pkg/client/broker.go to define the BrokerAPIService which implements GetMorpheusDetails, to make both broker API calls and return the details
  • we add a boolean removeVmaasCMPBasePath to pkg/client/api.go which is used to toggle removal of VmaasCmpAPIBasePath from the path if true (in the case of the broker API) or include it if false (in the case of the cmp API)
  • we add two methods to the APIClientHandler interface which will be used in broker client creation by the terraform provider code:
    • SetMetaFnAndVersion() which will be used to set the meta, tokenFunc and cmpVersion fields in APIClient, this avoids a call to the CMP API to get version information when initialising the Broker Client
    • GetSCMVersion() to return the CMP version when initialising the Broker Client after the CMP client, we add this as opposed to exporting the existing getVersion() to avoid approx 190 line changes
  • we add two constants to pkg/common used to set the Broker API paths

gandharvas
gandharvas previously approved these changes Sep 12, 2024
pkg/client/broker.go Outdated Show resolved Hide resolved
gandharvas
gandharvas previously approved these changes Sep 12, 2024
pkg/client/broker.go Outdated Show resolved Hide resolved
Copy link
Contributor

@mahesh-hpe mahesh-hpe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add the test results, and also plan to include the test cases for the new api

@eamonnotoole
Copy link
Contributor Author

@mahesh-hpe Thanks for the review. I've added unit-tests.

@gandharvas Could you re-review as well?

gandharvas
gandharvas previously approved these changes Sep 16, 2024
In this PR we add support for the Broker API.  The Broker API will be
used for two calls:
- to get Subscription Details, from which we extract the Subscription ID
  and the Morpheus URL
- to exchange the IAM API Client token for Morpheus access and refresh
  tokens

The Morpheus URL and both tokens will then be returned to the calling
terraform provider code.

The Changes:
- we add pkg/models/broker.go to define three structs, two for use with
  each broker API call and the third returned to the calling terraform
  provider code
- we add pkg/client/broker.go to define the BrokerAPIService which
  implements GetMorpheusDetails, to make both broker API calls and
  return the details
- we add a boolean removeVmaasCMPBasePath to pkg/client/api.go which is
  used to toggle removal of VmaasCmpAPIBasePath from the path if true
  (in the case of the broker API) or include it if false (in the case of
  the cmp API)
- we add two methods to the APIClientHandler interface which will be
  used in broker client creation by the terraform provider code:
  - SetMetaFnAndVersion() which will be used to set the meta, tokenFunc
    and cmpVersion fields in APIClient, this avoids a call to the CMP
    API to get version information when initialising the Broker Client
  - GetSCMVersion() to return the CMP version when initialising the
    Broker Client after the CMP client, we add this as opposed to
    exporting the existing getVersion() to avoid approx 190 line changes
- we add two constants to pkg/common used to set the Broker API paths
In this commit we add:
- access_token_expires_in
- refresh_token_expires
This is for use by the provider code.
pkg/models/broker.go Outdated Show resolved Hide resolved
pkg/models/broker.go Outdated Show resolved Hide resolved
pkg/models/broker.go Outdated Show resolved Hide resolved
pkg/models/broker.go Outdated Show resolved Hide resolved
pkg/models/broker.go Outdated Show resolved Hide resolved
We only add access_token and expires to MorpheusTokenResponse and
MorpheusDetails.
@eamonnotoole eamonnotoole force-pushed the morpheus-token-data-source branch from 5baf36d to c6c630e Compare September 17, 2024 15:05
Copy link
Contributor

@mahesh-hpe mahesh-hpe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes look good, pl attach a screenshot of your test. Which can include the get morpheus details datasource call, and a vmaas cloud datasource call

@eamonnotoole
Copy link
Contributor Author

eamonnotoole commented Sep 19, 2024

➜  vmaas-morpheus terraform apply -auto-approve
data.hpegl_vmaas_cloud.this: Reading...
data.hpegl_vmaas_morpheus_details.this: Reading...
data.hpegl_vmaas_morpheus_details.this: Read complete after 10s [id=18ba6409-ac59-4eac-9414-0147e72d615e]
data.hpegl_vmaas_cloud.this: Still reading... [10s elapsed]
data.hpegl_vmaas_cloud.this: Still reading... [20s elapsed]
data.hpegl_vmaas_cloud.this: Still reading... [30s elapsed]
data.hpegl_vmaas_cloud.this: Still reading... [40s elapsed]
data.hpegl_vmaas_cloud.this: Read complete after 41s [id=1]

Changes to Outputs:
  ~ access_token_expires = 1758190672466 -> 1758274234035

You can apply this plan to save these new output values to the Terraform state, without changing any real infrastructure.

Apply complete! Resources: 0 added, 0 changed, 0 destroyed.

Outputs:

access_token_expires = 1758274234035

@eamonnotoole
Copy link
Contributor Author

eamonnotoole commented Sep 19, 2024

# Set-up for terraform >= v0.13
terraform {
  required_providers {
  ¦ hpegl = {
  ¦ ¦ source  = "HPE/hpegl"
  ¦ ¦ version = ">= 0.0.1"
  ¦ }
  ¦ morpheus = {
  ¦ ¦ source  = "gomorpheus/morpheus"
  ¦ ¦ version = ">= 0.0.1"
  ¦ }
  }
}

provider "hpegl" {
  # Provide vmaas block if you want to create vmaas resources
  vmaas {
  ¦ location   = var.location
  ¦ space_name = var.space
  ¦ api_url    = "https://iac-vmaas.intg.hpedevops.net"
  ¦ broker_url = "https://vmaas-broker.intg.hpedevops.net"
  }
}

data "hpegl_vmaas_morpheus_details" "this" {}

data "hpegl_vmaas_cloud" "this" {
  name = "HPE GreenLake VMaaS Cloud"
}

provider "morpheus" {
  url          = data.hpegl_vmaas_morpheus_details.this.url
  access_token = data.hpegl_vmaas_morpheus_details.this.access_token
}

@reubenur-rahman reubenur-rahman merged commit fb2edb9 into HewlettPackard:master Sep 19, 2024
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants