Skip to content
This repository has been archived by the owner. It is now read-only.

Different syntax for accessing credentials in Steeltoe vs. Spring Boot #40

Closed
skmichaelson opened this issue Dec 11, 2018 · 5 comments

Comments

Projects
None yet
5 participants
@skmichaelson
Copy link

commented Dec 11, 2018

The syntax for accessing a credential is a bit verbose:

var config = builder.Build();
var name = config["vcap:services:service-name:0:name"]
var uri = config["vcap:services:service-name:0:credentials:uri"]

Also, if I have multiple services of the same type, then accessing the 0th element may not be sufficient.

On the other hand, Spring Boot allows users to select services by name:

@Data
@AllArgsConstructor
@Configuration
@ConfigurationProperties("vcap.services.cat_picture_service.credentials")
public class CatPictureServiceProperties {
  private String username;
  private String password;
}

Any chance that something similar can be implemented in Steeltoe? Or perhaps the syntax for accessing the config can be updated to match what is used in Spring Boot?

@cf-gitbot

This comment has been minimized.

Copy link
Collaborator

commented Dec 11, 2018

We have created an issue in Pivotal Tracker to manage this:

https://www.pivotaltracker.com/story/show/162592959

The labels on this github issue will be updated when the story is started.

@TimHess

This comment has been minimized.

Copy link
Member

commented Dec 12, 2018

Hi @skmichaelson,

Have you looked at Connectors? There's more code for dealing with service bindings in that repository than this one.

@dtillman is currently working on parity between Steeltoe Configuration and Spring Boot, I imagine he'll have some more specific commentary

@spinfooser

This comment has been minimized.

Copy link

commented Dec 17, 2018

I was looking into this a bit more, and found that although a Connector may solve this for postgres or rabbitmq.

However, there is no connector for using the CredHub service that would be for delivering generic credentials/secrets.

We have found that a lot of CF users end up needing to connect to external services that aren't provisioned using a tile. So could connectors still be used in this case?

@TimHess

This comment has been minimized.

Copy link
Member

commented Dec 17, 2018

Connectors has a few of the building blocks needed to solve the problem(s) you're facing, but I don't think its quite right at this point for bindings that haven't been pre-defined (such as those you listed).

@spinfooser, if you could file an issue over in Connectors with any additional information (such as any commonalities in those bindings that aren't currently supported) we could take that idea up over there.

A CredHub connector shouldn't be too much work, but I don't know yet if that would be a separate feature or not.

dtillman added a commit that referenced this issue Jan 13, 2019

Add a ability to configure user option classes to VCAP_SERVICES bindi…
…ngs [#40]

Add a simplier way to bind VCAP_SERVICES service bindings to a user provided class using the ANC Options features
@dtillman

This comment has been minimized.

Copy link
Contributor

commented Jan 13, 2019

@skmichaelson @spinfooser
I added to Steeltoe 2.2 the ability to easily bind Cloud Foundry services to user defined POCO objects.

The new feature is in the Steeltoe.Extensions.Configuration.CloudFoundry* packages.

I'm hoping this helps with your needs as your should be able to easily define POCO objects that can map to any Cloud Foundry service bindins (e.g. CUPS, CredHub, etc).

We hope to release Steeltoe 2.2 by end of 1st Qtr, but the changes are in the Steeltoe Dev feed now if you'd like to try it out.

To use it:

  1. Understand how the Microsoft Options framework works.

  2. Make sure you have added the CloudFoundry configuration provider to your ConfigurationBuilder.

  3. Define a POCO class (e.g. MySqlServiceOptions) which derives from the Steeltoe class AbstractServiceOptions. This class should have properties which map to the VCAP_SERVICES configuration data you want to extract using the normal Microsoft Options framework rules.

  4. Use either of the Steeltoe extension methods to add the TOption (e.g. MySqlServiceOptions) to the service container and also have it configured from the VCAP_SERVICES data.

ConfigureCloudFoundryService(IConfiguration config, string serviceName)
ConfigureCloudFoundryServices(IConfiguration config, string serviceLabel)

See the unit tests for examples.

Alternatively, if you are not using ASP.NET Core DI, you can also simply new the POCO (e.g. MySqlServiceOptions) and then call the Bind(configuration, serviceName).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.