Skip to content

Commit 4debead

Browse files
committed
Update example code links, remove unneeded comments
1 parent c257410 commit 4debead

File tree

9 files changed

+50
-127
lines changed

9 files changed

+50
-127
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ check out our [Getting Started guides](https://learn.hashicorp.com/collections/v
5959
on HashiCorp's learning platform. There are also [additional guides](https://learn.hashicorp.com/vault)
6060
to continue your learning.
6161

62-
For examples of how to interact with Vault from inside your application in different programming languages, see the [vault-examples](https://github.com/hashicorp/vault-examples) repo.
62+
For examples of how to interact with Vault from inside your application in different programming languages, see the [vault-examples](https://github.com/hashicorp/vault-examples) repo. An out-of-the-box [sample application](https://github.com/hashicorp/hello-vault-go) is also available.
6363

6464
Show off your Vault knowledge by passing a certification exam. Visit the
6565
[certification page](https://www.hashicorp.com/certification/#hashicorp-certified-vault-associate)

api/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ Vault API
33

44
This provides the `github.com/hashicorp/vault/api` package which contains code useful for interacting with a Vault server.
55

6-
For examples of how to use this module, see the [vault-examples](https://github.com/hashicorp/vault-examples/tree/main/go) repo.
6+
For examples of how to use this module, see the [vault-examples](https://github.com/hashicorp/vault-examples) repo.
77

88
[![GoDoc](https://godoc.org/github.com/hashicorp/vault/api?status.png)](https://godoc.org/github.com/hashicorp/vault/api)

website/content/api-docs/libraries.mdx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ These libraries are officially maintained by HashiCorp.
2525
$ go get github.com/hashicorp/vault/api
2626
```
2727

28-
[Code samples](https://github.com/hashicorp/vault-examples/tree/main/go)
28+
[Example application](https://github.com/hashicorp/hello-vault-go)
2929

3030
### Ruby
3131

@@ -56,8 +56,6 @@ $ pip install ansible-modules-hashivault
5656
$ Install-Package VaultSharp
5757
```
5858

59-
[Code samples](https://github.com/hashicorp/vault-examples/tree/main/dotnet/Examples)
60-
6159
- [Vault.NET](https://github.com/Chatham/Vault.NET)
6260

6361
```shell-session

website/content/docs/auth/approle.mdx

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,7 @@ import (
264264
auth "github.com/hashicorp/vault/api/auth/approle"
265265
)
266266

267-
// Fetches a key-value secret (kv-v2) after authenticating via AppRole,
268-
// an auth method used by machines that are unable to use platform-based
269-
// authentication mechanisms like AWS Auth, Kubernetes Auth, etc.
267+
// Fetches a key-value secret (kv-v2) after authenticating via AppRole.
270268
func getSecretWithAppRole() (string, error) {
271269
config := vault.DefaultConfig() // modify for more granular configuration
272270

@@ -343,12 +341,12 @@ using VaultSharp.V1.AuthMethods.AppRole;
343341
using VaultSharp.V1.AuthMethods.Token;
344342
using VaultSharp.V1.Commons;
345343

346-
namespace Examples
344+
namespace Examples
347345
{
348346
public class ApproleAuthExample
349347
{
350348
const string DefaultTokenPath = "../../../path/to/wrapping-token";
351-
349+
352350
/// <summary>
353351
/// Fetches a key-value secret (kv-v2) after authenticating to Vault via AppRole authentication
354352
/// </summary>
@@ -358,7 +356,7 @@ namespace Examples
358356
// The Secret ID is a value that needs to be protected, so instead of the app having knowledge of the secret ID directly,
359357
// we have a trusted orchestrator (https://learn.hashicorp.com/tutorials/vault/secure-introduction?in=vault/app-integration#trusted-orchestrator)
360358
// give the app access to a short-lived response-wrapping token (https://www.vaultproject.io/docs/concepts/response-wrapping).
361-
// Read more at: https://learn.hashicorp.com/tutorials/vault/approle-best-practices?in=vault/auth-methods#secretid-delivery-best-practices
359+
// Read more at: https://learn.hashicorp.com/tutorials/vault/approle-best-practices?in=vault/auth-methods#secretid-delivery-best-practices
362360
var vaultAddr = Environment.GetEnvironmentVariable("VAULT_ADDR");
363361
if(String.IsNullOrEmpty(vaultAddr))
364362
{
@@ -384,9 +382,9 @@ namespace Examples
384382
// We pass null here instead of the wrapping token to avoid depleting its single usage
385383
// given that we already initialized our client with the wrapping token
386384
Secret<Dictionary<string, object>> secretIdData = vaultClientForUnwrapping.V1.System
387-
.UnwrapWrappedResponseDataAsync<Dictionary<string, object>>(null).Result;
385+
.UnwrapWrappedResponseDataAsync<Dictionary<string, object>>(null).Result;
388386

389-
var secretId = secretIdData.Data["secret_id"]; // Grab the secret_id
387+
var secretId = secretIdData.Data["secret_id"]; // Grab the secret_id
390388
391389
// We create a second VaultClient and initialize it with the AppRole auth method and our new credentials.
392390
IAuthMethodInfo authMethod = new AppRoleAuthMethodInfo(roleId, secretId.ToString());
@@ -397,9 +395,9 @@ namespace Examples
397395
// We can retrieve the secret from VaultClient
398396
Secret<SecretData> kv2Secret = null;
399397
kv2Secret = vaultClient.V1.Secrets.KeyValue.V2.ReadSecretAsync(path: "/creds").Result;
400-
398+
401399
var password = kv2Secret.Data.Data["password"];
402-
400+
403401
return password.ToString();
404402
}
405403
}

website/content/docs/auth/aws.mdx

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -765,13 +765,6 @@ import (
765765

766766
// Fetches a key-value secret (kv-v2) after authenticating to Vault via AWS IAM,
767767
// one of two auth methods used to authenticate with AWS (the other is EC2 auth).
768-
// A role must first be created in Vault bound to the IAM ARN you wish to
769-
// authenticate with, like so:
770-
// vault write auth/aws/role/dev-role-iam \
771-
// auth_type=iam \
772-
// bound_iam_principal_arn="arn:aws:iam::AWS-ACCOUNT-NUMBER:role/AWS-IAM-ROLE-NAME" \
773-
// ttl=24h
774-
// Learn more about the available parameters at https://www.vaultproject.io/api/auth/aws#parameters-10
775768
func getSecretWithAWSAuthIAM() (string, error) {
776769
config := vault.DefaultConfig() // modify for more granular configuration
777770

@@ -840,17 +833,11 @@ using VaultSharp.V1.SecretsEngines.AWS;
840833

841834
namespace Examples
842835
{
843-
public class AwsAuthExample
836+
public class AwsAuthExample
844837
{
845-
/// <summary>
838+
/// <summary>
846839
/// Fetches a key-value secret (kv-v2) after authenticating to Vault via AWS IAM,
847840
/// one of two auth methods used to authenticate with AWS (the other is EC2 auth).
848-
/// A role must first be created in Vault bound to the IAM ARN you wish to authenticate with, like so:
849-
/// vault write auth/aws/role/dev-role-iam \
850-
/// auth_type=iam \
851-
/// bound_iam_principal_arn="arn:aws:iam::AWS-ACCOUNT-NUMBER:role/AWS-IAM-ROLE-NAME" \
852-
/// ttl=24h
853-
/// Learn more about the available parameters at https://www.vaultproject.io/api/auth/aws#parameters-10
854841
/// </summary>
855842
public string GetSecretAWSAuthIAM()
856843
{
@@ -860,21 +847,21 @@ namespace Examples
860847
throw new System.ArgumentNullException("Vault Address");
861848
}
862849

863-
var roleName = Environment.GetEnvironmentVariable("AWS_ROLE_NAME");
850+
var roleName = Environment.GetEnvironmentVariable("VAULT_ROLE");
864851
if(String.IsNullOrEmpty(roleName))
865852
{
866-
throw new System.ArgumentNullException("AWS Role Name");
853+
throw new System.ArgumentNullException("Vault Role Name");
867854
}
868855

869856
var amazonSecurityTokenServiceConfig = new AmazonSecurityTokenServiceConfig();
870857

871858
// Initialize BasicAWS Credentials w/ an accessKey and secretKey
872-
Amazon.Runtime.AWSCredentials awsCredentials = new BasicAWSCredentials(accessKey: Environment.GetEnvironmentVariable("AWS_ACCESS_KEY_ID"),
859+
Amazon.Runtime.AWSCredentials awsCredentials = new BasicAWSCredentials(accessKey: Environment.GetEnvironmentVariable("AWS_ACCESS_KEY_ID"),
873860
secretKey: Environment.GetEnvironmentVariable("AWS_SECRET_ACCESS_KEY"));
874-
861+
875862
// Construct the IAM Request and add necessary headers
876863
var iamRequest = GetCallerIdentityRequestMarshaller.Instance.Marshall(new GetCallerIdentityRequest());
877-
864+
878865
iamRequest.Endpoint = new Uri(amazonSecurityTokenServiceConfig.DetermineServiceURL());
879866
iamRequest.ResourcePath = "/";
880867

@@ -896,9 +883,9 @@ namespace Examples
896883
// We can retrieve the secret from the VaultClient object
897884
Secret<SecretData> kv2Secret = null;
898885
kv2Secret = vaultClient.V1.Secrets.KeyValue.V2.ReadSecretAsync(path: "/creds").Result;
899-
886+
900887
var password = kv2Secret.Data.Data["password"];
901-
888+
902889
return password.ToString();
903890
}
904891
}

website/content/docs/auth/azure.mdx

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -230,14 +230,6 @@ import (
230230

231231
// Fetches a key-value secret (kv-v2) after authenticating to Vault via Azure authentication.
232232
// This example assumes you have a configured Azure AD Application.
233-
// Learn more about Azure authentication prerequisites: https://www.vaultproject.io/docs/auth/azure
234-
//
235-
// A role must first be created in Vault bound to the resource groups and subscription ids:
236-
// vault write auth/azure/role/dev-role \
237-
// policies="dev-policy"
238-
// bound_subscription_ids=$AZURE_SUBSCRIPTION_ID \
239-
// bound_resource_groups=test-rg \
240-
// ttl=24h
241233
func getSecretWithAzureAuth() (string, error) {
242234
config := vault.DefaultConfig() // modify for more granular configuration
243235

@@ -282,6 +274,7 @@ func getSecretWithAzureAuth() (string, error) {
282274

283275
return value, nil
284276
}
277+
285278
```
286279
</CodeBlockConfig>
287280

@@ -302,7 +295,7 @@ using VaultSharp.V1.Commons;
302295

303296
namespace Examples
304297
{
305-
public class AzureAuthExample
298+
public class AzureAuthExample
306299
{
307300
public class InstanceMetadata
308301
{
@@ -314,17 +307,9 @@ namespace Examples
314307
const string MetadataEndPoint = "http://169.254.169.254/metadata/instance?api-version=2017-08-01";
315308
const string AccessTokenEndPoint = "http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01&resource=https://management.azure.com/";
316309

317-
/// <summary>
310+
/// <summary>
318311
/// Fetches a key-value secret (kv-v2) after authenticating to Vault via Azure authentication.
319312
/// This example assumes you have a configured Azure AD Application.
320-
/// Learn more about Azure authentication prerequisites: https://www.vaultproject.io/docs/auth/azure
321-
///
322-
/// A role must first be created in Vault bound to the resource groups and subscription ids:
323-
/// vault write auth/azure/role/dev-role \
324-
/// policies="dev-policy"
325-
/// bound_subscription_ids=$AZURE_SUBSCRIPTION_ID \
326-
/// bound_resource_groups=test-rg \
327-
/// ttl=24h
328313
/// </summary>
329314
public string GetSecretWithAzureAuth()
330315
{
@@ -338,7 +323,7 @@ namespace Examples
338323
if(String.IsNullOrEmpty(roleName))
339324
{
340325
throw new System.ArgumentNullException("Vault Role Name");
341-
}
326+
}
342327

343328
string jwt = GetJWT();
344329
InstanceMetadata metadata = GetMetadata();
@@ -347,16 +332,16 @@ namespace Examples
347332
var vaultClientSettings = new VaultClientSettings(vaultAddr, authMethod);
348333

349334
IVaultClient vaultClient = new VaultClient(vaultClientSettings);
350-
335+
351336
// We can retrieve the secret from the VaultClient object
352337
Secret<SecretData> kv2Secret = null;
353338
kv2Secret = vaultClient.V1.Secrets.KeyValue.V2.ReadSecretAsync(path: "/creds").Result;
354-
339+
355340
var password = kv2Secret.Data.Data["password"];
356-
341+
357342
return password.ToString();
358343
}
359-
344+
360345
/// <summary>
361346
/// Query Azure Resource Manage for metadata about the Azure instance
362347
/// </summary>
@@ -371,7 +356,7 @@ namespace Examples
371356
StreamReader streamResponse = new StreamReader(metadataResponse.GetResponseStream());
372357
string stringResponse = streamResponse.ReadToEnd();
373358
var resultsDict = JsonConvert.DeserializeObject<Dictionary<string, InstanceMetadata>>(stringResponse);
374-
359+
375360
return resultsDict["compute"];
376361
}
377362

@@ -387,7 +372,7 @@ namespace Examples
387372
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
388373

389374
// Pipe response Stream to a StreamReader and extract access token
390-
StreamReader streamResponse = new StreamReader(response.GetResponseStream());
375+
StreamReader streamResponse = new StreamReader(response.GetResponseStream());
391376
string stringResponse = streamResponse.ReadToEnd();
392377
var resultsDict = JsonConvert.DeserializeObject<Dictionary<string, string>>(stringResponse);
393378

website/content/docs/auth/gcp.mdx

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -388,17 +388,6 @@ import (
388388
// Fetches a key-value secret (kv-v2) after authenticating to Vault
389389
// via GCP IAM, one of two auth methods used to authenticate with
390390
// GCP (the other is GCE auth).
391-
//
392-
// A role must first be created in Vault bound to the IAM user's service
393-
// account you wish to authenticate with, like so:
394-
// vault write auth/gcp/role/dev-role-iam \
395-
// type="iam" \
396-
// policies="dev-policy" \
397-
// bound_service_accounts="my-service@my-project.iam.gserviceaccount.com"
398-
// Your Vault instance must also be configured with GCP credentials to
399-
// perform API calls to IAM, like so:
400-
// vault write auth/gcp/config credentials=@path/to/server/creds.json
401-
// Learn more at https://www.vaultproject.io/docs/auth/gcp
402391
func getSecretWithGCPAuthIAM() (string, error) {
403392
config := vault.DefaultConfig() // modify for more granular configuration
404393

@@ -457,6 +446,7 @@ func getSecretWithGCPAuthIAM() (string, error) {
457446

458447
return value, nil
459448
}
449+
460450
```
461451

462452
</CodeBlockConfig>
@@ -481,19 +471,11 @@ using Data = Google.Apis.Iam.v1.Data;
481471

482472
namespace Examples
483473
{
484-
public class GCPAuthExample
474+
public class GCPAuthExample
485475
{
486476
/// <summary>
487477
/// Fetches a key-value secret (kv-v2) after authenticating to Vault via GCP IAM,
488478
/// one of two auth methods used to authenticate with GCP (the other is GCE auth).
489-
///
490-
/// A role must first be created in Vault bound to the IAM user's service account you wish to authenticate with, like so:
491-
/// type="iam" \
492-
/// policies="dev-policy" \
493-
/// bound_service_accounts="my-service@my-project.iam.gserviceaccount.com"
494-
/// Your Vault instance must also be configured with GCP credentials to perform API calls to IAM, like so:
495-
/// vault write auth/gcp/config credentials=@path/to/server/creds.json
496-
/// Learn more at https://www.vaultproject.io/docs/auth/gcp
497479
/// </summary>
498480
public string GetSecretGcp()
499481
{
@@ -503,10 +485,10 @@ namespace Examples
503485
throw new System.ArgumentNullException("Vault Address");
504486
}
505487

506-
var roleName = Environment.GetEnvironmentVariable("GCP_ROLE");
488+
var roleName = Environment.GetEnvironmentVariable("VAULT_ROLE");
507489
if(String.IsNullOrEmpty(roleName))
508490
{
509-
throw new System.ArgumentNullException("GCP Role Name");
491+
throw new System.ArgumentNullException("Vault Role Name");
510492
}
511493

512494
// Learn about authenticating to GCS with service account credentials at https://cloud.google.com/docs/authentication/production
@@ -516,18 +498,18 @@ namespace Examples
516498
}
517499

518500
var jwt = SignJWT();
519-
501+
520502
IAuthMethodInfo authMethod = new GoogleCloudAuthMethodInfo(roleName, jwt);
521503
var vaultClientSettings = new VaultClientSettings(vaultAddr, authMethod);
522504

523-
IVaultClient vaultClient = new VaultClient(vaultClientSettings);
505+
IVaultClient vaultClient = new VaultClient(vaultClientSettings);
524506

525507
// We can retrieve the secret after creating our VaultClient object
526508
Secret<SecretData> kv2Secret = null;
527509
kv2Secret = vaultClient.V1.Secrets.KeyValue.V2.ReadSecretAsync(path: "/creds").Result;
528-
510+
529511
var password = kv2Secret.Data.Data["password"];
530-
512+
531513
return password.ToString();
532514
}
533515

@@ -547,7 +529,7 @@ namespace Examples
547529
});
548530

549531
string svcEmail = $"{svcAcctName}@{gcpProjName}.iam.gserviceaccount.com";
550-
string name = $"projects/-/serviceAccounts/{svcEmail}";
532+
string name = $"projects/-/serviceAccounts/{svcEmail}";
551533

552534
TimeSpan currentTime = (DateTime.UtcNow - new DateTime(1970, 1, 1));
553535
int expiration = (int)(currentTime.TotalSeconds) + 900;
@@ -563,7 +545,7 @@ namespace Examples
563545
ProjectsResource.ServiceAccountsResource.SignJwtRequest request = iamService.Projects.ServiceAccounts.SignJwt(requestBody, name);
564546

565547
Data.SignJwtResponse response = request.Execute();
566-
548+
567549
return JsonConvert.SerializeObject(response.SignedJwt).Replace("\"", "");
568550
}
569551

0 commit comments

Comments
 (0)