Skip to content

Commit

Permalink
MD tech review 1
Browse files Browse the repository at this point in the history
  • Loading branch information
rustagir committed Sep 16, 2024
1 parent 4f88941 commit 24667c2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 42 deletions.
35 changes: 6 additions & 29 deletions source/fundamentals/enterprise-auth.txt
Original file line number Diff line number Diff line change
Expand Up @@ -409,27 +409,16 @@ environment variable:
:start-after: start-custom-callback
:end-before: end-custom-callback

Next, create a map to store your authentication
mechanism properties, as shown in the following example. Replace
the ``<audience>`` placeholder with the value of the ``audience``
parameter configured on your MongoDB deployment.

.. code-block:: go

props := map[string]string{
"TOKEN_RESOURCE": "<audience>",
}

Then, you can create a ``Credential`` struct that uses the properties
map and the EKS callback function:
Then, you can create a ``Credential`` struct that uses the EKS callback
function that you defined:

.. literalinclude:: /includes/authentication/eks-custom-callback.go
:language: go
:dedent:
:copyable: true
:start-after: start-credential-callback
:end-before: end-credential-callback
:emphasize-lines: 10
:emphasize-lines: 6

.. _golang-mongodb-oidc-azure-envs:

Expand Down Expand Up @@ -478,28 +467,16 @@ service-account token-file location:
:start-after: start-callback
:end-before: end-callback

Next, create a map to store your authentication
mechanism properties, as shown in the following example. Replace
the ``<audience>`` placeholder with the value of the ``audience``
parameter configured on your MongoDB deployment.

.. code-block:: go

props := map[string]string{
"ENVIRONMENT": "gcp",
"TOKEN_RESOURCE": "<audience>",
}

Then, you can create a ``Credential`` struct that uses the properties
map and the GKE callback function:
Then, you can create a ``Credential`` struct that uses the the GKE
callback function that you defined:

.. literalinclude:: /includes/authentication/gke-callback.go
:language: go
:copyable: true
:dedent:
:start-after: start-credential-callback
:end-before: end-credential-callback
:emphasize-lines: 11
:emphasize-lines: 6

Additional Information
----------------------
Expand Down
8 changes: 2 additions & 6 deletions source/includes/authentication/eks-custom-callback.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,11 @@ func main() {

// start-credential-callback
uri := "mongodb://<hostname>:<port>"
props := map[string]string{
"TOKEN_RESOURCE": "<audience>",
}
opts := options.Client().ApplyURI(uri)
opts.SetAuth(
options.Credential{
AuthMechanism: "MONGODB-OIDC",
AuthMechanismProperties: props,
OIDCMachineCallback: eksCallback,
AuthMechanism: "MONGODB-OIDC",
OIDCMachineCallback: eksCallback,
},
)
client, err := mongo.Connect(opts)
Expand Down
9 changes: 2 additions & 7 deletions source/includes/authentication/gke-callback.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,11 @@ func main() {

// start-credential-callback
uri := "mongodb://<hostname>:<port>"
props := map[string]string{
"ENVIRONMENT": "gcp",
"TOKEN_RESOURCE": "<audience>",
}
opts := options.Client().ApplyURI(uri)
opts.SetAuth(
options.Credential{
AuthMechanism: "MONGODB-OIDC",
AuthMechanismProperties: props,
OIDCMachineCallback: gkeCallback,
AuthMechanism: "MONGODB-OIDC",
OIDCMachineCallback: gkeCallback,
},
)
client, err := mongo.Connect(opts)
Expand Down

0 comments on commit 24667c2

Please sign in to comment.