feat: add attributes (#6)
add support for google host attributes: - project_id (Required): The project ID associated with the service account - zone (Required): The deployment area within a region disable_credential_rotation (Optional): Disables credential rotation by the plugin - client_email (Optional): The email address associated with the service account. The email address used to uniquely identify the service account. It is required for authentication and authorization. If it is not set, authentication will fail. - target_service_account_id (Optional): The unique identifier for the service account that will be impersonated. - disable_credential_rotation (Optional): Disable the rotation of google service account key associated with the plugin
This commit is contained in:
1 parent
6588e10934
commit
eec01f7d69
6 files changed
+128
-40
No files matched your search
@@ -34,10 +34,16 @@ func getCatalogAttributes(in *structpb.Struct) (*CatalogAttributes, error) {
|
||||
for s := range unknownFields {
|
||||
switch s {
|
||||
// Ignore knownFields from CredentialAttributes
|
||||
case cred.ConstProject:
|
||||
case cred.ConstProjectId:
|
||||
continue
|
||||
case cred.ConstZone:
|
||||
continue
|
||||
case cred.ConstDisableCredentialRotation:
|
||||
continue
|
||||
case cred.ConstClientEmail:
|
||||
continue
|
||||
case cred.ConstTargetServiceAccountID:
|
||||
continue
|
||||
default:
|
||||
badFields[fmt.Sprintf("attributes.%s", s)] = "unrecognized field"
|
||||
}
|
||||
@@ -107,7 +113,7 @@ func getSetAttributes(in *structpb.Struct) (*SetAttributes, error) {
|
||||
|
||||
func buildListInstancesRequest(attributes *SetAttributes, catalog *CatalogAttributes) *computepb.ListInstancesRequest {
|
||||
request := &computepb.ListInstancesRequest{
|
||||
Project: catalog.Project,
|
||||
Project: catalog.ProjectId,
|
||||
Zone: catalog.Zone,
|
||||
}
|
||||
|
||||
@@ -121,7 +127,7 @@ func buildListInstancesRequest(attributes *SetAttributes, catalog *CatalogAttrib
|
||||
func buildListInstanceGroupsRequest(attributes *SetAttributes, catalog *CatalogAttributes) *computepb.ListInstancesInstanceGroupsRequest {
|
||||
request := &computepb.ListInstancesInstanceGroupsRequest{
|
||||
InstanceGroup: attributes.InstanceGroup,
|
||||
Project: catalog.Project,
|
||||
Project: catalog.ProjectId,
|
||||
Zone: catalog.Zone,
|
||||
}
|
||||
|
||||
|
||||
@@ -21,20 +21,20 @@ func TestGetCatalogAttributes(t *testing.T) {
|
||||
expectedErrContains string
|
||||
}{
|
||||
{
|
||||
name: "missing project and zone",
|
||||
name: "missing project_id and zone",
|
||||
in: &structpb.Struct{
|
||||
Fields: make(map[string]*structpb.Value),
|
||||
},
|
||||
expectedErrContains: "attributes.project: missing required value \"project\", attributes.zone: missing required value \"zone\"",
|
||||
expectedErrContains: "attributes.project_id: missing required value \"project_id\", attributes.zone: missing required value \"zone\"",
|
||||
},
|
||||
{
|
||||
name: "unknown fields",
|
||||
in: &structpb.Struct{
|
||||
Fields: map[string]*structpb.Value{
|
||||
"project": structpb.NewStringValue("test-12345"),
|
||||
"zone": structpb.NewStringValue("us-central-1a"),
|
||||
"foo": structpb.NewBoolValue(true),
|
||||
"bar": structpb.NewBoolValue(true),
|
||||
"project_id": structpb.NewStringValue("test-12345"),
|
||||
"zone": structpb.NewStringValue("us-central-1a"),
|
||||
"foo": structpb.NewBoolValue(true),
|
||||
"bar": structpb.NewBoolValue(true),
|
||||
},
|
||||
},
|
||||
expectedErrContains: "attributes.bar: unrecognized field, attributes.foo: unrecognized field",
|
||||
@@ -43,13 +43,13 @@ func TestGetCatalogAttributes(t *testing.T) {
|
||||
name: "valid project and zone",
|
||||
in: &structpb.Struct{
|
||||
Fields: map[string]*structpb.Value{
|
||||
"project": structpb.NewStringValue("test-12345"),
|
||||
"zone": structpb.NewStringValue("us-central-1a"),
|
||||
"project_id": structpb.NewStringValue("test-12345"),
|
||||
"zone": structpb.NewStringValue("us-central-1a"),
|
||||
},
|
||||
},
|
||||
expected: &CatalogAttributes{&cred.CredentialAttributes{
|
||||
Project: "test-12345",
|
||||
Zone: "us-central-1a",
|
||||
ProjectId: "test-12345",
|
||||
Zone: "us-central-1a",
|
||||
}},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -40,8 +40,8 @@ func TestListHosts(t *testing.T) {
|
||||
|
||||
hostCatalogAttributes := &hostcatalogs.HostCatalog_Attributes{
|
||||
Attributes: wrapMap(t, map[string]interface{}{
|
||||
cred.ConstProject: project,
|
||||
cred.ConstZone: zone,
|
||||
cred.ConstProjectId: project,
|
||||
cred.ConstZone: zone,
|
||||
}),
|
||||
}
|
||||
|
||||
@@ -309,8 +309,8 @@ func TestCreateCatalog(t *testing.T) {
|
||||
|
||||
hostCatalogAttributes := &hostcatalogs.HostCatalog_Attributes{
|
||||
Attributes: wrapMap(t, map[string]interface{}{
|
||||
cred.ConstProject: project,
|
||||
cred.ConstZone: zone,
|
||||
cred.ConstProjectId: project,
|
||||
cred.ConstZone: zone,
|
||||
}),
|
||||
}
|
||||
|
||||
@@ -390,8 +390,8 @@ func TestUpdateCatalog(t *testing.T) {
|
||||
|
||||
hostCatalogAttributes := &hostcatalogs.HostCatalog_Attributes{
|
||||
Attributes: wrapMap(t, map[string]interface{}{
|
||||
cred.ConstProject: project,
|
||||
cred.ConstZone: zone,
|
||||
cred.ConstProjectId: project,
|
||||
cred.ConstZone: zone,
|
||||
}),
|
||||
}
|
||||
|
||||
@@ -477,8 +477,8 @@ func TestCreateSet(t *testing.T) {
|
||||
Attrs: &hostcatalogs.HostCatalog_Attributes{
|
||||
Attributes: &structpb.Struct{
|
||||
Fields: map[string]*structpb.Value{
|
||||
cred.ConstProject: structpb.NewStringValue("test-project"),
|
||||
cred.ConstZone: structpb.NewStringValue("us-central1-a"),
|
||||
cred.ConstProjectId: structpb.NewStringValue("test-project"),
|
||||
cred.ConstZone: structpb.NewStringValue("us-central1-a"),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -599,8 +599,8 @@ func TestUpdateSet(t *testing.T) {
|
||||
Attrs: &hostcatalogs.HostCatalog_Attributes{
|
||||
Attributes: &structpb.Struct{
|
||||
Fields: map[string]*structpb.Value{
|
||||
cred.ConstProject: structpb.NewStringValue("test-project"),
|
||||
cred.ConstZone: structpb.NewStringValue("us-central1-a"),
|
||||
cred.ConstProjectId: structpb.NewStringValue("test-project"),
|
||||
cred.ConstZone: structpb.NewStringValue("us-central1-a"),
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user