OVHSDK 0.3.16

There is a newer version of this package available.
See the version list below for details.
dotnet add package OVHSDK --version 0.3.16                
NuGet\Install-Package OVHSDK -Version 0.3.16                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="OVHSDK" Version="0.3.16" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add OVHSDK --version 0.3.16                
#r "nuget: OVHSDK, 0.3.16"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install OVHSDK as a Cake Addin
#addin nuget:?package=OVHSDK&version=0.3.16

// Install OVHSDK as a Cake Tool
#tool nuget:?package=OVHSDK&version=0.3.16                

NuGet Version

Authentication

There are three ways to authenticate with OVH:

  • Application key, application secret, and consumer key
  • Client ID and Client Secret
  • Token

There is an authentication implementation for each method:

  • Ovh.Sdk.Net.AuthProviders.Application
  • Ovh.Sdk.Net.AuthProviders.OAuth2
  • Ovh.Sdk.Net.AuthProviders.Token

Refer to the examples for usage.

Samples

SA creation, attach policy and SA login

using _iam_policy;
using _oauth2;
using Ovh.Sdk.Net;
using Ovh.Sdk.Net.AuthProviders;
using Action = _iam_policy.Action;

// Login with an application

// Fetch credentials from environment variables (OVH_APPLICATION_KEY, OVH_APPLICATION_SECRET, OVH_CONSUMER_KEY)
var applicationProvider = new Application();

// Uncomment this line to log all requests and responses
//var handler = new LogHandler(new HttpClientHandler());
var handler = new HttpClientHandler();

var adminClient = new Client(new HttpClient(handler)
{
    BaseAddress = new Uri("https://eu.api.ovh.com"),
}, applicationProvider);

// Create a service account

var serviceAccount = await adminClient.PostV1MeApiOauth2ClientAsync(new clientRequest
{
    Name = "ProjectViewer",
    Description = "Service account to view all projects",
    CallbackUrls = [],
    Flow = ClientFlowEnum.CLIENT_CREDENTIALS,
});
var saInfos = await adminClient.GetV1MeApiOauth2ClientClientIdAsync(serviceAccount.ClientId);

// Upsert the policy for the service account

var activePolicies = await adminClient.GetV2IamPolicyAsync();
var policy = activePolicies.FirstOrDefault(x => x.Name == "OvhSdkNet_Sample");
if (policy == null)
{
    policy = await adminClient.PostV2IamPolicyAsync(new Creation
    {
        Description = "View all projects",
        Identities = [saInfos.Identity],
        Name = "OvhSdkNet_Sample",
        Permissions = new Permissions
        {
            Allow =
            [
                new Action
                {
                    _Action = "publicCloudProject:apiovh:get"
                }
            ]
        },
        Resources = [new Resource { Urn = "urn:v1:eu:resource:publicCloudProject:*" }]
    });
}
else
{
    await adminClient.PutV2IamPolicyPolicyIdAsync(new Update
    {
        Description = "View all projects",
        Identities = [saInfos.Identity],
        Name = "OvhSdkNet_Sample",
        Permissions = new Permissions
        {
            Allow =
            [
                new Action
                {
                    _Action = "publicCloudProject:apiovh:get"
                }
            ]
        },
        Resources = [new Resource { Urn = "urn:v1:eu:resource:publicCloudProject:*" }]
    }, policy.Id);
}

// Login with the service account

var oauthProvider = new OAuth2(serviceAccount.ClientId, serviceAccount._ClientSecret, "https://www.ovh.com/auth/oauth2/token");

var serviceAccountClient = new Client(new HttpClient(handler)
{
    BaseAddress = new Uri("https://eu.api.ovh.com"),
}, oauthProvider);

// Get all projects with our new service account

var projects = await serviceAccountClient.GetV1CloudProjectAsync();
foreach (var project in projects)
{
    var projectInfo = await serviceAccountClient.GetV1CloudProjectServiceNameAsync(project);
    Console.WriteLine($"{project}: {projectInfo.Description}");
}

// Cleanup the service account and policy

await adminClient.DeleteV2IamPolicyPolicyIdAsync(policy.Id);
await adminClient.DeleteV1MeApiOauth2ClientClientIdAsync(serviceAccount.ClientId);
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.3.42 39 11/28/2024
0.3.41 66 11/27/2024
0.3.40 70 11/26/2024
0.3.39 79 11/23/2024
0.3.38 81 11/22/2024
0.3.37 66 11/21/2024
0.3.36 68 11/20/2024
0.3.35 72 11/19/2024
0.3.34 75 11/16/2024
0.3.33 76 11/14/2024
0.3.32 75 11/13/2024
0.3.31 81 11/8/2024
0.3.30 76 11/7/2024
0.3.29 72 11/6/2024
0.3.28 75 11/5/2024
0.3.27 86 11/2/2024
0.3.26 78 11/1/2024
0.3.25 72 10/31/2024
0.3.24 67 10/30/2024
0.3.23 74 10/29/2024
0.3.22 82 10/28/2024
0.3.21 80 10/27/2024
0.3.20 72 10/26/2024
0.3.19 71 10/25/2024
0.3.18 77 10/23/2024
0.3.17 77 10/22/2024
0.3.16 109 10/19/2024
0.3.15 109 10/18/2024
0.3.14 81 10/17/2024
0.3.13 76 10/16/2024
0.3.12 81 10/15/2024
0.3.11 80 10/14/2024
0.3.10 81 10/13/2024
0.3.9 89 10/11/2024
0.3.8 83 10/10/2024
0.3.7 87 10/9/2024
0.3.6 79 10/8/2024
0.3.5 96 10/2/2024
0.3.4 108 10/1/2024
0.3.3 92 10/1/2024
0.3.2 95 9/30/2024
0.3.1 98 9/28/2024