Skip to content

Fix token renewal problem for rm and graph tokens passed in #4726

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

Merged
merged 2 commits into from
Oct 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,28 @@ public static void CopyFrom(this IAzureAccount account, IAzureAccount source)
{
account.TenantMap[item.Key] = item.Value;
}

account.CopyPropertiesFrom(source);
}
}

/// <summary>
/// Update non-null non-identity account properties from the given account
/// </summary>
/// <param name="account">The account to copy to (target)</param>
/// <param name="other">The account to copy from (source)</param>
public static void Update(this IAzureAccount account, IAzureAccount source)
{
if (account != null && source != null)
{
account.Credential = source.Credential ?? account.Credential;
foreach (var item in source.TenantMap)
{
account.TenantMap[item.Key] = item.Value;
}

account.UpdateProperties(source);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -128,5 +128,21 @@ public static IAzureAccount GetAccount(this IAzureContextContainer container, st
{
return container.Accounts.FirstOrDefault((a) => string.Equals(a.Id, account, StringComparison.CurrentCultureIgnoreCase));
}

/// <summary>
/// Update the properties of the context
/// </summary>
/// <param name="context">The context to update</param>
/// <param name="other">The context to update from</param>
public static void Update(this IAzureContext context, IAzureContext other)
{
if (context != null && other != null)
{
context.Account.Update(other.Account);
context.Subscription.Update(other.Subscription);
context.Tenant.Update(other.Tenant);
context.UpdateProperties(other);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,96 @@ public static void CopyFrom(this IAzureEnvironment environment, IAzureEnvironmen
}

}

public static void Update(this IAzureEnvironment environment, IAzureEnvironment other)
{
if (environment != null && other != null)
{
environment.OnPremise = other.OnPremise;
if (other.IsEndpointSet(AzureEnvironment.Endpoint.ActiveDirectoryServiceEndpointResourceId))
{
environment.ActiveDirectoryServiceEndpointResourceId = other.ActiveDirectoryServiceEndpointResourceId;
}
if (other.IsEndpointSet(AzureEnvironment.Endpoint.AdTenant))
{
environment.AdTenant = other.AdTenant;
}
if (other.IsEndpointSet(AzureEnvironment.Endpoint.Gallery))
{
environment.GalleryUrl = other.GalleryUrl;
}
if (other.IsEndpointSet(AzureEnvironment.Endpoint.ManagementPortalUrl))
{
environment.ManagementPortalUrl = other.ManagementPortalUrl;
}
if (other.IsEndpointSet(AzureEnvironment.Endpoint.ServiceManagement))
{
environment.ServiceManagementUrl = other.ServiceManagementUrl;
}
if (other.IsEndpointSet(AzureEnvironment.Endpoint.PublishSettingsFileUrl))
{
environment.PublishSettingsFileUrl = other.PublishSettingsFileUrl;
}
if (other.IsEndpointSet(AzureEnvironment.Endpoint.ResourceManager))
{
environment.ResourceManagerUrl = other.ResourceManagerUrl;
}
if (other.IsEndpointSet(AzureEnvironment.Endpoint.SqlDatabaseDnsSuffix))
{
environment.SqlDatabaseDnsSuffix = other.SqlDatabaseDnsSuffix;
}
if (other.IsEndpointSet(AzureEnvironment.Endpoint.StorageEndpointSuffix))
{
environment.StorageEndpointSuffix = other.StorageEndpointSuffix;
}
if (other.IsEndpointSet(AzureEnvironment.Endpoint.ActiveDirectory))
{
environment.ActiveDirectoryAuthority = other.ActiveDirectoryAuthority;
}
if (other.IsEndpointSet(AzureEnvironment.Endpoint.Graph))
{
environment.GraphUrl = other.GraphUrl;
}
if (other.IsEndpointSet(AzureEnvironment.Endpoint.GraphEndpointResourceId))
{
environment.GraphEndpointResourceId = other.GraphEndpointResourceId;
}
if (other.IsEndpointSet(AzureEnvironment.Endpoint.TrafficManagerDnsSuffix))
{
environment.TrafficManagerDnsSuffix = other.TrafficManagerDnsSuffix;
}
if (other.IsEndpointSet(AzureEnvironment.Endpoint.AzureKeyVaultDnsSuffix))
{
environment.AzureKeyVaultDnsSuffix = other.AzureKeyVaultDnsSuffix;
}
if (other.IsEndpointSet(AzureEnvironment.Endpoint.AzureDataLakeStoreFileSystemEndpointSuffix))
{
environment.AzureDataLakeStoreFileSystemEndpointSuffix = other.AzureDataLakeStoreFileSystemEndpointSuffix;
}
if (other.IsEndpointSet(AzureEnvironment.Endpoint.AzureDataLakeAnalyticsCatalogAndJobEndpointSuffix))
{
environment.AzureDataLakeAnalyticsCatalogAndJobEndpointSuffix =
other.AzureDataLakeAnalyticsCatalogAndJobEndpointSuffix;
}
if (other.IsEndpointSet(AzureEnvironment.Endpoint.AzureKeyVaultServiceEndpointResourceId))
{
environment.AzureKeyVaultServiceEndpointResourceId =
other.AzureKeyVaultServiceEndpointResourceId;
}

foreach (var profile in other.VersionProfiles)
{
if (!environment.VersionProfiles.Contains(profile))
{
environment.VersionProfiles.Add(profile);
}
}

environment.UpdateProperties(other);
}

}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public static void SetTenant(this IAzureSubscription subscription, string tenant
}

/// <summary>
///
/// Copy the properties from the given subscription
/// </summary>
/// <param name="subscription"></param>
/// <param name="other"></param>
Expand All @@ -156,5 +156,20 @@ public static void CopyFrom(this IAzureSubscription subscription, IAzureSubscrip
subscription.CopyPropertiesFrom(other);
}
}

/// <summary>
/// Update the non-identity properties from the given subscription
/// </summary>
/// <param name="subscription"></param>
/// <param name="other"></param>
public static void Update(this IAzureSubscription subscription, IAzureSubscription other)
{
if (subscription != null && other != null)
{
subscription.Name = other.Name?? subscription.Name;
subscription.State = other.State?? subscription.State;
subscription.UpdateProperties(other);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,19 @@ public static void CopyFrom(this IAzureTenant tenant, IAzureTenant other)
tenant.CopyPropertiesFrom(other);
}
}

/// <summary>
/// Update the non-identity properties of this tenant, using another tenant
/// </summary>
/// <param name="tenant"></param>
/// <param name="other"></param>
public static void Update(this IAzureTenant tenant, IAzureTenant other)
{
if (tenant != null && other != null)
{
tenant.Directory = other.Directory?? tenant.Directory;
tenant.UpdateProperties(other);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -115,5 +115,21 @@ public static void CopyPropertiesFrom(this IExtensibleModel model, IExtensibleMo
}
}
}

/// <summary>
/// Copy Unset propeties from another extensible model to this one
/// </summary>
/// <param name="model"></param>
/// <param name="newModel"></param>
public static void UpdateProperties(this IExtensibleModel model, IExtensibleModel newModel)
{
if (model != null && newModel != null)
{
foreach (var item in newModel.ExtendedProperties)
{
model.SetProperty(item.Key, item.Value);
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,12 @@ public bool TrySetContext(string name, IAzureContext context)
public bool TrySetContext(IAzureContext context, out string name)
{
bool result = false;
if (!TryFindContext(context, out name))
if (TryFindContext(context, out name) && Contexts != null && Contexts.ContainsKey(name))
{
Contexts[name].Update(context);
result = true;
}
else
{
result = TryAddContext(context, out name);
}
Expand All @@ -483,7 +488,11 @@ public bool TrySetDefaultContext(IAzureContext context)

if (context != null && (TryFindContext(context, out contextName) || TryAddContext(context, out contextName)))
{
result = TrySetDefaultContext(contextName);
if (TrySetDefaultContext(contextName) && DefaultContext != null)
{
DefaultContext.Update(context);
result = true;
}
}

return result;
Expand Down
Loading